{"question_id": 2515, "task_id": "shortest-distance-to-target-string-in-a-circular-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning.\n\n- Formally, the next element of words[i] is words[(i + 1) % n] and the previous element of words[i] is words[(i - 1 + n) % n], where n is the length of words.\n\nStarting from startIndex, you can move to either the next word or the previous word with 1 step at a time.\n\nReturn the shortest distance needed to reach the string target. If the string target does not exist in words, return -1.\n\nExample 1:\n\nInput: words = [\"hello\",\"i\",\"am\",\"leetcode\",\"hello\"], target = \"hello\", startIndex = 1\nOutput: 1\nExplanation: We start from index 1 and can reach \"hello\" by\n- moving 3 units to the right to reach index 4.\n- moving 2 units to the left to reach index 4.\n- moving 4 units to the right to reach index 0.\n- moving 1 unit to the left to reach index 0.\nThe shortest distance to reach \"hello\" is 1.\n\nExample 2:\n\nInput: words = [\"a\",\"b\",\"leetcode\"], target = \"leetcode\", startIndex = 0\nOutput: 1\nExplanation: We start from index 0 and can reach \"leetcode\" by\n- moving 2 units to the right to reach index 2.\n- moving 1 unit to the left to reach index 2.\nThe shortest distance to reach \"leetcode\" is 1.\n\nExample 3:\n\nInput: words = [\"i\",\"eat\",\"leetcode\"], target = \"ate\", startIndex = 0\nOutput: -1\nExplanation: Since \"ate\" does not exist in words, we return -1.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 100\n- words[i] and target consist of only lowercase English letters.\n- 0 <= startIndex < words.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'def', 'ghi'],target = \"xyz\",startIndex = 1) == -1\n assert candidate(words = ['apple', 'banana', 'cherry', 'date'],target = \"banana\",startIndex = 2) == 1\n assert candidate(words = ['cat', 'dog', 'bird', 'fish'],target = \"cat\",startIndex = 3) == 1\n assert candidate(words = ['dog', 'cat', 'bat'],target = \"dog\",startIndex = 2) == 1\n assert candidate(words = ['hello', 'i', 'am', 'leetcode', 'hello'],target = \"hello\",startIndex = 1) == 1\n assert candidate(words = ['a', 'a', 'a', 'a'],target = \"a\",startIndex = 0) == 0\n assert candidate(words = ['a', 'b', 'c', 'd'],target = \"a\",startIndex = 3) == 1\n assert candidate(words = ['a', 'b', 'leetcode'],target = \"leetcode\",startIndex = 0) == 1\n assert candidate(words = ['dog', 'cat', 'bat'],target = \"rat\",startIndex = 1) == -1\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"one\",startIndex = 3) == 1\n assert candidate(words = ['red', 'blue', 'green'],target = \"yellow\",startIndex = 1) == -1\n assert candidate(words = ['i', 'eat', 'leetcode'],target = \"ate\",startIndex = 0) == -1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"five\",startIndex = 3) == 1\n assert candidate(words = ['apple', 'banana', 'cherry'],target = \"banana\",startIndex = 2) == 1\n assert candidate(words = ['z', 'y', 'x', 'w', 'v'],target = \"v\",startIndex = 4) == 0\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"five\",startIndex = 0) == 1\n assert candidate(words = ['red', 'blue', 'green'],target = \"green\",startIndex = 1) == 1\n assert candidate(words = ['abc', 'def', 'ghi'],target = \"def\",startIndex = 1) == 0\n assert candidate(words = ['red', 'blue', 'green'],target = \"blue\",startIndex = 1) == 0\n assert candidate(words = ['a', 'a', 'a', 'a'],target = \"b\",startIndex = 0) == -1\n assert candidate(words = ['a', 'a', 'a', 'a', 'a'],target = \"a\",startIndex = 2) == 0\n assert candidate(words = ['dog', 'cat', 'bird'],target = \"fish\",startIndex = 1) == -1\n assert candidate(words = ['sun', 'moon', 'star'],target = \"planet\",startIndex = 1) == -1\n assert candidate(words = ['a', 'b', 'c', 'd'],target = \"d\",startIndex = 2) == 1\n assert candidate(words = ['a', 'b', 'c', 'd'],target = \"b\",startIndex = 2) == 1\n assert candidate(words = ['rotate', 'me', 'around', 'and', 'around', 'again', 'rotate'],target = \"around\",startIndex = 0) == 2\n assert candidate(words = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g'],target = \"d\",startIndex = 0) == 4\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"five\",startIndex = 0) == 4\n assert candidate(words = ['zebra', 'yak', 'xylophone', 'wolf', 'vulture'],target = \"wolf\",startIndex = 1) == 2\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"mno\",startIndex = 0) == 4\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],target = \"e\",startIndex = 8) == 4\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy'],target = \"galaxy\",startIndex = 3) == 3\n assert candidate(words = ['same', 'words', 'here', 'are', 'same', 'words'],target = \"words\",startIndex = 2) == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"seven\",startIndex = 4) == 2\n assert candidate(words = ['hello', 'world', 'hello', 'world', 'hello', 'world'],target = \"hello\",startIndex = 4) == 0\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],target = \"date\",startIndex = 0) == 3\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"mno\",startIndex = 6) == 2\n assert candidate(words = ['repeat', 'this', 'sentence', 'repeat', 'this', 'sentence'],target = \"sentence\",startIndex = 3) == 1\n assert candidate(words = ['search', 'for', 'this', 'word', 'in', 'this', 'circular', 'array'],target = \"this\",startIndex = 4) == 1\n assert candidate(words = ['single'],target = \"single\",startIndex = 0) == 0\n assert candidate(words = ['car', 'bus', 'bike', 'train', 'truck', 'van'],target = \"van\",startIndex = 3) == 2\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'red', 'blue', 'green', 'yellow'],target = \"yellow\",startIndex = 2) == 1\n assert candidate(words = ['unique', 'words', 'only', 'here'],target = \"only\",startIndex = 1) == 1\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink'],target = \"purple\",startIndex = 1) == 3\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"one\",startIndex = 9) == 1\n assert candidate(words = ['water', 'fire', 'earth', 'air', 'ice', 'steam', 'cloud'],target = \"cloud\",startIndex = 3) == 3\n assert candidate(words = ['hello', 'world', 'python', 'code', 'challenge'],target = \"python\",startIndex = 3) == 1\n assert candidate(words = ['algorithm', 'data', 'structures', 'algorithm', 'data'],target = \"structures\",startIndex = 0) == 2\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"five\",startIndex = 8) == 4\n assert candidate(words = ['python', 'java', 'c', 'cpp', 'ruby', 'swift', 'go'],target = \"cpp\",startIndex = 5) == 2\n assert candidate(words = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],target = \"y\",startIndex = 5) == 1\n assert candidate(words = ['dog', 'cat', 'mouse', 'rat', 'elephant', 'giraffe', 'hippo'],target = \"elephant\",startIndex = 2) == 2\n assert candidate(words = ['orange', 'peach', 'plum', 'grape', 'kiwi'],target = \"peach\",startIndex = 3) == 2\n assert candidate(words = ['last', 'element', 'is', 'the', 'target'],target = \"target\",startIndex = 3) == 1\n assert candidate(words = ['cat', 'dog', 'fish', 'bird', 'elephant', 'antelope', 'hippo'],target = \"hippo\",startIndex = 2) == 3\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"vwx\",startIndex = 4) == 3\n assert candidate(words = ['loop', 'around', 'this', 'circular', 'array'],target = \"array\",startIndex = 1) == 2\n assert candidate(words = ['circular', 'array', 'test', 'case', 'example', 'circular'],target = \"example\",startIndex = 4) == 0\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'],target = \"p\",startIndex = 15) == 0\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"seven\",startIndex = 7) == 1\n assert candidate(words = ['a', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'],target = \"lazy\",startIndex = 3) == 4\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa'],target = \"aaaaaa\",startIndex = 1) == 4\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"ten\",startIndex = 2) == 3\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'galaxy', 'universe', 'comet'],target = \"moon\",startIndex = 4) == 3\n assert candidate(words = ['hello', 'world', 'python', 'programming', 'hello', 'world'],target = \"programming\",startIndex = 4) == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"two\",startIndex = 8) == 3\n assert candidate(words = ['hello', 'world', 'python', 'programming', 'is', 'fun'],target = \"programming\",startIndex = 2) == 1\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'galaxy', 'universe', 'sun', 'moon'],target = \"galaxy\",startIndex = 6) == 2\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'purple', 'orange', 'pink'],target = \"pink\",startIndex = 6) == 0\n assert candidate(words = ['hello', 'world', 'python', 'programming', 'hello'],target = \"programming\",startIndex = 2) == 1\n assert candidate(words = ['mango', 'banana', 'mango', 'banana', 'mango'],target = \"banana\",startIndex = 0) == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"four\",startIndex = 7) == 4\n assert candidate(words = ['hello', 'world', 'this', 'is', 'a', 'circular', 'array'],target = \"is\",startIndex = 5) == 2\n assert candidate(words = ['ocean', 'lake', 'river', 'pond', 'creek', 'stream', 'flood', 'bay', 'harbor', 'gulf'],target = \"stream\",startIndex = 5) == 0\n assert candidate(words = ['dog', 'cat', 'bird', 'fish', 'dog', 'cat', 'bird', 'fish'],target = \"fish\",startIndex = 7) == 0\n assert candidate(words = ['banana', 'apple', 'orange', 'grape', 'banana', 'apple', 'orange', 'grape'],target = \"orange\",startIndex = 5) == 1\n assert candidate(words = ['longwordthatwillnotmatch', 'anotherlongword', 'yetanotherlongword', 'stillanotherlongword'],target = \"nonexistent\",startIndex = 1) == -1\n assert candidate(words = ['algorithm', 'data', 'structure', 'algorithm', 'data', 'structure'],target = \"structure\",startIndex = 2) == 0\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven'],target = \"four\",startIndex = 6) == 3\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'galaxy'],target = \"galaxy\",startIndex = 2) == 2\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'purple', 'orange'],target = \"blue\",startIndex = 5) == 2\n assert candidate(words = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e'],target = \"d\",startIndex = 7) == 1\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa'],target = \"delta\",startIndex = 8) == 5\n assert candidate(words = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g'],target = \"d\",startIndex = 9) == 3\n assert candidate(words = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],target = \"y\",startIndex = 4) == 0\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],target = \"date\",startIndex = 5) == 2\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],target = \"banana\",startIndex = 6) == 2\n assert candidate(words = ['find', 'the', 'shortest', 'distance', 'in', 'a', 'circular', 'array'],target = \"distance\",startIndex = 5) == 2\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],target = \"banana\",startIndex = 5) == 3\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"mno\",startIndex = 5) == 1\n assert candidate(words = ['hello', 'world', 'python', 'programming', 'code', 'hello'],target = \"code\",startIndex = 3) == 1\n assert candidate(words = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply', 'waldo', 'fred', 'plugh', 'xyzzy', 'thud'],target = \"garply\",startIndex = 10) == 3\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],target = \"banana\",startIndex = 4) == 3\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"mno\",startIndex = 7) == 3\n assert candidate(words = ['aardvark', 'anteater', 'armadillo', 'baboon', 'badger', 'bat', 'bear', 'beaver', 'bison', 'boar'],target = \"badger\",startIndex = 9) == 5\n assert candidate(words = ['cat', 'dog', 'fish', 'bird', 'ant'],target = \"ant\",startIndex = 2) == 2\n assert candidate(words = ['repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat'],target = \"repeat\",startIndex = 5) == 0\n assert candidate(words = ['red', 'green', 'blue', 'yellow', 'orange', 'purple'],target = \"green\",startIndex = 5) == 2\n assert candidate(words = ['algorithm', 'data', 'structures', 'algorithm', 'data', 'structures'],target = \"data\",startIndex = 3) == 1\n assert candidate(words = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w'],target = \"m\",startIndex = 10) == 5\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj'],target = \"jjj\",startIndex = 9) == 0\n assert candidate(words = ['longerword', 'stringexample', 'anotherexample', 'yetanother', 'finalword'],target = \"anotherexample\",startIndex = 1) == 1\n assert candidate(words = ['complex', 'circular', 'array', 'problem', 'solution'],target = \"complex\",startIndex = 3) == 2\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"vwx\",startIndex = 8) == 1\n assert candidate(words = ['loop', 'circle', 'ring', 'cycle', 'wheel', 'orbit', 'oval'],target = \"oval\",startIndex = 3) == 3\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],target = \"grape\",startIndex = 1) == 2\n assert candidate(words = ['repeated', 'words', 'are', 'repeated', 'here', 'repeated'],target = \"repeated\",startIndex = 2) == 1\n assert candidate(words = ['hello', 'world', 'hello', 'python', 'world'],target = \"python\",startIndex = 2) == 1\n assert candidate(words = ['leetcode', 'problem', 'solving', 'leetcode', 'problem'],target = \"solving\",startIndex = 4) == 2\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],target = \"z\",startIndex = 0) == 1\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'galaxy', 'universe'],target = \"planet\",startIndex = 0) == 3\n assert candidate(words = ['zebra', 'yak', 'xylophone', 'wolf', 'unicorn', 'tiger', 'snake'],target = \"yak\",startIndex = 6) == 2\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],target = \"seven\",startIndex = 1) == 5\n assert candidate(words = ['cat', 'dog', 'fish', 'bird', 'elephant', 'tiger', 'lion', 'bear'],target = \"fish\",startIndex = 6) == 4\n assert candidate(words = ['circular', 'array', 'example', 'circular'],target = \"example\",startIndex = 2) == 0\n assert candidate(words = ['hello', 'world', 'leetcode', 'python', 'hello'],target = \"python\",startIndex = 0) == 2\n assert candidate(words = ['car', 'bike', 'truck', 'motorcycle', 'bus', 'train', 'boat', 'plane'],target = \"plane\",startIndex = 6) == 1\n assert candidate(words = ['unique', 'words', 'here', 'only', 'once'],target = \"once\",startIndex = 2) == 2\n assert candidate(words = ['coding', 'is', 'fun', 'coding', 'is', 'great'],target = \"great\",startIndex = 3) == 2\n assert candidate(words = ['find', 'me', 'if', 'you', 'can'],target = \"can\",startIndex = 3) == 1\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],target = \"vwx\",startIndex = 5) == 2\n assert candidate(words = ['abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij'],target = \"abcdefghij\",startIndex = 5) == 1\n assert candidate(words = ['repeat', 'this', 'is', 'a', 'test', 'repeat'],target = \"test\",startIndex = 4) == 0\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],target = \"planet\",startIndex = 0) == 1\n assert candidate(words = ['sun', 'moon', 'star'],target = \"planet\",startIndex = 0) == -1\n assert candidate(words = ['sun', 'moon', 'star', 'sky'],target = \"star\",startIndex = 3) == 1\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],target = \"planet\",startIndex = 2) == 1\n assert candidate(words = ['find', 'me', 'in', 'the', 'list'],target = \"list\",startIndex = 0) == 1\n assert candidate(words = ['flower', 'grass', 'tree', 'bush'],target = \"bush\",startIndex = 2) == 1\n assert candidate(words = ['xyz', 'uvw', 'rst', 'qpo'],target = \"rst\",startIndex = 3) == 1\n assert candidate(words = ['unique', 'words', 'here'],target = \"words\",startIndex = 1) == 0\n assert candidate(words = ['aaa', 'bbb', 'ccc'],target = \"aaa\",startIndex = 1) == 1\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl'],target = \"def\",startIndex = 3) == 2\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"two\",startIndex = 4) == 2\n assert candidate(words = ['up', 'down', 'left', 'right'],target = \"up\",startIndex = 1) == 1\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'],target = \"beta\",startIndex = 3) == 2\n assert candidate(words = ['dog', 'cat', 'mouse'],target = \"elephant\",startIndex = 1) == -1\n assert candidate(words = ['foo', 'bar', 'baz'],target = \"foo\",startIndex = 1) == 1\n assert candidate(words = ['dog', 'cat', 'bat'],target = \"mouse\",startIndex = 1) == -1\n assert candidate(words = ['sun', 'moon', 'star', 'sky'],target = \"moon\",startIndex = 3) == 2\n assert candidate(words = ['coding', 'is', 'fun', 'coding'],target = \"fun\",startIndex = 1) == 1\n assert candidate(words = ['zebra', 'giraffe', 'elephant'],target = \"hippo\",startIndex = 1) == -1\n assert candidate(words = ['red', 'blue', 'green', 'red'],target = \"red\",startIndex = 3) == 0\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"three\",startIndex = 0) == 2\n assert candidate(words = ['cat', 'dog', 'bird'],target = \"dog\",startIndex = 2) == 1\n assert candidate(words = ['cup', 'bottle', 'spoon', 'knife', 'cup'],target = \"spoon\",startIndex = 4) == 2\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],target = \"elephant\",startIndex = 1) == -1\n assert candidate(words = ['unique'],target = \"unique\",startIndex = 0) == 0\n assert candidate(words = ['hello', 'world', 'hello'],target = \"world\",startIndex = 2) == 1\n assert candidate(words = ['car', 'bike', 'bus', 'train', 'boat'],target = \"plane\",startIndex = 1) == -1\n assert candidate(words = ['red', 'green', 'blue', 'yellow'],target = \"blue\",startIndex = 1) == 1\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],target = \"blue\",startIndex = 0) == 1\n assert candidate(words = ['one', 'two', 'three'],target = \"four\",startIndex = 1) == -1\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],target = \"blue\",startIndex = 2) == 1\n assert candidate(words = ['xyz', 'uvw', 'rst', 'qpo'],target = \"qpo\",startIndex = 3) == 0\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],target = \"planet\",startIndex = 1) == 2\n assert candidate(words = ['fast', 'slow', 'quick'],target = \"quick\",startIndex = 1) == 1\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl'],target = \"abc\",startIndex = 3) == 1\n assert candidate(words = ['start', 'middle', 'end'],target = \"end\",startIndex = 0) == 1\n assert candidate(words = ['sun', 'moon', 'star'],target = \"planet\",startIndex = 2) == -1\n assert candidate(words = ['loop', 'start', 'end', 'loop'],target = \"loop\",startIndex = 2) == 1\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'purple'],target = \"green\",startIndex = 4) == 2\n assert candidate(words = ['car', 'bus', 'train', 'plane'],target = \"train\",startIndex = 3) == 1\n assert candidate(words = ['red', 'green', 'blue', 'yellow', 'black'],target = \"red\",startIndex = 4) == 1\n assert candidate(words = ['house', 'car', 'tree', 'road', 'house'],target = \"road\",startIndex = 0) == 2\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"six\",startIndex = 0) == -1\n assert candidate(words = ['zebra', 'giraffe', 'elephant', 'lion'],target = \"elephant\",startIndex = 1) == 1\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"three\",startIndex = 3) == 1\n assert candidate(words = ['car', 'bus', 'train'],target = \"train\",startIndex = 2) == 0\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"one\",startIndex = 2) == 2\n assert candidate(words = ['car', 'bike', 'train', 'bus'],target = \"bike\",startIndex = 3) == 2\n assert candidate(words = ['sun', 'moon', 'star'],target = \"star\",startIndex = 1) == 1\n assert candidate(words = ['search', 'this', 'array', 'for', 'target'],target = \"target\",startIndex = 2) == 2\n assert candidate(words = ['foo', 'bar', 'baz'],target = \"foo\",startIndex = 2) == 1\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],target = \"a\",startIndex = 4) == 1\n assert candidate(words = ['start', 'middle', 'end'],target = \"start\",startIndex = 2) == 1\n assert candidate(words = ['house', 'building', 'apartment'],target = \"house\",startIndex = 1) == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"one\",startIndex = 3) == 2\n assert candidate(words = ['up', 'down', 'left', 'right'],target = \"left\",startIndex = 3) == 1\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],target = \"dog\",startIndex = 3) == 1\n assert candidate(words = ['dog', 'cat', 'bat', 'rat'],target = \"rat\",startIndex = 3) == 0\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"three\",startIndex = 3) == 1\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl'],target = \"def\",startIndex = 2) == 1\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],target = \"fish\",startIndex = 3) == 0\n assert candidate(words = ['hello', 'world', 'hello'],target = \"world\",startIndex = 0) == 1\n assert candidate(words = ['coding', 'is', 'fun'],target = \"fun\",startIndex = 2) == 0\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"five\",startIndex = 2) == -1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six'],target = \"three\",startIndex = 0) == 2\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"four\",startIndex = 0) == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"one\",startIndex = 2) == 2\n assert candidate(words = ['dog', 'cat', 'bat', 'rat'],target = \"bat\",startIndex = 3) == 1\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],target = \"moon\",startIndex = 0) == 1\n assert candidate(words = ['repeat', 'repeat', 'repeat', 'repeat'],target = \"repeat\",startIndex = 2) == 0\n assert candidate(words = ['unique', 'words', 'only', 'here'],target = \"only\",startIndex = 0) == 2\n assert candidate(words = ['dog', 'cat', 'bat'],target = \"bat\",startIndex = 1) == 1\n assert candidate(words = ['sun', 'moon', 'star', 'sky'],target = \"moon\",startIndex = 0) == 1\n assert candidate(words = ['cat', 'dog', 'bird', 'fish'],target = \"dog\",startIndex = 2) == 1\n assert candidate(words = ['sun', 'moon', 'star'],target = \"moon\",startIndex = 2) == 1\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],target = \"green\",startIndex = 0) == 2\n assert candidate(words = ['apple', 'banana', 'cherry', 'date'],target = \"banana\",startIndex = 3) == 2\n assert candidate(words = ['car', 'bike', 'train'],target = \"bus\",startIndex = 1) == -1\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'galaxy'],target = \"star\",startIndex = 3) == 1\n assert candidate(words = ['red', 'blue', 'green', 'red'],target = \"blue\",startIndex = 2) == 1\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry'],target = \"banana\",startIndex = 3) == 2\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"five\",startIndex = 0) == -1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"three\",startIndex = 0) == 2\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry'],target = \"banana\",startIndex = 2) == 1\n assert candidate(words = ['test', 'case', 'test'],target = \"test\",startIndex = 2) == 0\n assert candidate(words = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge'],target = \"qux\",startIndex = 5) == 2\n assert candidate(words = ['hello', 'hello', 'hello'],target = \"hello\",startIndex = 1) == 0\n assert candidate(words = ['a', 'a', 'a', 'a'],target = \"a\",startIndex = 2) == 0\n assert candidate(words = ['red', 'blue', 'green'],target = \"blue\",startIndex = 0) == 1\n assert candidate(words = ['left', 'right', 'up', 'down'],target = \"up\",startIndex = 1) == 1\n assert candidate(words = ['zebra', 'yak', 'antelope'],target = \"antelope\",startIndex = 1) == 1\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],target = \"d\",startIndex = 2) == 1\n assert candidate(words = ['cat', 'dog', 'elephant', 'cat'],target = \"elephant\",startIndex = 1) == 1\n assert candidate(words = ['repeat', 'repeat', 'repeat'],target = \"repeat\",startIndex = 2) == 0\n assert candidate(words = ['north', 'south', 'east', 'west'],target = \"north\",startIndex = 3) == 1\n assert candidate(words = ['zebra', 'elephant', 'tiger', 'lion', 'giraffe'],target = \"tiger\",startIndex = 4) == 2\n assert candidate(words = ['loop', 'around', 'the', 'circular', 'array'],target = \"around\",startIndex = 2) == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"six\",startIndex = 2) == -1\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],target = \"planet\",startIndex = 3) == 0\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],target = \"one\",startIndex = 4) == 1\n assert candidate(words = ['test', 'case', 'test'],target = \"test\",startIndex = 1) == 1\n assert candidate(words = ['up', 'down', 'left', 'right'],target = \"up\",startIndex = 3) == 1\n assert candidate(words = ['unique', 'words', 'only', 'here'],target = \"words\",startIndex = 3) == 2\n assert candidate(words = ['repeat', 'repeat', 'repeat'],target = \"repeat\",startIndex = 1) == 0\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta'],target = \"gamma\",startIndex = 2) == 0\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],target = \"star\",startIndex = 3) == 1\n assert candidate(words = ['left', 'right', 'up', 'down'],target = \"up\",startIndex = 3) == 1\n assert candidate(words = ['one', 'two', 'three', 'four'],target = \"four\",startIndex = 3) == 0\n assert candidate(words = ['z', 'y', 'x', 'w', 'v'],target = \"x\",startIndex = 4) == 2\n assert candidate(words = ['a', 'a', 'a', 'a', 'a'],target = \"b\",startIndex = 0) == -1\n assert candidate(words = ['red', 'green', 'blue'],target = \"blue\",startIndex = 1) == 1\n assert candidate(words = ['search', 'for', 'the', 'target'],target = \"search\",startIndex = 3) == 1\n assert candidate(words = ['car', 'bus', 'train'],target = \"train\",startIndex = 1) == 1\n assert candidate(words = ['happy', 'sad', 'mad'],target = \"mad\",startIndex = 0) == 1\n assert candidate(words = ['dog', 'cat', 'bird', 'fish', 'dog'],target = \"fish\",startIndex = 0) == 2\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno'],target = \"ghi\",startIndex = 3) == 1\n assert candidate(words = ['red', 'blue', 'green'],target = \"blue\",startIndex = 2) == 1\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'],target = \"zeta\",startIndex = 2) == -1\n assert candidate(words = ['repeat', 'repeat', 'repeat'],target = \"repeat\",startIndex = 0) == 0\n", "comparison": "exact"}, "public_tests": ["[\"hello\",\"i\",\"am\",\"leetcode\",\"hello\"]\n\"hello\"\n1", "[\"a\",\"b\",\"leetcode\"]\n\"leetcode\"\n0", "[\"i\",\"eat\",\"leetcode\"]\n\"ate\"\n0"], "hints": ["You have two options, either move straight to the left or move straight to the right.", "Find the first target word and record the distance.", "Choose the one with the minimum distance."], "metadata": {"canonical_parameter_names": ["words", "target", "startIndex"], "leetcode_dataset_entry_point": "Solution().closestTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:34+00:00", "tests_total": 247, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "string"]}, "language": "ruby", "interface": {"raw_signature": "def closest_target(words, target, start_index)", "container": null, "callable": "closest_target", "parameters": [{"name": "words", "type": "String[]"}, {"name": "target", "type": "String"}, {"name": "start_index", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2516, "task_id": "take-k-of-each-character-from-left-and-right", "difficulty": "Medium", "problem_description": "You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s.\n\nReturn the minimum number of minutes needed for you to take at least k of each character, or return -1 if it is not possible to take k of each character.\n\nExample 1:\n\nInput: s = \"aabaaaacaabc\", k = 2\nOutput: 8\nExplanation:\nTake three characters from the left of s. You now have two 'a' characters, and one 'b' character.\nTake five characters from the right of s. You now have four 'a' characters, two 'b' characters, and two 'c' characters.\nA total of 3 + 5 = 8 minutes is needed.\nIt can be proven that 8 is the minimum number of minutes needed.\n\nExample 2:\n\nInput: s = \"a\", k = 1\nOutput: -1\nExplanation: It is not possible to take one 'b' or 'c' so return -1.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of only the letters 'a', 'b', and 'c'.\n- 0 <= k <= s.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abacbacbacb\",k = 2) == 6\n assert candidate(s = \"baccbaccbacc\",k = 2) == 6\n assert candidate(s = \"abcabcabcabcabc\",k = 3) == 9\n assert candidate(s = \"aabbaacc\",k = 2) == 6\n assert candidate(s = \"abc\",k = 0) == 0\n assert candidate(s = \"abcabcabcabcabcabc\",k = 3) == 9\n assert candidate(s = \"cccbbaaaa\",k = 2) == 7\n assert candidate(s = \"abacbcabc\",k = 0) == 0\n assert candidate(s = \"ccccccc\",k = 2) == -1\n assert candidate(s = \"aabbbccc\",k = 2) == 6\n assert candidate(s = \"aaaabbbbcccc\",k = 4) == 12\n assert candidate(s = \"aabaaaacaabc\",k = 2) == 8\n assert candidate(s = \"abcabcabc\",k = 1) == 3\n assert candidate(s = \"abcabcabc\",k = 3) == 9\n assert candidate(s = \"ccccccc\",k = 3) == -1\n assert candidate(s = \"a\",k = 1) == -1\n assert candidate(s = \"cccaaaabbb\",k = 2) == 7\n assert candidate(s = \"aabbcc\",k = 1) == 4\n assert candidate(s = \"aaabbbccc\",k = 3) == 9\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 4) == 12\n assert candidate(s = \"ccccccbbbaaa\",k = 3) == 9\n assert candidate(s = \"abacbacbacb\",k = 3) == 9\n assert candidate(s = \"aabbccaaabbcc\",k = 2) == 6\n assert candidate(s = \"abacbacbacbac\",k = 2) == 6\n assert candidate(s = \"baacababacbacbacbacbacb\",k = 3) == 9\n assert candidate(s = \"ababababababcabcabc\",k = 3) == 9\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 5) == 15\n assert candidate(s = \"bababababababa\",k = 5) == -1\n assert candidate(s = \"aaaabbbbccccaaaabbbbccccaaaabbbbcccc\",k = 4) == 12\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabc\",k = 4) == 12\n assert candidate(s = \"bbbbbaaaaaccccaaaabbbbccccaaaa\",k = 5) == 18\n assert candidate(s = \"aabbbbccccaa\",k = 2) == 8\n assert candidate(s = \"abacabacabc\",k = 2) == 6\n assert candidate(s = \"aabacbacbacbac\",k = 3) == 9\n assert candidate(s = \"aabaaaabbbcccaabbcccaabbccc\",k = 3) == 9\n assert candidate(s = \"aabbbcccaaa\",k = 3) == 9\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 6) == 18\n assert candidate(s = \"ccccbbbaaaa\",k = 3) == 10\n assert candidate(s = \"bbbbbcccccc\",k = 2) == -1\n assert candidate(s = \"cccaaaabbbccc\",k = 3) == 9\n assert candidate(s = \"abcbaabcbaabcba\",k = 2) == 6\n assert candidate(s = \"aaaaaaaaaabbbbbbbbcccccccc\",k = 4) == 16\n assert candidate(s = \"abacbacbacbacbacbacbacbacb\",k = 3) == 9\n assert candidate(s = \"ccbbbaaa\",k = 2) == 6\n assert candidate(s = \"aabbccaaaabbcc\",k = 3) == 10\n assert candidate(s = \"abccbaabccba\",k = 2) == 6\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbbcccccc\",k = 5) == 16\n assert candidate(s = \"baccbaabccba\",k = 2) == 6\n assert candidate(s = \"abcabcabcabcabcabcabc\",k = 3) == 9\n assert candidate(s = \"abcabcabcabcabc\",k = 2) == 6\n assert candidate(s = \"cccccccccccccccccc\",k = 5) == -1\n assert candidate(s = \"cccccccccccaabbbbbb\",k = 3) == -1\n assert candidate(s = \"abacabacabac\",k = 3) == 11\n assert candidate(s = \"abacabaacaba\",k = 3) == -1\n assert candidate(s = \"aabbbcccbbbcccaaa\",k = 3) == 9\n assert candidate(s = \"abcabcabcabcabcabcabcabcabc\",k = 4) == 12\n assert candidate(s = \"abccbaabcbaabc\",k = 3) == 9\n assert candidate(s = \"ccccccbbbbaaa\",k = 2) == 7\n assert candidate(s = \"aaaaabbbbbcccc\",k = 1) == 6\n assert candidate(s = \"aaaaaaabbbccc\",k = 2) == 7\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 5) == 15\n assert candidate(s = \"aaabbbcccbbbcccaaaccc\",k = 4) == 14\n assert candidate(s = \"cccbbbbaaa\",k = 2) == 7\n assert candidate(s = \"aabbccabcabcabcabcabcabc\",k = 4) == 12\n assert candidate(s = \"aabaaaacaabc\",k = 5) == -1\n assert candidate(s = \"aabccbaabccbaabccba\",k = 3) == 9\n assert candidate(s = \"bbbbbbbccccaaa\",k = 2) == 7\n assert candidate(s = \"aaabbbcccaaa\",k = 2) == 8\n assert candidate(s = \"bbbaaabbbcccaaa\",k = 2) == 7\n assert candidate(s = \"abcabcabcabcabcabcabcabc\",k = 3) == 9\n assert candidate(s = \"abacbacbacbacbacbac\",k = 5) == 15\n assert candidate(s = \"aabaaabccbbccaa\",k = 3) == 10\n assert candidate(s = \"bacbacbacbacbac\",k = 4) == 12\n assert candidate(s = \"ccccaaabbb\",k = 2) == 7\n assert candidate(s = \"acbbacaabcbab\",k = 2) == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 3) == 9\n assert candidate(s = \"abababababababababcabcabcabc\",k = 4) == 12\n assert candidate(s = \"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcb\",k = 3) == -1\n assert candidate(s = \"abababababababababababababababababababababababab\",k = 5) == -1\n assert candidate(s = \"ccbaabacabcabcabcabcabcabcabcabcabcabc\",k = 4) == 12\n assert candidate(s = \"acbacbacbacbacbac\",k = 2) == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 10) == 30\n assert candidate(s = \"cccccccccccccccccccccccccccccccccccccccccccccc\",k = 15) == -1\n assert candidate(s = \"cccbaaaaabbccc\",k = 3) == 11\n assert candidate(s = \"aababababababababababababa\",k = 2) == -1\n assert candidate(s = \"aabbcccaabbcccaabbccc\",k = 5) == 16\n assert candidate(s = \"ccababacabac\",k = 2) == 6\n assert candidate(s = \"aabbaabbaabbaabbcc\",k = 4) == -1\n assert candidate(s = \"ccbacababacba\",k = 4) == 12\n assert candidate(s = \"aabaaaabbbcccaabbcccaabbccc\",k = 4) == 14\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabc\",k = 5) == 15\n assert candidate(s = \"cccccccccbaaaabbbccc\",k = 3) == 9\n assert candidate(s = \"bbaaccaabbbb\",k = 2) == 6\n assert candidate(s = \"abacbacbacbacbac\",k = 4) == 12\n assert candidate(s = \"caacbbacabcabc\",k = 2) == 6\n assert candidate(s = \"aabbccbaaabbccbaaabbcc\",k = 2) == 6\n assert candidate(s = \"cccccccccccbcccccccccc\",k = 3) == -1\n assert candidate(s = \"aabbcc\",k = 0) == 0\n assert candidate(s = \"cabcabcabcabcabcabcabcabcabcabcabc\",k = 5) == 15\n assert candidate(s = \"aabcaabcbaabcbaabcba\",k = 4) == 16\n assert candidate(s = \"ccccccbbbaaaaaaacccccccbbbaaaaaa\",k = 4) == 16\n assert candidate(s = \"abacabadabacaba\",k = 3) == -1\n assert candidate(s = \"bcccccccccccba\",k = 3) == -1\n assert candidate(s = \"aaabbbccc\",k = 0) == 0\n assert candidate(s = \"bcbcbcbcbcbc\",k = 2) == -1\n assert candidate(s = \"abcabcabcabcabcabc\",k = 2) == 6\n assert candidate(s = \"bacbacbacbacbacbacbacbacbacbacbacbac\",k = 4) == 12\n assert candidate(s = \"cccccccccccccccccccccccccc\",k = 10) == -1\n assert candidate(s = \"aabbbcccddd\",k = 1) == 7\n assert candidate(s = \"ccbaabccbaabccba\",k = 3) == 9\n assert candidate(s = \"ababababababababababababababababababababababababab\",k = 6) == -1\n assert candidate(s = \"ccccccaaaabbbb\",k = 2) == 8\n assert candidate(s = \"ccccbbbbaaaaccccbbaaaccccbbaa\",k = 4) == 12\n assert candidate(s = \"aabaaaacaabc\",k = 3) == -1\n assert candidate(s = \"bbbbbbbaaaaaaaccccccc\",k = 3) == 13\n assert candidate(s = \"cacacacacacaca\",k = 2) == -1\n assert candidate(s = \"bbacccbaaa\",k = 2) == 6\n assert candidate(s = \"bbbaaacccbbbaaacccbbbaaacccbbbaaaccc\",k = 3) == 9\n assert candidate(s = \"aabaaaacaabcbbbccc\",k = 3) == 9\n assert candidate(s = \"abcabcabcabcabcabcabc\",k = 4) == 12\n assert candidate(s = \"aabccccbaa\",k = 1) == 4\n assert candidate(s = \"aaaaabbbbbccccc\",k = 2) == 9\n assert candidate(s = \"abacabadabacabadabacabad\",k = 4) == -1\n assert candidate(s = \"ccccbbbaaa\",k = 2) == 7\n assert candidate(s = \"aaaaaaaaaaa\",k = 1) == -1\n assert candidate(s = \"abacabacabacabacabacabacabacabacabacabac\",k = 5) == 19\n assert candidate(s = \"aabbcc\",k = 2) == 6\n assert candidate(s = \"aabcaaacbbacabcabc\",k = 4) == 12\n", "comparison": "exact"}, "public_tests": ["\"aabaaaacaabc\"\n2", "\"a\"\n1"], "hints": ["Start by counting the frequency of each character and checking if it is possible.", "If you take x characters from the left side, what is the minimum number of characters you need to take from the right side? Find this for all values of x in the range 0 ≤ x ≤ s.length.", "Use a two-pointers approach to avoid computing the same information multiple times."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().takeCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:37+00:00", "tests_total": 129, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def take_characters(s, k)", "container": null, "callable": "take_characters", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2517, "task_id": "maximum-tastiness-of-candy-basket", "difficulty": "Medium", "problem_description": "You are given an array of positive integers price where price[i] denotes the price of the i^th candy and a positive integer k.\n\nThe store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket.\n\nReturn the maximum tastiness of a candy basket.\n\nExample 1:\n\nInput: price = [13,5,1,8,21,2], k = 3\nOutput: 8\nExplanation: Choose the candies with the prices [13,5,21].\nThe tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.\nIt can be proven that 8 is the maximum tastiness that can be achieved.\n\nExample 2:\n\nInput: price = [1,3,1], k = 2\nOutput: 2\nExplanation: Choose the candies with the prices [1,3].\nThe tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.\nIt can be proven that 2 is the maximum tastiness that can be achieved.\n\nExample 3:\n\nInput: price = [7,7,7,7], k = 2\nOutput: 0\nExplanation: Choosing any two distinct candies from the candies we have will result in a tastiness of 0.\n\nConstraints:\n\n- 2 <= k <= price.length <= 10^5\n- 1 <= price[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(price = [1000000000, 1, 2, 3, 4, 5],k = 3) == 4\n assert candidate(price = [1000000000, 1, 1000000000, 1, 1000000000],k = 3) == 0\n assert candidate(price = [10, 20, 30, 40, 50],k = 3) == 20\n assert candidate(price = [13, 5, 1, 8, 21, 2],k = 3) == 8\n assert candidate(price = [1, 1000000000, 2, 999999999],k = 2) == 999999999\n assert candidate(price = [7, 7, 7, 7],k = 2) == 0\n assert candidate(price = [50, 50, 50, 50, 50, 50],k = 2) == 0\n assert candidate(price = [1, 3, 1],k = 2) == 2\n assert candidate(price = [10, 20, 30, 40, 50],k = 4) == 10\n assert candidate(price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 2\n assert candidate(price = [100000000, 100000001, 100000002, 100000003, 100000004, 100000005, 100000006, 100000007, 100000008, 100000009],k = 5) == 2\n assert candidate(price = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 2) == 0\n assert candidate(price = [500, 400, 300, 200, 100, 90, 80, 70, 60, 50],k = 3) == 200\n assert candidate(price = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 0\n assert candidate(price = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7) == 20\n assert candidate(price = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 5) == 6\n assert candidate(price = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 6) == 100\n assert candidate(price = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],k = 6) == 18\n assert candidate(price = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 10) == 2\n assert candidate(price = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3) == 2\n assert candidate(price = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997],k = 5) == 1\n assert candidate(price = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],k = 9) == 20\n assert candidate(price = [100, 102, 105, 108, 110, 120, 130, 140, 150],k = 4) == 10\n assert candidate(price = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 6) == 63\n assert candidate(price = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946],k = 6) == 987\n assert candidate(price = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117],k = 10) == 12\n assert candidate(price = [500000000, 400000000, 300000000, 200000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1],k = 4) == 100000000\n assert candidate(price = [1000000000, 1, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10],k = 5) == 999999\n assert candidate(price = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],k = 6) == 30\n assert candidate(price = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],k = 8) == 6\n assert candidate(price = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],k = 5) == 2\n assert candidate(price = [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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 6) == 1\n assert candidate(price = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],k = 5) == 2\n assert candidate(price = [987654321, 987654322, 987654323, 987654324, 987654325, 987654326, 987654327, 987654328, 987654329, 987654330],k = 7) == 1\n assert candidate(price = [1, 1000000000, 2, 999999999, 3, 999999998],k = 3) == 2\n assert candidate(price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 20\n assert candidate(price = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 2) == 1\n assert candidate(price = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 4\n assert candidate(price = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 10) == 4\n assert candidate(price = [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],k = 6) == 1\n assert candidate(price = [999999999, 1, 1000000000, 2, 999999998, 3],k = 3) == 2\n assert candidate(price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 10\n assert candidate(price = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],k = 7) == 12\n assert candidate(price = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75],k = 12) == 6\n assert candidate(price = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],k = 5) == 2\n assert candidate(price = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 10) == 4\n assert candidate(price = [500000000, 500000001, 500000002, 500000003, 500000004, 500000005, 500000006, 500000007, 500000008, 500000009],k = 3) == 4\n assert candidate(price = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 4) == 1\n assert candidate(price = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 5) == 999999\n assert candidate(price = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80],k = 20) == 1\n assert candidate(price = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 8) == 200\n assert candidate(price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 1\n assert candidate(price = [1000000000, 1, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1],k = 6) == 99999\n assert candidate(price = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10) == 20\n assert candidate(price = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300],k = 8) == 40\n assert candidate(price = [1000000000, 900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000],k = 5) == 200000000\n assert candidate(price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 12) == 10\n assert candidate(price = [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 = 15) == 2\n assert candidate(price = [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(price = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 7) == 15\n assert candidate(price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 2\n assert candidate(price = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 2\n assert candidate(price = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],k = 5) == 2\n assert candidate(price = [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],k = 5) == 2\n assert candidate(price = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 1000000000],k = 5) == 200000000\n assert candidate(price = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 1\n assert candidate(price = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 5) == 999999\n assert candidate(price = [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],k = 15) == 4\n assert candidate(price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 2\n assert candidate(price = [5, 8, 12, 17, 22, 28, 33, 39, 44, 50],k = 5) == 11\n assert candidate(price = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000],k = 15) == 200\n assert candidate(price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 2\n assert candidate(price = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],k = 2) == 1\n assert candidate(price = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 10) == 2047\n assert candidate(price = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],k = 10) == 8\n assert candidate(price = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6],k = 4) == 1\n assert candidate(price = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 15) == 2\n assert candidate(price = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 7) == 100\n assert candidate(price = [524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 5) == 65535\n", "comparison": "exact"}, "public_tests": ["[13,5,1,8,21,2]\n3", "[1,3,1]\n2", "[7,7,7,7]\n2"], "hints": ["The answer is binary searchable.", "For some x, we can use a greedy strategy to check if it is possible to pick k distinct candies with tastiness being at least x.", "Sort prices and iterate from left to right. For some price[i] check if the price difference between the last taken candy and price[i] is at least x. If so, add the candy i to the basket.", "So, a candy basket with tastiness x can be achieved if the basket size is bigger than or equal to k."], "metadata": {"canonical_parameter_names": ["price", "k"], "leetcode_dataset_entry_point": "Solution().maximumTastiness", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:39+00:00", "tests_total": 81, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_tastiness(price, k)", "container": null, "callable": "maximum_tastiness", "parameters": [{"name": "price", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2518, "task_id": "number-of-great-partitions", "difficulty": "Hard", "problem_description": "You are given an array nums consisting of positive integers and an integer k.\n\nPartition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.\n\nReturn the number of distinct great partitions. Since the answer may be too large, return it modulo 10^9 + 7.\n\nTwo partitions are considered distinct if some element nums[i] is in different groups in the two partitions.\n\nExample 1:\n\nInput: nums = [1,2,3,4], k = 4\nOutput: 6\nExplanation: The great partitions are: ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) and ([4], [1,2,3]).\n\nExample 2:\n\nInput: nums = [3,3,3], k = 4\nOutput: 0\nExplanation: There are no great partitions for this array.\n\nExample 3:\n\nInput: nums = [6,6], k = 2\nOutput: 2\nExplanation: We can either put nums[0] in the first partition or in the second partition.\nThe great partitions will be ([6], [6]) and ([6], [6]).\n\nConstraints:\n\n- 1 <= nums.length, k <= 1000\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40],k = 50) == 2\n assert candidate(nums = [1, 1, 1, 1],k = 2) == 6\n assert candidate(nums = [2, 4, 6, 8, 10],k = 11) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 25) == 252\n assert candidate(nums = [6, 6],k = 2) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],k = 600) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 826\n assert candidate(nums = [3, 3, 3],k = 4) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 252\n assert candidate(nums = [1000, 1000, 1000],k = 1) == 6\n assert candidate(nums = [5, 5, 5, 5, 5],k = 10) == 20\n assert candidate(nums = [1, 3, 5, 7, 9],k = 15) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 15) == 20\n assert candidate(nums = [1, 2, 3, 4],k = 4) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 1039850\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 = 20) == 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],k = 5) == 1036184\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 150) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 300) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],k = 200) == 259246959\n assert candidate(nums = [100, 200, 300, 400, 500],k = 700) == 6\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 = 2) == 1048534\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],k = 1000) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 750) == 774794\n assert candidate(nums = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500],k = 1000) == 1048534\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 45) == 252\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 100) == 166910\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 = 10) == 184756\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) == 1036184\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],k = 2) == 67049447\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 100) == 17728\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 50) == 786\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 900) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 400) == 682822\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 519388\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 500) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 450) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 50) == 63526\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 252\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) == 73677955\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 = 50) == 73688469\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 35) == 252\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 = 100) == 68359565\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 150) == 826\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 25) == 236\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 150) == 826\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 = 200) == 533906260\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 826\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 100) == 996110\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 582\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 200) == 7930\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 = 21) == 1047834\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 250) == 236\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 40) == 31912\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],k = 50) == 33505686\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 50) == 28886\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 30) == 0\n assert candidate(nums = [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],k = 300) == 9026504\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 = 20) == 1047962\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 1000) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 10) == 146086846\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41],k = 200) == 295936\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 800) == 0\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 = 500) == 184756\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 100) == 1010582\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 700) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 1000) == 0\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],k = 25) == 73677955\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 1000) == 166910\n assert candidate(nums = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],k = 1000) == 582\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n4", "[3,3,3]\n4", "[6,6]\n2"], "hints": ["If the sum of the array is smaller than 2*k, then it is impossible to find a great partition.", "Solve the reverse problem, that is, find the number of partitions where the sum of elements of at least one of the two groups is smaller than k."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countPartitions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:41+00:00", "tests_total": 101, "tests_dropped": 30, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def count_partitions(nums, k)", "container": null, "callable": "count_partitions", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2520, "task_id": "count-the-digits-that-divide-a-number", "difficulty": "Easy", "problem_description": "Given an integer num, return the number of digits in num that divide num.\n\nAn integer val divides nums if nums % val == 0.\n\nExample 1:\n\nInput: num = 7\nOutput: 1\nExplanation: 7 divides itself, hence the answer is 1.\n\nExample 2:\n\nInput: num = 121\nOutput: 2\nExplanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.\n\nExample 3:\n\nInput: num = 1248\nOutput: 4\nExplanation: 1248 is divisible by all of its digits, hence the answer is 4.\n\nConstraints:\n\n- 1 <= num <= 10^9\n- num does not contain 0 as one of its digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 111111111) == 9\n assert candidate(num = 666) == 3\n assert candidate(num = 999) == 3\n assert candidate(num = 222) == 3\n assert candidate(num = 1122) == 4\n assert candidate(num = 123456789) == 3\n assert candidate(num = 4488) == 4\n assert candidate(num = 444) == 3\n assert candidate(num = 555) == 3\n assert candidate(num = 1248) == 4\n assert candidate(num = 13579) == 1\n assert candidate(num = 888) == 3\n assert candidate(num = 333) == 3\n assert candidate(num = 2222) == 4\n assert candidate(num = 987654321) == 3\n assert candidate(num = 7) == 1\n assert candidate(num = 1111) == 4\n assert candidate(num = 121) == 2\n assert candidate(num = 111) == 3\n assert candidate(num = 777) == 3\n assert candidate(num = 2244) == 4\n assert candidate(num = 357) == 2\n assert candidate(num = 3366) == 4\n assert candidate(num = 222222222) == 9\n assert candidate(num = 369125874) == 5\n assert candidate(num = 555666777) == 0\n assert candidate(num = 555555555) == 9\n assert candidate(num = 888888888) == 9\n assert candidate(num = 975318642) == 5\n assert candidate(num = 32481632) == 5\n assert candidate(num = 889977) == 0\n assert candidate(num = 777777777) == 9\n assert candidate(num = 199919991) == 3\n assert candidate(num = 111222333) == 6\n assert candidate(num = 666666666) == 9\n assert candidate(num = 135792468) == 7\n assert candidate(num = 222444666) == 6\n assert candidate(num = 333333333) == 9\n assert candidate(num = 595959) == 0\n assert candidate(num = 1352468) == 3\n assert candidate(num = 272727272) == 5\n assert candidate(num = 135791357) == 2\n assert candidate(num = 363636363) == 5\n assert candidate(num = 31313) == 2\n assert candidate(num = 333666999) == 6\n assert candidate(num = 7654321) == 1\n assert candidate(num = 82436) == 2\n assert candidate(num = 135) == 3\n assert candidate(num = 488848884) == 3\n assert candidate(num = 363636) == 6\n assert candidate(num = 478915) == 2\n assert candidate(num = 246813579) == 3\n assert candidate(num = 24682468) == 4\n assert candidate(num = 864213579) == 3\n assert candidate(num = 333999) == 6\n assert candidate(num = 369258147) == 3\n assert candidate(num = 899999999) == 0\n assert candidate(num = 29876) == 2\n assert candidate(num = 468297351) == 3\n assert candidate(num = 56324) == 2\n assert candidate(num = 199199199) == 3\n assert candidate(num = 975319753) == 1\n assert candidate(num = 112233) == 4\n", "comparison": "exact"}, "public_tests": ["7", "121", "1248"], "hints": ["Use mod by 10 to retrieve the least significant digit of the number", "Divide the number by 10, then round it down so that the second least significant digit becomes the least significant digit of the number", "Use your language’s mod operator to see if a number is a divisor of another."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().countDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:46+00:00", "tests_total": 73, "tests_dropped": 10, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def count_digits(num)", "container": null, "callable": "count_digits", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2521, "task_id": "distinct-prime-factors-of-product-of-array", "difficulty": "Medium", "problem_description": "Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.\n\nNote that:\n\n- A number greater than 1 is called prime if it is divisible by only 1 and itself.\n- An integer val1 is a factor of another integer val2 if val2 / val1 is an integer.\n\nExample 1:\n\nInput: nums = [2,4,3,7,10,6]\nOutput: 4\nExplanation:\nThe product of all the elements in nums is: 2 * 4 * 3 * 7 * 10 * 6 = 10080 = 2^5 * 3^2 * 5 * 7.\nThere are 4 distinct prime factors so we return 4.\n\nExample 2:\n\nInput: nums = [2,4,8,16]\nOutput: 1\nExplanation:\nThe product of all the elements in nums is: 2 * 4 * 8 * 16 = 1024 = 2^10.\nThere is 1 distinct prime factor so we return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 10^4\n- 2 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 200, 300, 400]) == 3\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [1000, 500, 250, 125]) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 6\n assert candidate(nums = [60, 120, 180, 240, 300]) == 3\n assert candidate(nums = [31, 37, 41, 43, 47, 53]) == 6\n assert candidate(nums = [2, 4, 3, 7, 10, 6]) == 4\n assert candidate(nums = [29, 31, 37, 41]) == 4\n assert candidate(nums = [1000, 500, 250, 125]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50]) == 3\n assert candidate(nums = [100, 200, 300]) == 3\n assert candidate(nums = [2, 4, 8, 16]) == 1\n assert candidate(nums = [997, 991, 983, 977, 971]) == 5\n assert candidate(nums = [3, 5, 7, 11, 13]) == 5\n assert candidate(nums = [60, 120, 180, 240]) == 3\n assert candidate(nums = [49, 49, 49, 49]) == 1\n assert candidate(nums = [999, 1000]) == 4\n assert candidate(nums = [7, 14, 21, 28, 35]) == 4\n assert candidate(nums = [31, 31, 31, 31, 31]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 10\n assert candidate(nums = [5, 10, 15, 20]) == 3\n assert candidate(nums = [3, 9, 27, 81]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [61, 67, 71, 73, 79, 83, 89, 97]) == 8\n assert candidate(nums = [15, 21, 27, 33, 39]) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 4\n assert candidate(nums = [17, 19, 23, 29, 31, 37, 41]) == 7\n assert candidate(nums = [111, 222, 333, 444, 555]) == 4\n assert candidate(nums = [15, 21, 35, 55, 77, 105]) == 4\n assert candidate(nums = [221, 247, 299, 323, 377, 413]) == 7\n assert candidate(nums = [29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 1\n assert candidate(nums = [84, 90, 120, 140, 182]) == 5\n assert candidate(nums = [50, 75, 100, 125, 150]) == 3\n assert candidate(nums = [60, 105, 140, 210, 231]) == 5\n assert candidate(nums = [101, 103, 107, 109, 113, 127]) == 6\n assert candidate(nums = [210, 154, 90]) == 5\n assert candidate(nums = [29, 31, 37, 41, 43]) == 5\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73]) == 20\n assert candidate(nums = [19, 23, 29, 31, 37, 41, 43, 47]) == 8\n assert candidate(nums = [36, 45, 60, 72, 84, 90]) == 4\n assert candidate(nums = [121, 143, 169, 187, 221]) == 3\n assert candidate(nums = [100, 200, 300, 400, 500]) == 3\n assert candidate(nums = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == 9\n assert candidate(nums = [121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 8\n assert candidate(nums = [60, 84, 90, 120, 180, 240]) == 4\n assert candidate(nums = [30, 45, 60, 75, 90]) == 3\n assert candidate(nums = [29, 31, 37, 41, 43, 47]) == 6\n assert candidate(nums = [98, 112, 147, 196, 294]) == 3\n assert candidate(nums = [961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975]) == 19\n assert candidate(nums = [231, 308, 396, 462]) == 4\n assert candidate(nums = [987, 654, 321, 876, 543, 210]) == 9\n assert candidate(nums = [8, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102]) == 7\n assert candidate(nums = [49, 64, 81, 100, 121, 144, 169, 196, 225]) == 6\n assert candidate(nums = [17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == 10\n assert candidate(nums = [30, 42, 60, 70, 105]) == 4\n assert candidate(nums = [19, 31, 37, 41, 43, 47, 53, 59]) == 8\n assert candidate(nums = [25, 49, 121, 169, 289, 361]) == 6\n assert candidate(nums = [729, 512, 343, 243, 125]) == 4\n assert candidate(nums = [15, 21, 33, 55, 77]) == 4\n assert candidate(nums = [997, 991, 983, 977, 971, 967, 953, 947, 941, 937]) == 10\n assert candidate(nums = [1000, 500, 250, 125, 62, 31]) == 3\n assert candidate(nums = [171, 195, 221, 255, 285, 323]) == 5\n assert candidate(nums = [18, 30, 45, 60, 75]) == 3\n assert candidate(nums = [81, 125, 243, 343, 625]) == 3\n assert candidate(nums = [37, 41, 43, 47, 53, 59, 61, 67, 71, 73]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == 3\n assert candidate(nums = [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]) == 25\n assert candidate(nums = [210, 231, 273, 308, 330, 364]) == 6\n assert candidate(nums = [60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 8\n assert candidate(nums = [60, 105, 140, 210, 300]) == 4\n assert candidate(nums = [97, 101, 103, 107, 109, 113]) == 6\n assert candidate(nums = [83, 89, 97, 101, 103, 107, 109, 113, 127, 131]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700]) == 4\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31]) == 8\n assert candidate(nums = [97, 98, 99, 100, 101]) == 7\n assert candidate(nums = [89, 107, 127, 137, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229]) == 20\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 5\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 5, 5, 5, 7, 7, 7, 11, 11, 11]) == 5\n assert candidate(nums = [60, 84, 90, 120, 210]) == 4\n assert candidate(nums = [13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 10\n assert candidate(nums = [49, 64, 81, 100, 121, 144]) == 5\n assert candidate(nums = [997, 991, 983, 977, 971]) == 5\n assert candidate(nums = [12, 15, 21, 28, 45]) == 4\n", "comparison": "exact"}, "public_tests": ["[2,4,3,7,10,6]", "[2,4,8,16]"], "hints": ["Do not multiply all the numbers together, as the product is too big to store.", "Think about how each individual number's prime factors contribute to the prime factors of the product of the entire array.", "Find the prime factors of each element in nums, and store all of them in a set to avoid duplicates."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().distinctPrimeFactors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:48+00:00", "tests_total": 115, "tests_dropped": 32, "flags": [], "topic_tags": ["array", "hash-table", "math", "number-theory", "prime-factorization", "euclidean-algorithm", "primality-test", "greatest-common-divisor", "sieve-theory", "prime-number-sieve"]}, "language": "ruby", "interface": {"raw_signature": "def distinct_prime_factors(nums)", "container": null, "callable": "distinct_prime_factors", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2522, "task_id": "partition-string-into-substrings-with-values-at-most-k", "difficulty": "Medium", "problem_description": "You are given a string s consisting of digits from 1 to 9 and an integer k.\n\nA partition of a string s is called good if:\n\n- Each digit of s is part of exactly one substring.\n- The value of each substring is less than or equal to k.\n\nReturn the minimum number of substrings in a good partition of s. If no good partition of s exists, return -1.\n\nNote that:\n\n- The value of a string is its result when interpreted as an integer. For example, the value of \"123\" is 123 and the value of \"1\" is 1.\n- A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"165462\", k = 60\nOutput: 4\nExplanation: We can partition the string into substrings \"16\", \"54\", \"6\", and \"2\". Each substring has a value less than or equal to k = 60.\nIt can be shown that we cannot partition the string into less than 4 substrings.\n\nExample 2:\n\nInput: s = \"238182\", k = 5\nOutput: -1\nExplanation: There is no good partition for this string.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s[i] is a digit from '1' to '9'.\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"473289651\",k = 10) == 9\n assert candidate(s = \"2222222222222222222\",k = 2) == 19\n assert candidate(s = \"987654321\",k = 10) == 9\n assert candidate(s = \"999\",k = 1000) == 1\n assert candidate(s = \"999999999\",k = 999999999) == 1\n assert candidate(s = \"999999999\",k = 1000) == 3\n assert candidate(s = \"47328165\",k = 100) == 4\n assert candidate(s = \"99999\",k = 100000) == 1\n assert candidate(s = \"1\",k = 1) == 1\n assert candidate(s = \"1111111111\",k = 1) == 10\n assert candidate(s = \"987654321\",k = 987654321) == 1\n assert candidate(s = \"123456789\",k = 9) == 9\n assert candidate(s = \"9\",k = 8) == -1\n assert candidate(s = \"823847291\",k = 823) == 4\n assert candidate(s = \"456\",k = 100) == 2\n assert candidate(s = \"555555555\",k = 55) == 5\n assert candidate(s = \"111111111\",k = 1) == 9\n assert candidate(s = \"987654321\",k = 50) == 7\n assert candidate(s = \"238182\",k = 5) == -1\n assert candidate(s = \"123\",k = 3) == 3\n assert candidate(s = \"165462\",k = 60) == 4\n assert candidate(s = \"123456789101112131415\",k = 1000) == 7\n assert candidate(s = \"88888888888888888888\",k = 888) == 7\n assert candidate(s = \"11111111111111111111\",k = 11) == 10\n assert candidate(s = \"8888888888888888888888888888888888\",k = 1000) == 12\n assert candidate(s = \"1234567891011121314151617181920\",k = 10) == 30\n assert candidate(s = \"123456789\",k = 987654321) == 1\n assert candidate(s = \"1919191919191919191919191919191919191919191919\",k = 19) == 23\n assert candidate(s = \"987654321\",k = 250) == 5\n assert candidate(s = \"123456789987654321\",k = 9999) == 5\n assert candidate(s = \"5678956789567895678956789\",k = 10000) == 7\n assert candidate(s = \"12345678901234567890123456789012345678901234567890\",k = 123456789) == 6\n assert candidate(s = \"9999999999999999999\",k = 1000000000) == 3\n assert candidate(s = \"1212121212121212121\",k = 12) == 10\n assert candidate(s = \"123123123123123123123123123123123123123123123123\",k = 123) == 16\n assert candidate(s = \"876543219876543219\",k = 50000) == 4\n assert candidate(s = \"5555555555555555555555555555555\",k = 555) == 11\n assert candidate(s = \"9999999999999999999\",k = 999999999) == 3\n assert candidate(s = \"1\",k = 9) == 1\n assert candidate(s = \"77777777777777777777777777777777777777777777\",k = 777777) == 8\n assert candidate(s = \"9999999999999999999\",k = 10) == 19\n assert candidate(s = \"135792468\",k = 100) == 5\n assert candidate(s = \"987654321123456789987654321\",k = 98765) == 6\n assert candidate(s = \"99999999999999999999999999999999999999999999\",k = 999999999) == 5\n assert candidate(s = \"33333333333333333333333333333333333333333333\",k = 333) == 15\n assert candidate(s = \"102030405060708090\",k = 100) == 9\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",k = 10) == 99\n assert candidate(s = \"123456789987654321\",k = 123456789) == 3\n assert candidate(s = \"987654321\",k = 987654320) == 2\n assert candidate(s = \"123456789123456789123456789\",k = 123456789) == 3\n assert candidate(s = \"7777777777777777777\",k = 50) == 19\n assert candidate(s = \"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\",k = 999999999) == 12\n assert candidate(s = \"246813579\",k = 1000) == 3\n assert candidate(s = \"19191919191919191919\",k = 19) == 10\n assert candidate(s = \"3333333333333333333\",k = 33333) == 4\n assert candidate(s = \"3333333333333333333\",k = 333) == 7\n assert candidate(s = \"55555555555555555555555555555555555555555555\",k = 55555) == 9\n assert candidate(s = \"3333333333333333333333333333333333\",k = 33) == 17\n assert candidate(s = \"321321321321321321321\",k = 321) == 7\n assert candidate(s = \"111222333444555666777888999\",k = 333) == 12\n assert candidate(s = \"1357924680135792468\",k = 1000) == 6\n assert candidate(s = \"1234567891011121314151617181920\",k = 1) == -1\n assert candidate(s = \"1111111111111111111111111111111111111111111111\",k = 1) == 46\n assert candidate(s = \"87654321\",k = 543) == 4\n assert candidate(s = \"987654321\",k = 100) == 5\n assert candidate(s = \"505050505050505050505050505050505050505050505050\",k = 505) == 13\n assert candidate(s = \"91827364510987654321\",k = 1000) == 7\n assert candidate(s = \"123456789123456789123456789123456789123456789\",k = 123456789) == 5\n assert candidate(s = \"1234567890123456789\",k = 123456789) == 2\n assert candidate(s = \"88888888888888888888888888888888888888888888\",k = 88888888) == 6\n assert candidate(s = \"99999999999999999999\",k = 10) == 20\n assert candidate(s = \"135792468\",k = 10) == 9\n assert candidate(s = \"1111111111111111111\",k = 1) == 19\n assert candidate(s = \"111111111111111111111111111111111111111111111111\",k = 1) == 48\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",k = 111) == 33\n assert candidate(s = \"1234567890987654321\",k = 12345) == 5\n assert candidate(s = \"9999999999999999999\",k = 1000) == 7\n assert candidate(s = \"1231231231231231231\",k = 123123) == 4\n assert candidate(s = \"1919191919191919191919191919191919191919191919\",k = 20) == 23\n assert candidate(s = \"99999999999999999999\",k = 999999999) == 3\n assert candidate(s = \"1010101010101010101\",k = 101) == 5\n assert candidate(s = \"987654321987654321987654321987654321987654321\",k = 987654321) == 5\n assert candidate(s = \"98765432109876543210987654321098765432109876543210\",k = 987654321) == 6\n assert candidate(s = \"9283746554321\",k = 10000) == 4\n assert candidate(s = \"123456789\",k = 123456789) == 1\n assert candidate(s = \"99999999999999999999999999999999999999999999999\",k = 999999999) == 6\n assert candidate(s = \"1234567891011121314151617181920\",k = 150) == 14\n assert candidate(s = \"987654321\",k = 500) == 4\n assert candidate(s = \"55555555555555555555555555555555555555555555555\",k = 60) == 24\n assert candidate(s = \"123456789\",k = 8) == -1\n assert candidate(s = \"987654321\",k = 999999999) == 1\n assert candidate(s = \"1999999999999999999999999999999999\",k = 1000000000) == 4\n assert candidate(s = \"1234567891011121314151617181920\",k = 100) == 15\n assert candidate(s = \"77777777777777777777777777777777777777777777777\",k = 77) == 24\n assert candidate(s = \"123456789\",k = 89) == 5\n assert candidate(s = \"3333333333333333333\",k = 33) == 10\n assert candidate(s = \"123456789\",k = 5) == -1\n assert candidate(s = \"8888888888888888888\",k = 9) == 19\n assert candidate(s = \"123456789123456789\",k = 1000000000) == 2\n assert candidate(s = \"11111111111111111111111111111111111111111111\",k = 111111111) == 5\n assert candidate(s = \"246813579\",k = 250) == 4\n assert candidate(s = \"123456789101112131415\",k = 100) == 10\n assert candidate(s = \"98765432187654321\",k = 1000) == 6\n assert candidate(s = \"1234567891011121314151617181920\",k = 99) == 15\n assert candidate(s = \"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555\",k = 555) == 33\n assert candidate(s = \"54321\",k = 5) == 5\n assert candidate(s = \"543215432154321\",k = 543) == 5\n assert candidate(s = \"9876543210987654321\",k = 100000) == 4\n assert candidate(s = \"112233445566778899112233445566778899112233\",k = 112233) == 8\n", "comparison": "exact"}, "public_tests": ["\"165462\"\n60", "\"238182\"\n5"], "hints": [], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().minimumPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:50+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_partition(s, k)", "container": null, "callable": "minimum_partition", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2523, "task_id": "closest-prime-numbers-in-range", "difficulty": "Medium", "problem_description": "Given two positive integers left and right, find the two integers num1 and num2 such that:\n\n- left <= num1 < num2 <= right .\n- Both num1 and num2 are prime numbers.\n- num2 - num1 is the minimum amongst all other pairs satisfying the above conditions.\n\nReturn the positive integer array ans = [num1, num2]. If there are multiple pairs satisfying these conditions, return the one with the smallest num1 value. If no such numbers exist, return [-1, -1].\n\nExample 1:\n\nInput: left = 10, right = 19\nOutput: [11,13]\nExplanation: The prime numbers between 10 and 19 are 11, 13, 17, and 19.\nThe closest gap between any pair is 2, which can be achieved by [11,13] or [17,19].\nSince 11 is smaller than 17, we return the first pair.\n\nExample 2:\n\nInput: left = 4, right = 6\nOutput: [-1,-1]\nExplanation: There exists only one prime number in the given range, so the conditions cannot be satisfied.\n\nConstraints:\n\n- 1 <= left <= right <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(left = 500,right = 550) == [521, 523]\n assert candidate(left = 1000,right = 1100) == [1019, 1021]\n assert candidate(left = 10000,right = 10020) == [10007, 10009]\n assert candidate(left = 1000,right = 1010) == [-1, -1]\n assert candidate(left = 999983,right = 999999) == [-1, -1]\n assert candidate(left = 20,right = 30) == [23, 29]\n assert candidate(left = 100,right = 110) == [101, 103]\n assert candidate(left = 500,right = 600) == [521, 523]\n assert candidate(left = 1,right = 10) == [2, 3]\n assert candidate(left = 7,right = 11) == [7, 11]\n assert candidate(left = 500,right = 520) == [503, 509]\n assert candidate(left = 30,right = 50) == [41, 43]\n assert candidate(left = 5000,right = 6000) == [5009, 5011]\n assert candidate(left = 100000,right = 100010) == [-1, -1]\n assert candidate(left = 500,right = 510) == [503, 509]\n assert candidate(left = 1000,right = 1020) == [1009, 1013]\n assert candidate(left = 100000,right = 100020) == [100003, 100019]\n assert candidate(left = 500000,right = 500010) == [-1, -1]\n assert candidate(left = 999950,right = 1000000) == [999959, 999961]\n assert candidate(left = 10000,right = 10010) == [10007, 10009]\n assert candidate(left = 4,right = 6) == [-1, -1]\n assert candidate(left = 104743,right = 104759) == [104743, 104759]\n assert candidate(left = 1,right = 1) == [-1, -1]\n assert candidate(left = 999900,right = 1000000) == [999959, 999961]\n assert candidate(left = 10,right = 19) == [11, 13]\n assert candidate(left = 5000,right = 5500) == [5009, 5011]\n assert candidate(left = 100000,right = 100100) == [100043, 100049]\n assert candidate(left = 999990,right = 1000000) == [-1, -1]\n assert candidate(left = 100000,right = 100001) == [-1, -1]\n assert candidate(left = 800000,right = 810000) == [800117, 800119]\n assert candidate(left = 500000,right = 510000) == [500111, 500113]\n assert candidate(left = 200000,right = 210000) == [200381, 200383]\n assert candidate(left = 1,right = 29) == [2, 3]\n assert candidate(left = 5000,right = 5010) == [5003, 5009]\n assert candidate(left = 300000,right = 310000) == [300149, 300151]\n assert candidate(left = 104740,right = 104760) == [104743, 104759]\n assert candidate(left = 100000,right = 100050) == [100043, 100049]\n assert candidate(left = 140000,right = 150000) == [140069, 140071]\n assert candidate(left = 800,right = 850) == [809, 811]\n assert candidate(left = 541,right = 547) == [541, 547]\n assert candidate(left = 1487,right = 1600) == [1487, 1489]\n assert candidate(left = 700000,right = 700100) == [700079, 700081]\n assert candidate(left = 100,right = 200) == [101, 103]\n assert candidate(left = 50000,right = 50100) == [50021, 50023]\n assert candidate(left = 999000,right = 999100) == [999023, 999029]\n assert candidate(left = 200000,right = 200100) == [200029, 200033]\n assert candidate(left = 999983,right = 999983) == [-1, -1]\n assert candidate(left = 300000,right = 300050) == [300017, 300023]\n assert candidate(left = 100000,right = 101000) == [100151, 100153]\n assert candidate(left = 50000,right = 51000) == [50021, 50023]\n assert candidate(left = 600000,right = 600010) == [-1, -1]\n assert candidate(left = 200000,right = 201000) == [200381, 200383]\n assert candidate(left = 14,right = 16) == [-1, -1]\n assert candidate(left = 900000,right = 910000) == [900089, 900091]\n assert candidate(left = 10000,right = 10050) == [10007, 10009]\n assert candidate(left = 1,right = 100) == [2, 3]\n assert candidate(left = 3000,right = 3010) == [-1, -1]\n assert candidate(left = 600000,right = 600100) == [600071, 600073]\n assert candidate(left = 987654,right = 987700) == [987659, 987697]\n assert candidate(left = 123456,right = 123556) == [123491, 123493]\n assert candidate(left = 2,right = 3) == [2, 3]\n assert candidate(left = 770000,right = 770100) == [770039, 770041]\n assert candidate(left = 100000,right = 110000) == [100151, 100153]\n assert candidate(left = 5000,right = 5100) == [5009, 5011]\n assert candidate(left = 800000,right = 800100) == [800053, 800057]\n assert candidate(left = 2,right = 5) == [2, 3]\n assert candidate(left = 14,right = 20) == [17, 19]\n assert candidate(left = 50000,right = 50010) == [-1, -1]\n assert candidate(left = 345678,right = 345778) == [345731, 345733]\n assert candidate(left = 654321,right = 654421) == [654343, 654349]\n assert candidate(left = 200000,right = 200050) == [200029, 200033]\n assert candidate(left = 999990,right = 999998) == [-1, -1]\n assert candidate(left = 300000,right = 300100) == [300017, 300023]\n assert candidate(left = 500000,right = 500100) == [500029, 500041]\n assert candidate(left = 100000,right = 100500) == [100151, 100153]\n assert candidate(left = 987654,right = 987754) == [987697, 987713]\n assert candidate(left = 1,right = 1000000) == [2, 3]\n assert candidate(left = 700000,right = 710000) == [700079, 700081]\n assert candidate(left = 950,right = 1000) == [967, 971]\n assert candidate(left = 2,right = 2) == [-1, -1]\n assert candidate(left = 500000,right = 501000) == [500111, 500113]\n assert candidate(left = 560030,right = 560050) == [560039, 560047]\n assert candidate(left = 3,right = 5) == [3, 5]\n assert candidate(left = 800000,right = 800200) == [800117, 800119]\n assert candidate(left = 200,right = 300) == [227, 229]\n assert candidate(left = 1487,right = 1601) == [1487, 1489]\n assert candidate(left = 150000,right = 150100) == [150089, 150091]\n", "comparison": "exact"}, "public_tests": ["10\n19", "4\n6"], "hints": ["Use Sieve of Eratosthenes to mark numbers that are primes.", "Iterate from right to left and find pair with the minimum distance between marked numbers."], "metadata": {"canonical_parameter_names": ["left", "right"], "leetcode_dataset_entry_point": "Solution().closestPrimes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:53+00:00", "tests_total": 95, "tests_dropped": 8, "flags": [], "topic_tags": ["math", "number-theory", "primality-test", "sieve-theory", "prime-number-sieve"]}, "language": "ruby", "interface": {"raw_signature": "def closest_primes(left, right)", "container": null, "callable": "closest_primes", "parameters": [{"name": "left", "type": "Integer"}, {"name": "right", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2525, "task_id": "categorize-box-according-to-criteria", "difficulty": "Easy", "problem_description": "Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.\n\n- The box is \"Bulky\" if:\n - Any of the dimensions of the box is greater or equal to 10^4.\n - Or, the volume of the box is greater or equal to 10^9.\n- If the mass of the box is greater or equal to 100, it is \"Heavy\".\n- If the box is both \"Bulky\" and \"Heavy\", then its category is \"Both\".\n- If the box is neither \"Bulky\" nor \"Heavy\", then its category is \"Neither\".\n- If the box is \"Bulky\" but not \"Heavy\", then its category is \"Bulky\".\n- If the box is \"Heavy\" but not \"Bulky\", then its category is \"Heavy\".\n\nNote that the volume of the box is the product of its length, width and height.\n\nExample 1:\n\nInput: length = 1000, width = 35, height = 700, mass = 300\nOutput: \"Heavy\"\nExplanation:\nNone of the dimensions of the box is greater or equal to 10^4.\nIts volume = 24500000 <= 10^9. So it cannot be categorized as \"Bulky\".\nHowever mass >= 100, so the box is \"Heavy\".\nSince the box is not \"Bulky\" but \"Heavy\", we return \"Heavy\".\n\nExample 2:\n\nInput: length = 200, width = 50, height = 800, mass = 50\nOutput: \"Neither\"\nExplanation:\nNone of the dimensions of the box is greater or equal to 10^4.\nIts volume = 8 * 10^6 <= 10^9. So it cannot be categorized as \"Bulky\".\nIts mass is also less than 100, so it cannot be categorized as \"Heavy\" either.\nSince its neither of the two above categories, we return \"Neither\".\n\nConstraints:\n\n- 1 <= length, width, height <= 10^5\n- 1 <= mass <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(length = 100000,width = 100000,height = 100000,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 10,height = 10,mass = 1) == \"Bulky\"\n assert candidate(length = 5000,width = 2000,height = 1000,mass = 50) == \"Bulky\"\n assert candidate(length = 5000,width = 2000,height = 1000,mass = 200) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 200,width = 50,height = 800,mass = 50) == \"Neither\"\n assert candidate(length = 10000,width = 10,height = 10,mass = 10) == \"Bulky\"\n assert candidate(length = 9999,width = 9999,height = 9999,mass = 100) == \"Both\"\n assert candidate(length = 1000,width = 35,height = 700,mass = 300) == \"Heavy\"\n assert candidate(length = 10,width = 10,height = 10,mass = 100) == \"Heavy\"\n assert candidate(length = 10000,width = 10000,height = 1,mass = 100) == \"Both\"\n assert candidate(length = 5000,width = 5000,height = 5000,mass = 1) == \"Bulky\"\n assert candidate(length = 10000,width = 1,height = 1,mass = 100) == \"Both\"\n assert candidate(length = 1000,width = 1000,height = 1000,mass = 1000) == \"Both\"\n assert candidate(length = 1,width = 1,height = 1,mass = 1) == \"Neither\"\n assert candidate(length = 9999,width = 9999,height = 9999,mass = 99) == \"Bulky\"\n assert candidate(length = 1000,width = 1000,height = 10,mass = 1000) == \"Heavy\"\n assert candidate(length = 10000,width = 10000,height = 10000,mass = 100) == \"Both\"\n assert candidate(length = 5000,width = 2000,height = 1,mass = 99) == \"Neither\"\n assert candidate(length = 10000,width = 10,height = 10,mass = 5) == \"Bulky\"\n assert candidate(length = 1,width = 10000,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 1000,width = 1000,height = 1000,mass = 999) == \"Both\"\n assert candidate(length = 1,width = 100000,height = 1,mass = 1000) == \"Both\"\n assert candidate(length = 10,width = 2,height = 50000,mass = 500) == \"Both\"\n assert candidate(length = 10,width = 1000,height = 1000,mass = 100) == \"Heavy\"\n assert candidate(length = 1000,width = 10000,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 10000,mass = 1) == \"Bulky\"\n assert candidate(length = 1,width = 1,height = 100000,mass = 100) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 10000,mass = 99) == \"Bulky\"\n assert candidate(length = 100000,width = 10,height = 1,mass = 100) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 1000,mass = 100) == \"Both\"\n assert candidate(length = 1,width = 100000,height = 10,mass = 100) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 1,mass = 999) == \"Both\"\n assert candidate(length = 10000,width = 9999,height = 10000,mass = 100) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 10,mass = 1000) == \"Both\"\n assert candidate(length = 1,width = 1,height = 100000,mass = 1000) == \"Both\"\n assert candidate(length = 1,width = 10000,height = 1,mass = 100) == \"Both\"\n assert candidate(length = 500,width = 500,height = 500,mass = 500) == \"Heavy\"\n assert candidate(length = 9999,width = 9999,height = 9999,mass = 101) == \"Both\"\n assert candidate(length = 1000,width = 1000,height = 1000,mass = 101) == \"Both\"\n assert candidate(length = 1000,width = 1000,height = 1000,mass = 100) == \"Both\"\n assert candidate(length = 9999,width = 9999,height = 10,mass = 99) == \"Neither\"\n assert candidate(length = 1000,width = 10,height = 1000,mass = 100) == \"Heavy\"\n assert candidate(length = 1,width = 10000,height = 10000,mass = 1) == \"Bulky\"\n assert candidate(length = 2,width = 50000,height = 10,mass = 500) == \"Both\"\n assert candidate(length = 103,width = 103,height = 103,mass = 99) == \"Neither\"\n assert candidate(length = 1,width = 1,height = 10000,mass = 100) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 1,width = 10000,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 10000,height = 1000,mass = 1000) == \"Both\"\n assert candidate(length = 100000,width = 1,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 10,width = 10000,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 1000,width = 1000,height = 1,mass = 99) == \"Neither\"\n assert candidate(length = 500,width = 2000,height = 1000,mass = 300) == \"Both\"\n assert candidate(length = 1,width = 10000,height = 10000,mass = 100) == \"Both\"\n assert candidate(length = 10000,width = 1,height = 10000,mass = 1) == \"Bulky\"\n assert candidate(length = 9999,width = 10000,height = 10000,mass = 99) == \"Bulky\"\n assert candidate(length = 10000,width = 1,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 10000,width = 10000,height = 9999,mass = 100) == \"Both\"\n assert candidate(length = 1,width = 1000,height = 1000,mass = 99) == \"Neither\"\n assert candidate(length = 10000,width = 1,height = 10000,mass = 100) == \"Both\"\n assert candidate(length = 500,width = 500,height = 500,mass = 150) == \"Heavy\"\n assert candidate(length = 9999,width = 9999,height = 10000,mass = 99) == \"Bulky\"\n assert candidate(length = 100000,width = 1,height = 1,mass = 100) == \"Both\"\n assert candidate(length = 1000,width = 1000,height = 1000,mass = 99) == \"Bulky\"\n assert candidate(length = 5000,width = 2000,height = 1000,mass = 99) == \"Bulky\"\n assert candidate(length = 9999,width = 10000,height = 10000,mass = 100) == \"Both\"\n assert candidate(length = 100,width = 100000,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 50000,width = 2,height = 10,mass = 500) == \"Both\"\n assert candidate(length = 1000,width = 1000,height = 10,mass = 100) == \"Heavy\"\n assert candidate(length = 1,width = 1,height = 1,mass = 99) == \"Neither\"\n assert candidate(length = 10000,width = 1,height = 1,mass = 1000) == \"Both\"\n assert candidate(length = 1,width = 10000,height = 1,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 1,height = 1,mass = 99) == \"Bulky\"\n assert candidate(length = 1,width = 1,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 100,height = 10,mass = 100) == \"Both\"\n assert candidate(length = 50000,width = 1,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 10,width = 10,height = 10,mass = 1000) == \"Heavy\"\n assert candidate(length = 5000,width = 5000,height = 5000,mass = 50) == \"Bulky\"\n assert candidate(length = 1,width = 10000,height = 1,mass = 99) == \"Bulky\"\n assert candidate(length = 1,width = 1,height = 10000,mass = 1) == \"Bulky\"\n assert candidate(length = 100,width = 100,height = 100,mass = 100) == \"Heavy\"\n assert candidate(length = 5000,width = 5000,height = 5000,mass = 100) == \"Both\"\n assert candidate(length = 1,width = 100000,height = 1,mass = 100) == \"Both\"\n assert candidate(length = 1,width = 10000,height = 10000,mass = 99) == \"Bulky\"\n assert candidate(length = 100000,width = 1,height = 1,mass = 1000) == \"Both\"\n assert candidate(length = 10000,width = 10,height = 10,mass = 50) == \"Bulky\"\n assert candidate(length = 1000,width = 1,height = 1000,mass = 99) == \"Neither\"\n assert candidate(length = 1,width = 1,height = 1,mass = 1000) == \"Heavy\"\n assert candidate(length = 10000,width = 9999,height = 9999,mass = 99) == \"Bulky\"\n assert candidate(length = 1,width = 1,height = 100000,mass = 1) == \"Bulky\"\n assert candidate(length = 10000,width = 1000,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 10,width = 1,height = 100000,mass = 100) == \"Both\"\n assert candidate(length = 1,width = 100000,height = 1,mass = 1) == \"Bulky\"\n assert candidate(length = 500,width = 500,height = 500,mass = 100) == \"Heavy\"\n assert candidate(length = 9999,width = 9999,height = 1000,mass = 999) == \"Both\"\n assert candidate(length = 1,width = 1,height = 10000,mass = 99) == \"Bulky\"\n assert candidate(length = 10000,width = 10000,height = 10000,mass = 101) == \"Both\"\n assert candidate(length = 1,width = 1,height = 1,mass = 100) == \"Heavy\"\n assert candidate(length = 9999,width = 9999,height = 1,mass = 100) == \"Heavy\"\n assert candidate(length = 9999,width = 10000,height = 9999,mass = 99) == \"Bulky\"\n assert candidate(length = 10000,width = 10,height = 10000,mass = 1000) == \"Both\"\n assert candidate(length = 999,width = 999,height = 999,mass = 999) == \"Heavy\"\n", "comparison": "exact"}, "public_tests": ["1000\n35\n700\n300", "200\n50\n800\n50"], "hints": ["Use conditional statements to find the right category of the box."], "metadata": {"canonical_parameter_names": ["length", "width", "height", "mass"], "leetcode_dataset_entry_point": "Solution().categorizeBox", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:55+00:00", "tests_total": 114, "tests_dropped": 11, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def categorize_box(length, width, height, mass)", "container": null, "callable": "categorize_box", "parameters": [{"name": "length", "type": "Integer"}, {"name": "width", "type": "Integer"}, {"name": "height", "type": "Integer"}, {"name": "mass", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2527, "task_id": "find-xor-beauty-of-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums.\n\nThe effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).\n\nThe xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.\n\nReturn the xor-beauty of nums.\n\nNote that:\n\n- val1 | val2 is bitwise OR of val1 and val2.\n- val1 & val2 is bitwise AND of val1 and val2.\n\nExample 1:\n\nInput: nums = [1,4]\nOutput: 5\nExplanation:\nThe triplets and their corresponding effective values are listed below:\n- (0,0,0) with effective value ((1 | 1) & 1) = 1\n- (0,0,1) with effective value ((1 | 1) & 4) = 0\n- (0,1,0) with effective value ((1 | 4) & 1) = 1\n- (0,1,1) with effective value ((1 | 4) & 4) = 4\n- (1,0,0) with effective value ((4 | 1) & 1) = 1\n- (1,0,1) with effective value ((4 | 1) & 4) = 4\n- (1,1,0) with effective value ((4 | 4) & 1) = 0\n- (1,1,1) with effective value ((4 | 4) & 4) = 4\nXor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.\n\nExample 2:\n\nInput: nums = [15,45,20,2,34,35,5,44,32,30]\nOutput: 34\nExplanation: The xor-beauty of the given array is 34.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 14\n assert candidate(nums = [15, 45, 20, 2, 34, 35, 5, 44, 32, 30]) == 34\n assert candidate(nums = [1, 4]) == 5\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50]) == 26\n assert candidate(nums = [2, 3, 5, 7, 11]) == 8\n assert candidate(nums = [2, 4, 8, 16, 32]) == 62\n assert candidate(nums = [7, 14, 21, 28, 35]) == 35\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000]) == 801260736\n assert candidate(nums = [7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777]) == 446738358\n assert candidate(nums = [31, 14, 7, 3, 1]) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 0\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 1]) == 630827518\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 588\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 262136\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 699050\n assert candidate(nums = [135792468, 246813579, 357924681, 468135792, 579246813, 681357924, 789246813, 892468135, 924681357, 24681357, 46813579, 68135792, 81357924, 13579246, 35792468, 57924681, 79246813, 92468135]) == 753001139\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216]) == 33553408\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [123456789, 987654321, 456789123, 321987654, 789123456]) == 445095137\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 31\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]) == 2\n assert candidate(nums = [987654321, 876543219, 765432198, 654321987, 543219876, 432198765, 321987654, 219876543, 198765432, 98765432, 8765432, 765432, 65432, 5432, 432, 32, 2, 1]) == 759310468\n assert candidate(nums = [531911163, 381216167, 84627534, 595912280, 691055427, 374083484, 163888428, 741109182, 830024027, 981830112]) == 1055643324\n assert candidate(nums = [123456789, 987654321, 246813579, 864209753, 135792468, 753951876, 321654987, 654987321, 987321654]) == 715524962\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 1047552\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) == 974967\n assert candidate(nums = [987654321, 876543219, 765432198, 654321987, 543219876, 432198765, 321987654, 219876543, 198765432]) == 674225103\n assert candidate(nums = [987654321, 876543219, 765432109, 654321099, 543210989, 432109879, 321098769, 210987659, 109876549, 98765439]) == 553747934\n assert candidate(nums = [12345, 67890, 13579, 24680, 97531, 86420, 75310, 64200, 53100, 42000, 31000, 20000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000]) == 49509\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 682\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 8184\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(nums = [13, 29, 47, 61, 73, 89, 101, 127, 149, 167]) == 58\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 99999999, 88888888, 77777777, 66666666, 55555555, 44444444, 33333333, 22222222, 11111111, 9999999, 8888888, 7777777, 6666666, 5555555, 4444444, 3333333, 2222222, 1111111, 999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111]) == 596022080\n assert candidate(nums = [5, 17, 34, 68, 136, 272, 544, 1088, 2176, 4352]) == 7690\n assert candidate(nums = [123456789, 987654321, 135792468, 246813579]) == 992719227\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888]) == 596034980\n assert candidate(nums = [987654321, 987654320, 987654319, 987654318, 987654317, 987654316, 987654315, 987654314, 987654313, 987654312]) == 1\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930, 313233, 343536, 373839, 404142, 434445]) == 211634\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 42\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 32767\n assert candidate(nums = [64, 32, 16, 8, 4, 2, 1, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216]) == 33554431\n assert candidate(nums = [89, 67, 45, 23, 1, 24, 46, 68, 90, 11, 33, 55, 77, 99, 22, 44, 66, 88, 10, 30]) == 14\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930]) == 524095\n assert candidate(nums = [7, 5, 3, 1, 9, 11, 13, 15]) == 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 = [13, 27, 41, 55, 69, 83, 97, 111, 125, 139, 153, 167, 181, 195, 209]) == 127\n assert candidate(nums = [17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]) == 69\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 682\n assert candidate(nums = [255, 511, 767, 1023, 1279, 1535, 1791, 2047, 2303, 2559]) == 256\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543]) == 618827735\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 2096128\n assert candidate(nums = [135792468, 246813579, 357924681, 468135792, 579246813, 681357924, 792468135, 813579246, 924681357]) == 710527387\n assert candidate(nums = [123456789, 987654321, 111222333, 444555666, 777888999]) == 252083948\n assert candidate(nums = [13, 29, 47, 61, 73, 89, 101, 113, 131, 137, 151, 163, 173, 191, 197, 211, 223, 229, 233, 239]) == 0\n assert candidate(nums = [987654321, 987654322, 987654323, 987654324, 987654325, 987654326, 987654327, 987654328, 987654329]) == 987654321\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1]) == 170\n assert candidate(nums = [500000000, 500000001, 500000002, 500000003, 500000004, 500000005, 500000006, 500000007, 500000008, 500000009]) == 1\n assert candidate(nums = [123456789, 234567891, 345678912, 456789123, 567891234, 678912345, 789123456, 891234567, 912345678, 123456789]) == 662886050\n assert candidate(nums = [234567890, 345678901, 456789012, 567890123, 678901234, 789012345]) == 619883187\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43]) == 47\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [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 = [101010101, 202020202, 303030303, 404040404, 505050505, 606060606, 707070707, 808080808, 909090909]) == 372268965\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(nums = [1048575, 2097150, 3145725, 4194300, 5242875, 6291450, 7340025, 8388500, 9437075, 10485650]) == 1048685\n assert candidate(nums = [1337, 2674, 4011, 5348, 6685, 8022, 9359, 10696, 12033, 13370]) == 1843\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 630827519\n assert candidate(nums = [999999937, 999999938, 999999939, 999999940, 999999941, 999999942, 999999943, 999999944, 999999945, 999999946]) == 11\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2047\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543, 98765432]) == 553747887\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 1000000000]) == 1041115904\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 503538687\n", "comparison": "exact"}, "public_tests": ["[1,4]", "[15,45,20,2,34,35,5,44,32,30]"], "hints": ["Try to simplify the given expression.", "Try constructing the answer bit by bit."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().xorBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:57+00:00", "tests_total": 97, "tests_dropped": 17, "flags": [], "topic_tags": ["array", "math", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def xor_beauty(nums)", "container": null, "callable": "xor_beauty", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2528, "task_id": "maximize-the-minimum-powered-city", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the i^th city.\n\nEach power station can provide power to every city in a fixed range. In other words, if the range is denoted by r, then a power station at city i can provide power to all cities j such that |i - j| <= r and 0 <= i, j <= n - 1.\n\n- Note that |x| denotes absolute value. For example, |7 - 5| = 2 and |3 - 10| = 7.\n\nThe power of a city is the total number of power stations it is being provided power from.\n\nThe government has sanctioned building k more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.\n\nGiven the two integers r and k, return the maximum possible minimum power of a city, if the additional power stations are built optimally.\n\nNote that you can build the k power stations in multiple cities.\n\nExample 1:\n\nInput: stations = [1,2,4,5,0], r = 1, k = 2\nOutput: 5\nExplanation:\nOne of the optimal ways is to install both the power stations at city 1.\nSo stations will become [1,4,4,5,0].\n- City 0 is provided by 1 + 4 = 5 power stations.\n- City 1 is provided by 1 + 4 + 4 = 9 power stations.\n- City 2 is provided by 4 + 4 + 5 = 13 power stations.\n- City 3 is provided by 5 + 4 = 9 power stations.\n- City 4 is provided by 5 + 0 = 5 power stations.\nSo the minimum power of a city is 5.\nSince it is not possible to obtain a larger power, we return 5.\n\nExample 2:\n\nInput: stations = [4,4,4,4], r = 0, k = 3\nOutput: 4\nExplanation:\nIt can be proved that we cannot make the minimum power of a city greater than 4.\n\nConstraints:\n\n- n == stations.length\n- 1 <= n <= 10^5\n- 0 <= stations[i] <= 10^5\n- 0 <= r <= n - 1\n- 0 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(stations = [1, 2, 4, 5, 0],r = 1,k = 2) == 5\n assert candidate(stations = [0, 0, 0, 0, 0],r = 2,k = 5) == 5\n assert candidate(stations = [0, 0, 0, 0, 0],r = 2,k = 10) == 10\n assert candidate(stations = [1, 3, 5, 7, 9],r = 2,k = 5) == 14\n assert candidate(stations = [3, 3, 3, 3, 3],r = 1,k = 5) == 8\n assert candidate(stations = [10, 20, 30, 40, 50],r = 3,k = 20) == 120\n assert candidate(stations = [1, 0, 1, 0, 1, 0, 1],r = 2,k = 3) == 3\n assert candidate(stations = [0, 0, 0, 0],r = 2,k = 5) == 5\n assert candidate(stations = [1, 0, 0, 0, 1],r = 2,k = 2) == 3\n assert candidate(stations = [0, 0, 0, 0],r = 2,k = 10) == 10\n assert candidate(stations = [10, 20, 30, 40, 50],r = 3,k = 100) == 200\n assert candidate(stations = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],r = 3,k = 15) == 27\n assert candidate(stations = [5, 5, 5, 5, 5],r = 2,k = 5) == 20\n assert candidate(stations = [10, 20, 30, 40, 50],r = 2,k = 10) == 70\n assert candidate(stations = [1, 0, 3, 0, 2],r = 2,k = 3) == 7\n assert candidate(stations = [4, 4, 4, 4],r = 0,k = 3) == 4\n assert candidate(stations = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],r = 3,k = 15) == 27\n assert candidate(stations = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],r = 5,k = 150) == 360\n assert candidate(stations = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],r = 5,k = 300) == 480\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 4,k = 10) == 5\n assert candidate(stations = [8, 9, 8, 9, 8, 9, 8, 9, 8, 9],r = 1,k = 10) == 22\n assert candidate(stations = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],r = 5,k = 100) == 68\n assert candidate(stations = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],r = 1,k = 4) == 2\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 9,k = 20) == 20\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 0,k = 5) == 1\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 4,k = 25) == 12\n assert candidate(stations = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],r = 1,k = 50) == 37\n assert candidate(stations = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],r = 5,k = 300) == 405\n assert candidate(stations = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],r = 5,k = 30) == 45\n assert candidate(stations = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],r = 0,k = 50) == 36\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 4,k = 20) == 10\n assert candidate(stations = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],r = 1,k = 500) == 262\n assert candidate(stations = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],r = 1,k = 50) == 25\n assert candidate(stations = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],r = 5,k = 5000) == 7100\n assert candidate(stations = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],r = 3,k = 150) == 185\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 4,k = 50) == 52\n assert candidate(stations = [1, 3, 0, 2, 5, 4, 2, 1, 0, 5],r = 2,k = 10) == 10\n assert candidate(stations = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],r = 2,k = 50000) == 41500\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 1,k = 45) == 25\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 10,k = 50) == 61\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 5,k = 10) == 11\n assert candidate(stations = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0],r = 3,k = 50) == 35\n assert candidate(stations = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],r = 5,k = 1000000) == 1600000\n assert candidate(stations = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],r = 4,k = 30) == 60\n assert candidate(stations = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],r = 3,k = 50) == 40\n assert candidate(stations = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],r = 4,k = 100) == 60\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 2,k = 10) == 5\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 9,k = 10) == 15\n assert candidate(stations = [1, 0, 0, 0, 0, 1],r = 2,k = 3) == 2\n assert candidate(stations = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0],r = 2,k = 10) == 12\n assert candidate(stations = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],r = 2,k = 100) == 145\n assert candidate(stations = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],r = 1,k = 5) == 2\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],r = 10,k = 500) == 566\n assert candidate(stations = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],r = 3,k = 150) == 250\n assert candidate(stations = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],r = 6,k = 10) == 6\n assert candidate(stations = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],r = 4,k = 1000) == 900\n assert candidate(stations = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],r = 4,k = 250) == 400\n assert candidate(stations = [50, 40, 30, 20, 10],r = 1,k = 50) == 80\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],r = 5,k = 150) == 138\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],r = 3,k = 100) == 80\n assert candidate(stations = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],r = 2,k = 60) == 120\n assert candidate(stations = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],r = 4,k = 500) == 2000\n assert candidate(stations = [100000, 0, 100000, 0, 100000, 0, 100000],r = 3,k = 500000) == 700000\n assert candidate(stations = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],r = 4,k = 30) == 37\n assert candidate(stations = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],r = 5,k = 5000) == 11000\n assert candidate(stations = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],r = 2,k = 50) == 39\n assert candidate(stations = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],r = 1,k = 10) == 13\n assert candidate(stations = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],r = 4,k = 250) == 400\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 0,k = 45) == 10\n assert candidate(stations = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],r = 1,k = 10) == 3\n assert candidate(stations = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],r = 2,k = 25) == 18\n assert candidate(stations = [100, 0, 100, 0, 100],r = 2,k = 50) == 250\n assert candidate(stations = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],r = 1,k = 100) == 125\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 4,k = 10) == 10\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 2,k = 20) == 26\n assert candidate(stations = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],r = 5,k = 100) == 350\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],r = 7,k = 100) == 134\n assert candidate(stations = [90, 80, 70, 60, 50, 40, 30, 20, 10, 0],r = 3,k = 100) == 160\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],r = 1,k = 100) == 40\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 1,k = 10) == 12\n assert candidate(stations = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],r = 2,k = 30) == 28\n assert candidate(stations = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],r = 3,k = 5) == 3\n assert candidate(stations = [5, 15, 25, 35, 45, 55],r = 1,k = 100) == 110\n assert candidate(stations = [1, 0, 0, 0, 1],r = 2,k = 3) == 4\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 8,k = 20) == 19\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 1,k = 10) == 2\n assert candidate(stations = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],r = 4,k = 20000) == 35000\n assert candidate(stations = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],r = 1,k = 5) == 8\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 4,k = 50) == 25\n assert candidate(stations = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],r = 3,k = 30) == 33\n assert candidate(stations = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],r = 3,k = 150) == 125\n assert candidate(stations = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],r = 2,k = 20) == 26\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 4,k = 20) == 35\n assert candidate(stations = [0, 0, 0, 0, 0, 0],r = 1,k = 10) == 5\n assert candidate(stations = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],r = 5,k = 200) == 305\n assert candidate(stations = [1, 0, 0, 0, 1],r = 2,k = 2) == 3\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 2,k = 20) == 10\n assert candidate(stations = [9, 7, 5, 3, 1, 0, 2, 4, 6, 8],r = 4,k = 25) == 35\n assert candidate(stations = [1, 3, 2, 5, 7, 8, 6, 4, 9, 0],r = 2,k = 10) == 14\n assert candidate(stations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],r = 5,k = 20) == 20\n assert candidate(stations = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],r = 1,k = 5) == 2\n assert candidate(stations = [10, 20, 30, 40, 50, 40, 30, 20, 10],r = 2,k = 50) == 85\n assert candidate(stations = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],r = 5,k = 20) == 43\n assert candidate(stations = [100, 0, 100, 0, 100, 0, 100],r = 2,k = 200) == 300\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],r = 5,k = 25) == 46\n assert candidate(stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],r = 3,k = 100) == 73\n assert candidate(stations = [100, 0, 100, 0, 100, 0, 100, 0, 100, 0],r = 4,k = 100) == 300\n assert candidate(stations = [50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50],r = 3,k = 100) == 190\n assert candidate(stations = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],r = 0,k = 500) == 100\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 9,k = 50) == 35\n assert candidate(stations = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],r = 4,k = 500) == 2000\n assert candidate(stations = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],r = 5,k = 2000) == 4100\n assert candidate(stations = [1, 3, 2, 5, 4, 6, 7, 8, 9, 0],r = 2,k = 20) == 21\n assert candidate(stations = [0, 0, 0, 0, 0],r = 1,k = 5) == 2\n assert candidate(stations = [9, 8, 7, 6, 5, 4, 3, 2, 1],r = 3,k = 25) == 32\n assert candidate(stations = [1, 3, 2, 1, 4, 1, 2, 3],r = 2,k = 5) == 8\n assert candidate(stations = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],r = 9,k = 20) == 20\n assert candidate(stations = [1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000],r = 1,k = 10000) == 3751\n", "comparison": "exact"}, "public_tests": ["[1,2,4,5,0]\n1\n2", "[4,4,4,4]\n0\n3"], "hints": ["Pre calculate the number of stations on each city using Line Sweep.", "Use binary search to maximize the minimum."], "metadata": {"canonical_parameter_names": ["stations", "r", "k"], "leetcode_dataset_entry_point": "Solution().maxPower", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:00+00:00", "tests_total": 118, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "queue", "sliding-window", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def max_power(stations, r, k)", "container": null, "callable": "max_power", "parameters": [{"name": "stations", "type": "Integer[]"}, {"name": "r", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2529, "task_id": "maximum-count-of-positive-integer-and-negative-integer", "difficulty": "Easy", "problem_description": "Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.\n\n- In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.\n\nNote that 0 is neither positive nor negative.\n\nExample 1:\n\nInput: nums = [-2,-1,-1,1,2,3]\nOutput: 3\nExplanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.\n\nExample 2:\n\nInput: nums = [-3,-2,-1,0,0,1,2]\nOutput: 3\nExplanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.\n\nExample 3:\n\nInput: nums = [5,20,66,1314]\nOutput: 4\nExplanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4.\n\nConstraints:\n\n- 1 <= nums.length <= 2000\n- -2000 <= nums[i] <= 2000\n- nums is sorted in a non-decreasing order.\n\nFollow up: Can you solve the problem in O(log(n)) time complexity?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-2, -1, -1, 1, 2, 3]) == 3\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0]) == 10\n assert candidate(nums = [5, 20, 66, 1314]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-1000, -500, -250, -100, -50, -25, -10, -5, -2, -1, 0, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000]) == 10\n assert candidate(nums = [-10, -5, -1, -1, 0, 0, 1, 2, 3, 5, 10]) == 5\n assert candidate(nums = [-5, -3, -1, 0, 2, 4, 6]) == 3\n assert candidate(nums = [-5, -4, -3, -2, -1]) == 5\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 10\n assert candidate(nums = [-5, -3, -1, 0, 1, 2, 4]) == 3\n assert candidate(nums = [-1000, -500, -100, -50, -10, -5, -1, 0, 1, 5, 10, 50, 100, 500, 1000]) == 7\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [-1000, -500, 0, 500, 1000]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [-3, -2, -1, 0, 0, 1, 2]) == 3\n assert candidate(nums = [-10, -5, -1, 0, 1, 5, 10]) == 3\n assert candidate(nums = [-2000, -1000, -500, -250, -100, -50, -25, -10, -5, -2, -1, 0, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 1500, 2000]) == 12\n assert candidate(nums = [-5, -4, -3, 0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [-10, -5, -1, -1, 0, 0, 1, 2, 3, 5]) == 4\n assert candidate(nums = [-1, 0, 1]) == 1\n assert candidate(nums = [-1, 0, 1]) == 1\n assert candidate(nums = [-2, -2, -2, 0, 1, 1, 1]) == 3\n assert candidate(nums = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 47\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [-2000, -1999, -1998, -1997, -1996, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]) == 10\n assert candidate(nums = [-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 20\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 50\n assert candidate(nums = [-2000, -1500, -1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 0, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000, 1500, 2000]) == 12\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [-1000, -900, -800, -700, -600, -500, -400, -300, -200, -100, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(nums = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [-1500, -1000, -500, -100, -10, -1, 0, 1, 10, 100, 500, 1000, 1500]) == 6\n assert candidate(nums = [-100, -50, -25, -10, -5, 0, 5, 10, 25, 50, 100]) == 5\n assert candidate(nums = [-100, -50, -25, -10, -5, 0, 5, 10, 25, 50, 100, 150, 175, 190, 195, 200]) == 10\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [-1000, -500, -100, -50, -10, -5, -1, 0, 1, 5, 10, 50, 100, 500, 1000]) == 7\n assert candidate(nums = [-1500, -1250, -1000, -750, -500, -250, 0, 250, 500, 750, 1000, 1250, 1500]) == 6\n assert candidate(nums = [-2000, 0, 2000]) == 1\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, 0, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 51\n assert candidate(nums = [-1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 0, 0, 0, 0, 0, 0, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000]) == 10\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, 0, 95, 96, 97, 98, 99, 100]) == 6\n assert candidate(nums = [-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [-1000, -500, -250, -100, -50, -25, -10, -5, -2, -1, 0, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000]) == 10\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-2000, -1999, -1998, 0, 0, 0, 1999, 2000]) == 3\n assert candidate(nums = [-1000, -999, -998, -997, -996, -995, -994, -993, -992, -991, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-1000, -900, -800, -700, -600, -500, -400, -300, -200, -100, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(nums = [-2000, -1500, -1000, -750, -500, -250, 0, 250, 500, 750, 1000, 1500, 2000]) == 6\n assert candidate(nums = [-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50]) == 5\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [-1000, 0, 1000]) == 1\n assert candidate(nums = [-1, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 0, 0, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000]) == 10\n assert candidate(nums = [-2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums = [-2000, -1999, -1998, -1997, -1996, -1995, -1994, -1993, -1992, -1991, -1990, -1989, -1988, -1987, -1986, -1985, -1984, -1983, -1982, -1981, -1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-500, -400, -300, -200, -100, 0, 100, 200, 300, 400, 500]) == 5\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\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, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 100\n assert candidate(nums = [-1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 0, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000]) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [-2000, -1500, -1000, -500, -1, 0, 1, 500, 1000, 1500, 2000]) == 5\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 10\n assert candidate(nums = [-1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000]) == 10\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-2000, -1500, -1000, -500, -100, -50, -10, -5, -2, -1, 0, 1, 2, 5, 10, 50, 100, 500, 1000, 1500, 2000]) == 10\n assert candidate(nums = [-500, -250, -100, -50, -25, -10, 0, 10, 25, 50, 100, 250, 500]) == 6\n assert candidate(nums = [-2000, -1999, -1998, -1997, 1998, 1999, 2000]) == 4\n assert candidate(nums = [-1999, -1998, -1997, -1996, -1995, 0, 1995, 1996, 1997, 1998, 1999]) == 5\n assert candidate(nums = [-2000, -1999, -1998, -1997, -1996, -1995, -1994, -1993, -1992, -1991, -1990, -1989, -1988, -1987, -1986, -1985, -1984, -1983, -1982, -1981, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 30\n assert candidate(nums = [-1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 0, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000]) == 10\n assert candidate(nums = [-2000, -1999, -1998, -1997, -1996, -1995, -1994, -1993, -1992, -1991, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [-2000, -2000, -1000, -500, 0, 0, 0, 0, 0, 0, 500, 1000, 2000, 2000, 2000, 2000, 2000, 2000]) == 8\n assert candidate(nums = [-2000, -1999, -1998, -1000, -1, 0, 1, 1000, 1999, 2000]) == 5\n assert candidate(nums = [-2000, -1500, -1000, -500, -250, -100, -50, -25, -10, -5, -1, 0, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 1500, 2000]) == 11\n assert candidate(nums = [-50, -25, -10, -5, -1, 0, 1, 5, 10, 25, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == 14\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, 0, 1, 2, 3, 4, 5]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [-2000, -1999, -1998, -1997, -1996, -1995, -1994, -1993, -1992, -1991, -1990, -1989, -1988, -1987, -1986, -1985, -1984, -1983, -1982, -1981, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000]) == 20\n assert candidate(nums = [-2000, -1500, -1000, -500, 0, 500, 1000, 1500, 2000]) == 4\n assert candidate(nums = [-15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 20\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 10\n assert candidate(nums = [-2000, -1500, -1000, -500, -250, -100, -50, -25, -10, -5, -1, 0, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 1500, 2000, 2000, 2000, 2000, 2000]) == 15\n assert candidate(nums = [-2000, -1999, -1998, -1997, -1996, -1995, -1994, -1993, -1992, -1991, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000]) == 10\n assert candidate(nums = [-1000, -999, -998, -997, 0, 0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 5\n", "comparison": "exact"}, "public_tests": ["[-2,-1,-1,1,2,3]", "[-3,-2,-1,0,0,1,2]", "[5,20,66,1314]"], "hints": ["Count how many positive integers and negative integers are in the array.", "Since the array is sorted, can we use the binary search?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:02+00:00", "tests_total": 96, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_count(nums)", "container": null, "callable": "maximum_count", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2530, "task_id": "maximal-score-after-applying-k-operations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.\n\nIn one operation:\n\n1. choose an index i such that 0 <= i < nums.length,\n2. increase your score by nums[i], and\n3. replace nums[i] with ceil(nums[i] / 3).\n\nReturn the maximum possible score you can attain after applying exactly k operations.\n\nThe ceiling function ceil(val) is the least integer greater than or equal to val.\n\nExample 1:\n\nInput: nums = [10,10,10,10,10], k = 5\nOutput: 50\nExplanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.\n\nExample 2:\n\nInput: nums = [1,10,3,3,3], k = 3\nOutput: 17\nExplanation: You can do the following operations:\nOperation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10.\nOperation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4.\nOperation 3: Select i = 2, so nums becomes [1,2,1,3,3]. Your score increases by 3.\nThe final score is 10 + 4 + 3 = 17.\n\nConstraints:\n\n- 1 <= nums.length, k <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 9, 9, 9, 9],k = 4) == 36\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 6) == 30\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 1) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(nums = [10, 10, 10, 10, 10],k = 5) == 50\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 50\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 9\n assert candidate(nums = [5, 6, 7, 8, 9],k = 4) == 30\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 3) == 3000000000\n assert candidate(nums = [1, 10, 3, 3, 3],k = 3) == 17\n assert candidate(nums = [9, 9, 9, 9, 9],k = 1) == 9\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 7) == 37\n assert candidate(nums = [9, 8, 7, 6, 5],k = 4) == 30\n assert candidate(nums = [9, 7, 5, 3, 1],k = 4) == 24\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666],k = 50000) == 6500049939\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 20) == 1452\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 59\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 5) == 120\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 400\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],k = 5) == 4333333330\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 584\n assert candidate(nums = [333333333, 666666666, 999999999, 1000000000, 1],k = 5) == 3333333332\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995],k = 3) == 2999999994\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 = 20) == 20\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 20\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120],k = 15) == 799\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 5) == 2250000001\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 15) == 369\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333],k = 5) == 1995884772\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 1, 1, 1],k = 10) == 271\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],k = 15) == 291\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 7) == 98\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 11) == 47\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 15) == 45\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 = 20) == 227\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000],k = 3) == 1200000000\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 15) == 46635\n assert candidate(nums = [123456789, 987654321, 135792468, 864208642, 246813579],k = 5) == 2715964197\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 5000000000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 20) == 748\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 10) == 2754\n assert candidate(nums = [100, 99, 98, 97, 96],k = 10) == 655\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 1050\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],k = 20) == 2168\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 7) == 490\n assert candidate(nums = [8, 6, 4, 2, 1],k = 5) == 23\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],k = 10) == 6333333329\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],k = 25) == 100\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 107, 113, 119],k = 20) == 1335\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 20) == 1127\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 25) == 24803\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 = 10) == 10\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666],k = 5) == 4333333330\n assert candidate(nums = [123456789, 987654321, 456789123, 321987654, 654321987, 789123456, 891234567, 234567891, 567891234, 912345678],k = 15) == 7416772992\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 20) == 13333333340\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 10) == 292\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 10) == 1652386837\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 10) == 5834\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 692\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],k = 15) == 372\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 7) == 21\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 10) == 1378\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 15) == 1281\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 5) == 375\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 7) == 91\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000],k = 10) == 6666666670\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 = 30) == 30\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],k = 100) == 100\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 4000\n assert candidate(nums = [100, 200, 300, 400, 500],k = 5) == 1567\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 10\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610],k = 10) == 1984\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 100000) == 7500099960\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 10) == 9999955\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 10) == 303\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 = 30) == 269\n assert candidate(nums = [123456789, 987654321, 135792468, 246813579, 112233445, 543216789, 987654321, 123456789],k = 8) == 3740639955\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555],k = 5) == 3888888885\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 48\n assert candidate(nums = [15, 21, 33, 47, 61, 75, 89, 103, 117, 131],k = 7) == 623\n assert candidate(nums = [987654321, 876543219, 765432198, 654321987, 543219876],k = 50000) == 5740807347\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 109\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 9) == 1648271610\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 5) == 4999999990\n assert candidate(nums = [9, 7, 5, 3, 1, 9, 7, 5, 3, 1, 9, 7, 5, 3, 1],k = 15) == 81\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 10) == 10000000000\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],k = 20) == 675\n", "comparison": "exact"}, "public_tests": ["[10,10,10,10,10]\n5", "[1,10,3,3,3]\n3"], "hints": ["It is always optimal to select the greatest element in the array.", "Use a heap to query for the maximum in O(log n) time."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxKelements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:05+00:00", "tests_total": 89, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def max_kelements(nums, k)", "container": null, "callable": "max_kelements", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2531, "task_id": "make-number-of-distinct-characters-equal", "difficulty": "Medium", "problem_description": "You are given two 0-indexed strings word1 and word2.\n\nA move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j].\n\nReturn true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one move. Return false otherwise.\n\nExample 1:\n\nInput: word1 = \"ac\", word2 = \"b\"\nOutput: false\nExplanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.\n\nExample 2:\n\nInput: word1 = \"abcc\", word2 = \"aab\"\nOutput: true\nExplanation: We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = \"abac\" and word2 = \"cab\", which both have 3 distinct characters.\n\nExample 3:\n\nInput: word1 = \"abcde\", word2 = \"fghij\"\nOutput: true\nExplanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap.\n\nConstraints:\n\n- 1 <= word1.length, word2.length <= 10^5\n- word1 and word2 consist of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"abcde\",word2 = \"fghij\") == True\n assert candidate(word1 = \"xyz\",word2 = \"zyx\") == True\n assert candidate(word1 = \"aaa\",word2 = \"bbb\") == True\n assert candidate(word1 = \"ac\",word2 = \"b\") == False\n assert candidate(word1 = \"unique\",word2 = \"letters\") == True\n assert candidate(word1 = \"abcc\",word2 = \"aab\") == True\n assert candidate(word1 = \"aabb\",word2 = \"ccdd\") == True\n assert candidate(word1 = \"hello\",word2 = \"world\") == True\n assert candidate(word1 = \"ab\",word2 = \"cd\") == True\n assert candidate(word1 = \"xyz\",word2 = \"xyz\") == True\n assert candidate(word1 = \"abcd\",word2 = \"efgh\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"xyz\") == False\n assert candidate(word1 = \"abcd\",word2 = \"dcba\") == True\n assert candidate(word1 = \"same\",word2 = \"same\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"xxxyyzz\") == True\n assert candidate(word1 = \"aaaa\",word2 = \"bbbb\") == True\n assert candidate(word1 = \"qrstuvwxyz\",word2 = \"abcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(word1 = \"single\",word2 = \"letter\") == True\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(word1 = \"mississippi\",word2 = \"missouri\") == True\n assert candidate(word1 = \"mississippi\",word2 = \"penelope\") == True\n assert candidate(word1 = \"xyzz\",word2 = \"zzxx\") == True\n assert candidate(word1 = \"aaaaaaa\",word2 = \"bbbbbbb\") == True\n assert candidate(word1 = \"oneonetwo\",word2 = \"twotwoone\") == True\n assert candidate(word1 = \"uniquecharacters\",word2 = \"distinctcharacters\") == True\n assert candidate(word1 = \"aaaaabbbbbaaaa\",word2 = \"cccccbccccbcccc\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"abcdefghijlkmnopqrstuvwxyz\") == True\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"aabbccddeeff\") == True\n assert candidate(word1 = \"repeatedletters\",word2 = \"differentletters\") == True\n assert candidate(word1 = \"unique\",word2 = \"distinct\") == True\n assert candidate(word1 = \"aaaaabbbbbccccc\",word2 = \"dddddeeeeeffffff\") == True\n assert candidate(word1 = \"onetwothreefour\",word2 = \"five\") == False\n assert candidate(word1 = \"almost\",word2 = \"almost\") == True\n assert candidate(word1 = \"aaaabbbb\",word2 = \"cccddd\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"bacbabacbacbacb\") == False\n assert candidate(word1 = \"aaaaabbbb\",word2 = \"ccccc\") == False\n assert candidate(word1 = \"abcd\",word2 = \"efghijklmnopqrstuvwxyz\") == False\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzxxwwvvttrrssppoonnmmllkkjjiihhggffeeddccbbaa\") == False\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxy\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(word1 = \"samechars\",word2 = \"samechars\") == True\n assert candidate(word1 = \"abcdefghij\",word2 = \"jihgfedcba\") == True\n assert candidate(word1 = \"abcdefg\",word2 = \"hijklmnopqrstuv\") == False\n assert candidate(word1 = \"longerstringwithrepeatedcharacters\",word2 = \"short\") == False\n assert candidate(word1 = \"xyz\",word2 = \"zyxwvut\") == False\n assert candidate(word1 = \"abcdefgh\",word2 = \"hgfedcba\") == True\n assert candidate(word1 = \"abcdef\",word2 = \"ghijklmnopqrstuvwxyz\") == False\n assert candidate(word1 = \"abcdefg\",word2 = \"hijklmnop\") == False\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"bcadcbadcbadcbc\") == True\n assert candidate(word1 = \"xyxzyzxzyx\",word2 = \"zyxzyzxzyz\") == True\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"dcbaabcdabcd\") == True\n assert candidate(word1 = \"xyzz\",word2 = \"xxxyyyzzzz\") == True\n assert candidate(word1 = \"abracadabra\",word2 = \"alakazam\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijj\",word2 = \"zzzzzyyyxxwwvvuuttssrrqqppoonnmmllijkkihgfedcba\") == False\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"zzzzzzzzzzzzzzzzz\") == False\n assert candidate(word1 = \"abcabcabcabc\",word2 = \"abcabcabcabc\") == True\n assert candidate(word1 = \"aaaaaa\",word2 = \"bbbbbb\") == True\n assert candidate(word1 = \"almost\",word2 = \"equal\") == True\n assert candidate(word1 = \"abcabcabc\",word2 = \"defdefdef\") == True\n assert candidate(word1 = \"ababababab\",word2 = \"bababababa\") == True\n assert candidate(word1 = \"almostthesame\",word2 = \"almostthesamee\") == True\n assert candidate(word1 = \"abcdefghij\",word2 = \"mnopqrstuv\") == True\n assert candidate(word1 = \"zzzzzzzzzzzz\",word2 = \"aaaaaaaaaaab\") == True\n assert candidate(word1 = \"almostthesame\",word2 = \"almostthesame\") == True\n assert candidate(word1 = \"xyzz\",word2 = \"xyz\") == True\n assert candidate(word1 = \"thisisaverylongwordwithrepeatedcharacters\",word2 = \"anotherlongwordwithdifferentcharacters\") == True\n assert candidate(word1 = \"unique\",word2 = \"words\") == True\n assert candidate(word1 = \"unique\",word2 = \"characters\") == False\n assert candidate(word1 = \"aabbcc\",word2 = \"aabbcd\") == True\n assert candidate(word1 = \"abcdef\",word2 = \"ghijkl\") == True\n assert candidate(word1 = \"thisisaverylongword\",word2 = \"whichhasmanycharacters\") == False\n assert candidate(word1 = \"mnopqr\",word2 = \"rstuvw\") == True\n assert candidate(word1 = \"aaaaaaaabbbbbbb\",word2 = \"ccccccccddddd\") == True\n assert candidate(word1 = \"mississippi\",word2 = \"louisiana\") == False\n assert candidate(word1 = \"aabbcceeddee\",word2 = \"fghhiijjkk\") == True\n assert candidate(word1 = \"abcdefghijklmnop\",word2 = \"qrstuvwxyz\") == False\n assert candidate(word1 = \"aaaaabbbbcccc\",word2 = \"bbbbccccdddd\") == True\n assert candidate(word1 = \"aaaaaaaa\",word2 = \"bbbbbbbb\") == True\n assert candidate(word1 = \"aaaaaabbbbbcccccdddddeeeee\",word2 = \"eeeeeaaaaabbbbbcccccddddd\") == True\n assert candidate(word1 = \"mississippi\",word2 = \"pennsylvania\") == False\n assert candidate(word1 = \"xyzz\",word2 = \"zzxy\") == True\n assert candidate(word1 = \"aabbccdd\",word2 = \"efgghhii\") == True\n assert candidate(word1 = \"aaaaabbbbbcccccdddddeeeee\",word2 = \"fffffggggghhhhhiiiii\") == False\n assert candidate(word1 = \"abcdefgh\",word2 = \"ijklmnop\") == True\n assert candidate(word1 = \"repeatrepeat\",word2 = \"repeatrepeat\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"ddeeff\") == True\n assert candidate(word1 = \"abcdefghijk\",word2 = \"klmnopqrstu\") == True\n assert candidate(word1 = \"aabbc\",word2 = \"ccdde\") == True\n assert candidate(word1 = \"complex\",word2 = \"inputs\") == True\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"dcbaabcdabdc\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzzyyxxwwvvuuttoosssrrqqppoonnmlkkjjiihhggffeeddccbbaa\") == True\n assert candidate(word1 = \"one\",word2 = \"twothreefour\") == False\n assert candidate(word1 = \"xyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(word1 = \"xyzz\",word2 = \"yzxx\") == True\n assert candidate(word1 = \"singlechar\",word2 = \"different\") == False\n assert candidate(word1 = \"aabbcc\",word2 = \"ddeeffgghhiijj\") == False\n assert candidate(word1 = \"abcdefg\",word2 = \"abcdefg\") == True\n assert candidate(word1 = \"characters\",word2 = \"words\") == False\n assert candidate(word1 = \"mississippi\",word2 = \"banana\") == True\n assert candidate(word1 = \"hellohello\",word2 = \"worldworld\") == True\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"ggffeeddccbaaa\") == True\n assert candidate(word1 = \"python\",word2 = \"programming\") == False\n assert candidate(word1 = \"aaaaaa\",word2 = \"bbbbbbbbb\") == True\n assert candidate(word1 = \"aaaaaaaaaa\",word2 = \"bbbbbbbbbb\") == True\n assert candidate(word1 = \"xyzzxyzz\",word2 = \"mnopmnop\") == False\n assert candidate(word1 = \"mississippi\",word2 = \"elephant\") == False\n assert candidate(word1 = \"qqqq\",word2 = \"pppq\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"xxxyyy\") == False\n assert candidate(word1 = \"aabbcc\",word2 = \"bbccdd\") == True\n assert candidate(word1 = \"zzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == True\n assert candidate(word1 = \"a\",word2 = \"b\") == True\n assert candidate(word1 = \"aabbaa\",word2 = \"aabbaa\") == True\n assert candidate(word1 = \"abcabcabcabc\",word2 = \"defdefdefdef\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"abc\") == True\n assert candidate(word1 = \"aabbbcc\",word2 = \"dddeeefff\") == True\n assert candidate(word1 = \"abacabadaba\",word2 = \"acaacaaca\") == True\n assert candidate(word1 = \"abcdabcd\",word2 = \"abcdabcd\") == True\n assert candidate(word1 = \"aabbccddeeffgghh\",word2 = \"iiiiijjjjjkkkkkk\") == False\n", "comparison": "exact"}, "public_tests": ["\"ac\"\n\"b\"", "\"abcc\"\n\"aab\"", "\"abcde\"\n\"fghij\""], "hints": ["Create a frequency array of the letters of each string.", "There are 26*26 possible pairs of letters to swap. Can we try them all?", "Iterate over all possible pairs of letters and check if swapping them will yield two strings that have the same number of distinct characters. Use the frequency array for the check."], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().isItPossible", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:07+00:00", "tests_total": 119, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def is_it_possible(word1, word2)", "container": null, "callable": "is_it_possible", "parameters": [{"name": "word1", "type": "String"}, {"name": "word2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2532, "task_id": "time-to-cross-a-bridge", "difficulty": "Hard", "problem_description": "There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [right_i, pick_i, left_i, put_i].\n\nThe warehouses are separated by a river and connected by a bridge. Initially, all k workers are waiting on the left side of the bridge. To move the boxes, the i^th worker can do the following:\n\n- Cross the bridge to the right side in right_i minutes.\n- Pick a box from the right warehouse in pick_i minutes.\n- Cross the bridge to the left side in left_i minutes.\n- Put the box into the left warehouse in put_i minutes.\n\nThe i^th worker is less efficient than the j^th worker if either condition is met:\n\n- left_i + right_i > left_j + right_j\n- left_i + right_i == left_j + right_j and i > j\n\nThe following rules regulate the movement of the workers through the bridge:\n\n- Only one worker can use the bridge at a time.\n- When the bridge is unused prioritize the least efficient worker (who have picked up the box) on the right side to cross. If not, prioritize the least efficient worker on the left side to cross.\n- If enough workers have already been dispatched from the left side to pick up all the remaining boxes, no more workers will be sent from the left side.\n\nReturn the elapsed minutes at which the last box reaches the left side of the bridge.\n\nExample 1:\n\nInput: n = 1, k = 3, time = [[1,1,2,1],[1,1,3,1],[1,1,4,1]]\nOutput: 6\nExplanation:\n\nFrom 0 to 1 minutes: worker 2 crosses the bridge to the right.\nFrom 1 to 2 minutes: worker 2 picks up a box from the right warehouse.\nFrom 2 to 6 minutes: worker 2 crosses the bridge to the left.\nFrom 6 to 7 minutes: worker 2 puts a box at the left warehouse.\nThe whole process ends after 7 minutes. We return 6 because the problem asks for the instance of time at which the last worker reaches the left side of the bridge.\n\nExample 2:\n\nInput: n = 3, k = 2, time = [[1,5,1,8],[10,10,10,10]]\nOutput: 37\nExplanation:\n\nThe last box reaches the left side at 37 seconds. Notice, how we do not put the last boxes down, as that would take more time, and they are already on the left with the workers.\n\nConstraints:\n\n- 1 <= n, k <= 10^4\n- time.length == k\n- time[i].length == 4\n- 1 <= left_i, pick_i, right_i, put_i <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,k = 1,time = [[1, 2, 3, 4]]) == 16\n assert candidate(n = 5,k = 5,time = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]) == 54\n assert candidate(n = 7,k = 4,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == 48\n assert candidate(n = 5,k = 5,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]) == 43\n assert candidate(n = 2,k = 1,time = [[1, 2, 1, 2]]) == 10\n assert candidate(n = 10,k = 1,time = [[5, 5, 5, 5]]) == 195\n assert candidate(n = 5,k = 3,time = [[1, 2, 1, 2], [3, 4, 3, 4], [2, 3, 2, 3]]) == 26\n assert candidate(n = 10,k = 3,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]) == 45\n assert candidate(n = 6,k = 3,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]) == 24\n assert candidate(n = 2,k = 4,time = [[2, 10, 1, 1], [3, 1, 2, 2], [1, 4, 3, 3], [1, 1, 5, 5]]) == 11\n assert candidate(n = 10,k = 5,time = [[2, 1, 3, 2], [4, 3, 5, 4], [3, 2, 4, 3], [1, 1, 2, 1], [2, 2, 3, 3]]) == 80\n assert candidate(n = 10,k = 5,time = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]) == 108\n assert candidate(n = 4,k = 2,time = [[1, 1, 2, 2], [3, 3, 4, 4]]) == 25\n assert candidate(n = 10,k = 5,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]) == 87\n assert candidate(n = 3,k = 2,time = [[1, 5, 1, 8], [10, 10, 10, 10]]) == 37\n assert candidate(n = 1,k = 3,time = [[1, 1, 2, 1], [1, 1, 3, 1], [1, 1, 4, 1]]) == 6\n assert candidate(n = 5,k = 4,time = [[1, 2, 1, 2], [2, 2, 2, 2], [3, 2, 3, 3], [4, 2, 4, 4]]) == 34\n assert candidate(n = 15,k = 5,time = [[2, 3, 2, 2], [4, 4, 3, 3], [1, 2, 1, 1], [5, 5, 5, 5], [3, 3, 3, 3]]) == 115\n assert candidate(n = 10,k = 10,time = [[5, 1, 5, 1], [4, 2, 4, 2], [3, 3, 3, 3], [2, 4, 2, 4], [1, 5, 1, 5], [2, 3, 2, 3], [3, 2, 3, 2], [4, 1, 4, 1], [5, 4, 5, 4], [6, 5, 6, 5]]) == 110\n assert candidate(n = 20,k = 7,time = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 1, 3, 4], [3, 4, 1, 2], [1, 3, 4, 2], [5, 5, 5, 5], [2, 2, 2, 2]]) == 143\n assert candidate(n = 20,k = 5,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]) == 163\n assert candidate(n = 25,k = 4,time = [[10, 5, 15, 20], [5, 10, 10, 15], [20, 25, 30, 5], [15, 15, 10, 10]]) == 875\n assert candidate(n = 12,k = 6,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]) == 120\n assert candidate(n = 10,k = 5,time = [[1, 1, 1, 10], [2, 2, 2, 20], [3, 3, 3, 30], [4, 4, 4, 40], [5, 5, 5, 50]]) == 77\n assert candidate(n = 8,k = 4,time = [[10, 10, 1, 1], [5, 5, 2, 2], [3, 3, 3, 3], [1, 1, 5, 5]]) == 60\n assert candidate(n = 25,k = 3,time = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 255\n assert candidate(n = 20,k = 3,time = [[3, 2, 2, 1], [4, 3, 3, 2], [5, 4, 4, 3]]) == 160\n assert candidate(n = 50,k = 3,time = [[1, 10, 1, 1], [2, 9, 2, 2], [3, 8, 3, 3]]) == 288\n assert candidate(n = 15,k = 5,time = [[2, 1, 3, 2], [1, 2, 4, 1], [3, 1, 1, 3], [2, 2, 2, 2], [1, 1, 1, 1]]) == 74\n assert candidate(n = 10,k = 4,time = [[2, 5, 3, 2], [3, 5, 5, 2], [4, 5, 6, 2], [5, 5, 7, 2]]) == 107\n assert candidate(n = 15,k = 3,time = [[10, 10, 1, 1], [1, 10, 5, 10], [5, 5, 2, 2]]) == 142\n assert candidate(n = 25,k = 7,time = [[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]]) == 309\n assert candidate(n = 30,k = 6,time = [[5, 1, 5, 1], [3, 2, 3, 2], [2, 3, 2, 3], [1, 4, 1, 4], [4, 1, 4, 1], [6, 1, 6, 1]]) == 330\n assert candidate(n = 15,k = 5,time = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 1, 3, 4], [3, 4, 1, 2], [1, 3, 4, 2]]) == 80\n assert candidate(n = 50,k = 5,time = [[1, 1, 1, 10], [10, 1, 1, 1], [1, 10, 1, 1], [1, 1, 10, 1], [1, 1, 1, 1]]) == 550\n assert candidate(n = 10,k = 3,time = [[2, 3, 1, 2], [1, 2, 2, 3], [3, 2, 2, 1]]) == 40\n assert candidate(n = 20,k = 10,time = [[1, 2, 1, 2], [2, 1, 2, 1], [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]]) == 363\n assert candidate(n = 15,k = 5,time = [[3, 7, 2, 5], [5, 4, 2, 6], [1, 3, 1, 2], [4, 6, 3, 8], [2, 2, 2, 2]]) == 90\n assert candidate(n = 20,k = 4,time = [[5, 5, 5, 5], [4, 4, 4, 4], [3, 3, 3, 3], [2, 2, 2, 2]]) == 163\n assert candidate(n = 25,k = 4,time = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 3, 3, 1], [1, 4, 4, 1]]) == 99\n assert candidate(n = 50,k = 9,time = [[1, 1, 1, 1], [1, 2, 1, 2], [1, 3, 1, 3], [1, 4, 1, 4], [1, 5, 1, 5], [1, 6, 1, 6], [1, 7, 1, 7], [1, 8, 1, 8], [1, 9, 1, 9]]) == 115\n assert candidate(n = 40,k = 5,time = [[1, 1, 2, 2], [2, 2, 3, 3], [3, 3, 4, 4], [4, 4, 5, 5], [5, 5, 6, 6]]) == 367\n assert candidate(n = 8,k = 8,time = [[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]]) == 115\n assert candidate(n = 25,k = 6,time = [[2, 3, 2, 3], [3, 2, 3, 2], [1, 4, 1, 4], [4, 1, 4, 1], [5, 5, 5, 5], [6, 6, 6, 6]]) == 258\n assert candidate(n = 8,k = 8,time = [[1, 2, 3, 4], [8, 7, 6, 5], [1, 3, 5, 7], [2, 4, 6, 8], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == 72\n assert candidate(n = 100,k = 10,time = [[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]]) == 1812\n assert candidate(n = 40,k = 5,time = [[5, 10, 5, 10], [10, 5, 10, 5], [5, 10, 10, 5], [10, 5, 5, 10], [5, 5, 5, 5]]) == 700\n assert candidate(n = 15,k = 5,time = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]) == 150\n assert candidate(n = 12,k = 4,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == 72\n assert candidate(n = 20,k = 3,time = [[3, 1, 2, 1], [2, 2, 3, 2], [1, 3, 1, 3]]) == 100\n assert candidate(n = 5,k = 3,time = [[1, 1, 1, 100], [2, 2, 2, 90], [3, 3, 3, 80]]) == 107\n assert candidate(n = 30,k = 10,time = [[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], [3, 3, 3, 3], [3, 3, 3, 3]]) == 180\n assert candidate(n = 50,k = 5,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]) == 403\n assert candidate(n = 30,k = 8,time = [[1, 1, 1, 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]]) == 240\n assert candidate(n = 30,k = 7,time = [[1, 1, 1, 1], [1, 2, 1, 2], [1, 3, 1, 3], [1, 4, 1, 4], [1, 5, 1, 5], [1, 6, 1, 6], [1, 7, 1, 7]]) == 74\n assert candidate(n = 20,k = 3,time = [[10, 10, 10, 10], [15, 15, 15, 15], [5, 5, 5, 5]]) == 415\n assert candidate(n = 30,k = 10,time = [[1, 1, 1, 1], [1, 2, 1, 2], [2, 1, 2, 1], [1, 3, 1, 3], [2, 2, 2, 2], [1, 4, 1, 4], [2, 3, 2, 3], [3, 2, 3, 2], [3, 3, 3, 3], [4, 1, 4, 1]]) == 210\n assert candidate(n = 12,k = 6,time = [[5, 2, 3, 1], [2, 3, 4, 2], [1, 4, 5, 3], [3, 5, 1, 4], [2, 1, 4, 5], [4, 3, 2, 6]]) == 84\n assert candidate(n = 30,k = 7,time = [[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]]) == 420\n assert candidate(n = 20,k = 5,time = [[2, 3, 2, 1], [1, 1, 1, 1], [3, 2, 3, 2], [2, 2, 2, 2], [1, 3, 1, 3]]) == 100\n assert candidate(n = 18,k = 5,time = [[1, 1, 10, 10], [2, 2, 9, 9], [3, 3, 8, 8], [4, 4, 7, 7], [5, 5, 6, 6]]) == 198\n assert candidate(n = 18,k = 7,time = [[5, 3, 4, 2], [2, 1, 2, 1], [3, 2, 3, 2], [1, 5, 1, 5], [4, 4, 4, 4], [6, 6, 6, 6], [7, 7, 7, 7]]) == 210\n assert candidate(n = 100,k = 8,time = [[5, 5, 5, 5], [4, 4, 4, 4], [3, 3, 3, 3], [2, 2, 2, 2], [1, 1, 1, 1], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]]) == 1410\n assert candidate(n = 20,k = 4,time = [[10, 10, 1, 1], [1, 1, 10, 10], [5, 5, 5, 5], [2, 2, 2, 2]]) == 209\n assert candidate(n = 60,k = 12,time = [[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]]) == 1320\n assert candidate(n = 40,k = 8,time = [[2, 1, 3, 4], [4, 2, 1, 3], [1, 2, 2, 1], [3, 3, 3, 3], [5, 4, 4, 5], [2, 2, 2, 2], [3, 1, 2, 1], [4, 3, 1, 4]]) == 268\n assert candidate(n = 10,k = 6,time = [[1, 2, 3, 4], [4, 5, 6, 7], [7, 8, 9, 10], [10, 9, 8, 7], [8, 7, 6, 5], [5, 4, 3, 2]]) == 171\n assert candidate(n = 15,k = 3,time = [[5, 2, 3, 2], [3, 5, 3, 2], [2, 3, 4, 2]]) == 108\n assert candidate(n = 30,k = 6,time = [[2, 5, 3, 7], [3, 4, 2, 6], [4, 3, 5, 2], [1, 6, 4, 3], [5, 2, 1, 4], [6, 1, 3, 5]]) == 270\n assert candidate(n = 25,k = 4,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == 156\n assert candidate(n = 15,k = 3,time = [[2, 3, 4, 5], [1, 4, 3, 2], [3, 2, 5, 1]]) == 105\n assert candidate(n = 10,k = 4,time = [[1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 2, 1], [1, 1, 1, 3]]) == 25\n assert candidate(n = 25,k = 4,time = [[2, 1, 2, 1], [4, 2, 4, 2], [3, 3, 3, 3], [5, 5, 5, 5]]) == 207\n assert candidate(n = 25,k = 3,time = [[10, 1, 1, 1], [1, 10, 1, 1], [1, 1, 10, 1]]) == 276\n assert candidate(n = 30,k = 5,time = [[2, 2, 2, 2], [3, 3, 3, 3], [1, 1, 1, 1], [4, 4, 4, 4], [5, 5, 5, 5]]) == 240\n assert candidate(n = 15,k = 3,time = [[5, 1, 2, 1], [2, 1, 5, 2], [1, 1, 1, 1]]) == 106\n assert candidate(n = 100,k = 5,time = [[2, 3, 4, 1], [1, 2, 3, 1], [5, 3, 2, 1], [4, 1, 3, 2], [3, 2, 1, 5]]) == 700\n assert candidate(n = 10,k = 6,time = [[2, 3, 2, 3], [1, 1, 1, 1], [5, 5, 5, 5], [3, 2, 3, 2], [2, 5, 2, 5], [4, 4, 4, 4]]) == 87\n assert candidate(n = 25,k = 6,time = [[1, 5, 1, 8], [10, 10, 10, 10], [3, 2, 1, 4], [2, 1, 2, 3], [1, 4, 3, 2], [4, 3, 2, 1]]) == 178\n assert candidate(n = 6,k = 6,time = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]) == 60\n assert candidate(n = 15,k = 6,time = [[1, 1, 1, 10], [1, 1, 1, 9], [1, 1, 1, 8], [1, 1, 1, 7], [1, 1, 1, 6], [1, 1, 1, 5]]) == 31\n assert candidate(n = 100,k = 10,time = [[10, 10, 10, 10], [9, 9, 9, 9], [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]]) == 1812\n assert candidate(n = 8,k = 4,time = [[1, 4, 2, 3], [3, 2, 1, 4], [2, 3, 4, 1], [4, 1, 3, 2]]) == 52\n assert candidate(n = 12,k = 3,time = [[3, 3, 2, 2], [2, 2, 3, 3], [1, 1, 1, 1]]) == 49\n assert candidate(n = 7,k = 3,time = [[10, 5, 10, 5], [5, 10, 5, 10], [1, 1, 1, 1]]) == 115\n assert candidate(n = 12,k = 4,time = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 3, 4, 1], [3, 4, 1, 2]]) == 72\n assert candidate(n = 15,k = 4,time = [[5, 1, 1, 5], [1, 5, 5, 1], [3, 3, 3, 3], [2, 2, 2, 2]]) == 86\n assert candidate(n = 7,k = 7,time = [[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]]) == 93\n assert candidate(n = 25,k = 4,time = [[10, 10, 10, 10], [9, 9, 9, 9], [8, 8, 8, 8], [7, 7, 7, 7]]) == 462\n assert candidate(n = 20,k = 5,time = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 2, 2, 2], [3, 1, 4, 1], [5, 5, 5, 5]]) == 156\n assert candidate(n = 18,k = 5,time = [[1, 1, 10, 1], [1, 1, 9, 1], [1, 1, 8, 1], [1, 1, 7, 1], [1, 1, 6, 1]]) == 189\n assert candidate(n = 12,k = 6,time = [[3, 2, 1, 2], [2, 2, 2, 2], [1, 2, 3, 2], [4, 2, 4, 2], [5, 2, 5, 2], [6, 2, 6, 2]]) == 132\n assert candidate(n = 8,k = 6,time = [[1, 2, 1, 2], [2, 3, 2, 3], [3, 4, 3, 4], [4, 5, 4, 5], [5, 6, 5, 6], [6, 7, 6, 7]]) == 84\n assert candidate(n = 50,k = 10,time = [[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]]) == 903\n assert candidate(n = 20,k = 5,time = [[2, 3, 4, 5], [1, 2, 3, 4], [3, 1, 2, 1], [4, 4, 1, 3], [5, 5, 5, 5]]) == 145\n assert candidate(n = 20,k = 5,time = [[5, 2, 3, 2], [4, 3, 2, 5], [3, 5, 1, 3], [2, 4, 1, 4], [1, 6, 2, 6]]) == 140\n assert candidate(n = 10,k = 3,time = [[1, 2, 1, 2], [2, 3, 2, 3], [3, 4, 3, 4]]) == 52\n", "comparison": "exact"}, "public_tests": ["1\n3\n[[1,1,2,1],[1,1,3,1],[1,1,4,1]]", "3\n2\n[[1,9,1,8],[10,10,10,10]]"], "hints": ["Try simulating this process.", "We can use a priority queue to query over the least efficient worker."], "metadata": {"canonical_parameter_names": ["n", "k", "time"], "leetcode_dataset_entry_point": "Solution().findCrossingTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:09+00:00", "tests_total": 100, "tests_dropped": 3, "flags": ["has_images"], "topic_tags": ["array", "heap-priority-queue", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_crossing_time(n, k, time)", "container": null, "callable": "find_crossing_time", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}, {"name": "time", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2535, "task_id": "difference-between-element-sum-and-digit-sum-of-an-array", "difficulty": "Easy", "problem_description": "You are given a positive integer array nums.\n\n- The element sum is the sum of all the elements in nums.\n- The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.\n\nReturn the absolute difference between the element sum and digit sum of nums.\n\nNote that the absolute difference between two integers x and y is defined as |x - y|.\n\nExample 1:\n\nInput: nums = [1,15,6,3]\nOutput: 9\nExplanation:\nThe element sum of nums is 1 + 15 + 6 + 3 = 25.\nThe digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.\nThe absolute difference between the element sum and digit sum is |25 - 16| = 9.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 0\nExplanation:\nThe element sum of nums is 1 + 2 + 3 + 4 = 10.\nThe digit sum of nums is 1 + 2 + 3 + 4 = 10.\nThe absolute difference between the element sum and digit sum is |10 - 10| = 0.\n\nConstraints:\n\n- 1 <= nums.length <= 2000\n- 1 <= nums[i] <= 2000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 11, 12, 13]) == 36\n assert candidate(nums = [1, 15, 6, 3]) == 9\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [10, 100, 1000]) == 1107\n assert candidate(nums = [1, 2, 3, 4]) == 0\n assert candidate(nums = [5, 12, 43, 78]) == 108\n assert candidate(nums = [123, 456, 789, 101, 111]) == 1530\n assert candidate(nums = [2000, 1999, 1000, 999]) == 5940\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 504\n assert candidate(nums = [999, 1000, 1001]) == 2970\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [123, 456, 789]) == 1323\n assert candidate(nums = [2000, 1000, 500, 250]) == 3735\n assert candidate(nums = [10, 20, 30, 40, 50]) == 135\n assert candidate(nums = [18, 46, 89, 37]) == 144\n assert candidate(nums = [2000, 1999, 1998, 1997]) == 7911\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [2000, 1111, 999, 888]) == 4941\n assert candidate(nums = [111, 222, 333]) == 648\n assert candidate(nums = [10, 20, 30, 40]) == 90\n assert candidate(nums = [555, 666, 777, 888, 999, 1000]) == 4779\n assert candidate(nums = [123, 456, 789, 101, 112, 123, 134, 145, 156, 167, 178, 189]) == 2538\n assert candidate(nums = [999, 888, 777, 666, 555, 444, 333, 222, 111]) == 4860\n assert candidate(nums = [1999, 1888, 1777, 1666, 1555, 1444, 1333, 1222, 1111]) == 13851\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980]) == 19350\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1010, 1111]) == 6975\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 5454\n assert candidate(nums = [1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990]) == 19710\n assert candidate(nums = [1999, 1998, 1997, 1996, 1995, 1994]) == 11826\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993]) == 15795\n assert candidate(nums = [2000, 2000, 2000, 2000, 2000]) == 9990\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981]) == 39366\n assert candidate(nums = [987, 654, 321, 111, 222]) == 2241\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991]) == 19737\n assert candidate(nums = [2000, 1500, 1000, 500, 250]) == 5229\n assert candidate(nums = [1, 234, 567, 890, 432, 765, 109, 876, 543, 210]) == 4509\n assert candidate(nums = [987, 654, 321, 999, 888]) == 3753\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005]) == 5994\n assert candidate(nums = [19, 28, 37, 46, 55, 64, 73, 82, 91]) == 405\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1000]) == 5859\n assert candidate(nums = [987, 654, 321, 876, 543, 210, 765, 432, 109]) == 4779\n assert candidate(nums = [2000, 1000, 500, 250, 125]) == 3852\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 4860\n assert candidate(nums = [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]) == 9999\n assert candidate(nums = [500, 400, 300, 200, 100, 99, 98, 97, 96, 95]) == 1890\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995]) == 11853\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1971\n assert candidate(nums = [2000, 1500, 1000, 500, 100]) == 5085\n assert candidate(nums = [999, 111, 222, 333, 444, 555, 666, 777, 888]) == 4860\n assert candidate(nums = [1999, 1998, 1997, 1996, 1995, 1994, 1993]) == 13797\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909]) == 4455\n assert candidate(nums = [1999, 1888, 1777, 1666, 1555, 1444, 1333, 1222, 1111, 1000]) == 14850\n assert candidate(nums = [123, 456, 789, 321, 654, 987, 159, 753, 951, 842]) == 5886\n assert candidate(nums = [1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509]) == 14940\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992]) == 17766\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 108\n assert candidate(nums = [2000, 1500, 1000, 500, 100, 50, 10, 5, 1]) == 5139\n assert candidate(nums = [123, 456, 789, 1011, 1213]) == 3537\n assert candidate(nums = [150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]) == 5904\n", "comparison": "exact"}, "public_tests": ["[1,15,6,3]", "[1,2,3,4]"], "hints": ["Use a simple for loop to iterate each number.", "How you can get the digit for each number?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().differenceOfSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:16+00:00", "tests_total": 99, "tests_dropped": 39, "flags": [], "topic_tags": ["array", "math"]}, "language": "ruby", "interface": {"raw_signature": "def difference_of_sum(nums)", "container": null, "callable": "difference_of_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2536, "task_id": "increment-submatrices-by-one", "difficulty": "Medium", "problem_description": "You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.\n\nYou are also given a 2D integer array query. For each query[i] = [row1_i, col1_i, row2_i, col2_i], you should do the following operation:\n\n- Add 1 to every element in the submatrix with the top left corner (row1_i, col1_i) and the bottom right corner (row2_i, col2_i). That is, add 1 to mat[x][y] for all row1_i <= x <= row2_i and col1_i <= y <= col2_i.\n\nReturn the matrix mat after performing every query.\n\nExample 1:\n\nInput: n = 3, queries = [[1,1,2,2],[0,0,1,1]]\nOutput: [[1,1,0],[1,2,1],[0,1,1]]\nExplanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.\n- In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).\n- In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).\n\nExample 2:\n\nInput: n = 2, queries = [[0,0,1,1]]\nOutput: [[1,1],[1,1]]\nExplanation: The diagram above shows the initial matrix and the matrix after the first query.\n- In the first query we add 1 to every element in the matrix.\n\nConstraints:\n\n- 1 <= n <= 500\n- 1 <= queries.length <= 10^4\n- 0 <= row1_i <= row2_i < n\n- 0 <= col1_i <= col2_i < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,queries = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]\n assert candidate(n = 1,queries = [[0, 0, 0, 0]]) == [[1]]\n assert candidate(n = 5,queries = [[0, 0, 4, 4], [1, 1, 3, 3], [2, 2, 2, 2]]) == [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]\n assert candidate(n = 3,queries = [[0, 0, 2, 2], [1, 1, 1, 1], [0, 1, 1, 2]]) == [[1, 2, 2], [1, 3, 2], [1, 1, 1]]\n assert candidate(n = 4,queries = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]) == [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [0, 0, 3, 3], [0, 0, 3, 3]]) == [[3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [1, 1, 2, 2], [2, 2, 3, 3]]) == [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 3, 2], [1, 1, 2, 2]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [1, 1, 2, 2], [0, 0, 1, 1]]) == [[2, 2, 1, 1], [2, 3, 2, 1], [1, 2, 2, 1], [1, 1, 1, 1]]\n assert candidate(n = 2,queries = [[0, 0, 1, 1]]) == [[1, 1], [1, 1]]\n assert candidate(n = 3,queries = [[1, 1, 2, 2], [0, 0, 1, 1]]) == [[1, 1, 0], [1, 2, 1], [0, 1, 1]]\n assert candidate(n = 5,queries = [[0, 0, 2, 2], [2, 2, 4, 4], [1, 1, 3, 3], [0, 2, 0, 4], [4, 0, 4, 2]]) == [[1, 1, 2, 1, 1], [1, 2, 2, 1, 0], [1, 2, 3, 2, 1], [0, 1, 2, 2, 1], [1, 1, 2, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [1, 1, 8, 8], [2, 2, 7, 7], [3, 3, 6, 6], [4, 4, 5, 5], [5, 5, 5, 5]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 4, 4], [4, 4, 8, 8], [8, 8, 9, 9], [0, 0, 9, 0], [9, 0, 9, 9], [0, 9, 9, 9]]) == [[2, 1, 1, 1, 1, 0, 0, 0, 0, 1], [2, 1, 1, 1, 1, 0, 0, 0, 0, 1], [2, 1, 1, 1, 1, 0, 0, 0, 0, 1], [2, 1, 1, 1, 1, 0, 0, 0, 0, 1], [2, 1, 1, 1, 2, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 1, 1, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2, 3]]\n assert candidate(n = 8,queries = [[0, 0, 7, 7], [1, 1, 6, 6], [2, 2, 5, 5], [3, 3, 4, 4], [0, 0, 3, 3], [4, 4, 7, 7], [1, 2, 5, 6], [2, 3, 4, 5]]) == [[2, 2, 2, 2, 1, 1, 1, 1], [2, 3, 4, 4, 3, 3, 3, 1], [2, 3, 5, 6, 5, 5, 3, 1], [2, 3, 5, 7, 6, 5, 3, 1], [1, 2, 4, 6, 7, 6, 4, 2], [1, 2, 4, 4, 5, 5, 4, 2], [1, 2, 2, 2, 3, 3, 3, 2], [1, 1, 1, 1, 2, 2, 2, 2]]\n assert candidate(n = 3,queries = [[0, 0, 2, 2], [1, 1, 1, 1], [0, 1, 1, 2], [2, 0, 2, 0]]) == [[1, 2, 2], [1, 3, 2], [2, 1, 1]]\n assert candidate(n = 3,queries = [[0, 0, 0, 0], [0, 1, 0, 1], [0, 2, 0, 2], [1, 0, 1, 0], [1, 1, 1, 1], [1, 2, 1, 2], [2, 0, 2, 0], [2, 1, 2, 1], [2, 2, 2, 2]]) == [[1, 1, 1], [1, 1, 1], [1, 1, 1]]\n assert candidate(n = 3,queries = [[0, 0, 2, 2], [0, 0, 2, 1], [0, 1, 2, 2], [1, 0, 2, 1], [1, 1, 2, 2], [0, 0, 0, 0]]) == [[3, 3, 2], [3, 5, 3], [3, 5, 3]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [1, 1, 8, 8], [2, 2, 7, 7], [3, 3, 6, 6], [4, 4, 5, 5], [5, 5, 5, 5], [0, 0, 9, 9], [1, 1, 8, 8]]) == [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 4, 4, 4, 4, 4, 4, 4, 4, 2], [2, 4, 5, 5, 5, 5, 5, 5, 4, 2], [2, 4, 5, 6, 6, 6, 6, 5, 4, 2], [2, 4, 5, 6, 7, 7, 6, 5, 4, 2], [2, 4, 5, 6, 7, 8, 6, 5, 4, 2], [2, 4, 5, 6, 6, 6, 6, 5, 4, 2], [2, 4, 5, 5, 5, 5, 5, 5, 4, 2], [2, 4, 4, 4, 4, 4, 4, 4, 4, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]]\n assert candidate(n = 20,queries = [[0, 0, 19, 19], [5, 5, 14, 14], [10, 10, 10, 10], [3, 3, 16, 16], [8, 8, 11, 11]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1], [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 4, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1], [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 30,queries = [[0, 0, 29, 29], [0, 0, 0, 29], [29, 0, 29, 29], [0, 29, 29, 29], [15, 15, 15, 15], [14, 14, 16, 16], [10, 10, 20, 20]]) == [[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, 2, 2, 2, 2, 3], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 4, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 3]]\n assert candidate(n = 5,queries = [[0, 0, 4, 4], [0, 1, 3, 4], [1, 0, 4, 3], [1, 1, 3, 3], [2, 2, 2, 2]]) == [[1, 2, 2, 2, 2], [2, 4, 4, 4, 2], [2, 4, 5, 4, 2], [2, 4, 4, 4, 2], [2, 2, 2, 2, 1]]\n assert candidate(n = 3,queries = [[0, 0, 2, 2], [0, 1, 1, 2], [1, 0, 2, 1]]) == [[1, 2, 2], [2, 3, 2], [2, 2, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [0, 0, 0, 9], [9, 0, 9, 9], [0, 9, 9, 9], [5, 5, 5, 5], [4, 4, 6, 6]]) == [[2, 2, 2, 2, 2, 2, 2, 2, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 2, 2, 2, 1, 1, 2], [1, 1, 1, 1, 2, 3, 2, 1, 1, 2], [1, 1, 1, 1, 2, 2, 2, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [0, 0, 1, 1], [2, 2, 3, 3], [1, 2, 2, 3], [1, 1, 2, 2]]) == [[2, 2, 1, 1], [2, 3, 3, 2], [1, 2, 4, 3], [1, 1, 2, 2]]\n assert candidate(n = 5,queries = [[0, 0, 4, 4], [1, 1, 3, 3], [2, 2, 2, 2], [0, 4, 0, 4], [4, 0, 4, 4], [3, 1, 3, 3]]) == [[1, 1, 1, 1, 2], [1, 2, 2, 2, 1], [1, 2, 3, 2, 1], [1, 3, 3, 3, 1], [2, 2, 2, 2, 2]]\n assert candidate(n = 10,queries = [[0, 0, 0, 0], [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]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]\n assert candidate(n = 3,queries = [[0, 0, 2, 0], [0, 1, 2, 1], [0, 2, 2, 2], [1, 0, 1, 2], [2, 0, 2, 2], [0, 0, 2, 2]]) == [[2, 2, 2], [3, 3, 3], [3, 3, 3]]\n assert candidate(n = 3,queries = [[0, 0, 2, 2], [0, 1, 0, 1], [1, 0, 1, 0], [1, 2, 1, 2], [2, 1, 2, 1]]) == [[1, 2, 1], [2, 1, 2], [1, 2, 1]]\n assert candidate(n = 100,queries = [[0, 0, 99, 99], [25, 25, 74, 74], [50, 50, 49, 49], [0, 50, 49, 99], [50, 0, 99, 49], [25, 25, 74, 74]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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], [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, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 2, 2, 2, 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, 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, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 5, 5], [1, 2, 4, 3], [2, 3, 4, 2], [3, 1, 3, 1], [4, 2, 4, 4]]) == [[1, 1, 1, 1, 1, 1], [1, 1, 2, 2, 1, 1], [1, 1, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1], [1, 1, 3, 3, 2, 1], [1, 1, 1, 1, 1, 1]]\n assert candidate(n = 4,queries = [[0, 0, 1, 1], [1, 1, 2, 2], [2, 2, 3, 3], [0, 2, 1, 3]]) == [[1, 1, 1, 1], [1, 2, 2, 1], [0, 1, 2, 1], [0, 0, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 5, 5], [1, 1, 4, 4], [2, 2, 3, 3], [0, 2, 2, 4], [3, 0, 5, 2]]) == [[1, 1, 2, 2, 2, 1], [1, 2, 3, 3, 3, 1], [1, 2, 4, 4, 3, 1], [2, 3, 4, 3, 2, 1], [2, 3, 3, 2, 2, 1], [2, 2, 2, 1, 1, 1]]\n assert candidate(n = 4,queries = [[0, 0, 1, 1], [1, 1, 2, 2], [2, 2, 3, 3], [0, 3, 1, 3]]) == [[1, 1, 0, 1], [1, 2, 1, 1], [0, 1, 2, 1], [0, 0, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]) == [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [1, 1, 2, 2], [0, 1, 1, 2], [2, 3, 3, 3], [0, 0, 1, 3], [2, 2, 3, 3], [0, 2, 1, 3], [1, 0, 2, 1]]) == [[2, 3, 4, 3], [3, 5, 5, 3], [2, 3, 3, 3], [1, 1, 2, 3]]\n assert candidate(n = 10,queries = [[0, 0, 4, 4], [5, 5, 9, 9], [0, 5, 4, 9], [5, 0, 9, 4], [2, 2, 7, 7], [3, 3, 8, 8], [6, 6, 9, 9], [1, 1, 8, 8]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 3, 1], [1, 2, 3, 4, 4, 4, 4, 4, 3, 1], [1, 2, 3, 4, 4, 4, 4, 4, 3, 1], [1, 2, 3, 4, 4, 4, 5, 5, 4, 2], [1, 2, 3, 4, 4, 4, 5, 5, 4, 2], [1, 2, 2, 3, 3, 3, 4, 4, 4, 2], [1, 1, 1, 1, 1, 1, 2, 2, 2, 2]]\n assert candidate(n = 7,queries = [[0, 0, 6, 6], [1, 1, 5, 5], [2, 2, 4, 4], [0, 3, 2, 5], [4, 2, 6, 5], [1, 0, 3, 3]]) == [[1, 1, 1, 2, 2, 2, 1], [2, 3, 3, 4, 3, 3, 1], [2, 3, 4, 5, 4, 3, 1], [2, 3, 4, 4, 3, 2, 1], [1, 2, 4, 4, 4, 3, 1], [1, 2, 3, 3, 3, 3, 1], [1, 1, 2, 2, 2, 2, 1]]\n assert candidate(n = 100,queries = [[0, 0, 99, 99], [50, 50, 99, 99], [0, 0, 49, 49], [50, 50, 50, 50]]) == [[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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [1, 1, 8, 8], [2, 2, 7, 7], [3, 3, 6, 6], [4, 4, 5, 5], [5, 5, 4, 4], [6, 6, 3, 3], [7, 7, 2, 2], [8, 8, 1, 1], [9, 9, 0, 0]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 3, 3, 3, 3, 3, 3, 3, 3, 1], [1, 3, 5, 5, 5, 5, 5, 5, 3, 1], [1, 3, 5, 7, 7, 7, 7, 5, 3, 1], [1, 3, 5, 7, 9, 9, 7, 5, 3, 1], [1, 3, 5, 7, 9, 9, 7, 5, 3, 1], [1, 3, 5, 7, 7, 7, 7, 5, 3, 1], [1, 3, 5, 5, 5, 5, 5, 5, 3, 1], [1, 3, 3, 3, 3, 3, 3, 3, 3, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 2, 2], [2, 2, 4, 4], [4, 4, 1, 1], [1, 1, 3, 3], [3, 3, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0], [2, 2, 3, 3], [3, 3, 2, 2], [4, 4, 5, 5], [5, 5, 4, 4]]) == [[2, 2, 1, 0, 0, 0], [2, 4, 3, 1, 0, 0], [1, 3, 6, 4, 1, 0], [0, 1, 4, 4, 1, 0], [0, 0, 1, 1, 2, 1], [0, 0, 0, 0, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 1], [1, 1, 8, 2], [2, 2, 7, 3], [3, 3, 6, 4], [4, 4, 5, 5]]) == [[1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0, 0, 0, 0, 0], [1, 2, 2, 2, 1, 0, 0, 0, 0, 0], [1, 2, 2, 2, 2, 1, 0, 0, 0, 0], [1, 2, 2, 2, 2, 1, 0, 0, 0, 0], [1, 2, 2, 2, 1, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(n = 50,queries = [[0, 0, 49, 49], [0, 0, 0, 49], [49, 0, 49, 49], [0, 49, 49, 49], [25, 25, 25, 25], [24, 24, 26, 26], [15, 15, 35, 35]]) == [[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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 2, 2, 2, 3]]\n assert candidate(n = 4,queries = [[0, 0, 1, 1], [1, 1, 3, 3], [0, 2, 2, 3], [2, 0, 3, 1]]) == [[1, 1, 1, 1], [1, 2, 2, 2], [1, 2, 2, 2], [1, 2, 1, 1]]\n assert candidate(n = 4,queries = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [0, 1, 1, 0], [1, 2, 2, 1], [2, 3, 3, 2], [3, 0, 0, 3]]) == [[1, 0, 0, 0], [-1, 0, -1, -1], [-1, -1, 0, -1], [0, 0, 0, 1]]\n assert candidate(n = 20,queries = [[0, 0, 19, 19], [1, 1, 18, 18], [2, 2, 17, 17], [3, 3, 16, 16], [4, 4, 15, 15], [5, 5, 14, 14], [6, 6, 13, 13], [7, 7, 12, 12], [8, 8, 11, 11], [9, 9, 10, 10]]) == [[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, 1], [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 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], [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, 9, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 5, 5], [1, 2, 4, 4], [2, 3, 3, 5], [0, 0, 2, 2], [3, 3, 5, 5]]) == [[2, 2, 2, 1, 1, 1], [2, 2, 3, 2, 2, 1], [2, 2, 3, 3, 3, 2], [1, 1, 2, 4, 4, 3], [1, 1, 2, 3, 3, 2], [1, 1, 1, 2, 2, 2]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [2, 2, 7, 7], [5, 5, 5, 5]]) == [[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, 1, 1], [1, 1, 2, 2, 2, 2, 2, 2, 1, 1], [1, 1, 2, 2, 2, 2, 2, 2, 1, 1], [1, 1, 2, 2, 2, 3, 2, 2, 1, 1], [1, 1, 2, 2, 2, 2, 2, 2, 1, 1], [1, 1, 2, 2, 2, 2, 2, 2, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [0, 0, 8, 8], [1, 1, 7, 7], [2, 2, 6, 6], [3, 3, 5, 5], [4, 4, 4, 4]]) == [[2, 2, 2, 2, 2, 2, 2, 2, 2, 1], [2, 3, 3, 3, 3, 3, 3, 3, 2, 1], [2, 3, 4, 4, 4, 4, 4, 3, 2, 1], [2, 3, 4, 5, 5, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 5, 5, 4, 3, 2, 1], [2, 3, 4, 4, 4, 4, 4, 3, 2, 1], [2, 3, 3, 3, 3, 3, 3, 3, 2, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 50,queries = [[0, 0, 49, 49], [10, 10, 39, 39], [25, 25, 25, 25], [15, 15, 35, 35], [20, 20, 29, 29], [5, 5, 44, 44]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [2, 2, 7, 7], [3, 3, 6, 6], [5, 5, 5, 5]]) == [[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, 1, 1], [1, 1, 2, 3, 3, 3, 3, 2, 1, 1], [1, 1, 2, 3, 3, 3, 3, 2, 1, 1], [1, 1, 2, 3, 3, 4, 3, 2, 1, 1], [1, 1, 2, 3, 3, 3, 3, 2, 1, 1], [1, 1, 2, 2, 2, 2, 2, 2, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 7,queries = [[0, 0, 6, 6], [1, 1, 5, 5], [2, 2, 4, 4], [3, 3, 3, 3], [0, 3, 3, 0]]) == [[1, 0, 0, 1, 1, 1, 1], [1, 1, 1, 2, 2, 2, 1], [1, 1, 2, 3, 3, 2, 1], [1, 1, 2, 4, 3, 2, 1], [1, 2, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 8,queries = [[0, 0, 7, 7], [1, 1, 6, 6], [2, 2, 5, 5], [3, 3, 4, 4], [0, 7, 7, 0], [1, 6, 6, 1], [2, 5, 5, 2], [3, 4, 4, 3]]) == [[1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [1, 1, 8, 8], [2, 2, 7, 7], [3, 3, 6, 6], [4, 4, 5, 5]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 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, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 5, 5], [0, 0, 2, 2], [3, 3, 5, 5], [1, 1, 4, 4], [0, 3, 2, 5], [3, 0, 5, 2], [1, 2, 4, 3], [2, 1, 3, 4]]) == [[2, 2, 2, 2, 2, 2], [2, 3, 4, 4, 3, 2], [2, 4, 5, 5, 4, 2], [2, 4, 5, 5, 4, 2], [2, 3, 4, 4, 3, 2], [2, 2, 2, 2, 2, 2]]\n assert candidate(n = 8,queries = [[0, 0, 7, 7], [1, 1, 6, 6], [2, 2, 5, 5], [3, 3, 4, 4], [0, 2, 1, 5], [6, 2, 7, 7]]) == [[1, 1, 2, 2, 2, 2, 1, 1], [1, 2, 3, 3, 3, 3, 2, 1], [1, 2, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 3, 2, 1], [1, 2, 3, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 2], [1, 1, 2, 2, 2, 2, 2, 2]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [1, 1, 2, 2], [0, 1, 1, 3], [2, 0, 3, 1]]) == [[1, 2, 2, 2], [1, 3, 3, 2], [2, 3, 2, 1], [2, 2, 1, 1]]\n assert candidate(n = 100,queries = [[0, 0, 99, 99], [0, 0, 0, 99], [99, 0, 99, 99], [0, 99, 99, 99], [50, 50, 50, 50], [49, 49, 51, 51], [30, 30, 70, 70]]) == [[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, 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, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 3, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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, 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, 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, 2, 2, 2, 3]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [1, 1, 2, 2], [2, 2, 3, 3], [0, 1, 2, 3], [1, 0, 3, 2]]) == [[1, 2, 2, 2], [2, 4, 4, 2], [2, 4, 5, 3], [2, 2, 3, 2]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [1, 1, 2, 2], [0, 2, 1, 3], [2, 0, 3, 1]]) == [[1, 1, 2, 2], [1, 2, 3, 2], [2, 3, 2, 1], [2, 2, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 0, 9], [1, 1, 1, 8], [2, 2, 2, 7], [3, 3, 3, 6], [4, 4, 4, 5], [5, 5, 5, 5]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(n = 5,queries = [[0, 0, 4, 0], [0, 1, 0, 4], [4, 0, 4, 4], [2, 2, 2, 2], [3, 3, 3, 3]]) == [[1, 1, 1, 1, 1], [1, 0, 0, 0, 0], [1, 0, 1, 0, 0], [1, 0, 0, 1, 0], [2, 1, 1, 1, 1]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [2, 2, 7, 7], [4, 4, 5, 5], [1, 1, 8, 8], [6, 6, 9, 9]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 3, 4, 4, 3, 3, 2, 1], [1, 2, 3, 3, 4, 4, 3, 3, 2, 1], [1, 2, 3, 3, 3, 3, 4, 4, 3, 2], [1, 2, 3, 3, 3, 3, 4, 4, 3, 2], [1, 2, 2, 2, 2, 2, 3, 3, 3, 2], [1, 1, 1, 1, 1, 1, 2, 2, 2, 2]]\n assert candidate(n = 10,queries = [[0, 0, 9, 9], [1, 1, 8, 8], [2, 2, 7, 7], [3, 3, 6, 6], [4, 4, 5, 5], [0, 5, 5, 0], [5, 0, 0, 5]]) == [[1, 0, 0, 0, 0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 1, 2, 2, 2, 1], [0, 0, 1, 1, 1, 2, 3, 3, 2, 1], [0, 0, 1, 2, 2, 3, 4, 3, 2, 1], [0, 0, 1, 2, 3, 4, 4, 3, 2, 1], [1, 1, 2, 3, 4, 5, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 9,queries = [[0, 0, 8, 8], [1, 2, 7, 6], [2, 3, 5, 4], [3, 4, 4, 5], [4, 5, 5, 6], [5, 6, 6, 7], [6, 7, 7, 8]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 2, 2, 2, 2, 2, 1, 1], [1, 1, 2, 3, 3, 2, 2, 1, 1], [1, 1, 2, 3, 4, 3, 2, 1, 1], [1, 1, 2, 3, 4, 4, 3, 1, 1], [1, 1, 2, 3, 3, 3, 4, 2, 1], [1, 1, 2, 2, 2, 2, 3, 3, 2], [1, 1, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 15,queries = [[0, 0, 14, 14], [1, 1, 13, 13], [2, 2, 12, 12], [3, 3, 11, 11], [4, 4, 10, 10], [5, 5, 9, 9]]) == [[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, 1], [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 5,queries = [[0, 0, 0, 4], [1, 1, 1, 3], [2, 2, 2, 2], [3, 3, 3, 4], [4, 4, 4, 4]]) == [[1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]]\n assert candidate(n = 50,queries = [[0, 0, 49, 49], [10, 10, 39, 39], [20, 20, 29, 29], [5, 5, 44, 44], [15, 15, 34, 34]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [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, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 6,queries = [[0, 0, 2, 2], [1, 1, 4, 4], [2, 2, 5, 5], [3, 3, 5, 5], [0, 3, 2, 3], [1, 4, 3, 4]]) == [[1, 1, 1, 1, 0, 0], [1, 2, 2, 2, 2, 0], [1, 2, 3, 3, 3, 1], [0, 1, 2, 3, 4, 2], [0, 1, 2, 3, 3, 2], [0, 0, 1, 2, 2, 2]]\n assert candidate(n = 8,queries = [[0, 0, 7, 7], [0, 2, 6, 6], [2, 0, 5, 5], [3, 3, 3, 3], [4, 4, 4, 4]]) == [[1, 1, 2, 2, 2, 2, 2, 1], [1, 1, 2, 2, 2, 2, 2, 1], [2, 2, 3, 3, 3, 3, 2, 1], [2, 2, 3, 4, 3, 3, 2, 1], [2, 2, 3, 3, 4, 3, 2, 1], [2, 2, 3, 3, 3, 3, 2, 1], [1, 1, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 4,queries = [[0, 0, 3, 3], [0, 0, 1, 1], [1, 1, 2, 2], [2, 2, 3, 3], [0, 3, 3, 3], [3, 0, 3, 0]]) == [[2, 2, 1, 2], [2, 3, 2, 2], [1, 2, 3, 3], [2, 1, 2, 3]]\n assert candidate(n = 15,queries = [[0, 0, 14, 14], [1, 1, 13, 13], [2, 2, 12, 12], [3, 3, 11, 11], [4, 4, 10, 10], [5, 5, 9, 9], [6, 6, 8, 8]]) == [[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, 1], [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 7, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 7, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 7, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(n = 20,queries = [[0, 0, 19, 19], [5, 5, 14, 14], [10, 10, 15, 15], [0, 10, 9, 19], [10, 0, 19, 9]]) == [[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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [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, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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]]\n assert candidate(n = 3,queries = [[0, 0, 2, 2], [0, 1, 2, 1], [1, 0, 1, 2], [2, 0, 2, 2], [0, 0, 0, 0]]) == [[2, 2, 1], [2, 3, 2], [2, 3, 2]]\n", "comparison": "exact"}, "public_tests": ["3\n[[1,1,2,2],[0,0,1,1]]", "2\n[[0,0,1,1]]"], "hints": ["Imagine each row as a separate array. Instead of updating the whole submatrix together, we can use prefix sum to update each row separately.", "For each query, iterate over the rows i in the range [row1, row2] and add 1 to prefix sum S[i][col1], and subtract 1 from S[i][col2 + 1].", "After doing this operation for all the queries, update each row separately with S[i][j] = S[i][j] + S[i][j - 1]."], "metadata": {"canonical_parameter_names": ["n", "queries"], "leetcode_dataset_entry_point": "Solution().rangeAddQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:19+00:00", "tests_total": 73, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def range_add_queries(n, queries)", "container": null, "callable": "range_add_queries", "parameters": [{"name": "n", "type": "Integer"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2537, "task_id": "count-the-number-of-good-subarrays", "difficulty": "Medium", "problem_description": "Given an integer array nums and an integer k, return the number of good subarrays of nums.\n\nA subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,1,1,1,1], k = 10\nOutput: 1\nExplanation: The only good subarray is the array nums itself.\n\nExample 2:\n\nInput: nums = [3,1,4,3,2,2,4], k = 2\nOutput: 4\nExplanation: There are 4 different good subarrays:\n- [3,1,4,3,2,2] that has 2 pairs.\n- [3,1,4,3,2,2,4] that has 3 pairs.\n- [1,4,3,2,2,4] that has 2 pairs.\n- [4,3,2,2,4] that has 2 pairs.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i], k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 15) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 0\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10],k = 3) == 3\n assert candidate(nums = [10, 10, 10, 1, 1, 1, 1, 1, 1, 1],k = 5) == 23\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 5\n assert candidate(nums = [10, 20, 30, 10, 20, 30],k = 3) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 5) == 15\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3],k = 10) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],k = 5) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 20) == 10\n assert candidate(nums = [3, 1, 4, 3, 2, 2, 4],k = 2) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 25) == 6\n assert candidate(nums = [1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(nums = [1],k = 1) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 9) == 3\n assert candidate(nums = [1, 3, 2, 1, 3, 1, 3],k = 3) == 3\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) == 36\n assert candidate(nums = [1, 1],k = 1) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 50) == 55\n assert candidate(nums = [10, 20, 10, 20, 10],k = 4) == 1\n assert candidate(nums = [1, 2, 1, 3, 4, 2, 1, 2, 1],k = 2) == 12\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],k = 6) == 22\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 0\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1],k = 5) == 6\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 200) == 153\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 40) == 0\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4],k = 10) == 2\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 = 15) == 78\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50],k = 10) == 6\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 10) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 15) == 0\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],k = 40) == 0\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],k = 100) == 1\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],k = 20) == 120\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 = 5) == 21\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 0\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],k = 25) == 68\n assert candidate(nums = [10, 20, 10, 20, 30, 10, 20, 30, 40, 10, 20],k = 8) == 3\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4],k = 20) == 20\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 = 10) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 10) == 36\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],k = 30) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2],k = 10) == 14\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 28\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 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, 7],k = 60) == 37\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],k = 30) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3],k = 5) == 36\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 20) == 25\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 25) == 55\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],k = 30) == 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 = 1) == 55\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],k = 30) == 47\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],k = 50) == 0\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],k = 60) == 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],k = 100) == 21\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 45) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500],k = 10) == 6\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],k = 30) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 6) == 0\n assert candidate(nums = [10, 10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40],k = 40) == 0\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30],k = 30) == 28\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],k = 30) == 28\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 = 5) == 21\n assert candidate(nums = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 20) == 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 = 30) == 45\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2],k = 15) == 82\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 10) == 55\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 25) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 30) == 78\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],k = 15) == 22\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 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],k = 5) == 66\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 25) == 0\n assert candidate(nums = [1, 2, 2, 1, 1, 3, 3, 3, 2, 2, 1, 1],k = 6) == 15\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1],k = 5) == 10\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],k = 50) == 0\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2],k = 5) == 15\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13],k = 10) == 128\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],k = 150) == 351\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6],k = 15) == 78\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 1, 2, 2, 1, 3, 3, 3, 1, 2, 2, 1, 3, 3, 3, 1, 2, 2, 1, 3, 3, 3, 1, 2, 2],k = 35) == 136\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3],k = 10) == 28\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 = 100) == 21\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6],k = 20) == 28\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 25) == 73\n assert candidate(nums = [7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 20) == 15\n assert candidate(nums = [1, 2, 2, 1, 1, 1, 2, 1, 1],k = 5) == 12\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],k = 5) == 136\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 = 10) == 91\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],k = 25) == 28\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 1\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],k = 5) == 21\n assert candidate(nums = [7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10],k = 25) == 10\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],k = 25) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 30) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 1\n assert candidate(nums = [7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10],k = 18) == 0\n assert candidate(nums = [7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10],k = 25) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 100) == 153\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],k = 40) == 12\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 1, 2, 2, 1],k = 5) == 15\n assert candidate(nums = [10, 10, 20, 20, 20, 30, 30, 30, 30, 30],k = 15) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 0\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],k = 50) == 0\n assert candidate(nums = [7, 7, 7, 8, 8, 9, 9, 7, 7, 7],k = 10) == 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],k = 15) == 21\n assert candidate(nums = [1, 2, 2, 1, 1, 3, 3, 3, 4, 4, 4, 4],k = 5) == 24\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],k = 50) == 3\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 = 15) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 15) == 11\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],k = 40) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 3\n assert candidate(nums = [10, 20, 10, 30, 20, 10, 40, 30, 20, 10],k = 5) == 6\n assert candidate(nums = [7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10],k = 30) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 25) == 6\n", "comparison": "exact"}, "public_tests": ["[1,1,1,1,1]\n10", "[3,1,4,3,2,2,4]\n2"], "hints": ["For a fixed index l, try to find the minimum value of index r, such that the subarray is not good", "When a number is added to a subarray, it increases the number of pairs by its previous appearances.", "When a number is removed from the subarray, it decreases the number of pairs by its remaining appearances.", "Maintain 2-pointers l and r such that we can keep in account the number of equal pairs."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:21+00:00", "tests_total": 116, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def count_good(nums, k)", "container": null, "callable": "count_good", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2538, "task_id": "difference-between-maximum-and-minimum-price-sum", "difficulty": "Hard", "problem_description": "There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.\n\nEach node has an associated price. You are given an integer array price, where price[i] is the price of the i^th node.\n\nThe price sum of a given path is the sum of the prices of all nodes lying on that path.\n\nThe tree can be rooted at any node root of your choice. The incurred cost after choosing root is the difference between the maximum and minimum price sum amongst all paths starting at root.\n\nReturn the maximum possible cost amongst all possible root choices.\n\nExample 1:\n\nInput: n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5]\nOutput: 24\nExplanation: The diagram above denotes the tree after rooting it at node 2. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.\n- The first path contains nodes [2,1,3,4]: the prices are [7,8,6,10], and the sum of the prices is 31.\n- The second path contains the node [2] with the price [7].\nThe difference between the maximum and minimum price sum is 24. It can be proved that 24 is the maximum cost.\n\nExample 2:\n\nInput: n = 3, edges = [[0,1],[1,2]], price = [1,1,1]\nOutput: 2\nExplanation: The diagram above denotes the tree after rooting it at node 0. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.\n- The first path contains nodes [0,1,2]: the prices are [1,1,1], and the sum of the prices is 3.\n- The second path contains node [0] with a price [1].\nThe difference between the maximum and minimum price sum is 2. It can be proved that 2 is the maximum cost.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- edges.length == n - 1\n- 0 <= a_i, b_i <= n - 1\n- edges represents a valid tree.\n- price.length == n\n- 1 <= price[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [5, 4, 3, 2, 1]) == 12\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [5, 10, 20, 30, 40]) == 55\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],price = [10, 5, 1, 1]) == 15\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],price = [1, 2, 3, 4]) == 6\n assert candidate(n = 4,edges = [[0, 1], [0, 2], [0, 3]],price = [2, 3, 4, 5]) == 7\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]],price = [10, 20, 30, 40, 50]) == 140\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]],price = [9, 8, 7, 6, 10, 5]) == 24\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6]],price = [1, 2, 3, 4, 5, 6, 7]) == 19\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]],price = [10, 9, 8, 7, 6]) == 34\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 24\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [1, 1, 1]) == 2\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],price = [10, 20, 30, 40]) == 60\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 21\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [2, 3], [2, 4], [2, 5], [5, 6]],price = [3, 5, 6, 2, 1, 7, 4]) == 21\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [5, 2, 3, 4, 6]) == 13\n assert candidate(n = 1,edges = [],price = [100]) == 0\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],price = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 44\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],price = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16]) == 438\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 330\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],price = [7, 6, 5, 4, 3, 2, 1, 8]) == 30\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19]],price = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 30\n assert candidate(n = 14,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 320\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10]],price = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 30\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],price = [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]) == 65\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],price = [100, 200, 300, 400, 500, 600, 700, 800]) == 3500\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 33\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],price = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],price = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980, 99979, 99978, 99977, 99976]) == 799956\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11]],price = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10, 12, 11]) == 36\n assert candidate(n = 30,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29]],price = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 30]) == 72\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],price = [15, 25, 35, 45, 55, 65, 75, 85]) == 205\n assert candidate(n = 30,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29]],price = [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]) == 370\n assert candidate(n = 100,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30], [15, 31], [15, 32], [16, 33], [16, 34], [17, 35], [17, 36], [18, 37], [18, 38], [19, 39], [19, 40], [20, 41], [20, 42], [21, 43], [21, 44], [22, 45], [22, 46], [23, 47], [23, 48], [24, 49], [24, 50], [25, 51], [25, 52], [26, 53], [26, 54], [27, 55], [27, 56], [28, 57], [28, 58], [29, 59], [29, 60], [30, 61], [30, 62], [31, 63], [31, 64], [32, 65], [32, 66], [33, 67], [33, 68], [34, 69], [34, 70], [35, 71], [35, 72], [36, 73], [36, 74], [37, 75], [37, 76], [38, 77], [38, 78], [39, 79], [39, 80], [40, 81], [40, 82], [41, 83], [41, 84], [42, 85], [42, 86], [43, 87], [43, 88], [44, 89], [44, 90], [45, 91], [45, 92], [46, 93], [46, 94], [47, 95], [47, 96], [48, 97], [48, 98], [49, 99]],price = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 285\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 50\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],price = [5, 8, 3, 11, 10, 4, 2, 6, 9, 7, 12, 14, 13, 1, 15, 17, 16, 18, 19, 20]) == 65\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],price = [2, 5, 1, 8, 3, 6, 9, 4, 7, 10, 12, 14, 13, 1, 15, 17, 16, 18, 19, 20, 21, 22, 23, 24, 25]) == 68\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [100, 50, 200, 150, 250, 300, 400, 5, 10, 15, 20, 25, 30, 35, 40]) == 1040\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8], [6, 9]],price = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 130\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],price = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500]) == 6500\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],price = [10, 20, 30, 40, 50, 60]) == 200\n assert candidate(n = 18,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17]],price = [15, 22, 10, 25, 30, 12, 18, 20, 21, 24, 26, 27, 31, 32, 33, 34, 35, 36]) == 147\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],price = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 385\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [3, 4, 5, 6, 7, 8, 9]) == 21\n assert candidate(n = 50,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30], [15, 31], [15, 32], [16, 33], [16, 34], [17, 35], [17, 36], [18, 37], [18, 38], [19, 39], [19, 40], [20, 41], [20, 42], [21, 43], [21, 44], [22, 45], [22, 46], [23, 47], [23, 48], [24, 49]],price = [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]) == 138\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 275\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 29\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 280\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],price = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 143\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]],price = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == 20000\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],price = [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]) == 122\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 3300\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [5, 15, 25, 35, 45, 55, 65]) == 110\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 500\n", "comparison": "exact"}, "public_tests": ["6\n[[0,1],[1,2],[1,3],[3,4],[3,5]]\n[9,8,7,6,10,5]", "3\n[[0,1],[1,2]]\n[1,1,1]"], "hints": ["The minimum price sum is always the price of a rooted node.", "Let’s root the tree at vertex 0 and find the answer from this perspective.", "In the optimal answer maximum price is the sum of the prices of nodes on the path from “u” to “v” where either “u” or “v” is the parent of the second one or neither is a parent of the second one.", "The first case is easy to find. For the second case, notice that in the optimal path, “u” and “v” are both leaves. Then we can use dynamic programming to find such a path.", "Let DP(v,1) denote “the maximum price sum from node v to leaf, where v is a parent of that leaf” and let DP(v,0) denote “the maximum price sum from node v to leaf, where v is a parent of that leaf - price[leaf]”. Then the answer is maximum of DP(u,0) + DP(v,1) + price[parent] where u, v are directly connected to vertex “parent”."], "metadata": {"canonical_parameter_names": ["n", "edges", "price"], "leetcode_dataset_entry_point": "Solution().maxOutput", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:24+00:00", "tests_total": 58, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "tree", "depth-first-search", "dp-on-trees"]}, "language": "ruby", "interface": {"raw_signature": "def max_output(n, edges, price)", "container": null, "callable": "max_output", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "price", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2540, "task_id": "minimum-common-value", "difficulty": "Easy", "problem_description": "Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.\n\nNote that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.\n\nExample 1:\n\nInput: nums1 = [1,2,3], nums2 = [2,4]\nOutput: 2\nExplanation: The smallest element common to both arrays is 2, so we return 2.\n\nExample 2:\n\nInput: nums1 = [1,2,3,6], nums2 = [2,3,4,5]\nOutput: 2\nExplanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 10^5\n- 1 <= nums1[i], nums2[j] <= 10^9\n- Both nums1 and nums2 are sorted in non-decreasing order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 2, 3],nums2 = [2, 2]) == 2\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25, 35]) == -1\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1, 3, 5, 7],nums2 = [2, 4, 6, 8]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == -1\n assert candidate(nums1 = [10, 20, 30],nums2 = [1, 2, 3]) == -1\n assert candidate(nums1 = [1, 1, 2, 2],nums2 = [2, 2, 3, 3]) == 2\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25]) == -1\n assert candidate(nums1 = [1, 2, 3],nums2 = [2, 4]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [1000000000],nums2 = [1000000000]) == 1000000000\n assert candidate(nums1 = [1, 5, 9],nums2 = [3, 6, 9]) == 9\n assert candidate(nums1 = [1, 5, 9, 13, 17],nums2 = [2, 6, 10, 14, 18]) == -1\n assert candidate(nums1 = [1],nums2 = [2]) == -1\n assert candidate(nums1 = [1, 5, 9],nums2 = [3, 7, 11]) == -1\n assert candidate(nums1 = [5, 10, 15],nums2 = [15, 20, 25]) == 15\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == -1\n assert candidate(nums1 = [1, 2, 3, 6],nums2 = [2, 3, 4, 5]) == 2\n assert candidate(nums1 = [1, 10, 20],nums2 = [5, 15, 25]) == -1\n assert candidate(nums1 = [1],nums2 = [1]) == 1\n assert candidate(nums1 = [1, 5, 7, 9],nums2 = [2, 6, 8, 10]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 5\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [11, 13, 15, 17, 19]) == -1\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 2\n assert candidate(nums1 = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],nums2 = [2, 5, 8, 13, 21, 34, 55, 89]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1, 2, 2, 3, 4, 5],nums2 = [2, 2, 3, 4, 5, 6]) == 2\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == -1\n assert candidate(nums1 = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],nums2 = [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]) == 1\n assert candidate(nums1 = [1, 4, 7, 10, 13],nums2 = [2, 5, 8, 11, 14]) == -1\n assert candidate(nums1 = [2, 10, 20, 30, 50],nums2 = [1, 2, 3, 10, 100]) == 2\n assert candidate(nums1 = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],nums2 = [5, 10, 16, 23, 31, 40, 50, 61, 73, 86]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 5\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 3\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums1 = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28],nums2 = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29]) == -1\n assert candidate(nums1 = [100, 101, 102, 103, 104],nums2 = [99, 100, 101, 102, 105]) == 100\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums1 = [1, 4, 8, 10, 12, 15, 18, 20],nums2 = [2, 4, 6, 8, 10, 14, 18]) == 4\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],nums2 = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536]) == -1\n assert candidate(nums1 = [1, 2, 2, 3, 4, 5],nums2 = [2, 3, 3, 4, 5, 6]) == 2\n assert candidate(nums1 = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28],nums2 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == -1\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == -1\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [16, 17, 18, 19, 20]) == -1\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [1, 3, 5, 7, 9]) == -1\n assert candidate(nums1 = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45],nums2 = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45]) == 1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == -1\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums1 = [1, 4, 6, 10, 20],nums2 = [3, 4, 15, 20, 25]) == 4\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(nums1 = [1, 4, 7, 10, 13],nums2 = [2, 5, 8, 11, 14]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == -1\n assert candidate(nums1 = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],nums2 = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 15\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 5\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]) == 20\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1000000, 2000000, 3000000, 4000000],nums2 = [500000, 1500000, 2500000, 3500000]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 3\n assert candidate(nums1 = [1, 2, 2, 3, 4, 5, 5, 5, 6],nums2 = [2, 3, 3, 4, 5, 5, 6, 7, 8]) == 2\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67],nums2 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 2\n assert candidate(nums1 = [5, 15, 25, 35, 45],nums2 = [6, 12, 18, 24, 30]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [11, 12, 13, 14, 15]) == -1\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [5, 10, 15, 20, 25, 30, 35, 40]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums1 = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 10\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums1 = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [150, 250, 350, 450, 550]) == -1\n assert candidate(nums1 = [1, 2, 2, 3, 4, 5],nums2 = [2, 2, 3, 4, 6, 7]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 6, 7, 8, 9]) == 5\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45, 55]) == -1\n assert candidate(nums1 = [1, 10, 100, 1000, 10000],nums2 = [5, 50, 500, 5000, 50000]) == -1\n assert candidate(nums1 = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],nums2 = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250]) == 50\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n[2,4]", "[1,2,3,6]\n[2,3,4,5]"], "hints": ["Try to use a set.", "Otherwise, try to use a two-pointer approach."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().getCommon", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:26+00:00", "tests_total": 103, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "binary-search"]}, "language": "ruby", "interface": {"raw_signature": "def get_common(nums1, nums2)", "container": null, "callable": "get_common", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2541, "task_id": "minimum-operations-to-make-array-equal-ii", "difficulty": "Medium", "problem_description": "You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1:\n\n- Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.\n\nnums1 is said to be equal to nums2 if for all indices i such that 0 <= i < n, nums1[i] == nums2[i].\n\nReturn the minimum number of operations required to make nums1 equal to nums2. If it is impossible to make them equal, return -1.\n\nExample 1:\n\nInput: nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3\nOutput: 2\nExplanation: In 2 operations, we can transform nums1 to nums2.\n1^st operation: i = 2, j = 0. After applying the operation, nums1 = [1,3,4,4].\n2^nd operation: i = 2, j = 3. After applying the operation, nums1 = [1,3,7,1].\nOne can prove that it is impossible to make arrays equal in fewer operations.\n\nExample 2:\n\nInput: nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1\nOutput: -1\nExplanation: It can be proved that it is impossible to make the two arrays equal.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 2 <= n <= 10^5\n- 0 <= nums1[i], nums2[j] <= 10^9\n- 0 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [3, 8, 5, 2],nums2 = [2, 4, 1, 6],k = 1) == -1\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [10, 10, 10, 10],k = 5) == -1\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [1, 2, 3, 4],k = 2) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [20, 30, 40],k = 10) == -1\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1],k = 2) == 1\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0],k = 0) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [10, 10, 0, 0],k = 5) == 2\n assert candidate(nums1 = [1, 1, 1],nums2 = [2, 2, 2],k = 0) == -1\n assert candidate(nums1 = [1, 2, 3],nums2 = [1, 2, 3],k = 0) == 0\n assert candidate(nums1 = [0, 0, 0],nums2 = [0, 0, 0],k = 0) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 20, 10],k = 10) == 2\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1],k = 2) == -1\n assert candidate(nums1 = [10, 20, 30],nums2 = [10, 20, 30],k = 5) == 0\n assert candidate(nums1 = [4, 3, 1, 4],nums2 = [1, 3, 7, 1],k = 3) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 100\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1],k = 100000) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100],k = 50) == 12\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1],nums2 = [9, 9, 9, 9, 9, 9, 9, 9],k = 2) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 3],k = 1) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [20, 30, 40, 50, 60],k = 10) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [9, 7, 5, 3, 1],k = 2) == 6\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [40, 30, 20, 10],k = 10) == 4\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [50, 150, 250, 350, 451],k = 50) == -1\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == -1\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [10, 8, 6, 4, 2],k = 2) == 6\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [400, 300, 200, 100],k = 50) == 8\n assert candidate(nums1 = [100000, 200000, 300000],nums2 = [300000, 200000, 100000],k = 100000) == 2\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],k = 0) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1],k = 1) == 9\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1],k = 1) == 9\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [10, 10, 10, 10, 10, 0, 0, 0, 0, 0],k = 5) == 5\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [40, 30, 20, 10],k = 10) == 4\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11],k = 1) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 10, 9],k = 1) == 1\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 10) == 6\n assert candidate(nums1 = [100, 150, 200, 250, 300],nums2 = [300, 250, 200, 150, 100],k = 50) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2],k = 1) == -1\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0],k = 100000) == 0\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [400, 300, 200, 100],k = 100) == 4\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1],nums2 = [7, 7, 7, 7, 7, 7, 7, 7],k = 3) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13],nums2 = [13, 11, 9, 7, 5, 3, 1],k = 2) == 12\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 15) == -1\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600],nums2 = [600, 500, 400, 300, 200, 100],k = 100) == 9\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [50, 100, 150, 200, 250],k = 50) == -1\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [10, 8, 6, 4, 2],k = 2) == 6\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [1, 3, 5, 7, 9],k = 1) == -1\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [10, 8, 6, 4, 2],k = 3) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100],k = 10) == 60\n assert candidate(nums1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 0) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60],nums2 = [60, 50, 40, 30, 20, 10],k = 10) == 9\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],k = 0) == 0\n assert candidate(nums1 = [10, 15, 20, 25, 30, 35],nums2 = [35, 30, 25, 20, 15, 10],k = 5) == 9\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100],k = 50) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1) == 0\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1) == 25\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55, 65],nums2 = [15, 25, 35, 45, 55, 65, 75],k = 10) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2],k = 1) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1],k = 100) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 10) == 6\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [10, 20, 30, 40, 50],k = 5) == 0\n assert candidate(nums1 = [7, 7, 7, 7],nums2 = [1, 13, 1, 13],k = 3) == 4\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],k = 5) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 9],k = 2) == -1\n assert candidate(nums1 = [5, 6, 7, 8, 9, 10],nums2 = [15, 14, 13, 12, 11, 10],k = 2) == -1\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],k = 5) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55, 65],nums2 = [65, 55, 45, 35, 25, 15, 5],k = 10) == 12\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],k = 10) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 1) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 25\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 25\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2],k = 0) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 0\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0],k = 10) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [5, 5, 5, 5, 5, 5],k = 4) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1],k = 1) == 9\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1000) == 0\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],k = 5) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 1) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [9, 7, 5, 3, 1],k = 2) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 3],k = 2) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6],k = 1) == -1\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [10, 20, 30, 40, 50],k = 0) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6],k = 5) == -1\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 2) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [50, 150, 250, 350, 450],k = 50) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 10) == 25\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [40, 30, 20, 10],k = 5) == 8\n assert candidate(nums1 = [9, 18, 27, 36, 45],nums2 = [45, 36, 27, 18, 9],k = 9) == 6\n assert candidate(nums1 = [2, 4, 6, 8, 10, 12, 14, 16],nums2 = [16, 14, 12, 10, 8, 6, 4, 2],k = 2) == 16\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5],k = 0) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 56\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 5) == 12\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [40, 30, 20, 10],k = 5) == 8\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == -1\n", "comparison": "exact"}, "public_tests": ["[4,3,1,4]\n[1,3,7,1]\n3", "[3,8,5,2]\n[2,4,1,6]\n1"], "hints": ["What are the cases for which we cannot make nums1 == nums2?", "For minimum moves, if nums1[i] < nums2[i], then we should never decrement nums1[i]. If nums1[i] > nums2[i], then we should never increment nums1[i]."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "k"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:29+00:00", "tests_total": 109, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums1, nums2, k)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2542, "task_id": "maximum-subsequence-score", "difficulty": "Medium", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.\n\nFor chosen indices i_0, i_1, ..., i_{k - 1}, your score is defined as:\n\n- The sum of the selected elements from nums1 multiplied with the minimum of the selected elements from nums2.\n- It can defined simply as: (nums1[i_0] + nums1[i_1] +...+ nums1[i_{k - 1}]) * min(nums2[i_0] , nums2[i_1], ... ,nums2[i_{k - 1}]).\n\nReturn the maximum possible score.\n\nA subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1} by deleting some or no elements.\n\nExample 1:\n\nInput: nums1 = [1,3,3,2], nums2 = [2,1,3,4], k = 3\nOutput: 12\nExplanation:\nThe four possible subsequence scores are:\n- We choose the indices 0, 1, and 2 with score = (1+3+3) * min(2,1,3) = 7.\n- We choose the indices 0, 1, and 3 with score = (1+3+2) * min(2,1,4) = 6.\n- We choose the indices 0, 2, and 3 with score = (1+3+2) * min(2,3,4) = 12.\n- We choose the indices 1, 2, and 3 with score = (3+3+2) * min(1,3,4) = 8.\nTherefore, we return the max score, which is 12.\n\nExample 2:\n\nInput: nums1 = [4,2,3,1,1], nums2 = [7,5,10,9,6], k = 1\nOutput: 30\nExplanation:\nChoosing index 2 is optimal: nums1[2] * nums2[2] = 3 * 10 = 30 is the maximum possible score.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 1 <= n <= 10^5\n- 0 <= nums1[i], nums2[j] <= 10^5\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k = 2) == 15\n assert candidate(nums1 = [100000, 0, 0, 0, 0],nums2 = [1, 100000, 1, 100000, 1],k = 1) == 100000\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],k = 5) == 150\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1],k = 3) == 27\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 3) == 3\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 10, 15, 20, 25],k = 4) == 1400\n assert candidate(nums1 = [1, 3, 3, 2],nums2 = [2, 1, 3, 4],k = 3) == 12\n assert candidate(nums1 = [4, 2, 3, 1, 1],nums2 = [7, 5, 10, 9, 6],k = 1) == 30\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5],k = 4) == 0\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [100, 200, 300, 400],k = 2) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],k = 3) == 360\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0],k = 4) == 0\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5],k = 2) == 15\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],k = 5) == 125\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [0, 0, 0, 0, 0],k = 2) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1],k = 2) == 10\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [1, 1, 1, 1, 1],k = 2) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 55\n assert candidate(nums1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 50\n assert candidate(nums1 = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 8888800\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 6) == 225000\n assert candidate(nums1 = [5, 15, 10, 20, 25, 30],nums2 = [3, 1, 4, 2, 5, 6],k = 4) == 210\n assert candidate(nums1 = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 198437\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0],k = 3) == 12\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 6) == 2250\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 100\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55],nums2 = [10, 20, 30, 40, 50, 60],k = 4) == 4800\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 20\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 4) == 1155\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 80\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 7) == 490000\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 400\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 550\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 240000\n assert candidate(nums1 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 1000\n assert candidate(nums1 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5],k = 7) == 448\n assert candidate(nums1 = [5, 15, 20, 25, 30, 35, 40],nums2 = [10, 20, 15, 30, 25, 40, 35],k = 5) == 2900\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 72\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 1000\n assert candidate(nums1 = [5, 15, 10, 20, 25, 30, 40],nums2 = [2, 3, 1, 5, 4, 6, 7],k = 3) == 450\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000],nums2 = [5, 10, 15, 20, 25],k = 3) == 3150000\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 24\n assert candidate(nums1 = [99999, 99999, 99998, 99997, 99996, 99995],nums2 = [1, 1, 2, 2, 3, 3],k = 2) == 599973\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 720\n assert candidate(nums1 = [10, 15, 20, 25, 30, 35, 40],nums2 = [40, 35, 30, 25, 20, 15, 10],k = 4) == 1800\n assert candidate(nums1 = [100, 100, 100, 100, 100],nums2 = [100, 100, 100, 100, 100],k = 5) == 50000\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 2040\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],nums2 = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 10) == 33000\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 80\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 10000\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 4) == 56\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 294\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == 0\n assert candidate(nums1 = [5, 8, 9, 3, 7],nums2 = [6, 5, 4, 3, 2],k = 3) == 88\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 8) == 1560\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 40\n assert candidate(nums1 = [9, 1, 4, 7, 3, 6, 2, 8, 5, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 114\n assert candidate(nums1 = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 1400000\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 30\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 18\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 330\n assert candidate(nums1 = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 300000\n assert candidate(nums1 = [50, 60, 10, 90, 30, 20, 80, 70, 40, 60],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 6) == 1500\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [10, 20, 30, 40, 50],k = 1) == 450\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 0\n assert candidate(nums1 = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],nums2 = [60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10],k = 8) == 5500\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [10, 9, 8, 7, 6],k = 2) == 54\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5],k = 5) == 2500\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 30\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 10000\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [2, 4, 6, 8, 10],k = 3) == 60\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 1960\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 5500\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [1, 3, 5, 7, 9],k = 4) == 48\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 75\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 0\n assert candidate(nums1 = [100000, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000],k = 5) == 100000\n assert candidate(nums1 = [8, 2, 11, 3, 6, 9],nums2 = [5, 8, 1, 4, 7, 10],k = 4) == 125\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 300\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 1000\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 55000\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 30\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 400\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5],k = 3) == 75\n assert candidate(nums1 = [50, 40, 30, 20, 10],nums2 = [1, 2, 3, 4, 5],k = 3) == 180\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 216000\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 1120000\n assert candidate(nums1 = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 3000000\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 400\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 100\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 6) == 450\n assert candidate(nums1 = [5, 2, 6, 1, 4, 3],nums2 = [10, 5, 8, 2, 7, 6],k = 4) == 108\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 30\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 7500\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 80\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 15) == 4500\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k = 3) == 18\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 110\n assert candidate(nums1 = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 955\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],k = 5) == 1500\n assert candidate(nums1 = [50000, 50000, 50000, 50000, 50000],nums2 = [1, 2, 3, 4, 5],k = 5) == 250000\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 90\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [10, 10, 10, 10, 10],k = 2) == 9000\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 7) == 11200\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 90\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3) == 21600\n assert candidate(nums1 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5],k = 10) == 1050\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 240000\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 5) == 300\n", "comparison": "exact"}, "public_tests": ["[1,3,3,2]\n[2,1,3,4]\n3", "[4,2,3,1,1]\n[7,5,10,9,6]\n1"], "hints": ["How can we use sorting here?", "Try sorting the two arrays based on second array.", "Loop through nums2 and compute the max product given the minimum is nums2[i]. Update the answer accordingly."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "k"], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:31+00:00", "tests_total": 114, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def max_score(nums1, nums2, k)", "container": null, "callable": "max_score", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2543, "task_id": "check-if-point-is-reachable", "difficulty": "Hard", "problem_description": "There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.\n\nIn one step, you can move from point (x, y) to any one of the following points:\n\n- (x, y - x)\n- (x - y, y)\n- (2 * x, y)\n- (x, 2 * y)\n\nGiven two integers targetX and targetY representing the X-coordinate and Y-coordinate of your final position, return true if you can reach the point from (1, 1) using some number of steps, and false otherwise.\n\nExample 1:\n\nInput: targetX = 6, targetY = 9\nOutput: false\nExplanation: It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.\n\nExample 2:\n\nInput: targetX = 4, targetY = 7\nOutput: true\nExplanation: You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7).\n\nConstraints:\n\n- 1 <= targetX, targetY <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(targetX = 7,targetY = 3) == True\n assert candidate(targetX = 6,targetY = 9) == False\n assert candidate(targetX = 16,targetY = 8) == True\n assert candidate(targetX = 3,targetY = 5) == True\n assert candidate(targetX = 10,targetY = 1) == True\n assert candidate(targetX = 1,targetY = 1) == True\n assert candidate(targetX = 9,targetY = 6) == False\n assert candidate(targetX = 2,targetY = 2) == True\n assert candidate(targetX = 8,targetY = 16) == True\n assert candidate(targetX = 4,targetY = 7) == True\n assert candidate(targetX = 31,targetY = 47) == True\n assert candidate(targetX = 2,targetY = 1048576) == True\n assert candidate(targetX = 17,targetY = 34) == False\n assert candidate(targetX = 100,targetY = 1) == True\n assert candidate(targetX = 19,targetY = 38) == False\n assert candidate(targetX = 13,targetY = 19) == True\n assert candidate(targetX = 100,targetY = 200) == False\n assert candidate(targetX = 63,targetY = 27) == False\n assert candidate(targetX = 13,targetY = 21) == True\n assert candidate(targetX = 5,targetY = 13) == True\n assert candidate(targetX = 16,targetY = 32) == True\n assert candidate(targetX = 10,targetY = 10) == False\n assert candidate(targetX = 987654321,targetY = 987654321) == False\n assert candidate(targetX = 27,targetY = 18) == False\n assert candidate(targetX = 77,targetY = 154) == False\n assert candidate(targetX = 49,targetY = 147) == False\n assert candidate(targetX = 31,targetY = 62) == False\n assert candidate(targetX = 255,targetY = 1023) == False\n assert candidate(targetX = 512,targetY = 384) == True\n assert candidate(targetX = 16384,targetY = 8192) == True\n assert candidate(targetX = 88888,targetY = 55555) == False\n assert candidate(targetX = 512,targetY = 1025) == True\n assert candidate(targetX = 128,targetY = 192) == True\n assert candidate(targetX = 18,targetY = 33) == False\n assert candidate(targetX = 77,targetY = 44) == False\n assert candidate(targetX = 27,targetY = 81) == False\n assert candidate(targetX = 999999999,targetY = 333333333) == False\n assert candidate(targetX = 17,targetY = 1024) == True\n assert candidate(targetX = 5,targetY = 25) == False\n assert candidate(targetX = 65536,targetY = 129) == True\n assert candidate(targetX = 3125,targetY = 243) == True\n assert candidate(targetX = 1234567,targetY = 7654321) == True\n assert candidate(targetX = 32,targetY = 48) == True\n assert candidate(targetX = 999,targetY = 333) == False\n assert candidate(targetX = 987,targetY = 654) == False\n assert candidate(targetX = 1023,targetY = 1) == True\n assert candidate(targetX = 123456,targetY = 654321) == False\n assert candidate(targetX = 123,targetY = 456) == False\n assert candidate(targetX = 31,targetY = 31) == False\n assert candidate(targetX = 63,targetY = 21) == False\n assert candidate(targetX = 8192,targetY = 16384) == True\n assert candidate(targetX = 511,targetY = 256) == True\n assert candidate(targetX = 54,targetY = 36) == False\n assert candidate(targetX = 19,targetY = 23) == True\n assert candidate(targetX = 99999,targetY = 1) == True\n assert candidate(targetX = 1000000000,targetY = 1) == True\n assert candidate(targetX = 1000000000,targetY = 500000000) == False\n assert candidate(targetX = 1024,targetY = 512) == True\n assert candidate(targetX = 81,targetY = 27) == False\n assert candidate(targetX = 15,targetY = 10) == False\n assert candidate(targetX = 256,targetY = 513) == True\n assert candidate(targetX = 256,targetY = 512) == True\n assert candidate(targetX = 81,targetY = 243) == False\n assert candidate(targetX = 32,targetY = 128) == True\n assert candidate(targetX = 97,targetY = 83) == True\n assert candidate(targetX = 256,targetY = 256) == True\n assert candidate(targetX = 77,targetY = 49) == False\n assert candidate(targetX = 256,targetY = 1024) == True\n assert candidate(targetX = 1001,targetY = 1003) == True\n assert candidate(targetX = 511,targetY = 1024) == True\n assert candidate(targetX = 128,targetY = 256) == True\n assert candidate(targetX = 65536,targetY = 32768) == True\n assert candidate(targetX = 777,targetY = 111) == False\n assert candidate(targetX = 1,targetY = 1000000000) == True\n assert candidate(targetX = 33333,targetY = 22222) == False\n assert candidate(targetX = 999999937,targetY = 999999937) == False\n assert candidate(targetX = 33,targetY = 55) == False\n assert candidate(targetX = 3,targetY = 12) == False\n assert candidate(targetX = 1024,targetY = 2048) == True\n assert candidate(targetX = 255,targetY = 127) == True\n assert candidate(targetX = 100,targetY = 25) == False\n assert candidate(targetX = 77,targetY = 33) == False\n assert candidate(targetX = 101,targetY = 101) == False\n assert candidate(targetX = 13,targetY = 39) == False\n assert candidate(targetX = 123456789,targetY = 987654321) == False\n", "comparison": "exact"}, "public_tests": ["6\n9", "4\n7"], "hints": ["Let’s go in reverse order, from (targetX, targetY) to (1, 1). So, now we can move from (x, y) to (x+y, y), (x, y+x), (x/2, y) if x is even, and (x, y/2) if y is even.", "When is it optimal to use the third and fourth operations?", "Think how GCD of (x, y) is affected if we apply the first two operations.", "How can we check if we can reach (1, 1) using the GCD value calculate above?"], "metadata": {"canonical_parameter_names": ["targetX", "targetY"], "leetcode_dataset_entry_point": "Solution().isReachable", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:34+00:00", "tests_total": 86, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "ruby", "interface": {"raw_signature": "def is_reachable(target_x, target_y)", "container": null, "callable": "is_reachable", "parameters": [{"name": "target_x", "type": "Integer"}, {"name": "target_y", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2544, "task_id": "alternating-digit-sum", "difficulty": "Easy", "problem_description": "You are given a positive integer n. Each digit of n has a sign according to the following rules:\n\n- The most significant digit is assigned a positive sign.\n- Each other digit has an opposite sign to its adjacent digits.\n\nReturn the sum of all digits with their corresponding sign.\n\nExample 1:\n\nInput: n = 521\nOutput: 4\nExplanation: (+5) + (-2) + (+1) = 4.\n\nExample 2:\n\nInput: n = 111\nOutput: 1\nExplanation: (+1) + (-1) + (+1) = 1.\n\nExample 3:\n\nInput: n = 886996\nOutput: 0\nExplanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0.\n\nConstraints:\n\n- 1 <= n <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 987654321) == 5\n assert candidate(n = 123) == 2\n assert candidate(n = 987) == 8\n assert candidate(n = 9) == 9\n assert candidate(n = 123456789) == 5\n assert candidate(n = 111) == 1\n assert candidate(n = 1) == 1\n assert candidate(n = 1000000000) == 1\n assert candidate(n = 521) == 4\n assert candidate(n = 100000000) == 1\n assert candidate(n = 24680) == -4\n assert candidate(n = 886996) == 0\n assert candidate(n = 222222222) == 2\n assert candidate(n = 999999999) == 9\n assert candidate(n = 100000001) == 2\n assert candidate(n = 909090909) == 45\n assert candidate(n = 202020202) == 10\n assert candidate(n = 135791357) == 9\n assert candidate(n = 975318642) == 1\n assert candidate(n = 505050505) == 25\n assert candidate(n = 999888777) == 8\n assert candidate(n = 135792468) == 9\n assert candidate(n = 246802468) == 0\n assert candidate(n = 121212121) == -3\n assert candidate(n = 808080808) == 40\n assert candidate(n = 101010101) == 5\n assert candidate(n = 4321234) == 5\n assert candidate(n = 7654321) == 4\n assert candidate(n = 555555555) == 5\n assert candidate(n = 864208642) == 0\n assert candidate(n = 111111111) == 1\n assert candidate(n = 110011001) == 1\n assert candidate(n = 123321) == 0\n assert candidate(n = 246813579) == 1\n assert candidate(n = 123012301) == 5\n assert candidate(n = 543210987) == 11\n", "comparison": "exact"}, "public_tests": ["521", "111", "886996"], "hints": ["The first step is to loop over the digits. We can convert the integer into a string, an array of digits, or just loop over its digits.", "Keep a variable sign that initially equals 1 and a variable answer that initially equals 0.", "Each time you loop over a digit i, add sign * i to answer, then multiply sign by -1."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().alternateDigitSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:36+00:00", "tests_total": 57, "tests_dropped": 21, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def alternate_digit_sum(n)", "container": null, "callable": "alternate_digit_sum", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2545, "task_id": "sort-the-students-by-their-kth-score", "difficulty": "Medium", "problem_description": "There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the i^th student got in the j^th exam. The matrix score contains distinct integers only.\n\nYou are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the k^th (0-indexed) exam from the highest to the lowest.\n\nReturn the matrix after sorting it.\n\nExample 1:\n\nInput: score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2\nOutput: [[7,5,11,2],[10,6,9,1],[4,8,3,15]]\nExplanation: In the above diagram, S denotes the student, while E denotes the exam.\n- The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.\n- The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.\n- The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.\n\nExample 2:\n\nInput: score = [[3,4],[5,6]], k = 0\nOutput: [[5,6],[3,4]]\nExplanation: In the above diagram, S denotes the student, while E denotes the exam.\n- The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.\n- The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place.\n\nConstraints:\n\n- m == score.length\n- n == score[i].length\n- 1 <= m, n <= 250\n- 1 <= score[i][j] <= 10^5\n- score consists of distinct integers.\n- 0 <= k < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(score = [[90, 80, 70], [60, 50, 40], [30, 20, 10]],k = 1) == [[90, 80, 70], [60, 50, 40], [30, 20, 10]]\n assert candidate(score = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]],k = 3) == [[3, 4, 5, 6], [2, 3, 4, 5], [1, 2, 3, 4]]\n assert candidate(score = [[10, 6, 9, 1], [7, 5, 11, 2], [4, 8, 3, 15]],k = 2) == [[7, 5, 11, 2], [10, 6, 9, 1], [4, 8, 3, 15]]\n assert candidate(score = [[20, 10], [15, 5], [25, 15]],k = 1) == [[25, 15], [20, 10], [15, 5]]\n assert candidate(score = [[100]],k = 0) == [[100]]\n assert candidate(score = [[5, 1, 4, 2, 3], [2, 5, 3, 4, 1], [1, 2, 5, 3, 4]],k = 3) == [[2, 5, 3, 4, 1], [1, 2, 5, 3, 4], [5, 1, 4, 2, 3]]\n assert candidate(score = [[9, 5, 7], [8, 4, 6], [7, 3, 5]],k = 1) == [[9, 5, 7], [8, 4, 6], [7, 3, 5]]\n assert candidate(score = [[25, 50, 75], [15, 30, 45], [10, 20, 30]],k = 0) == [[25, 50, 75], [15, 30, 45], [10, 20, 30]]\n assert candidate(score = [[3, 4], [5, 6]],k = 0) == [[5, 6], [3, 4]]\n assert candidate(score = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 2) == [[7, 8, 9], [4, 5, 6], [1, 2, 3]]\n assert candidate(score = [[1, 2, 3], [6, 5, 4], [9, 8, 7]],k = 2) == [[9, 8, 7], [6, 5, 4], [1, 2, 3]]\n assert candidate(score = [[5, 2, 1, 4], [3, 1, 4, 2], [4, 4, 2, 3]],k = 0) == [[5, 2, 1, 4], [4, 4, 2, 3], [3, 1, 4, 2]]\n assert candidate(score = [[20, 30], [15, 25], [10, 15]],k = 1) == [[20, 30], [15, 25], [10, 15]]\n assert candidate(score = [[5, 3, 7, 9], [8, 6, 4, 2], [1, 10, 11, 12]],k = 1) == [[1, 10, 11, 12], [8, 6, 4, 2], [5, 3, 7, 9]]\n assert candidate(score = [[20, 40, 60, 80, 100], [50, 30, 90, 70, 120], [10, 20, 30, 40, 50]],k = 2) == [[50, 30, 90, 70, 120], [20, 40, 60, 80, 100], [10, 20, 30, 40, 50]]\n assert candidate(score = [[123, 456, 789], [789, 456, 123], [123, 789, 456], [456, 123, 789], [789, 123, 456]],k = 0) == [[789, 456, 123], [789, 123, 456], [456, 123, 789], [123, 456, 789], [123, 789, 456]]\n assert candidate(score = [[12345, 98765, 45678], [11111, 22222, 33333], [99999, 88888, 77777]],k = 1) == [[12345, 98765, 45678], [99999, 88888, 77777], [11111, 22222, 33333]]\n assert candidate(score = [[42, 23, 67, 19], [85, 43, 23, 56], [34, 67, 89, 23], [78, 56, 45, 34]],k = 1) == [[34, 67, 89, 23], [78, 56, 45, 34], [85, 43, 23, 56], [42, 23, 67, 19]]\n assert candidate(score = [[98765, 43210, 12345, 67890, 24680], [13579, 24680, 35791, 46802, 57913], [65432, 12345, 98765, 24680, 35791], [24680, 35791, 46802, 57913, 65432], [57913, 65432, 79135, 87914, 96721]],k = 2) == [[65432, 12345, 98765, 24680, 35791], [57913, 65432, 79135, 87914, 96721], [24680, 35791, 46802, 57913, 65432], [13579, 24680, 35791, 46802, 57913], [98765, 43210, 12345, 67890, 24680]]\n assert candidate(score = [[1, 25, 49, 73, 97], [2, 26, 50, 74, 98], [3, 27, 51, 75, 99], [4, 28, 52, 76, 100], [5, 29, 53, 77, 101], [6, 30, 54, 78, 102], [7, 31, 55, 79, 103], [8, 32, 56, 80, 104], [9, 33, 57, 81, 105], [10, 34, 58, 82, 106]],k = 2) == [[10, 34, 58, 82, 106], [9, 33, 57, 81, 105], [8, 32, 56, 80, 104], [7, 31, 55, 79, 103], [6, 30, 54, 78, 102], [5, 29, 53, 77, 101], [4, 28, 52, 76, 100], [3, 27, 51, 75, 99], [2, 26, 50, 74, 98], [1, 25, 49, 73, 97]]\n assert candidate(score = [[123, 456, 789], [321, 654, 987], [456, 789, 123], [789, 123, 456], [654, 987, 321]],k = 1) == [[654, 987, 321], [456, 789, 123], [321, 654, 987], [123, 456, 789], [789, 123, 456]]\n assert candidate(score = [[20, 30, 40, 50], [50, 40, 30, 20], [10, 60, 70, 80]],k = 3) == [[10, 60, 70, 80], [20, 30, 40, 50], [50, 40, 30, 20]]\n assert candidate(score = [[10, 20, 30, 40, 50, 60, 70], [70, 60, 50, 40, 30, 20, 10], [30, 40, 50, 60, 70, 10, 20]],k = 5) == [[10, 20, 30, 40, 50, 60, 70], [70, 60, 50, 40, 30, 20, 10], [30, 40, 50, 60, 70, 10, 20]]\n assert candidate(score = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 4, 6, 8, 10], [10, 8, 6, 4, 2]],k = 4) == [[2, 4, 6, 8, 10], [1, 2, 3, 4, 5], [10, 8, 6, 4, 2], [5, 4, 3, 2, 1]]\n assert candidate(score = [[5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [3, 1, 4, 2, 5], [2, 3, 5, 1, 4]],k = 0) == [[5, 4, 3, 2, 1], [3, 1, 4, 2, 5], [2, 3, 5, 1, 4], [1, 2, 3, 4, 5]]\n assert candidate(score = [[100, 200, 300, 400, 500], [90, 190, 290, 390, 490], [80, 180, 280, 380, 480], [70, 170, 270, 370, 470], [60, 160, 260, 360, 460]],k = 2) == [[100, 200, 300, 400, 500], [90, 190, 290, 390, 490], [80, 180, 280, 380, 480], [70, 170, 270, 370, 470], [60, 160, 260, 360, 460]]\n assert candidate(score = [[1000, 2000, 3000], [2000, 1000, 3000], [3000, 2000, 1000], [1000, 3000, 2000]],k = 1) == [[1000, 3000, 2000], [1000, 2000, 3000], [3000, 2000, 1000], [2000, 1000, 3000]]\n assert candidate(score = [[100, 50, 75, 25], [70, 90, 30, 10], [60, 40, 80, 65], [20, 85, 55, 45]],k = 2) == [[60, 40, 80, 65], [100, 50, 75, 25], [20, 85, 55, 45], [70, 90, 30, 10]]\n assert candidate(score = [[15, 25, 35, 45], [25, 35, 45, 15], [35, 45, 15, 25], [45, 15, 25, 35], [10, 20, 30, 40]],k = 0) == [[45, 15, 25, 35], [35, 45, 15, 25], [25, 35, 45, 15], [15, 25, 35, 45], [10, 20, 30, 40]]\n assert candidate(score = [[1000, 1001, 1002, 1003, 1004], [2000, 2001, 2002, 2003, 2004], [3000, 3001, 3002, 3003, 3004], [4000, 4001, 4002, 4003, 4004], [5000, 5001, 5002, 5003, 5004]],k = 0) == [[5000, 5001, 5002, 5003, 5004], [4000, 4001, 4002, 4003, 4004], [3000, 3001, 3002, 3003, 3004], [2000, 2001, 2002, 2003, 2004], [1000, 1001, 1002, 1003, 1004]]\n assert candidate(score = [[1, 2, 3, 4, 5], [10, 20, 30, 40, 50], [100, 200, 300, 400, 500], [1000, 2000, 3000, 4000, 5000], [10000, 20000, 30000, 40000, 50000]],k = 3) == [[10000, 20000, 30000, 40000, 50000], [1000, 2000, 3000, 4000, 5000], [100, 200, 300, 400, 500], [10, 20, 30, 40, 50], [1, 2, 3, 4, 5]]\n assert candidate(score = [[5, 8, 1, 9], [9, 1, 5, 8], [8, 9, 5, 1], [1, 5, 8, 9]],k = 2) == [[1, 5, 8, 9], [9, 1, 5, 8], [8, 9, 5, 1], [5, 8, 1, 9]]\n assert candidate(score = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95], [9, 19, 29, 39, 49, 59, 69, 79, 89, 99]],k = 9) == [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [9, 19, 29, 39, 49, 59, 69, 79, 89, 99], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]]\n assert candidate(score = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [3, 1, 4, 6, 5, 2], [2, 4, 6, 1, 3, 5]],k = 4) == [[1, 2, 3, 4, 5, 6], [3, 1, 4, 6, 5, 2], [2, 4, 6, 1, 3, 5], [6, 5, 4, 3, 2, 1]]\n assert candidate(score = [[10, 20, 30], [30, 10, 20], [20, 30, 10], [50, 40, 60], [40, 50, 70], [60, 70, 80], [70, 80, 90]],k = 0) == [[70, 80, 90], [60, 70, 80], [50, 40, 60], [40, 50, 70], [30, 10, 20], [20, 30, 10], [10, 20, 30]]\n assert candidate(score = [[100, 99, 98], [97, 96, 95], [94, 93, 92], [91, 90, 89], [88, 87, 86]],k = 2) == [[100, 99, 98], [97, 96, 95], [94, 93, 92], [91, 90, 89], [88, 87, 86]]\n assert candidate(score = [[1, 3, 2], [3, 2, 1], [2, 1, 3], [4, 5, 6], [6, 4, 5], [5, 6, 4]],k = 2) == [[4, 5, 6], [6, 4, 5], [5, 6, 4], [2, 1, 3], [1, 3, 2], [3, 2, 1]]\n assert candidate(score = [[150, 130, 110], [140, 120, 100], [135, 115, 95], [145, 125, 105]],k = 1) == [[150, 130, 110], [145, 125, 105], [140, 120, 100], [135, 115, 95]]\n assert candidate(score = [[20, 45, 67, 89, 10], [45, 78, 12, 56, 34], [67, 23, 89, 12, 45], [89, 10, 23, 45, 67], [10, 89, 45, 67, 23]],k = 3) == [[20, 45, 67, 89, 10], [10, 89, 45, 67, 23], [45, 78, 12, 56, 34], [89, 10, 23, 45, 67], [67, 23, 89, 12, 45]]\n assert candidate(score = [[99, 100, 98], [97, 96, 95], [94, 93, 92], [91, 90, 89]],k = 0) == [[99, 100, 98], [97, 96, 95], [94, 93, 92], [91, 90, 89]]\n assert candidate(score = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [2, 12, 22, 32, 42], [8, 18, 28, 38, 48], [4, 14, 24, 34, 44]],k = 1) == [[10, 20, 30, 40, 50], [8, 18, 28, 38, 48], [5, 15, 25, 35, 45], [4, 14, 24, 34, 44], [2, 12, 22, 32, 42]]\n assert candidate(score = [[123, 456, 789], [987, 654, 321], [111, 222, 333], [444, 555, 666]],k = 1) == [[987, 654, 321], [444, 555, 666], [123, 456, 789], [111, 222, 333]]\n assert candidate(score = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [20, 30, 40, 50, 10], [40, 50, 10, 20, 30]],k = 1) == [[40, 50, 10, 20, 30], [50, 40, 30, 20, 10], [20, 30, 40, 50, 10], [10, 20, 30, 40, 50]]\n assert candidate(score = [[100, 200, 300, 400, 500], [500, 400, 300, 200, 100], [300, 500, 200, 100, 400], [200, 300, 500, 400, 100]],k = 4) == [[100, 200, 300, 400, 500], [300, 500, 200, 100, 400], [500, 400, 300, 200, 100], [200, 300, 500, 400, 100]]\n assert candidate(score = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1]],k = 4) == [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1]]\n assert candidate(score = [[1, 12, 3, 4, 5], [10, 11, 2, 7, 8], [6, 9, 1, 10, 4], [2, 5, 6, 3, 9]],k = 0) == [[10, 11, 2, 7, 8], [6, 9, 1, 10, 4], [2, 5, 6, 3, 9], [1, 12, 3, 4, 5]]\n assert candidate(score = [[2, 1, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [11, 22, 33, 44, 55, 66, 77, 88, 99, 100]],k = 5) == [[11, 22, 33, 44, 55, 66, 77, 88, 99, 100], [2, 1, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]\n assert candidate(score = [[100000, 90000, 80000, 70000, 60000], [50000, 40000, 30000, 20000, 10000]],k = 4) == [[100000, 90000, 80000, 70000, 60000], [50000, 40000, 30000, 20000, 10000]]\n assert candidate(score = [[100000, 90000, 80000, 70000, 60000], [10000, 20000, 30000, 40000, 50000], [5000, 6000, 7000, 8000, 9000], [1, 2, 3, 4, 5]],k = 0) == [[100000, 90000, 80000, 70000, 60000], [10000, 20000, 30000, 40000, 50000], [5000, 6000, 7000, 8000, 9000], [1, 2, 3, 4, 5]]\n assert candidate(score = [[99, 101, 102, 98], [103, 104, 97, 96], [95, 94, 93, 105], [106, 107, 108, 109]],k = 3) == [[106, 107, 108, 109], [95, 94, 93, 105], [99, 101, 102, 98], [103, 104, 97, 96]]\n assert candidate(score = [[5, 10, 15, 20, 25, 30, 35, 40], [40, 35, 30, 25, 20, 15, 10, 5], [15, 20, 25, 30, 35, 40, 5, 10]],k = 6) == [[5, 10, 15, 20, 25, 30, 35, 40], [40, 35, 30, 25, 20, 15, 10, 5], [15, 20, 25, 30, 35, 40, 5, 10]]\n assert candidate(score = [[10, 20, 30], [20, 10, 40], [30, 40, 20], [40, 30, 10], [50, 10, 20], [60, 20, 30]],k = 2) == [[20, 10, 40], [10, 20, 30], [60, 20, 30], [30, 40, 20], [50, 10, 20], [40, 30, 10]]\n assert candidate(score = [[5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [4, 3, 2, 1, 5], [2, 1, 5, 4, 3], [3, 5, 4, 3, 2]],k = 2) == [[2, 1, 5, 4, 3], [3, 5, 4, 3, 2], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [4, 3, 2, 1, 5]]\n assert candidate(score = [[5, 3, 1, 4], [2, 1, 5, 3], [4, 2, 3, 1], [3, 5, 4, 2]],k = 0) == [[5, 3, 1, 4], [4, 2, 3, 1], [3, 5, 4, 2], [2, 1, 5, 3]]\n assert candidate(score = [[50, 90, 80, 70], [60, 10, 20, 30], [100, 5, 15, 25], [40, 65, 55, 45]],k = 1) == [[50, 90, 80, 70], [40, 65, 55, 45], [60, 10, 20, 30], [100, 5, 15, 25]]\n assert candidate(score = [[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]],k = 0) == [[5, 5, 5, 5, 5], [4, 4, 4, 4, 4], [3, 3, 3, 3, 3], [2, 2, 2, 2, 2], [1, 1, 1, 1, 1]]\n assert candidate(score = [[120, 130, 140, 150], [110, 100, 90, 80], [160, 170, 180, 190], [95, 85, 75, 65]],k = 2) == [[160, 170, 180, 190], [120, 130, 140, 150], [110, 100, 90, 80], [95, 85, 75, 65]]\n assert candidate(score = [[55, 65, 75, 85, 95], [45, 35, 25, 15, 5], [90, 80, 70, 60, 50], [15, 25, 35, 45, 55]],k = 3) == [[55, 65, 75, 85, 95], [90, 80, 70, 60, 50], [15, 25, 35, 45, 55], [45, 35, 25, 15, 5]]\n assert candidate(score = [[88, 77, 66, 55], [55, 66, 77, 88], [66, 88, 77, 55], [77, 55, 88, 66]],k = 0) == [[88, 77, 66, 55], [77, 55, 88, 66], [66, 88, 77, 55], [55, 66, 77, 88]]\n assert candidate(score = [[34, 56, 23, 89], [67, 34, 56, 12], [90, 89, 78, 67], [23, 45, 67, 89]],k = 3) == [[34, 56, 23, 89], [23, 45, 67, 89], [90, 89, 78, 67], [67, 34, 56, 12]]\n assert candidate(score = [[123, 456, 789, 101, 112], [234, 567, 890, 212, 123], [345, 678, 901, 323, 134], [456, 789, 101, 434, 145], [567, 890, 212, 545, 156], [678, 901, 323, 656, 167]],k = 1) == [[678, 901, 323, 656, 167], [567, 890, 212, 545, 156], [456, 789, 101, 434, 145], [345, 678, 901, 323, 134], [234, 567, 890, 212, 123], [123, 456, 789, 101, 112]]\n assert candidate(score = [[50, 85, 75], [35, 90, 60], [45, 95, 65], [25, 80, 70]],k = 1) == [[45, 95, 65], [35, 90, 60], [50, 85, 75], [25, 80, 70]]\n assert candidate(score = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [19, 18, 17, 16, 15, 14, 13, 12, 11, 10]],k = 5) == [[19, 18, 17, 16, 15, 14, 13, 12, 11, 10], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]]\n assert candidate(score = [[100000, 1, 2, 3], [99999, 4, 5, 6], [99998, 7, 8, 9], [99997, 10, 11, 12]],k = 1) == [[99997, 10, 11, 12], [99998, 7, 8, 9], [99999, 4, 5, 6], [100000, 1, 2, 3]]\n assert candidate(score = [[95, 85, 75, 65, 55], [65, 55, 45, 35, 25], [80, 90, 100, 70, 85], [40, 50, 60, 95, 80], [70, 80, 90, 100, 75]],k = 3) == [[70, 80, 90, 100, 75], [40, 50, 60, 95, 80], [80, 90, 100, 70, 85], [95, 85, 75, 65, 55], [65, 55, 45, 35, 25]]\n assert candidate(score = [[50, 90, 20, 60], [30, 70, 80, 40], [10, 50, 30, 20], [70, 30, 50, 90]],k = 2) == [[30, 70, 80, 40], [70, 30, 50, 90], [10, 50, 30, 20], [50, 90, 20, 60]]\n assert candidate(score = [[5, 10, 15, 20], [20, 15, 10, 5], [10, 5, 20, 15], [15, 20, 5, 10], [25, 30, 35, 40]],k = 3) == [[25, 30, 35, 40], [5, 10, 15, 20], [10, 5, 20, 15], [15, 20, 5, 10], [20, 15, 10, 5]]\n assert candidate(score = [[20, 30, 10], [40, 50, 60], [10, 20, 30], [70, 80, 90]],k = 2) == [[70, 80, 90], [40, 50, 60], [10, 20, 30], [20, 30, 10]]\n assert candidate(score = [[15, 25, 35, 45, 55], [55, 45, 35, 25, 15], [25, 35, 15, 55, 45], [45, 15, 55, 35, 25]],k = 3) == [[25, 35, 15, 55, 45], [15, 25, 35, 45, 55], [45, 15, 55, 35, 25], [55, 45, 35, 25, 15]]\n assert candidate(score = [[100, 200, 300, 400, 500], [200, 100, 400, 300, 500], [500, 400, 300, 200, 100], [400, 300, 200, 500, 100]],k = 2) == [[200, 100, 400, 300, 500], [100, 200, 300, 400, 500], [500, 400, 300, 200, 100], [400, 300, 200, 500, 100]]\n assert candidate(score = [[200, 300, 400, 500], [250, 350, 450, 550], [150, 250, 350, 450], [100, 200, 300, 400]],k = 3) == [[250, 350, 450, 550], [200, 300, 400, 500], [150, 250, 350, 450], [100, 200, 300, 400]]\n assert candidate(score = [[250, 240, 230], [220, 210, 200], [190, 180, 170], [160, 150, 140], [130, 120, 110]],k = 0) == [[250, 240, 230], [220, 210, 200], [190, 180, 170], [160, 150, 140], [130, 120, 110]]\n assert candidate(score = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41], [2, 12, 22, 32, 42], [3, 13, 23, 33, 43], [4, 14, 24, 34, 44]],k = 4) == [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [4, 14, 24, 34, 44], [3, 13, 23, 33, 43], [2, 12, 22, 32, 42], [1, 11, 21, 31, 41]]\n assert candidate(score = [[500, 600, 700, 800], [400, 300, 200, 100], [900, 1000, 1100, 1200], [1300, 1400, 1500, 1600], [1700, 1800, 1900, 2000]],k = 3) == [[1700, 1800, 1900, 2000], [1300, 1400, 1500, 1600], [900, 1000, 1100, 1200], [500, 600, 700, 800], [400, 300, 200, 100]]\n assert candidate(score = [[150, 140, 130, 120, 110], [100, 90, 80, 70, 60], [50, 40, 30, 20, 10], [200, 190, 180, 170, 160]],k = 2) == [[200, 190, 180, 170, 160], [150, 140, 130, 120, 110], [100, 90, 80, 70, 60], [50, 40, 30, 20, 10]]\n assert candidate(score = [[5, 4, 3, 2, 1], [9, 8, 7, 6, 5], [13, 12, 11, 10, 9], [17, 16, 15, 14, 13]],k = 4) == [[17, 16, 15, 14, 13], [13, 12, 11, 10, 9], [9, 8, 7, 6, 5], [5, 4, 3, 2, 1]]\n assert candidate(score = [[999, 998, 997, 996, 995, 994, 993, 992, 991, 990], [989, 988, 987, 986, 985, 984, 983, 982, 981, 980], [979, 978, 977, 976, 975, 974, 973, 972, 971, 970]],k = 7) == [[999, 998, 997, 996, 995, 994, 993, 992, 991, 990], [989, 988, 987, 986, 985, 984, 983, 982, 981, 980], [979, 978, 977, 976, 975, 974, 973, 972, 971, 970]]\n assert candidate(score = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1], [4, 5, 1, 2, 3], [3, 1, 2, 4, 5]],k = 4) == [[1, 2, 3, 4, 5], [3, 1, 2, 4, 5], [4, 5, 1, 2, 3], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1]]\n assert candidate(score = [[100000, 99999, 99998, 99997, 99996], [99995, 99994, 99993, 99992, 99991], [99990, 99989, 99988, 99987, 99986]],k = 1) == [[100000, 99999, 99998, 99997, 99996], [99995, 99994, 99993, 99992, 99991], [99990, 99989, 99988, 99987, 99986]]\n assert candidate(score = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70], [50, 60, 70, 80]],k = 3) == [[50, 60, 70, 80], [40, 50, 60, 70], [30, 40, 50, 60], [20, 30, 40, 50], [10, 20, 30, 40]]\n", "comparison": "exact"}, "public_tests": ["[[10,6,9,1],[7,5,11,2],[4,8,3,15]]\n2", "[[3,4],[5,6]]\n0"], "hints": ["Find the row with the highest score in the kth exam and swap it with the first row.", "After fixing the first row, perform the same operation for the rest of the rows, and the matrix's rows will get sorted one by one."], "metadata": {"canonical_parameter_names": ["score", "k"], "leetcode_dataset_entry_point": "Solution().sortTheStudents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:38+00:00", "tests_total": 83, "tests_dropped": 3, "flags": ["has_images"], "topic_tags": ["array", "sorting", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def sort_the_students(score, k)", "container": null, "callable": "sort_the_students", "parameters": [{"name": "score", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2546, "task_id": "apply-bitwise-operations-to-make-strings-equal", "difficulty": "Medium", "problem_description": "You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:\n\n- Choose two different indices i and j where 0 <= i, j < n.\n- Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).\n\nFor example, if s = \"0110\", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0] OR s[2] = 0 OR 1 = 1), and s[2] with (s[0] XOR s[2] = 0 XOR 1 = 1), so we will have s = \"1110\".\n\nReturn true if you can make the string s equal to target, or false otherwise.\n\nExample 1:\n\nInput: s = \"1010\", target = \"0110\"\nOutput: true\nExplanation: We can do the following operations:\n- Choose i = 2 and j = 0. We have now s = \"0010\".\n- Choose i = 2 and j = 1. We have now s = \"0110\".\nSince we can make s equal to target, we return true.\n\nExample 2:\n\nInput: s = \"11\", target = \"00\"\nOutput: false\nExplanation: It is not possible to make s equal to target with any number of operations.\n\nConstraints:\n\n- n == s.length == target.length\n- 2 <= n <= 10^5\n- s and target consist of only the digits 0 and 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1001\",target = \"1001\") == True\n assert candidate(s = \"1010\",target = \"0110\") == True\n assert candidate(s = \"11\",target = \"00\") == False\n assert candidate(s = \"0000\",target = \"0000\") == True\n assert candidate(s = \"1100\",target = \"0011\") == True\n assert candidate(s = \"1101\",target = \"1101\") == True\n assert candidate(s = \"1111\",target = \"1111\") == True\n assert candidate(s = \"111000\",target = \"000111\") == True\n assert candidate(s = \"1001\",target = \"1100\") == True\n assert candidate(s = \"0101\",target = \"1010\") == True\n assert candidate(s = \"101010\",target = \"010101\") == True\n assert candidate(s = \"000111\",target = \"111000\") == True\n assert candidate(s = \"11110000000000000000\",target = \"00001111111111111111\") == True\n assert candidate(s = \"11001100110011001100\",target = \"00110011001100110011\") == True\n assert candidate(s = \"111100001111\",target = \"000011110000\") == True\n assert candidate(s = \"101010101010\",target = \"010101010101\") == True\n assert candidate(s = \"0000000000\",target = \"1010101010\") == False\n assert candidate(s = \"11111111111111111111\",target = \"11111111111111111111\") == True\n assert candidate(s = \"10010010010010010010\",target = \"01101101101101101101\") == True\n assert candidate(s = \"01010101010101010101\",target = \"10101010101010101010\") == True\n assert candidate(s = \"0101010101\",target = \"1010101010\") == True\n assert candidate(s = \"10101010101010\",target = \"01010101010101\") == True\n assert candidate(s = \"0110011001\",target = \"1001100110\") == True\n assert candidate(s = \"0101010101\",target = \"1010101011\") == True\n assert candidate(s = \"0101010101\",target = \"0000000000\") == False\n assert candidate(s = \"0000011111\",target = \"1111100000\") == True\n assert candidate(s = \"111000111000\",target = \"100111100111\") == True\n assert candidate(s = \"1000000001\",target = \"0111111110\") == True\n assert candidate(s = \"00000000000000000000\",target = \"10101010101010101010\") == False\n assert candidate(s = \"10101010101010101010101010101010\",target = \"01010101010101010101010101010101\") == True\n assert candidate(s = \"110101\",target = \"011010\") == True\n assert candidate(s = \"1010101010\",target = \"1111111111\") == True\n assert candidate(s = \"110000110000\",target = \"001111001111\") == True\n assert candidate(s = \"0000111100\",target = \"1111000011\") == True\n assert candidate(s = \"1111000011\",target = \"1100110011\") == True\n assert candidate(s = \"1001011011011011\",target = \"0110100100100100\") == True\n assert candidate(s = \"101010101010101010\",target = \"010101010101010101\") == True\n assert candidate(s = \"1000000001\",target = \"1000000001\") == True\n assert candidate(s = \"10101010101010101010101010\",target = \"01010101010101010101010101\") == True\n assert candidate(s = \"0000000000\",target = \"1111111111\") == False\n assert candidate(s = \"1111111111\",target = \"1111111111\") == True\n assert candidate(s = \"1100110011001100\",target = \"0011001100110011\") == True\n assert candidate(s = \"00000000000000000000\",target = \"11111111111111111111\") == False\n assert candidate(s = \"1111000011110000\",target = \"0000111100001111\") == True\n assert candidate(s = \"0010101110\",target = \"1001010110\") == True\n assert candidate(s = \"1111100000000000\",target = \"0000011111111111\") == True\n assert candidate(s = \"11000110001100011000\",target = \"00111001110011100111\") == True\n assert candidate(s = \"1001100110\",target = \"0110011001\") == True\n assert candidate(s = \"10101010101010101010\",target = \"01010101010101010101\") == True\n assert candidate(s = \"1111111100\",target = \"0000000011\") == True\n assert candidate(s = \"1101010101\",target = \"1110110110\") == True\n assert candidate(s = \"11110000111100001111\",target = \"00001111000011110000\") == True\n assert candidate(s = \"1100110011\",target = \"0011001100\") == True\n assert candidate(s = \"1010101010\",target = \"0101010101\") == True\n assert candidate(s = \"1010010101\",target = \"0101101010\") == True\n assert candidate(s = \"11111111000000001111\",target = \"11111111000000001111\") == True\n assert candidate(s = \"01001000100001001000\",target = \"10110111011110110111\") == True\n assert candidate(s = \"000011110000\",target = \"111100001111\") == True\n assert candidate(s = \"1000001000\",target = \"0010000010\") == True\n assert candidate(s = \"11100000000000000000\",target = \"11100000000000000000\") == True\n assert candidate(s = \"00000000000000000000\",target = \"00000000000000000000\") == True\n assert candidate(s = \"00001111\",target = \"11110000\") == True\n assert candidate(s = \"1111000011\",target = \"0000111100\") == True\n assert candidate(s = \"10000010000010000010\",target = \"01111101111101111101\") == True\n assert candidate(s = \"1110001110\",target = \"0001110001\") == True\n assert candidate(s = \"0001000100\",target = \"1110111011\") == True\n assert candidate(s = \"11111111111111111111\",target = \"00000000000000000000\") == False\n assert candidate(s = \"11001100110011001100\",target = \"10101010101010101010\") == True\n assert candidate(s = \"00001111111111110000\",target = \"11110000000000001111\") == True\n assert candidate(s = \"1111111111\",target = \"0000000000\") == False\n assert candidate(s = \"0101010101\",target = \"1101101101\") == True\n assert candidate(s = \"1101101101\",target = \"0010010010\") == True\n assert candidate(s = \"1010101010101010\",target = \"0101010101010101\") == True\n assert candidate(s = \"11001100\",target = \"00110011\") == True\n assert candidate(s = \"01001000100001001000\",target = \"01001000100001001000\") == True\n assert candidate(s = \"10101010\",target = \"01010101\") == True\n assert candidate(s = \"1001011011\",target = \"0110100100\") == True\n assert candidate(s = \"101101101101\",target = \"010010010010\") == True\n assert candidate(s = \"010010\",target = \"100100\") == True\n assert candidate(s = \"11110000\",target = \"00001111\") == True\n assert candidate(s = \"111000111000\",target = \"111000111000\") == True\n assert candidate(s = \"110011001100\",target = \"001100110011\") == True\n assert candidate(s = \"000111000111\",target = \"111000111000\") == True\n assert candidate(s = \"1101110111\",target = \"0010001000\") == True\n assert candidate(s = \"11111111111100000000\",target = \"00000000000011111111\") == True\n assert candidate(s = \"10100101001010010100\",target = \"01011010110101101011\") == True\n assert candidate(s = \"10101010101010101010\",target = \"11111111111111111111\") == True\n assert candidate(s = \"001100110011\",target = \"110011001100\") == True\n assert candidate(s = \"1111100000\",target = \"0000011111\") == True\n assert candidate(s = \"000000\",target = \"000000\") == True\n assert candidate(s = \"1111110000\",target = \"0000001111\") == True\n assert candidate(s = \"100010001000\",target = \"011101110111\") == True\n assert candidate(s = \"1010101010\",target = \"1010101011\") == True\n assert candidate(s = \"111111\",target = \"111111\") == True\n assert candidate(s = \"1110001110\",target = \"1110001110\") == True\n", "comparison": "exact"}, "public_tests": ["\"1010\"\n\"0110\"", "\"11\"\n\"00\""], "hints": ["Think of when it is impossible to convert the string to the target.", "If exactly one of the strings is having all 0’s, then it is impossible. And it is possible in all other cases. Why is that true?"], "metadata": {"canonical_parameter_names": ["s", "target"], "leetcode_dataset_entry_point": "Solution().makeStringsEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:41+00:00", "tests_total": 95, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def make_strings_equal(s, target)", "container": null, "callable": "make_strings_equal", "parameters": [{"name": "s", "type": "String"}, {"name": "target", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2547, "task_id": "minimum-cost-to-split-an-array", "difficulty": "Hard", "problem_description": "You are given an integer array nums and an integer k.\n\nSplit the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split.\n\nLet trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed.\n\n- For example, trimmed([3,1,2,4,3,4]) = [3,4,3,4].\n\nThe importance value of a subarray is k + trimmed(subarray).length.\n\n- For example, if a subarray is [1,2,3,3,3,4,4], then trimmed([1,2,3,3,3,4,4]) = [3,3,3,4,4].The importance value of this subarray will be k + 5.\n\nReturn the minimum possible cost of a split of nums.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1,2,1,3,3], k = 2\nOutput: 8\nExplanation: We split nums to have two subarrays: [1,2], [1,2,1,3,3].\nThe importance value of [1,2] is 2 + (0) = 2.\nThe importance value of [1,2,1,3,3] is 2 + (2 + 2) = 6.\nThe cost of the split is 2 + 6 = 8. It can be shown that this is the minimum possible cost among all the possible splits.\n\nExample 2:\n\nInput: nums = [1,2,1,2,1], k = 2\nOutput: 6\nExplanation: We split nums to have two subarrays: [1,2], [1,2,1].\nThe importance value of [1,2] is 2 + (0) = 2.\nThe importance value of [1,2,1] is 2 + (2) = 4.\nThe cost of the split is 2 + 4 = 6. It can be shown that this is the minimum possible cost among all the possible splits.\n\nExample 3:\n\nInput: nums = [1,2,1,2,1], k = 5\nOutput: 10\nExplanation: We split nums to have one subarray: [1,2,1,2,1].\nThe importance value of [1,2,1,2,1] is 5 + (3 + 2) = 10.\nThe cost of the split is 10. It can be shown that this is the minimum possible cost among all the possible splits.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 0 <= nums[i] < nums.length\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 4) == 14\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],k = 1) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 15\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 5) == 15\n assert candidate(nums = [0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 3) == 18\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 3) == 21\n assert candidate(nums = [1, 3, 2, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 3) == 9\n assert candidate(nums = [1, 2, 1, 2, 1, 3, 3],k = 2) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 7) == 27\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10],k = 4) == 14\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 6) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1) == 1\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],k = 8) == 30\n assert candidate(nums = [1, 2, 1, 2, 1],k = 2) == 6\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 5\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 7) == 17\n assert candidate(nums = [1, 2, 1, 2, 1],k = 5) == 10\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 10) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == 12\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],k = 15) == 43\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 8) == 16\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],k = 4) == 34\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 12) == 60\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 3) == 18\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7],k = 12) == 39\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) == 25\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 25\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 3) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 6) == 24\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 = 10) == 20\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],k = 6) == 18\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 5) == 21\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5],k = 4) == 26\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],k = 7) == 27\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 6, 5, 4, 7, 8, 9, 8, 7, 10, 11, 12, 11, 10],k = 8) == 24\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 = 5) == 25\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],k = 10) == 52\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],k = 10) == 30\n assert candidate(nums = [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) == 16\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 6) == 36\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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 4) == 46\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 3, 3, 2, 2, 1, 1, 4, 4, 3, 3, 2, 2, 1, 1],k = 4) == 24\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 2) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 30\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],k = 9) == 39\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 = 5) == 10\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],k = 9) == 39\n assert candidate(nums = [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],k = 10) == 30\n assert candidate(nums = [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 = 8) == 32\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1],k = 6) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 7) == 14\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],k = 15) == 59\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 12) == 36\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 3) == 18\n assert candidate(nums = [1, 2, 3, 3, 2, 1, 4, 5, 5, 4, 6, 7, 7, 6, 8, 9, 9, 8, 10, 11, 11, 10],k = 9) == 31\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 7) == 27\n assert candidate(nums = [1, 2, 1, 2, 1, 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],k = 5) == 43\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 10) == 20\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],k = 20) == 44\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 10) == 76\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 3) == 18\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],k = 20) == 50\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 9) == 27\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],k = 5) == 26\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 = 1) == 20\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],k = 2) == 26\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) == 6\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],k = 10) == 30\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],k = 7) == 57\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 = 8) == 16\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],k = 9) == 36\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],k = 5) == 71\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 4) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 16\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 = 1) == 10\n assert candidate(nums = [1, 2, 1, 2, 1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 31\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],k = 6) == 30\n assert candidate(nums = [1, 2, 1, 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],k = 6) == 20\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6],k = 8) == 27\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 = 6) == 26\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2],k = 7) == 26\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2],k = 7) == 27\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 12\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],k = 5) == 51\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 6) == 26\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8],k = 9) == 40\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, 1, 2, 3, 4, 5],k = 9) == 36\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],k = 10) == 26\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 3) == 23\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 74\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],k = 5) == 23\n assert candidate(nums = [1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 14\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 3) == 17\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],k = 7) == 31\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],k = 8) == 38\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2],k = 10) == 37\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 10) == 25\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 10) == 25\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],k = 7) == 32\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 = 15) == 30\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 15) == 35\n assert candidate(nums = [1, 2, 1, 2, 1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 7) == 28\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 4) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],k = 3) == 23\n", "comparison": "exact"}, "public_tests": ["[1,2,1,2,1,3,3]\n2", "[1,2,1,2,1]\n2", "[1,2,1,2,1]\n5"], "hints": ["Let's denote dp[r] = minimum cost to partition the first r elements of nums. What would be the transitions of such dynamic programming?", "dp[r] = min(dp[l] + importance(nums[l..r])) over all 0 <= l < r. This already gives us an O(n^3) approach, as importance can be calculated in linear time, and there are a total of O(n^2) transitions.", "Can you think of a way to compute multiple importance values of related subarrays faster?", "importance(nums[l-1..r]) is either importance(nums[l..r]) if a new unique element is added, importance(nums[l..r]) + 1 if an old element that appeared at least twice is added, or importance(nums[l..r]) + 2, if a previously unique element is duplicated. This allows us to compute importance(nums[l..r]) for all 0 <= l < r in O(n) by keeping a frequency table and decreasing l from r-1 down to 0."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:43+00:00", "tests_total": 122, "tests_dropped": 16, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def min_cost(nums, k)", "container": null, "callable": "min_cost", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2549, "task_id": "count-distinct-numbers-on-board", "difficulty": "Easy", "problem_description": "You are given a positive integer n, that is initially placed on a board. Every day, for 10^9 days, you perform the following procedure:\n\n- For each number x present on the board, find all numbers 1 <= i <= n such that x % i == 1.\n- Then, place those numbers on the board.\n\nReturn the number of distinct integers present on the board after 10^9 days have elapsed.\n\nNote:\n\n- Once a number is placed on the board, it will remain on it until the end.\n- % stands for the modulo operation. For example, 14 % 3 is 2.\n\nExample 1:\n\nInput: n = 5\nOutput: 4\nExplanation: Initially, 5 is present on the board.\nThe next day, 2 and 4 will be added since 5 % 2 == 1 and 5 % 4 == 1.\nAfter that day, 3 will be added to the board because 4 % 3 == 1.\nAt the end of a billion days, the distinct numbers on the board will be 2, 3, 4, and 5.\n\nExample 2:\n\nInput: n = 3\nOutput: 2\nExplanation:\nSince 3 % 2 == 1, 2 will be added to the board.\nAfter a billion days, the only two distinct numbers on the board are 2 and 3.\n\nConstraints:\n\n- 1 <= n <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 99) == 98\n assert candidate(n = 20) == 19\n assert candidate(n = 100) == 99\n assert candidate(n = 1) == 1\n assert candidate(n = 10) == 9\n assert candidate(n = 5) == 4\n assert candidate(n = 97) == 96\n assert candidate(n = 88) == 87\n assert candidate(n = 29) == 28\n assert candidate(n = 45) == 44\n assert candidate(n = 61) == 60\n assert candidate(n = 49) == 48\n assert candidate(n = 47) == 46\n assert candidate(n = 82) == 81\n assert candidate(n = 70) == 69\n assert candidate(n = 50) == 49\n assert candidate(n = 34) == 33\n assert candidate(n = 28) == 27\n assert candidate(n = 60) == 59\n assert candidate(n = 87) == 86\n assert candidate(n = 30) == 29\n assert candidate(n = 95) == 94\n assert candidate(n = 67) == 66\n assert candidate(n = 40) == 39\n assert candidate(n = 37) == 36\n assert candidate(n = 64) == 63\n assert candidate(n = 17) == 16\n assert candidate(n = 98) == 97\n assert candidate(n = 2) == 1\n assert candidate(n = 23) == 22\n assert candidate(n = 73) == 72\n assert candidate(n = 80) == 79\n assert candidate(n = 89) == 88\n assert candidate(n = 75) == 74\n assert candidate(n = 71) == 70\n assert candidate(n = 91) == 90\n assert candidate(n = 77) == 76\n assert candidate(n = 81) == 80\n assert candidate(n = 13) == 12\n assert candidate(n = 11) == 10\n assert candidate(n = 85) == 84\n assert candidate(n = 41) == 40\n assert candidate(n = 31) == 30\n assert candidate(n = 83) == 82\n assert candidate(n = 65) == 64\n assert candidate(n = 55) == 54\n assert candidate(n = 7) == 6\n assert candidate(n = 90) == 89\n assert candidate(n = 25) == 24\n", "comparison": "exact"}, "public_tests": ["5", "3"], "hints": ["For n > 2, n % (n - 1) == 1 thus n - 1 will be added on the board the next day.", "As the operations are performed for so long time, all the numbers lesser than n except 1 will be added to the board.", "What will happen if n == 1?"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().distinctIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:48+00:00", "tests_total": 50, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "math", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def distinct_integers(n)", "container": null, "callable": "distinct_integers", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2551, "task_id": "put-marbles-in-bags", "difficulty": "Hard", "problem_description": "You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the i^th marble. You are also given the integer k.\n\nDivide the marbles into the k bags according to the following rules:\n\n- No bag is empty.\n- If the i^th marble and j^th marble are in a bag, then all marbles with an index between the i^th and j^th indices should also be in that same bag.\n- If a bag consists of all the marbles with an index from i to j inclusively, then the cost of the bag is weights[i] + weights[j].\n\nThe score after distributing the marbles is the sum of the costs of all the k bags.\n\nReturn the difference between the maximum and minimum scores among marble distributions.\n\nExample 1:\n\nInput: weights = [1,3,5,1], k = 2\nOutput: 4\nExplanation:\nThe distribution [1],[3,5,1] results in the minimal score of (1+1) + (3+1) = 6.\nThe distribution [1,3],[5,1], results in the maximal score of (1+3) + (5+1) = 10.\nThus, we return their difference 10 - 6 = 4.\n\nExample 2:\n\nInput: weights = [1, 3], k = 2\nOutput: 0\nExplanation: The only distribution possible is [1],[3].\nSince both the maximal and minimal score are the same, we return 0.\n\nConstraints:\n\n- 1 <= k <= weights.length <= 10^5\n- 1 <= weights[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(weights = [1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(weights = [1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(weights = [5, 5, 5, 5, 5, 5],k = 4) == 0\n assert candidate(weights = [1, 3],k = 2) == 0\n assert candidate(weights = [4, 1, 2, 2, 7, 1, 3, 2],k = 3) == 10\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(weights = [1, 3, 5, 1],k = 2) == 4\n assert candidate(weights = [4, 1, 5, 1, 2],k = 3) == 4\n assert candidate(weights = [5, 5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == 30\n assert candidate(weights = [4, 1, 5, 1, 2],k = 3) == 4\n assert candidate(weights = [10, 20, 30, 40, 50],k = 4) == 60\n assert candidate(weights = [10, 20, 30, 40, 50],k = 2) == 60\n assert candidate(weights = [10, 20, 30, 40, 50],k = 2) == 60\n assert candidate(weights = [1, 2, 3, 4, 5],k = 3) == 8\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(weights = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],k = 5) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 0\n assert candidate(weights = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125],k = 5) == 560\n assert candidate(weights = [1000000000, 500000000, 1000000000, 500000000, 1000000000],k = 3) == 0\n assert candidate(weights = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 30\n assert candidate(weights = [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],k = 15) == 0\n assert candidate(weights = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100],k = 15) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 96\n assert candidate(weights = [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],k = 15) == 280\n assert candidate(weights = [100, 200, 100, 200, 100, 200, 100],k = 4) == 0\n assert candidate(weights = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 10) == 0\n assert candidate(weights = [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(weights = [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],k = 13) == 0\n assert candidate(weights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 8) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 180\n assert candidate(weights = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 4000\n assert candidate(weights = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 3) == 280\n assert candidate(weights = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 4) == 300\n assert candidate(weights = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000],k = 4) == 122087790\n assert candidate(weights = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000],k = 4) == 12208779\n assert candidate(weights = [5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2],k = 7) == 0\n assert candidate(weights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 3) == 0\n assert candidate(weights = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 6) == 700\n assert candidate(weights = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 3) == 280\n assert candidate(weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 10) == 0\n assert candidate(weights = [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],k = 25) == 1200\n assert candidate(weights = [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],k = 25) == 720\n assert candidate(weights = [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 = 20) == 380\n assert candidate(weights = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 10) == 18000\n assert candidate(weights = [2, 3, 4, 1, 6, 7, 8],k = 4) == 18\n assert candidate(weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 0\n assert candidate(weights = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000],k = 4) == 0\n assert candidate(weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(weights = [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],k = 20) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == 90\n assert candidate(weights = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 7) == 6000\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 120\n assert candidate(weights = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 9) == 72\n assert candidate(weights = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 32\n assert candidate(weights = [1, 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 = 10) == 0\n assert candidate(weights = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],k = 5) == 2777777775\n assert candidate(weights = [2, 1, 3, 4, 5, 6, 7],k = 4) == 19\n assert candidate(weights = [500000000, 1, 500000000, 1, 500000000, 1, 500000000],k = 3) == 0\n assert candidate(weights = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],k = 6) == 50\n assert candidate(weights = [20, 15, 10, 5, 1, 2, 3, 4, 5, 10, 15, 20],k = 4) == 81\n assert candidate(weights = [5, 1, 3, 8, 2, 9, 4, 7, 6, 10],k = 3) == 19\n assert candidate(weights = [1, 2, 3, 4, 5],k = 1) == 0\n assert candidate(weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 20) == 0\n assert candidate(weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 0\n assert candidate(weights = [5, 1, 3, 2, 4, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 144\n assert candidate(weights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 6) == 0\n assert candidate(weights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 0\n assert candidate(weights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 80\n assert candidate(weights = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 24\n assert candidate(weights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5) == 800\n assert candidate(weights = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200],k = 3) == 0\n assert candidate(weights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 400\n assert candidate(weights = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 6) == 4000\n assert candidate(weights = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6],k = 3) == 28\n assert candidate(weights = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 5) == 320\n assert candidate(weights = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5],k = 10) == 0\n assert candidate(weights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7) == 960\n assert candidate(weights = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],k = 6) == 39\n assert candidate(weights = [9, 1, 8, 2, 7, 3, 6, 4, 5],k = 3) == 2\n assert candidate(weights = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 2) == 1099999989\n assert candidate(weights = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 3) == 12\n assert candidate(weights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 13) == 96\n assert candidate(weights = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],k = 4) == 35\n assert candidate(weights = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],k = 4) == 0\n assert candidate(weights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 6) == 1400\n", "comparison": "exact"}, "public_tests": ["[1,3,5,1]\n2", "[1,3]\n2"], "hints": ["Each bag will contain a subarray, and only the endpoints of these subarrays matter.", "Each subarray only contributes two numbers to the sum. Use this property to choose the subarrays optimally.", "Try to use a priority queue."], "metadata": {"canonical_parameter_names": ["weights", "k"], "leetcode_dataset_entry_point": "Solution().putMarbles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:50+00:00", "tests_total": 87, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def put_marbles(weights, k)", "container": null, "callable": "put_marbles", "parameters": [{"name": "weights", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2552, "task_id": "count-increasing-quadruplets", "difficulty": "Hard", "problem_description": "Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.\n\nA quadruplet (i, j, k, l) is increasing if:\n\n- 0 <= i < j < k < l < n, and\n- nums[i] < nums[k] < nums[j] < nums[l].\n\nExample 1:\n\nInput: nums = [1,3,2,4,5]\nOutput: 2\nExplanation:\n- When i = 0, j = 1, k = 2, and l = 3, nums[i] < nums[k] < nums[j] < nums[l].\n- When i = 0, j = 1, k = 2, and l = 4, nums[i] < nums[k] < nums[j] < nums[l].\nThere are no other quadruplets, so we return 2.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 0\nExplanation: There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0.\n\nConstraints:\n\n- 4 <= nums.length <= 4000\n- 1 <= nums[i] <= nums.length\n- All the integers of nums are unique. nums is a permutation.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 2\n assert candidate(nums = [4, 3, 2, 1]) == 0\n assert candidate(nums = [4, 3, 2, 1, 5, 6]) == 0\n assert candidate(nums = [3, 1, 4, 2, 5, 6, 9, 7, 8, 10]) == 18\n assert candidate(nums = [5, 2, 3, 1, 4, 6, 7]) == 0\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 7]) == 10\n assert candidate(nums = [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]) == 0\n assert candidate(nums = [3, 1, 2, 4, 5]) == 0\n assert candidate(nums = [2, 3, 1, 5, 4, 8, 7, 10, 9, 6]) == 25\n assert candidate(nums = [1, 2, 3, 4]) == 0\n assert candidate(nums = [5, 1, 4, 2, 3]) == 0\n assert candidate(nums = [3, 1, 2, 6, 5, 4, 9, 7, 10, 8]) == 42\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 35\n assert candidate(nums = [1, 4, 3, 2, 5]) == 3\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7]) == 0\n assert candidate(nums = [1, 2, 4, 3, 5, 6, 7]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 0\n assert candidate(nums = [5, 2, 3, 4, 1, 6, 7]) == 0\n assert candidate(nums = [1, 4, 2, 3, 5]) == 2\n assert candidate(nums = [2, 3, 1, 4, 5]) == 0\n assert candidate(nums = [5, 1, 4, 3, 2]) == 0\n assert candidate(nums = [20, 1, 18, 3, 16, 5, 14, 7, 12, 9, 10, 11, 8, 13, 6, 15, 4, 17, 2, 19]) == 370\n assert candidate(nums = [1, 15, 3, 14, 4, 13, 5, 12, 6, 11, 7, 10, 8, 9, 2]) == 0\n assert candidate(nums = [4, 10, 3, 6, 2, 8, 1, 7, 5, 9]) == 13\n assert candidate(nums = [30, 1, 29, 2, 28, 3, 27, 4, 26, 5, 25, 6, 24, 7, 23, 8, 22, 9, 21, 10, 20, 11, 19, 12, 18, 13, 17, 14, 16, 15]) == 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]) == 0\n assert candidate(nums = [7, 1, 6, 2, 5, 3, 4]) == 0\n assert candidate(nums = [5, 2, 8, 3, 7, 4, 10, 6, 1, 9]) == 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]) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\n assert candidate(nums = [6, 1, 8, 3, 9, 2, 10, 5, 7, 4]) == 8\n assert candidate(nums = [12, 1, 11, 2, 10, 3, 9, 4, 8, 5, 7, 6]) == 0\n assert candidate(nums = [20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10]) == 0\n assert candidate(nums = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5]) == 0\n assert candidate(nums = [1, 6, 3, 2, 8, 5, 4, 9, 10, 7]) == 41\n assert candidate(nums = [8, 6, 5, 7, 4, 3, 2, 1, 9, 10, 11, 12]) == 0\n assert candidate(nums = [12, 1, 11, 2, 10, 3, 9, 4, 8, 5, 7, 6]) == 0\n assert candidate(nums = [1, 4, 2, 7, 3, 8, 5, 10, 6, 11, 9, 14, 12, 15, 13]) == 224\n assert candidate(nums = [4, 7, 10, 2, 6, 8, 3, 5, 9, 1]) == 9\n assert candidate(nums = [15, 1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8]) == 0\n assert candidate(nums = [10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == 0\n assert candidate(nums = [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 = [3, 8, 5, 2, 9, 4, 7, 1, 6, 10]) == 20\n assert candidate(nums = [40, 1, 39, 2, 38, 3, 37, 4, 36, 5, 35, 6, 34, 7, 33, 8, 32, 9, 31, 10, 30, 11, 29, 12, 28, 13, 27, 14, 26, 15, 25, 16, 24, 17, 23, 18, 22, 19, 21, 20]) == 0\n assert candidate(nums = [10, 1, 3, 2, 9, 5, 7, 4, 8, 6]) == 15\n assert candidate(nums = [20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10]) == 0\n assert candidate(nums = [15, 1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8]) == 0\n assert candidate(nums = [10, 1, 3, 5, 2, 6, 4, 7, 8, 9]) == 24\n assert candidate(nums = [3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13]) == 270\n assert candidate(nums = [1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 3]) == 140\n assert candidate(nums = [30, 1, 29, 2, 28, 3, 27, 4, 26, 5, 25, 6, 24, 7, 23, 8, 22, 9, 21, 10, 20, 11, 19, 12, 18, 13, 17, 14, 16, 15]) == 0\n assert candidate(nums = [4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 14, 13, 12, 11]) == 240\n assert candidate(nums = [4, 1, 5, 3, 8, 2, 7, 6, 10, 9]) == 41\n assert candidate(nums = [7, 1, 5, 3, 9, 2, 8, 4, 10, 6]) == 23\n assert candidate(nums = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == 0\n assert candidate(nums = [3, 5, 2, 1, 6, 4, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]) == 448\n assert candidate(nums = [3, 6, 1, 5, 8, 2, 7, 4, 10, 9]) == 33\n assert candidate(nums = [3, 7, 5, 4, 10, 6, 1, 9, 8, 2]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 0\n assert candidate(nums = [8, 1, 7, 2, 6, 3, 5, 4]) == 0\n assert candidate(nums = [8, 1, 10, 4, 6, 2, 9, 3, 7, 5]) == 8\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]) == 480\n assert candidate(nums = [15, 1, 6, 9, 3, 11, 4, 14, 2, 7, 13, 5, 12, 8, 10]) == 83\n assert candidate(nums = [7, 2, 9, 4, 10, 3, 1, 8, 5, 6]) == 4\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 182\n assert candidate(nums = [9, 2, 7, 5, 1, 8, 3, 6, 10, 4]) == 11\n assert candidate(nums = [1, 5, 2, 9, 3, 6, 4, 7, 8, 10]) == 34\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10]) == 30\n assert candidate(nums = [10, 3, 6, 7, 2, 5, 9, 1, 8, 4]) == 4\n assert candidate(nums = [4, 3, 5, 1, 6, 2, 7, 8, 9, 10]) == 4\n assert candidate(nums = [7, 1, 3, 10, 2, 8, 5, 9, 4, 6]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16]) == 1000\n assert candidate(nums = [1, 20, 2, 19, 3, 18, 4, 17, 5, 16, 6, 15, 7, 14, 8, 13, 9, 12, 10, 11]) == 0\n assert candidate(nums = [1, 5, 7, 3, 6, 9, 2, 10, 8, 4]) == 23\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]) == 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 = [10, 2, 7, 4, 6, 3, 9, 1, 8, 5]) == 11\n assert candidate(nums = [7, 1, 5, 3, 6, 2, 4, 8, 9]) == 16\n assert candidate(nums = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == 0\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]) == 40\n", "comparison": "exact"}, "public_tests": ["[1,3,2,4,5]", "[1,2,3,4]"], "hints": ["Can you loop over all possible (j, k) and find the answer?", "We can pre-compute all possible (i, j) and (k, l) and store them in 2 matrices.", "The answer will the sum of prefix[j][k] * suffix[k][j]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countQuadruplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:52+00:00", "tests_total": 90, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "dynamic-programming", "binary-indexed-tree", "enumeration", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def count_quadruplets(nums)", "container": null, "callable": "count_quadruplets", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2553, "task_id": "separate-the-digits-in-an-array", "difficulty": "Easy", "problem_description": "Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.\n\nTo separate the digits of an integer is to get all the digits it has in the same order.\n\n- For example, for the integer 10921, the separation of its digits is [1,0,9,2,1].\n\nExample 1:\n\nInput: nums = [13,25,83,77]\nOutput: [1,3,2,5,8,3,7,7]\nExplanation:\n- The separation of 13 is [1,3].\n- The separation of 25 is [2,5].\n- The separation of 83 is [8,3].\n- The separation of 77 is [7,7].\nanswer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.\n\nExample 2:\n\nInput: nums = [7,1,3,9]\nOutput: [7,1,3,9]\nExplanation: The separation of each integer in nums is itself.\nanswer = [7,1,3,9].\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10921, 456, 78]) == [1, 0, 9, 2, 1, 4, 5, 6, 7, 8]\n assert candidate(nums = [98765, 43210, 11111, 22222]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]\n assert candidate(nums = [98765, 43210]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [7, 1, 3, 9]) == [7, 1, 3, 9]\n assert candidate(nums = [999, 888, 777, 666, 555]) == [9, 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5]\n assert candidate(nums = [10921, 123, 456, 789]) == [1, 0, 9, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [10921, 2024, 55]) == [1, 0, 9, 2, 1, 2, 0, 2, 4, 5, 5]\n assert candidate(nums = [100, 200, 300, 400]) == [1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0]\n assert candidate(nums = [9, 99, 999, 9999, 99999]) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [13, 25, 83, 77]) == [1, 3, 2, 5, 8, 3, 7, 7]\n assert candidate(nums = [10921, 123, 4567, 89]) == [1, 0, 9, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [98765, 43210, 10203]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0, 2, 0, 3]\n assert candidate(nums = [111, 222, 333, 444]) == [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]\n assert candidate(nums = [12345, 67890, 111]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 1, 1]\n assert candidate(nums = [111, 222, 333]) == [1, 1, 1, 2, 2, 2, 3, 3, 3]\n assert candidate(nums = [505, 303, 101]) == [5, 0, 5, 3, 0, 3, 1, 0, 1]\n assert candidate(nums = [10921, 2023]) == [1, 0, 9, 2, 1, 2, 0, 2, 3]\n assert candidate(nums = [12345, 67890, 11111]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 1, 1, 1, 1]\n assert candidate(nums = [99998, 88887, 77776, 66665, 55554]) == [9, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4]\n assert candidate(nums = [1, 11, 111, 1111, 11111]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1234, 5678, 91011, 1213]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 1, 1, 2, 1, 3]\n assert candidate(nums = [54321, 12345, 98765, 56789, 23456]) == [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 9, 8, 7, 6, 5, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6]\n assert candidate(nums = [123, 456, 789, 101, 202, 303]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 2, 0, 2, 3, 0, 3]\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5]\n assert candidate(nums = [54321, 12345, 67890, 98765]) == [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 9, 8, 7, 6, 5]\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == [1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0]\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == [1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0]\n assert candidate(nums = [10101, 20202, 30303, 40404]) == [1, 0, 1, 0, 1, 2, 0, 2, 0, 2, 3, 0, 3, 0, 3, 4, 0, 4, 0, 4]\n assert candidate(nums = [987, 654, 321, 876, 543, 210]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1001, 2002, 3003, 4004]) == [1, 0, 0, 1, 2, 0, 0, 2, 3, 0, 0, 3, 4, 0, 0, 4]\n assert candidate(nums = [100000, 20000, 3000, 400, 50, 6]) == [1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 5, 0, 6]\n assert candidate(nums = [1, 20, 300, 4000, 50000]) == [1, 2, 0, 3, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 0]\n assert candidate(nums = [12, 23, 34, 45, 56, 67, 78, 89, 90]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 0]\n assert candidate(nums = [12, 34, 56, 78, 90, 1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10101, 20202, 30303]) == [1, 0, 1, 0, 1, 2, 0, 2, 0, 2, 3, 0, 3, 0, 3]\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4]\n assert candidate(nums = [98765, 43210, 54321, 65432, 76543]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3]\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005]) == [1, 0, 0, 1, 2, 0, 0, 2, 3, 0, 0, 3, 4, 0, 0, 4, 5, 0, 0, 5]\n assert candidate(nums = [1, 22, 333, 4444, 55555]) == [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0]\n assert candidate(nums = [55555, 4444, 333, 22, 1]) == [5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]\n assert candidate(nums = [99999, 88888, 77777, 66666, 55555, 44444]) == [9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0]\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == [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]\n assert candidate(nums = [10, 100, 1000, 10000, 100000]) == [1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n assert candidate(nums = [12, 34, 56, 78, 90, 11, 22, 33, 44, 55]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]\n assert candidate(nums = [99999, 8888, 777, 66, 5, 4, 3, 2, 1]) == [9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 23, 456, 7890, 12345]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10001, 20002, 30003, 40004, 50005]) == [1, 0, 0, 0, 1, 2, 0, 0, 0, 2, 3, 0, 0, 0, 3, 4, 0, 0, 0, 4, 5, 0, 0, 0, 5]\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909]) == [1, 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7, 0, 7, 8, 0, 8, 9, 0, 9]\n assert candidate(nums = [98765, 87654, 76543, 65432, 54321]) == [9, 8, 7, 6, 5, 8, 7, 6, 5, 4, 7, 6, 5, 4, 3, 6, 5, 4, 3, 2, 5, 4, 3, 2, 1]\n assert candidate(nums = [54321, 65432, 76543, 87654]) == [5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 8, 7, 6, 5, 4]\n", "comparison": "exact"}, "public_tests": ["[13,25,83,77]", "[7,1,3,9]"], "hints": ["Convert each number into a list and append that list to the answer.", "You can convert the integer into a string to do that easily."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().separateDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:55+00:00", "tests_total": 110, "tests_dropped": 57, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def separate_digits(nums)", "container": null, "callable": "separate_digits", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2554, "task_id": "maximum-number-of-integers-to-choose-from-a-range-i", "difficulty": "Medium", "problem_description": "You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:\n\n- The chosen integers have to be in the range [1, n].\n- Each integer can be chosen at most once.\n- The chosen integers should not be in the array banned.\n- The sum of the chosen integers should not exceed maxSum.\n\nReturn the maximum number of integers you can choose following the mentioned rules.\n\nExample 1:\n\nInput: banned = [1,6,5], n = 5, maxSum = 6\nOutput: 2\nExplanation: You can choose the integers 2 and 4.\n2 and 4 are from the range [1, 5], both did not appear in banned, and their sum is 6, which did not exceed maxSum.\n\nExample 2:\n\nInput: banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1\nOutput: 0\nExplanation: You cannot choose any integer while following the mentioned conditions.\n\nExample 3:\n\nInput: banned = [11], n = 7, maxSum = 50\nOutput: 7\nExplanation: You can choose the integers 1, 2, 3, 4, 5, 6, and 7.\nThey are from the range [1, 7], all did not appear in banned, and their sum is 28, which did not exceed maxSum.\n\nConstraints:\n\n- 1 <= banned.length <= 10^4\n- 1 <= banned[i], n <= 10^4\n- 1 <= maxSum <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(banned = [11],n = 7,maxSum = 50) == 7\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7],n = 8,maxSum = 1) == 0\n assert candidate(banned = [1, 6, 5],n = 5,maxSum = 6) == 2\n assert candidate(banned = [2, 4, 6, 8],n = 10,maxSum = 30) == 5\n assert candidate(banned = [2, 4, 6, 8],n = 10,maxSum = 15) == 3\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],n = 10,maxSum = 55) == 0\n assert candidate(banned = [5, 6, 7, 8, 9, 10],n = 10,maxSum = 1) == 1\n assert candidate(banned = [100, 200, 300],n = 500,maxSum = 1500) == 54\n assert candidate(banned = [10],n = 10,maxSum = 10) == 4\n assert candidate(banned = [1, 3, 5, 7, 9],n = 10,maxSum = 25) == 4\n assert candidate(banned = [3, 5, 7],n = 10,maxSum = 25) == 5\n assert candidate(banned = [2, 4, 6, 8],n = 10,maxSum = 15) == 3\n assert candidate(banned = [1, 2, 3],n = 3,maxSum = 5) == 0\n assert candidate(banned = [3, 5, 7, 9],n = 15,maxSum = 40) == 6\n assert candidate(banned = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],n = 20,maxSum = 100) == 9\n assert candidate(banned = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],n = 100,maxSum = 1000) == 41\n assert candidate(banned = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],n = 100,maxSum = 1500) == 51\n assert candidate(banned = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],n = 100,maxSum = 450) == 28\n assert candidate(banned = [9996, 9997, 9998, 9999, 10000],n = 10000,maxSum = 50000000) == 9995\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],n = 20,maxSum = 150) == 5\n assert candidate(banned = [10, 20, 30, 40, 50],n = 50,maxSum = 1275) == 45\n assert candidate(banned = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],n = 100,maxSum = 4950) == 89\n assert candidate(banned = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],n = 50,maxSum = 125) == 14\n assert candidate(banned = [5000, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009],n = 10000,maxSum = 25000000) == 7067\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],n = 15,maxSum = 45) == 3\n assert candidate(banned = [100, 200, 300, 400],n = 500,maxSum = 10000) == 140\n assert candidate(banned = [1, 3, 5, 7, 9],n = 15,maxSum = 50) == 6\n assert candidate(banned = [5000, 5001, 5002, 5003, 5004],n = 10000,maxSum = 25000000) == 7069\n assert candidate(banned = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],n = 30,maxSum = 250) == 15\n assert candidate(banned = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60],n = 100,maxSum = 2500) == 67\n assert candidate(banned = [1000],n = 10000,maxSum = 1000000) == 1413\n assert candidate(banned = [100, 200, 300, 400, 500],n = 1000,maxSum = 10000) == 140\n assert candidate(banned = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60],n = 100,maxSum = 5000) == 89\n assert candidate(banned = [15, 25, 35, 45, 55, 65, 75, 85, 95],n = 100,maxSum = 4500) == 90\n assert candidate(banned = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],n = 50,maxSum = 1000) == 40\n assert candidate(banned = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],n = 100,maxSum = 3000) == 70\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],n = 20,maxSum = 150) == 9\n assert candidate(banned = [1, 2, 3, 4, 5],n = 10000,maxSum = 1000000000) == 9995\n assert candidate(banned = [1000, 2000, 3000, 4000],n = 5000,maxSum = 12500000) == 4996\n assert candidate(banned = [9999],n = 10000,maxSum = 10000) == 140\n assert candidate(banned = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],n = 50,maxSum = 600) == 24\n assert candidate(banned = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],n = 10000,maxSum = 10000000) == 4460\n assert candidate(banned = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],n = 30,maxSum = 150) == 12\n assert candidate(banned = [1, 10, 100, 1000, 10000],n = 10000,maxSum = 50005000) == 9995\n assert candidate(banned = [50, 51, 52, 53, 54, 55],n = 100,maxSum = 1000) == 44\n assert candidate(banned = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99],n = 100,maxSum = 1500) == 47\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],n = 25,maxSum = 100) == 4\n assert candidate(banned = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],n = 50,maxSum = 1275) == 40\n assert candidate(banned = [1, 3, 5, 7, 9],n = 10,maxSum = 25) == 4\n assert candidate(banned = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],n = 30,maxSum = 250) == 18\n assert candidate(banned = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],n = 20,maxSum = 190) == 10\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],n = 20,maxSum = 190) == 0\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],n = 20,maxSum = 90) == 5\n assert candidate(banned = [2, 3, 5, 7, 11, 13, 17, 19],n = 20,maxSum = 50) == 7\n assert candidate(banned = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],n = 1000,maxSum = 500500) == 990\n assert candidate(banned = [100, 200, 300, 400, 500],n = 1000,maxSum = 5000) == 99\n assert candidate(banned = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],n = 30,maxSum = 225) == 15\n assert candidate(banned = [15, 16, 17, 18, 19, 20],n = 20,maxSum = 150) == 14\n assert candidate(banned = [1],n = 10000,maxSum = 5000000) == 3160\n assert candidate(banned = [2, 4, 6, 8, 10, 12, 14, 16],n = 20,maxSum = 100) == 10\n assert candidate(banned = [2, 4, 6, 8, 10],n = 15,maxSum = 50) == 7\n assert candidate(banned = [1, 10, 100, 1000, 10000],n = 10000,maxSum = 50000000) == 9995\n assert candidate(banned = [101, 102, 103, 104, 105],n = 150,maxSum = 10000) == 139\n assert candidate(banned = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],n = 40,maxSum = 400) == 19\n assert candidate(banned = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],n = 20,maxSum = 100) == 10\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],n = 20,maxSum = 190) == 1\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],n = 20,maxSum = 210) == 0\n assert candidate(banned = [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],n = 100,maxSum = 2500) == 49\n assert candidate(banned = [1, 2, 3, 4, 5],n = 10,maxSum = 20) == 2\n assert candidate(banned = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],n = 15,maxSum = 50) == 4\n assert candidate(banned = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],n = 1500,maxSum = 100000) == 444\n assert candidate(banned = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],n = 1000,maxSum = 5000) == 99\n assert candidate(banned = [1, 3, 5, 7, 9, 11, 13, 15],n = 15,maxSum = 60) == 7\n assert candidate(banned = [2, 4, 6, 8, 10],n = 20,maxSum = 100) == 10\n assert candidate(banned = [15, 30, 45, 60, 75],n = 100,maxSum = 3775) == 83\n assert candidate(banned = [1],n = 10000,maxSum = 50005000) == 9999\n assert candidate(banned = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],n = 150,maxSum = 1000) == 42\n assert candidate(banned = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],n = 10000,maxSum = 1000000) == 1413\n assert candidate(banned = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145],n = 150,maxSum = 1000) == 41\n assert candidate(banned = [1000],n = 2000,maxSum = 1000000) == 1413\n assert candidate(banned = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],n = 110,maxSum = 1050) == 45\n assert candidate(banned = [15, 16, 17, 18, 19, 20],n = 20,maxSum = 190) == 14\n assert candidate(banned = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],n = 20,maxSum = 150) == 10\n assert candidate(banned = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],n = 50,maxSum = 200) == 17\n assert candidate(banned = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],n = 1000,maxSum = 20000) == 198\n assert candidate(banned = [100, 101, 102, 103, 104],n = 110,maxSum = 500) == 31\n assert candidate(banned = [5, 10, 15, 20, 25],n = 30,maxSum = 200) == 17\n assert candidate(banned = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],n = 100,maxSum = 2500) == 63\n assert candidate(banned = [10, 20, 30, 40, 50],n = 60,maxSum = 1770) == 55\n assert candidate(banned = [10000],n = 10000,maxSum = 10000000) == 4471\n assert candidate(banned = [50, 51, 52, 53, 54, 55],n = 100,maxSum = 2500) == 68\n assert candidate(banned = [20, 40, 60, 80, 100],n = 100,maxSum = 500) == 30\n assert candidate(banned = [1, 3, 5, 7, 9],n = 15,maxSum = 60) == 7\n assert candidate(banned = [2500, 5000, 7500],n = 10000,maxSum = 25000000) == 7069\n assert candidate(banned = [1],n = 100,maxSum = 5050) == 99\n assert candidate(banned = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],n = 20,maxSum = 90) == 9\n assert candidate(banned = [1, 3, 5, 7, 9, 11, 13, 15],n = 15,maxSum = 100) == 7\n", "comparison": "exact"}, "public_tests": ["[1,6,5]\n5\n6", "[1,2,3,4,5,6,7]\n8\n1", "[11]\n7\n50"], "hints": ["Keep the banned numbers that are less than or equal to n in a set.", "Loop over the numbers from 1 to n and if the number is not banned, use it.", "Keep adding numbers while they are not banned, and their sum is less than or equal to k."], "metadata": {"canonical_parameter_names": ["banned", "n", "maxSum"], "leetcode_dataset_entry_point": "Solution().maxCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:56:57+00:00", "tests_total": 101, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_count(banned, n, max_sum)", "container": null, "callable": "max_count", "parameters": [{"name": "banned", "type": "Integer[]"}, {"name": "n", "type": "Integer"}, {"name": "max_sum", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2555, "task_id": "maximize-win-from-two-segments", "difficulty": "Medium", "problem_description": "There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the i^th prize. There could be different prizes at the same position on the line. You are also given an integer k.\n\nYou are allowed to select two segments with integer endpoints. The length of each segment must be k. You will collect all prizes whose position falls within at least one of the two selected segments (including the endpoints of the segments). The two selected segments may intersect.\n\n- For example if k = 2, you can choose segments [1, 3] and [2, 4], and you will win any prize i that satisfies 1 <= prizePositions[i] <= 3 or 2 <= prizePositions[i] <= 4.\n\nReturn the maximum number of prizes you can win if you choose the two segments optimally.\n\nExample 1:\n\nInput: prizePositions = [1,1,2,2,3,3,5], k = 2\nOutput: 7\nExplanation: In this example, you can win all 7 prizes by selecting two segments [1, 3] and [3, 5].\n\nExample 2:\n\nInput: prizePositions = [1,2,3,4], k = 0\nOutput: 2\nExplanation: For this example, one choice for the segments is [3, 3] and [4, 4], and you will be able to get 2 prizes.\n\nConstraints:\n\n- 1 <= prizePositions.length <= 10^5\n- 1 <= prizePositions[i] <= 10^9\n- 0 <= k <= 10^9\n- prizePositions is sorted in non-decreasing order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(prizePositions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(prizePositions = [1, 3, 5, 7, 9],k = 1) == 2\n assert candidate(prizePositions = [5, 5, 5, 5, 5],k = 1) == 5\n assert candidate(prizePositions = [5, 5, 5, 5, 5],k = 3) == 5\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 8\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 5],k = 2) == 7\n assert candidate(prizePositions = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 20\n assert candidate(prizePositions = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 9],k = 3) == 18\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 6\n assert candidate(prizePositions = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],k = 5) == 4\n assert candidate(prizePositions = [1, 3, 5, 7, 9],k = 2) == 4\n assert candidate(prizePositions = [1, 1, 1, 1, 1],k = 0) == 5\n assert candidate(prizePositions = [1, 2, 3, 4],k = 0) == 2\n assert candidate(prizePositions = [1, 2, 2, 2, 3, 4, 5, 5],k = 2) == 8\n assert candidate(prizePositions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 4\n assert candidate(prizePositions = [1, 2, 2, 3, 3, 3, 4, 4, 5],k = 2) == 9\n assert candidate(prizePositions = [1, 3, 5, 7, 9],k = 4) == 5\n assert candidate(prizePositions = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15],k = 3) == 20\n assert candidate(prizePositions = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 4\n assert candidate(prizePositions = [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],k = 3) == 16\n assert candidate(prizePositions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 4\n assert candidate(prizePositions = [1, 3, 6, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 5\n assert candidate(prizePositions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10],k = 1) == 14\n assert candidate(prizePositions = [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],k = 5) == 30\n assert candidate(prizePositions = [1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 10, 10],k = 4) == 15\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 8\n assert candidate(prizePositions = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],k = 10) == 4\n assert candidate(prizePositions = [1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16],k = 5) == 31\n assert candidate(prizePositions = [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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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, 10],k = 10) == 70\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 20\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 6\n assert candidate(prizePositions = [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],k = 6) == 36\n assert candidate(prizePositions = [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],k = 2) == 33\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 6\n assert candidate(prizePositions = [1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, 19, 19, 21, 21, 23, 23, 25, 25, 27, 27, 29, 29],k = 2) == 8\n assert candidate(prizePositions = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 15) == 8\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 6\n assert candidate(prizePositions = [1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10],k = 2) == 9\n assert candidate(prizePositions = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80],k = 20) == 42\n assert candidate(prizePositions = [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],k = 0) == 8\n assert candidate(prizePositions = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10],k = 4) == 40\n assert candidate(prizePositions = [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],k = 5) == 28\n assert candidate(prizePositions = [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],k = 4) == 6\n assert candidate(prizePositions = [1, 1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13],k = 4) == 24\n assert candidate(prizePositions = [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, 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],k = 5) == 62\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25],k = 5) == 12\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10],k = 3) == 12\n assert candidate(prizePositions = [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 = 15) == 30\n assert candidate(prizePositions = [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],k = 1) == 24\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 5) == 6\n assert candidate(prizePositions = [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],k = 1) == 30\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 2) == 12\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 4) == 6\n assert candidate(prizePositions = [1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 13, 14, 15],k = 4) == 20\n assert candidate(prizePositions = [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],k = 5) == 12\n assert candidate(prizePositions = [1, 2, 2, 3, 3, 4, 5, 5, 5, 6, 7, 8, 8, 9, 10, 10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 20\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 12\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 3) == 16\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],k = 9) == 38\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15],k = 2) == 13\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 6\n assert candidate(prizePositions = [1, 1, 1, 1, 1, 1, 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) == 30\n assert candidate(prizePositions = [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 = 0) == 2\n assert candidate(prizePositions = [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],k = 2) == 18\n assert candidate(prizePositions = [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, 10, 10, 10, 10, 10, 10, 10],k = 8) == 70\n assert candidate(prizePositions = [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],k = 10) == 44\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 20\n assert candidate(prizePositions = [1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 7) == 20\n assert candidate(prizePositions = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 6) == 28\n assert candidate(prizePositions = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6],k = 3) == 29\n assert candidate(prizePositions = [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 = 0) == 2\n assert candidate(prizePositions = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 8) == 7\n assert candidate(prizePositions = [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],k = 15) == 32\n assert candidate(prizePositions = [1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 7) == 22\n assert candidate(prizePositions = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 2) == 16\n assert candidate(prizePositions = [1, 2, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 10],k = 3) == 12\n assert candidate(prizePositions = [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],k = 10) == 22\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14],k = 4) == 22\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 0) == 2\n assert candidate(prizePositions = [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],k = 2) == 18\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 6) == 14\n assert candidate(prizePositions = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13],k = 1) == 14\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 19) == 20\n assert candidate(prizePositions = [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],k = 15) == 40\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 6\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 3) == 17\n assert candidate(prizePositions = [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) == 12\n assert candidate(prizePositions = [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],k = 3) == 32\n assert candidate(prizePositions = [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 = 10) == 22\n assert candidate(prizePositions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 0) == 12\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 5) == 20\n assert candidate(prizePositions = [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 = 10) == 22\n assert candidate(prizePositions = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 4) == 20\n assert candidate(prizePositions = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10],k = 2) == 16\n assert candidate(prizePositions = [1, 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, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 3) == 49\n assert candidate(prizePositions = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10, 10],k = 1) == 16\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 3) == 4\n assert candidate(prizePositions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 1) == 2\n", "comparison": "exact"}, "public_tests": ["[1,1,2,2,3,3,5]\n2", "[1,2,3,4]\n0"], "hints": ["Try solving the problem for one interval.", "Using the solution with one interval, how can you combine that with a second interval?"], "metadata": {"canonical_parameter_names": ["prizePositions", "k"], "leetcode_dataset_entry_point": "Solution().maximizeWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:00+00:00", "tests_total": 98, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def maximize_win(prize_positions, k)", "container": null, "callable": "maximize_win", "parameters": [{"name": "prize_positions", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2556, "task_id": "disconnect-path-in-a-binary-matrix-by-at-most-one-flip", "difficulty": "Medium", "problem_description": "You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).\n\nYou can flip the value of at most one (possibly none) cell. You cannot flip the cells (0, 0) and (m - 1, n - 1).\n\nReturn true if it is possible to make the matrix disconnect or false otherwise.\n\nNote that flipping a cell changes its value from 0 to 1 or from 1 to 0.\n\nExample 1:\n\nInput: grid = [[1,1,1],[1,0,0],[1,1,1]]\nOutput: true\nExplanation: We can change the cell shown in the diagram above. There is no path from (0, 0) to (2, 2) in the resulting grid.\n\nExample 2:\n\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: false\nExplanation: It is not possible to change at most one cell such that there is not path from (0, 0) to (2, 2).\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 1000\n- 1 <= m * n <= 10^5\n- grid[i][j] is either 0 or 1.\n- grid[0][0] == grid[m - 1][n - 1] == 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 0, 1], [1, 0, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1], [1, 0, 0], [1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0], [1, 0, 0, 0], [1, 1, 1, 0], [1, 0, 1, 1]]) == True\n assert candidate(grid = [[1, 0], [0, 1]]) == True\n assert candidate(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 0], [0, 1, 0], [0, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0], [1, 1, 1, 0], [0, 1, 1, 1], [0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0], [1, 1, 1, 0], [0, 1, 1, 1], [0, 0, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 1, 1], [1, 1, 0, 0], [1, 1, 1, 0], [0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 1, 1, 0], [0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0], [1, 0, 1], [1, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0], [1, 1, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0], [1, 1, 1], [0, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 1], [1, 1, 1], [1, 0, 1]]) == True\n assert candidate(grid = [[1, 1], [1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1], [1, 1, 1, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 0, 1, 0, 1, 1], [1, 1, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0], [1, 0, 0, 1, 1], [1, 1, 0, 0, 1], [0, 1, 1, 1, 0], [1, 0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1], [0, 1, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 0, 1, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1, 0], [1, 1, 0, 0, 0, 0, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 0, 1], [1, 0, 1, 1, 1], [1, 1, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1, 0, 1, 1], [0, 1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1, 0, 1, 1], [1, 1, 0, 1, 1, 0, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 0], [1, 0, 0, 1, 0], [1, 1, 0, 1, 1], [0, 1, 1, 0, 1], [1, 0, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 0, 1], [1, 0, 0, 1, 1, 1, 0, 1], [1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 1, 1, 1, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0, 0], [1, 0, 0, 1, 1, 0], [1, 1, 0, 0, 1, 1], [0, 1, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 1, 1], [1, 0, 0, 0, 1, 1, 0, 1], [1, 1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 1, 1], [1, 0, 1, 0, 1, 1, 0, 1], [1, 1, 1, 1, 0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1], [0, 1, 0, 1, 1], [1, 0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 1, 0], [1, 0, 1, 1, 1, 1], [0, 1, 1, 0, 0, 1], [1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 0, 0, 1, 0], [1, 0, 1, 0, 1, 1], [1, 1, 1, 0, 1, 0], [1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 0, 1, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 0, 1], [1, 0, 1, 1, 0, 1], [1, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 0, 1], [1, 1, 0, 0, 1, 1], [0, 1, 1, 0, 1, 1], [1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 1, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 0], [1, 0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1, 1], [1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0], [1, 1, 1, 1, 0], [0, 0, 0, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 1, 1, 1, 1], [1, 0, 1, 0, 0, 0, 1, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1, 1, 0, 1], [1, 0, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1], [1, 1, 1, 0, 1, 1], [1, 0, 0, 1, 1, 0], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 0, 1, 1], [1, 0, 0, 1, 1, 1, 1, 0, 1], [1, 1, 1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1, 1], [0, 1, 1, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1, 1], [1, 1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 0, 1], [1, 0, 0, 1, 1], [1, 1, 0, 0, 1], [0, 1, 1, 0, 1], [1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 1, 1, 1, 1, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 0, 1], [0, 0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 1, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 0, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 1, 0, 1], [1, 0, 1, 1, 1], [1, 1, 0, 0, 1], [1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 0, 1, 0, 1], [1, 1, 1, 0, 1], [1, 0, 0, 1, 1], [1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1], [1, 1, 1, 0, 1, 1], [1, 0, 1, 1, 0, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 1], [1, 0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 1, 1, 1, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1, 0, 1, 1], [1, 1, 1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 0, 1, 0, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 0, 1, 0, 1, 1], [1, 1, 1, 0, 1, 1, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 0, 1, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 1, 1, 0], [1, 0, 1, 1, 1, 0, 1], [1, 1, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [1, 0, 1, 1, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1], [0, 1, 0, 1, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [1, 1, 1, 0, 0, 1], [1, 0, 1, 1, 0, 1], [1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 1], [1, 0, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == True\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 0, 1, 1, 1], [1, 1, 0, 1, 1], [0, 1, 1, 0, 1], [1, 1, 1, 1, 1]]) == True\n", "comparison": "exact"}, "public_tests": ["[[1,1,1],[1,0,0],[1,1,1]]", "[[1,1,1],[1,0,1],[1,1,1]]"], "hints": ["We can consider the grid a graph with edges between adjacent cells.", "If you can find two non-intersecting paths from (0, 0) to (m - 1, n - 1) then the answer is false. Otherwise, it is always true."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().isPossibleToCutPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:02+00:00", "tests_total": 81, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "depth-first-search", "breadth-first-search", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def is_possible_to_cut_path(grid)", "container": null, "callable": "is_possible_to_cut_path", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2558, "task_id": "take-gifts-from-the-richest-pile", "difficulty": "Easy", "problem_description": "You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:\n\n- Choose the pile with the maximum number of gifts.\n- If there is more than one pile with the maximum number of gifts, choose any.\n- Reduce the number of gifts in the pile to the floor of the square root of the original number of gifts in the pile.\n\nReturn the number of gifts remaining after k seconds.\n\nExample 1:\n\nInput: gifts = [25,64,9,4,100], k = 4\nOutput: 29\nExplanation:\nThe gifts are taken in the following way:\n- In the first second, the last pile is chosen and 10 gifts are left behind.\n- Then the second pile is chosen and 8 gifts are left behind.\n- After that the first pile is chosen and 5 gifts are left behind.\n- Finally, the last pile is chosen again and 3 gifts are left behind.\nThe final remaining gifts are [5,8,9,4,3], so the total number of gifts remaining is 29.\n\nExample 2:\n\nInput: gifts = [1,1,1,1], k = 4\nOutput: 4\nExplanation:\nIn this case, regardless which pile you choose, you have to leave behind 1 gift in each pile.\nThat is, you can't take any pile with you.\nSo, the total gifts remaining are 4.\n\nConstraints:\n\n- 1 <= gifts.length <= 10^3\n- 1 <= gifts[i] <= 10^9\n- 1 <= k <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(gifts = [25, 64, 9, 4, 100],k = 4) == 29\n assert candidate(gifts = [16, 81, 49],k = 3) == 20\n assert candidate(gifts = [1, 1, 1, 1],k = 4) == 4\n assert candidate(gifts = [49, 36, 25, 16, 9],k = 5) == 25\n assert candidate(gifts = [1000000000],k = 1000) == 1\n assert candidate(gifts = [16, 81, 4, 25, 9],k = 3) == 31\n assert candidate(gifts = [36, 27, 18, 12, 9],k = 5) == 21\n assert candidate(gifts = [1000000000],k = 10) == 1\n assert candidate(gifts = [36, 49, 64, 81],k = 2) == 102\n assert candidate(gifts = [16, 25, 36, 49, 64, 81, 100],k = 3) == 153\n assert candidate(gifts = [1000000000],k = 1) == 31622\n assert candidate(gifts = [16, 81, 25, 9],k = 3) == 27\n assert candidate(gifts = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 10) == 27\n assert candidate(gifts = [1000000000, 999999999, 888888888, 777777777, 666666666],k = 100) == 5\n assert candidate(gifts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 25) == 20\n assert candidate(gifts = [987654321, 876543219, 765432198, 654321987, 543219876],k = 7) == 76901\n assert candidate(gifts = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991, 99999990, 99999989, 99999988, 99999987, 99999986, 99999985, 99999984, 99999983, 99999982, 99999981],k = 1000) == 20\n assert candidate(gifts = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 30) == 11\n assert candidate(gifts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 60) == 15\n assert candidate(gifts = [987654321, 98765432, 9876543, 987654, 98765],k = 15) == 38\n assert candidate(gifts = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 100) == 10\n assert candidate(gifts = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 15) == 30\n assert candidate(gifts = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1024, 512, 256, 128, 64],k = 50) == 16\n assert candidate(gifts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 75) == 20\n assert candidate(gifts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1000) == 20\n assert candidate(gifts = [123456789, 987654321, 135792468, 246813579, 111213141],k = 20) == 15\n assert candidate(gifts = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119],k = 500) == 20\n assert candidate(gifts = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42],k = 1000) == 15\n assert candidate(gifts = [987654321, 987654321, 987654321, 987654321, 987654321],k = 100) == 5\n assert candidate(gifts = [1000000000, 100000000, 10000000, 1000000, 100000],k = 10) == 381\n assert candidate(gifts = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 24\n assert candidate(gifts = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],k = 100) == 10\n assert candidate(gifts = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 10) == 195\n assert candidate(gifts = [1000000, 100000, 10000, 1000, 100, 10, 1],k = 1000) == 7\n assert candidate(gifts = [81, 81, 81, 81, 81, 81, 81, 81, 81, 81],k = 20) == 30\n assert candidate(gifts = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42],k = 50) == 50\n assert candidate(gifts = [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],k = 25) == 125\n assert candidate(gifts = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 10) == 56\n assert candidate(gifts = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 1000) == 5\n assert candidate(gifts = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 100) == 10\n assert candidate(gifts = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000) == 10\n assert candidate(gifts = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144],k = 100) == 9\n assert candidate(gifts = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000],k = 100) == 10\n assert candidate(gifts = [16, 81, 4, 25, 9, 36, 64, 49, 100],k = 15) == 23\n assert candidate(gifts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50) == 10\n assert candidate(gifts = [123456, 654321, 111111, 222222, 333333],k = 50) == 5\n assert candidate(gifts = [987654321, 876543219, 765432108, 654321097, 543210986, 432109875, 321098764, 210987653, 109876542],k = 500) == 9\n assert candidate(gifts = [123456789, 987654321, 456789123, 321987654, 654321987],k = 15) == 58\n assert candidate(gifts = [1000000, 990000, 980000, 970000, 960000, 950000],k = 100) == 6\n assert candidate(gifts = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000],k = 500) == 10\n assert candidate(gifts = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225],k = 75) == 15\n assert candidate(gifts = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 500) == 10\n assert candidate(gifts = [16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324],k = 100) == 15\n assert candidate(gifts = [1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10],k = 10) == 1890\n assert candidate(gifts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 100) == 20\n assert candidate(gifts = [987654321, 876543219, 765432197, 654321975, 543219753, 432197531, 321975319, 219753197, 197531975, 975319753],k = 1000) == 10\n assert candidate(gifts = [100000, 100000, 100000, 100000, 100000],k = 250) == 5\n assert candidate(gifts = [100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1],k = 100) == 9\n assert candidate(gifts = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 20) == 84\n assert candidate(gifts = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],k = 30) == 77\n assert candidate(gifts = [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],k = 100) == 25\n assert candidate(gifts = [981, 961, 941, 921, 901, 881, 861, 841, 821, 801, 781, 761, 741, 721, 701],k = 15) == 428\n assert candidate(gifts = [16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529],k = 20) == 263\n assert candidate(gifts = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36],k = 50) == 34\n assert candidate(gifts = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625],k = 25) == 268\n assert candidate(gifts = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 20) == 10\n assert candidate(gifts = [314159265, 271828182, 161803398, 141421356, 111111111, 618033988, 333333333],k = 100) == 7\n assert candidate(gifts = [3, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61],k = 30) == 29\n assert candidate(gifts = [999999999, 1, 999999999, 1, 999999999, 1, 999999999, 1, 999999999, 1],k = 10) == 890\n assert candidate(gifts = [999999999],k = 1000) == 1\n assert candidate(gifts = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 100) == 9\n assert candidate(gifts = [1000000, 1000000, 1000000, 1000000, 1000000],k = 50) == 5\n assert candidate(gifts = [987654321, 98765432, 9876543, 987654, 98765, 9876, 987, 98, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 20) == 106\n assert candidate(gifts = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 20) == 37\n assert candidate(gifts = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 50) == 15\n assert candidate(gifts = [16, 144, 121, 100, 81, 64, 49, 36, 25, 16],k = 15) == 40\n assert candidate(gifts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 10\n assert candidate(gifts = [1000000000, 999999999, 888888888, 777777777, 666666666],k = 10) == 852\n assert candidate(gifts = [361, 441, 529, 625, 729, 841, 961],k = 20) == 16\n assert candidate(gifts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 20) == 51\n assert candidate(gifts = [441, 361, 289, 225, 169, 121, 81, 49, 25, 9, 1],k = 7) == 189\n assert candidate(gifts = [361, 441, 529, 625, 729, 841, 961, 1089, 1225, 1369, 1521, 1681, 1849, 2025, 2209],k = 15) == 495\n assert candidate(gifts = [65536, 4096, 256, 16, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 500) == 20\n assert candidate(gifts = [123456789, 987654321, 135792468, 246813579, 864204680],k = 50) == 5\n assert candidate(gifts = [1000000000, 999999999, 888888888, 777777777, 666666666],k = 1000) == 5\n assert candidate(gifts = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],k = 100) == 10\n assert candidate(gifts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 25) == 10\n assert candidate(gifts = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42],k = 200) == 20\n assert candidate(gifts = [121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484],k = 30) == 31\n assert candidate(gifts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 500) == 10\n assert candidate(gifts = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 10) == 644\n assert candidate(gifts = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543, 98765432],k = 50) == 10\n assert candidate(gifts = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025],k = 500) == 25\n assert candidate(gifts = [169, 441, 961, 1681, 2809, 4489, 6889, 10201, 14641],k = 75) == 9\n assert candidate(gifts = [64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024],k = 30) == 375\n assert candidate(gifts = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 5) == 5005000\n assert candidate(gifts = [46656, 1296, 324, 81, 25, 9, 4, 1],k = 15) == 18\n assert candidate(gifts = [1000000000, 999999999, 999999998, 999999997],k = 1000) == 4\n assert candidate(gifts = [3125, 5625, 144, 2025, 441, 900],k = 25) == 6\n assert candidate(gifts = [999999999, 1, 999999999, 1, 999999999, 1, 999999999, 1, 999999999, 1],k = 1000) == 10\n assert candidate(gifts = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287],k = 15) == 451\n assert candidate(gifts = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 100) == 5\n assert candidate(gifts = [1000, 500, 250, 125, 63, 32, 16, 8, 4, 2, 1],k = 500) == 11\n assert candidate(gifts = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 20) == 20\n assert candidate(gifts = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111],k = 300) == 9\n assert candidate(gifts = [169, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1],k = 13) == 72\n assert candidate(gifts = [123456789, 987654321, 111213141, 212223242, 313233343, 414243444, 515253545, 616263646, 717273747, 818283848],k = 1000) == 10\n", "comparison": "exact"}, "public_tests": ["[25,64,9,4,100]\n4", "[1,1,1,1]\n4"], "hints": ["How can you keep track of the largest gifts in the array", "What is an efficient way to find the square root of a number?", "Can you keep adding up the values of the gifts while ensuring they are in a certain order?", "Can we use a priority queue or heap here?"], "metadata": {"canonical_parameter_names": ["gifts", "k"], "leetcode_dataset_entry_point": "Solution().pickGifts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:07+00:00", "tests_total": 108, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "heap-priority-queue", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def pick_gifts(gifts, k)", "container": null, "callable": "pick_gifts", "parameters": [{"name": "gifts", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2559, "task_id": "count-vowel-strings-in-ranges", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of strings words and a 2D array of integers queries.\n\nEach query queries[i] = [l_i, r_i] asks us to find the number of strings present at the indices ranging from l_i to r_i (both inclusive) of words that start and end with a vowel.\n\nReturn an array ans of size queries.length, where ans[i] is the answer to the i^th query.\n\nNote that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.\n\nExample 1:\n\nInput: words = [\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"], queries = [[0,2],[1,4],[1,1]]\nOutput: [2,3,0]\nExplanation: The strings starting and ending with a vowel are \"aba\", \"ece\", \"aa\" and \"e\".\nThe answer to the query [0,2] is 2 (strings \"aba\" and \"ece\").\nto query [1,4] is 3 (strings \"ece\", \"aa\", \"e\").\nto query [1,1] is 0.\nWe return [2,3,0].\n\nExample 2:\n\nInput: words = [\"a\",\"e\",\"i\"], queries = [[0,2],[0,1],[2,2]]\nOutput: [3,2,1]\nExplanation: Every string satisfies the conditions, so we return [3,2,1].\n\nConstraints:\n\n- 1 <= words.length <= 10^5\n- 1 <= words[i].length <= 40\n- words[i] consists only of lowercase English letters.\n- sum(words[i].length) <= 3 * 10^5\n- 1 <= queries.length <= 10^5\n- 0 <= l_i <= r_i < words.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'ua'],queries = [[0, 0], [1, 2], [0, 3]]) == [1, 0, 2]\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'dea'],queries = [[0, 3], [1, 2], [2, 2]]) == [1, 0, 0]\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'aeiou'],queries = [[0, 3], [1, 2], [3, 3]]) == [2, 0, 1]\n assert candidate(words = ['aaaa', 'ee', 'iii', 'oo', 'uu'],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == [1, 1, 1, 1, 1]\n assert candidate(words = ['abc', 'bcd', 'cde', 'dea'],queries = [[0, 1], [1, 3], [2, 3]]) == [0, 0, 0]\n assert candidate(words = ['abc', 'bcd', 'cde', 'dea'],queries = [[0, 1], [1, 3], [0, 3]]) == [0, 0, 0]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u'],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == [1, 1, 1, 1, 1]\n assert candidate(words = ['aba', 'bcb', 'ece', 'aa', 'e'],queries = [[0, 2], [1, 4], [1, 1]]) == [2, 3, 0]\n assert candidate(words = ['abc', 'bcd', 'cde', 'dea'],queries = [[0, 1], [2, 3], [0, 3]]) == [0, 0, 0]\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'dea', 'eae'],queries = [[0, 4], [1, 3], [2, 2]]) == [2, 0, 0]\n assert candidate(words = ['abc', 'bcd', 'cde', 'dea', 'eae'],queries = [[0, 1], [1, 3], [2, 4]]) == [0, 0, 1]\n assert candidate(words = ['a', 'e', 'i'],queries = [[0, 2], [0, 1], [2, 2]]) == [3, 2, 1]\n assert candidate(words = ['abc', 'bcd', 'cde', 'dea'],queries = [[0, 3], [1, 2], [2, 2]]) == [0, 0, 0]\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == [1, 0, 0, 0, 1]\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],queries = [[0, 4], [1, 3], [2, 2]]) == [2, 0, 0]\n assert candidate(words = ['aeiou', 'bcd', 'eoe'],queries = [[0, 0], [1, 2], [0, 2]]) == [1, 1, 2]\n assert candidate(words = ['aeioua', 'beoibe', 'ieoiie', 'oioioi', 'uaouau', 'aeiou', 'eioue', 'iouoi', 'ououo', 'uouou'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == [9, 7, 6, 4, 2, 4, 5, 2, 3, 3, 3, 3, 3, 3]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aeiou', 'uoiea', 'aeiouaeiou'],queries = [[0, 7], [1, 6], [2, 5], [3, 4], [0, 0], [7, 7]]) == [8, 6, 4, 2, 1, 1]\n assert candidate(words = ['ae', 'ea', 'aa', 'ee', 'ii', 'oo', 'uu', 'aee', 'eaa', 'iee'],queries = [[0, 9], [0, 5], [5, 9], [3, 6], [7, 8]]) == [10, 6, 5, 4, 2]\n assert candidate(words = ['aeiou'],queries = [[0, 0]]) == [1]\n assert candidate(words = ['apple', 'orange', 'umbrella', 'elephant', 'ice'],queries = [[0, 2], [1, 4], [2, 2], [3, 4], [0, 4]]) == [3, 3, 1, 1, 4]\n assert candidate(words = ['automobile', 'bicycle', 'car', 'plane', 'ship', 'train', 'truck', 'motorcycle', 'bus', 'ferry'],queries = [[0, 4], [1, 5], [2, 8], [0, 9], [1, 6], [2, 4], [3, 7], [0, 7], [8, 9]]) == [1, 0, 0, 1, 0, 0, 0, 1, 0]\n assert candidate(words = ['education', 'environment', 'algorithm', 'finance', 'economics', 'optimization', 'development'],queries = [[0, 2], [3, 5], [0, 6], [2, 4], [1, 3], [0, 5], [4, 6]]) == [0, 0, 0, 0, 0, 0, 0]\n assert candidate(words = ['umbrella', 'elephant', 'ice', 'onion', 'apple', 'orange'],queries = [[0, 2], [1, 5], [3, 4], [0, 1], [2, 3]]) == [2, 3, 1, 1, 1]\n assert candidate(words = ['banana', 'grape', 'kiwi', 'lemon', 'melon', 'mango', 'peach', 'pear', 'plum'],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [5, 5], [6, 6], [7, 7], [0, 1], [2, 3], [4, 5], [6, 7]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(words = ['aabbcc', 'eoo', 'i', 'oee', 'u', 'aa', 'e', 'i', 'o', 'u'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [9, 8, 6, 4, 2, 4, 5]\n assert candidate(words = ['ab', 'cd', 'ef', 'gh', 'ij', 'kl', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz'],queries = [[0, 12], [1, 11], [2, 10], [3, 9], [4, 8]]) == [0, 0, 0, 0, 0]\n assert candidate(words = ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd', 'eeeeee', 'ffffff', 'gggggg'],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 6]]) == [1, 0, 0, 1, 1, 0, 2]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u'],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 4], [0, 3], [1, 4]]) == [1, 1, 1, 1, 1, 5, 4, 4]\n assert candidate(words = ['aeiou', 'bcd', 'efg', 'hij', 'klm', 'nop', 'qrstu', 'vwxyz', 'yzzzy', 'uaeuu'],queries = [[0, 9], [1, 3], [2, 8], [4, 7], [5, 5]]) == [2, 0, 0, 0, 0]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aa', 'ee', 'ii', 'oo', 'uu', 'aaa', 'eee', 'iii', 'ooo', 'uuu'],queries = [[0, 4], [5, 9], [10, 14], [0, 9], [5, 14], [0, 14], [1, 13]]) == [5, 5, 5, 10, 10, 15, 13]\n assert candidate(words = ['banana', 'apple', 'grape', 'kiwi', 'melon', 'peach', 'pear'],queries = [[0, 3], [2, 5], [1, 6], [0, 6], [4, 4]]) == [1, 0, 1, 1, 0]\n assert candidate(words = ['aeiouaeiou', 'bcdefghijklmno', 'pqrstuvwxyzz', 'zyxwvutsrqponmlkjihgfedcba', 'aeiouaeiouaeiou'],queries = [[0, 4], [1, 3], [0, 0], [2, 2], [1, 4]]) == [2, 0, 1, 0, 1]\n assert candidate(words = ['education', 'university', 'college', 'school', 'academy', 'institute', 'faculty', 'student', 'teacher', 'research'],queries = [[0, 9], [1, 4], [2, 6], [3, 8], [4, 7]]) == [1, 0, 1, 1, 1]\n assert candidate(words = ['umbrella', 'elephant', 'ice', 'onion', 'apple', 'orange', 'grape'],queries = [[0, 6], [1, 5], [2, 4], [0, 1], [5, 6], [2, 3], [4, 4]]) == [4, 3, 2, 1, 1, 1, 1]\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [3, 2, 1, 1, 1]\n assert candidate(words = ['aaaa', 'eeeee', 'iiii', 'oooo', 'uuuu', 'aeiou', 'uoiea'],queries = [[0, 4], [3, 6], [0, 3], [4, 4], [5, 6], [1, 1], [2, 2]]) == [5, 4, 4, 1, 2, 1, 1]\n assert candidate(words = ['abc', 'bcd', 'cde', 'dea', 'aeiou', 'uoiea'],queries = [[0, 5], [1, 4], [2, 3], [0, 0], [5, 5]]) == [2, 1, 0, 0, 1]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aeiou', 'uoiea'],queries = [[0, 6], [1, 5], [2, 4], [0, 3], [3, 6]]) == [7, 5, 3, 4, 4]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'ae', 'ei', 'ou', 'io', 'ua'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 0], [9, 9]]) == [10, 8, 6, 4, 2, 1, 1]\n assert candidate(words = ['apple', 'orange', 'banana', 'grape', 'peach'],queries = [[0, 2], [1, 3], [0, 3], [2, 2], [3, 3], [1, 4], [0, 4]]) == [2, 1, 2, 0, 0, 1, 2]\n assert candidate(words = ['bcd'],queries = [[0, 0]]) == [0]\n assert candidate(words = ['banana', 'apricot', 'grape', 'kiwi', 'peach', 'melon'],queries = [[0, 5], [1, 3], [2, 4], [0, 2], [3, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(words = ['banana', 'anana', 'nana', 'ana', 'na', 'a', 'e', 'i', 'o', 'u'],queries = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9], [0, 9]]) == [3, 4, 4, 5, 5, 7]\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'],queries = [[0, 14], [0, 9], [5, 10], [10, 14]]) == [4, 3, 1, 1]\n assert candidate(words = ['abcde', 'edcba', 'fghij', 'jihgf', 'klmno', 'onmlk', 'pqrst', 'tsrqp', 'uvwxy', 'yxwvu'],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [0, 8], [1, 9], [0, 7], [2, 5]]) == [2, 0, 0, 0, 2, 1, 2, 0]\n assert candidate(words = ['banana', 'grape', 'avocado', 'kiwi', 'melon', 'orange', 'elderberry'],queries = [[0, 6], [1, 5], [2, 4], [3, 3], [0, 3]]) == [2, 2, 1, 0, 1]\n assert candidate(words = ['x', 'y', 'z', 'aeiou', 'aeiou', 'aeiou'],queries = [[0, 2], [2, 4], [4, 5], [0, 5]]) == [0, 2, 2, 3]\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [3, 2, 1, 1, 1]\n assert candidate(words = ['aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea'],queries = [[0, 15], [1, 14], [2, 13], [3, 12], [4, 11], [5, 10], [6, 9], [7, 8]]) == [4, 3, 3, 3, 2, 1, 1, 1]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'ae', 'ei', 'ou', 'ia', 'uo'],queries = [[0, 5], [2, 8], [1, 4], [0, 9], [3, 7], [5, 9], [0, 0], [9, 9]]) == [6, 7, 4, 10, 5, 5, 1, 1]\n assert candidate(words = ['abacax', 'azedo', 'oiue', 'ueia', 'uiaeu', 'uiaed', 'uieaeu', 'ueae', 'euae', 'aeu'],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [0, 1, 1, 1, 1, 0, 1, 1, 1, 1]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'ae', 'ei', 'ou', 'uo', 'ea'],queries = [[0, 9], [0, 5], [5, 9], [3, 6], [7, 8]]) == [10, 6, 5, 4, 2]\n assert candidate(words = ['aeiou', 'bcd', 'aee', 'oau', 'bcd', 'eaa'],queries = [[0, 2], [1, 5], [3, 5], [0, 5]]) == [2, 3, 2, 4]\n assert candidate(words = ['apple', 'orange', 'umbrella', 'elephant', 'ice', 'onion'],queries = [[0, 5], [1, 4], [2, 3], [0, 0], [5, 5]]) == [4, 3, 1, 1, 0]\n assert candidate(words = ['aeiou', 'bcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvw', 'xyz'],queries = [[0, 7], [1, 6], [2, 5], [3, 4], [0, 0], [7, 7]]) == [1, 0, 0, 0, 1, 0]\n assert candidate(words = ['aaa', 'eee', 'iii', 'ooo', 'uuu', 'aa', 'ee', 'ii', 'oo', 'uu'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [10, 8, 6, 4, 2, 5, 5]\n assert candidate(words = ['banana', 'avocado', 'elderberry', 'kiwi', 'grape', 'lemon'],queries = [[0, 2], [1, 5], [2, 3], [0, 5]]) == [1, 1, 0, 1]\n assert candidate(words = ['aeiou', 'bcd', 'ocean', 'elephant', 'umbrella'],queries = [[0, 0], [0, 4], [1, 2], [2, 3], [3, 4], [0, 3], [1, 4]]) == [1, 2, 0, 0, 1, 1, 1]\n assert candidate(words = ['under', 'over', 'around', 'before', 'after', 'above', 'below'],queries = [[0, 1], [2, 4], [1, 3], [0, 6], [5, 5]]) == [0, 0, 0, 1, 1]\n assert candidate(words = ['aeiou', 'bcd', 'eae', 'oio', 'uaa'],queries = [[0, 2], [1, 4], [0, 4]]) == [2, 3, 4]\n assert candidate(words = ['aabbcc', 'bbaacc', 'ccaabb', 'ccbbdd', 'ddeerr', 'eeffgg', 'ffggee', 'gghhee', 'hhiig', 'iihhj'],queries = [[0, 2], [1, 5], [2, 7], [0, 8], [1, 6], [2, 4], [3, 7], [0, 7], [8, 9]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(words = ['abacax', 'azedo', 'oiue', 'ueia', 'uiaeu', 'uiaed', 'uieaeu', 'ueae', 'euae', 'aeu'],queries = [[0, 4], [1, 7], [2, 8], [3, 9], [0, 9]]) == [4, 6, 6, 6, 8]\n assert candidate(words = ['aeiou', 'bcdfg', 'ae', 'iou', 'a', 'e', 'i', 'o', 'u'],queries = [[0, 8], [1, 5], [2, 7], [3, 6], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == [8, 4, 6, 4, 1, 1, 1, 1, 1]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aeiou'],queries = [[0, 5], [1, 4], [2, 3], [0, 0], [5, 5], [1, 1], [2, 2], [3, 3], [4, 4]]) == [6, 4, 2, 1, 1, 1, 1, 1, 1]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aeiou'],queries = [[0, 5], [1, 4], [0, 0], [5, 5]]) == [6, 4, 1, 1]\n assert candidate(words = ['apple', 'orange', 'umbrella', 'echo', 'alpha'],queries = [[0, 4], [1, 3], [0, 0], [2, 2], [1, 4]]) == [5, 3, 1, 1, 4]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7], [0, 9], [1, 8]]) == [15, 13, 11, 9, 7, 5, 3, 1, 10, 8]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aeiou', 'uoiea', 'bcd'],queries = [[0, 6], [1, 5], [2, 7], [3, 3]]) == [7, 5, 5, 1]\n assert candidate(words = ['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yz'],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 6], [1, 5], [2, 4]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(words = ['amplifier', 'equalizer', 'microphone', 'audio', 'sound', 'voice', 'volume', 'level', 'peak', 'gain'],queries = [[0, 2], [1, 5], [2, 7], [3, 8], [4, 9], [0, 9]]) == [0, 1, 1, 1, 0, 1]\n assert candidate(words = ['algorithm', 'datastructure', 'programming', 'python', 'java', 'csharp', 'javascript', 'html', 'css', 'vue'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(words = ['a', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea', 'aeiou', 'bcd', 'cde', 'dea'],queries = [[0, 15], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15]]) == [4, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]\n assert candidate(words = ['strawberry', 'blueberry', 'raspberry', 'blackberry', 'kiwi', 'mango', 'papaya'],queries = [[0, 6], [1, 5], [2, 4], [0, 1], [5, 6]]) == [0, 0, 0, 0, 0]\n assert candidate(words = ['aabb', 'bbaa', 'abcd', 'dcba', 'efgh', 'hgfe', 'ijkl', 'lkji', 'mnop', 'ponm'],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 9]]) == [0, 0, 0, 0, 0, 0]\n assert candidate(words = ['algorithm', 'engine', 'idea', 'open', 'ocean', 'under', 'education'],queries = [[0, 2], [1, 5], [2, 6], [0, 6]]) == [2, 2, 1, 2]\n assert candidate(words = ['abacaxi', 'ananas', 'acerola', 'banana', 'manga', 'abacaxi', 'manga', 'banana'],queries = [[0, 3], [4, 7], [0, 4], [3, 6], [1, 5], [2, 2], [6, 7]]) == [2, 1, 2, 1, 2, 1, 0]\n assert candidate(words = ['umbrella', 'orange', 'apple', 'elephant', 'ocean', 'idea', 'education'],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 6]]) == [2, 2, 1, 0, 1, 1, 4]\n assert candidate(words = ['ae', 'ei', 'ou', 'ia', 'oe', 'uo', 'oi', 'ie', 'oa', 'eu'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9], [0, 3], [1, 7], [2, 6]]) == [10, 8, 6, 4, 2, 5, 5, 4, 7, 5]\n assert candidate(words = ['apple', 'orange', 'umbrella', 'electric', 'ice', 'onion', 'octopus'],queries = [[0, 6], [1, 3], [2, 5], [0, 0], [6, 6], [3, 4], [1, 5]]) == [4, 2, 2, 1, 0, 1, 3]\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'vowel', 'nonvowel'],queries = [[0, 6], [1, 5], [2, 4], [3, 3], [4, 4]]) == [5, 4, 3, 1, 1]\n assert candidate(words = ['aeioua', 'aeioue', 'aeiouo', 'aeioui', 'aeiouu', 'euoeu', 'iuoie', 'oueia', 'uaeio', 'eaoui'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9], [0, 3], [1, 7], [2, 6]]) == [10, 8, 6, 4, 2, 5, 5, 4, 7, 5]\n assert candidate(words = ['aabbcc', 'ddeeff', 'gg', 'hhii', 'jjkk', 'llmm', 'nnoopp', 'qqrr', 'ssttuu', 'vvww'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(words = ['aeiou', 'bcd', 'eae', 'oio', 'uaa', 'aeiou', 'bcd', 'eae', 'oio', 'uaa'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 5], [0, 4], [1, 9]]) == [8, 6, 5, 3, 2, 5, 4, 7]\n assert candidate(words = ['apple', 'orange', 'ice', 'elephant', 'umbrella'],queries = [[0, 1], [1, 3], [2, 4], [0, 4]]) == [2, 2, 2, 4]\n assert candidate(words = ['aeiou', 'bcd', 'eee', 'oee', 'uau'],queries = [[0, 4], [1, 3], [2, 4], [0, 0], [4, 4]]) == [4, 2, 3, 1, 1]\n assert candidate(words = ['umbrella', 'raincoat', 'umbrella', 'hat', 'scarf', 'umbrella', 'umbrella', 'raincoat'],queries = [[0, 3], [4, 7], [0, 4], [3, 6], [1, 5], [0, 6], [2, 2], [5, 7]]) == [2, 2, 2, 2, 2, 4, 1, 2]\n assert candidate(words = ['abacax', 'azedo', 'oiue', 'ueia', 'uiaeu', 'uiaed', 'uieaeu', 'ueae', 'euae', 'aeu'],queries = [[0, 4], [1, 3], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == [4, 3, 3, 3, 3, 3, 4]\n assert candidate(words = ['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvw', 'xyz'],queries = [[0, 6], [1, 5], [2, 4], [0, 2], [3, 5], [0, 6], [6, 6]]) == [0, 0, 0, 0, 0, 0, 0]\n assert candidate(words = ['aeiouaeiou', 'bcd', 'eee', 'oau', 'bcd', 'eaa', 'aeiou', 'bcd', 'cde', 'dea'],queries = [[0, 4], [1, 7], [3, 8], [0, 9], [5, 5]]) == [3, 4, 3, 5, 1]\n assert candidate(words = ['aabbcc', 'eeffgg', 'hhhiii', 'jjjkll', 'mmmoonnn', 'pppqqq', 'rrrsss', 'tttuuu', 'vvvwww', 'xxxyyy'],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(words = ['apple', 'orange', 'banana', 'umbrella', 'ice', 'elephant', 'octopus'],queries = [[0, 2], [3, 6], [0, 6], [2, 4]]) == [2, 2, 4, 2]\n assert candidate(words = ['banana', 'apple', 'orange', 'grape', 'kiwi'],queries = [[0, 4], [1, 2], [2, 3], [3, 4], [0, 3]]) == [2, 2, 1, 0, 2]\n assert candidate(words = ['aeiou', 'banana', 'grape', 'kiwi', 'a', 'e', 'i', 'o', 'u'],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4]]) == [6, 4, 3, 2, 1]\n", "comparison": "exact"}, "public_tests": ["[\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"]\n[[0,2],[1,4],[1,1]]", "[\"a\",\"e\",\"i\"]\n[[0,2],[0,1],[2,2]]"], "hints": ["Precompute the prefix sum of strings that start and end with vowels.", "Use unordered_set to store vowels.", "Check if the first and last characters of the string are present in the vowels set.", "Subtract prefix sum for range [l-1, r] to find the number of strings starting and ending with vowels."], "metadata": {"canonical_parameter_names": ["words", "queries"], "leetcode_dataset_entry_point": "Solution().vowelStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:10+00:00", "tests_total": 97, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "string", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def vowel_strings(words, queries)", "container": null, "callable": "vowel_strings", "parameters": [{"name": "words", "type": "String[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2560, "task_id": "house-robber-iv", "difficulty": "Medium", "problem_description": "There are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the homes, but he refuses to steal from adjacent homes.\n\nThe capability of the robber is the maximum amount of money he steals from one house of all the houses he robbed.\n\nYou are given an integer array nums representing how much money is stashed in each house. More formally, the i^th house from the left has nums[i] dollars.\n\nYou are also given an integer k, representing the minimum number of houses the robber will steal from. It is always possible to steal at least k houses.\n\nReturn the minimum capability of the robber out of all the possible ways to steal at least k houses.\n\nExample 1:\n\nInput: nums = [2,3,5,9], k = 2\nOutput: 5\nExplanation:\nThere are three ways to rob at least 2 houses:\n- Rob the houses at indices 0 and 2. Capability is max(nums[0], nums[2]) = 5.\n- Rob the houses at indices 0 and 3. Capability is max(nums[0], nums[3]) = 9.\n- Rob the houses at indices 1 and 3. Capability is max(nums[1], nums[3]) = 9.\nTherefore, we return min(5, 9, 9) = 5.\n\nExample 2:\n\nInput: nums = [2,7,9,3,1], k = 2\nOutput: 2\nExplanation: There are 7 ways to rob the houses. The way which leads to minimum capability is to rob the house at index 0 and 4. Return max(nums[0], nums[4]) = 2.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= (nums.length + 1)/2\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 9\n assert candidate(nums = [10, 1, 1, 10, 1, 1, 10],k = 3) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1) == 10\n assert candidate(nums = [5, 3, 1, 1, 2, 3],k = 2) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 5\n assert candidate(nums = [2, 7, 9, 3, 1],k = 2) == 2\n assert candidate(nums = [2, 3, 5, 9],k = 2) == 5\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 4) == 2\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],k = 15) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 9\n assert candidate(nums = [10, 5, 15, 20, 25, 30, 35, 40],k = 4) == 35\n assert candidate(nums = [2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1],k = 5) == 1\n assert candidate(nums = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],k = 3) == 250\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) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 9\n assert candidate(nums = [3, 6, 1, 8, 5, 2, 9, 4, 7, 10],k = 4) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 10) == 37\n assert candidate(nums = [3, 5, 7, 2, 9, 1, 10, 8, 6, 4],k = 3) == 3\n assert candidate(nums = [10, 2, 8, 4, 7, 3, 9, 5, 6, 1],k = 4) == 4\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],k = 3) == 1\n assert candidate(nums = [10, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31],k = 6) == 29\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 = 10) == 1\n assert candidate(nums = [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],k = 10) == 67\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 = 6) == 11\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],k = 5) == 1\n assert candidate(nums = [100, 10, 1, 100, 10, 1, 100, 10, 1, 100],k = 4) == 100\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 8) == 29\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 5) == 1\n assert candidate(nums = [10, 1, 1, 10, 1, 1, 10, 1, 1, 10],k = 5) == 10\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],k = 2) == 1000000000\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 3) == 50\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 4) == 35\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 10) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 10) == 38\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 5\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 13\n assert candidate(nums = [3, 5, 10, 2, 8, 14, 1, 11, 7, 6],k = 5) == 10\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 5) == 50\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 900\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],k = 15) == 3\n assert candidate(nums = [3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10],k = 4) == 3\n assert candidate(nums = [8, 3, 9, 2, 7, 4, 6, 1, 5, 10],k = 4) == 4\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],k = 7) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 90\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 6) == 22\n assert candidate(nums = [1, 3, 1, 1, 2, 1, 5, 1, 4, 1],k = 4) == 1\n assert candidate(nums = [2, 3, 7, 8, 4, 5, 6, 9],k = 3) == 6\n assert candidate(nums = [10, 2, 9, 4, 7, 3, 8, 5, 6, 1],k = 3) == 3\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3],k = 8) == 3\n assert candidate(nums = [9, 2, 5, 7, 1, 3, 8, 6, 4, 10],k = 5) == 9\n assert candidate(nums = [23, 45, 12, 34, 56, 78, 89, 67, 45, 23, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],k = 6) == 20\n assert candidate(nums = [7, 10, 4, 3, 20, 15],k = 3) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 17\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],k = 10) == 98\n assert candidate(nums = [2, 1, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2],k = 5) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3) == 500\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 = 10) == 1\n assert candidate(nums = [3, 6, 2, 8, 7, 2, 5, 9, 4, 10],k = 4) == 4\n assert candidate(nums = [3, 6, 7, 12, 14, 11, 14, 13, 15, 10, 11, 13],k = 4) == 11\n assert candidate(nums = [1000000000, 500000000, 1000000000, 500000000, 1000000000, 500000000, 1000000000],k = 3) == 500000000\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1],k = 5) == 1\n assert candidate(nums = [100, 200, 300, 10, 20, 30, 400, 500, 600, 1000],k = 5) == 600\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 7) == 26\n assert candidate(nums = [1, 3, 2, 5, 7, 6, 4, 8, 9, 10],k = 5) == 9\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 = 5) == 1\n assert candidate(nums = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3],k = 4) == 3\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 5) == 1\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5],k = 3) == 3\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 6) == 5\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) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 50\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],k = 5) == 1\n assert candidate(nums = [1, 3, 1, 5, 1, 7, 1, 9],k = 4) == 1\n assert candidate(nums = [5, 9, 7, 1, 3, 8, 6, 4, 2, 10, 1, 11, 13, 12, 14, 15, 16, 17, 18, 19],k = 6) == 7\n assert candidate(nums = [9, 1, 5, 3, 7, 11, 15, 13, 17, 19],k = 4) == 13\n assert candidate(nums = [15, 20, 10, 5, 1, 25, 30, 40, 50, 60],k = 5) == 50\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],k = 4) == 1\n assert candidate(nums = [15, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 80\n assert candidate(nums = [1, 2, 100, 3, 4, 100, 5, 6, 100, 7, 8, 100, 9, 10, 100],k = 5) == 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],k = 6) == 11\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 = 10) == 19\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 5) == 5\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 7) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 7) == 5\n assert candidate(nums = [1, 3, 2, 5, 7, 8, 6, 9, 4, 10],k = 3) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 17\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 5\n assert candidate(nums = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5],k = 10) == 1\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60],k = 3) == 10\n assert candidate(nums = [50, 1, 51, 2, 52, 3, 53, 4, 54, 5, 55, 6, 56, 7, 57, 8, 58, 9, 59, 10],k = 5) == 5\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 5) == 5\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 4) == 70\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 = 7) == 5\n assert candidate(nums = [8, 2, 4, 1, 6, 5, 3, 7, 10, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 6) == 11\n", "comparison": "exact"}, "public_tests": ["[2,3,5,9]\n2", "[2,7,9,3,1]\n2"], "hints": ["Can we use binary search to find the minimum value of a non-contiguous subsequence of a given size k?", "Initialize the search range with the minimum and maximum elements of the input array.", "Use a check function to determine if it is possible to select k non-consecutive elements that are less than or equal to the current \"guess\" value.", "Adjust the search range based on the outcome of the check function, until the range converges and the minimum value is found."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minCapability", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:12+00:00", "tests_total": 105, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def min_capability(nums, k)", "container": null, "callable": "min_capability", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2561, "task_id": "rearranging-fruits", "difficulty": "Hard", "problem_description": "You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can use the following operation as many times as you want:\n\n- Choose two indices i and j, and swap the i^th fruit of basket1 with the j^th fruit of basket2.\n- The cost of the swap is min(basket1[i], basket2[j]).\n\nTwo baskets are considered equal if sorting them according to the fruit cost makes them exactly the same baskets.\n\nReturn the minimum cost to make both the baskets equal or -1 if impossible.\n\nExample 1:\n\nInput: basket1 = [4,2,2,2], basket2 = [1,4,1,2]\nOutput: 1\nExplanation: Swap index 1 of basket1 with index 0 of basket2, which has cost 1. Now basket1 = [4,1,2,2] and basket2 = [2,4,1,2]. Rearranging both the arrays makes them equal.\n\nExample 2:\n\nInput: basket1 = [2,3,4,1], basket2 = [3,2,5,1]\nOutput: -1\nExplanation: It can be shown that it is impossible to make both the baskets equal.\n\nConstraints:\n\n- basket1.length == basket2.length\n- 1 <= basket1.length <= 10^5\n- 1 <= basket1[i], basket2[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(basket1 = [1000000000, 1000000000],basket2 = [1000000000, 1000000000]) == 0\n assert candidate(basket1 = [2, 3, 4, 1],basket2 = [3, 2, 5, 1]) == -1\n assert candidate(basket1 = [1, 1, 2, 2],basket2 = [2, 2, 1, 1]) == 0\n assert candidate(basket1 = [5, 7, 10, 15],basket2 = [15, 10, 7, 5]) == 0\n assert candidate(basket1 = [1, 2, 3],basket2 = [3, 2, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5],basket2 = [5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9],basket2 = [2, 4, 6, 8, 10]) == -1\n assert candidate(basket1 = [4, 2, 2, 2],basket2 = [1, 4, 1, 2]) == 1\n assert candidate(basket1 = [10, 10, 10, 10],basket2 = [10, 10, 10, 10]) == 0\n assert candidate(basket1 = [100, 200, 300, 400],basket2 = [400, 500, 600, 700]) == -1\n assert candidate(basket1 = [5, 7, 9, 11],basket2 = [11, 9, 7, 5]) == 0\n assert candidate(basket1 = [1, 3, 5, 7],basket2 = [2, 4, 6, 8]) == -1\n assert candidate(basket1 = [1, 2, 3, 4],basket2 = [4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 1, 2, 3],basket2 = [1, 1, 3, 2]) == 0\n assert candidate(basket1 = [10, 10, 10, 10],basket2 = [1, 1, 1, 1]) == 2\n assert candidate(basket1 = [5, 5, 5, 5],basket2 = [5, 5, 5, 5]) == 0\n assert candidate(basket1 = [10, 20, 30, 40],basket2 = [40, 30, 20, 10]) == 0\n assert candidate(basket1 = [1, 1, 1, 1],basket2 = [1, 1, 1, 1]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9, 11, 13, 15],basket2 = [15, 13, 11, 9, 7, 5, 3, 1]) == 0\n assert candidate(basket1 = [100, 200, 300, 400, 500],basket2 = [500, 400, 300, 200, 100]) == 0\n assert candidate(basket1 = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5],basket2 = [5, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1]) == 0\n assert candidate(basket1 = [3, 5, 7, 9, 11],basket2 = [9, 11, 5, 7, 3]) == 0\n assert candidate(basket1 = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4],basket2 = [1, 1, 2, 2, 2, 2, 3, 3, 4, 4]) == -1\n assert candidate(basket1 = [1, 2, 2, 3, 3, 4, 5, 5, 5, 6],basket2 = [6, 5, 5, 4, 3, 3, 2, 2, 1, 1]) == -1\n assert candidate(basket1 = [1000000000, 999999999, 1, 2],basket2 = [1000000000, 999999999, 3, 4]) == -1\n assert candidate(basket1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],basket2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(basket1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],basket2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],basket2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9, 11],basket2 = [2, 4, 6, 8, 10, 12]) == -1\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],basket2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],basket2 = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1]) == 0\n assert candidate(basket1 = [1, 1, 2, 3, 4, 5, 6, 7, 8],basket2 = [8, 7, 6, 5, 4, 3, 2, 1, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],basket2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],basket2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == -1\n assert candidate(basket1 = [3, 5, 6, 7, 8, 9],basket2 = [9, 8, 7, 6, 5, 3]) == 0\n assert candidate(basket1 = [1000000000, 1000000000, 1, 1],basket2 = [1, 1, 1000000000, 1000000000]) == 0\n assert candidate(basket1 = [3, 3, 3, 3, 3, 3],basket2 = [1, 1, 1, 1, 1, 1]) == 3\n assert candidate(basket1 = [1, 2, 3, 4, 5],basket2 = [6, 7, 8, 9, 10]) == -1\n assert candidate(basket1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],basket2 = [6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9],basket2 = [9, 7, 5, 3, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],basket2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(basket1 = [1, 2, 2, 3, 4, 5],basket2 = [5, 4, 3, 2, 2, 6]) == -1\n assert candidate(basket1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 5],basket2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(basket1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],basket2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 5\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],basket2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1]) == 0\n assert candidate(basket1 = [1, 1, 1, 2, 2, 3],basket2 = [1, 1, 1, 2, 2, 3]) == 0\n assert candidate(basket1 = [5, 5, 5, 5, 5],basket2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(basket1 = [2, 2, 2, 2, 3, 3, 3, 3],basket2 = [1, 1, 1, 1, 4, 4, 4, 4]) == 6\n assert candidate(basket1 = [9, 7, 5, 3, 1],basket2 = [1, 3, 5, 7, 9]) == 0\n assert candidate(basket1 = [1, 2, 2, 3, 4, 5],basket2 = [5, 4, 3, 2, 2, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(basket1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],basket2 = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == -1\n assert candidate(basket1 = [1, 1, 2, 3, 4, 5],basket2 = [2, 3, 4, 5, 5, 5]) == 1\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],basket2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(basket1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],basket2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(basket1 = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],basket2 = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(basket1 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],basket2 = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 0\n assert candidate(basket1 = [5, 7, 9, 11, 13, 15],basket2 = [15, 13, 11, 9, 7, 5]) == 0\n assert candidate(basket1 = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4],basket2 = [4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],basket2 = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 0\n assert candidate(basket1 = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3],basket2 = [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],basket2 = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],basket2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],basket2 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9, 11, 13, 15],basket2 = [2, 4, 6, 8, 10, 12, 14, 16]) == -1\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6],basket2 = [6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [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],basket2 = [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(basket1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],basket2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],basket2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 0\n assert candidate(basket1 = [5, 10, 15, 20, 25, 30, 35, 40],basket2 = [40, 35, 30, 25, 20, 15, 10, 5]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],basket2 = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],basket2 = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],basket2 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6]) == -1\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],basket2 = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [3, 6, 8, 8, 10],basket2 = [10, 8, 6, 3, 8]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],basket2 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],basket2 = [5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 0\n assert candidate(basket1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],basket2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(basket1 = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3],basket2 = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9, 11, 13],basket2 = [13, 11, 9, 7, 5, 3, 1]) == 0\n assert candidate(basket1 = [1000000000, 1000000000, 1000000000, 1000000000],basket2 = [1, 1, 1, 1]) == 2\n assert candidate(basket1 = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],basket2 = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 11]) == -1\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [1, 1, 1, 1, 1, 10, 10, 10, 10, 10]) == -1\n assert candidate(basket1 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],basket2 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8],basket2 = [8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [10, 20, 30, 40, 50, 60],basket2 = [60, 50, 40, 30, 20, 10]) == 0\n assert candidate(basket1 = [1, 2, 2, 3, 4, 5, 5, 6],basket2 = [6, 5, 5, 4, 3, 2, 2, 1]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(basket1 = [1, 3, 5, 7, 9, 11, 13, 15],basket2 = [15, 13, 11, 9, 7, 5, 3, 1]) == 0\n assert candidate(basket1 = [5, 10, 15, 20, 25],basket2 = [25, 20, 15, 10, 5]) == 0\n assert candidate(basket1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],basket2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(basket1 = [10, 20, 30, 40, 50],basket2 = [50, 40, 30, 20, 10]) == 0\n assert candidate(basket1 = [1000000000, 1000000000, 1000000000],basket2 = [1, 1, 1]) == -1\n assert candidate(basket1 = [2, 2, 3, 3, 4, 4],basket2 = [4, 4, 3, 3, 2, 2]) == 0\n assert candidate(basket1 = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2],basket2 = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(basket1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],basket2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == -1\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(basket1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],basket2 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 0\n assert candidate(basket1 = [7, 7, 7, 8, 9],basket2 = [9, 8, 7, 7, 7]) == 0\n assert candidate(basket1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],basket2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 0\n assert candidate(basket1 = [1, 1, 1, 2, 2, 3],basket2 = [1, 1, 1, 2, 3, 3]) == -1\n assert candidate(basket1 = [1, 3, 5, 7, 9],basket2 = [2, 4, 6, 8, 10]) == -1\n assert candidate(basket1 = [1, 1, 2, 3, 4, 5, 6, 7],basket2 = [7, 6, 5, 4, 3, 2, 1, 1]) == 0\n assert candidate(basket1 = [10, 20, 30, 40, 50],basket2 = [5, 15, 25, 35, 45]) == -1\n assert candidate(basket1 = [1, 2, 2, 3, 4],basket2 = [1, 2, 2, 3, 4]) == 0\n", "comparison": "exact"}, "public_tests": ["[4,2,2,2]\n[1,4,1,2]", "[2,3,4,1]\n[3,2,5,1]"], "hints": ["Create two frequency maps for both arrays, and find the minimum element among all elements of both arrays.", "Check if the sum of frequencies of an element in both arrays is odd, if so return -1", "Store the elements that need to be swapped in a vector, and sort it.", "Can we reduce swapping cost with the help of minimum element?", "Calculate the minimum cost of swapping."], "metadata": {"canonical_parameter_names": ["basket1", "basket2"], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:14+00:00", "tests_total": 109, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "sort"]}, "language": "ruby", "interface": {"raw_signature": "def min_cost(basket1, basket2)", "container": null, "callable": "min_cost", "parameters": [{"name": "basket1", "type": "Integer[]"}, {"name": "basket2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2562, "task_id": "find-the-array-concatenation-value", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums.\n\nThe concatenation of two numbers is the number formed by concatenating their numerals.\n\n- For example, the concatenation of 15, 49 is 1549.\n\nThe concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:\n\n- If nums has a size greater than one, add the value of the concatenation of the first and the last element to the concatenation value of nums, and remove those two elements from nums. For example, if the nums was [1, 2, 4, 5, 6], add 16 to the concatenation value.\n- If only one element exists in nums, add its value to the concatenation value of nums, then remove it.\n\nReturn the concatenation value of nums.\n\nExample 1:\n\nInput: nums = [7,52,2,4]\nOutput: 596\nExplanation: Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.\n - In the first operation:\nWe pick the first element, 7, and the last element, 4.\nTheir concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.\nThen we delete them from nums, so nums becomes equal to [52,2].\n - In the second operation:\nWe pick the first element, 52, and the last element, 2.\nTheir concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.\nThen we delete them from the nums, so nums becomes empty.\nSince the concatenation value is 596 so the answer is 596.\n\nExample 2:\n\nInput: nums = [5,14,13,8,12]\nOutput: 673\nExplanation: Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.\n - In the first operation:\nWe pick the first element, 5, and the last element, 12.\nTheir concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.\nThen we delete them from the nums, so nums becomes equal to [14,13,8].\n - In the second operation:\nWe pick the first element, 14, and the last element, 8.\nTheir concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.\nThen we delete them from the nums, so nums becomes equal to [13].\n - In the third operation:\nnums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.\nThen we delete it from nums, so nums become empty.\nSince the concatenation value is 673 so the answer is 673.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 14, 13, 8, 12]) == 673\n assert candidate(nums = [1, 1, 1, 1]) == 22\n assert candidate(nums = [111, 222, 333, 444, 555]) == 334332\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 315\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 280\n assert candidate(nums = [9]) == 9\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [56, 78, 90, 12, 34]) == 13536\n assert candidate(nums = [7, 52, 2, 4]) == 596\n assert candidate(nums = [9999]) == 9999\n assert candidate(nums = [1234, 5678, 9101]) == 12354779\n assert candidate(nums = [1, 2, 3, 4, 5]) == 42\n assert candidate(nums = [123, 456, 789]) == 124245\n assert candidate(nums = [9, 99, 999, 9999]) == 199998\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 75\n assert candidate(nums = [100, 200, 300, 400, 500]) == 301200\n assert candidate(nums = [9876, 5432, 1234]) == 98766666\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000]) == 30012000\n assert candidate(nums = [10, 20]) == 1020\n assert candidate(nums = [111, 222, 333]) == 111555\n assert candidate(nums = [123, 456, 789, 101, 112]) == 580002\n assert candidate(nums = [1, 2, 3]) == 15\n assert candidate(nums = [10000]) == 10000\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996]) == 200019991\n assert candidate(nums = [123, 456, 789, 101]) == 579890\n assert candidate(nums = [10, 20, 30, 40]) == 3070\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 1113885\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 32775\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 2404000\n assert candidate(nums = [123, 456, 789, 1011, 1213]) == 5793013\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 11, 22, 33, 44, 55]) == 31152\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 315\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300]) == 11107000\n assert candidate(nums = [123, 456, 789, 1011, 1213, 1415, 1617, 1819, 2021, 2223]) == 35929095\n assert candidate(nums = [555, 555, 555, 555, 555, 555, 555, 555, 555, 555]) == 2777775\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 100135035\n assert candidate(nums = [9999, 1, 222, 33, 4444, 555]) == 10036232\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == 16818\n assert candidate(nums = [10000, 9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 433316665\n assert candidate(nums = [1, 10, 100, 1000, 10000, 9999, 999, 99, 9, 8888, 888, 88, 8, 7777, 777, 77, 7]) == 13208429\n assert candidate(nums = [1, 9, 8, 7, 6, 5, 4, 3, 2]) == 270\n assert candidate(nums = [1, 10, 100, 1000, 10000, 9999, 999, 99, 9]) == 10122116\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 333316665\n assert candidate(nums = [555, 555, 555, 555, 555, 555, 555, 555]) == 2222220\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 42510\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 5655\n assert candidate(nums = [10000, 1, 10000, 1, 10000, 1, 10000]) == 2000020012\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 10350\n assert candidate(nums = [9876, 5432, 1234, 8765, 4321]) == 153094320\n assert candidate(nums = [12, 34, 56, 78, 90, 87, 65, 43, 21]) == 18306\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]) == 8047\n assert candidate(nums = [1000, 200, 30, 4, 500, 60, 7000, 800]) == 3015360\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 2262\n assert candidate(nums = [505, 404, 303, 202, 101, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 151845\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 551550\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == 111138885\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1010, 1111, 2222]) == 8332007\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 75570\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 5655\n assert candidate(nums = [123, 456, 789, 101, 112, 131, 141, 151]) == 1469535\n assert candidate(nums = [10000, 1000, 100, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 10000]) == 1010112245\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111, 1234]) == 388862344\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333]) == 8334330\n assert candidate(nums = [104, 205, 306, 407, 508, 609, 710, 811, 912, 1013, 1114, 1215, 1316, 1417, 1518]) == 22109316\n assert candidate(nums = [23, 45, 67, 89, 12, 34, 56, 78, 90, 11, 22, 33, 44, 55, 66, 77, 88, 99]) == 49895\n assert candidate(nums = [876, 543, 210, 987, 654, 321]) == 1630962\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006]) == 60075015\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]) == 496450\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 275\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 110\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == 111138885\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == 2428040\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 240040000\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 4444, 3333, 2222, 1111]) == 111116665\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 9999, 8888, 7777]) == 570060664\n", "comparison": "exact"}, "public_tests": ["[7,52,2,4]", "[5,14,13,8,12]"], "hints": ["Consider simulating the process to calculate the answer", "iterate until the array becomes empty. In each iteration, concatenate the first element to the last element and add their concatenation value to the answer.", "Don’t forget to handle cases when one element is left in the end, not two elements."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findTheArrayConcVal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:16+00:00", "tests_total": 120, "tests_dropped": 45, "flags": [], "topic_tags": ["array", "two-pointers", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_the_array_conc_val(nums)", "container": null, "callable": "find_the_array_conc_val", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2563, "task_id": "count-the-number-of-fair-pairs", "difficulty": "Medium", "problem_description": "Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.\n\nA pair (i, j) is fair if:\n\n- 0 <= i < j < n, and\n- lower <= nums[i] + nums[j] <= upper\n\nExample 1:\n\nInput: nums = [0,1,7,4,4,5], lower = 3, upper = 6\nOutput: 6\nExplanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).\n\nExample 2:\n\nInput: nums = [1,7,9,2,5], lower = 11, upper = 11\nOutput: 1\nExplanation: There is a single fair pair: (2,3).\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- nums.length == n\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= lower <= upper <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000],lower = 0,upper = 0) == 2\n assert candidate(nums = [0, 1, 7, 4, 4, 5],lower = 3,upper = 6) == 6\n assert candidate(nums = [5, 5, 5, 5, 5],lower = 10,upper = 10) == 10\n assert candidate(nums = [-1, 0, 1, 2, 3],lower = 0,upper = 4) == 8\n assert candidate(nums = [-1, 0, 1, 2, 3],lower = -2,upper = 2) == 6\n assert candidate(nums = [10, 20, 30, 40, 50],lower = 50,upper = 70) == 6\n assert candidate(nums = [-1, 0, 1, 2, 3],lower = 0,upper = 2) == 5\n assert candidate(nums = [1, 7, 9, 2, 5],lower = 11,upper = 11) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 5,upper = 15) == 37\n assert candidate(nums = [5, 5, 5, 5, 5],lower = 10,upper = 10) == 10\n assert candidate(nums = [-1, 0, 1, 2, 3],lower = 0,upper = 2) == 5\n assert candidate(nums = [-10, -20, -30, -40, -50],lower = -80,upper = -50) == 7\n assert candidate(nums = [1, 2, 3, 4, 5],lower = 5,upper = 8) == 7\n assert candidate(nums = [-1, 0, 1, 2, 3],lower = 0,upper = 4) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],lower = 1,upper = 38) == 189\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],lower = 0,upper = 0) == 190\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 50,upper = 150) == 37\n assert candidate(nums = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10],lower = -150,upper = -50) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],lower = 10,upper = 20) == 64\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],lower = 10,upper = 30) == 37\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 250000000, -250000000],lower = -1000000000,upper = 1000000000) == 11\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],lower = 15,upper = 35) == 57\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 0],lower = -1000000000,upper = 1000000000) == 8\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45, -45],lower = -50,upper = 50) == 37\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],lower = 15,upper = 20) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],lower = 5,upper = 10) == 18\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],lower = 10,upper = 28) == 35\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],lower = 3,upper = 7) == 34\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],lower = -10,upper = 10) == 55\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 2,upper = 2) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],lower = 10,upper = 20) == 21\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],lower = 10,upper = 20) == 18\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],lower = 1,upper = 38) == 45\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40],lower = -50,upper = 50) == 24\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],lower = -150,upper = -50) == 37\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],lower = 10,upper = 50) == 97\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],lower = 100,upper = 300) == 149\n assert candidate(nums = [50, 40, 30, 20, 10, 0, -10, -20, -30, -40],lower = -50,upper = 50) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 5,upper = 15) == 37\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 30,upper = 170) == 43\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],lower = 500,upper = 1500) == 37\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],lower = 20,upper = 80) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],lower = 10,upper = 20) == 64\n assert candidate(nums = [5, 2, 8, 3, 1, 9, 6, 4, 7, 10],lower = 5,upper = 15) == 37\n assert candidate(nums = [1, 2, 3, 4, 5],lower = 3,upper = 9) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],lower = 50,upper = 80) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 2,upper = 2) == 105\n assert candidate(nums = [-5, -4, -3, -2, -1],lower = -8,upper = -2) == 9\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],lower = 5,upper = 10) == 37\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 1,upper = 2) == 190\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],lower = 1000,upper = 2000) == 29\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],lower = 20,upper = 20) == 105\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 15,upper = 18) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 100,upper = 200) == 29\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],lower = 10,upper = 20) == 21\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45, -45],lower = -30,upper = 30) == 27\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10],lower = 6,upper = 12) == 40\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],lower = -200,upper = -100) == 29\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],lower = 5000,upper = 15000) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],lower = 18,upper = 20) == 26\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],lower = 0,upper = 0) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],lower = 10,upper = 30) == 149\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 15,upper = 20) == 9\n assert candidate(nums = [-5, 0, 5, 10, 15, 20, 25, 30, 35, 40],lower = 10,upper = 60) == 37\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 2,upper = 2) == 190\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35],lower = -20,upper = 20) == 16\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],lower = -20,upper = -10) == 29\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],lower = 20,upper = 30) == 84\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],lower = 30,upper = 40) == 30\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5, 6, 7, 8, 9, 10],lower = 6,upper = 12) == 49\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],lower = 5,upper = 15) == 47\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 190,upper = 200) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],lower = 18,upper = 30) == 25\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],lower = 1000,upper = 1900) == 29\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],lower = 5,upper = 10) == 23\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],lower = -150,upper = -50) == 37\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],lower = 3,upper = 19) == 188\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],lower = 5,upper = 15) == 37\n assert candidate(nums = [-1, -3, -5, -7, -9, -11, -13, -15, -17, -19],lower = -20,upper = -10) == 21\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],lower = 100,upper = 200) == 35\n assert candidate(nums = [-9, -7, -5, -3, -1, 1, 3, 5, 7, 9],lower = -18,upper = 18) == 45\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 50,upper = 150) == 37\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],lower = 0,upper = 0) == 45\n", "comparison": "exact"}, "public_tests": ["[0,1,7,4,4,5]\n3\n6", "[1,7,9,2,5]\n11\n11"], "hints": ["Sort the array in ascending order.", "For each number in the array, keep track of the smallest and largest numbers in the array that can form a fair pair with this number.", "As you move to larger number, both boundaries move down."], "metadata": {"canonical_parameter_names": ["nums", "lower", "upper"], "leetcode_dataset_entry_point": "Solution().countFairPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:18+00:00", "tests_total": 89, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def count_fair_pairs(nums, lower, upper)", "container": null, "callable": "count_fair_pairs", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "lower", "type": "Integer"}, {"name": "upper", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2564, "task_id": "substring-xor-queries", "difficulty": "Medium", "problem_description": "You are given a binary string s, and a 2D integer array queries where queries[i] = [first_i, second_i].\n\nFor the i^th query, find the shortest substring of s whose decimal value, val, yields second_i when bitwise XORed with first_i. In other words, val ^ first_i == second_i.\n\nThe answer to the i^th query is the endpoints (0-indexed) of the substring [left_i, right_i] or [-1, -1] if no such substring exists. If there are multiple answers, choose the one with the minimum left_i.\n\nReturn an array ans where ans[i] = [left_i, right_i] is the answer to the i^th query.\n\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"101101\", queries = [[0,5],[1,2]]\nOutput: [[0,2],[2,3]]\nExplanation: For the first query the substring in range [0,2] is \"101\" which has a decimal value of 5, and 5 ^ 0 = 5, hence the answer to the first query is [0,2]. In the second query, the substring in range [2,3] is \"11\", and has a decimal value of 3, and 3 ^ 1 = 2. So, [2,3] is returned for the second query.\n\nExample 2:\n\nInput: s = \"0101\", queries = [[12,8]]\nOutput: [[-1,-1]]\nExplanation: In this example there is no substring that answers the query, hence [-1,-1] is returned.\n\nExample 3:\n\nInput: s = \"1\", queries = [[4,5]]\nOutput: [[0,0]]\nExplanation: For this example, the substring in range [0,0] has a decimal value of 1, and 1 ^ 4 = 5. So, the answer is [0,0].\n\nConstraints:\n\n- 1 <= s.length <= 10^4\n- s[i] is either '0' or '1'.\n- 1 <= queries.length <= 10^5\n- 0 <= first_i, second_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1\",queries = [[4, 5]]) == [[0, 0]]\n assert candidate(s = \"1100110011\",queries = [[15, 0], [7, 8], [3, 12], [5, 10]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"0101\",queries = [[12, 8]]) == [[-1, -1]]\n assert candidate(s = \"101101\",queries = [[0, 5], [1, 2]]) == [[0, 2], [2, 3]]\n assert candidate(s = \"1010101010\",queries = [[1, 0], [0, 1], [2, 3], [3, 2]]) == [[0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1111111111\",queries = [[0, 0], [1, 1], [2, 2], [3, 3]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"0000000000\",queries = [[0, 0], [1, 1], [2, 2], [3, 3]]) == [[0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1010101010101010101010101010101010101010\",queries = [[1, 2], [3, 0], [7, 4], [15, 8], [31, 16]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100\",queries = [[15, 0], [31, 16], [63, 48], [127, 96], [255, 192]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"10101100011001100110011001100110011001100110011001100110011001100\",queries = [[12, 8], [14, 10], [15, 9], [16, 8], [17, 9], [18, 10]]) == [[5, 7], [5, 7], [4, 6], [4, 8], [4, 8], [4, 8]]\n assert candidate(s = \"111000111000\",queries = [[7, 7], [14, 14], [1, 1], [2, 2], [3, 3]]) == [[3, 3], [3, 3], [3, 3], [3, 3], [3, 3]]\n assert candidate(s = \"1101001010111010100101001110010111\",queries = [[15, 7], [30, 5], [63, 6], [127, 8], [255, 9]]) == [[-1, -1], [-1, -1], [24, 29], [-1, -1], [-1, -1]]\n assert candidate(s = \"10111011101110111011101110111011101110111011101110111011101110111\",queries = [[0, 5], [1, 2], [3, 6], [4, 7], [8, 9], [10, 11]]) == [[0, 2], [2, 3], [0, 2], [2, 3], [0, 0], [0, 0]]\n assert candidate(s = \"0110110110110110110110110110110110110110110110110110110110110110\",queries = [[6, 6], [14, 14], [22, 22], [30, 30], [38, 38], [46, 46], [54, 54]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010\",queries = [[1, 1], [3, 3], [7, 7], [15, 15], [31, 31], [63, 63], [127, 127], [255, 255], [511, 511]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"1110001110001110\",queries = [[7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0], [14, 14], [13, 13], [12, 12], [11, 11], [10, 10], [9, 9], [8, 8]]) == [[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]]\n assert candidate(s = \"1111000011110000111100001111000011110000\",queries = [[15, 15], [30, 30], [60, 60], [120, 120], [240, 240]]) == [[4, 4], [4, 4], [4, 4], [4, 4], [4, 4]]\n assert candidate(s = \"10010010010010010010\",queries = [[9, 9], [18, 18], [27, 27], [36, 36], [45, 45]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"1101101101101101101101101101101101101101101101101101101101101101\",queries = [[13, 13], [9, 9], [7, 7], [5, 5], [3, 3], [1, 1], [0, 0], [15, 15], [2, 2], [6, 6], [4, 4], [8, 8]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010\",queries = [[0, 1], [1, 0], [2, 3], [3, 2], [4, 5], [5, 4]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"10010010010010010010010010010010\",queries = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"01010101010101010101010101010101\",queries = [[1, 1], [2, 2], [4, 4], [8, 8], [16, 16], [32, 32]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"111111111111\",queries = [[1023, 1023], [511, 511], [255, 255], [127, 127]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"01100110011001100110011001100110\",queries = [[6, 6], [3, 3], [7, 7], [14, 14], [1, 1], [15, 15], [0, 0]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"10000000000000000001\",queries = [[1, 1], [1024, 1], [1, 1024], [2048, 2], [2, 2048]]) == [[1, 1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"100010001000100010\",queries = [[1, 1], [0, 0], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [15, 15], [14, 14], [13, 13], [12, 12], [11, 11]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111111\",queries = [[1, 0], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"10111011101110111011\",queries = [[15, 15], [30, 30], [60, 60], [120, 120], [240, 240]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"1100110011\",queries = [[3, 7], [15, 8], [2, 14], [5, 10], [6, 12]]) == [[1, 3], [-1, -1], [0, 3], [-1, -1], [-1, -1]]\n assert candidate(s = \"000100010001000100010001000100010001000100010001000100010001000100010001\",queries = [[1, 1], [3, 3], [7, 7], [15, 15], [31, 31], [63, 63], [127, 127], [255, 255], [511, 511]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"101010101010101010\",queries = [[5, 5], [3, 0], [1, 2], [7, 6], [15, 10], [31, 28]]) == [[1, 1], [-1, -1], [-1, -1], [0, 0], [0, 2], [-1, -1]]\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"11001100110011001100\",queries = [[3, 3], [12, 12], [48, 48], [192, 192], [768, 768]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"00000000000000000000000000000000\",queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"11001100110011001100\",queries = [[10, 5], [14, 1], [7, 8], [1, 14]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"11011010101100110110\",queries = [[5, 3], [2, 7], [15, 10], [1, 1]]) == [[0, 2], [1, 3], [1, 3], [2, 2]]\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101\",queries = [[9, 8], [13, 14], [5, 4], [11, 10], [1, 0]]) == [[1, 1], [-1, -1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"110101011010\",queries = [[1, 3], [4, 0], [5, 7], [6, 2]]) == [[1, 2], [-1, -1], [1, 2], [-1, -1]]\n assert candidate(s = \"000111000111000111\",queries = [[7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0], [14, 14], [13, 13], [12, 12], [11, 11], [10, 10], [9, 9], [8, 8]]) == [[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]]\n assert candidate(s = \"10110110110110110110110110110110110110110110110110110110110110110\",queries = [[0, 5], [1, 2], [3, 6], [4, 7], [8, 9], [10, 11]]) == [[0, 2], [2, 3], [0, 2], [2, 3], [0, 0], [0, 0]]\n assert candidate(s = \"10100101001010010100101001010010\",queries = [[1, 0], [2, 3], [3, 2], [4, 7], [8, 15]]) == [[0, 0], [0, 0], [0, 0], [-1, -1], [-1, -1]]\n assert candidate(s = \"0101010101010101\",queries = [[255, 255], [127, 127], [63, 63], [31, 31], [15, 15], [7, 7], [3, 3], [1, 1]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"00010001000100010001000100010001\",queries = [[0, 1], [1, 0], [2, 3], [3, 2], [4, 5]]) == [[3, 3], [3, 3], [3, 3], [3, 3], [3, 3]]\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101\",queries = [[1, 0], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19], [20, 21], [22, 23]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"11111111111111111111\",queries = [[1023, 1023], [0, 2047], [1, 2046], [2047, 0]]) == [[-1, -1], [0, 10], [0, 10], [0, 10]]\n assert candidate(s = \"11011011011011011011011011011011\",queries = [[1, 1], [3, 3], [5, 5], [7, 7], [15, 15]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"11111111111111111111\",queries = [[31, 0], [15, 16], [7, 8], [3, 12]]) == [[0, 4], [0, 4], [0, 3], [0, 3]]\n assert candidate(s = \"101010101010\",queries = [[0, 1], [1, 0], [2, 3], [3, 2]]) == [[0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"01010101010101010101\",queries = [[1, 1], [2, 3], [3, 2], [4, 7], [5, 4]]) == [[0, 0], [1, 1], [1, 1], [-1, -1], [1, 1]]\n assert candidate(s = \"1000000000000000000000000000000000000000000000000000000000000000\",queries = [[0, 1], [1, 0], [2, 3], [3, 2], [4, 5], [5, 4]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1100110011001100110011001100110011001100\",queries = [[3, 3], [6, 6], [12, 12], [24, 24], [48, 48]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"11110000111100001111\",queries = [[15, 15], [240, 240], [15, 240], [240, 15], [15, 0]]) == [[4, 4], [4, 4], [-1, -1], [-1, -1], [0, 3]]\n assert candidate(s = \"11100011100011100011\",queries = [[7, 2], [1, 14], [6, 9], [11, 4]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"110011001100110011001100\",queries = [[15, 10], [8, 1], [4, 4], [2, 5], [7, 7], [0, 0]]) == [[-1, -1], [1, 4], [2, 2], [-1, -1], [2, 2], [2, 2]]\n assert candidate(s = \"01010101010101010101010101010101\",queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"10101010101010101010\",queries = [[10, 10], [40, 40], [160, 160], [640, 640], [2560, 2560]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"110110110110\",queries = [[7, 6], [6, 7], [5, 4], [4, 5], [3, 2], [2, 3], [1, 0], [0, 1]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"10110101010110111011011011010110101101011010110101101011010110101\",queries = [[0, 5], [1, 2], [3, 6], [4, 7], [8, 9], [10, 11]]) == [[0, 2], [2, 3], [0, 2], [2, 3], [0, 0], [0, 0]]\n assert candidate(s = \"01001011010010011001001\",queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"01110111011101110111011101110111\",queries = [[1, 0], [2, 3], [3, 2], [7, 0], [15, 8]]) == [[1, 1], [1, 1], [1, 1], [1, 3], [1, 3]]\n assert candidate(s = \"100010001000100010001000100010001000100010001000100010001000\",queries = [[8, 8], [12, 12], [16, 16], [24, 24], [32, 32], [48, 48], [64, 64]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"101010101010101010101010101010101010101010101010\",queries = [[3, 10], [12, 5], [8, 1], [4, 4], [2, 5], [7, 7], [0, 0]]) == [[-1, -1], [-1, -1], [-1, -1], [1, 1], [-1, -1], [1, 1], [1, 1]]\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101010101010\",queries = [[12, 8], [14, 10], [15, 9], [16, 8], [17, 9], [18, 10]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"11110000111100001111000011110000111100001111000011110000\",queries = [[15, 15], [31, 31], [63, 63], [127, 127], [255, 255], [511, 511]]) == [[4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4]]\n assert candidate(s = \"110100101011001010110011001010110010101100110010101001010011001\",queries = [[10, 11], [20, 21], [30, 31], [40, 41], [50, 51], [60, 61], [70, 71]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1010101010101010\",queries = [[1, 0], [2, 3], [4, 7], [8, 15], [16, 31]]) == [[0, 0], [0, 0], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"10101010101010101010\",queries = [[10, 5], [14, 1], [6, 9], [2, 13]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"1100101011001010110010101100101011001010110010101100101011001010110010101100101011001010\",queries = [[123, 89], [456, 789], [101010, 110110], [98765, 56789]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"11111111111111111111111111111111\",queries = [[255, 255], [127, 127], [63, 63], [31, 31], [15, 15], [7, 7], [3, 3], [1, 1]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"001100110011\",queries = [[3, 0], [3, 1], [3, 2], [3, 3]]) == [[2, 3], [3, 4], [2, 2], [0, 0]]\n assert candidate(s = \"11111111111111111111111111111111\",queries = [[15, 0], [14, 1], [13, 2], [12, 3], [11, 4]]) == [[0, 3], [0, 3], [0, 3], [0, 3], [0, 3]]\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111000111\",queries = [[31, 30], [28, 29], [25, 26], [22, 23], [19, 20], [16, 17], [13, 14]]) == [[0, 0], [0, 0], [0, 1], [0, 0], [0, 2], [0, 0], [0, 1]]\n assert candidate(s = \"111100001111000011110000\",queries = [[15, 15], [0, 0], [1, 1], [14, 14], [7, 7], [8, 8]]) == [[4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4]]\n assert candidate(s = \"001110011100111\",queries = [[5, 5], [3, 0], [1, 2], [7, 6], [15, 10]]) == [[0, 0], [2, 3], [2, 3], [2, 2], [-1, -1]]\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010\",queries = [[511, 510], [255, 254], [127, 126], [63, 62], [31, 30], [15, 14], [7, 6]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001001001\",queries = [[9, 9], [5, 5], [10, 10], [6, 6], [2, 2], [3, 3], [1, 1], [0, 0]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"10010010010010010010\",queries = [[9, 6], [3, 12], [11, 4], [1, 14]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001\",queries = [[1, 0], [0, 1], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6], [8, 9], [9, 8]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"00110011001100110011\",queries = [[3, 12], [14, 1], [5, 0], [2, 13]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"00000000000000000000000000000000\",queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"10101010101010101010101010101010\",queries = [[10, 5], [3, 6], [7, 0], [15, 15]]) == [[-1, -1], [0, 2], [-1, -1], [1, 1]]\n assert candidate(s = \"01010101010101010101\",queries = [[5, 0], [2, 3], [6, 7], [10, 5]]) == [[1, 3], [1, 1], [1, 1], [-1, -1]]\n assert candidate(s = \"1011001100011100000111100000111110000011\",queries = [[255, 255], [127, 127], [63, 63], [31, 31], [15, 15]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"1100110011\",queries = [[3, 6], [7, 0], [1, 3], [2, 1]]) == [[-1, -1], [-1, -1], [1, 2], [0, 1]]\n assert candidate(s = \"11001100110011001100110011001100\",queries = [[1, 1], [2, 3], [4, 7], [8, 15]]) == [[2, 2], [0, 0], [0, 1], [-1, -1]]\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100\",queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010\",queries = [[21, 30], [15, 16], [7, 8], [3, 12], [10, 5], [6, 9], [14, 1], [2, 13], [11, 4], [5, 0], [9, 6], [1, 14], [4, 11], [8, 7]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [0, 2], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"10101010101010101010\",queries = [[10, 15], [5, 0], [1, 1], [0, 2], [255, 255]]) == [[0, 2], [0, 2], [1, 1], [0, 1], [1, 1]]\n assert candidate(s = \"0011110011110011110011110011110011110011\",queries = [[1, 0], [3, 2], [7, 6], [15, 14], [31, 30]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"1100110011001100\",queries = [[15, 15], [14, 14], [13, 13], [12, 12], [11, 11], [10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0]]) == [[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, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"1001101001101001101001101001101001101001101001101001101001101001\",queries = [[5, 6], [10, 11], [15, 16], [20, 21], [25, 26], [30, 31], [35, 36]]) == [[3, 4], [0, 0], [-1, -1], [0, 0], [3, 4], [0, 0], [-1, -1]]\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000000000000000\",queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\",queries = [[1023, 511], [511, 1023], [2047, 255], [255, 2047], [65535, 32767], [32767, 65535]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"11111111111111111111\",queries = [[31, 30], [15, 14], [7, 6], [3, 2], [1, 0]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001\",queries = [[9, 1], [15, 15], [7, 0], [3, 1], [1, 0]]) == [[-1, -1], [1, 1], [-1, -1], [0, 1], [0, 0]]\n assert candidate(s = \"0011001100110011001100110011001100110011001100110011001100110011\",queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13]]) == [[2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(s = \"1001001001001001001001001001\",queries = [[9, 9], [5, 5], [10, 10], [6, 6], [2, 2], [3, 3], [1, 1]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",queries = [[1000000, 500000], [500000, 1000000], [2000000, 250000], [250000, 2000000], [6000000, 3000000], [3000000, 6000000]]) == [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1]]\n assert candidate(s = \"00110011001100110011\",queries = [[3, 3], [12, 12], [48, 48], [192, 192], [768, 768]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n assert candidate(s = \"0100100010001000100010001000100010001000\",queries = [[1, 1], [2, 2], [4, 4], [8, 8], [16, 16]]) == [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]\n", "comparison": "exact"}, "public_tests": ["\"101101\"\n[[0,5],[1,2]]", "\"0101\"\n[[12,8]]", "\"1\"\n[[4,5]]"], "hints": ["You do not need to consider substrings having lengths greater than 30.", "Pre-process all substrings with lengths not greater than 30, and add the best endpoints to a dictionary."], "metadata": {"canonical_parameter_names": ["s", "queries"], "leetcode_dataset_entry_point": "Solution().substringXorQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:21+00:00", "tests_total": 100, "tests_dropped": 0, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "string", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def substring_xor_queries(s, queries)", "container": null, "callable": "substring_xor_queries", "parameters": [{"name": "s", "type": "String"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2565, "task_id": "subsequence-with-the-minimum-score", "difficulty": "Hard", "problem_description": "You are given two strings s and t.\n\nYou are allowed to remove any number of characters from the string t.\n\nThe score of the string is 0 if no characters are removed from the string t, otherwise:\n\n- Let left be the minimum index among all removed characters.\n- Let right be the maximum index among all removed characters.\n\nThen the score of the string is right - left + 1.\n\nReturn the minimum possible score to make t a subsequence of s.\n\nA subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not).\n\nExample 1:\n\nInput: s = \"abacaba\", t = \"bzaa\"\nOutput: 1\nExplanation: In this example, we remove the character \"z\" at index 1 (0-indexed).\nThe string t becomes \"baa\" which is a subsequence of the string \"abacaba\" and the score is 1 - 1 + 1 = 1.\nIt can be proven that 1 is the minimum score that we can achieve.\n\nExample 2:\n\nInput: s = \"cde\", t = \"xyz\"\nOutput: 3\nExplanation: In this example, we remove characters \"x\", \"y\" and \"z\" at indices 0, 1, and 2 (0-indexed).\nThe string t becomes \"\" which is a subsequence of the string \"cde\" and the score is 2 - 0 + 1 = 3.\nIt can be proven that 3 is the minimum score that we can achieve.\n\nConstraints:\n\n- 1 <= s.length, t.length <= 10^5\n- s and t consist of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcd\",t = \"abcde\") == 1\n assert candidate(s = \"hello\",t = \"world\") == 5\n assert candidate(s = \"abcdefghij\",t = \"fihgjedcba\") == 8\n assert candidate(s = \"abcde\",t = \"edcba\") == 4\n assert candidate(s = \"aaaaa\",t = \"aa\") == 0\n assert candidate(s = \"testcase\",t = \"ttccasse\") == 3\n assert candidate(s = \"programming\",t = \"gnimmargorp\") == 9\n assert candidate(s = \"abcd\",t = \"dbca\") == 3\n assert candidate(s = \"xyz\",t = \"abc\") == 3\n assert candidate(s = \"minimum\",t = \"imumin\") == 2\n assert candidate(s = \"abcd\",t = \"dcba\") == 3\n assert candidate(s = \"abcdefg\",t = \"xyz\") == 3\n assert candidate(s = \"programming\",t = \"gaming\") == 0\n assert candidate(s = \"abacaba\",t = \"bzaa\") == 1\n assert candidate(s = \"cde\",t = \"xyz\") == 3\n assert candidate(s = \"abcde\",t = \"ace\") == 0\n assert candidate(s = \"hello\",t = \"olelh\") == 4\n assert candidate(s = \"xyzxyzxyzxyzxyz\",t = \"zyzyzyzyzyzyzyzyzyz\") == 9\n assert candidate(s = \"testcase\",t = \"tttttttt\") == 6\n assert candidate(s = \"abcde\",t = \"abcdxyzef\") == 5\n assert candidate(s = \"abacabadabacaba\",t = \"zabacabadabacabaz\") == 17\n assert candidate(s = \"abababab\",t = \"bababa\") == 0\n assert candidate(s = \"aaaaaaaaaa\",t = \"aaaaaaaaaab\") == 1\n assert candidate(s = \"abcdexyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"aabbaabbaabb\",t = \"bbbb\") == 0\n assert candidate(s = \"abacabadabacaba\",t = \"aaaaabaaa\") == 0\n assert candidate(s = \"longstringwithmanypatterns\",t = \"stringwithpatternsstring\") == 6\n assert candidate(s = \"thisisaverylongstringfortesting\",t = \"stringfortestingthisisaverylong\") == 15\n assert candidate(s = \"abcdefghij\",t = \"bcdefghia\") == 1\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",t = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 84\n assert candidate(s = \"abcabcabcabc\",t = \"cccc\") == 0\n assert candidate(s = \"mississippi\",t = \"pi\") == 0\n assert candidate(s = \"hellotherehellotherehellotherehellothere\",t = \"herehellotherehellotherehellotherehellotherehello\") == 14\n assert candidate(s = \"abracadabra\",t = \"acraabdbrac\") == 6\n assert candidate(s = \"xyzxyzxyz\",t = \"zyxzyxzyx\") == 5\n assert candidate(s = \"abcdabcdabcd\",t = \"dcbaabdcba\") == 7\n assert candidate(s = \"sequence\",t = \"enqueseq\") == 5\n assert candidate(s = \"abracadabra\",t = \"rac\") == 0\n assert candidate(s = \"repeatedcharactersarehere\",t = \"tareeere\") == 0\n assert candidate(s = \"aabbccddeeffgg\",t = \"fedcbazyxwvutsrqponmlkjihgfedcba\") == 31\n assert candidate(s = \"abcdefghij\",t = \"abcdefghijabcdefghij\") == 10\n assert candidate(s = \"bananaananabayananabananabananabanana\",t = \"nananananananananananananananananan\") == 11\n assert candidate(s = \"abcde\",t = \"edcbaa\") == 5\n assert candidate(s = \"longstringwithseveralcharacters\",t = \"characterswithseveralstringlong\") == 21\n assert candidate(s = \"thisisaverylongstringwithmanysimilarcharacters\",t = \"similarcharacters\") == 0\n assert candidate(s = \"hellohellohello\",t = \"ollhll\") == 0\n assert candidate(s = \"longestsubstring\",t = \"strolng\") == 2\n assert candidate(s = \"solvingproblems\",t = \"problemsolving\") == 6\n assert candidate(s = \"banana\",t = \"bananabananabanana\") == 12\n assert candidate(s = \"ababababababababababababababababa\",t = \"bababababababababababababababababa\") == 1\n assert candidate(s = \"aabbccddeeffgghhii\",t = \"ihgfedcba\") == 8\n assert candidate(s = \"abcdefghij\",t = \"ihgfedcbaj\") == 8\n assert candidate(s = \"hellohellohello\",t = \"lllllooohehe\") == 5\n assert candidate(s = \"aaaaaa\",t = \"bbbbbb\") == 6\n assert candidate(s = \"aaaaaabbbbbbcccccc\",t = \"cccccccbaaaaa\") == 7\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",t = \"dogzyxvutwrofsjpmnklobq\") == 20\n assert candidate(s = \"aaaaaaaaaa\",t = \"aaaaaaaaa\") == 0\n assert candidate(s = \"programmingisfun\",t = \"misnpfrmigong\") == 9\n assert candidate(s = \"complexproblem\",t = \"problemcomplex\") == 7\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzzyyxxwwvvuuttssrrqppoonnmmllkkjjiihhhgggffeeedddccbbaa\") == 54\n assert candidate(s = \"abracadabra\",t = \"raac\") == 1\n assert candidate(s = \"findingthesolution\",t = \"solutionfinding\") == 7\n assert candidate(s = \"abcdefghijabcdefghij\",t = \"hgfedcbajihgfedcbaj\") == 16\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 23\n assert candidate(s = \"aaaaabbbbbccccc\",t = \"abcabcabcabc\") == 8\n assert candidate(s = \"abcdabcdabcd\",t = \"ddddccbbbaaa\") == 9\n assert candidate(s = \"racecar\",t = \"racecarracecar\") == 7\n assert candidate(s = \"mississippi\",t = \"ississipisipismiss\") == 9\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzzzyyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbaaabbaa\") == 59\n assert candidate(s = \"mississippi\",t = \"ppiisimiss\") == 6\n assert candidate(s = \"samestring\",t = \"samestring\") == 0\n assert candidate(s = \"abcdexyzabcdexyz\",t = \"zyxwvutzyxwvutzyxwvut\") == 19\n assert candidate(s = \"abcde\",t = \"bcdea\") == 1\n assert candidate(s = \"aabbccddeeff\",t = \"fedcba\") == 5\n assert candidate(s = \"uniquecharacters\",t = \"charactersunique\") == 6\n assert candidate(s = \"abcdefghijabcdefghij\",t = \"fihgjedcbafihgjedcbafihg\") == 21\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 50\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"quickbrownfox\",t = \"brownfoxquick\") == 5\n assert candidate(s = \"dynamicprogramming\",t = \"ymnpgmcratidnodpmg\") == 13\n assert candidate(s = \"abababababab\",t = \"bababababa\") == 0\n assert candidate(s = \"aaaaaabbbbbccccc\",t = \"ccccbbbaaaaa\") == 7\n assert candidate(s = \"abacaxbadacabacaba\",t = \"bacabaa\") == 0\n assert candidate(s = \"abcdefghij\",t = \"abcdefghijk\") == 1\n assert candidate(s = \"longstringthatcontainscharactersrepeatedly\",t = \"characterscharacterscharacters\") == 18\n assert candidate(s = \"abcdabcdabcdabcdabcdabcd\",t = \"dddddddddd\") == 4\n assert candidate(s = \"thisisaverylongstring\",t = \"stringisaverylong\") == 5\n assert candidate(s = \"mississippi\",t = \"issississississississsissississississsississississs\") == 44\n assert candidate(s = \"qzxtqzxtqzxt\",t = \"xtzxtzxtzxtzxtzxtzxtzxtzxtzxtzxtzxtzxtzxtzxt\") == 35\n assert candidate(s = \"abacabadabacaba\",t = \"bzaaazza\") == 6\n assert candidate(s = \"repeatedcharacters\",t = \"eedaaeerereeeddperrrrttt\") == 18\n assert candidate(s = \"pythonprogramming\",t = \"ptyhnonrpgmaminnorgm\") == 14\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzzyyxxwwvvuutssrrqqppoonnllkkjjiihhhgggffeeeddccbaab\") == 50\n assert candidate(s = \"mississippi\",t = \"ppisissam\") == 6\n assert candidate(s = \"thisisatest\",t = \"ttttt\") == 2\n assert candidate(s = \"mississippi\",t = \"ssssii\") == 0\n assert candidate(s = \"abcabcabcabcabcabc\",t = \"cccbbbbaaabbbcccbbbbaaabbb\") == 19\n assert candidate(s = \"thisisalongstring\",t = \"thisstringislong\") == 6\n assert candidate(s = \"xyzxyzxyzxyz\",t = \"zzzzyyyyxxxxyyyyzzzz\") == 15\n assert candidate(s = \"thisisaverylongstring\",t = \"gnirtsylonlavraesiisthis\") == 20\n assert candidate(s = \"abcdefghij\",t = \"aabbccddeeffgghhiijj\") == 18\n assert candidate(s = \"optimization\",t = \"ttttiiiooonnnssss\") == 15\n assert candidate(s = \"abacabadabacaba\",t = \"dabacabad\") == 1\n assert candidate(s = \"abcdeabcdeabcde\",t = \"ecbedcab\") == 4\n assert candidate(s = \"abacabadabacaba\",t = \"abadab\") == 0\n assert candidate(s = \"abcdabcdabcd\",t = \"dddd\") == 1\n assert candidate(s = \"hello\",t = \"hhheeelllllooooo\") == 14\n assert candidate(s = \"thisisaverylongstring\",t = \"tsring\") == 0\n assert candidate(s = \"abacabadabacaba\",t = \"aaabbbccc\") == 3\n assert candidate(s = \"pythonprogramming\",t = \"notapysubsequence\") == 15\n assert candidate(s = \"abacabadabacaba\",t = \"aaaaa\") == 0\n assert candidate(s = \"mississippi\",t = \"ssissip\") == 0\n assert candidate(s = \"abcdefghijabcdefghij\",t = \"jihgfedcbajihgfedcba\") == 18\n assert candidate(s = \"abcdefabcdefabcdef\",t = \"fedcba\") == 3\n assert candidate(s = \"abcdefg\",t = \"gfedcbaacdefg\") == 7\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",t = \"dcbaabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 3\n assert candidate(s = \"mississippi\",t = \"msssssssssssss\") == 9\n assert candidate(s = \"abababababababab\",t = \"babababababababa\") == 1\n assert candidate(s = \"abacabadabacaba\",t = \"abacabacaba\") == 0\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\",t = \"jihgfedcbajihgfedcbajihgfedcbajihgfedcba\") == 36\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"nestednestednested\",t = \"nns\") == 0\n assert candidate(s = \"abacabadabacaba\",t = \"zzzzzzzzzzzzzzz\") == 15\n assert candidate(s = \"aaaaabbbbbcccccdddddeeeee\",t = \"bbbbbeeecdddd\") == 3\n assert candidate(s = \"mississippi\",t = \"ppisss\") == 2\n assert candidate(s = \"aaaaaabbbbbbbccccccdddddeeeeefffff\",t = \"ffffeeeeeddccccbbbaaaa\") == 18\n assert candidate(s = \"longwordhere\",t = \"helloworld\") == 8\n assert candidate(s = \"aaaaaaa\",t = \"aaaaaaa\") == 0\n assert candidate(s = \"abcdefghij\",t = \"abcdefghijxyz\") == 3\n", "comparison": "exact"}, "public_tests": ["\"abacaba\"\n\"bzaa\"", "\"cde\"\n\"xyz\""], "hints": ["Maintain two pointers: i and j. We need to perform a similar operation: while t[0:i] + t[j:n] is not a subsequence of the string s, increase j.", "We can check the condition greedily. Create the array leftmost[i] which denotes minimum index k, such that in prefix s[0:k] exists subsequence t[0:i]. Similarly, we define rightmost[i].", "If leftmost[i] < rightmost[j] then t[0:i] + t[j:n] is the subsequence of s."], "metadata": {"canonical_parameter_names": ["s", "t"], "leetcode_dataset_entry_point": "Solution().minimumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:23+00:00", "tests_total": 130, "tests_dropped": 1, "flags": [], "topic_tags": ["two-pointers", "string", "binary-search"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_score(s, t)", "container": null, "callable": "minimum_score", "parameters": [{"name": "s", "type": "String"}, {"name": "t", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2566, "task_id": "maximum-difference-by-remapping-a-digit", "difficulty": "Easy", "problem_description": "You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.\n\nReturn the difference between the maximum and minimum values Bob can make by remapping exactly one digit in num.\n\nNotes:\n\n- When Bob remaps a digit d1 to another digit d2, Bob replaces all occurrences of d1 in num with d2.\n- Bob can remap a digit to itself, in which case num does not change.\n- Bob can remap different digits for obtaining minimum and maximum values respectively.\n- The resulting number after remapping can contain leading zeroes.\n\nExample 1:\n\nInput: num = 11891\nOutput: 99009\nExplanation:\nTo achieve the maximum value, Bob can remap the digit 1 to the digit 9 to yield 99899.\nTo achieve the minimum value, Bob can remap the digit 1 to the digit 0, yielding 890.\nThe difference between these two numbers is 99009.\n\nExample 2:\n\nInput: num = 90\nOutput: 99\nExplanation:\nThe maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0).\nThus, we return 99.\n\nConstraints:\n\n- 1 <= num <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 11891) == 99009\n assert candidate(num = 123321) == 900009\n assert candidate(num = 55555555) == 99999999\n assert candidate(num = 111111) == 999999\n assert candidate(num = 88888888) == 99999999\n assert candidate(num = 12321) == 90009\n assert candidate(num = 9999999) == 9999999\n assert candidate(num = 1) == 9\n assert candidate(num = 475328) == 900000\n assert candidate(num = 99999999) == 99999999\n assert candidate(num = 8888888) == 9999999\n assert candidate(num = 99999) == 99999\n assert candidate(num = 1000000) == 9000000\n assert candidate(num = 90) == 99\n assert candidate(num = 1111111) == 9999999\n assert candidate(num = 66666666) == 99999999\n assert candidate(num = 44444444) == 99999999\n assert candidate(num = 80808080) == 90909090\n assert candidate(num = 3330333) == 9990999\n assert candidate(num = 11119999) == 99990000\n assert candidate(num = 59595959) == 90909090\n assert candidate(num = 50505050) == 90909090\n assert candidate(num = 12233445) == 90000000\n assert candidate(num = 111999) == 999000\n assert candidate(num = 10001) == 90009\n assert candidate(num = 10101010) == 90909090\n assert candidate(num = 90909090) == 99999999\n assert candidate(num = 99990000) == 99999999\n assert candidate(num = 555000) == 999000\n assert candidate(num = 11100011) == 99900099\n assert candidate(num = 95959595) == 94949494\n assert candidate(num = 99009900) == 99999999\n assert candidate(num = 5555555) == 9999999\n assert candidate(num = 999000) == 999999\n assert candidate(num = 88811122) == 99900000\n assert candidate(num = 12121212) == 90909090\n", "comparison": "exact"}, "public_tests": ["11891", "90"], "hints": ["Try to remap the first non-nine digit to 9 to obtain the maximum number.", "Try to remap the first non-zero digit to 0 to obtain the minimum number."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().minMaxDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:26+00:00", "tests_total": 111, "tests_dropped": 75, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def min_max_difference(num)", "container": null, "callable": "min_max_difference", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2567, "task_id": "minimum-score-by-changing-two-elements", "difficulty": "Medium", "problem_description": "You are given an integer array nums.\n\n- The low score of nums is the minimum absolute difference between any two integers.\n- The high score of nums is the maximum absolute difference between any two integers.\n- The score of nums is the sum of the high and low scores.\n\nReturn the minimum score after changing two elements of nums.\n\nExample 1:\n\nInput: nums = [1,4,7,8,5]\nOutput: 3\nExplanation:\n- Change nums[0] and nums[1] to be 6 so that nums becomes [6,6,7,8,5].\n- The low score is the minimum absolute difference: |6 - 6| = 0.\n- The high score is the maximum absolute difference: |8 - 5| = 3.\n- The sum of high and low score is 3.\n\nExample 2:\n\nInput: nums = [1,4,3]\nOutput: 0\nExplanation:\n- Change nums[1] and nums[2] to 1 so that nums becomes [1,1,1].\n- The sum of maximum absolute difference and minimum absolute difference is 0.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 100, 1000, 10000, 100000]) == 990\n assert candidate(nums = [1, 4, 7, 8, 5]) == 3\n assert candidate(nums = [1, 4, 3]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1200\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91, 11, 90, 12, 89, 13, 88, 14, 87, 15, 86, 16, 85, 17, 84, 18, 83, 19, 82, 20, 81]) == 97\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 26\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5]) == 6\n assert candidate(nums = [1, 2, 3, 1000, 1001, 1002, 1003, 1004, 1005, 1006]) == 1003\n assert candidate(nums = [1, 1, 1, 1, 100, 100, 100, 100, 100, 100]) == 99\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 24\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997]) == 999999997\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1001, 1002, 1003, 1004]) == 704\n assert candidate(nums = [1, 2, 3, 4, 5, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 799\n assert candidate(nums = [1000000000, 999999999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 12\n assert candidate(nums = [1, 2, 3, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 799\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]) == 100\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 8\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, 1000]) == 0\n assert candidate(nums = [1, 2, 100, 101, 102, 103, 104, 105, 106, 107]) == 7\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 3\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 10, 20, 30, 40]) == 79\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1001, 1002, 1003, 1004, 1005]) == 705\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]) == 13\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 30\n assert candidate(nums = [1, 2, 3, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 18\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]) == 22\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 80\n assert candidate(nums = [1000000000, 999999999, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 97\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 200, 300, 400, 500]) == 299\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 100, 101]) == 13\n assert candidate(nums = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 799\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 70\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84]) == 13\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]) == 27\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 119\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 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, 100]) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 80\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500]) == 300\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 2]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 70\n assert candidate(nums = [1, 2, 3, 1000000000, 2, 3, 1000000000, 2, 3, 1000000000]) == 999999998\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 12\n assert candidate(nums = [10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100]) == 70\n assert candidate(nums = [1, 2, 1000000000, 2, 1000000000, 3, 1000000000, 4, 1000000000, 5]) == 999999998\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 170\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 17\n assert candidate(nums = [1, 2, 3, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 999999997\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 179\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 100, 200, 300, 400, 500]) == 299\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 2, 3, 4, 5, 6]) == 9999999\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == 999999997\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [1, 3, 6, 8, 12, 15, 18, 21, 24, 27]) == 20\n assert candidate(nums = [1, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == 8\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 70\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100]) == 0\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 79\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1000000000, 999999999]) == 9\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]) == 90\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 120\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 60\n", "comparison": "exact"}, "public_tests": ["[1,4,7,8,5]", "[1,4,3]"], "hints": ["Changing the minimum or maximum values will only minimize the score.", "Think about what all possible pairs of minimum and maximum values can be changed to form the minimum score."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimizeSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:28+00:00", "tests_total": 82, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimize_sum(nums)", "container": null, "callable": "minimize_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2568, "task_id": "minimum-impossible-or", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums.\n\nWe say that an integer x is expressible from nums if there exist some integers 0 <= index_1 < index_2 < ... < index_k < nums.length for which nums[index_1] | nums[index_2] | ... | nums[index_k] = x. In other words, an integer is expressible if it can be written as the bitwise OR of some subsequence of nums.\n\nReturn the minimum positive non-zero integer that is not expressible from nums.\n\nExample 1:\n\nInput: nums = [2,1]\nOutput: 4\nExplanation: 1 and 2 are already present in the array. We know that 3 is expressible, since nums[0] | nums[1] = 2 | 1 = 3. Since 4 is not expressible, we return 4.\n\nExample 2:\n\nInput: nums = [5,3,2]\nOutput: 1\nExplanation: We can show that 1 is the smallest number that is not expressible.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 3, 2]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16]) == 32\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2048\n assert candidate(nums = [2, 1]) == 4\n assert candidate(nums = [7, 14, 21, 28]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9]) == 2\n assert candidate(nums = [3, 6, 9, 12]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(nums = [6, 10, 14, 18]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50]) == 1\n assert candidate(nums = [1024, 2048, 4096, 8192]) == 1\n assert candidate(nums = [7, 14, 28, 56]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [3, 7, 15, 31, 63]) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 16\n assert candidate(nums = [7, 14, 28]) == 1\n assert candidate(nums = [3, 6, 9]) == 1\n assert candidate(nums = [3, 7, 15, 31]) == 1\n assert candidate(nums = [10, 20, 30, 40]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) == 32\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 2097152\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1024\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 1048576\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 2\n assert candidate(nums = [1048576, 2097152, 4194304, 8388608, 16777216, 33554432]) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095]) == 2\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864]) == 1\n assert candidate(nums = [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456]) == 2\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]) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]) == 2\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 65536\n assert candidate(nums = [2, 6, 18, 54, 162, 486, 1458, 4374, 13122, 39366]) == 1\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 102, 106, 110, 114, 118]) == 1\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143]) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 2\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == 1\n assert candidate(nums = [5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131077]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58]) == 1\n assert candidate(nums = [1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125]) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2048\n assert candidate(nums = [3, 5, 9, 17, 33, 65, 129, 257, 513]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 32768\n assert candidate(nums = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120]) == 1\n assert candidate(nums = [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046, 4094, 8190, 16382, 32766, 65534]) == 1\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]) == 1\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000]) == 1\n assert candidate(nums = [4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 124]) == 1\n assert candidate(nums = [31, 63, 127, 255, 511, 1023, 2047, 4095]) == 1\n assert candidate(nums = [100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400]) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 4096\n assert candidate(nums = [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]) == 1\n assert candidate(nums = [3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385]) == 1\n assert candidate(nums = [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456]) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 1\n assert candidate(nums = [1, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == 2\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584, 7168]) == 1\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62]) == 1\n assert candidate(nums = [1, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097]) == 2\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 33]) == 4\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 131072\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 1\n assert candidate(nums = [2, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 32\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 1\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(nums = [255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 1\n assert candidate(nums = [3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 24, 30]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 8192\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144]) == 524288\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152]) == 1\n assert candidate(nums = [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]) == 32\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2048\n assert candidate(nums = [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144]) == 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]) == 2\n assert candidate(nums = [3, 11, 43, 171, 683, 2731, 10923, 43691, 174763, 699051, 2796203, 11184811, 44739243, 178956971, 715827883]) == 1\n assert candidate(nums = [3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 33, 34, 36, 40, 48]) == 1\n assert candidate(nums = [31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]) == 1\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61]) == 2\n assert candidate(nums = [7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071]) == 1\n assert candidate(nums = [9, 18, 36, 72, 144, 288, 576, 1152, 2304, 4608, 9216]) == 1\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77]) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 1\n", "comparison": "exact"}, "public_tests": ["[2,1]", "[5,3,2]"], "hints": ["Think about forming numbers in the powers of 2 using their bit representation.", "The minimum power of 2 not present in the array will be the first number that could not be expressed using the given operation."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minImpossibleOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:31+00:00", "tests_total": 108, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "bit-manipulation", "brainteaser"]}, "language": "ruby", "interface": {"raw_signature": "def min_impossible_or(nums)", "container": null, "callable": "min_impossible_or", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2569, "task_id": "handling-sum-queries-after-update", "difficulty": "Hard", "problem_description": "You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:\n\n1. For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nums1 from index l to index r. Both l and r are 0-indexed.\n2. For a query of type 2, queries[i] = [2, p, 0]. For every index 0 <= i < n, set nums2[i] = nums2[i] + nums1[i] * p.\n3. For a query of type 3, queries[i] = [3, 0, 0]. Find the sum of the elements in nums2.\n\nReturn an array containing all the answers to the third type queries.\n\nExample 1:\n\nInput: nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]\nOutput: [3]\nExplanation: After the first query nums1 becomes [1,1,1]. After the second query, nums2 becomes [1,1,1], so the answer to the third query is 3. Thus, [3] is returned.\n\nExample 2:\n\nInput: nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]\nOutput: [5]\nExplanation: After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned.\n\nConstraints:\n\n- 1 <= nums1.length,nums2.length <= 10^5\n- nums1.length = nums2.length\n- 1 <= queries.length <= 10^5\n- queries[i].length = 3\n- 0 <= l <= r <= nums1.length - 1\n- 0 <= p <= 10^6\n- 0 <= nums1[i] <= 1\n- 0 <= nums2[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1],nums2 = [5],queries = [[2, 0, 0], [3, 0, 0]]) == [5]\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10, 20, 30, 40, 50],queries = [[2, 5, 0], [3, 0, 0], [1, 0, 2], [2, 3, 0], [3, 0, 0]]) == [175, 181]\n assert candidate(nums1 = [1, 0, 1],nums2 = [0, 0, 0],queries = [[1, 1, 1], [2, 1, 0], [3, 0, 0]]) == [3]\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],queries = [[1, 0, 4], [1, 0, 4], [2, 1, 0], [3, 0, 0]]) == [0]\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 2, 3, 4],queries = [[1, 0, 3], [2, 2, 0], [3, 0, 0], [1, 1, 2], [3, 0, 0]]) == [18, 18]\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],queries = [[3, 0, 0], [1, 0, 1], [3, 0, 0], [2, 3, 0], [3, 0, 0]]) == [4, 4, 10]\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [0, 0, 0, 0],queries = [[2, 1, 0], [3, 0, 0], [1, 0, 1], [2, 2, 0], [3, 0, 0]]) == [4, 8]\n assert candidate(nums1 = [0, 1, 0, 1, 0],nums2 = [1, 2, 3, 4, 5],queries = [[1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 1, 3], [2, 3, 0], [3, 0, 0]]) == [21, 33]\n assert candidate(nums1 = [1, 0, 0, 1],nums2 = [10, 20, 30, 40],queries = [[1, 0, 3], [2, 5, 0], [3, 0, 0], [1, 1, 2], [2, 10, 0], [3, 0, 0]]) == [110, 110]\n assert candidate(nums1 = [1, 1, 0, 0],nums2 = [10, 20, 30, 40],queries = [[2, 1, 0], [3, 0, 0], [1, 0, 1], [2, 3, 0], [3, 0, 0]]) == [102, 102]\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 1, 1, 1],queries = [[1, 0, 2], [2, 3, 0], [3, 0, 0], [1, 1, 3], [3, 0, 0]]) == [13, 13]\n assert candidate(nums1 = [1, 0, 1, 0, 1],nums2 = [5, 5, 5, 5, 5],queries = [[1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 1, 3], [2, 1, 0], [3, 0, 0]]) == [29, 30]\n assert candidate(nums1 = [0, 1, 0, 1],nums2 = [1, 2, 3, 4],queries = [[1, 0, 3], [2, 2, 0], [3, 0, 0], [1, 1, 2], [3, 0, 0]]) == [14, 14]\n assert candidate(nums1 = [0, 1, 1, 0, 1],nums2 = [1, 2, 3, 4, 5],queries = [[1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 2, 3], [3, 0, 0]]) == [19, 19]\n assert candidate(nums1 = [1, 0, 0, 1, 1],nums2 = [5, 5, 5, 5, 5],queries = [[2, 1, 0], [3, 0, 0], [1, 0, 4], [3, 0, 0], [2, 2, 0], [3, 0, 0]]) == [28, 28, 32]\n assert candidate(nums1 = [1, 1, 0, 0, 1],nums2 = [10, 20, 30, 40, 50],queries = [[1, 1, 3], [2, 3, 0], [3, 0, 0], [1, 0, 2], [3, 0, 0]]) == [162, 162]\n assert candidate(nums1 = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[1, 0, 9], [2, 5, 0], [3, 0, 0], [1, 2, 7], [2, 3, 0], [3, 0, 0], [1, 1, 8], [3, 0, 0], [1, 0, 9], [3, 0, 0]]) == [5520, 5526, 5526, 5526]\n assert candidate(nums1 = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],queries = [[1, 0, 5], [2, 10, 0], [3, 0, 0], [1, 6, 11], [2, 20, 0], [3, 0, 0], [1, 2, 9], [3, 0, 0], [1, 0, 11], [2, 5, 0], [3, 0, 0]]) == [820, 940, 940, 970]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 5, 9], [2, 3, 0], [3, 0, 0], [1, 0, 9], [3, 0, 0]]) == [558, 573, 573]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000],queries = [[1, 0, 9], [2, 1000000, 0], [3, 0, 0], [1, 0, 4], [2, 500000, 0], [3, 0, 0], [1, 5, 9], [2, 300000, 0], [3, 0, 0], [1, 1, 8], [3, 0, 0]]) == [60000000, 63000000, 64500000, 64500000]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[1, 0, 19], [2, 1, 0], [3, 0, 0], [1, 2, 18], [2, 2, 0], [3, 0, 0], [1, 3, 17], [2, 3, 0], [3, 0, 0], [1, 0, 16], [3, 0, 0]]) == [230, 236, 290, 290]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],queries = [[2, 5, 0], [3, 0, 0], [1, 0, 2], [2, 3, 0], [3, 0, 0], [1, 3, 6], [2, 2, 0], [3, 0, 0], [1, 0, 4], [3, 0, 0]]) == [10000005, 10000026, 10000032, 10000032]\n assert candidate(nums1 = [1, 0, 0, 1, 1, 0, 0, 1],nums2 = [100, 200, 300, 400, 500, 600, 700, 800],queries = [[1, 0, 3], [2, 4, 0], [3, 0, 0], [1, 4, 7], [2, 2, 0], [3, 0, 0]]) == [3616, 3624]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],queries = [[1, 0, 19], [2, 2, 0], [3, 0, 0], [1, 5, 15], [2, 3, 0], [3, 0, 0], [1, 10, 18], [2, 5, 0], [3, 0, 0]]) == [2120, 2147, 2197]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000],queries = [[1, 0, 9], [2, 1000, 0], [3, 0, 0], [1, 0, 4], [2, 500, 0], [3, 0, 0], [1, 5, 9], [2, 300, 0], [3, 0, 0]]) == [55005000, 55007000, 55008500]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[1, 0, 19], [2, 1, 0], [3, 0, 0], [1, 5, 14], [2, 2, 0], [3, 0, 0], [1, 0, 9], [3, 0, 0], [1, 10, 19], [3, 0, 0]]) == [220, 240, 240, 240]\n assert candidate(nums1 = [0, 0, 1, 1, 0, 1, 0, 0, 1, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 2, 5], [2, 3, 0], [3, 0, 0], [1, 1, 8], [2, 5, 0], [3, 0, 0], [1, 0, 9], [2, 1, 0], [3, 0, 0]]) == [556, 586, 590]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[1, 0, 19], [2, 5, 0], [3, 0, 0], [1, 5, 14], [2, 3, 0], [3, 0, 0], [1, 1, 18], [2, 7, 0], [3, 0, 0]]) == [260, 290, 360]\n assert candidate(nums1 = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],queries = [[1, 0, 19], [2, 5, 0], [3, 0, 0], [1, 2, 17], [2, 3, 0], [3, 0, 0], [1, 1, 16], [3, 0, 0], [1, 0, 15], [3, 0, 0], [1, 0, 19], [3, 0, 0]]) == [21050, 21080, 21080, 21080, 21080]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[1, 0, 14], [2, 1, 0], [3, 0, 0], [1, 3, 7], [2, 2, 0], [3, 0, 0], [1, 10, 14], [3, 0, 0]]) == [82, 94, 94]\n assert candidate(nums1 = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 1, 8], [2, 2, 0], [3, 0, 0], [1, 2, 7], [2, 3, 0], [3, 0, 0]]) == [104, 112, 130]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 19], [2, 1, 0], [3, 0, 0], [1, 0, 9], [2, 2, 0], [3, 0, 0], [1, 10, 19], [2, 3, 0], [3, 0, 0]]) == [40, 60, 60]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 0, 9], [3, 0, 0], [1, 0, 9], [3, 0, 0]]) == [20, 20, 20, 20]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[1, 0, 3], [2, 2, 0], [3, 0, 0], [1, 4, 7], [2, 3, 0], [3, 0, 0], [1, 5, 9], [2, 1, 0], [3, 0, 0], [1, 0, 9], [3, 0, 0]]) == [5510, 5525, 5531, 5531]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[2, 10, 0], [3, 0, 0], [1, 0, 4], [2, 5, 0], [3, 0, 0], [1, 5, 9], [2, 3, 0], [3, 0, 0]]) == [5600, 5625, 5625]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 1, 8], [2, 5, 0], [3, 0, 0], [1, 0, 4], [2, 3, 0], [3, 0, 0], [1, 5, 9], [3, 0, 0]]) == [575, 593, 593]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 5, 9], [2, 3, 0], [3, 0, 0]]) == [5510, 5520, 5520]\n assert candidate(nums1 = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[1, 0, 1], [2, 5, 0], [3, 0, 0], [1, 2, 3], [2, 3, 0], [3, 0, 0], [1, 4, 5], [3, 0, 0]]) == [5530, 5542, 5542]\n assert candidate(nums1 = [0, 0, 1, 1, 0, 1, 0, 0, 1, 1],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 0, 9], [2, 2, 0], [3, 0, 0], [1, 1, 5], [2, 3, 0], [3, 0, 0], [1, 2, 4], [2, 1, 0], [3, 0, 0]]) == [560, 578, 583]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 1, 8], [2, 2, 0], [3, 0, 0], [1, 2, 7], [3, 0, 0]]) == [15, 25, 25]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [[1, 0, 9], [2, 5, 0], [3, 0, 0], [1, 1, 8], [2, 3, 0], [3, 0, 0], [1, 0, 4], [3, 0, 0], [1, 5, 9], [3, 0, 0]]) == [300, 315, 315, 315]\n assert candidate(nums1 = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 3, 6], [2, 2, 0], [3, 0, 0], [1, 0, 4], [2, 3, 0], [3, 0, 0]]) == [54, 62, 77]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 1, 8], [2, 2, 0], [3, 0, 0], [1, 2, 7], [2, 3, 0], [3, 0, 0], [1, 0, 9], [2, 1, 0], [3, 0, 0]]) == [15, 25, 40, 45]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],queries = [[1, 0, 14], [2, 15, 0], [3, 0, 0], [1, 3, 7], [2, 2, 0], [3, 0, 0], [1, 10, 14], [3, 0, 0], [1, 0, 14], [2, 1, 0], [3, 0, 0], [1, 6, 10], [2, 3, 0], [3, 0, 0]]) == [12000, 12010, 12010, 12015, 12033]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1000000, 0], [3, 0, 0], [1, 0, 4], [2, 1000000, 0], [3, 0, 0], [1, 5, 9], [2, 1000000, 0], [3, 0, 0]]) == [10, 5000010, 15000010]\n assert candidate(nums1 = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[1, 1, 3], [2, 1, 0], [3, 0, 0], [1, 5, 7], [2, 2, 0], [3, 0, 0], [1, 0, 9], [3, 0, 0]]) == [57, 73, 73]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 1, 8], [2, 2, 0], [3, 0, 0], [1, 2, 7], [2, 3, 0], [3, 0, 0]]) == [280, 290, 305]\n assert candidate(nums1 = [0, 0, 1, 1, 0, 0, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 1, 6], [2, 1, 0], [3, 0, 0], [1, 0, 5], [2, 3, 0], [3, 0, 0], [1, 2, 4], [3, 0, 0], [1, 0, 7], [3, 0, 0]]) == [12, 24, 24, 24]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[1, 0, 0], [2, 15, 0], [3, 0, 0], [1, 1, 1], [2, 14, 0], [3, 0, 0], [1, 2, 2], [3, 0, 0], [1, 3, 3], [3, 0, 0], [1, 4, 4], [3, 0, 0], [1, 5, 5], [3, 0, 0], [1, 6, 6], [3, 0, 0], [1, 7, 7], [3, 0, 0], [1, 8, 8], [3, 0, 0], [1, 9, 9], [3, 0, 0], [1, 10, 10], [3, 0, 0], [1, 11, 11], [3, 0, 0], [1, 12, 12], [3, 0, 0], [1, 13, 13], [3, 0, 0], [1, 14, 14], [3, 0, 0]]) == [135, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [[1, 0, 14], [2, 2, 0], [3, 0, 0], [1, 1, 13], [2, 3, 0], [3, 0, 0], [1, 2, 12], [2, 1, 0], [3, 0, 0], [1, 3, 11], [3, 0, 0], [1, 4, 10], [2, 2, 0], [3, 0, 0]]) == [1214, 1232, 1237, 1237, 1243]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 0, 9], [2, 2, 0], [3, 0, 0], [1, 1, 8], [2, 3, 0], [3, 0, 0], [1, 4, 7], [2, 4, 0], [3, 0, 0]]) == [65, 80, 100]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[1, 0, 9], [2, 2, 0], [3, 0, 0], [1, 1, 8], [2, 4, 0], [3, 0, 0], [1, 2, 7], [2, 6, 0], [3, 0, 0]]) == [120, 140, 170]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 5, 9], [2, 3, 0], [3, 0, 0], [1, 2, 8], [2, 1, 0], [3, 0, 0]]) == [20, 50, 53]\n assert candidate(nums1 = [1, 0, 0, 1, 1, 0, 1, 0, 1, 1],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [[1, 0, 9], [2, 5, 0], [3, 0, 0], [1, 3, 6], [2, 3, 0], [3, 0, 0], [1, 2, 4], [3, 0, 0], [1, 1, 8], [2, 2, 0], [3, 0, 0]]) == [295, 313, 313, 323]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [[1, 0, 4], [2, 2, 0], [3, 0, 0], [1, 5, 9], [2, 3, 0], [3, 0, 0], [1, 2, 6], [2, 1, 0], [3, 0, 0]]) == [283, 298, 304]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 2, 8], [2, 2, 0], [3, 0, 0], [1, 3, 7], [2, 3, 0], [3, 0, 0]]) == [65, 71, 95]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 10, 19], [2, 1, 0], [3, 0, 0], [1, 0, 19], [2, 1, 0], [3, 0, 0]]) == [30, 30, 50]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986, 999985, 999984, 999983, 999982, 999981],queries = [[2, 5, 0], [3, 0, 0], [1, 0, 2], [2, 3, 0], [3, 0, 0], [1, 3, 6], [2, 2, 0], [3, 0, 0], [1, 0, 4], [3, 0, 0], [2, 7, 0], [3, 0, 0]]) == [19999910, 19999961, 19999987, 19999987, 20000113]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [0, 2, 0, 4, 0, 6, 0, 8, 0, 10],queries = [[1, 1, 8], [2, 3, 0], [3, 0, 0], [1, 0, 9], [2, 2, 0], [3, 0, 0]]) == [45, 55]\n assert candidate(nums1 = [0, 1, 1, 0, 1, 0, 1, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8],queries = [[1, 0, 7], [2, 3, 0], [3, 0, 0], [1, 1, 5], [2, 2, 0], [3, 0, 0], [1, 2, 4], [3, 0, 0]]) == [48, 58, 58]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 0, 9], [2, 5, 0], [3, 0, 0], [1, 2, 7], [2, 3, 0], [3, 0, 0], [1, 1, 8], [3, 0, 0]]) == [575, 590, 590]\n assert candidate(nums1 = [0, 1, 1, 0, 1, 1, 0, 1],nums2 = [100, 200, 300, 400, 500, 600, 700, 800],queries = [[1, 1, 6], [2, 150, 0], [3, 0, 0], [1, 2, 5], [2, 100, 0], [3, 0, 0], [1, 0, 7], [3, 0, 0]]) == [4050, 4550, 4550]\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[1, 0, 19], [2, 5, 0], [3, 0, 0], [1, 2, 17], [2, 3, 0], [3, 0, 0], [1, 1, 16], [3, 0, 0], [1, 0, 15], [3, 0, 0]]) == [260, 290, 290, 290]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 0, 9], [2, 5, 0], [3, 0, 0], [1, 2, 7], [2, 2, 0], [3, 0, 0], [1, 1, 8], [2, 3, 0], [3, 0, 0], [1, 3, 6], [3, 0, 0]]) == [550, 562, 568, 568]\n assert candidate(nums1 = [1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0],nums2 = [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],queries = [[1, 0, 29], [2, 30, 0], [3, 0, 0], [1, 0, 10], [2, 10, 0], [3, 0, 0], [1, 5, 25], [2, 20, 0], [3, 0, 0], [1, 10, 20], [2, 15, 0], [3, 0, 0]]) == [945, 1115, 1395, 1680]\n assert candidate(nums1 = [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, 1, 0, 1, 0, 1],nums2 = [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],queries = [[1, 0, 29], [2, 30, 0], [3, 0, 0], [1, 5, 20], [2, 10, 0], [3, 0, 0], [1, 15, 25], [3, 0, 0], [1, 10, 25], [2, 2, 0], [3, 0, 0]]) == [945, 1105, 1105, 1139]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 19], [2, 2, 0], [3, 0, 0], [1, 1, 18], [2, 3, 0], [3, 0, 0], [1, 2, 17], [2, 1, 0], [3, 0, 0], [1, 3, 16], [3, 0, 0], [1, 4, 15], [2, 2, 0], [3, 0, 0], [1, 5, 14], [3, 0, 0], [1, 6, 13], [3, 0, 0], [1, 7, 12], [3, 0, 0], [1, 8, 11], [3, 0, 0], [1, 9, 10], [3, 0, 0]]) == [60, 66, 84, 84, 116, 116, 116, 116, 116, 116]\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 1, 8], [2, 2, 0], [3, 0, 0], [1, 2, 7], [2, 3, 0], [3, 0, 0], [1, 3, 6], [3, 0, 0], [1, 4, 5], [3, 0, 0]]) == [15, 25, 40, 40, 40]\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 9], [2, 1, 0], [3, 0, 0], [1, 2, 8], [2, 2, 0], [3, 0, 0], [1, 0, 4], [3, 0, 0]]) == [20, 26, 26]\n assert candidate(nums1 = [1, 0, 0, 1, 1, 0, 1, 0, 1, 0],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 0, 9], [2, 2, 0], [3, 0, 0], [1, 3, 6], [2, 3, 0], [3, 0, 0], [1, 1, 8], [3, 0, 0]]) == [560, 581, 581]\n", "comparison": "exact"}, "public_tests": ["[1,0,1]\n[0,0,0]\n[[1,1,1],[2,1,0],[3,0,0]]", "[1]\n[5]\n[[2,0,0],[3,0,0]]"], "hints": ["Use the Lazy Segment Tree to process the queries quickly."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "queries"], "leetcode_dataset_entry_point": "Solution().handleQuery", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:33+00:00", "tests_total": 70, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def handle_query(nums1, nums2, queries)", "container": null, "callable": "handle_query", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2570, "task_id": "merge-two-2d-arrays-by-summing-values", "difficulty": "Easy", "problem_description": "You are given two 2D integer arrays nums1 and nums2.\n\n- nums1[i] = [id_i, val_i] indicate that the number with the id id_i has a value equal to val_i.\n- nums2[i] = [id_i, val_i] indicate that the number with the id id_i has a value equal to val_i.\n\nEach array contains unique ids and is sorted in ascending order by id.\n\nMerge the two arrays into one array that is sorted in ascending order by id, respecting the following conditions:\n\n- Only ids that appear in at least one of the two arrays should be included in the resulting array.\n- Each id should be included only once and its value should be the sum of the values of this id in the two arrays. If the id does not exist in one of the two arrays, then assume its value in that array to be 0.\n\nReturn the resulting array. The returned array must be sorted in ascending order by id.\n\nExample 1:\n\nInput: nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]]\nOutput: [[1,6],[2,3],[3,2],[4,6]]\nExplanation: The resulting array contains the following:\n- id = 1, the value of this id is 2 + 4 = 6.\n- id = 2, the value of this id is 3.\n- id = 3, the value of this id is 2.\n- id = 4, the value of this id is 5 + 1 = 6.\n\nExample 2:\n\nInput: nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]]\nOutput: [[1,3],[2,4],[3,6],[4,3],[5,5]]\nExplanation: There are no common ids, so we just include each id with its value in the resulting list.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 200\n- nums1[i].length == nums2[j].length == 2\n- 1 <= id_i, val_i <= 1000\n- Both arrays contain unique ids.\n- Both arrays are in strictly ascending order by id.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [[1, 2], [2, 3], [4, 5]],nums2 = [[1, 4], [3, 2], [4, 1]]) == [(1, 6), (2, 3), (3, 2), (4, 6)]\n assert candidate(nums1 = [[2, 4], [3, 6], [5, 5]],nums2 = [[1, 3], [4, 3]]) == [(1, 3), (2, 4), (3, 6), (4, 3), (5, 5)]\n assert candidate(nums1 = [[1, 5], [2, 3]],nums2 = [[1, 5], [2, 3]]) == [(1, 10), (2, 6)]\n assert candidate(nums1 = [[1, 5]],nums2 = [[2, 3]]) == [(1, 5), (2, 3)]\n assert candidate(nums1 = [[1, 1000], [2, 999], [3, 998]],nums2 = [[4, 997], [5, 996], [6, 995]]) == [(1, 1000), (2, 999), (3, 998), (4, 997), (5, 996), (6, 995)]\n assert candidate(nums1 = [[500, 1000], [600, 900], [700, 800]],nums2 = [[550, 850], [650, 750], [750, 650]]) == [(500, 1000), (550, 850), (600, 900), (650, 750), (700, 800), (750, 650)]\n assert candidate(nums1 = [[1, 2], [3, 4], [5, 6], [7, 8]],nums2 = [[1, 9], [3, 8], [5, 7], [7, 6]]) == [(1, 11), (3, 12), (5, 13), (7, 14)]\n assert candidate(nums1 = [[1, 5], [3, 15], [5, 25], [7, 35]],nums2 = [[2, 10], [4, 20], [6, 30], [8, 40]]) == [(1, 5), (2, 10), (3, 15), (4, 20), (5, 25), (6, 30), (7, 35), (8, 40)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],nums2 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]) == [(1, 11), (2, 22), (3, 33), (4, 44), (5, 55), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]\n assert candidate(nums1 = [[1, 999], [2, 998], [3, 997], [4, 996], [5, 995]],nums2 = [[1, 1]]) == [(1, 1000), (2, 998), (3, 997), (4, 996), (5, 995)]\n assert candidate(nums1 = [[50, 1], [100, 1], [150, 1], [200, 1]],nums2 = [[25, 1], [75, 1], [125, 1], [175, 1], [225, 1]]) == [(25, 1), (50, 1), (75, 1), (100, 1), (125, 1), (150, 1), (175, 1), (200, 1), (225, 1)]\n assert candidate(nums1 = [[1, 50], [2, 50], [3, 50], [4, 50], [5, 50]],nums2 = [[1, 50], [2, 50], [3, 50], [4, 50], [5, 50]]) == [(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)]\n assert candidate(nums1 = [[1, 1000], [2, 999], [3, 998]],nums2 = [[1, 1], [2, 2], [3, 3]]) == [(1, 1001), (2, 1001), (3, 1001)]\n assert candidate(nums1 = [[1, 999]],nums2 = [[2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [(1, 999), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3]],nums2 = [[1, 2], [2, 3], [3, 4]]) == [(1, 3), (2, 5), (3, 7)]\n assert candidate(nums1 = [[1, 1]],nums2 = [[999, 1000], [998, 999], [997, 998], [996, 997], [995, 996]]) == [(1, 1), (995, 996), (996, 997), (997, 998), (998, 999), (999, 1000)]\n assert candidate(nums1 = [[1, 2], [5, 6], [9, 10]],nums2 = [[2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) == [(1, 2), (2, 3), (4, 5), (5, 6), (6, 7), (8, 9), (9, 10), (10, 11)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],nums2 = [[10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18]]) == [(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)]\n assert candidate(nums1 = [[1, 999]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1000), (2, 2), (3, 3), (4, 4), (5, 5)]\n assert candidate(nums1 = [[100, 100], [200, 200], [300, 300]],nums2 = [[101, 101], [201, 201], [301, 301]]) == [(100, 100), (101, 101), (200, 200), (201, 201), (300, 300), (301, 301)]\n assert candidate(nums1 = [[100, 100], [200, 200], [300, 300]],nums2 = [[100, 100], [200, 200], [300, 300]]) == [(100, 200), (200, 400), (300, 600)]\n assert candidate(nums1 = [[10, 20], [30, 40], [50, 60], [70, 80]],nums2 = [[20, 30], [40, 50], [60, 70], [80, 90]]) == [(10, 20), (20, 30), (30, 40), (40, 50), (50, 60), (60, 70), (70, 80), (80, 90)]\n assert candidate(nums1 = [[100, 100], [101, 101], [102, 102], [103, 103], [104, 104]],nums2 = [[99, 99], [100, 1], [101, 1], [102, 1], [103, 1], [104, 1], [105, 99]]) == [(99, 99), (100, 101), (101, 102), (102, 103), (103, 104), (104, 105), (105, 99)]\n assert candidate(nums1 = [[1, 1], [3, 3], [5, 5], [7, 7]],nums2 = [[2, 2], [4, 4], [6, 6], [8, 8]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8)]\n assert candidate(nums1 = [[10, 100], [20, 200], [30, 300]],nums2 = [[5, 50], [15, 150], [25, 250], [35, 350]]) == [(5, 50), (10, 100), (15, 150), (20, 200), (25, 250), (30, 300), (35, 350)]\n assert candidate(nums1 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70]],nums2 = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700]]) == [(1, 110), (2, 220), (3, 330), (4, 440), (5, 550), (6, 660), (7, 770)]\n assert candidate(nums1 = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],nums2 = [[2, 2], [4, 4], [6, 6], [8, 8], [10, 10]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]\n assert candidate(nums1 = [[1, 100], [2, 200], [3, 300]],nums2 = [[1, 900], [2, 800], [3, 700], [4, 600], [5, 500]]) == [(1, 1000), (2, 1000), (3, 1000), (4, 600), (5, 500)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4]],nums2 = [[1, 9], [2, 8], [3, 7], [5, 6], [6, 5]]) == [(1, 10), (2, 10), (3, 10), (4, 4), (5, 6), (6, 5)]\n assert candidate(nums1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],nums2 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]) == [(10, 20), (20, 40), (30, 60), (40, 80), (50, 100)]\n assert candidate(nums1 = [[1, 100], [5, 200], [10, 300]],nums2 = [[2, 150], [5, 250], [8, 350]]) == [(1, 100), (2, 150), (5, 450), (8, 350), (10, 300)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [(1, 6), (2, 6), (3, 6), (4, 6), (5, 6)]\n assert candidate(nums1 = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]],nums2 = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1]]) == [(1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 1), (7, 1)]\n assert candidate(nums1 = [[1, 200], [2, 199], [3, 198], [4, 197], [5, 196]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 201), (2, 201), (3, 201), (4, 201), (5, 201)]\n assert candidate(nums1 = [[1, 500], [100, 150], [200, 250]],nums2 = [[50, 200], [150, 300], [250, 350], [300, 400]]) == [(1, 500), (50, 200), (100, 150), (150, 300), (200, 250), (250, 350), (300, 400)]\n assert candidate(nums1 = [[100, 1], [101, 1], [102, 1], [103, 1], [104, 1]],nums2 = [[105, 1], [106, 1], [107, 1], [108, 1], [109, 1]]) == [(100, 1), (101, 1), (102, 1), (103, 1), (104, 1), (105, 1), (106, 1), (107, 1), (108, 1), (109, 1)]\n assert candidate(nums1 = [[1, 10], [3, 20], [5, 30], [7, 40]],nums2 = [[2, 15], [4, 25], [6, 35], [8, 45]]) == [(1, 10), (2, 15), (3, 20), (4, 25), (5, 30), (6, 35), (7, 40), (8, 45)]\n assert candidate(nums1 = [[1, 10], [3, 20], [5, 30], [7, 40], [9, 50]],nums2 = [[2, 10], [4, 20], [6, 30], [8, 40], [10, 50]]) == [(1, 10), (2, 10), (3, 20), (4, 20), (5, 30), (6, 30), (7, 40), (8, 40), (9, 50), (10, 50)]\n assert candidate(nums1 = [[1, 10], [3, 15], [6, 20]],nums2 = [[2, 5], [3, 10], [7, 30]]) == [(1, 10), (2, 5), (3, 25), (6, 20), (7, 30)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]) == [(1, 11), (2, 22), (3, 33), (4, 44), (5, 55)]\n assert candidate(nums1 = [[1, 10], [2, 20], [3, 30], [4, 40]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [(1, 11), (2, 22), (3, 33), (4, 44), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]\n assert candidate(nums1 = [[50, 100], [150, 200], [250, 300]],nums2 = [[100, 250], [200, 350], [300, 400]]) == [(50, 100), (100, 250), (150, 200), (200, 350), (250, 300), (300, 400)]\n assert candidate(nums1 = [[1, 999], [2, 998], [3, 997]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1000), (2, 1000), (3, 1000), (4, 4), (5, 5)]\n assert candidate(nums1 = [[1, 50], [2, 30], [4, 20]],nums2 = [[1, 20], [2, 50], [3, 40], [5, 60]]) == [(1, 70), (2, 80), (3, 40), (4, 20), (5, 60)]\n assert candidate(nums1 = [[1, 999], [2, 998], [3, 997]],nums2 = [[4, 996], [5, 995], [6, 994]]) == [(1, 999), (2, 998), (3, 997), (4, 996), (5, 995), (6, 994)]\n assert candidate(nums1 = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]],nums2 = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == [(1, 3), (2, 3), (3, 3), (4, 3), (5, 3)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],nums2 = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == [(1, 11), (2, 11), (3, 11), (4, 11), (5, 11), (6, 11), (7, 11), (8, 11), (9, 11), (10, 11)]\n assert candidate(nums1 = [[1, 100], [2, 200], [3, 300]],nums2 = [[2, 250], [3, 350], [4, 400]]) == [(1, 100), (2, 450), (3, 650), (4, 400)]\n assert candidate(nums1 = [[1, 200], [3, 400], [5, 600], [7, 800]],nums2 = [[2, 100], [4, 300], [6, 500], [8, 700]]) == [(1, 200), (2, 100), (3, 400), (4, 300), (5, 600), (6, 500), (7, 800), (8, 700)]\n assert candidate(nums1 = [[1, 100], [2, 200], [3, 300]],nums2 = [[1, 100], [2, 200], [3, 300]]) == [(1, 200), (2, 400), (3, 600)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]\n assert candidate(nums1 = [[5, 50], [10, 100], [15, 150], [20, 200], [25, 250]],nums2 = [[3, 30], [6, 60], [9, 90], [12, 120], [18, 180]]) == [(3, 30), (5, 50), (6, 60), (9, 90), (10, 100), (12, 120), (15, 150), (18, 180), (20, 200), (25, 250)]\n assert candidate(nums1 = [[1, 100], [200, 200]],nums2 = [[50, 50], [150, 150]]) == [(1, 100), (50, 50), (150, 150), (200, 200)]\n assert candidate(nums1 = [[1, 50], [4, 75], [7, 100], [10, 125]],nums2 = [[2, 60], [3, 80], [5, 90], [6, 105], [8, 130], [9, 145]]) == [(1, 50), (2, 60), (3, 80), (4, 75), (5, 90), (6, 105), (7, 100), (8, 130), (9, 145), (10, 125)]\n assert candidate(nums1 = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]],nums2 = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]]) == [(1, 200), (2, 400), (3, 600), (4, 800), (5, 1000), (6, 1200), (7, 1400), (8, 1600), (9, 1800), (10, 2000)]\n assert candidate(nums1 = [[500, 500]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (500, 500)]\n assert candidate(nums1 = [[999, 1000]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (999, 1000)]\n assert candidate(nums1 = [[100, 100], [200, 200], [300, 300], [400, 400]],nums2 = [[150, 150], [250, 250], [350, 350], [450, 450]]) == [(100, 100), (150, 150), (200, 200), (250, 250), (300, 300), (350, 350), (400, 400), (450, 450)]\n assert candidate(nums1 = [[1, 999]],nums2 = [[1, 1]]) == [(1, 1000)]\n assert candidate(nums1 = [[10, 10], [20, 20], [30, 30]],nums2 = [[5, 5], [15, 15], [25, 25], [35, 35]]) == [(5, 5), (10, 10), (15, 15), (20, 20), (25, 25), (30, 30), (35, 35)]\n assert candidate(nums1 = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10)]\n assert candidate(nums1 = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]],nums2 = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5]]) == [(1, 10), (2, 9), (3, 8), (4, 7), (5, 6)]\n assert candidate(nums1 = [[100, 1], [200, 2], [300, 3]],nums2 = [[150, 4], [250, 5], [350, 6]]) == [(100, 1), (150, 4), (200, 2), (250, 5), (300, 3), (350, 6)]\n assert candidate(nums1 = [[1, 500], [100, 500], [1000, 500]],nums2 = [[50, 500], [250, 500], [500, 500], [750, 500]]) == [(1, 500), (50, 500), (100, 500), (250, 500), (500, 500), (750, 500), (1000, 500)]\n assert candidate(nums1 = [[1, 1]],nums2 = [[1, 999], [2, 998], [3, 997], [4, 996], [5, 995]]) == [(1, 1000), (2, 998), (3, 997), (4, 996), (5, 995)]\n assert candidate(nums1 = [[1, 200], [100, 300], [200, 400]],nums2 = [[1, 100], [150, 200], [200, 100]]) == [(1, 300), (100, 300), (150, 200), (200, 500)]\n assert candidate(nums1 = [[100, 200], [102, 202], [104, 204], [106, 206], [108, 208]],nums2 = [[101, 201], [103, 203], [105, 205], [107, 207], [109, 209]]) == [(100, 200), (101, 201), (102, 202), (103, 203), (104, 204), (105, 205), (106, 206), (107, 207), (108, 208), (109, 209)]\n assert candidate(nums1 = [[1, 1], [1000, 1000]],nums2 = [[500, 500], [1000, 500]]) == [(1, 1), (500, 500), (1000, 1500)]\n assert candidate(nums1 = [[5, 1], [10, 10], [15, 15], [20, 20]],nums2 = [[2, 2], [4, 4], [6, 6], [8, 8], [12, 12], [14, 14], [16, 16], [18, 18], [22, 22]]) == [(2, 2), (4, 4), (5, 1), (6, 6), (8, 8), (10, 10), (12, 12), (14, 14), (15, 15), (16, 16), (18, 18), (20, 20), (22, 22)]\n assert candidate(nums1 = [[1, 1000], [1000, 1]],nums2 = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [(1, 1000), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (1000, 1)]\n assert candidate(nums1 = [[1, 1000], [2, 1000], [3, 1000]],nums2 = [[4, 1000], [5, 1000], [6, 1000], [7, 1000], [8, 1000]]) == [(1, 1000), (2, 1000), (3, 1000), (4, 1000), (5, 1000), (6, 1000), (7, 1000), (8, 1000)]\n assert candidate(nums1 = [[1, 100], [3, 150], [5, 200], [7, 250]],nums2 = [[2, 120], [4, 180], [6, 240], [8, 300]]) == [(1, 100), (2, 120), (3, 150), (4, 180), (5, 200), (6, 240), (7, 250), (8, 300)]\n assert candidate(nums1 = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],nums2 = [[100, 10], [200, 20], [300, 30], [400, 40], [500, 50]]) == [(100, 11), (200, 22), (300, 33), (400, 44), (500, 55)]\n assert candidate(nums1 = [[10, 10], [20, 20], [30, 30]],nums2 = [[15, 15], [25, 25], [35, 35]]) == [(10, 10), (15, 15), (20, 20), (25, 25), (30, 30), (35, 35)]\n assert candidate(nums1 = [[1, 1]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 2), (2, 2), (3, 3), (4, 4), (5, 5)]\n assert candidate(nums1 = [[1, 1], [1000, 1000]],nums2 = [[500, 500], [1000, 1000]]) == [(1, 1), (500, 500), (1000, 2000)]\n assert candidate(nums1 = [[10, 100], [20, 200], [30, 300]],nums2 = [[10, 10], [20, 20], [40, 40]]) == [(10, 110), (20, 220), (30, 300), (40, 40)]\n assert candidate(nums1 = [[1, 900], [2, 800], [3, 700], [4, 600], [5, 500]],nums2 = [[6, 400], [7, 300], [8, 200], [9, 100]]) == [(1, 900), (2, 800), (3, 700), (4, 600), (5, 500), (6, 400), (7, 300), (8, 200), (9, 100)]\n assert candidate(nums1 = [[100, 100], [200, 200], [300, 300]],nums2 = [[101, 101], [102, 102], [103, 103], [104, 104], [105, 105]]) == [(100, 100), (101, 101), (102, 102), (103, 103), (104, 104), (105, 105), (200, 200), (300, 300)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[3, 10], [4, 20], [5, 30], [6, 40], [7, 50]]) == [(1, 1), (2, 2), (3, 13), (4, 24), (5, 35), (6, 40), (7, 50)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10)]\n assert candidate(nums1 = [[1, 2], [3, 4], [5, 6]],nums2 = [[2, 3], [4, 5], [6, 7]]) == [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)]\n assert candidate(nums1 = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],nums2 = [[1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2]]) == [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10)]\n assert candidate(nums1 = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],nums2 = [[1, 999]]) == [(1, 1000), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15]]) == [(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)]\n assert candidate(nums1 = [[10, 50], [20, 60], [30, 70]],nums2 = [[5, 10], [15, 20], [25, 30], [35, 40]]) == [(5, 10), (10, 50), (15, 20), (20, 60), (25, 30), (30, 70), (35, 40)]\n assert candidate(nums1 = [[50, 500], [100, 1000]],nums2 = [[25, 250], [75, 750], [125, 1250]]) == [(25, 250), (50, 500), (75, 750), (100, 1000), (125, 1250)]\n assert candidate(nums1 = [[1, 100], [3, 200], [5, 300], [7, 400]],nums2 = [[2, 150], [4, 250], [6, 350], [8, 450]]) == [(1, 100), (2, 150), (3, 200), (4, 250), (5, 300), (6, 350), (7, 400), (8, 450)]\n assert candidate(nums1 = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1001), (2, 1001), (3, 1001), (4, 1001), (5, 1001)]\n assert candidate(nums1 = [[1, 5], [100, 5], [200, 5]],nums2 = [[50, 5], [150, 5], [250, 5], [300, 5], [350, 5]]) == [(1, 5), (50, 5), (100, 5), (150, 5), (200, 5), (250, 5), (300, 5), (350, 5)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],nums2 = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 10), (6, 6), (7, 7), (8, 8), (9, 9)]\n assert candidate(nums1 = [[1, 10], [4, 20], [6, 30]],nums2 = [[2, 15], [4, 25], [5, 35]]) == [(1, 10), (2, 15), (4, 45), (5, 35), (6, 30)]\n assert candidate(nums1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],nums2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10), (6, 12), (7, 14), (8, 16), (9, 18)]\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,3],[4,5]]\n[[1,4],[3,2],[4,1]]", "[[2,4],[3,6],[5,5]]\n[[1,3],[4,3]]"], "hints": ["Use a dictionary/hash map to keep track of the indices and their sum values."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().mergeArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:35+00:00", "tests_total": 93, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers"]}, "language": "ruby", "interface": {"raw_signature": "def merge_arrays(nums1, nums2)", "container": null, "callable": "merge_arrays", "parameters": [{"name": "nums1", "type": "Integer[][]"}, {"name": "nums2", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2571, "task_id": "minimum-operations-to-reduce-an-integer-to-0", "difficulty": "Medium", "problem_description": "You are given a positive integer n, you can do the following operation any number of times:\n\n- Add or subtract a power of 2 from n.\n\nReturn the minimum number of operations to make n equal to 0.\n\nA number x is power of 2 if x == 2^i where i >= 0.\n\nExample 1:\n\nInput: n = 39\nOutput: 3\nExplanation: We can do the following operations:\n- Add 2^0 = 1 to n, so now n = 40.\n- Subtract 2^3 = 8 from n, so now n = 32.\n- Subtract 2^5 = 32 from n, so now n = 0.\nIt can be shown that 3 is the minimum number of operations we need to make n equal to 0.\n\nExample 2:\n\nInput: n = 54\nOutput: 3\nExplanation: We can do the following operations:\n- Add 2^1 = 2 to n, so now n = 56.\n- Add 2^3 = 8 to n, so now n = 64.\n- Subtract 2^6 = 64 from n, so now n = 0.\nSo the minimum number of operations is 3.\n\nConstraints:\n\n- 1 <= n <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 63) == 2\n assert candidate(n = 100) == 3\n assert candidate(n = 50000) == 6\n assert candidate(n = 4) == 1\n assert candidate(n = 64) == 1\n assert candidate(n = 16) == 1\n assert candidate(n = 10000) == 4\n assert candidate(n = 2) == 1\n assert candidate(n = 1024) == 1\n assert candidate(n = 54) == 3\n assert candidate(n = 100000) == 6\n assert candidate(n = 65536) == 1\n assert candidate(n = 32) == 1\n assert candidate(n = 1023) == 2\n assert candidate(n = 39) == 3\n assert candidate(n = 65535) == 2\n assert candidate(n = 15) == 2\n assert candidate(n = 32768) == 1\n assert candidate(n = 31) == 2\n assert candidate(n = 1) == 1\n assert candidate(n = 10) == 2\n assert candidate(n = 65534) == 2\n assert candidate(n = 33333) == 6\n assert candidate(n = 99999) == 7\n assert candidate(n = 8765) == 5\n assert candidate(n = 12345) == 5\n assert candidate(n = 7456) == 4\n assert candidate(n = 77777) == 6\n assert candidate(n = 67890) == 6\n assert candidate(n = 65537) == 2\n assert candidate(n = 32767) == 2\n assert candidate(n = 65533) == 3\n assert candidate(n = 86420) == 7\n assert candidate(n = 19683) == 7\n assert candidate(n = 16383) == 2\n assert candidate(n = 24680) == 5\n assert candidate(n = 16384) == 1\n assert candidate(n = 123) == 3\n assert candidate(n = 10001) == 5\n assert candidate(n = 81920) == 2\n assert candidate(n = 1365) == 6\n assert candidate(n = 32769) == 2\n assert candidate(n = 4095) == 2\n assert candidate(n = 8192) == 1\n assert candidate(n = 999) == 4\n assert candidate(n = 8191) == 2\n assert candidate(n = 7890) == 5\n assert candidate(n = 11001) == 6\n assert candidate(n = 39321) == 8\n assert candidate(n = 13579) == 7\n assert candidate(n = 98765) == 7\n assert candidate(n = 43210) == 7\n assert candidate(n = 54321) == 7\n assert candidate(n = 1536) == 2\n", "comparison": "exact"}, "public_tests": ["39", "54"], "hints": ["Can we set/unset the bits in binary representation?", "If there are multiple adjacent ones, how can we optimally add and subtract in 2 operations such that all ones get unset?", "Bonus: Try to solve the problem with higher constraints: n ≤ 10^18."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:37+00:00", "tests_total": 60, "tests_dropped": 5, "flags": [], "topic_tags": ["dynamic-programming", "greedy", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(n)", "container": null, "callable": "min_operations", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2572, "task_id": "count-the-number-of-square-free-subsets", "difficulty": "Medium", "problem_description": "You are given a positive integer 0-indexed array nums.\n\nA subset of the array nums is square-free if the product of its elements is a square-free integer.\n\nA square-free integer is an integer that is divisible by no square number other than 1.\n\nReturn the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 10^9 + 7.\n\nA non-empty subset of nums is an array that can be obtained by deleting some (possibly none but not all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.\n\nExample 1:\n\nInput: nums = [3,4,4,5]\nOutput: 3\nExplanation: There are 3 square-free subsets in this example:\n- The subset consisting of the 0^th element [3]. The product of its elements is 3, which is a square-free integer.\n- The subset consisting of the 3^rd element [5]. The product of its elements is 5, which is a square-free integer.\n- The subset consisting of 0^th and 3^rd elements [3,5]. The product of its elements is 15, which is a square-free integer.\nIt can be proven that there are no more than 3 square-free subsets in the given array.\n\nExample 2:\n\nInput: nums = [1]\nOutput: 1\nExplanation: There is 1 square-free subset in this example:\n- The subset consisting of the 0^th element [1]. The product of its elements is 1, which is a square-free integer.\nIt can be proven that there is no more than 1 square-free subset in the given array.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 30\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\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]) == 147483633.0\n assert candidate(nums = [2, 3, 5, 7, 11]) == 31.0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 47.0\n assert candidate(nums = [1]) == 1.0\n assert candidate(nums = [30, 30, 30, 30, 30]) == 5.0\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 6655.0\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 10.0\n assert candidate(nums = [2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 3327.0\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 20.0\n assert candidate(nums = [29, 28, 21, 18, 16, 13, 10, 3, 25, 7]) == 39.0\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28]) == 0.0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1023.0\n assert candidate(nums = [4, 9, 16, 25]) == 0.0\n assert candidate(nums = [9, 10, 14, 15, 21, 22, 26, 30]) == 13.0\n assert candidate(nums = [3, 4, 4, 5]) == 3.0\n assert candidate(nums = [4, 8, 12, 16]) == 0.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1023.0\n assert candidate(nums = [1, 2, 3, 6, 7, 10, 14, 15, 21, 22, 26, 30]) == 79.0\n assert candidate(nums = [9, 15, 21, 25, 27, 30]) == 3.0\n assert candidate(nums = [10, 15, 21, 22, 26, 27]) == 10.0\n assert candidate(nums = [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29]) == 59048.0\n assert candidate(nums = [29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 20.0\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30]) == 78.0\n assert candidate(nums = [2, 3, 5, 6, 7, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 7, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 7, 10, 14, 15, 21, 22, 26, 30]) == 1053.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 6015.0\n assert candidate(nums = [4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 78.0\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 118097.0\n assert candidate(nums = [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1048575.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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 949480668.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]) == 73741816.0\n assert candidate(nums = [10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30, 10, 14, 15, 21, 22, 26, 30]) == 440.0\n assert candidate(nums = [2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30]) == 402.0\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30, 1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 691091.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1048575.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 9765624.0\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 4607.0\n assert candidate(nums = [29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 25.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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 6655.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, 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]) == 691091.0\n assert candidate(nums = [30, 21, 15, 10, 6, 3, 2, 1, 1, 2, 3, 6, 10, 15, 21, 30, 1, 1, 2, 3, 6, 10, 15, 21, 30, 1, 1]) == 4287.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 59048.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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 371842543.0\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 80.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]) == 1055.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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 268198251.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, 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]) == 691091.0\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 120.0\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30]) == 128.0\n assert candidate(nums = [2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 26, 29, 30, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 26, 29, 30]) == 172772.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]) == 1048575.0\n assert candidate(nums = [1, 2, 3, 5, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 6143.0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 20.0\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30, 6, 10, 14, 15, 21, 22, 26, 30]) == 190.0\n assert candidate(nums = [2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 3327.0\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 6655.0\n assert candidate(nums = [2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 6, 10, 14, 15, 21, 22, 26, 30]) == 2298.0\n assert candidate(nums = [1, 1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30]) == 13311.0\n", "comparison": "exact"}, "public_tests": ["[3,4,4,5]", "[1]"], "hints": ["There are 10 primes before number 30.", "Label primes from {2, 3, … 29} with {0,1, … 9} and let DP(i, mask) denote the number of subsets before index: i with the subset of taken primes: mask.", "If the mask and prime factorization of nums[i] have a common prime, then it is impossible to add to the current subset, otherwise, it is possible."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().squareFreeSubsets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:39+00:00", "tests_total": 103, "tests_dropped": 46, "flags": [], "topic_tags": ["array", "math", "dynamic-programming", "bit-manipulation", "number-theory", "bitmask"]}, "language": "ruby", "interface": {"raw_signature": "def square_free_subsets(nums)", "container": null, "callable": "square_free_subsets", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2573, "task_id": "find-the-string-with-lcp", "difficulty": "Hard", "problem_description": "We define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that:\n\n- lcp[i][j] is equal to the length of the longest common prefix between the substrings word[i,n-1] and word[j,n-1].\n\nGiven an n x n matrix lcp, return the alphabetically smallest string word that corresponds to lcp. If there is no such string, return an empty string.\n\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, \"aabd\" is lexicographically smaller than \"aaca\" because the first position they differ is at the third letter, and 'b' comes before 'c'.\n\nExample 1:\n\nInput: lcp = [[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]]\nOutput: \"abab\"\nExplanation: lcp corresponds to any 4 letter string with two alternating letters. The lexicographically smallest of them is \"abab\".\n\nExample 2:\n\nInput: lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]]\nOutput: \"aaaa\"\nExplanation: lcp corresponds to any 4 letter string with a single distinct letter. The lexicographically smallest of them is \"aaaa\".\n\nExample 3:\n\nInput: lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]]\nOutput: \"\"\nExplanation: lcp[3][3] cannot be equal to 3 since word[3,...,3] consists of only a single letter; Thus, no answer exists.\n\nConstraints:\n\n- 1 <= n == lcp.length == lcp[i].length <= 1000\n- 0 <= lcp[i][j] <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(lcp = [[4, 3, 2, 1], [3, 3, 2, 1], [2, 2, 2, 1], [1, 1, 1, 3]]) == \"\"\n assert candidate(lcp = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[4, 0, 2, 0], [0, 3, 0, 1], [2, 0, 2, 0], [0, 1, 0, 1]]) == \"abab\"\n assert candidate(lcp = [[4, 3, 2, 1], [3, 3, 2, 1], [2, 2, 2, 1], [1, 1, 1, 1]]) == \"aaaa\"\n assert candidate(lcp = [[2, 1, 0], [1, 2, 0], [0, 0, 1]]) == \"\"\n assert candidate(lcp = [[2, 1], [1, 2]]) == \"\"\n assert candidate(lcp = [[3, 2, 1], [2, 2, 1], [1, 1, 1]]) == \"aaa\"\n assert candidate(lcp = [[3, 2, 2, 1], [2, 3, 2, 1], [2, 2, 3, 1], [1, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[3, 2, 1, 0], [2, 2, 1, 0], [1, 1, 1, 0], [0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 10, 9, 8, 7, 6, 5, 4, 3, 2], [8, 9, 10, 9, 8, 7, 6, 5, 4, 3], [7, 8, 9, 10, 9, 8, 7, 6, 5, 4], [6, 7, 8, 9, 10, 9, 8, 7, 6, 5], [5, 6, 7, 8, 9, 10, 9, 8, 7, 6], [4, 5, 6, 7, 8, 9, 10, 9, 8, 7], [3, 4, 5, 6, 7, 8, 9, 10, 9, 8], [2, 3, 4, 5, 6, 7, 8, 9, 10, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == \"\"\n assert candidate(lcp = [[1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1]]) == \"\"\n assert candidate(lcp = [[5, 1, 1, 1, 1], [1, 4, 2, 2, 2], [1, 2, 3, 1, 1], [1, 2, 1, 3, 1], [1, 2, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[5, 4, 3, 2, 1], [4, 5, 4, 3, 2], [3, 4, 5, 4, 3], [2, 3, 4, 5, 4], [1, 2, 3, 4, 5]]) == \"\"\n assert candidate(lcp = [[6, 5, 4, 3, 2, 1], [5, 5, 4, 3, 2, 1], [4, 4, 4, 3, 2, 1], [3, 3, 3, 6, 5, 4], [2, 2, 2, 5, 5, 4], [1, 1, 1, 4, 4, 4]]) == \"\"\n assert candidate(lcp = [[5, 0, 3, 0, 0], [0, 5, 0, 0, 0], [3, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 0, 0, 0, 2]]) == \"\"\n assert candidate(lcp = [[2, 2, 0, 0], [2, 2, 0, 0], [0, 0, 3, 1], [0, 0, 1, 1]]) == \"\"\n assert candidate(lcp = [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[4, 2, 2, 2, 2], [2, 3, 1, 1, 1], [2, 1, 3, 1, 1], [2, 1, 1, 2, 1], [2, 1, 1, 1, 2]]) == \"\"\n assert candidate(lcp = [[3, 3, 2, 1], [3, 3, 2, 1], [2, 2, 2, 1], [1, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[4, 3, 2, 1], [3, 3, 2, 1], [2, 2, 3, 2], [1, 1, 2, 3]]) == \"\"\n assert candidate(lcp = [[8, 7, 6, 5, 4, 3, 2, 1], [7, 7, 6, 5, 4, 3, 2, 1], [6, 6, 6, 5, 4, 3, 2, 1], [5, 5, 5, 5, 4, 3, 2, 1], [4, 4, 4, 4, 4, 3, 2, 1], [3, 3, 3, 3, 3, 3, 2, 1], [2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == \"aaaaaaaa\"\n assert candidate(lcp = [[10, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 10, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 10, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 10, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 10, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 10, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 10, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]) == \"\"\n assert candidate(lcp = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[3, 1, 1, 0, 0], [1, 3, 2, 0, 0], [1, 2, 3, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]]) == \"\"\n assert candidate(lcp = [[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[5, 0, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0], [0, 0, 0, 5, 0, 0], [0, 0, 0, 0, 5, 0], [0, 0, 0, 0, 0, 5]]) == \"\"\n assert candidate(lcp = [[3, 2, 1, 0, 0], [2, 2, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]]) == \"\"\n assert candidate(lcp = [[5, 0, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 0, 5, 2, 2, 0], [0, 0, 2, 5, 2, 1], [0, 0, 2, 2, 5, 1], [0, 0, 0, 1, 1, 5]]) == \"\"\n assert candidate(lcp = [[2, 2, 2, 0, 0], [2, 2, 2, 0, 0], [2, 2, 2, 0, 0], [0, 0, 0, 3, 2], [0, 0, 0, 2, 3]]) == \"\"\n assert candidate(lcp = [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]) == \"\"\n assert candidate(lcp = [[5, 4, 3, 2, 1], [4, 4, 2, 2, 1], [3, 2, 3, 2, 1], [2, 2, 2, 2, 1], [1, 1, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[0, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 0]]) == \"\"\n assert candidate(lcp = [[2, 1, 0, 0], [1, 2, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[4, 3, 2, 1, 0, 0], [3, 4, 3, 2, 0, 0], [2, 3, 4, 3, 0, 0], [1, 2, 3, 4, 0, 0], [0, 0, 0, 0, 4, 2], [0, 0, 0, 0, 2, 4]]) == \"\"\n assert candidate(lcp = [[3, 2, 2, 1], [2, 2, 2, 1], [2, 2, 2, 1], [1, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[5, 2, 2, 2, 2], [2, 3, 2, 1, 1], [2, 2, 3, 2, 2], [2, 1, 2, 3, 2], [2, 1, 2, 2, 3]]) == \"\"\n assert candidate(lcp = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 0]]) == \"\"\n assert candidate(lcp = [[7, 0, 0, 0, 0, 0, 0], [0, 3, 2, 1, 0, 0, 0], [0, 2, 3, 2, 0, 0, 0], [0, 1, 2, 3, 0, 0, 0], [0, 0, 0, 0, 5, 4, 3], [0, 0, 0, 0, 4, 5, 4], [0, 0, 0, 0, 3, 4, 5]]) == \"\"\n assert candidate(lcp = [[5, 4, 3, 2, 1], [4, 4, 3, 2, 1], [3, 3, 3, 2, 1], [2, 2, 2, 2, 1], [1, 1, 1, 1, 1]]) == \"aaaaa\"\n assert candidate(lcp = [[5, 3, 3, 3, 3], [3, 4, 2, 2, 2], [3, 2, 3, 2, 2], [3, 2, 2, 3, 2], [3, 2, 2, 2, 3]]) == \"\"\n assert candidate(lcp = [[6, 5, 4, 3, 2, 1], [5, 5, 4, 3, 2, 1], [4, 4, 4, 3, 2, 1], [3, 3, 3, 3, 2, 1], [2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1]]) == \"aaaaaa\"\n assert candidate(lcp = [[5, 4, 3, 2, 1, 0], [4, 4, 3, 2, 1, 0], [3, 3, 3, 2, 1, 0], [2, 2, 2, 2, 1, 0], [1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[3, 2, 1, 0, 0], [2, 3, 2, 1, 0], [1, 2, 3, 2, 1], [0, 1, 2, 3, 2], [0, 0, 1, 2, 3]]) == \"\"\n assert candidate(lcp = [[3, 1, 0, 0, 0], [1, 3, 0, 0, 0], [0, 0, 2, 1, 1], [0, 0, 1, 2, 1], [0, 0, 1, 1, 2]]) == \"\"\n assert candidate(lcp = [[6, 0, 0, 0, 0, 0], [0, 5, 4, 3, 2, 1], [0, 4, 4, 3, 2, 1], [0, 3, 3, 3, 2, 1], [0, 2, 2, 2, 2, 1], [0, 1, 1, 1, 1, 1]]) == \"abbbbb\"\n assert candidate(lcp = [[4, 0, 2, 0, 0, 0], [0, 4, 0, 2, 0, 0], [2, 0, 4, 0, 2, 0], [0, 2, 0, 4, 0, 2], [0, 0, 2, 0, 4, 0], [0, 0, 0, 2, 0, 4]]) == \"\"\n assert candidate(lcp = [[3, 2, 2, 0, 0], [2, 3, 2, 0, 0], [2, 2, 3, 1, 0], [0, 0, 1, 3, 1], [0, 0, 0, 1, 3]]) == \"\"\n assert candidate(lcp = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 9, 8, 7, 6, 5, 4, 3, 2, 1], [8, 8, 8, 7, 6, 5, 4, 3, 2, 1], [7, 7, 7, 7, 6, 5, 4, 3, 2, 1], [6, 6, 6, 6, 6, 5, 4, 3, 2, 1], [5, 5, 5, 5, 5, 5, 4, 3, 2, 1], [4, 4, 4, 4, 4, 4, 4, 3, 2, 1], [3, 3, 3, 3, 3, 3, 3, 3, 2, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == \"aaaaaaaaaa\"\n assert candidate(lcp = [[4, 2, 0, 0], [2, 4, 0, 0], [0, 0, 3, 0], [0, 0, 0, 3]]) == \"\"\n assert candidate(lcp = [[2, 0, 0, 0, 0], [0, 2, 2, 0, 0], [0, 2, 2, 0, 0], [0, 0, 0, 2, 0], [0, 0, 0, 0, 2]]) == \"\"\n assert candidate(lcp = [[3, 2, 2, 2], [2, 3, 2, 2], [2, 2, 3, 2], [2, 2, 2, 3]]) == \"\"\n assert candidate(lcp = [[5, 3, 2, 1, 0], [3, 5, 3, 2, 1], [2, 3, 5, 3, 2], [1, 2, 3, 5, 3], [0, 1, 2, 3, 5]]) == \"\"\n assert candidate(lcp = [[8, 0, 0, 0, 0, 0, 0, 0], [0, 7, 6, 5, 4, 3, 2, 1], [0, 6, 6, 5, 4, 3, 2, 1], [0, 5, 5, 5, 4, 3, 2, 1], [0, 4, 4, 4, 4, 3, 2, 1], [0, 3, 3, 3, 3, 3, 2, 1], [0, 2, 2, 2, 2, 2, 2, 1], [0, 1, 1, 1, 1, 1, 1, 1]]) == \"abbbbbbb\"\n assert candidate(lcp = [[7, 3, 2, 0, 0, 0, 0], [3, 7, 3, 0, 0, 0, 0], [2, 3, 7, 0, 0, 0, 0], [0, 0, 0, 3, 2, 0, 0], [0, 0, 0, 2, 3, 0, 0], [0, 0, 0, 0, 0, 3, 2], [0, 0, 0, 0, 0, 2, 3]]) == \"\"\n assert candidate(lcp = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == \"\"\n assert candidate(lcp = [[5, 4, 0, 0, 0], [4, 5, 0, 0, 0], [0, 0, 5, 4, 3], [0, 0, 4, 5, 4], [0, 0, 3, 4, 5]]) == \"\"\n assert candidate(lcp = [[9, 1, 1, 1, 1, 1, 1, 1, 1], [1, 9, 1, 1, 1, 1, 1, 1, 1], [1, 1, 9, 1, 1, 1, 1, 1, 1], [1, 1, 1, 9, 1, 1, 1, 1, 1], [1, 1, 1, 1, 9, 1, 1, 1, 1], [1, 1, 1, 1, 1, 9, 1, 1, 1], [1, 1, 1, 1, 1, 1, 9, 1, 1], [1, 1, 1, 1, 1, 1, 1, 9, 1], [1, 1, 1, 1, 1, 1, 1, 1, 9]]) == \"\"\n assert candidate(lcp = [[7, 0, 0, 0, 0, 0, 0], [0, 4, 3, 2, 1, 0, 0], [0, 3, 4, 3, 2, 1, 0], [0, 2, 3, 4, 3, 2, 1], [0, 1, 2, 3, 4, 3, 2], [0, 0, 1, 2, 3, 4, 3], [0, 0, 0, 1, 2, 3, 4]]) == \"\"\n assert candidate(lcp = [[10, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 7, 6, 5, 4, 3, 2, 1, 0, 0], [0, 6, 6, 5, 4, 3, 2, 1, 0, 0], [0, 5, 5, 5, 4, 3, 2, 1, 0, 0], [0, 4, 4, 4, 4, 3, 2, 1, 0, 0], [0, 3, 3, 3, 3, 3, 2, 1, 0, 0], [0, 2, 2, 2, 2, 2, 2, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 6, 5], [0, 0, 0, 0, 0, 0, 0, 0, 5, 6]]) == \"\"\n assert candidate(lcp = [[7, 1, 1, 1, 1, 1, 1], [1, 6, 1, 1, 1, 1, 1], [1, 1, 6, 1, 1, 1, 1], [1, 1, 1, 6, 1, 1, 1], [1, 1, 1, 1, 6, 1, 1], [1, 1, 1, 1, 1, 6, 1], [1, 1, 1, 1, 1, 1, 6]]) == \"\"\n assert candidate(lcp = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [8, 8, 7, 6, 5, 4, 3, 2, 1], [7, 7, 7, 6, 5, 4, 3, 2, 1], [6, 6, 6, 6, 5, 4, 3, 2, 1], [5, 5, 5, 5, 5, 4, 3, 2, 1], [4, 4, 4, 4, 4, 4, 3, 2, 1], [3, 3, 3, 3, 3, 3, 3, 2, 1], [2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == \"aaaaaaaaa\"\n assert candidate(lcp = [[4, 3, 2, 1, 0], [3, 3, 2, 1, 0], [2, 2, 2, 1, 0], [1, 1, 1, 1, 0], [0, 0, 0, 0, 1]]) == \"\"\n assert candidate(lcp = [[4, 3, 2, 1, 0], [3, 3, 2, 1, 0], [2, 2, 3, 2, 1], [1, 1, 2, 3, 2], [0, 0, 1, 2, 4]]) == \"\"\n assert candidate(lcp = [[4, 1, 0, 0], [1, 4, 1, 0], [0, 1, 4, 1], [0, 0, 1, 4]]) == \"\"\n assert candidate(lcp = [[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, 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], [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, 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]]) == \"\"\n assert candidate(lcp = [[7, 6, 5, 4, 3, 2, 1], [6, 6, 5, 4, 3, 2, 1], [5, 5, 5, 4, 3, 2, 1], [4, 4, 4, 4, 3, 2, 1], [3, 3, 3, 3, 3, 2, 1], [2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]]) == \"aaaaaaa\"\n assert candidate(lcp = [[7, 1, 0, 0, 0, 0, 0], [1, 7, 1, 0, 0, 0, 0], [0, 1, 7, 1, 0, 0, 0], [0, 0, 1, 7, 1, 0, 0], [0, 0, 0, 1, 7, 1, 0], [0, 0, 0, 0, 1, 7, 1], [0, 0, 0, 0, 0, 1, 7]]) == \"\"\n assert candidate(lcp = [[5, 0, 2, 0, 0], [0, 3, 0, 2, 0], [2, 0, 3, 0, 1], [0, 2, 0, 2, 0], [0, 0, 1, 0, 1]]) == \"\"\n assert candidate(lcp = [[2, 1, 0, 0], [1, 2, 1, 0], [0, 1, 2, 1], [0, 0, 1, 2]]) == \"\"\n assert candidate(lcp = [[5, 0, 0, 0, 0], [0, 3, 0, 0, 0], [0, 0, 2, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 5]]) == \"\"\n", "comparison": "exact"}, "public_tests": ["[[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]]", "[[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]]", "[[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]]"], "hints": ["Use the LCP array to determine which groups of elements must be equal.", "Match the smallest letter to the group that contains the smallest unassigned index.", "Build the LCP matrix of the resulting string then check if it is equal to the target LCP."], "metadata": {"canonical_parameter_names": ["lcp"], "leetcode_dataset_entry_point": "Solution().findTheString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:42+00:00", "tests_total": 75, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "string", "dynamic-programming", "greedy", "union-find", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def find_the_string(lcp)", "container": null, "callable": "find_the_string", "parameters": [{"name": "lcp", "type": "Integer[][]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2574, "task_id": "left-and-right-sum-differences", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums of size n.\n\nDefine two arrays leftSum and rightSum where:\n\n- leftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.\n- rightSum[i] is the sum of elements to the right of the index i in the array nums. If there is no such element, rightSum[i] = 0.\n\nReturn an integer array answer of size n where answer[i] = |leftSum[i] - rightSum[i]|.\n\nExample 1:\n\nInput: nums = [10,4,8,3]\nOutput: [15,1,11,22]\nExplanation: The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0].\nThe array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].\n\nExample 2:\n\nInput: nums = [1]\nOutput: [0]\nExplanation: The array leftSum is [0] and the array rightSum is [0].\nThe array answer is [|0 - 0|] = [0].\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == [10, 1, 6, 11, 14]\n assert candidate(nums = [1]) == [0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [54, 51, 46, 39, 30, 19, 6, 9, 26, 45]\n assert candidate(nums = [10, 20, 30]) == [50, 20, 30]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [9, 7, 5, 3, 1, 1, 3, 5, 7, 9]\n assert candidate(nums = [100000, 100000, 100000]) == [200000, 0, 200000]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [9, 7, 5, 3, 1, 1, 3, 5, 7, 9]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [540, 510, 460, 390, 300, 190, 60, 90, 260, 450]\n assert candidate(nums = [1, 1, 1, 1, 1]) == [4, 2, 0, 2, 4]\n assert candidate(nums = [1, 2]) == [2, 1]\n assert candidate(nums = [100000, 1, 1, 1]) == [3, 99998, 100000, 100002]\n assert candidate(nums = [1000, 1000, 1000, 1000]) == [3000, 1000, 1000, 3000]\n assert candidate(nums = [5, 5, 5, 5]) == [15, 5, 5, 15]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [14, 11, 6, 1, 10]\n assert candidate(nums = [100000, 100000, 100000]) == [200000, 0, 200000]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == [400000, 200000, 0, 200000, 400000]\n assert candidate(nums = [10, 4, 8, 3]) == [15, 1, 11, 22]\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1]) == [400005, 300004, 200003, 100002, 1, 100000, 200001, 300002, 400003, 500004]\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [196, 140, 88, 40, 4, 44, 80, 112, 140, 164, 184, 200, 212, 220, 224]\n assert candidate(nums = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [361, 285, 213, 145, 81, 21, 35, 87, 135, 179, 219, 255, 287, 315, 339, 359, 375, 387, 395, 399]\n assert candidate(nums = [99999, 1, 99999, 1, 99999, 1, 99999]) == [300000, 200000, 100000, 0, 100000, 200000, 300000]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [1045, 1030, 1005, 970, 925, 870, 805, 730, 645, 550, 445, 330, 205, 70, 75, 230, 395, 570, 755, 950]\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == [450000, 260000, 90000, 60000, 190000, 300000, 390000, 460000, 510000, 540000]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3, 1]) == [99994, 50006, 125006, 162506, 181256, 190631, 195318, 197661, 198832, 199417, 199709, 199854, 199926, 199962, 199980, 199989, 199993]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == [11900, 11600, 11100, 10400, 9500, 8400, 7100, 5600, 3900, 2000, 100, 2400, 4900, 7600, 10500]\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]) == [607, 604, 599, 591, 578, 557, 523, 468, 379, 235, 2, 375]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300]) == [9000, 8700, 8200, 7500, 6600, 5500, 4200, 2700, 1000, 900, 3000, 5300, 7800]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [5400, 5100, 4600, 3900, 3000, 1900, 600, 900, 2600, 4500]\n assert candidate(nums = [100, 100, 200, 200, 300, 300, 400, 400, 500, 500, 600, 600, 700, 700, 800, 800, 900, 900, 1000, 1000]) == [10900, 10700, 10400, 10000, 9500, 8900, 8200, 7400, 6500, 5500, 4400, 3200, 1900, 500, 1000, 2600, 4300, 6100, 8000, 10000]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [1022, 1019, 1013, 1001, 977, 929, 833, 641, 257, 511]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [270, 255, 230, 195, 150, 95, 30, 45, 130, 225]\n assert candidate(nums = [10, 4, 8, 3, 7, 2, 5, 6, 9, 1]) == [45, 31, 19, 8, 2, 11, 18, 29, 44, 54]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [600, 580, 540, 480, 400, 300, 180, 40, 120, 300, 500]\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985]) == [1399881, 1199884, 999889, 799896, 599905, 399916, 199929, 56, 200039, 400020, 599999, 799976, 999951, 1199924, 1399895]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [399, 395, 387, 375, 359, 339, 315, 287, 255, 219, 179, 135, 87, 35, 21, 81, 145, 213, 285, 361]\n assert candidate(nums = [100000, 10000, 1000, 100, 10, 1]) == [11111, 98889, 109889, 110989, 111099, 111110]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [95, 85, 75, 65, 55, 45, 35, 25, 15, 5, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == [9900, 9600, 9100, 8400, 7500, 6400, 5100, 3600, 1900, 0, 1900, 3600, 5100, 6400, 7500, 8400, 9100, 9600, 9900]\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == [450000, 350000, 250000, 150000, 50000, 50000, 150000, 250000, 350000, 450000]\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]) == [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [45, 26, 9, 6, 19, 30, 39, 46, 51, 54]\n assert candidate(nums = [210, 190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1]) == [1330, 930, 569, 245, 44, 300, 525, 721, 890, 1034, 1155, 1255, 1336, 1400, 1449, 1485, 1510, 1526, 1535, 1539]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [190, 151, 114, 79, 46, 15, 14, 41, 66, 89, 110, 129, 146, 161, 174, 185, 194, 201, 206, 209]\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]) == [2320, 2305, 2280, 2245, 2200, 2145, 2080, 2005, 1920, 1825, 1720, 1605, 1480, 1345, 1200, 1045, 880, 705, 520, 325, 120, 95, 320, 555, 800, 1055, 1320, 1595, 1880, 2175]\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025]) == [196415, 196412, 196407, 196399, 196386, 196365, 196331, 196276, 196187, 196043, 195810, 195433, 194823, 193836, 192239, 189655, 185474, 178709, 167763, 150052, 121395, 75027, 2, 121391]\n assert candidate(nums = [12345, 67890, 54321, 98765, 43210, 87654, 32109, 76543, 21098, 65432]) == [547022, 466787, 344576, 191490, 49515, 81349, 201112, 309764, 407405, 493935]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == [900000, 700000, 500000, 300000, 100000, 100000, 300000, 500000, 700000, 900000]\n assert candidate(nums = [99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1]) == [400001, 300001, 200001, 100001, 1, 99999, 199999, 299999, 399999, 499999]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [36, 19, 4, 9, 20, 29, 36, 41, 44]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == [24, 21, 16, 9, 0, 9, 16, 21, 24]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [2046, 2043, 2037, 2025, 2001, 1953, 1857, 1665, 1281, 513, 1023]\n assert candidate(nums = [20000, 10000, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 2, 1]) == [19995, 10005, 25005, 32505, 36255, 38130, 39067, 39535, 39769, 39886, 39944, 39972, 39985, 39991, 39994]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [105, 76, 49, 24, 1, 20, 39, 56, 71, 84, 95, 104, 111, 116, 119]\n assert candidate(nums = [5, 4, 3, 2, 1]) == [10, 1, 6, 11, 14]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [119, 116, 111, 104, 95, 84, 71, 56, 39, 20, 1, 24, 49, 76, 105]\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == [1400, 1100, 800, 500, 200, 100, 400, 700, 1000, 1300]\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]) == [66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 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, 62, 64, 66]\n assert candidate(nums = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999]) == [899991, 699993, 499995, 299997, 99999, 99999, 299997, 499995, 699993, 899991]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [990, 960, 910, 840, 750, 640, 510, 360, 190, 0, 190, 360, 510, 640, 750, 840, 910, 960, 990]\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10]) == [240, 210, 160, 90, 0, 90, 160, 210, 240]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [224, 220, 212, 200, 184, 164, 140, 112, 80, 44, 4, 40, 88, 140, 196]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == [2090, 2060, 2010, 1940, 1850, 1740, 1610, 1460, 1290, 1100, 890, 660, 410, 140, 150, 460, 790, 1140, 1510, 1900]\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == [1539, 1535, 1526, 1510, 1485, 1449, 1400, 1336, 1255, 1155, 1034, 890, 721, 525, 300, 44, 245, 569, 930, 1330]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [99999, 1, 99999, 2, 99999, 3, 99999, 4, 99999, 5]) == [400011, 300011, 200011, 100010, 9, 99993, 199995, 299998, 400001, 500005]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [70, 60, 50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50, 60, 70]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [495, 475, 435, 375, 295, 195, 75, 65, 225, 405]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == [950, 850, 750, 650, 550, 450, 350, 250, 150, 50, 50, 150, 250, 350, 450, 550, 650, 750, 850, 950]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [209, 206, 201, 194, 185, 174, 161, 146, 129, 110, 89, 66, 41, 14, 15, 46, 79, 114, 151, 190]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == [54000, 51000, 46000, 39000, 30000, 19000, 6000, 9000, 26000, 45000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [1190, 1160, 1110, 1040, 950, 840, 710, 560, 390, 200, 10, 240, 490, 760, 1050]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 10000, 1000, 100, 10]) == [122220, 122209, 122099, 120999, 109999, 1, 110001, 121001, 122101, 122211]\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 3, 2, 1, 1, 2, 3, 5, 10, 20, 30, 40, 50]) == [272, 182, 112, 62, 32, 17, 9, 4, 1, 1, 4, 9, 17, 32, 62, 112, 182, 272]\n assert candidate(nums = [100000, 100000, 100000, 100000]) == [300000, 100000, 100000, 300000]\n assert candidate(nums = [1000, 500, 250, 125, 63, 31, 15, 7, 3, 1]) == [995, 505, 1255, 1630, 1818, 1912, 1958, 1980, 1990, 1994]\n assert candidate(nums = [1, 2, 3]) == [5, 2, 3]\n assert candidate(nums = [8, 8, 8, 8, 8]) == [32, 16, 0, 16, 32]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == [6, 4, 2, 0, 2, 4, 6]\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995]) == [399986, 199989, 6, 199999, 399990]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == [399990, 199991, 6, 200001, 399994]\n assert candidate(nums = [100000, 100000, 100000, 100000]) == [300000, 100000, 100000, 300000]\n assert candidate(nums = [1000, 2000, 3000]) == [5000, 2000, 3000]\n assert candidate(nums = [5, 10, 15, 20, 25, 30]) == [100, 85, 60, 25, 20, 75]\n assert candidate(nums = [3, 2, 1]) == [3, 2, 5]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [140, 110, 60, 10, 100]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [14, 11, 6, 1, 10]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == [400000, 200000, 0, 200000, 400000]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [45, 26, 9, 6, 19, 30, 39, 46, 51, 54]\n assert candidate(nums = [100000, 1, 1, 1, 1]) == [4, 99997, 99999, 100001, 100003]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [36, 19, 4, 9, 20, 29, 36, 41, 44]\n assert candidate(nums = [5, 6, 7, 8, 9]) == [30, 19, 6, 9, 26]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [140, 110, 60, 10, 100]\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == [5, 3, 1, 1, 3, 5]\n assert candidate(nums = [5, 5, 5, 5, 5]) == [20, 10, 0, 10, 20]\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000]) == [4000, 2000, 0, 2000, 4000]\n assert candidate(nums = [9, 7, 5, 3, 1]) == [16, 0, 12, 20, 24]\n assert candidate(nums = [1, 1, 1, 1, 1]) == [4, 2, 0, 2, 4]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == [440, 410, 360, 290, 200, 90, 40, 190, 360]\n assert candidate(nums = [2, 3, 2, 4, 3, 2, 3, 4]) == [21, 16, 11, 5, 2, 7, 12, 19]\n assert candidate(nums = [5, 10]) == [10, 5]\n assert candidate(nums = [100, 200, 300, 400, 500]) == [1400, 1100, 600, 100, 1000]\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == [899946, 699949, 499954, 299961, 99970, 100019, 300006, 499991, 699974, 899955]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [54, 51, 46, 39, 30, 19, 6, 9, 26, 45]\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == [4500, 2600, 900, 600, 1900, 3000, 3900, 4600, 5100, 5400]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [540, 510, 460, 390, 300, 190, 60, 90, 260, 450]\n assert candidate(nums = [30, 25, 20, 15, 10, 5]) == [75, 20, 25, 60, 85, 100]\n assert candidate(nums = [1, 2]) == [2, 1]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == [99803, 50197, 125197, 162697, 181447, 190822, 195509, 197852, 199023, 199608]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250]) == [93750, 56250, 131250, 168750, 187500]\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == [200, 170, 120, 50, 40, 150]\n assert candidate(nums = [10, 4, 8, 3]) == [15, 1, 11, 22]\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == [25, 15, 5, 5, 15, 25]\n assert candidate(nums = [7, 1, 3, 4, 1]) == [9, 1, 3, 10, 15]\n assert candidate(nums = [50, 40, 30, 20, 10]) == [100, 10, 60, 110, 140]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [99, 95, 87, 75, 59, 39, 15, 13, 45, 81]\n assert candidate(nums = [100, 200, 300, 400, 500]) == [1400, 1100, 600, 100, 1000]\n assert candidate(nums = [5]) == [0]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000]) == [14000, 11000, 6000, 1000, 10000]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [450, 260, 90, 60, 190, 300, 390, 460, 510, 540]\n assert candidate(nums = [7, 1, 3, 4, 1, 5]) == [14, 6, 2, 5, 10, 16]\n assert candidate(nums = [500, 400, 300, 200, 100]) == [1000, 100, 600, 1100, 1400]\n", "comparison": "exact"}, "public_tests": ["[10,4,8,3]", "[1]"], "hints": ["For each index i, maintain two variables leftSum and rightSum.", "Iterate on the range j: [0 … i - 1] and add nums[j] to the leftSum and similarly iterate on the range j: [i + 1 … nums.length - 1] and add nums[j] to the rightSum."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().leftRightDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:44+00:00", "tests_total": 131, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def left_right_difference(nums)", "container": null, "callable": "left_right_difference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2576, "task_id": "find-the-maximum-number-of-marked-indices", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums.\n\nInitially, all of the indices are unmarked. You are allowed to make this operation any number of times:\n\n- Pick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark i and j.\n\nReturn the maximum possible number of marked indices in nums using the above operation any number of times.\n\nExample 1:\n\nInput: nums = [3,5,2,4]\nOutput: 2\nExplanation: In the first operation: pick i = 2 and j = 1, the operation is allowed because 2 * nums[2] <= nums[1]. Then mark index 2 and 1.\nIt can be shown that there's no other valid operation so the answer is 2.\n\nExample 2:\n\nInput: nums = [9,2,5,4]\nOutput: 4\nExplanation: In the first operation: pick i = 3 and j = 0, the operation is allowed because 2 * nums[3] <= nums[0]. Then mark index 3 and 0.\nIn the second operation: pick i = 1 and j = 2, the operation is allowed because 2 * nums[1] <= nums[2]. Then mark index 1 and 2.\nSince there is no other operation, the answer is 4.\n\nExample 3:\n\nInput: nums = [7,6,8]\nOutput: 0\nExplanation: There is no valid operation to do, so the answer is 0.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 6\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 10\n assert candidate(nums = [7, 6, 8]) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [5, 10, 20, 25, 30, 35, 40, 45, 50]) == 8\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [5, 5, 5, 10, 10, 10, 15, 15, 15, 20, 20, 20]) == 12\n assert candidate(nums = [10, 20, 30, 40, 50]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [3, 5, 2, 4]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [5, 10, 20, 40, 80, 160]) == 6\n assert candidate(nums = [9, 2, 5, 4]) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 16\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 14\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]) == 20\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\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]) == 26\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 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]) == 40\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 20\n assert candidate(nums = [1, 2, 3, 6, 12, 24, 48, 96]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 6, 6, 12, 12]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 18\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128]) == 16\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721]) == 16\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864]) == 20\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800]) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 14\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 440, 480, 520, 560, 600, 640, 680, 720, 760, 800, 880, 960, 1040, 1120, 1200]) == 56\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]) == 30\n assert candidate(nums = [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]) == 30\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180, 189, 198, 207, 216, 225, 234, 243, 252, 261, 270]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 30\n assert candidate(nums = [2, 5, 7, 8, 10, 13, 15, 16, 19, 20, 22, 23, 25, 27, 28, 30, 32, 33, 35, 37, 38, 40, 41, 43, 45, 46, 48, 50]) == 26\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]) == 24\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) == 6\n assert candidate(nums = [1000000000, 900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000]) == 10\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 18\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]) == 32\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040]) == 28\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 14\n assert candidate(nums = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480, 40960, 81920, 163840, 327680, 655360, 1310720, 2621440, 5242880, 10485760, 20971520, 41943040, 83886080, 167772160, 335544320, 671088640]) == 28\n assert candidate(nums = [1, 2, 3, 6, 12, 24, 48, 96, 192]) == 8\n assert candidate(nums = [2, 4, 4, 8, 8, 8, 16, 16, 16, 16, 32, 32, 32, 32, 32]) == 14\n assert candidate(nums = [50, 25, 10, 5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 24\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]) == 24\n assert candidate(nums = [1, 3, 5, 15, 25, 45, 75, 105, 150, 225, 300, 450, 600]) == 12\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]) == 12\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 20\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 14\n assert candidate(nums = [1, 4, 5, 6, 8, 10, 12, 15, 16, 18, 20, 22, 25, 28, 30]) == 14\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 14\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164, 175, 186, 197, 208]) == 18\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]) == 20\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 107, 113, 119]) == 20\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144]) == 18\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 20\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 16\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500]) == 24\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 10\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 10\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]) == 30\n assert candidate(nums = [1, 2, 3, 6, 9, 12, 18, 27, 36, 54, 81, 108, 162, 243, 324, 486, 729, 972, 1458, 2187, 2916, 4374, 6561, 8748, 13122, 19683, 26244, 39366, 59049, 78732, 118098, 177147, 236196, 354294, 531441, 708588, 1062882]) == 36\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 18\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10]) == 22\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 14\n assert candidate(nums = [1, 3, 3, 7, 10, 15, 20, 25, 30, 40, 50, 60]) == 12\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 28\n assert candidate(nums = [10, 10, 10, 20, 20, 20, 30, 30, 30, 40, 40, 40, 50, 50, 50]) == 12\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]) == 30\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 20\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]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 12\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [9, 4, 2, 18, 3, 12, 6, 24, 8, 48]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90]) == 30\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 20\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 20\n assert candidate(nums = [1, 5, 10, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170]) == 20\n assert candidate(nums = [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]) == 24\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147]) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 20\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135]) == 14\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584, 7168, 14336, 28672, 57344, 114688, 229376, 458752, 917504, 1835008, 3670016]) == 20\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304]) == 22\n assert candidate(nums = [3, 5, 2, 4, 8, 16, 32, 64]) == 8\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969]) == 14\n assert candidate(nums = [1, 3, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200]) == 20\n assert candidate(nums = [10, 25, 30, 50, 60, 100, 120, 150, 200, 300]) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]) == 16\n assert candidate(nums = [1, 2, 3, 6, 9, 12, 18, 24, 36, 48]) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]) == 12\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]) == 20\n assert candidate(nums = [3, 3, 6, 6, 12, 12, 24, 24, 48, 48, 96, 96]) == 12\n", "comparison": "exact"}, "public_tests": ["[3,5,2,4]", "[9,2,5,4]", "[7,6,8]"], "hints": ["Think about how to check that performing k operations is possible.", "To perform k operations, it’s optimal to use the smallest k elements and the largest k elements and think about how to match them.", "It’s optimal to match the ith smallest number with the k-i + 1 largest number.", "Now we need to binary search on the answer and find the greatest possible valid k."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxNumOfMarkedIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:49+00:00", "tests_total": 119, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_num_of_marked_indices(nums)", "container": null, "callable": "max_num_of_marked_indices", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2577, "task_id": "minimum-time-to-visit-a-cell-in-a-grid", "difficulty": "Hard", "problem_description": "You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which means you can visit the cell (row, col) only when the time you visit it is greater than or equal to grid[row][col].\n\nYou are standing in the top-left cell of the matrix in the 0^th second, and you must move to any adjacent cell in the four directions: up, down, left, and right. Each move you make takes 1 second.\n\nReturn the minimum time required in which you can visit the bottom-right cell of the matrix. If you cannot visit the bottom-right cell, then return -1.\n\nExample 1:\n\nInput: grid = [[0,1,3,2],[5,1,2,5],[4,3,8,6]]\nOutput: 7\nExplanation: One of the paths that we can take is the following:\n- at t = 0, we are on the cell (0,0).\n- at t = 1, we move to the cell (0,1). It is possible because grid[0][1] <= 1.\n- at t = 2, we move to the cell (1,1). It is possible because grid[1][1] <= 2.\n- at t = 3, we move to the cell (1,2). It is possible because grid[1][2] <= 3.\n- at t = 4, we move to the cell (1,1). It is possible because grid[1][1] <= 4.\n- at t = 5, we move to the cell (1,2). It is possible because grid[1][2] <= 5.\n- at t = 6, we move to the cell (1,3). It is possible because grid[1][3] <= 6.\n- at t = 7, we move to the cell (2,3). It is possible because grid[2][3] <= 7.\nThe final time is 7. It can be shown that it is the minimum time possible.\n\nExample 2:\n\nInput: grid = [[0,2,4],[3,2,1],[1,0,4]]\nOutput: -1\nExplanation: There is no path from the top left to the bottom-right cell.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 1000\n- 4 <= m * n <= 10^5\n- 0 <= grid[i][j] <= 10^5\n- grid[0][0] == 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 2, 4], [3, 2, 1], [1, 0, 4]]) == -1\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 4\n assert candidate(grid = [[0, 0], [0, 1]]) == 2\n assert candidate(grid = [[0, 1, 3, 2], [5, 1, 2, 5], [4, 3, 8, 6]]) == 7\n assert candidate(grid = [[0, 1], [2, 1]]) == 2\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 4\n assert candidate(grid = [[0, 1, 0, 1, 2], [0, 1, 0, 1, 2], [0, 1, 0, 1, 2], [0, 1, 0, 1, 2]]) == 7\n assert candidate(grid = [[0, 100], [101, 100]]) == -1\n assert candidate(grid = [[0, 1], [2, 3]]) == 4\n assert candidate(grid = [[0, 1, 2], [1, 1, 1], [2, 1, 0]]) == 4\n assert candidate(grid = [[0, 1, 1], [2, 2, 1], [1, 1, 0]]) == 4\n assert candidate(grid = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]) == 8\n assert candidate(grid = [[0, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8]]) == 8\n assert candidate(grid = [[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]) == 6\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 99, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29]]) == 29\n assert candidate(grid = [[0, 10000, 10000], [10000, 1, 10000], [10000, 10000, 1]]) == -1\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 0], [5, 4, 3, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[0, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 99, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 0]]) == 8\n assert candidate(grid = [[0, 1, 1, 1, 1, 1], [1, 9, 9, 9, 9, 1], [1, 9, 9, 9, 9, 1], [1, 9, 9, 9, 9, 1], [1, 9, 9, 9, 9, 1], [1, 1, 1, 1, 1, 0]]) == 10\n assert candidate(grid = [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11]]) == 11\n assert candidate(grid = [[0, 99, 99, 99, 99, 99, 99], [99, 99, 99, 99, 99, 99, 99], [99, 99, 0, 1, 1, 1, 99], [99, 99, 1, 99, 99, 1, 99], [99, 99, 1, 1, 1, 1, 99], [99, 99, 99, 99, 99, 99, 99], [99, 99, 99, 99, 99, 99, 0]]) == -1\n assert candidate(grid = [[0, 10, 15], [1, 5, 20], [2, 10, 25], [3, 15, 30]]) == 31\n assert candidate(grid = [[0, 1, 1, 1], [1, 99, 99, 1], [1, 1, 99, 1], [1, 1, 1, 0]]) == 6\n assert candidate(grid = [[0, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000], [1, 1000, 1, 1, 1, 1, 1, 1, 1, 1000], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 18\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, 0], [4, 3, 2, 1, 0, 0]]) == 10\n assert candidate(grid = [[0, 2, 2, 1, 3], [1, 2, 3, 1, 2], [1, 2, 1, 2, 1], [2, 1, 1, 3, 2]]) == 7\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [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]]) == 12\n assert candidate(grid = [[0, 2, 5, 7], [2, 5, 7, 9], [7, 9, 2, 5], [9, 2, 5, 0]]) == -1\n assert candidate(grid = [[0, 1, 2, 3, 4], [4, 3, 2, 1, 0], [0, 1, 2, 3, 4], [4, 3, 2, 1, 0], [0, 1, 2, 3, 0]]) == 8\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, 9, 8, 7, 6, 5, 4, 3, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 18\n assert candidate(grid = [[0, 10, 20, 30], [15, 5, 25, 35], [10, 30, 10, 40], [5, 20, 30, 1]]) == -1\n assert candidate(grid = [[0, 1, 2, 3], [10, 9, 8, 7], [2, 3, 4, 5], [11, 12, 13, 6]]) == 10\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [1, 6, 7, 8, 9, 10], [2, 7, 12, 13, 14, 15], [3, 8, 13, 18, 19, 20], [4, 9, 14, 19, 24, 25], [5, 10, 15, 20, 25, 0]]) == 26\n assert candidate(grid = [[0, 2, 2, 2], [2, 1, 2, 2], [2, 2, 1, 2], [2, 2, 2, 1]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 5, 4, 3, 1], [1, 2, 3, 4, 5, 6, 7, 6, 5, 1], [1, 2, 3, 4, 5, 6, 7, 8, 7, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 18\n assert candidate(grid = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) == 6\n assert candidate(grid = [[0, 10000, 9999], [10000, 9998, 10000], [9997, 10000, 10000]]) == -1\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 100000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 38\n assert candidate(grid = [[0, 0, 0], [0, 100, 0], [0, 0, 0]]) == 4\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29], [30, 31, 32, 33, 34, 35, 36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49]]) == 49\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [1, 6, 7, 8, 9, 10], [2, 11, 12, 13, 14, 15], [3, 16, 17, 18, 19, 20], [4, 21, 22, 23, 24, 25], [5, 26, 27, 28, 29, 30]]) == 30\n assert candidate(grid = [[0, 1, 2], [3, 100, 5], [6, 101, 8]]) == 8\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 18\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 0]]) == 25\n assert candidate(grid = [[0, 1, 3, 5, 7], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11], [4, 6, 8, 10, 12], [5, 7, 9, 11, 13]]) == 14\n assert candidate(grid = [[0, 2, 5, 9, 13], [4, 5, 6, 10, 14], [7, 8, 7, 11, 15], [12, 13, 14, 16, 19], [16, 17, 18, 18, 20]]) == -1\n assert candidate(grid = [[0, 2, 1, 4], [1, 6, 1, 2], [3, 1, 5, 3], [1, 2, 3, 0]]) == 8\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 99999, 99999, 99999, 0], [0, 99999, 99999, 99999, 0], [0, 99999, 99999, 99999, 0], [0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 18\n assert candidate(grid = [[0, 2, 4, 5, 6], [7, 3, 8, 9, 1], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) == -1\n assert candidate(grid = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]) == 16\n assert candidate(grid = [[0, 5, 10, 15], [15, 10, 5, 0], [10, 5, 0, 5], [15, 0, 5, 0]]) == -1\n assert candidate(grid = [[0, 5, 7, 8, 9], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 0]]) == 16\n assert candidate(grid = [[0, 1, 2, 3], [1, 100000, 1, 4], [2, 1, 1, 5], [3, 4, 5, 6]]) == 6\n assert candidate(grid = [[0, 1, 3, 2], [5, 8, 2, 5], [4, 3, 8, 6], [7, 6, 9, 0]]) == 8\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8], [4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 0]]) == 10\n assert candidate(grid = [[0, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8]]) == 8\n assert candidate(grid = [[0, 99, 99, 99, 99], [99, 99, 99, 99, 99], [99, 99, 1, 99, 99], [99, 99, 1, 99, 99], [99, 99, 1, 1, 0]]) == -1\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 3, 5, 7, 9, 11, 13, 15, 17, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 3], [3, 5, 7, 9, 11, 13, 15, 17, 19, 5], [4, 6, 8, 10, 12, 14, 16, 18, 20, 7], [5, 7, 9, 11, 13, 15, 17, 19, 21, 9], [6, 8, 10, 12, 14, 16, 18, 20, 22, 11], [7, 9, 11, 13, 15, 17, 19, 21, 23, 13], [8, 10, 12, 14, 16, 18, 20, 22, 24, 15], [9, 1, 3, 5, 7, 9, 11, 13, 15, 17]]) == 18\n assert candidate(grid = [[0, 10, 11, 12], [1, 2, 3, 4], [5, 6, 7, 8], [9, 1, 2, 1]]) == 10\n assert candidate(grid = [[0, 1, 2, 3, 4], [4, 3, 2, 3, 4], [4, 3, 2, 3, 4], [4, 3, 2, 3, 4], [4, 3, 2, 3, 0]]) == 8\n assert candidate(grid = [[0, 1, 5, 3, 4, 2], [1, 0, 1, 0, 1, 0], [2, 0, 2, 0, 2, 0], [1, 0, 1, 0, 1, 0], [3, 2, 3, 2, 3, 1]]) == 9\n assert candidate(grid = [[0, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 8\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 20\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34], [35, 36, 37, 38, 39, 40, 41], [42, 43, 44, 45, 46, 47, 48]]) == 48\n assert candidate(grid = [[0, 1, 5], [1, 9, 1], [2, 8, 1]]) == 8\n assert candidate(grid = [[0, 3, 1, 1, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1]]) == 8\n assert candidate(grid = [[0, 2, 5, 7, 8], [1, 3, 4, 6, 9], [2, 1, 3, 5, 7], [3, 4, 2, 1, 8], [4, 3, 5, 2, 0]]) == 8\n assert candidate(grid = [[0, 10, 10, 10], [10, 9, 9, 10], [10, 9, 8, 10], [10, 10, 10, 0]]) == -1\n assert candidate(grid = [[0, 10, 5], [20, 0, 15], [5, 15, 0]]) == -1\n assert candidate(grid = [[0, 1, 2, 3, 4], [9, 8, 7, 6, 5], [4, 3, 2, 1, 0], [5, 6, 7, 8, 9], [0, 1, 2, 3, 4]]) == 10\n assert candidate(grid = [[0, 10, 15, 20], [5, 4, 3, 2], [10, 9, 8, 7], [15, 14, 13, 6]]) == -1\n assert candidate(grid = [[0, 1, 1, 1, 1], [1, 9, 1, 9, 1], [1, 1, 9, 1, 1], [1, 9, 1, 9, 1], [1, 1, 1, 9, 0]]) == 8\n assert candidate(grid = [[0, 10, 10, 10], [10, 1, 10, 10], [10, 10, 1, 10], [10, 10, 10, 1]]) == -1\n assert candidate(grid = [[0, 2, 3, 5, 1], [1, 4, 3, 2, 6], [7, 3, 1, 5, 8], [6, 2, 4, 1, 7], [5, 1, 2, 3, 0]]) == 10\n assert candidate(grid = [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9], [10, 12, 14, 16, 18], [19, 21, 23, 25, 27], [28, 30, 32, 34, 36]]) == 36\n assert candidate(grid = [[0, 2, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 8\n assert candidate(grid = [[0, 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], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 10, 0], [0, 0, 0, 0]]) == 6\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, 99, 99, 99], [0, 1, 2, 99, 99, 99], [0, 0, 0, 99, 99, 99]]) == 102\n assert candidate(grid = [[0, 5, 5, 5, 5, 5], [5, 1, 1, 1, 1, 1], [5, 1, 5, 5, 5, 1], [5, 1, 1, 5, 1, 1], [5, 5, 5, 1, 5, 5], [5, 1, 1, 1, 1, 5]]) == -1\n assert candidate(grid = [[0, 1, 1, 1], [1, 2, 2, 1], [1, 2, 3, 4], [1, 1, 1, 0]]) == 6\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0], [10, 9, 8, 7, 6, 5, 4, 3, 2, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0], [10, 9, 8, 7, 6, 5, 4, 3, 2, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0], [10, 9, 8, 7, 6, 5, 4, 3, 2, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 19\n assert candidate(grid = [[0, 2, 1, 4], [3, 0, 5, 2], [1, 4, 0, 3], [2, 5, 3, 0]]) == -1\n assert candidate(grid = [[0, 0, 0], [0, 10, 0], [0, 0, 0]]) == 4\n assert candidate(grid = [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11], [4, 6, 8, 10, 12]]) == 12\n assert candidate(grid = [[0, 3, 1, 4], [3, 5, 7, 8], [4, 9, 6, 7], [11, 12, 5, 10]]) == -1\n assert candidate(grid = [[0, 1, 2, 3], [10, 11, 12, 4], [13, 14, 15, 5], [16, 17, 18, 6]]) == 6\n assert candidate(grid = [[0, 1, 2, 3], [1, 9, 8, 7], [2, 8, 7, 6], [3, 7, 6, 0]]) == 10\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, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 18\n assert candidate(grid = [[0, 10, 20, 30, 40], [10, 11, 21, 31, 41], [20, 21, 22, 32, 42], [30, 31, 32, 33, 43], [40, 41, 42, 43, 44]]) == -1\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 1], [2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 3], [4, 5, 6, 7, 8, 9], [10, 1, 2, 3, 4, 5]]) == 10\n assert candidate(grid = [[0, 1, 3, 5], [9, 1, 2, 4], [8, 7, 6, 5], [1, 3, 5, 7]]) == 8\n assert candidate(grid = [[0, 1, 2, 3, 4], [1, 10, 10, 10, 1], [2, 10, 1, 10, 2], [3, 10, 10, 10, 3], [4, 1, 2, 3, 4]]) == 8\n assert candidate(grid = [[0, 1, 2, 3], [4, 1, 2, 3], [4, 1, 2, 3], [4, 1, 2, 3]]) == 6\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]]) == 10\n assert candidate(grid = [[0, 3, 4, 5, 6], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 0]]) == 8\n assert candidate(grid = [[0, 2, 2, 2, 2, 2], [2, 2, 9, 9, 9, 2], [2, 9, 9, 9, 9, 9], [2, 9, 9, 9, 9, 9], [2, 2, 9, 9, 9, 2], [2, 2, 2, 2, 2, 0]]) == -1\n assert candidate(grid = [[0, 1, 5, 2, 10], [6, 3, 1, 4, 7], [8, 5, 9, 1, 6], [7, 4, 8, 3, 2]]) == 9\n assert candidate(grid = [[0, 5, 10, 15], [20, 25, 30, 35], [40, 45, 50, 55], [60, 65, 70, 75]]) == -1\n assert candidate(grid = [[0, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 0]]) == 10\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29], [30, 31, 32, 33, 34, 35, 36, 37, 38, 39]]) == 40\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], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 13\n assert candidate(grid = [[0, 1, 99, 99, 99, 99, 99, 99, 99, 99, 99], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [99, 1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 1, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1], [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 0]]) == 20\n assert candidate(grid = [[0, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 1, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0], [0, 10, 10, 0], [0, 10, 10, 0], [0, 0, 0, 0]]) == 6\n assert candidate(grid = [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11], [4, 6, 8, 10, 12]]) == 12\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, 3, 0]]) == 10\n assert candidate(grid = [[0, 100], [1, 101], [2, 102], [3, 103], [4, 104], [5, 105]]) == 106\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) == 6\n assert candidate(grid = [[0, 1, 2], [3, 1, 1], [2, 1, 0]]) == 4\n", "comparison": "exact"}, "public_tests": ["[[0,1,3,2],[5,1,2,5],[4,3,8,6]]", "[[0,2,4],[3,2,1],[1,0,4]]"], "hints": ["Try using some algorithm that can find the shortest paths on a graph.", "Consider the case where you have to go back and forth between two cells of the matrix to unlock some other cells."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:51+00:00", "tests_total": 114, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "breadth-first-search", "graph", "heap-priority-queue", "matrix", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_time(grid)", "container": null, "callable": "minimum_time", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2578, "task_id": "split-with-minimum-sum", "difficulty": "Easy", "problem_description": "Given a positive integer num, split it into two non-negative integers num1 and num2 such that:\n\n- The concatenation of num1 and num2 is a permutation of num.\n - In other words, the sum of the number of occurrences of each digit in num1 and num2 is equal to the number of occurrences of that digit in num.\n- num1 and num2 can contain leading zeros.\n\nReturn the minimum possible sum of num1 and num2.\n\nNotes:\n\n- It is guaranteed that num does not contain any leading zeros.\n- The order of occurrence of the digits in num1 and num2 may differ from the order of occurrence of num.\n\nExample 1:\n\nInput: num = 4325\nOutput: 59\nExplanation: We can split 4325 so that num1 is 24 and num2 is 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.\n\nExample 2:\n\nInput: num = 687\nOutput: 75\nExplanation: We can split 687 so that num1 is 68 and num2 is 7, which would give an optimal sum of 75.\n\nConstraints:\n\n- 10 <= num <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 10) == 1\n assert candidate(num = 687) == 75\n assert candidate(num = 4325) == 59\n assert candidate(num = 1234) == 37\n assert candidate(num = 222) == 24\n assert candidate(num = 1000000000) == 1\n assert candidate(num = 111111) == 222\n assert candidate(num = 123456789) == 16047\n assert candidate(num = 111222333) == 12456\n assert candidate(num = 29392342) == 4588\n assert candidate(num = 1001) == 2\n assert candidate(num = 543321) == 369\n assert candidate(num = 999999) == 1998\n assert candidate(num = 1000000) == 1\n assert candidate(num = 314159) == 284\n assert candidate(num = 567894321) == 16047\n assert candidate(num = 99991111) == 2398\n assert candidate(num = 87654321) == 3825\n assert candidate(num = 987654321) == 16047\n assert candidate(num = 54321) == 159\n assert candidate(num = 1234321) == 1357\n", "comparison": "exact"}, "public_tests": ["4325", "687"], "hints": ["Sort the digits of num in non decreasing order.", "Assign digits to num1 and num2 alternatively."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().splitNum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:54+00:00", "tests_total": 98, "tests_dropped": 77, "flags": [], "topic_tags": ["math", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def split_num(num)", "container": null, "callable": "split_num", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2579, "task_id": "count-total-number-of-colored-cells", "difficulty": "Medium", "problem_description": "There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:\n\n- At the first minute, color any arbitrary unit cell blue.\n- Every minute thereafter, color blue every uncolored cell that touches a blue cell.\n\nBelow is a pictorial representation of the state of the grid after minutes 1, 2, and 3.\n\nReturn the number of colored cells at the end of n minutes.\n\nExample 1:\n\nInput: n = 1\nOutput: 1\nExplanation: After 1 minute, there is only 1 blue cell, so we return 1.\n\nExample 2:\n\nInput: n = 2\nOutput: 5\nExplanation: After 2 minutes, there are 4 colored cells on the boundary and 1 in the center, so we return 5.\n\nConstraints:\n\n- 1 <= n <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 13\n assert candidate(n = 100000) == 19999800001\n assert candidate(n = 100) == 19801\n assert candidate(n = 10000) == 199980001\n assert candidate(n = 2) == 5\n assert candidate(n = 1) == 1\n assert candidate(n = 1000) == 1998001\n assert candidate(n = 10) == 181\n assert candidate(n = 15000) == 449970001\n assert candidate(n = 99999) == 19999400005\n assert candidate(n = 12345) == 304773361\n assert candidate(n = 7500) == 112485001\n assert candidate(n = 2000) == 7996001\n assert candidate(n = 50000) == 4999900001\n assert candidate(n = 50) == 4901\n assert candidate(n = 5) == 41\n assert candidate(n = 30) == 1741\n assert candidate(n = 60000) == 7199880001\n assert candidate(n = 1500) == 4497001\n assert candidate(n = 4) == 25\n assert candidate(n = 30000) == 1799940001\n assert candidate(n = 1001) == 2002001\n assert candidate(n = 85000) == 14449830001\n assert candidate(n = 80000) == 12799840001\n assert candidate(n = 20000) == 799960001\n assert candidate(n = 5000) == 49990001\n assert candidate(n = 75000) == 11249850001\n assert candidate(n = 20) == 761\n assert candidate(n = 40000) == 3199920001\n assert candidate(n = 15) == 421\n assert candidate(n = 2500) == 12495001\n assert candidate(n = 9000) == 161982001\n assert candidate(n = 200) == 79601\n assert candidate(n = 99998) == 19999000013\n assert candidate(n = 500) == 499001\n assert candidate(n = 25) == 1201\n assert candidate(n = 25000) == 1249950001\n", "comparison": "exact"}, "public_tests": ["1", "2"], "hints": ["Derive a mathematical relation between total number of colored cells and the time elapsed in minutes."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().coloredCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:56+00:00", "tests_total": 37, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def colored_cells(n)", "container": null, "callable": "colored_cells", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2581, "task_id": "count-number-of-possible-root-nodes", "difficulty": "Hard", "problem_description": "Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as a 2D integer array edges of length n - 1 where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.\n\nAlice wants Bob to find the root of the tree. She allows Bob to make several guesses about her tree. In one guess, he does the following:\n\n- Chooses two distinct integers u and v such that there exists an edge [u, v] in the tree.\n- He tells Alice that u is the parent of v in the tree.\n\nBob's guesses are represented by a 2D integer array guesses where guesses[j] = [u_j, v_j] indicates Bob guessed u_j to be the parent of v_j.\n\nAlice being lazy, does not reply to each of Bob's guesses, but just says that at least k of his guesses are true.\n\nGiven the 2D integer arrays edges, guesses and the integer k, return the number of possible nodes that can be the root of Alice's tree. If there is no such tree, return 0.\n\nExample 1:\n\nInput: edges = [[0,1],[1,2],[1,3],[4,2]], guesses = [[1,3],[0,1],[1,0],[2,4]], k = 3\nOutput: 3\nExplanation:\nRoot = 0, correct guesses = [1,3], [0,1], [2,4]\nRoot = 1, correct guesses = [1,3], [1,0], [2,4]\nRoot = 2, correct guesses = [1,3], [1,0], [2,4]\nRoot = 3, correct guesses = [1,0], [2,4]\nRoot = 4, correct guesses = [1,3], [1,0]\nConsidering 0, 1, or 2 as root node leads to 3 correct guesses.\n\nExample 2:\n\nInput: edges = [[0,1],[1,2],[2,3],[3,4]], guesses = [[1,0],[3,4],[2,1],[3,2]], k = 1\nOutput: 5\nExplanation:\nRoot = 0, correct guesses = [3,4]\nRoot = 1, correct guesses = [1,0], [3,4]\nRoot = 2, correct guesses = [1,0], [2,1], [3,4]\nRoot = 3, correct guesses = [1,0], [2,1], [3,2], [3,4]\nRoot = 4, correct guesses = [1,0], [2,1], [3,2]\nConsidering any node as root will give at least 1 correct guess.\n\nConstraints:\n\n- edges.length == n - 1\n- 2 <= n <= 10^5\n- 1 <= guesses.length <= 10^5\n- 0 <= a_i, b_i, u_j, v_j <= n - 1\n- a_i != b_i\n- u_j != v_j\n- edges represents a valid tree.\n- guesses[j] is an edge of the tree.\n- guesses is unique.\n- 0 <= k <= guesses.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2], [0, 3]],guesses = [[0, 1], [0, 2], [0, 3]],k = 2) == 4\n assert candidate(edges = [[0, 1], [0, 2]],guesses = [[0, 1]],k = 1) == 2\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [4, 2]],guesses = [[1, 3], [0, 1], [1, 0], [2, 4]],k = 3) == 3\n assert candidate(edges = [[0, 1], [1, 2], [2, 3]],guesses = [[1, 2], [2, 3]],k = 2) == 2\n assert candidate(edges = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5]],guesses = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5]],k = 5) == 1\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4]],guesses = [[1, 0], [3, 4], [2, 1], [3, 2]],k = 1) == 5\n assert candidate(edges = [[0, 1], [0, 2], [0, 3]],guesses = [[0, 1], [0, 2], [0, 3]],k = 3) == 1\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [1, 4]],guesses = [[0, 1], [1, 2], [1, 3], [1, 4]],k = 4) == 1\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],k = 15) == 6\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],guesses = [[0, 1], [1, 3], [3, 7], [3, 8], [1, 4], [4, 9], [4, 10], [0, 2], [2, 5], [2, 6]],k = 5) == 11\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],guesses = [[0, 1], [1, 4], [1, 5], [0, 2], [2, 6], [2, 7], [0, 3], [3, 8], [3, 9]],k = 4) == 10\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],k = 5) == 11\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],k = 5) == 4\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27]],guesses = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [2, 1], [14, 7], [15, 7], [16, 8], [17, 8], [20, 10], [21, 10], [22, 11], [23, 11], [24, 12], [25, 12], [26, 13], [27, 13]],k = 10) == 28\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],k = 8) == 1\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [0, 2], [1, 4], [6, 2], [3, 7], [4, 9], [5, 11]],k = 8) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],guesses = [[0, 1], [1, 3], [2, 5], [3, 7], [4, 9], [0, 2], [1, 4], [2, 6], [3, 8], [4, 10]],k = 5) == 11\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6]],guesses = [[0, 1], [1, 3], [3, 5], [0, 2], [2, 4], [4, 6]],k = 4) == 5\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28]],guesses = [[0, 1], [1, 2], [1, 3], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [1, 0], [3, 1], [5, 2], [10, 4], [7, 3], [13, 6], [15, 7], [16, 7], [17, 8], [18, 8], [19, 9], [20, 9], [21, 10], [22, 10], [23, 11], [24, 11], [25, 12], [26, 12], [27, 13], [28, 13]],k = 15) == 29\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16]],guesses = [[0, 1], [1, 3], [3, 7], [3, 8], [1, 4], [4, 9], [0, 2], [2, 5], [2, 6], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16]],k = 10) == 17\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1]],k = 5) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 1], [5, 2]],k = 4) == 7\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],guesses = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],k = 7) == 10\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16], [12, 17], [13, 18], [14, 19], [15, 20], [16, 21]],guesses = [[0, 1], [1, 3], [3, 7], [3, 8], [1, 4], [4, 9], [0, 2], [2, 5], [2, 6], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16], [12, 17], [13, 18], [14, 19], [15, 20], [16, 21]],k = 12) == 22\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [3, 2], [7, 6], [11, 10], [13, 14]],k = 9) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],k = 6) == 7\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],k = 10) == 6\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3], [9, 4], [10, 4], [11, 5], [12, 5], [13, 6], [14, 6]],k = 9) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [3, 2], [7, 6]],k = 6) == 6\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7], [4, 8]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7], [4, 8], [3, 1], [5, 2]],k = 4) == 9\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3], [9, 4], [10, 4], [11, 5], [12, 5], [13, 6], [14, 6]],k = 10) == 13\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],guesses = [[0, 1], [1, 3], [3, 7], [3, 8], [1, 4], [4, 9], [4, 10], [0, 2], [2, 5], [2, 6]],k = 7) == 11\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],k = 9) == 2\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11]],guesses = [[0, 1], [1, 3], [3, 7], [3, 8], [1, 4], [4, 9], [0, 2], [2, 5], [2, 6], [5, 10], [6, 11]],k = 7) == 12\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],guesses = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 1], [5, 1], [6, 2], [7, 2], [8, 3], [9, 3]],k = 4) == 10\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],k = 8) == 7\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],guesses = [[0, 1], [1, 4], [1, 5], [0, 2], [2, 6], [2, 7], [0, 3], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],k = 10) == 22\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [3, 1], [5, 2], [10, 4], [7, 3], [13, 6]],k = 7) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 6) == 4\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],guesses = [[1, 0], [3, 4], [2, 1], [3, 2], [5, 6], [4, 5], [6, 7]],k = 4) == 7\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9]],guesses = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9]],k = 6) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],k = 6) == 1\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],guesses = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [1, 0], [2, 0], [3, 0], [4, 1], [5, 1], [6, 2], [7, 2], [8, 3], [9, 3]],k = 7) == 10\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],guesses = [[0, 1], [1, 3], [3, 7], [3, 8], [1, 4], [4, 9], [4, 10], [0, 2], [2, 5], [2, 6], [5, 11], [5, 12], [6, 13], [6, 14]],k = 7) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [2, 1], [6, 5], [10, 9]],k = 7) == 8\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],guesses = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 2], [5, 2], [6, 3], [7, 3]],k = 5) == 8\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 9) == 1\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [3, 2], [7, 6], [11, 10], [13, 14]],k = 12) == 27\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 13], [13, 12], [12, 11], [11, 10], [10, 9], [9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 0]],k = 10) == 15\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],guesses = [[0, 1], [1, 3], [2, 5], [1, 0], [4, 1], [6, 2]],k = 3) == 5\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],guesses = [[0, 1], [1, 3], [2, 5], [3, 7], [4, 9], [0, 2], [1, 4], [2, 6], [3, 8], [4, 10]],k = 3) == 11\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3]],k = 6) == 9\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7], [4, 8], [8, 9], [9, 10], [10, 11], [11, 12]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [4, 7], [4, 8], [8, 9], [9, 10], [10, 11], [11, 12]],k = 6) == 7\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],guesses = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],k = 12) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 1], [5, 2], [4, 1], [6, 2]],k = 3) == 7\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],guesses = [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3], [4, 5], [5, 4], [5, 6], [6, 5], [6, 7], [7, 6]],k = 7) == 8\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [0, 2], [1, 4]],k = 5) == 6\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],guesses = [[1, 0], [3, 1], [5, 3], [2, 1], [4, 2], [6, 5]],k = 3) == 1\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7], [4, 8]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7], [4, 8]],k = 8) == 1\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],k = 5) == 6\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],guesses = [[0, 1], [1, 3], [2, 5], [1, 0], [4, 1], [6, 2], [3, 7], [4, 9], [5, 11], [0, 2], [1, 4], [6, 14], [3, 8], [4, 10], [5, 12]],k = 7) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],k = 7) == 1\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],guesses = [[0, 1], [1, 4], [2, 6], [3, 8], [4, 10], [0, 2], [1, 5], [2, 7], [3, 9], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],k = 10) == 22\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],guesses = [[0, 1], [1, 4], [2, 6], [3, 8], [4, 10], [0, 2], [1, 5], [2, 7], [3, 9], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],k = 5) == 22\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],guesses = [[0, 1], [1, 4], [1, 5], [0, 2], [2, 6], [2, 7], [0, 3], [3, 8], [3, 9]],k = 5) == 10\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],guesses = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 0]],k = 5) == 10\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30]],guesses = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30], [1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3], [9, 4], [10, 4], [11, 5], [12, 5], [13, 6], [14, 6], [15, 7], [16, 7], [17, 8], [18, 8], [19, 9], [20, 9], [21, 10], [22, 10], [23, 11], [24, 11], [25, 12], [26, 12], [27, 13], [28, 13], [29, 14], [30, 14]],k = 15) == 31\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8]],guesses = [[0, 1], [1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8]],k = 8) == 1\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20]],guesses = [[0, 1], [1, 2], [1, 3], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20]],k = 14) == 21\n", "comparison": "exact"}, "public_tests": ["[[0,1],[1,2],[1,3],[4,2]]\n[[1,3],[0,1],[1,0],[2,4]]\n3", "[[0,1],[1,2],[2,3],[3,4]]\n[[1,0],[3,4],[2,1],[3,2]]\n1"], "hints": ["How can we check if any node can be the root?", "Can we use this information to check its neighboring nodes?", "When we traverse from current node to a neighboring node, how will we update our answer?"], "metadata": {"canonical_parameter_names": ["edges", "guesses", "k"], "leetcode_dataset_entry_point": "Solution().rootCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:57:58+00:00", "tests_total": 70, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "dynamic-programming", "tree", "depth-first-search"]}, "language": "ruby", "interface": {"raw_signature": "def root_count(edges, guesses, k)", "container": null, "callable": "root_count", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "guesses", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2582, "task_id": "pass-the-pillow", "difficulty": "Easy", "problem_description": "There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.\n\n- For example, once the pillow reaches the n^th person they pass it to the n - 1^th person, then to the n - 2^th person and so on.\n\nGiven the two positive integers n and time, return the index of the person holding the pillow after time seconds.\n\nExample 1:\n\nInput: n = 4, time = 5\nOutput: 2\nExplanation: People pass the pillow in the following way: 1 -> 2 -> 3 -> 4 -> 3 -> 2.\nAfter five seconds, the 2^nd person is holding the pillow.\n\nExample 2:\n\nInput: n = 3, time = 2\nOutput: 3\nExplanation: People pass the pillow in the following way: 1 -> 2 -> 3.\nAfter two seconds, the 3^r^d person is holding the pillow.\n\nConstraints:\n\n- 2 <= n <= 1000\n- 1 <= time <= 1000\n\nNote: This question is the same as 3178: Find the Child Who Has the Ball After K Seconds.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,time = 5) == 2\n assert candidate(n = 10,time = 15) == 4\n assert candidate(n = 500,time = 750) == 249\n assert candidate(n = 2,time = 1) == 2\n assert candidate(n = 7,time = 20) == 5\n assert candidate(n = 8,time = 20) == 7\n assert candidate(n = 5,time = 7) == 2\n assert candidate(n = 3,time = 2) == 3\n assert candidate(n = 6,time = 12) == 3\n assert candidate(n = 2,time = 2) == 1\n assert candidate(n = 1000,time = 1000) == 999\n assert candidate(n = 6,time = 1) == 2\n assert candidate(n = 8,time = 12) == 3\n assert candidate(n = 4,time = 5) == 2\n assert candidate(n = 600,time = 800) == 399\n assert candidate(n = 7,time = 49) == 2\n assert candidate(n = 15,time = 500) == 5\n assert candidate(n = 9,time = 50) == 3\n assert candidate(n = 15,time = 120) == 9\n assert candidate(n = 15,time = 100) == 13\n assert candidate(n = 100,time = 800) == 9\n assert candidate(n = 50,time = 1000) == 21\n assert candidate(n = 8,time = 45) == 4\n assert candidate(n = 20,time = 150) == 3\n assert candidate(n = 550,time = 725) == 374\n assert candidate(n = 15,time = 25) == 4\n assert candidate(n = 12,time = 150) == 5\n assert candidate(n = 499,time = 500) == 497\n assert candidate(n = 12,time = 60) == 7\n assert candidate(n = 15,time = 225) == 2\n assert candidate(n = 200,time = 400) == 3\n assert candidate(n = 999,time = 999) == 998\n assert candidate(n = 7,time = 1000) == 5\n assert candidate(n = 10,time = 100) == 9\n assert candidate(n = 20,time = 500) == 7\n assert candidate(n = 999,time = 998) == 999\n assert candidate(n = 6,time = 11) == 2\n assert candidate(n = 250,time = 1000) == 5\n assert candidate(n = 100,time = 150) == 49\n assert candidate(n = 2,time = 1000) == 1\n assert candidate(n = 12,time = 30) == 9\n assert candidate(n = 450,time = 999) == 102\n assert candidate(n = 450,time = 675) == 224\n assert candidate(n = 100,time = 250) == 53\n assert candidate(n = 3,time = 9) == 2\n assert candidate(n = 450,time = 500) == 399\n assert candidate(n = 150,time = 500) == 97\n assert candidate(n = 18,time = 90) == 13\n assert candidate(n = 6,time = 13) == 4\n assert candidate(n = 12,time = 100) == 11\n assert candidate(n = 2,time = 100) == 1\n assert candidate(n = 250,time = 750) == 247\n assert candidate(n = 9,time = 150) == 7\n assert candidate(n = 20,time = 1000) == 13\n assert candidate(n = 6,time = 30) == 1\n assert candidate(n = 20,time = 199) == 10\n assert candidate(n = 100,time = 500) == 95\n assert candidate(n = 9,time = 40) == 9\n assert candidate(n = 8,time = 31) == 4\n assert candidate(n = 9,time = 25) == 8\n assert candidate(n = 20,time = 50) == 13\n assert candidate(n = 333,time = 998) == 331\n assert candidate(n = 8,time = 24) == 5\n assert candidate(n = 10,time = 25) == 8\n assert candidate(n = 30,time = 150) == 25\n assert candidate(n = 3,time = 999) == 2\n assert candidate(n = 9,time = 81) == 2\n assert candidate(n = 300,time = 550) == 49\n assert candidate(n = 300,time = 600) == 3\n assert candidate(n = 6,time = 101) == 2\n assert candidate(n = 25,time = 625) == 2\n assert candidate(n = 9,time = 18) == 3\n assert candidate(n = 1000,time = 999) == 1000\n assert candidate(n = 5,time = 25) == 2\n assert candidate(n = 12,time = 25) == 4\n assert candidate(n = 600,time = 999) == 200\n assert candidate(n = 8,time = 27) == 2\n assert candidate(n = 999,time = 1000) == 997\n assert candidate(n = 8,time = 100) == 3\n assert candidate(n = 2,time = 500) == 1\n assert candidate(n = 8,time = 30) == 3\n assert candidate(n = 600,time = 900) == 299\n assert candidate(n = 25,time = 250) == 11\n", "comparison": "exact"}, "public_tests": ["4\n5", "3\n2"], "hints": ["Maintain two integer variables, direction and i, where direction denotes the current direction in which the pillow should pass, and i denotes an index of the person holding the pillow.", "While time is positive, update the current index with the current direction. If the index reaches the end of the line, multiply direction by - 1."], "metadata": {"canonical_parameter_names": ["n", "time"], "leetcode_dataset_entry_point": "Solution().passThePillow", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:01+00:00", "tests_total": 94, "tests_dropped": 11, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def pass_the_pillow(n, time)", "container": null, "callable": "pass_the_pillow", "parameters": [{"name": "n", "type": "Integer"}, {"name": "time", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2584, "task_id": "split-the-array-to-make-coprime-products", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums of length n.\n\nA split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.\n\n- For example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are coprime, while a split at the index i = 1 is not valid because 6 and 3 are not coprime. A split at the index i = 2 is not valid because i == n - 1.\n\nReturn the smallest index i at which the array can be split validly or -1 if there is no such split.\n\nTwo values val1 and val2 are coprime if gcd(val1, val2) == 1 where gcd(val1, val2) is the greatest common divisor of val1 and val2.\n\nExample 1:\n\nInput: nums = [4,7,8,15,3,5]\nOutput: 2\nExplanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.\nThe only valid split is at index 2.\n\nExample 2:\n\nInput: nums = [4,7,15,8,3,5]\nOutput: -1\nExplanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.\nThere is no valid split.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^4\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [60, 1, 2, 3]) == -1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == -1\n assert candidate(nums = [30, 35, 14]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [60, 45, 10]) == -1\n assert candidate(nums = [1000000, 1000000]) == -1\n assert candidate(nums = [18, 5, 100]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums = [4, 7, 15, 8, 3, 5]) == -1\n assert candidate(nums = [4, 7, 8, 15, 3, 5]) == 2\n assert candidate(nums = [13, 17, 19, 23, 29]) == 0\n assert candidate(nums = [7, 3, 5, 2, 10]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums = [6, 10, 15, 21, 28, 35]) == -1\n assert candidate(nums = [30, 30, 30, 30]) == -1\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == -1\n assert candidate(nums = [2, 2, 2, 2]) == -1\n assert candidate(nums = [7, 11, 13, 17, 19, 23]) == 0\n assert candidate(nums = [60, 45, 105, 30, 20]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11]) == 0\n assert candidate(nums = [30, 30, 30, 30, 30, 30]) == -1\n assert candidate(nums = [3, 9, 7, 11, 13]) == 1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == -1\n assert candidate(nums = [60, 105, 210, 315, 420, 525, 630, 735, 840, 945]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == -1\n assert candidate(nums = [18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90]) == -1\n assert candidate(nums = [1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129]) == 0\n assert candidate(nums = [60, 105, 56, 21, 10, 14]) == -1\n assert candidate(nums = [31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == -1\n assert candidate(nums = [2, 3, 4, 6, 8, 12, 18, 24, 36, 48, 72, 144]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == -1\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == -1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == -1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996]) == -1\n assert candidate(nums = [8, 12, 18, 24, 30, 36]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == -1\n assert candidate(nums = [210, 330, 420, 462, 546, 630, 714, 840, 924, 1092, 1260]) == -1\n assert candidate(nums = [30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180]) == -1\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 33, 35, 38, 39, 45, 46, 51, 55]) == -1\n assert candidate(nums = [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, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167]) == 0\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == -1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == -1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187]) == -1\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625]) == -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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == -1\n assert candidate(nums = [18, 24, 30, 42, 56, 70, 84, 98, 112, 126]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111]) == -1\n assert candidate(nums = [6, 10, 15, 21, 35, 70]) == -1\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 0\n assert candidate(nums = [6, 10, 15, 21, 28, 35, 42, 50, 56, 63, 70, 77, 84, 90, 91]) == -1\n assert candidate(nums = [987654, 321654, 123456, 654321, 789012, 369258, 456789]) == -1\n assert candidate(nums = [15, 21, 35, 14, 30, 63, 70, 90, 105, 140]) == -1\n assert candidate(nums = [9973, 9967, 9979, 9983, 9971, 9989]) == 0\n assert candidate(nums = [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020]) == -1\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == -1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 8\n assert candidate(nums = [1024, 512, 256, 128, 64, 32]) == -1\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10]) == -1\n assert candidate(nums = [60, 70, 84, 90, 105, 110, 130, 154, 165, 210, 220, 231, 286, 315, 330, 385, 462, 495, 550, 770, 840, 924, 990, 1155, 1320, 1430, 1540, 1650, 2145, 2310, 2640, 2772, 2970, 3300, 3960, 4290, 4620, 4950, 6600, 7260, 7920, 8580, 9900]) == -1\n assert candidate(nums = [840, 720, 600, 480, 360, 240, 120, 60, 30, 15, 5]) == -1\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005]) == -1\n assert candidate(nums = [60, 35, 28, 15, 45, 70]) == -1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990]) == -1\n assert candidate(nums = [99, 121, 165, 495, 605, 1210]) == -1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == -1\n assert candidate(nums = [121, 143, 169, 187, 209, 221, 247, 253, 299, 323, 341]) == -1\n assert candidate(nums = [143, 169, 187, 221, 247, 299, 323, 341, 377, 391, 437, 451, 481, 493, 529]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 0\n assert candidate(nums = [50, 75, 100, 125, 150, 175, 200, 225, 250, 275]) == -1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]) == 0\n assert candidate(nums = [23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23]) == -1\n assert candidate(nums = [840, 924, 1008, 1092, 1176, 1260, 1344, 1428, 1512, 1608]) == -1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == 8\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]) == 0\n assert candidate(nums = [60, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == -1\n assert candidate(nums = [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]) == -1\n assert candidate(nums = [84, 132, 220, 154, 385]) == -1\n assert candidate(nums = [12, 15, 21, 25, 30, 35, 42]) == -1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == -1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147]) == -1\n assert candidate(nums = [999983, 999979, 999961, 999959, 999953, 999943]) == 0\n assert candidate(nums = [60, 105, 140, 210, 35, 10]) == -1\n assert candidate(nums = [42, 63, 84, 105, 126, 147]) == -1\n assert candidate(nums = [121, 143, 169, 187, 209, 221, 247, 253, 299, 319]) == -1\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480]) == -1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 9\n assert candidate(nums = [210, 330, 55, 14, 22, 110]) == -1\n", "comparison": "exact"}, "public_tests": ["[4,7,8,15,3,5]", "[4,7,15,8,3,5]"], "hints": ["Two numbers with GCD equal to 1 have no common prime divisor.", "Find the prime factorization of the left and right sides and check if they share a prime divisor."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findValidSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:06+00:00", "tests_total": 107, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "math", "number-theory", "prime-factorization"]}, "language": "ruby", "interface": {"raw_signature": "def find_valid_split(nums)", "container": null, "callable": "find_valid_split", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2585, "task_id": "number-of-ways-to-earn-points", "difficulty": "Hard", "problem_description": "There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [count_i, marks_i] indicates that there are count_i questions of the i^th type, and each one of them is worth marks_i points.\n\nReturn the number of ways you can earn exactly target points in the exam. Since the answer may be too large, return it modulo 10^9 + 7.\n\nNote that questions of the same type are indistinguishable.\n\n- For example, if there are 3 questions of the same type, then solving the 1^st and 2^nd questions is the same as solving the 1^st and 3^rd questions, or the 2^nd and 3^rd questions.\n\nExample 1:\n\nInput: target = 6, types = [[6,1],[3,2],[2,3]]\nOutput: 7\nExplanation: You can earn 6 points in one of the seven ways:\n- Solve 6 questions of the 0^th type: 1 + 1 + 1 + 1 + 1 + 1 = 6\n- Solve 4 questions of the 0^th type and 1 question of the 1^st type: 1 + 1 + 1 + 1 + 2 = 6\n- Solve 2 questions of the 0^th type and 2 questions of the 1^st type: 1 + 1 + 2 + 2 = 6\n- Solve 3 questions of the 0^th type and 1 question of the 2^nd type: 1 + 1 + 1 + 3 = 6\n- Solve 1 question of the 0^th type, 1 question of the 1^st type and 1 question of the 2^nd type: 1 + 2 + 3 = 6\n- Solve 3 questions of the 1^st type: 2 + 2 + 2 = 6\n- Solve 2 questions of the 2^nd type: 3 + 3 = 6\n\nExample 2:\n\nInput: target = 5, types = [[50,1],[50,2],[50,5]]\nOutput: 4\nExplanation: You can earn 5 points in one of the four ways:\n- Solve 5 questions of the 0^th type: 1 + 1 + 1 + 1 + 1 = 5\n- Solve 3 questions of the 0^th type and 1 question of the 1^st type: 1 + 1 + 1 + 2 = 5\n- Solve 1 questions of the 0^th type and 2 questions of the 1^st type: 1 + 2 + 2 = 5\n- Solve 1 question of the 2^nd type: 5\n\nExample 3:\n\nInput: target = 18, types = [[6,1],[3,2],[2,3]]\nOutput: 1\nExplanation: You can only earn 18 points by answering all questions.\n\nConstraints:\n\n- 1 <= target <= 1000\n- n == types.length\n- 1 <= n <= 50\n- types[i].length == 2\n- 1 <= count_i, marks_i <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(target = 10,types = [[2, 5], [1, 3]]) == 1\n assert candidate(target = 1,types = [[1, 1]]) == 1\n assert candidate(target = 30,types = [[5, 10], [3, 5], [2, 15]]) == 5\n assert candidate(target = 750,types = [[50, 15], [50, 25], [50, 35]]) == 119\n assert candidate(target = 20,types = [[2, 5], [3, 10], [4, 20]]) == 3\n assert candidate(target = 10,types = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]) == 3\n assert candidate(target = 5,types = [[50, 1], [50, 2], [50, 5]]) == 4\n assert candidate(target = 10,types = [[10, 1], [5, 2]]) == 6\n assert candidate(target = 100,types = [[10, 5], [10, 10], [10, 15], [10, 20]]) == 90\n assert candidate(target = 20,types = [[2, 5], [2, 10], [3, 15]]) == 3\n assert candidate(target = 6,types = [[6, 1], [3, 2], [2, 3]]) == 7\n assert candidate(target = 10,types = [[10, 1], [5, 2], [3, 3]]) == 14\n assert candidate(target = 20,types = [[1, 10], [2, 5], [3, 2]]) == 1\n assert candidate(target = 20,types = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]) == 0\n assert candidate(target = 18,types = [[6, 1], [3, 2], [2, 3]]) == 1\n assert candidate(target = 20,types = [[5, 10], [3, 5], [2, 2]]) == 2\n assert candidate(target = 500,types = [[20, 10], [30, 20], [40, 30], [10, 50]]) == 721\n assert candidate(target = 500,types = [[20, 10], [20, 15], [20, 20], [20, 25], [20, 30]]) == 6939\n assert candidate(target = 450,types = [[50, 3], [50, 6], [50, 9], [50, 12], [50, 15]]) == 165604\n assert candidate(target = 400,types = [[20, 5], [20, 10], [20, 15], [20, 20], [20, 25]]) == 12066\n assert candidate(target = 650,types = [[40, 10], [30, 15], [20, 20], [10, 25], [5, 30], [2, 35], [1, 40]]) == 56729\n assert candidate(target = 999,types = [[49, 1], [49, 2], [49, 3], [49, 4], [49, 5]]) == 0\n assert candidate(target = 650,types = [[30, 20], [30, 21], [30, 22], [30, 23], [30, 24]]) == 2012\n assert candidate(target = 700,types = [[25, 28], [25, 29], [25, 30], [25, 31], [25, 32]]) == 624\n assert candidate(target = 200,types = [[10, 10], [20, 20], [30, 30], [40, 40]]) == 90\n assert candidate(target = 300,types = [[30, 10], [20, 20], [40, 30], [10, 40], [30, 50]]) == 674\n assert candidate(target = 300,types = [[50, 10], [30, 15], [20, 20], [10, 25], [5, 30], [2, 35]]) == 2734\n assert candidate(target = 600,types = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]]) == 0\n assert candidate(target = 250,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5]]) == 692188\n assert candidate(target = 550,types = [[25, 10], [25, 20], [25, 30], [25, 40], [25, 50]]) == 4654\n assert candidate(target = 600,types = [[50, 1], [50, 2], [50, 4], [50, 8]]) == 6711\n assert candidate(target = 350,types = [[25, 5], [25, 15], [25, 25], [25, 35]]) == 530\n assert candidate(target = 900,types = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]]) == 0\n assert candidate(target = 700,types = [[40, 10], [30, 20], [20, 30], [10, 40]]) == 2426\n assert candidate(target = 800,types = [[15, 20], [25, 30], [10, 40], [20, 50]]) == 574\n assert candidate(target = 300,types = [[20, 10], [30, 15], [40, 25], [50, 30]]) == 276\n assert candidate(target = 350,types = [[15, 7], [15, 14], [15, 21], [15, 28], [15, 35]]) == 2610\n assert candidate(target = 800,types = [[50, 5], [50, 10], [50, 15], [50, 20]]) == 19178\n assert candidate(target = 250,types = [[25, 5], [25, 10], [25, 15], [25, 20], [25, 25]]) == 3432\n assert candidate(target = 700,types = [[50, 10], [50, 20], [50, 30], [50, 40], [50, 50]]) == 12306\n assert candidate(target = 700,types = [[25, 5], [25, 10], [25, 15], [25, 20], [25, 25], [25, 30], [25, 35], [25, 40], [25, 45], [25, 50]]) == 56776700\n assert candidate(target = 999,types = [[30, 5], [20, 10], [40, 20], [30, 25]]) == 0\n assert candidate(target = 500,types = [[15, 5], [25, 10], [35, 15], [45, 20]]) == 2461\n assert candidate(target = 700,types = [[50, 1], [50, 3], [50, 7], [50, 11], [50, 13], [50, 17], [50, 19]]) == 53354051\n assert candidate(target = 400,types = [[25, 4], [25, 8], [25, 12], [25, 16], [25, 20]]) == 27739\n assert candidate(target = 1000,types = [[50, 1], [50, 3], [50, 7], [50, 11], [50, 13]]) == 433268\n assert candidate(target = 250,types = [[20, 1], [30, 2], [20, 3], [10, 4], [10, 5], [5, 6]]) == 35\n assert candidate(target = 650,types = [[50, 10], [50, 20], [50, 30], [50, 40], [50, 50]]) == 9472\n assert candidate(target = 450,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5], [50, 6], [50, 7], [50, 8], [50, 9], [50, 10]]) == 909681426\n assert candidate(target = 500,types = [[25, 20], [25, 30], [25, 40], [25, 50]]) == 258\n assert candidate(target = 400,types = [[50, 20], [30, 15], [20, 10], [10, 5]]) == 1129\n assert candidate(target = 600,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5], [50, 6], [50, 7], [50, 8], [50, 9], [50, 10]]) == 209801687\n assert candidate(target = 450,types = [[15, 30], [20, 25], [25, 20], [30, 15], [35, 10]]) == 5753\n assert candidate(target = 500,types = [[30, 10], [20, 15], [10, 20], [5, 25]]) == 535\n assert candidate(target = 300,types = [[15, 5], [15, 10], [15, 15], [15, 20], [15, 25], [15, 30], [15, 35], [15, 40], [15, 45]]) == 108177\n assert candidate(target = 200,types = [[20, 10], [20, 20], [20, 30], [20, 40]]) == 108\n assert candidate(target = 900,types = [[20, 10], [30, 20], [10, 30], [20, 40]]) == 1725\n assert candidate(target = 500,types = [[20, 25], [20, 30], [20, 35], [20, 40], [20, 45]]) == 520\n assert candidate(target = 600,types = [[50, 12], [50, 14], [50, 16], [50, 18], [50, 20]]) == 14453\n assert candidate(target = 999,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5], [50, 6], [50, 7], [50, 8], [50, 9], [50, 10], [50, 11], [50, 12], [50, 13], [50, 14], [50, 15]]) == 805840421\n assert candidate(target = 550,types = [[40, 5], [40, 10], [40, 15], [30, 20], [20, 25], [10, 30]]) == 249864\n assert candidate(target = 800,types = [[40, 10], [30, 20], [20, 30], [10, 40], [5, 50]]) == 13462\n assert candidate(target = 800,types = [[50, 1], [50, 3], [50, 5], [50, 7], [50, 9]]) == 485554\n assert candidate(target = 600,types = [[50, 5], [50, 10], [50, 15], [50, 20], [50, 25]]) == 79630\n assert candidate(target = 1000,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5]]) == 0\n assert candidate(target = 400,types = [[25, 1], [25, 2], [25, 3], [25, 4], [25, 5], [25, 6], [25, 7], [25, 8]]) == 683239099\n assert candidate(target = 300,types = [[20, 5], [30, 10], [10, 15]]) == 116\n assert candidate(target = 250,types = [[50, 5], [50, 10], [50, 15], [50, 20], [50, 25]]) == 3765\n assert candidate(target = 600,types = [[30, 10], [20, 20], [10, 30], [5, 40]]) == 858\n assert candidate(target = 300,types = [[10, 2], [20, 3], [30, 5], [40, 7], [50, 11]]) == 18034\n assert candidate(target = 900,types = [[50, 1], [50, 2], [50, 5], [50, 10]]) == 1\n assert candidate(target = 400,types = [[20, 10], [20, 20], [20, 30], [20, 40], [20, 50]]) == 1583\n assert candidate(target = 250,types = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]]) == 57127\n assert candidate(target = 800,types = [[40, 10], [30, 20], [20, 30], [10, 40]]) == 3041\n assert candidate(target = 200,types = [[10, 5], [10, 10], [10, 15], [10, 20], [10, 25]]) == 1003\n assert candidate(target = 600,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5], [50, 6], [50, 7], [50, 8], [50, 9], [50, 10]]) == 209801687\n assert candidate(target = 300,types = [[10, 10], [20, 20], [30, 30], [40, 40]]) == 203\n assert candidate(target = 900,types = [[20, 5], [30, 10], [40, 15], [10, 20], [10, 25]]) == 21573\n assert candidate(target = 750,types = [[50, 1], [50, 2], [50, 3], [50, 4], [50, 5], [50, 6], [50, 7], [50, 8], [50, 9], [50, 10]]) == 450083451\n", "comparison": "exact"}, "public_tests": ["6\n[[6,1],[3,2],[2,3]]", "5\n[[50,1],[50,2],[50,5]]", "18\n[[6,1],[3,2],[2,3]]"], "hints": ["Use Dynamic Programming", "Let ways[i][points] be the number of ways to score a given number of points after solving some questions of the first i types.", "ways[i][points] is equal to the sum of ways[i-1][points - solved * marks[i] over 0 <= solved <= count_i"], "metadata": {"canonical_parameter_names": ["target", "types"], "leetcode_dataset_entry_point": "Solution().waysToReachTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:08+00:00", "tests_total": 117, "tests_dropped": 38, "flags": [], "topic_tags": ["array", "dynamic-programming", "knapsack-problem", "multiple-knapsack"]}, "language": "ruby", "interface": {"raw_signature": "def ways_to_reach_target(target, types)", "container": null, "callable": "ways_to_reach_target", "parameters": [{"name": "target", "type": "Integer"}, {"name": "types", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2586, "task_id": "count-the-number-of-vowel-strings-in-range", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array of string words and two integers left and right.\n\nA string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.\n\nReturn the number of vowel strings words[i] where i belongs to the inclusive range [left, right].\n\nExample 1:\n\nInput: words = [\"are\",\"amy\",\"u\"], left = 0, right = 2\nOutput: 2\nExplanation:\n- \"are\" is a vowel string because it starts with 'a' and ends with 'e'.\n- \"amy\" is not a vowel string because it does not end with a vowel.\n- \"u\" is a vowel string because it starts with 'u' and ends with 'u'.\nThe number of vowel strings in the mentioned range is 2.\n\nExample 2:\n\nInput: words = [\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"], left = 1, right = 4\nOutput: 3\nExplanation:\n- \"aeo\" is a vowel string because it starts with 'a' and ends with 'o'.\n- \"mu\" is not a vowel string because it does not start with a vowel.\n- \"ooo\" is a vowel string because it starts with 'o' and ends with 'o'.\n- \"artro\" is a vowel string because it starts with 'a' and ends with 'o'.\nThe number of vowel strings in the mentioned range is 3.\n\nConstraints:\n\n- 1 <= words.length <= 1000\n- 1 <= words[i].length <= 10\n- words[i] consists of only lowercase English letters.\n- 0 <= left <= right < words.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['sky', 'fly', 'why'],left = 0,right = 2) == 0\n assert candidate(words = ['apple', 'banana', 'orange', 'umbrella'],left = 0,right = 3) == 3\n assert candidate(words = ['are', 'amy', 'u'],left = 0,right = 2) == 2\n assert candidate(words = ['hey', 'aeo', 'mu', 'ooo', 'artro'],left = 1,right = 4) == 3\n assert candidate(words = ['up', 'open', 'over'],left = 1,right = 2) == 0\n assert candidate(words = ['ae', 'ea', 'ei', 'ie', 'ou'],left = 0,right = 4) == 5\n assert candidate(words = ['aeiou', 'uoiea', 'aeiou', 'uoiea', 'aeiou', 'uoiea'],left = 0,right = 5) == 6\n assert candidate(words = ['sky', 'fly', 'why', 'a', 'e'],left = 0,right = 4) == 2\n assert candidate(words = ['ocean', 'mountain', 'forest', 'desert', 'rain'],left = 0,right = 4) == 0\n assert candidate(words = ['beautiful', 'world', 'with', 'diverse', 'languages'],left = 2,right = 4) == 0\n assert candidate(words = ['aeiou', 'uoiea', 'uiaeou', 'ouaei', 'eioua'],left = 0,right = 4) == 5\n assert candidate(words = ['xylophone', 'zephyr', 'orchestra', 'xylophone', 'aeiou', 'uoiea', 'uoiea'],left = 0,right = 6) == 4\n assert candidate(words = ['aaa', 'eee', 'iii', 'ooo', 'uuu', 'aaee', 'eeaa', 'aeea', 'aaea', 'eeea', 'eaae', 'eaeaa', 'aeaae', 'aaeae'],left = 0,right = 13) == 14\n assert candidate(words = ['queue', 'adieu', 'ice', 'ocean', 'earth'],left = 0,right = 3) == 2\n assert candidate(words = ['umbrella', 'moon', 'noon', 'noon', 'moon'],left = 2,right = 4) == 0\n assert candidate(words = ['algorithm', 'education', 'umbrella', 'icecream', 'operation', 'university'],left = 1,right = 5) == 1\n assert candidate(words = ['elephant', 'umbrella', 'apple', 'orange', 'ice', 'echo', 'umbrella'],left = 1,right = 6) == 6\n assert candidate(words = ['vowel', 'nonvowel', 'aeiou', 'bvowel', 'endvowel'],left = 0,right = 4) == 1\n assert candidate(words = ['aabb', 'abba', 'baab', 'baba', 'abab'],left = 0,right = 4) == 1\n assert candidate(words = ['example', 'samples', 'tests', 'inputs', 'outputs'],left = 0,right = 4) == 1\n assert candidate(words = ['xyz', 'uvw', 'qwe', 'rty', 'poi'],left = 0,right = 4) == 0\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],left = 0,right = 24) == 5\n assert candidate(words = ['eeeee', 'aaaaa', 'iiiii', 'ooooo', 'uuuuu', 'auaeu', 'eiaie', 'ouioo', 'uaeuu', 'ieoia'],left = 2,right = 9) == 8\n assert candidate(words = ['banana', 'orange', 'grape', 'kiwi', 'pear', 'peach', 'plum', 'grapefruit', 'blueberry', 'cherry'],left = 3,right = 9) == 0\n assert candidate(words = ['racecar', 'level', 'rotor', 'kayak', 'reviler'],left = 1,right = 4) == 0\n assert candidate(words = ['quick', 'brown', 'fox', 'jumps', 'over', 'lazy', 'dog'],left = 1,right = 5) == 0\n assert candidate(words = ['aardvark', 'elephant', 'iguana', 'okapi', 'umbrella'],left = 0,right = 4) == 3\n assert candidate(words = ['vowel', 'voewl', 'ovwle', 'wolve', 'volve'],left = 0,right = 4) == 1\n assert candidate(words = ['ar', 'er', 'ir', 'or', 'ur'],left = 1,right = 4) == 0\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'],left = 0,right = 9) == 10\n assert candidate(words = ['a', 'e', 'i', 'o', 'u', 'aeiou'],left = 0,right = 5) == 6\n assert candidate(words = ['racecar', 'level', 'rotor', 'deified', 'repaper'],left = 1,right = 4) == 0\n assert candidate(words = ['volcano', 'trident', 'ozone', 'ocean', 'mountain'],left = 2,right = 4) == 1\n assert candidate(words = ['zzzzz', 'yyyyy', 'xxxxx', 'wwwww', 'vvvvv'],left = 0,right = 4) == 0\n assert candidate(words = ['education', 'university', 'algorithm', 'openai'],left = 1,right = 3) == 1\n assert candidate(words = ['aeiou', 'bcd', 'efg', 'hij', 'klm', 'nop', 'qrst', 'uvw', 'xyz'],left = 2,right = 7) == 0\n assert candidate(words = ['aardvark', 'algorithm', 'antelope', 'antenna', 'apple', 'antiquity', 'apricot', 'atlas'],left = 1,right = 7) == 3\n assert candidate(words = ['aeiou', 'uoiea', 'iouea', 'uaieo', 'oieau', 'aeo', 'uoiea', 'uoiea', 'uoiea', 'uoiea', 'uoiea', 'uoiea'],left = 0,right = 11) == 12\n assert candidate(words = ['start', 'end', 'begin', 'finish', 'conclude'],left = 0,right = 4) == 0\n assert candidate(words = ['education', 'is', 'awesome', 'and', 'effective'],left = 1,right = 4) == 2\n assert candidate(words = ['xyz', 'uvw', 'qrs', 'tuv', 'lmn', 'opq'],left = 1,right = 5) == 0\n assert candidate(words = ['aeiou', 'ueiou', 'ieoai', 'oeuia', 'uaeio'],left = 0,right = 4) == 5\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'],left = 0,right = 14) == 4\n assert candidate(words = ['aeiou', 'uaeiou', 'aeu', 'aue', 'eua'],left = 0,right = 4) == 5\n assert candidate(words = ['bcd', 'efg', 'hij', 'klm', 'nop'],left = 0,right = 4) == 0\n assert candidate(words = ['a', 'e', 'i', 'o', 'u'],left = 0,right = 4) == 5\n assert candidate(words = ['umbrella', 'raincoat', 'scarf', 'boots', 'gloves', 'jacket', 'shoes', 'hat', 'mittens', 'gloves', 'umbrella', 'hat'],left = 0,right = 11) == 2\n assert candidate(words = ['a', 'a', 'a', 'a', 'a', 'a'],left = 0,right = 5) == 6\n assert candidate(words = ['aeiou', 'uoiea', 'aieou', 'euoia', 'oueai'],left = 0,right = 4) == 5\n assert candidate(words = ['aabbcc', 'ddeeff', 'gghhii', 'jjkkll', 'mmnnoo'],left = 0,right = 4) == 0\n assert candidate(words = ['education', 'algorithm', 'umbrella', 'opposite', 'idea'],left = 0,right = 4) == 3\n assert candidate(words = ['aeiouaeiou', 'uoieauoiea', 'aieouaieou', 'euoiaeuoia', 'oueaioueai'],left = 1,right = 3) == 3\n assert candidate(words = ['aaa', 'eee', 'iii', 'ooo', 'uuu'],left = 0,right = 4) == 5\n assert candidate(words = ['education', 'umbrella', 'idea', 'algorithm', 'elephant'],left = 1,right = 4) == 2\n assert candidate(words = ['abacaxi', 'elderberry', 'fig', 'grape', 'honeydew', 'kiwi', 'lemon', 'mango', 'nectarine', 'orange', 'papaya', 'quince'],left = 0,right = 11) == 2\n assert candidate(words = ['aeiou', 'uoiea', 'ioeau', 'oaeiu', 'ueiao'],left = 0,right = 4) == 5\n assert candidate(words = ['aaaaa', 'eeeee', 'iiiii', 'ooooo', 'uuuuu'],left = 1,right = 3) == 3\n assert candidate(words = ['sequence', 'encounter', 'interval', 'equation', 'occasion'],left = 2,right = 4) == 0\n assert candidate(words = ['acoustic', 'analysis', 'bassoon', 'clarinet', 'didgeridoo', 'flute', 'guitar', 'harp', 'harp', 'piano', 'tuba'],left = 2,right = 10) == 0\n assert candidate(words = ['ae', 'ea', 'oi', 'io', 'ou', 'uo'],left = 0,right = 5) == 6\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],left = 0,right = 4) == 2\n assert candidate(words = ['elephant', 'giraffe', 'hippo', 'iguana', 'jaguar'],left = 0,right = 4) == 1\n assert candidate(words = ['xylophone', 'xylo', 'yolo', 'mono', 'neon'],left = 1,right = 4) == 0\n assert candidate(words = ['sequence', 'structure', 'synergy', 'symmetry', 'spectrum', 'syzygy'],left = 2,right = 5) == 0\n assert candidate(words = ['vowel', 'words', 'only', 'here', 'now'],left = 0,right = 4) == 0\n assert candidate(words = ['aeiou', 'eioua', 'iouae', 'ouaei', 'uaeio'],left = 0,right = 4) == 5\n assert candidate(words = ['vowel', 'start', 'end', 'middle', 'zone', 'sequence'],left = 2,right = 5) == 0\n assert candidate(words = ['sequence', 'queue', 'deque', 'peep', 'beep', 'keel', 'heel', 'heal', 'heap', 'heap', 'jeep', 'weep'],left = 1,right = 11) == 0\n assert candidate(words = ['elephant', 'antelope', 'giraffe', 'hippo', 'iguana', 'jackal', 'kangaroo', 'lemur'],left = 1,right = 7) == 2\n", "comparison": "exact"}, "public_tests": ["[\"are\",\"amy\",\"u\"]\n0\n2", "[\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"]\n1\n4"], "hints": ["consider iterating over all strings from left to right and use an if condition to check if the first character and last character are vowels."], "metadata": {"canonical_parameter_names": ["words", "left", "right"], "leetcode_dataset_entry_point": "Solution().vowelStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:11+00:00", "tests_total": 99, "tests_dropped": 30, "flags": [], "topic_tags": ["array", "string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def vowel_strings(words, left, right)", "container": null, "callable": "vowel_strings", "parameters": [{"name": "words", "type": "String[]"}, {"name": "left", "type": "Integer"}, {"name": "right", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2587, "task_id": "rearrange-array-to-maximize-prefix-score", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).\n\nLet prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of nums is the number of positive integers in the array prefix.\n\nReturn the maximum score you can achieve.\n\nExample 1:\n\nInput: nums = [2,-1,0,1,-3,3,-3]\nOutput: 6\nExplanation: We can rearrange the array into nums = [2,3,1,-1,-3,0,-3].\nprefix = [2,5,6,5,2,2,-1], so the score is 6.\nIt can be shown that 6 is the maximum score we can obtain.\n\nExample 2:\n\nInput: nums = [-2,-3,0]\nOutput: 0\nExplanation: Any rearrangement of the array will result in a score of 0.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^6 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, -1, 3, 2, -4, 0, 2]) == 7\n assert candidate(nums = [-1]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 5\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, -2, 3, 1, -4, 7]) == 6\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 9\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, -1, 3, -2, 4, 0]) == 6\n assert candidate(nums = [5, -2, 3, 1, -4, 7, -1]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [-2, -3, 0]) == 0\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [5, -1, 3, -2, 4, 0, -6, 2]) == 8\n assert candidate(nums = [2, -1, 0, 1, -3, 3, -3]) == 6\n assert candidate(nums = [-5, 1, -3, 2, -4, 0]) == 3\n assert candidate(nums = [1000000, -1000000, 1000000, -1000000, 1000000]) == 5\n assert candidate(nums = [1000000, -1000000, 1000000, -1000000, 0]) == 4\n assert candidate(nums = [1000000, -500000, 500000, -250000, 250000, -125000, 125000, -62500, 62500, -31250, 31250]) == 11\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10]) == 10\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600]) == 11\n assert candidate(nums = [1000000, -500000, 500000, -250000, 250000, -125000, 125000]) == 7\n assert candidate(nums = [50, 40, 30, 20, 10, -10, -20, -30, -40, -50, -60, -70, -80]) == 9\n assert candidate(nums = [-1, -2, -3, -4, -5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, -5, -5, -5, -5, -5, 10, 10, 10, 10, 10, -10, -10, -10, -10, -10]) == 17\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == 20\n assert candidate(nums = [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]) == 9\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1]) == 11\n assert candidate(nums = [-5, 4, -3, 2, -1, 1, -2, 3, -4, 5]) == 9\n assert candidate(nums = [1000000, 999999, 999998, -1000000, -999999, -999998, 0, 0, 0]) == 8\n assert candidate(nums = [100000, -100000, 90000, -90000, 80000, -80000, 70000, -70000, 60000, -60000, 50000, -50000, 40000, -40000, 30000, -30000, 20000, -20000, 10000, -10000]) == 19\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20]) == 19\n assert candidate(nums = [1000000, -999999, 1, -1, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums = [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, -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, 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, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == 19\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 55]) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 20\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4, 5]) == 19\n assert candidate(nums = [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5, -6, -7, -8, -9, -10]) == 9\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 9\n assert candidate(nums = [500000, 400000, 300000, 200000, 100000, -100000, -200000, -300000, -400000, -500000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 19\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 9\n assert candidate(nums = [1000000, 999999, -1000000, 999998, -999999, 1]) == 6\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7]) == 14\n assert candidate(nums = [1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1]) == 11\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 10\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, -1000000, -999999, -999998, -999997, -999996]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 6, 7, 8, 9, 10, -6, -7, -8, -9, -10]) == 19\n assert candidate(nums = [-1, -2, -3, -4, -5, 1, 2, 3, 4, 5]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 6, 7, 8, 9, 10]) == 15\n assert candidate(nums = [1000000, -1000000, 1000000, -1000000, 1000000, -1000000, 1000000, -1000000, 1000000, -1000000]) == 9\n assert candidate(nums = [500000, 500000, 500000, 500000, 500000, 500000, -1000000, -1000000, -1000000, -1000000]) == 8\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 19\n assert candidate(nums = [10, 20, 30, -60, 40, 50, -70, 60, 70, 80, 90, -450]) == 11\n assert candidate(nums = [5, 4, 3, 2, 1, -1, -2, -3, -4, -5, 6, 7, 8, 9, 10]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, -10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [50, -50, 40, -40, 30, -30, 20, -20, 10, -10]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50]) == 9\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, -1]) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10]) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [999999, -1, 999998, -2, 999997, -3, 999996, -4, 999995, -5, 999994, -6, 999993, -7, 999992, -8]) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, -100, -200, -300, -400, -500, -600, -700, -800, -900]) == 11\n assert candidate(nums = [-1, -2, -3, -4, -5, 1, 2, 3, 4, 5, 6]) == 11\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, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == 29\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, 100, 200, 300, 400, 500, 600, 700, 800, 900]) == 18\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 55]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, -15, 10, -20, 25, -30]) == 9\n assert candidate(nums = [-1000000, -999999, -999998, 1000000, 999999, 999998, 0, 0, 0]) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, -100, -200, -300, -400, -500, 0, 0, 0, 0, 0]) == 14\n assert candidate(nums = [-1000000, -1000000, -1000000, 1000000, 1000000, 1000000, 1000000]) == 7\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -2, -3, -4, -5]) == 20\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 16\n assert candidate(nums = [-1000000, -999999, -999998, -999997, -999996, -999995, -999994, -999993, -999992, -999991]) == 0\n assert candidate(nums = [1000000, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 10\n assert candidate(nums = [999999, 1, -999999, -1, 999999, -999999]) == 5\n assert candidate(nums = [-500000, -400000, -300000, -200000, -100000, 100000, 200000, 300000, 400000, 500000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 19\n assert candidate(nums = [-1000000, 1000000, -1000000, 1000000, -1000000, 1000000]) == 5\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -55]) == 10\n assert candidate(nums = [100000, -50000, 50000, -10000, 20000, -5000, 3000, 1000, -1000, 500, 50, 5, 1]) == 13\n assert candidate(nums = [100, -50, 200, -100, 300, -150, 400, -200, 500]) == 9\n assert candidate(nums = [-1, -2, -3, -4, -5, 20, -10, 30, -25, 40]) == 10\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 9\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 15\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 19\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 0\n assert candidate(nums = [999999, -999999, 999998, -999998, 999997, -999997, 999996, -999996]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -55]) == 10\n", "comparison": "exact"}, "public_tests": ["[2,-1,0,1,-3,3,-3]", "[-2,-3,0]"], "hints": ["The best order of the array is in decreasing order.", "Sort the array in decreasing order and count the number of positive values in the prefix sum array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:13+00:00", "tests_total": 105, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "greedy", "sorting", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def max_score(nums)", "container": null, "callable": "max_score", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2588, "task_id": "count-the-number-of-beautiful-subarrays", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. In one operation, you can:\n\n- Choose two different indices i and j such that 0 <= i, j < nums.length.\n- Choose a non-negative integer k such that the k^th bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.\n- Subtract 2^k from nums[i] and nums[j].\n\nA subarray is beautiful if it is possible to make all of its elements equal to 0 after applying the above operation any number of times (including zero).\n\nReturn the number of beautiful subarrays in the array nums.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nNote: Subarrays where all elements are initially 0 are considered beautiful, as no operation is needed.\n\nExample 1:\n\nInput: nums = [4,3,1,2,4]\nOutput: 2\nExplanation: There are 2 beautiful subarrays in nums: [4,3,1,2,4] and [4,3,1,2,4].\n- We can make all elements in the subarray [3,1,2] equal to 0 in the following way:\n - Choose [3, 1, 2] and k = 1. Subtract 2^1 from both numbers. The subarray becomes [1, 1, 0].\n - Choose [1, 1, 0] and k = 0. Subtract 2^0 from both numbers. The subarray becomes [0, 0, 0].\n- We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:\n - Choose [4, 3, 1, 2, 4] and k = 2. Subtract 2^2 from both numbers. The subarray becomes [0, 3, 1, 2, 0].\n - Choose [0, 3, 1, 2, 0] and k = 0. Subtract 2^0 from both numbers. The subarray becomes [0, 2, 0, 2, 0].\n - Choose [0, 2, 0, 2, 0] and k = 1. Subtract 2^1 from both numbers. The subarray becomes [0, 0, 0, 0, 0].\n\nExample 2:\n\nInput: nums = [1,10,4]\nOutput: 0\nExplanation: There are no beautiful subarrays in nums.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 25\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [2, 4, 6, 8, 10]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [8, 1, 2, 12, 7]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5]) == 6\n assert candidate(nums = [8, 8, 8, 8, 8]) == 6\n assert candidate(nums = [0, 0, 0, 0, 0]) == 15\n assert candidate(nums = [5, 5, 5, 5]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [1, 10, 4]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [8, 12, 10, 14, 16]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 2\n assert candidate(nums = [8, 14, 4, 8, 7]) == 0\n assert candidate(nums = [0, 0, 0, 0]) == 10\n assert candidate(nums = [2, 2, 2, 2]) == 4\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 0\n assert candidate(nums = [4, 3, 1, 2, 4]) == 2\n assert candidate(nums = [8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) == 6\n assert candidate(nums = [1024, 512, 256, 128, 64]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 25\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 0\n assert candidate(nums = [2, 2, 2, 2, 2]) == 6\n assert candidate(nums = [15, 15, 15, 15, 15]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 16\n assert candidate(nums = [21, 33, 45, 57, 69, 81, 93, 105, 117, 129]) == 2\n assert candidate(nums = [31, 15, 7, 3, 1, 1, 3, 7, 15, 31]) == 5\n assert candidate(nums = [32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 25\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 10\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35]) == 4\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 0\n assert candidate(nums = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3]) == 45\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 16\n assert candidate(nums = [5, 3, 15, 6, 9, 2, 8, 12]) == 2\n assert candidate(nums = [1023, 1023, 511, 511, 255, 255, 127, 127, 63, 63, 31, 31, 15, 15, 7, 7, 3, 3, 1, 1]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 16\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 210\n assert candidate(nums = [5, 3, 8, 10, 14, 12, 6, 4, 2, 1]) == 5\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 100\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1023, 511, 255]) == 0\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 0\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 56\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 55\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 6\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61]) == 0\n assert candidate(nums = [4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095]) == 64\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]) == 56\n assert candidate(nums = [13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57]) == 6\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 100\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) == 7\n assert candidate(nums = [5, 7, 1, 3, 9, 6, 2, 8, 4, 10]) == 2\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 0\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 1, 3, 7, 15, 31]) == 5\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 0\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 255]) == 2\n assert candidate(nums = [3, 5, 11, 7, 3, 5, 11, 7]) == 1\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1, 3, 15, 31]) == 2\n assert candidate(nums = [23, 17, 5, 10, 14, 6, 9, 3, 11, 15, 2, 7, 13]) == 2\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210]) == 12\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 100\n assert candidate(nums = [32, 16, 8, 4, 2, 1, 1, 2, 4, 8, 16, 32, 1, 2, 4, 8, 16, 32]) == 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]) == 100\n assert candidate(nums = [31, 28, 19, 5, 11, 23, 17, 7, 9, 3]) == 2\n assert candidate(nums = [7, 5, 3, 2, 5, 3, 7, 2]) == 2\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023]) == 25\n assert candidate(nums = [1, 3, 2, 7, 6, 5, 4, 15, 14, 13, 12, 11, 10, 9, 8]) == 16\n assert candidate(nums = [31, 14, 7, 14, 31]) == 0\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 16\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 0\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1]) == 45\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 0\n assert candidate(nums = [31, 14, 7, 15, 28, 21, 24, 13, 26, 19]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 49\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 16\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 25\n assert candidate(nums = [31, 17, 15, 23, 29, 31, 19, 23, 29]) == 0\n assert candidate(nums = [65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535]) == 16\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 4\n assert candidate(nums = [31, 14, 7, 3, 1, 0, 1, 3, 7, 14, 31]) == 6\n assert candidate(nums = [9, 5, 12, 6, 3, 15, 8, 4, 10, 2, 7, 11, 1, 13, 14]) == 8\n assert candidate(nums = [29, 25, 21, 17, 13, 9, 5, 1, 1, 5, 9, 13, 17, 21, 25, 29]) == 20\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135]) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 0\n assert candidate(nums = [5, 3, 7, 2, 1, 10, 6, 8, 4, 12]) == 3\n assert candidate(nums = [1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1]) == 70\n assert candidate(nums = [9, 3, 7, 15, 31, 15, 7, 3, 9]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 4\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 4\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13]) == 56\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61, 30, 15, 7, 3, 1]) == 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]) == 100\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 0\n assert candidate(nums = [64, 32, 16, 8, 4, 2, 1, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums = [3, 1, 5, 7, 2, 4, 6, 8, 10, 12]) == 6\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 1, 3, 7, 15, 31, 63, 127, 255]) == 8\n assert candidate(nums = [13, 11, 7, 5, 3, 2, 1, 1, 2, 3, 5, 7, 11, 13]) == 9\n assert candidate(nums = [31, 14, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]) == 27\n assert candidate(nums = [17, 34, 68, 136, 272, 544, 1088, 2176, 4352, 8704, 17408, 34816, 69632, 139264, 278528]) == 0\n assert candidate(nums = [5, 3, 6, 12, 5, 3, 6, 12]) == 4\n", "comparison": "exact"}, "public_tests": ["[4,3,1,2,4]", "[1,10,4]"], "hints": ["A subarray is beautiful if its xor is equal to zero.", "Compute the prefix xor for every index, then the xor of subarray [left, right] is equal to zero if prefix_xor[left] ^ perfix_xor[right] == 0", "Iterate from left to right and maintain a hash table to count the number of indices equal to the current prefix xor."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().beautifulSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:16+00:00", "tests_total": 121, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def beautiful_subarrays(nums)", "container": null, "callable": "beautiful_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2589, "task_id": "minimum-time-to-complete-all-tasks", "difficulty": "Hard", "problem_description": "There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [start_i, end_i, duration_i] indicates that the i^th task should run for a total of duration_i seconds (not necessarily continuous) within the inclusive time range [start_i, end_i].\n\nYou may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.\n\nReturn the minimum time during which the computer should be turned on to complete all tasks.\n\nExample 1:\n\nInput: tasks = [[2,3,1],[4,5,1],[1,5,2]]\nOutput: 2\nExplanation:\n- The first task can be run in the inclusive time range [2, 2].\n- The second task can be run in the inclusive time range [5, 5].\n- The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].\nThe computer will be on for a total of 2 seconds.\n\nExample 2:\n\nInput: tasks = [[1,3,2],[2,5,3],[5,6,2]]\nOutput: 4\nExplanation:\n- The first task can be run in the inclusive time range [2, 3].\n- The second task can be run in the inclusive time ranges [2, 3] and [5, 5].\n- The third task can be run in the two inclusive time range [5, 6].\nThe computer will be on for a total of 4 seconds.\n\nConstraints:\n\n- 1 <= tasks.length <= 2000\n- tasks[i].length == 3\n- 1 <= start_i, end_i <= 2000\n- 1 <= duration_i <= end_i - start_i + 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [[1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1]]) == 2\n assert candidate(tasks = [[1, 100, 50], [50, 150, 50], [100, 200, 50]]) == 99\n assert candidate(tasks = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]) == 5\n assert candidate(tasks = [[1, 2, 1], [1, 2, 1], [1, 2, 1]]) == 1\n assert candidate(tasks = [[1, 100, 50], [50, 150, 50], [150, 200, 50]]) == 100\n assert candidate(tasks = [[1, 10, 10], [2, 9, 8], [3, 8, 6], [4, 7, 4], [5, 6, 2]]) == 10\n assert candidate(tasks = [[5, 10, 5], [15, 20, 5], [25, 30, 5]]) == 15\n assert candidate(tasks = [[1, 10, 10], [10, 20, 5], [20, 30, 5]]) == 18\n assert candidate(tasks = [[1, 5, 1], [2, 6, 2], [3, 7, 3], [4, 8, 4]]) == 4\n assert candidate(tasks = [[10, 20, 5], [20, 30, 5], [30, 40, 5], [40, 50, 5]]) == 17\n assert candidate(tasks = [[5, 10, 3], [10, 15, 3], [15, 20, 4]]) == 8\n assert candidate(tasks = [[1, 3, 2], [2, 5, 3], [5, 6, 2]]) == 4\n assert candidate(tasks = [[1, 5, 5], [6, 10, 5], [11, 15, 5]]) == 15\n assert candidate(tasks = [[1, 2, 1], [2, 3, 1], [3, 4, 1]]) == 2\n assert candidate(tasks = [[1, 10, 10], [10, 20, 10], [20, 30, 10]]) == 28\n assert candidate(tasks = [[1, 10, 10]]) == 10\n assert candidate(tasks = [[1, 10, 5], [2, 9, 4], [3, 8, 3], [4, 7, 2]]) == 5\n assert candidate(tasks = [[2, 3, 1], [4, 5, 1], [1, 5, 2]]) == 2\n assert candidate(tasks = [[1, 10, 5], [10, 20, 5], [20, 30, 5]]) == 13\n assert candidate(tasks = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1]]) == 4\n assert candidate(tasks = [[1, 2, 2], [2, 3, 2], [3, 4, 2]]) == 4\n assert candidate(tasks = [[1, 100, 50], [51, 150, 50], [101, 200, 50]]) == 100\n assert candidate(tasks = [[1, 10, 5], [10, 20, 10], [15, 25, 10]]) == 18\n assert candidate(tasks = [[1, 20, 10], [5, 15, 5], [10, 25, 10]]) == 10\n assert candidate(tasks = [[1, 2, 1], [3, 4, 1], [5, 6, 1]]) == 3\n assert candidate(tasks = [[1, 5, 1], [2, 6, 1], [3, 7, 1], [4, 8, 1], [5, 9, 1], [6, 10, 1], [7, 11, 1], [8, 12, 1], [9, 13, 1], [10, 14, 1]]) == 2\n assert candidate(tasks = [[1, 3, 1], [2, 4, 1], [3, 5, 1], [4, 6, 1], [5, 7, 1], [6, 8, 1], [7, 9, 1], [8, 10, 1], [9, 11, 1], [10, 12, 1]]) == 4\n assert candidate(tasks = [[1, 500, 250], [200, 600, 200], [300, 700, 150], [400, 800, 100]]) == 250\n assert candidate(tasks = [[1, 10, 5], [1, 10, 5], [1, 10, 5], [1, 10, 5], [1, 10, 5]]) == 5\n assert candidate(tasks = [[1, 5, 2], [2, 4, 2], [3, 4, 2], [4, 5, 2], [5, 6, 2]]) == 4\n assert candidate(tasks = [[1, 50, 25], [25, 75, 25], [50, 100, 25], [75, 125, 25], [100, 150, 25], [125, 175, 25], [150, 200, 25]]) == 97\n assert candidate(tasks = [[1, 5, 5], [5, 10, 5], [10, 15, 5], [15, 20, 5]]) == 17\n assert candidate(tasks = [[10, 20, 1], [11, 21, 1], [12, 22, 1], [13, 23, 1], [14, 24, 1], [15, 25, 1], [16, 26, 1], [17, 27, 1], [18, 28, 1], [19, 29, 1]]) == 1\n assert candidate(tasks = [[1, 100, 10], [20, 120, 20], [40, 140, 30], [60, 160, 40], [80, 180, 50], [100, 190, 60]]) == 69\n assert candidate(tasks = [[1, 10, 10], [2, 15, 5], [3, 20, 3], [4, 25, 2], [5, 30, 1], [6, 35, 2], [7, 40, 3], [8, 45, 4], [9, 50, 5], [10, 55, 6]]) == 15\n assert candidate(tasks = [[10, 20, 10], [15, 30, 5], [20, 40, 3], [25, 50, 2], [30, 60, 1], [35, 70, 2], [40, 80, 3], [45, 90, 4], [50, 100, 5]]) == 17\n assert candidate(tasks = [[1, 10, 5], [1, 10, 5], [1, 10, 5], [1, 10, 5], [1, 10, 5], [1, 10, 5]]) == 5\n assert candidate(tasks = [[1, 2000, 1000], [500, 1500, 1000], [1000, 2000, 1000], [1, 1000, 500], [1001, 2000, 500]]) == 1499\n assert candidate(tasks = [[10, 20, 5], [15, 25, 4], [20, 30, 3], [25, 35, 2], [30, 40, 1], [35, 45, 2], [40, 50, 3], [45, 55, 4], [50, 60, 5], [55, 65, 6]]) == 17\n assert candidate(tasks = [[1, 2000, 1000], [500, 1500, 500], [1000, 2000, 1000], [1500, 2000, 500], [1, 1000, 500], [500, 1000, 250]]) == 1499\n assert candidate(tasks = [[1, 20, 15], [5, 15, 10], [10, 25, 12], [15, 30, 10]]) == 19\n assert candidate(tasks = [[1, 10, 9], [2, 10, 8], [3, 10, 7], [4, 10, 6], [5, 10, 5]]) == 9\n assert candidate(tasks = [[1, 10, 1], [2, 3, 1], [4, 5, 1], [6, 7, 1], [8, 9, 1], [10, 10, 1]]) == 5\n assert candidate(tasks = [[1, 1000, 500], [1, 1000, 500], [1, 1000, 500], [1, 1000, 500], [1, 1000, 500]]) == 500\n assert candidate(tasks = [[5, 15, 10], [10, 20, 5], [15, 25, 3], [20, 30, 2], [25, 35, 1]]) == 12\n assert candidate(tasks = [[1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4], [1, 5, 5]]) == 5\n assert candidate(tasks = [[1, 5, 1], [2, 6, 1], [3, 7, 1], [4, 8, 1], [5, 9, 1], [6, 10, 1], [7, 11, 1], [8, 12, 1], [9, 13, 1], [10, 14, 1]]) == 2\n assert candidate(tasks = [[1, 1000, 500], [200, 800, 300], [400, 600, 200], [500, 700, 150]]) == 500\n assert candidate(tasks = [[1, 2, 1], [3, 4, 1], [5, 6, 1], [7, 8, 1], [9, 10, 1], [11, 12, 1], [13, 14, 1], [15, 16, 1], [17, 18, 1], [19, 20, 1]]) == 10\n assert candidate(tasks = [[1, 500, 250], [250, 750, 300], [500, 1000, 350], [750, 1250, 400], [1000, 1500, 450]]) == 1048\n assert candidate(tasks = [[1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3], [1, 10, 3]]) == 3\n assert candidate(tasks = [[1, 10, 3], [2, 9, 5], [3, 8, 4], [4, 7, 1], [5, 6, 2]]) == 5\n assert candidate(tasks = [[1, 10, 10], [1, 10, 10], [1, 10, 10], [1, 10, 10], [1, 10, 10], [1, 10, 10], [1, 10, 10], [1, 10, 10], [1, 10, 10]]) == 10\n assert candidate(tasks = [[1, 3, 3], [4, 6, 2], [7, 9, 1], [10, 12, 3], [13, 15, 2]]) == 11\n assert candidate(tasks = [[5, 10, 5], [10, 15, 5], [15, 20, 5], [20, 25, 5], [25, 30, 5], [30, 35, 5], [35, 40, 5], [40, 45, 5]]) == 33\n assert candidate(tasks = [[1, 50, 25], [25, 75, 30], [50, 100, 35], [75, 125, 40], [100, 150, 45]]) == 103\n assert candidate(tasks = [[1, 3, 3], [4, 6, 3], [7, 9, 3], [10, 12, 3], [13, 15, 3], [16, 18, 3], [19, 21, 3], [22, 24, 3], [25, 27, 3], [28, 30, 3]]) == 30\n assert candidate(tasks = [[1, 10, 3], [1, 20, 3], [1, 30, 3], [1, 40, 3], [1, 50, 3], [1, 60, 3], [1, 70, 3], [1, 80, 3], [1, 90, 3], [1, 100, 3]]) == 3\n assert candidate(tasks = [[1, 1000, 999], [500, 1500, 1000], [1000, 2000, 1000]]) == 1998\n assert candidate(tasks = [[1, 100, 99], [2, 150, 98], [3, 200, 97], [4, 250, 96], [5, 300, 95], [6, 350, 94], [7, 400, 93], [8, 450, 92], [9, 500, 91]]) == 99\n assert candidate(tasks = [[1, 2, 1], [3, 4, 1], [5, 6, 1], [7, 8, 1], [9, 10, 1], [11, 12, 1], [13, 14, 1], [15, 16, 1], [17, 18, 1], [19, 20, 1], [21, 22, 1], [23, 24, 1], [25, 26, 1], [27, 28, 1], [29, 30, 1]]) == 15\n assert candidate(tasks = [[1, 100, 50], [2, 90, 40], [3, 80, 30], [4, 70, 20], [5, 60, 10], [6, 50, 5], [7, 40, 3], [8, 30, 2], [9, 20, 1]]) == 50\n assert candidate(tasks = [[1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1], [1, 10, 1]]) == 1\n assert candidate(tasks = [[1, 2000, 2000], [10, 500, 400], [150, 800, 300], [300, 1800, 500], [1000, 1900, 600]]) == 2000\n assert candidate(tasks = [[1, 2000, 1000], [2, 1999, 999], [3, 1998, 998], [4, 1997, 997], [5, 1996, 996], [6, 1995, 995], [7, 1994, 994], [8, 1993, 993], [9, 1992, 992], [10, 1991, 991]]) == 1000\n assert candidate(tasks = [[1, 5, 5], [2, 6, 4], [3, 7, 3], [4, 8, 2], [5, 9, 1], [6, 10, 1], [7, 11, 1], [8, 12, 1], [9, 13, 1], [10, 14, 1]]) == 6\n assert candidate(tasks = [[1, 50, 10], [10, 20, 5], [20, 30, 5], [30, 40, 5], [40, 50, 5], [50, 60, 5], [60, 70, 5], [70, 80, 5], [80, 90, 5]]) == 33\n assert candidate(tasks = [[1, 100, 50], [50, 150, 60], [100, 200, 70], [150, 250, 80], [200, 300, 90]]) == 208\n assert candidate(tasks = [[1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1]]) == 5\n assert candidate(tasks = [[50, 150, 100], [100, 200, 100], [150, 250, 100], [200, 300, 100], [250, 350, 100], [300, 400, 100], [350, 450, 100], [400, 500, 100]]) == 446\n assert candidate(tasks = [[1, 10, 1], [2, 11, 2], [3, 12, 3], [4, 13, 4], [5, 14, 5], [6, 15, 6], [7, 16, 7], [8, 17, 8], [9, 18, 9], [10, 19, 10]]) == 10\n assert candidate(tasks = [[1, 5, 1], [6, 10, 1], [11, 15, 1], [16, 20, 1]]) == 4\n assert candidate(tasks = [[1, 100, 100], [50, 150, 50], [100, 200, 30], [150, 250, 20], [200, 300, 10]]) == 138\n assert candidate(tasks = [[1, 5, 5], [2, 6, 5], [3, 7, 5], [4, 8, 5], [5, 9, 5], [6, 10, 5], [7, 11, 5], [8, 12, 5], [9, 13, 5], [10, 14, 5]]) == 14\n assert candidate(tasks = [[1, 2000, 500], [2, 1999, 499], [3, 1998, 498], [4, 1997, 497], [5, 1996, 496], [6, 1995, 495], [7, 1994, 494], [8, 1993, 493], [9, 1992, 492], [10, 1991, 491]]) == 500\n assert candidate(tasks = [[1, 100, 50], [51, 150, 50], [101, 200, 50], [151, 250, 50], [201, 300, 50]]) == 150\n assert candidate(tasks = [[1, 100, 1], [2, 99, 1], [3, 98, 1], [4, 97, 1], [5, 96, 1], [6, 95, 1], [7, 94, 1], [8, 93, 1], [9, 92, 1], [10, 91, 1], [11, 90, 1], [12, 89, 1], [13, 88, 1], [14, 87, 1], [15, 86, 1], [16, 85, 1], [17, 84, 1], [18, 83, 1], [19, 82, 1], [20, 81, 1], [21, 80, 1], [22, 79, 1], [23, 78, 1], [24, 77, 1], [25, 76, 1], [26, 75, 1], [27, 74, 1], [28, 73, 1], [29, 72, 1], [30, 71, 1], [31, 70, 1], [32, 69, 1], [33, 68, 1], [34, 67, 1], [35, 66, 1], [36, 65, 1], [37, 64, 1], [38, 63, 1], [39, 62, 1], [40, 61, 1], [41, 60, 1], [42, 59, 1], [43, 58, 1], [44, 57, 1], [45, 56, 1], [46, 55, 1], [47, 54, 1], [48, 53, 1], [49, 52, 1], [50, 51, 1]]) == 1\n assert candidate(tasks = [[1, 3, 3], [2, 4, 2], [3, 5, 2], [4, 6, 2], [5, 7, 2], [6, 8, 2], [7, 9, 2]]) == 7\n assert candidate(tasks = [[1, 5, 5], [2, 10, 5], [3, 15, 5], [4, 20, 5], [5, 25, 5], [6, 30, 5]]) == 10\n assert candidate(tasks = [[1, 3, 1], [2, 5, 2], [3, 7, 3], [4, 9, 4], [5, 11, 5], [6, 13, 6], [7, 15, 7]]) == 9\n assert candidate(tasks = [[1, 50, 40], [25, 75, 30], [50, 100, 20], [75, 125, 10]]) == 59\n assert candidate(tasks = [[1, 20, 5], [1, 15, 5], [1, 10, 5], [1, 5, 5], [6, 10, 5], [11, 15, 5], [16, 20, 5]]) == 20\n assert candidate(tasks = [[1, 2000, 1000], [500, 1500, 500], [1000, 2000, 500], [1, 500, 100], [1500, 2000, 100]]) == 1000\n assert candidate(tasks = [[1, 2000, 1], [2, 2000, 2], [3, 2000, 3], [4, 2000, 4], [5, 2000, 5], [6, 2000, 6], [7, 2000, 7], [8, 2000, 8], [9, 2000, 9], [10, 2000, 10]]) == 10\n assert candidate(tasks = [[100, 200, 100], [150, 250, 100], [200, 300, 100], [250, 350, 100], [300, 400, 100]]) == 298\n assert candidate(tasks = [[1, 2000, 1000], [2, 1999, 999], [3, 1998, 998], [4, 1997, 997], [5, 1996, 996], [6, 1995, 995], [7, 1994, 994], [8, 1993, 993], [9, 1992, 992], [10, 1991, 991]]) == 1000\n assert candidate(tasks = [[1, 2000, 1000], [1000, 2000, 1000], [500, 1500, 500], [100, 1900, 900]]) == 1000\n assert candidate(tasks = [[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, 10, 1]]) == 1\n assert candidate(tasks = [[1, 100, 50], [50, 150, 50], [100, 200, 50], [150, 250, 50], [200, 300, 50]]) == 148\n assert candidate(tasks = [[1, 50, 25], [10, 60, 25], [20, 70, 25], [30, 80, 25], [40, 90, 25], [50, 100, 25], [60, 110, 25], [70, 120, 25], [80, 130, 25], [90, 140, 25]]) == 63\n assert candidate(tasks = [[1, 3, 1], [2, 4, 1], [3, 5, 1], [4, 6, 1], [5, 7, 1]]) == 2\n assert candidate(tasks = [[1, 5, 2], [1, 5, 2], [1, 5, 2], [1, 5, 2], [1, 5, 2]]) == 2\n assert candidate(tasks = [[1, 100, 50], [20, 150, 60], [30, 180, 70], [40, 200, 80]]) == 80\n assert candidate(tasks = [[1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4], [1, 5, 5], [2, 6, 1], [2, 6, 2], [2, 6, 3], [2, 6, 4], [2, 6, 5]]) == 6\n", "comparison": "exact"}, "public_tests": ["[[2,3,1],[4,5,1],[1,5,2]]", "[[1,3,2],[2,5,3],[5,6,2]]"], "hints": ["Sort the tasks in ascending order of end time", "Since there are only up to 2000 time points to consider, you can check them one by one", "It is always beneficial to run the task as late as possible so that later tasks can run simultaneously."], "metadata": {"canonical_parameter_names": ["tasks"], "leetcode_dataset_entry_point": "Solution().findMinimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:18+00:00", "tests_total": 112, "tests_dropped": 18, "flags": [], "topic_tags": ["array", "binary-search", "stack", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def find_minimum_time(tasks)", "container": null, "callable": "find_minimum_time", "parameters": [{"name": "tasks", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2591, "task_id": "distribute-money-to-maximum-children", "difficulty": "Easy", "problem_description": "You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.\n\nYou have to distribute the money according to the following rules:\n\n- All money must be distributed.\n- Everyone must receive at least 1 dollar.\n- Nobody receives 4 dollars.\n\nReturn the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money, return -1.\n\nExample 1:\n\nInput: money = 20, children = 3\nOutput: 1\nExplanation:\nThe maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:\n- 8 dollars to the first child.\n- 9 dollars to the second child.\n- 3 dollars to the third child.\nIt can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.\n\nExample 2:\n\nInput: money = 16, children = 2\nOutput: 2\nExplanation: Each child can be given 8 dollars.\n\nConstraints:\n\n- 1 <= money <= 200\n- 2 <= children <= 30\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(money = 150,children = 15) == 14\n assert candidate(money = 100,children = 5) == 4\n assert candidate(money = 15,children = 3) == 1\n assert candidate(money = 31,children = 3) == 2\n assert candidate(money = 7,children = 2) == 0\n assert candidate(money = 25,children = 4) == 3\n assert candidate(money = 8,children = 8) == 0\n assert candidate(money = 50,children = 6) == 5\n assert candidate(money = 28,children = 3) == 2\n assert candidate(money = 25,children = 5) == 2\n assert candidate(money = 150,children = 20) == 18\n assert candidate(money = 199,children = 25) == 24\n assert candidate(money = 100,children = 12) == 11\n assert candidate(money = 7,children = 3) == 0\n assert candidate(money = 16,children = 2) == 2\n assert candidate(money = 40,children = 5) == 5\n assert candidate(money = 30,children = 4) == 3\n assert candidate(money = 3,children = 2) == 0\n assert candidate(money = 4,children = 2) == 0\n assert candidate(money = 30,children = 3) == 2\n assert candidate(money = 31,children = 4) == 3\n assert candidate(money = 8,children = 2) == 0\n assert candidate(money = 20,children = 3) == 1\n assert candidate(money = 200,children = 30) == 24\n assert candidate(money = 72,children = 9) == 9\n assert candidate(money = 28,children = 4) == 2\n assert candidate(money = 32,children = 4) == 4\n assert candidate(money = 12,children = 2) == 0\n assert candidate(money = 25,children = 3) == 2\n assert candidate(money = 6,children = 2) == 0\n assert candidate(money = 1,children = 2) == -1\n assert candidate(money = 200,children = 25) == 25\n assert candidate(money = 10,children = 2) == 1\n assert candidate(money = 30,children = 5) == 3\n assert candidate(money = 50,children = 7) == 6\n assert candidate(money = 100,children = 10) == 9\n assert candidate(money = 15,children = 2) == 1\n assert candidate(money = 56,children = 7) == 7\n assert candidate(money = 24,children = 3) == 3\n assert candidate(money = 5,children = 2) == 0\n assert candidate(money = 50,children = 5) == 4\n", "comparison": "exact"}, "public_tests": ["20\n3", "16\n2"], "hints": ["Can we distribute the money according to the rules if we give 'k' children exactly 8 dollars?", "Brute force to find the largest possible value of k, or return -1 if there doesn’t exist any such k."], "metadata": {"canonical_parameter_names": ["money", "children"], "leetcode_dataset_entry_point": "Solution().distMoney", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:20+00:00", "tests_total": 47, "tests_dropped": 6, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def dist_money(money, children)", "container": null, "callable": "dist_money", "parameters": [{"name": "money", "type": "Integer"}, {"name": "children", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2592, "task_id": "maximize-greatness-of-an-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.\n\nWe define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].\n\nReturn the maximum possible greatness you can achieve after permuting nums.\n\nExample 1:\n\nInput: nums = [1,3,5,2,1,3,1]\nOutput: 4\nExplanation: One of the optimal rearrangements is perm = [2,5,1,3,3,1,1].\nAt indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation: We can prove the optimal perm is [2,3,4,1].\nAt indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4]) == 3\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == 5\n assert candidate(nums = [10000, 1000, 100, 10, 1]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 8\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 4\n assert candidate(nums = [1, 3, 5, 2, 1, 3, 1]) == 4\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == 4\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 18\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]) == 15\n assert candidate(nums = [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]) == 27\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 19\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9]) == 17\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]) == 28\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]) == 19\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 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]) == 10\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(nums = [1, 1, 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]) == 23\n assert candidate(nums = [10, 10, 10, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 9\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 24\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 18\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 28\n assert candidate(nums = [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]) == 24\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 9\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500]) == 13\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]) == 0\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19\n assert candidate(nums = [100, 101, 102, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88]) == 14\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 19\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 14\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 18\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, 4, 4, 4]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 18\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8]) == 15\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [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]) == 29\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 18\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]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 19\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 18\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 19\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, 1]) == 28\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]) == 29\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 18\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 18\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]) == 29\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 18\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 10, 20, 30, 40, 50]) == 23\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 12\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 45\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 14\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]) == 38\n assert candidate(nums = [1, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 13, 13]) == 17\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]) == 27\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 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]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 14\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 5, 4]) == 16\n", "comparison": "exact"}, "public_tests": ["[1,3,5,2,1,3,1]", "[1,2,3,4]"], "hints": ["Can we use sorting and two pointers here?", "Assign every element the next bigger unused element as many times as possible."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximizeGreatness", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:23+00:00", "tests_total": 86, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "two-pointers", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximize_greatness(nums)", "container": null, "callable": "maximize_greatness", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2593, "task_id": "find-score-of-an-array-after-marking-all-elements", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of positive integers.\n\nStarting with score = 0, apply the following algorithm:\n\n- Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.\n- Add the value of the chosen integer to score.\n- Mark the chosen element and its two adjacent elements if they exist.\n- Repeat until all the array elements are marked.\n\nReturn the score you get after applying the above algorithm.\n\nExample 1:\n\nInput: nums = [2,1,3,4,5,2]\nOutput: 7\nExplanation: We mark the elements as follows:\n- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].\n- 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].\n- 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].\nOur score is 1 + 2 + 4 = 7.\n\nExample 2:\n\nInput: nums = [2,3,5,1,3,2]\nOutput: 5\nExplanation: We mark the elements as follows:\n- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].\n- 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].\n- 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].\nOur score is 1 + 2 + 2 = 5.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 1000000]) == 1\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 25\n assert candidate(nums = [7, 3, 5, 1, 9, 2, 8, 6, 4]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 7\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(nums = [5, 3, 6, 2, 7, 4, 1, 8, 9]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50]) == 90\n assert candidate(nums = [1, 2, 3, 4, 5]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [2, 3, 5, 1, 3, 2]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 9\n assert candidate(nums = [3, 1, 2, 4, 5, 3, 2, 1]) == 9\n assert candidate(nums = [2, 1, 3, 4, 5, 2]) == 7\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 4, 4, 5, 5]) == 14\n assert candidate(nums = [1000000, 1]) == 1\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 24\n assert candidate(nums = [1000000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 25\n assert candidate(nums = [5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == 20\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [1000000]) == 1000000\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000, 1]) == 3\n assert candidate(nums = [999999, 1, 999998, 2, 999997, 3, 999996, 4, 999995, 5]) == 15\n assert candidate(nums = [2, 1, 4, 1, 3, 4, 2, 1]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1]) == 38\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 25\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6]) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 41\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 21\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 10\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 130\n assert candidate(nums = [6, 7, 8, 9, 10, 5, 4, 3, 2, 1]) == 23\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 16\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 64\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 29\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 1]) == 9\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]) == 1090\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]) == 435\n assert candidate(nums = [500000, 500001, 499999, 500002, 499998, 500003, 499997, 500004, 499996]) == 2499990\n assert candidate(nums = [1000000, 2, 1000000, 3, 1000000, 4, 1000000, 5]) == 14\n assert candidate(nums = [1000000, 1000000, 1, 1, 1000000, 1, 1000000, 1]) == 1000003\n assert candidate(nums = [7, 5, 3, 5, 7, 9, 1, 2, 8, 4, 6]) == 22\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1]) == 6\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5, 999996, 6, 999995, 7, 999994, 8]) == 36\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5, 999996]) == 15\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]) == 225\n assert candidate(nums = [3, 1, 2, 4, 5, 3, 2, 1, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8]) == 45\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 30\n assert candidate(nums = [9, 5, 7, 3, 8, 6, 10, 4, 2, 1]) == 19\n assert candidate(nums = [2, 3, 2, 4, 3, 2, 5, 4, 3, 2, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3]) == 26\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 125\n assert candidate(nums = [5, 3, 8, 3, 9, 1, 6, 2, 7, 4]) == 13\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9]) == 6\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 40\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 15\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]) == 120\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 24\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 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]) == 169\n assert candidate(nums = [2, 3, 5, 1, 3, 2, 5, 1, 3, 2, 5, 1, 3, 2, 5]) == 11\n assert candidate(nums = [1000, 999, 998, 1001, 1002, 997, 996, 995, 1003, 1004, 1005, 994, 993, 992, 1006]) == 6980\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 50\n assert candidate(nums = [5, 3, 8, 1, 4, 7, 2, 6]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 225\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\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]) == 24\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]) == 80\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 25\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1]) == 50\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 325\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 64\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5]) == 259\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 57\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 6, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 85\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 360\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 100\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 75\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1, 1, 4, 4, 4, 5, 5, 5]) == 21\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 50, 60, 10, 70]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 50\n assert candidate(nums = [100, 101, 102, 99, 98, 97, 103, 104, 105, 96, 95, 94, 106, 107, 108]) == 697\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 95\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == 19\n assert candidate(nums = [7, 1, 3, 2, 5, 4, 6, 8]) == 15\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [7, 6, 5, 8, 9, 1, 2, 3, 4, 10]) == 26\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990]) == 4999970\n assert candidate(nums = [15, 10, 5, 1, 20, 25, 30, 35, 40, 45]) == 116\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 40\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 13\n assert candidate(nums = [100, 50, 25, 125, 62, 31, 156, 78, 39, 200, 100, 50, 25, 125, 62, 31]) == 351\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5]) == 46\n assert candidate(nums = [500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]) == 2500000\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5]) == 15\n", "comparison": "exact"}, "public_tests": ["[2,1,3,4,5,2]", "[2,3,5,1,3,2]"], "hints": ["Try simulating the process of marking the elements and their adjacent.", "If there is an element that was already marked, then you skip it."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:25+00:00", "tests_total": 112, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "heap-priority-queue", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_score(nums)", "container": null, "callable": "find_score", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2594, "task_id": "minimum-time-to-repair-cars", "difficulty": "Medium", "problem_description": "You are given an integer array ranks representing the ranks of some mechanics. ranks_i is the rank of the i^th mechanic. A mechanic with a rank r can repair n cars in r * n^2 minutes.\n\nYou are also given an integer cars representing the total number of cars waiting in the garage to be repaired.\n\nReturn the minimum time taken to repair all the cars.\n\nNote: All the mechanics can repair the cars simultaneously.\n\nExample 1:\n\nInput: ranks = [4,2,3,1], cars = 10\nOutput: 16\nExplanation:\n- The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.\n- The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.\n- The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.\n- The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\n\nExample 2:\n\nInput: ranks = [5,1,8], cars = 6\nOutput: 16\nExplanation:\n- The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.\n- The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\n- The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\n\nConstraints:\n\n- 1 <= ranks.length <= 10^5\n- 1 <= ranks[i] <= 100\n- 1 <= cars <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(ranks = [1],cars = 1000000) == 1000000000000\n assert candidate(ranks = [10],cars = 100) == 100000\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 20) == 25\n assert candidate(ranks = [5, 1, 8],cars = 6) == 16\n assert candidate(ranks = [1, 1, 1, 1, 1],cars = 5) == 1\n assert candidate(ranks = [1],cars = 1) == 1\n assert candidate(ranks = [1, 1, 1, 1],cars = 4) == 1\n assert candidate(ranks = [1, 2, 3, 4, 5],cars = 15) == 27\n assert candidate(ranks = [4, 2, 3, 1],cars = 10) == 16\n assert candidate(ranks = [10, 20, 30, 40, 50],cars = 5) == 40\n assert candidate(ranks = [100, 100, 100],cars = 3) == 100\n assert candidate(ranks = [100, 100, 100],cars = 300) == 1000000\n assert candidate(ranks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],cars = 100000) == 99181681\n assert candidate(ranks = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5],cars = 500000) == 17879098464\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 1000000) == 39666387103\n assert candidate(ranks = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],cars = 50000) == 214060374\n assert candidate(ranks = [1, 1, 1, 1, 1],cars = 25) == 25\n assert candidate(ranks = [1, 3, 6, 10, 15],cars = 100000) == 1525913427\n assert candidate(ranks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cars = 1000000) == 396663871030\n assert candidate(ranks = [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],cars = 10000) == 530670\n assert candidate(ranks = [1, 1, 1, 1, 1],cars = 1000000) == 40000000000\n assert candidate(ranks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],cars = 10000) == 10000000\n assert candidate(ranks = [100, 100, 100, 100, 100],cars = 1000000) == 4000000000000\n assert candidate(ranks = [100, 50, 25, 12, 6, 3, 1],cars = 10000) == 13571856\n assert candidate(ranks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],cars = 1000000) == 28757183175\n assert candidate(ranks = [3, 3, 3, 3, 3],cars = 25) == 75\n assert candidate(ranks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cars = 50) == 25\n assert candidate(ranks = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],cars = 10000) == 8568300\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 100000) == 99181681\n assert candidate(ranks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cars = 1000) == 10000\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],cars = 100) == 288\n assert candidate(ranks = [50, 25, 100, 20, 60, 40, 30, 80, 90, 10],cars = 1000) == 361250\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],cars = 500000) == 4333852224\n assert candidate(ranks = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],cars = 5000) == 25000000\n assert candidate(ranks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cars = 50) == 176\n assert candidate(ranks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cars = 100) == 100\n assert candidate(ranks = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],cars = 100000) == 3966868890\n assert candidate(ranks = [50, 40, 30, 20, 10],cars = 1000000) == 957518758440\n assert candidate(ranks = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20],cars = 50) == 360\n assert candidate(ranks = [5, 10, 15, 20, 25],cars = 1000) == 480500\n assert candidate(ranks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cars = 50000) == 991816810\n assert candidate(ranks = [10, 20, 30, 40, 50],cars = 1000000) == 957518758440\n assert candidate(ranks = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],cars = 500000) == 236091196044\n assert candidate(ranks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cars = 50) == 1210\n assert candidate(ranks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],cars = 100) == 2205\n assert candidate(ranks = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],cars = 75) == 363\n assert candidate(ranks = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],cars = 5000) == 23655095\n assert candidate(ranks = [1, 2, 3, 4, 5],cars = 1000000) == 95751875844\n assert candidate(ranks = [100],cars = 1000000) == 100000000000000\n assert candidate(ranks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cars = 100000) == 3966868890\n assert candidate(ranks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],cars = 1000) == 200000\n assert candidate(ranks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],cars = 500) == 25000\n assert candidate(ranks = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],cars = 1000000) == 239380328180\n assert candidate(ranks = [100, 50, 25, 10, 5, 2, 1],cars = 1000) == 118810\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 100000) == 396686889\n assert candidate(ranks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cars = 1000000) == 10000000000\n assert candidate(ranks = [100, 50, 25, 12, 6],cars = 10000) == 77199414\n assert candidate(ranks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cars = 100000) == 100000000\n assert candidate(ranks = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],cars = 1000) == 400000\n assert candidate(ranks = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],cars = 30) == 144\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cars = 1000) == 40000\n assert candidate(ranks = [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],cars = 1000000) == 32624594527\n assert candidate(ranks = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],cars = 1000000) == 396663871030\n assert candidate(ranks = [100, 100, 100, 100, 100],cars = 500000) == 1000000000000\n assert candidate(ranks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],cars = 50000) == 24800400\n assert candidate(ranks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cars = 1000) == 400000\n assert candidate(ranks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cars = 1000) == 10000\n assert candidate(ranks = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],cars = 1000000) == 500000000000\n assert candidate(ranks = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],cars = 250) == 25920\n assert candidate(ranks = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],cars = 500) == 30276\n assert candidate(ranks = [99, 98, 97, 96, 95],cars = 1000000) == 3879392825484\n assert candidate(ranks = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],cars = 500000) == 55765049760\n assert candidate(ranks = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],cars = 100000) == 856147600\n assert candidate(ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],cars = 10000) == 2434446\n assert candidate(ranks = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],cars = 100) == 847\n assert candidate(ranks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cars = 10000) == 1250000\n assert candidate(ranks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cars = 1000) == 61731\n assert candidate(ranks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],cars = 10000) == 19845315\n assert candidate(ranks = [10, 10, 10, 10, 10],cars = 1000000) == 400000000000\n assert candidate(ranks = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],cars = 1000) == 500000\n assert candidate(ranks = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],cars = 500) == 20172\n assert candidate(ranks = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],cars = 1000000) == 34669800750\n", "comparison": "exact"}, "public_tests": ["[4,2,3,1]\n10", "[5,1,8]\n6"], "hints": ["For a predefined fixed time, can all the cars be repaired?", "Try using binary search on the answer."], "metadata": {"canonical_parameter_names": ["ranks", "cars"], "leetcode_dataset_entry_point": "Solution().repairCars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:27+00:00", "tests_total": 92, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "ruby", "interface": {"raw_signature": "def repair_cars(ranks, cars)", "container": null, "callable": "repair_cars", "parameters": [{"name": "ranks", "type": "Integer[]"}, {"name": "cars", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2595, "task_id": "number-of-even-and-odd-bits", "difficulty": "Easy", "problem_description": "You are given a positive integer n.\n\nLet even denote the number of even indices in the binary representation of n with value 1.\n\nLet odd denote the number of odd indices in the binary representation of n with value 1.\n\nNote that bits are indexed from right to left in the binary representation of a number.\n\nReturn the array [even, odd].\n\nExample 1:\n\nInput: n = 50\nOutput: [1,2]\nExplanation:\nThe binary representation of 50 is 110010.\nIt contains 1 on indices 1, 4, and 5.\n\nExample 2:\n\nInput: n = 2\nOutput: [0,1]\nExplanation:\nThe binary representation of 2 is 10.\nIt contains 1 only on index 1.\n\nConstraints:\n\n- 1 <= n <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8) == [0, 1]\n assert candidate(n = 3) == [1, 1]\n assert candidate(n = 1000) == [2, 4]\n assert candidate(n = 63) == [3, 3]\n assert candidate(n = 255) == [4, 4]\n assert candidate(n = 15) == [2, 2]\n assert candidate(n = 64) == [1, 0]\n assert candidate(n = 31) == [3, 2]\n assert candidate(n = 2) == [0, 1]\n assert candidate(n = 1) == [1, 0]\n assert candidate(n = 50) == [1, 2]\n assert candidate(n = 7) == [2, 1]\n assert candidate(n = 5) == [2, 0]\n assert candidate(n = 123) == [3, 3]\n assert candidate(n = 97) == [2, 1]\n assert candidate(n = 315) == [3, 3]\n assert candidate(n = 678) == [1, 4]\n assert candidate(n = 170) == [0, 4]\n assert candidate(n = 511) == [5, 4]\n assert candidate(n = 341) == [5, 0]\n assert candidate(n = 100) == [2, 1]\n assert candidate(n = 496) == [3, 2]\n assert candidate(n = 841) == [3, 2]\n assert candidate(n = 384) == [1, 1]\n assert candidate(n = 4) == [1, 0]\n assert candidate(n = 345) == [4, 1]\n assert candidate(n = 16) == [1, 0]\n assert candidate(n = 192) == [1, 1]\n assert candidate(n = 254) == [3, 4]\n assert candidate(n = 977) == [4, 2]\n assert candidate(n = 819) == [3, 3]\n assert candidate(n = 128) == [0, 1]\n assert candidate(n = 250) == [2, 4]\n assert candidate(n = 789) == [4, 1]\n assert candidate(n = 234) == [1, 4]\n assert candidate(n = 131) == [1, 2]\n assert candidate(n = 999) == [4, 4]\n assert candidate(n = 89) == [3, 1]\n assert candidate(n = 32) == [0, 1]\n assert candidate(n = 240) == [2, 2]\n assert candidate(n = 564) == [2, 2]\n assert candidate(n = 768) == [1, 1]\n assert candidate(n = 665) == [2, 3]\n assert candidate(n = 641) == [1, 2]\n assert candidate(n = 456) == [2, 2]\n assert candidate(n = 85) == [4, 0]\n assert candidate(n = 867) == [3, 3]\n assert candidate(n = 399) == [3, 3]\n assert candidate(n = 512) == [0, 1]\n assert candidate(n = 224) == [1, 2]\n assert candidate(n = 577) == [2, 1]\n assert candidate(n = 199) == [3, 2]\n assert candidate(n = 987) == [4, 4]\n", "comparison": "exact"}, "public_tests": ["50", "2"], "hints": ["Maintain two integer variables, even and odd, to count the number of even and odd indices in the binary representation of integer n.", "Divide n by 2 while n is positive, and if n modulo 2 is 1, add 1 to its corresponding variable."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().evenOddBit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:30+00:00", "tests_total": 62, "tests_dropped": 9, "flags": [], "topic_tags": ["bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def even_odd_bit(n)", "container": null, "callable": "even_odd_bit", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2596, "task_id": "check-knight-tour-configuration", "difficulty": "Medium", "problem_description": "There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.\n\nYou are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]^th cell that the knight visited. The moves are 0-indexed.\n\nReturn true if grid represents a valid configuration of the knight's movements or false otherwise.\n\nNote that a valid knight move consists of moving two squares vertically and one square horizontally, or two squares horizontally and one square vertically. The figure below illustrates all the possible eight moves of a knight from some cell.\n\nExample 1:\n\nInput: grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]\nOutput: true\nExplanation: The above diagram represents the grid. It can be shown that it is a valid configuration.\n\nExample 2:\n\nInput: grid = [[0,3,6],[5,8,1],[2,7,4]]\nOutput: false\nExplanation: The above diagram represents the grid. The 8^th move of the knight is not valid considering its position after the 7^th move.\n\nConstraints:\n\n- n == grid.length == grid[i].length\n- 3 <= n <= 7\n- 0 <= grid[row][col] < n * n\n- All integers in grid are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 5, 2], [6, 3, 1], [8, 7, 4]]) == False\n assert candidate(grid = [[0, 12, 3, 14, 5], [19, 2, 15, 4, 13], [6, 23, 8, 17, 16], [22, 11, 10, 9, 18], [7, 24, 21, 1, 20]]) == False\n assert candidate(grid = [[0, 5, 2], [3, 8, 7], [4, 1, 6]]) == False\n assert candidate(grid = [[0, 6, 1], [5, 8, 3], [4, 7, 2]]) == False\n assert candidate(grid = [[0, 1, 4, 25, 24, 23], [19, 8, 9, 26, 27, 22], [18, 7, 2, 17, 28, 21], [11, 6, 3, 12, 13, 20], [10, 15, 16, 1, 4, 14], [12, 21, 20, 29, 30, 5]]) == False\n assert candidate(grid = [[0, 2, 3], [1, 5, 4], [6, 7, 8]]) == False\n assert candidate(grid = [[0, 2, 3], [5, 6, 1], [4, 7, 8]]) == False\n assert candidate(grid = [[0, 11, 16, 5, 20], [17, 4, 19, 10, 15], [12, 1, 8, 21, 6], [3, 18, 23, 14, 9], [24, 13, 2, 7, 22]]) == True\n assert candidate(grid = [[0, 3, 6], [5, 8, 1], [2, 7, 4]]) == False\n assert candidate(grid = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]) == False\n assert candidate(grid = [[0, 29, 8, 25, 16, 23, 4], [31, 24, 7, 14, 27, 10, 15], [18, 1, 28, 9, 22, 5, 20], [13, 17, 32, 26, 11, 30, 19], [21, 34, 3, 31, 12, 33, 6], [37, 10, 1, 2, 35, 36, 17], [38, 5, 18, 30, 33, 28, 2]]) == False\n assert candidate(grid = [[0, 15, 24, 19, 8, 31, 28], [33, 4, 25, 12, 7, 30, 29], [18, 5, 26, 11, 6, 27, 20], [3, 2, 23, 14, 9, 22, 13], [17, 10, 1, 24, 32, 15, 21], [16, 35, 34, 31, 28, 10, 19], [30, 37, 36, 33, 38, 26, 12]]) == False\n assert candidate(grid = [[0, 15, 28, 21, 8, 19, 2], [31, 22, 7, 16, 29, 10, 27], [14, 23, 6, 25, 18, 9, 20], [3, 12, 33, 26, 11, 30, 17], [13, 24, 5, 32, 1, 34, 21], [35, 10, 1, 2, 31, 4, 23], [36, 11, 26, 3, 14, 27, 6]]) == False\n assert candidate(grid = [[0, 11, 24, 5, 21, 16], [23, 12, 4, 19, 10, 15], [18, 1, 8, 22, 6, 20], [13, 17, 25, 3, 27, 14], [26, 2, 9, 28, 7, 1], [30, 29, 18, 5, 24, 31]]) == False\n assert candidate(grid = [[0, 17, 28, 25, 8, 31, 16], [33, 24, 7, 14, 29, 10, 15], [18, 1, 26, 9, 22, 5, 20], [13, 17, 34, 27, 11, 32, 19], [21, 36, 3, 35, 12, 37, 6], [39, 10, 1, 2, 38, 30, 23], [40, 5, 18, 30, 33, 28, 2]]) == False\n assert candidate(grid = [[0, 29, 28, 13, 12, 3, 2], [27, 26, 15, 14, 11, 4, 1], [24, 17, 8, 7, 16, 5, 20], [19, 18, 3, 6, 15, 2, 16], [21, 22, 9, 20, 1, 14, 11], [33, 32, 35, 34, 23, 28, 37], [30, 31, 36, 39, 38, 41, 40]]) == False\n assert candidate(grid = [[0, 27, 12, 19, 24, 29, 4], [21, 28, 11, 20, 25, 30, 3], [22, 26, 13, 18, 23, 31, 5], [23, 22, 14, 17, 2, 32, 6], [24, 21, 15, 16, 33, 34, 7], [25, 20, 10, 1, 8, 35, 36], [26, 19, 9, 12, 11, 6, 37]]) == False\n assert candidate(grid = [[0, 25, 14, 1, 18, 29, 2], [21, 24, 15, 26, 19, 28, 3], [20, 23, 16, 27, 12, 21, 4], [31, 22, 17, 28, 13, 24, 5], [30, 33, 36, 19, 25, 18, 6], [35, 32, 37, 34, 31, 38, 7], [39, 34, 35, 36, 37, 38, 8]]) == False\n assert candidate(grid = [[0, 27, 8, 25, 16, 35, 10], [1, 28, 9, 24, 17, 34, 11], [2, 29, 6, 23, 18, 33, 12], [3, 30, 7, 22, 19, 32, 13], [4, 31, 36, 21, 20, 37, 14], [5, 32, 39, 26, 29, 38, 15], [14, 33, 38, 39, 40, 41, 42]]) == False\n assert candidate(grid = [[0, 19, 10, 3, 18, 27, 12], [21, 2, 9, 14, 17, 26, 13], [20, 7, 4, 11, 16, 25, 14], [1, 8, 5, 12, 15, 24, 15], [2, 11, 6, 13, 14, 23, 16], [3, 10, 7, 14, 13, 22, 17], [4, 9, 8, 15, 12, 21, 18]]) == False\n assert candidate(grid = [[0, 19, 12, 25, 10, 9], [2, 20, 13, 24, 11, 8], [15, 3, 22, 1, 14, 7], [16, 17, 4, 21, 6, 18], [5, 23, 26, 18, 27, 12], [30, 29, 28, 27, 26, 31]]) == False\n assert candidate(grid = [[0, 25, 24, 11, 10, 3, 2], [23, 26, 13, 12, 9, 4, 1], [22, 17, 8, 7, 14, 5, 20], [19, 18, 3, 6, 15, 2, 16], [21, 10, 9, 20, 1, 14, 11], [30, 29, 34, 33, 28, 27, 32], [31, 26, 25, 36, 35, 38, 37]]) == False\n assert candidate(grid = [[0, 14, 9, 2, 23], [18, 8, 21, 15, 19], [13, 22, 1, 16, 10], [20, 5, 11, 4, 3], [6, 17, 12, 7, 24]]) == False\n assert candidate(grid = [[0, 13, 10, 21, 4], [22, 9, 2, 17, 20], [15, 6, 1, 18, 11], [24, 19, 8, 3, 16], [23, 14, 5, 12, 7]]) == False\n assert candidate(grid = [[0, 25, 16, 19, 22, 9, 28], [31, 14, 7, 12, 29, 2, 21], [32, 39, 20, 1, 18, 3, 10], [8, 27, 13, 26, 3, 24, 5], [38, 43, 11, 23, 4, 41, 6], [44, 35, 36, 22, 33, 20, 17], [37, 42, 45, 30, 31, 15, 34]]) == False\n assert candidate(grid = [[0, 25, 12, 13, 24, 11, 22], [21, 8, 19, 14, 23, 10, 27], [20, 7, 30, 15, 28, 9, 26], [17, 6, 29, 4, 31, 18, 33], [16, 5, 34, 3, 35, 2, 32], [39, 1, 38, 0, 37, 36, 19], [38, 35, 36, 37, 4, 5, 6]]) == False\n assert candidate(grid = [[0, 25, 18, 9, 26, 17, 6], [23, 2, 19, 10, 27, 16, 7], [22, 31, 4, 11, 28, 15, 8], [21, 32, 3, 12, 29, 14, 20], [24, 5, 36, 13, 30, 1, 34], [33, 38, 27, 6, 35, 32, 19], [37, 39, 30, 31, 4, 28, 25]]) == False\n assert candidate(grid = [[0, 17, 16, 3, 2, 1, 6], [15, 8, 9, 4, 7, 18, 13], [14, 11, 12, 19, 10, 5, 20], [31, 28, 29, 22, 21, 24, 23], [32, 27, 26, 39, 38, 25, 30], [37, 34, 35, 40, 33, 36, 41], [38, 43, 42, 45, 44, 47, 46]]) == False\n assert candidate(grid = [[0, 17, 14, 3, 4, 5, 36], [25, 18, 13, 2, 1, 6, 35], [24, 27, 12, 15, 10, 7, 34], [23, 26, 29, 8, 11, 16, 33], [22, 31, 28, 21, 20, 9, 32], [37, 30, 21, 18, 19, 14, 39], [38, 41, 32, 35, 40, 33, 42]]) == False\n assert candidate(grid = [[0, 21, 4, 15, 22, 33, 30], [25, 8, 29, 16, 23, 34, 31], [24, 7, 28, 17, 20, 35, 32], [26, 3, 27, 18, 19, 36, 33], [27, 22, 2, 13, 14, 37, 34], [28, 9, 23, 12, 11, 38, 35], [29, 10, 8, 1, 6, 39, 36]]) == False\n assert candidate(grid = [[0, 11, 16, 5, 20, 25, 24], [17, 4, 19, 10, 15, 26, 30], [12, 1, 8, 21, 6, 23, 29], [3, 18, 27, 14, 9, 31, 28], [24, 13, 2, 7, 22, 32, 33], [35, 34, 29, 30, 31, 32, 33], [36, 37, 38, 39, 40, 41, 42]]) == False\n assert candidate(grid = [[0, 33, 24, 27, 4, 35, 18], [32, 1, 25, 26, 5, 34, 17], [31, 2, 23, 10, 7, 36, 16], [19, 20, 3, 12, 11, 28, 37], [30, 39, 22, 13, 8, 29, 38], [29, 38, 21, 36, 9, 14, 27], [28, 37, 32, 35, 2, 15, 10]]) == False\n assert candidate(grid = [[0, 35, 12, 3, 26, 15, 2], [23, 14, 1, 36, 17, 28, 31], [22, 13, 24, 11, 18, 27, 16], [33, 20, 7, 4, 37, 19, 29], [32, 21, 8, 35, 2, 38, 10], [39, 30, 15, 24, 13, 36, 9], [34, 31, 16, 17, 28, 19, 20]]) == False\n assert candidate(grid = [[0, 21, 12, 19, 8, 25, 2], [27, 22, 7, 16, 29, 10, 15], [18, 1, 8, 23, 6, 28, 24], [13, 17, 33, 26, 11, 30, 14], [20, 25, 34, 12, 3, 27, 9], [35, 10, 31, 4, 32, 1, 36], [37, 5, 18, 30, 33, 28, 21]]) == False\n assert candidate(grid = [[0, 19, 32, 15, 20, 23, 18], [35, 14, 7, 26, 17, 4, 13], [30, 37, 2, 25, 8, 11, 16], [9, 28, 1, 12, 3, 24, 6], [31, 34, 39, 42, 27, 22, 19], [36, 43, 21, 40, 33, 38, 5], [41, 44, 45, 30, 46, 47, 3]]) == False\n assert candidate(grid = [[0, 17, 2, 19, 22, 11, 26], [15, 8, 27, 4, 23, 20, 13], [16, 1, 24, 3, 28, 21, 12], [9, 18, 7, 10, 29, 25, 6], [14, 33, 36, 5, 32, 39, 1], [31, 26, 35, 34, 37, 4, 2], [30, 11, 38, 28, 3, 37, 5]]) == False\n assert candidate(grid = [[0, 13, 22, 9, 24, 21, 18], [17, 4, 11, 28, 25, 14, 19], [3, 16, 5, 12, 27, 20, 7], [30, 1, 2, 29, 6, 23, 10], [31, 8, 15, 26, 21, 20, 11], [36, 33, 38, 39, 40, 31, 42], [34, 41, 32, 37, 35, 30, 43]]) == False\n assert candidate(grid = [[0, 25, 6, 19, 22, 13, 2], [21, 16, 7, 18, 23, 12, 9], [20, 15, 8, 17, 24, 11, 10], [13, 14, 5, 16, 21, 2, 17], [12, 11, 4, 15, 20, 3, 18], [31, 30, 1, 32, 35, 10, 33], [32, 33, 28, 31, 36, 35, 34]]) == False\n assert candidate(grid = [[0, 15, 2, 21, 8, 7], [13, 14, 19, 20, 5, 6], [18, 17, 10, 11, 4, 1], [9, 16, 23, 24, 3, 12], [35, 30, 25, 26, 29, 28], [31, 32, 33, 34, 27, 22]]) == False\n assert candidate(grid = [[0, 27, 26, 25, 24, 23, 22], [21, 28, 13, 12, 11, 10, 20], [14, 15, 8, 7, 6, 19, 9], [17, 18, 5, 4, 16, 3, 1], [2, 31, 29, 1, 30, 35, 34], [33, 32, 37, 36, 39, 38, 41], [40, 43, 42, 47, 46, 45, 44]]) == False\n assert candidate(grid = [[0, 21, 24, 17, 4, 23, 2], [25, 16, 13, 18, 19, 8, 11], [22, 9, 12, 15, 6, 20, 5], [7, 14, 1, 10, 3, 11, 26], [27, 30, 29, 32, 31, 36, 33], [34, 28, 35, 38, 41, 40, 37], [42, 39, 44, 43, 48, 45, 46]]) == False\n assert candidate(grid = [[0, 25, 8, 1, 12, 23, 30], [31, 24, 9, 26, 13, 22, 33], [28, 7, 10, 27, 14, 21, 2], [29, 6, 11, 18, 15, 20, 3], [32, 5, 16, 19, 17, 20, 34], [35, 4, 36, 19, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46]]) == False\n assert candidate(grid = [[0, 11, 18, 5, 22, 13], [19, 4, 21, 12, 23, 14], [16, 1, 10, 25, 8, 15], [3, 17, 24, 9, 20, 6], [26, 10, 3, 14, 27, 7], [32, 29, 28, 11, 16, 2]]) == False\n assert candidate(grid = [[0, 7, 14, 21, 16, 11, 6], [1, 8, 15, 22, 17, 12, 5], [2, 9, 10, 23, 18, 13, 4], [3, 12, 19, 24, 15, 14, 3], [4, 11, 18, 25, 20, 21, 2], [5, 10, 17, 26, 23, 22, 1], [6, 9, 16, 27, 24, 25, 0]]) == False\n assert candidate(grid = [[0, 19, 10, 3, 22, 13, 24], [35, 18, 11, 2, 23, 12, 25], [34, 17, 8, 1, 20, 14, 9], [33, 26, 7, 4, 21, 15, 16], [32, 27, 36, 3, 28, 19, 20], [31, 30, 29, 4, 26, 34, 35], [24, 25, 28, 29, 30, 31, 32]]) == False\n assert candidate(grid = [[0, 23, 12, 5, 24, 19, 6], [21, 2, 13, 22, 25, 18, 7], [20, 3, 8, 21, 26, 17, 8], [1, 10, 9, 16, 23, 14, 9], [2, 11, 4, 15, 20, 27, 10], [3, 12, 11, 18, 19, 28, 11], [4, 13, 14, 17, 22, 29, 12]]) == False\n assert candidate(grid = [[0, 15, 24, 3, 20, 11, 6], [19, 2, 13, 22, 17, 12, 5], [18, 7, 4, 23, 18, 13, 4], [1, 8, 5, 12, 15, 24, 3], [2, 11, 6, 13, 14, 23, 2], [5, 10, 17, 26, 21, 22, 1], [6, 9, 16, 27, 24, 25, 0]]) == False\n assert candidate(grid = [[0, 29, 28, 17, 16, 7, 6], [27, 26, 15, 14, 13, 8, 5], [24, 19, 18, 9, 12, 11, 4], [23, 22, 1, 2, 10, 3, 20], [31, 30, 25, 24, 21, 28, 29], [32, 37, 34, 33, 36, 39, 38], [35, 42, 41, 40, 47, 46, 45]]) == False\n assert candidate(grid = [[0, 17, 24, 13, 4, 35, 32], [37, 2, 25, 14, 5, 34, 31], [16, 1, 26, 15, 6, 33, 30], [21, 28, 3, 22, 11, 32, 29], [20, 27, 8, 19, 2, 23, 12], [9, 36, 23, 30, 7, 31, 18], [10, 31, 22, 29, 18, 33, 17]]) == False\n assert candidate(grid = [[0, 11, 18, 25, 16, 7, 28], [21, 12, 3, 14, 17, 8, 27], [20, 13, 2, 15, 10, 9, 26], [31, 22, 19, 4, 1, 12, 29], [30, 33, 24, 23, 6, 5, 32], [39, 34, 41, 36, 27, 26, 35], [38, 37, 40, 43, 42, 31, 44]]) == False\n", "comparison": "exact"}, "public_tests": ["[[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]", "[[0,3,6],[5,8,1],[2,7,4]]"], "hints": ["It is enough to check if each move of the knight is valid.", "Try all cases of the knight's movements to check if a move is valid."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().checkValidGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:32+00:00", "tests_total": 54, "tests_dropped": 4, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "depth-first-search", "breadth-first-search", "matrix", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def check_valid_grid(grid)", "container": null, "callable": "check_valid_grid", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2597, "task_id": "the-number-of-beautiful-subsets", "difficulty": "Medium", "problem_description": "You are given an array nums of positive integers and a positive integer k.\n\nA subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.\n\nReturn the number of non-empty beautiful subsets of the array nums.\n\nA subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.\n\nExample 1:\n\nInput: nums = [2,4,6], k = 2\nOutput: 4\nExplanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].\nIt can be proved that there are only 4 beautiful subsets in the array [2,4,6].\n\nExample 2:\n\nInput: nums = [1], k = 1\nOutput: 1\nExplanation: The beautiful subset of the array nums is [1].\nIt can be proved that there is only 1 beautiful subset in the array [1].\n\nConstraints:\n\n- 1 <= nums.length <= 18\n- 1 <= nums[i], k <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90],k = 5) == 6764\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 1) == 6764\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 143\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 3) == 9260\n assert candidate(nums = [5, 10, 15, 20, 25, 30],k = 5) == 20\n assert candidate(nums = [1, 3, 5, 7, 9],k = 2) == 12\n assert candidate(nums = [2, 4, 6],k = 2) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 143\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36],k = 2) == 6764\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],k = 1) == 232\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],k = 2) == 7920\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 143\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95],k = 6) == 2583\n assert candidate(nums = [3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123, 131, 139],k = 8) == 6764\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450],k = 25) == 6764\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126],k = 7) == 6764\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35],k = 2) == 6764\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72],k = 4) == 6764\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144],k = 8) == 6764\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198],k = 11) == 6764\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 199\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14],k = 2) == 33\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59],k = 1) == 163839\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180],k = 20) == 7920\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 143\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52],k = 3) == 6764\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],k = 15) == 143\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35],k = 2) == 6764\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70],k = 4) == 6764\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 1) == 6764\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26],k = 1) == 19682\n assert candidate(nums = [4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54],k = 5) == 232\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 3) == 9260\n assert candidate(nums = [1, 2, 5, 6, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 29, 30, 33, 34],k = 4) == 7920\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234],k = 13) == 6764\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 199\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69],k = 4) == 6764\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198],k = 11) == 6764\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 20) == 168\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126],k = 7) == 6764\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20],k = 3) == 33\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36],k = 2) == 6764\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70],k = 4) == 6764\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112],k = 7) == 2583\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 2) == 143\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54],k = 3) == 6764\n assert candidate(nums = [2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122, 130, 138],k = 8) == 6764\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180],k = 10) == 6764\n assert candidate(nums = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141, 151, 161, 171],k = 10) == 6764\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61],k = 4) == 2583\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900],k = 100) == 88\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 2) == 1596\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 21, 22, 23, 26, 27, 28],k = 3) == 62207\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53],k = 3) == 6764\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53],k = 1) == 49151\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59],k = 2) == 41471\n assert candidate(nums = [3, 13, 23, 33, 43, 53, 63, 73, 83, 93, 103, 113, 123, 133, 143, 153, 163, 173],k = 10) == 6764\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 143\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240],k = 15) == 2583\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90],k = 5) == 6764\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175],k = 10) == 6764\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69],k = 4) == 6764\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 143\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54],k = 3) == 6764\n", "comparison": "exact"}, "public_tests": ["[2,4,6]\n2", "[1]\n1"], "hints": ["Sort the array nums and create another array cnt of size nums[i].", "Use backtracking to generate all the beautiful subsets. If cnt[nums[i] - k] is positive, then it is impossible to add nums[i] in the subset, and we just move to the next index. Otherwise, it is also possible to add nums[i] in the subset, in this case, increase cnt[nums[i]], and move to the next index.", "Bonus: Can you solve the problem in O(n log n)?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().beautifulSubsets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:34+00:00", "tests_total": 74, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "hash-table", "math", "dynamic-programming", "backtracking", "sorting", "combinatorics"]}, "language": "ruby", "interface": {"raw_signature": "def beautiful_subsets(nums, k)", "container": null, "callable": "beautiful_subsets", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2598, "task_id": "smallest-missing-non-negative-integer-after-operations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer value.\n\nIn one operation, you can add or subtract value from any element of nums.\n\n- For example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].\n\nThe MEX (minimum excluded) of an array is the smallest missing non-negative integer in it.\n\n- For example, the MEX of [-1,2,3] is 0 while the MEX of [1,0,3] is 2.\n\nReturn the maximum MEX of nums after applying the mentioned operation any number of times.\n\nExample 1:\n\nInput: nums = [1,-10,7,13,6,8], value = 5\nOutput: 4\nExplanation: One can achieve this result by applying the following operations:\n- Add value to nums[1] twice to make nums = [1,0,7,13,6,8]\n- Subtract value from nums[2] once to make nums = [1,0,2,13,6,8]\n- Subtract value from nums[3] twice to make nums = [1,0,2,3,6,8]\nThe MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.\n\nExample 2:\n\nInput: nums = [1,-10,7,13,6,8], value = 7\nOutput: 2\nExplanation: One can achieve this result by applying the following operation:\n- subtract value from nums[2] once to make nums = [1,-10,0,13,6,8]\nThe MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve.\n\nConstraints:\n\n- 1 <= nums.length, value <= 10^5\n- -10^9 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5],value = 1) == 6\n assert candidate(nums = [0, 0, 0, 0],value = 3) == 1\n assert candidate(nums = [10, 15, 20, 25, 30],value = 5) == 1\n assert candidate(nums = [-1, -2, -3, -4],value = 2) == 4\n assert candidate(nums = [-5, -10, -15, -20, -25],value = 5) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5],value = 3) == 3\n assert candidate(nums = [10, 20, 30, 40],value = 10) == 1\n assert candidate(nums = [1, -10, 7, 13, 6, 8],value = 7) == 2\n assert candidate(nums = [1, -10, 7, 13, 6, 8],value = 5) == 4\n assert candidate(nums = [-5, -4, -3, -2, -1],value = 3) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],value = 2) == 10\n assert candidate(nums = [100, 200, 300, 400, 500],value = 3) == 3\n assert candidate(nums = [-5, -4, -3, -2, -1],value = 2) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],value = 1) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],value = 10) == 1\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000],value = 1) == 4\n assert candidate(nums = [2, 3, 4, 5, 6],value = 3) == 4\n assert candidate(nums = [0, 1, 2, 3, 4, 5],value = 6) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],value = 13) == 13\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -110, -120, -130, -140, -150],value = 20) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],value = 5) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],value = 1) == 10\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],value = 2) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],value = 2) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],value = 2) == 0\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],value = 25) == 1\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91],value = 5) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],value = 16) == 16\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],value = 7) == 31\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],value = 100) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7],value = 3) == 6\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000],value = 100000) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],value = 1) == 20\n assert candidate(nums = [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],value = 1) == 30\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],value = 10) == 1\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11],value = 3) == 9\n assert candidate(nums = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100],value = 10) == 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],value = 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],value = 3) == 18\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],value = 10) == 1\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],value = 3) == 30\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],value = 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],value = 3) == 18\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],value = 10) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],value = 7) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0],value = 1) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],value = 10) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],value = 1) == 31\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],value = 7) == 26\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],value = 5) == 1\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164, 175, 186, 197, 208, 219],value = 11) == 0\n assert candidate(nums = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81],value = 5) == 2\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],value = 1) == 10\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],value = 12) == 24\n assert candidate(nums = [10, 20, 30, 40, 50, 60],value = 15) == 1\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109],value = 11) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],value = 2) == 0\n assert candidate(nums = [-1000000000, -999999999, -999999998, -999999997, -999999996],value = 5) == 5\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],value = 1000) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],value = 11) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],value = 5) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],value = 5) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],value = 2) == 20\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],value = 5) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],value = 2) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],value = 1) == 10\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],value = 3) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],value = 10) == 1\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],value = 5) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],value = 2) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],value = 1) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],value = 5) == 1\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81],value = 4) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],value = 4) == 16\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],value = 2) == 10\n assert candidate(nums = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19],value = 3) == 19\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],value = 5) == 30\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],value = 3) == 9\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],value = 2) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],value = 19) == 19\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27],value = 3) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],value = 1) == 11\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],value = 5) == 10\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],value = 10) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],value = 10) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],value = 2) == 1\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],value = 3) == 9\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],value = 5) == 5\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],value = 1) == 16\n assert candidate(nums = [1, 1, 1, 1, 1],value = 2) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],value = 4) == 20\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],value = 2) == 0\n assert candidate(nums = [-100, -50, -25, -10, -5, -1, 0, 1, 5, 10, 25, 50, 100],value = 25) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],value = 3) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],value = 1) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],value = 2) == 0\n assert candidate(nums = [-1, -1, -2, -2, -3, -3, -4, -4, -5, -5],value = 3) == 6\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],value = 1) == 10\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],value = 100) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20],value = 5) == 20\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],value = 6) == 6\n assert candidate(nums = [-100, -200, -300, -400, -500],value = 150) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],value = 7) == 14\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29],value = 3) == 0\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25],value = 4) == 0\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],value = 5) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],value = 3) == 20\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],value = 4) == 21\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],value = 15) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],value = 5) == 15\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],value = 5) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],value = 6) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],value = 1) == 10\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],value = 7) == 26\n", "comparison": "exact"}, "public_tests": ["[1,-10,7,13,6,8]\n5", "[1,-10,7,13,6,8]\n7"], "hints": ["Think about using modular arithmetic.", "if x = nums[i] (mod value), then we can make nums[i] equal to x after some number of operations", "How does finding the frequency of (nums[i] mod value) help?"], "metadata": {"canonical_parameter_names": ["nums", "value"], "leetcode_dataset_entry_point": "Solution().findSmallestInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:37+00:00", "tests_total": 125, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "hash-table", "math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def find_smallest_integer(nums, value)", "container": null, "callable": "find_smallest_integer", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "value", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2600, "task_id": "k-items-with-the-maximum-sum", "difficulty": "Easy", "problem_description": "There is a bag that consists of items, each item has a number 1, 0, or -1 written on it.\n\nYou are given four non-negative integers numOnes, numZeros, numNegOnes, and k.\n\nThe bag initially contains:\n\n- numOnes items with 1s written on them.\n- numZeroes items with 0s written on them.\n- numNegOnes items with -1s written on them.\n\nWe want to pick exactly k items among the available items. Return the maximum possible sum of numbers written on the items.\n\nExample 1:\n\nInput: numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2\nOutput: 2\nExplanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 2 items with 1 written on them and get a sum in a total of 2.\nIt can be proven that 2 is the maximum possible sum.\n\nExample 2:\n\nInput: numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4\nOutput: 3\nExplanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 3 items with 1 written on them, and 1 item with 0 written on it, and get a sum in a total of 3.\nIt can be proven that 3 is the maximum possible sum.\n\nConstraints:\n\n- 0 <= numOnes, numZeros, numNegOnes <= 50\n- 0 <= k <= numOnes + numZeros + numNegOnes\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 50) == 25\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 10) == 0\n assert candidate(numOnes = 3,numZeros = 2,numNegOnes = 0,k = 2) == 2\n assert candidate(numOnes = 20,numZeros = 20,numNegOnes = 10,k = 50) == 10\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 10,k = 5) == 5\n assert candidate(numOnes = 25,numZeros = 0,numNegOnes = 25,k = 30) == 20\n assert candidate(numOnes = 50,numZeros = 50,numNegOnes = 50,k = 100) == 50\n assert candidate(numOnes = 0,numZeros = 25,numNegOnes = 25,k = 50) == -25\n assert candidate(numOnes = 1,numZeros = 3,numNegOnes = 2,k = 5) == 0\n assert candidate(numOnes = 5,numZeros = 5,numNegOnes = 5,k = 5) == 5\n assert candidate(numOnes = 50,numZeros = 30,numNegOnes = 20,k = 100) == 30\n assert candidate(numOnes = 0,numZeros = 0,numNegOnes = 50,k = 10) == -10\n assert candidate(numOnes = 0,numZeros = 25,numNegOnes = 25,k = 40) == -15\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 50) == 0\n assert candidate(numOnes = 0,numZeros = 0,numNegOnes = 50,k = 25) == -25\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 10,k = 15) == 10\n assert candidate(numOnes = 50,numZeros = 0,numNegOnes = 0,k = 50) == 50\n assert candidate(numOnes = 0,numZeros = 0,numNegOnes = 50,k = 50) == -50\n assert candidate(numOnes = 0,numZeros = 0,numNegOnes = 0,k = 0) == 0\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 30,k = 40) == -10\n assert candidate(numOnes = 1,numZeros = 1,numNegOnes = 1,k = 1) == 1\n assert candidate(numOnes = 50,numZeros = 0,numNegOnes = 0,k = 10) == 10\n assert candidate(numOnes = 0,numZeros = 0,numNegOnes = 5,k = 3) == -3\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 30) == 0\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 30) == 25\n assert candidate(numOnes = 25,numZeros = 0,numNegOnes = 25,k = 50) == 0\n assert candidate(numOnes = 0,numZeros = 0,numNegOnes = 50,k = 20) == -20\n assert candidate(numOnes = 3,numZeros = 2,numNegOnes = 0,k = 4) == 3\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 20) == 0\n assert candidate(numOnes = 45,numZeros = 0,numNegOnes = 5,k = 45) == 45\n assert candidate(numOnes = 30,numZeros = 10,numNegOnes = 10,k = 50) == 20\n assert candidate(numOnes = 20,numZeros = 10,numNegOnes = 20,k = 50) == 0\n assert candidate(numOnes = 30,numZeros = 20,numNegOnes = 5,k = 40) == 30\n assert candidate(numOnes = 45,numZeros = 20,numNegOnes = 35,k = 50) == 45\n assert candidate(numOnes = 20,numZeros = 20,numNegOnes = 10,k = 30) == 20\n assert candidate(numOnes = 15,numZeros = 10,numNegOnes = 25,k = 30) == 10\n assert candidate(numOnes = 40,numZeros = 5,numNegOnes = 5,k = 48) == 37\n assert candidate(numOnes = 20,numZeros = 0,numNegOnes = 30,k = 20) == 20\n assert candidate(numOnes = 30,numZeros = 10,numNegOnes = 10,k = 45) == 25\n assert candidate(numOnes = 30,numZeros = 15,numNegOnes = 10,k = 45) == 30\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 30,k = 35) == -5\n assert candidate(numOnes = 40,numZeros = 5,numNegOnes = 5,k = 45) == 40\n assert candidate(numOnes = 5,numZeros = 0,numNegOnes = 45,k = 10) == 0\n assert candidate(numOnes = 30,numZeros = 0,numNegOnes = 20,k = 40) == 20\n assert candidate(numOnes = 20,numZeros = 15,numNegOnes = 15,k = 30) == 20\n assert candidate(numOnes = 50,numZeros = 0,numNegOnes = 0,k = 49) == 49\n assert candidate(numOnes = 40,numZeros = 5,numNegOnes = 5,k = 50) == 35\n assert candidate(numOnes = 20,numZeros = 30,numNegOnes = 10,k = 50) == 20\n assert candidate(numOnes = 45,numZeros = 3,numNegOnes = 2,k = 50) == 43\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 24) == 24\n assert candidate(numOnes = 0,numZeros = 50,numNegOnes = 0,k = 25) == 0\n assert candidate(numOnes = 45,numZeros = 0,numNegOnes = 5,k = 48) == 42\n assert candidate(numOnes = 25,numZeros = 15,numNegOnes = 10,k = 50) == 15\n assert candidate(numOnes = 10,numZeros = 0,numNegOnes = 40,k = 50) == -30\n assert candidate(numOnes = 15,numZeros = 0,numNegOnes = 35,k = 20) == 10\n assert candidate(numOnes = 20,numZeros = 10,numNegOnes = 20,k = 30) == 20\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 30,k = 20) == 10\n assert candidate(numOnes = 45,numZeros = 2,numNegOnes = 3,k = 45) == 45\n assert candidate(numOnes = 10,numZeros = 20,numNegOnes = 30,k = 60) == -20\n assert candidate(numOnes = 20,numZeros = 15,numNegOnes = 15,k = 40) == 15\n assert candidate(numOnes = 10,numZeros = 30,numNegOnes = 10,k = 30) == 10\n assert candidate(numOnes = 10,numZeros = 20,numNegOnes = 20,k = 30) == 10\n assert candidate(numOnes = 15,numZeros = 15,numNegOnes = 20,k = 40) == 5\n assert candidate(numOnes = 0,numZeros = 25,numNegOnes = 25,k = 45) == -20\n assert candidate(numOnes = 0,numZeros = 20,numNegOnes = 30,k = 40) == -20\n assert candidate(numOnes = 40,numZeros = 0,numNegOnes = 10,k = 45) == 35\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 40) == 25\n assert candidate(numOnes = 15,numZeros = 15,numNegOnes = 20,k = 20) == 15\n assert candidate(numOnes = 50,numZeros = 0,numNegOnes = 0,k = 30) == 30\n assert candidate(numOnes = 30,numZeros = 15,numNegOnes = 5,k = 40) == 30\n assert candidate(numOnes = 35,numZeros = 10,numNegOnes = 5,k = 45) == 35\n assert candidate(numOnes = 0,numZeros = 30,numNegOnes = 20,k = 40) == -10\n assert candidate(numOnes = 15,numZeros = 20,numNegOnes = 15,k = 25) == 15\n assert candidate(numOnes = 10,numZeros = 20,numNegOnes = 20,k = 10) == 10\n assert candidate(numOnes = 10,numZeros = 40,numNegOnes = 10,k = 60) == 0\n assert candidate(numOnes = 30,numZeros = 10,numNegOnes = 10,k = 25) == 25\n assert candidate(numOnes = 20,numZeros = 0,numNegOnes = 30,k = 30) == 10\n assert candidate(numOnes = 1,numZeros = 48,numNegOnes = 1,k = 50) == 0\n assert candidate(numOnes = 0,numZeros = 25,numNegOnes = 25,k = 25) == 0\n assert candidate(numOnes = 1,numZeros = 1,numNegOnes = 1,k = 3) == 0\n assert candidate(numOnes = 30,numZeros = 15,numNegOnes = 15,k = 40) == 30\n assert candidate(numOnes = 40,numZeros = 40,numNegOnes = 10,k = 60) == 40\n assert candidate(numOnes = 20,numZeros = 30,numNegOnes = 50,k = 60) == 10\n assert candidate(numOnes = 10,numZeros = 30,numNegOnes = 10,k = 40) == 10\n assert candidate(numOnes = 2,numZeros = 2,numNegOnes = 2,k = 6) == 0\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 25) == 25\n assert candidate(numOnes = 15,numZeros = 25,numNegOnes = 10,k = 20) == 15\n assert candidate(numOnes = 50,numZeros = 0,numNegOnes = 0,k = 25) == 25\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 10,k = 25) == 5\n assert candidate(numOnes = 30,numZeros = 20,numNegOnes = 50,k = 70) == 10\n assert candidate(numOnes = 30,numZeros = 5,numNegOnes = 15,k = 40) == 25\n assert candidate(numOnes = 20,numZeros = 15,numNegOnes = 15,k = 50) == 5\n assert candidate(numOnes = 30,numZeros = 20,numNegOnes = 10,k = 40) == 30\n assert candidate(numOnes = 0,numZeros = 25,numNegOnes = 25,k = 30) == -5\n assert candidate(numOnes = 45,numZeros = 30,numNegOnes = 25,k = 50) == 45\n assert candidate(numOnes = 0,numZeros = 10,numNegOnes = 40,k = 20) == -10\n assert candidate(numOnes = 25,numZeros = 25,numNegOnes = 0,k = 49) == 25\n assert candidate(numOnes = 45,numZeros = 0,numNegOnes = 5,k = 35) == 35\n assert candidate(numOnes = 50,numZeros = 0,numNegOnes = 50,k = 45) == 45\n assert candidate(numOnes = 20,numZeros = 15,numNegOnes = 10,k = 30) == 20\n assert candidate(numOnes = 5,numZeros = 5,numNegOnes = 40,k = 20) == -5\n assert candidate(numOnes = 45,numZeros = 5,numNegOnes = 0,k = 45) == 45\n assert candidate(numOnes = 10,numZeros = 10,numNegOnes = 30,k = 25) == 5\n assert candidate(numOnes = 5,numZeros = 10,numNegOnes = 35,k = 50) == -30\n", "comparison": "exact"}, "public_tests": ["3\n2\n0\n2", "3\n2\n0\n4"], "hints": ["It is always optimal to take items with the number 1 written on them as much as possible.", "If k > numOnes, after taking all items with the number 1, it is always optimal to take items with the number 0 written on them as much as possible.", "If k > numOnes + numZeroes we are forced to take k - numOnes - numZeroes -1s."], "metadata": {"canonical_parameter_names": ["numOnes", "numZeros", "numNegOnes", "k"], "leetcode_dataset_entry_point": "Solution().kItemsWithMaximumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:41+00:00", "tests_total": 105, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def k_items_with_maximum_sum(num_ones, num_zeros, num_neg_ones, k)", "container": null, "callable": "k_items_with_maximum_sum", "parameters": [{"name": "num_ones", "type": "Integer"}, {"name": "num_zeros", "type": "Integer"}, {"name": "num_neg_ones", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2601, "task_id": "prime-subtraction-operation", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of length n.\n\nYou can perform the following operation as many times as you want:\n\n- Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].\n\nReturn true if you can make nums a strictly increasing array using the above operation and false otherwise.\n\nA strictly increasing array is an array whose each element is strictly greater than its preceding element.\n\nExample 1:\n\nInput: nums = [4,9,6,10]\nOutput: true\nExplanation: In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0], so that nums becomes [1,9,6,10].\nIn the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10].\nAfter the second operation, nums is sorted in strictly increasing order, so the answer is true.\n\nExample 2:\n\nInput: nums = [6,8,11,12]\nOutput: true\nExplanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.\n\nExample 3:\n\nInput: nums = [5,8,3]\nOutput: false\nExplanation: It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n- nums.length == n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 9, 6, 10]) == True\n assert candidate(nums = [999, 998, 997, 996, 995]) == True\n assert candidate(nums = [5, 8, 3]) == False\n assert candidate(nums = [100, 99, 98, 97, 96]) == True\n assert candidate(nums = [2, 3, 5, 7, 11]) == True\n assert candidate(nums = [1000, 999, 998]) == True\n assert candidate(nums = [2, 3, 5]) == True\n assert candidate(nums = [7, 14, 4, 14]) == True\n assert candidate(nums = [3, 6, 9, 12]) == True\n assert candidate(nums = [7, 11, 13, 17]) == True\n assert candidate(nums = [20, 18, 15, 10]) == True\n assert candidate(nums = [1, 2, 3, 4]) == True\n assert candidate(nums = [1000, 999, 998, 997, 996]) == True\n assert candidate(nums = [30, 25, 20, 15, 10]) == True\n assert candidate(nums = [500, 400, 300, 200, 100]) == True\n assert candidate(nums = [1000, 999, 998, 997, 996, 995]) == True\n assert candidate(nums = [2, 5, 6]) == True\n assert candidate(nums = [1, 2, 3, 4, 5]) == True\n assert candidate(nums = [10, 9, 8, 7, 6]) == False\n assert candidate(nums = [20, 18, 16, 14, 12, 10]) == False\n assert candidate(nums = [10, 15, 20, 25]) == True\n assert candidate(nums = [15, 14, 13, 12, 11]) == True\n assert candidate(nums = [2, 3, 5, 7]) == True\n assert candidate(nums = [6, 8, 11, 12]) == True\n assert candidate(nums = [2, 5, 10, 17, 26]) == True\n assert candidate(nums = [10, 8, 5, 3]) == False\n assert candidate(nums = [10, 9, 8]) == True\n assert candidate(nums = [3, 3, 3]) == False\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == True\n assert candidate(nums = [20, 18, 16, 14, 12]) == True\n assert candidate(nums = [10, 5, 7, 8]) == True\n assert candidate(nums = [30, 25, 20, 15, 10, 5]) == False\n assert candidate(nums = [2, 5, 4, 6, 8]) == True\n assert candidate(nums = [10, 9, 8, 7]) == True\n assert candidate(nums = [500, 400, 300, 200, 100]) == True\n assert candidate(nums = [541, 523, 509, 499, 491, 487, 479, 467, 463, 461]) == True\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == True\n assert candidate(nums = [541, 521, 503, 491, 479, 467, 457, 449, 439, 431]) == True\n assert candidate(nums = [100, 85, 75, 60, 50]) == True\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == True\n assert candidate(nums = [50, 60, 70, 80]) == True\n assert candidate(nums = [7, 17, 27, 37, 47, 57, 67, 77]) == True\n assert candidate(nums = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50]) == True\n assert candidate(nums = [20, 30, 50, 70, 110]) == True\n assert candidate(nums = [7, 17, 27, 37, 47, 57]) == True\n assert candidate(nums = [31, 31, 31, 31, 31]) == True\n assert candidate(nums = [30, 25, 20, 15, 10, 5]) == False\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == False\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23]) == True\n assert candidate(nums = [12, 14, 16, 18, 20, 22, 24]) == True\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24]) == True\n assert candidate(nums = [23, 29, 31, 37, 41]) == True\n assert candidate(nums = [500, 550, 600, 650, 700, 750, 800]) == True\n assert candidate(nums = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42]) == True\n assert candidate(nums = [11, 13, 15, 17, 19, 21, 23]) == True\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == True\n assert candidate(nums = [500, 490, 480, 470, 460, 450, 440, 430, 420, 410, 400, 390, 380, 370, 360, 350, 340, 330, 320, 310]) == True\n assert candidate(nums = [37, 41, 31, 38, 43]) == True\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80]) == True\n assert candidate(nums = [1000, 500, 250, 125, 63]) == True\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == True\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41]) == True\n assert candidate(nums = [13, 19, 23, 29, 31, 37, 41]) == True\n assert candidate(nums = [500, 490, 480, 470, 460, 450]) == True\n assert candidate(nums = [19, 23, 29, 31, 37, 41, 43, 47]) == True\n assert candidate(nums = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]) == True\n assert candidate(nums = [999, 998, 997, 996, 995]) == True\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56]) == True\n assert candidate(nums = [40, 35, 30, 25, 20, 15, 10]) == False\n assert candidate(nums = [300, 250, 200, 150, 100, 50]) == True\n assert candidate(nums = [8, 15, 22, 29, 36, 43]) == True\n assert candidate(nums = [500, 501, 502, 503, 504]) == True\n assert candidate(nums = [999, 888, 777, 666, 555]) == True\n assert candidate(nums = [4, 8, 12, 16, 20, 24]) == True\n assert candidate(nums = [29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == False\n assert candidate(nums = [19, 23, 29, 31, 37, 41, 43, 47, 53, 59]) == True\n assert candidate(nums = [11, 19, 29, 37, 41, 43]) == True\n assert candidate(nums = [100, 200, 150, 250, 200, 300, 250, 350, 300, 400]) == True\n assert candidate(nums = [20, 18, 16, 14, 12]) == True\n assert candidate(nums = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == False\n assert candidate(nums = [100, 90, 80, 70, 60]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131]) == True\n assert candidate(nums = [200, 199, 198, 197, 196]) == True\n assert candidate(nums = [17, 23, 19, 29, 31]) == True\n assert candidate(nums = [19, 23, 18, 29, 31]) == True\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29]) == True\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149]) == True\n assert candidate(nums = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == True\n assert candidate(nums = [600, 500, 400, 300, 200, 100]) == True\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == False\n assert candidate(nums = [15, 20, 25, 30, 35, 40]) == True\n assert candidate(nums = [83, 79, 73, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == False\n assert candidate(nums = [11, 11, 11, 11, 11, 11, 11, 11, 11, 11]) == False\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]) == True\n assert candidate(nums = [89, 97, 83, 79, 88, 85]) == True\n assert candidate(nums = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == True\n assert candidate(nums = [15, 18, 21, 25]) == True\n assert candidate(nums = [997, 991, 983, 977, 971, 967, 953, 947, 941, 937]) == True\n assert candidate(nums = [100, 98, 96, 94, 92]) == True\n assert candidate(nums = [100, 200, 150, 250, 200, 300]) == True\n assert candidate(nums = [250, 251, 252, 253, 254, 255]) == True\n assert candidate(nums = [1000, 999, 998, 997]) == True\n assert candidate(nums = [89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67]) == True\n assert candidate(nums = [50, 49, 48, 47, 46, 45]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(nums = [11, 13, 15, 17, 19]) == True\n assert candidate(nums = [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]) == True\n assert candidate(nums = [30, 28, 25, 23, 21, 19]) == True\n assert candidate(nums = [500, 450, 400, 350, 300]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [500, 400, 300, 200, 100, 50, 25, 10, 5, 1]) == False\n assert candidate(nums = [100, 90, 80, 70, 60]) == True\n assert candidate(nums = [29, 28, 27, 26, 25, 24]) == True\n assert candidate(nums = [20, 18, 16, 14]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == True\n assert candidate(nums = [17, 23, 29, 31, 37, 41, 43]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == True\n assert candidate(nums = [45, 55, 65, 75, 85, 95, 105]) == True\n assert candidate(nums = [41, 43, 47, 53, 61]) == True\n assert candidate(nums = [30, 28, 26, 24, 22, 20, 18, 16]) == False\n assert candidate(nums = [20, 18, 15, 12, 10]) == True\n assert candidate(nums = [41, 37, 31, 29, 23, 19, 17, 13]) == False\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980, 979, 978, 977, 976, 975, 974, 973, 972, 971, 970, 969, 968, 967, 966, 965, 964, 963, 962, 961, 960, 959, 958, 957, 956, 955, 954, 953, 952, 951, 950]) == True\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == False\n assert candidate(nums = [888, 887, 886, 885, 884]) == True\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == True\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == False\n assert candidate(nums = [100, 97, 94, 91]) == True\n assert candidate(nums = [42, 41, 40, 39, 38, 37, 36, 35, 34, 33]) == True\n assert candidate(nums = [10, 12, 8, 14, 6, 18, 4, 20, 2]) == False\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70]) == True\n assert candidate(nums = [7, 14, 21, 28, 35, 42]) == True\n assert candidate(nums = [839, 829, 827, 823, 821, 811, 809, 803, 797, 787]) == True\n assert candidate(nums = [300, 299, 298, 297, 296, 295]) == True\n assert candidate(nums = [15, 14, 13, 12, 11]) == True\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991]) == True\n assert candidate(nums = [29, 23, 19, 17, 13, 11, 7]) == False\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == True\n assert candidate(nums = [12, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == True\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == False\n assert candidate(nums = [45, 56, 78, 89, 100]) == True\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59]) == True\n assert candidate(nums = [800, 850, 900, 950, 1000]) == True\n assert candidate(nums = [20, 15, 10, 5]) == True\n assert candidate(nums = [7, 14, 21, 28, 35]) == True\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117]) == True\n assert candidate(nums = [11, 22, 33, 44, 55, 66]) == True\n assert candidate(nums = [7, 17, 11, 23, 19]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19]) == True\n assert candidate(nums = [15, 18, 21, 24, 27, 30]) == True\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == True\n assert candidate(nums = [101, 103, 107, 109, 113]) == True\n assert candidate(nums = [24, 24, 24, 24, 24]) == True\n assert candidate(nums = [13, 23, 13, 23, 13]) == True\n assert candidate(nums = [50, 40, 30, 20, 10]) == False\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19]) == True\n", "comparison": "exact"}, "public_tests": ["[4,9,6,10]", "[6,8,11,12]", "[5,8,3]"], "hints": ["Think about if we have many primes to subtract from nums[i]. Which prime is more optimal?", "The most optimal prime to subtract from nums[i] is the one that makes nums[i] the smallest as possible and greater than nums[i-1]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().primeSubOperation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:44+00:00", "tests_total": 157, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "binary-search", "greedy", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def prime_sub_operation(nums)", "container": null, "callable": "prime_sub_operation", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2602, "task_id": "minimum-operations-to-make-all-array-elements-equal", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of positive integers.\n\nYou are also given an integer array queries of size m. For the i^th query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:\n\n- Increase or decrease an element of the array by 1.\n\nReturn an array answer of size m where answer[i] is the minimum number of operations to make all elements of nums equal to queries[i].\n\nNote that after each query the array is reset to its original state.\n\nExample 1:\n\nInput: nums = [3,1,6,8], queries = [1,5]\nOutput: [14,10]\nExplanation: For the first query we can do the following operations:\n- Decrease nums[0] 2 times, so that nums = [1,1,6,8].\n- Decrease nums[2] 5 times, so that nums = [1,1,1,8].\n- Decrease nums[3] 7 times, so that nums = [1,1,1,1].\nSo the total number of operations for the first query is 2 + 5 + 7 = 14.\nFor the second query we can do the following operations:\n- Increase nums[0] 2 times, so that nums = [5,1,6,8].\n- Increase nums[1] 4 times, so that nums = [5,5,6,8].\n- Decrease nums[2] 1 time, so that nums = [5,5,5,8].\n- Decrease nums[3] 3 times, so that nums = [5,5,5,5].\nSo the total number of operations for the second query is 2 + 4 + 1 + 3 = 10.\n\nExample 2:\n\nInput: nums = [2,9,6,3], queries = [10]\nOutput: [20]\nExplanation: We can increase each value in the array to 10. The total number of operations will be 8 + 1 + 4 + 7 = 20.\n\nConstraints:\n\n- n == nums.length\n- m == queries.length\n- 1 <= n, m <= 10^5\n- 1 <= nums[i], queries[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],queries = [1000000000, 1, 999999999]) == [0, 999999999, 1]\n assert candidate(nums = [2, 9, 6, 3],queries = [10]) == [20]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [1, 2, 3]) == [0, 5, 10]\n assert candidate(nums = [100, 200, 300],queries = [150, 250]) == [250, 250]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [3]) == [6]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],queries = [2, 3, 4]) == [12, 8, 10]\n assert candidate(nums = [1, 1, 1, 1],queries = [1]) == [0]\n assert candidate(nums = [3, 1, 6, 8],queries = [1, 5]) == [14, 10]\n assert candidate(nums = [1000000000, 1000000000, 1000000000],queries = [1000000000]) == [0]\n assert candidate(nums = [1, 3, 5, 7, 9],queries = [2, 4, 6, 8]) == [17, 13, 13, 17]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 1, 10, 3]) == [25, 45, 45, 31]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [3, 7, 10]) == [40, 40, 100]\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000],queries = [500000, 1500000]) == [2500000, 2500000]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],queries = [3, 10]) == [21, 66]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [3, 5]) == [12, 20]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [500000000, 1, 1000000000]) == [4888888889, 1111111101, 8888888889]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [5, 50, 500, 5000, 50000, 500000, 5000000, 50000000, 500000000]) == [1111111069, 1111110789, 1111108889, 1111098889, 1111088889, 1111888889, 1128888889, 1388888889, 4888888889]\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],queries = [15, 20, 25]) == [225, 245, 315]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],queries = [10, 25, 1, 35]) == [260, 208, 400, 298]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [7, 15, 1]) == [57, 105, 105]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],queries = [20, 10, 30, 15]) == [200, 250, 250, 212]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],queries = [25, 50, 75]) == [250, 0, 250]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [500000000, 1, 1000000000]) == [4888888889, 1111111101, 8888888889]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [500, 410, 340, 290, 260, 250, 260, 290, 340, 410, 500]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [5, 1, 10, 3]) == [0, 40, 50, 20]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],queries = [1, 3, 5, 7, 9]) == [33, 21, 21, 37, 55]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [55, 45, 65, 35, 75]) == [250, 260, 260, 290, 290]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [25, 15, 35, 10, 40]) == [125, 155, 135, 185, 155]\n assert candidate(nums = [1, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [1, 50, 100, 500, 1000, 5000, 10000, 50000, 1000000]) == [1111111092, 1111110749, 1111110399, 1111108399, 1111105899, 1111093899, 1111078899, 1111038899, 1111888899]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],queries = [1, 5, 10]) == [90, 50, 90]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [1, 5, 9]) == [40, 0, 40]\n assert candidate(nums = [999999999, 1, 999999998, 2, 999999997, 3, 999999996, 4, 999999995, 5],queries = [999999999, 1, 500000000, 1000000000]) == [4999999990, 4999999990, 4999999970, 5000000000]\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],queries = [999999990, 999999995, 999999999]) == [45, 25, 45]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [15, 25, 35, 45]) == [85, 65, 65, 85]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],queries = [10, 20, 30, 40]) == [250, 200, 250, 400]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [1, 5, 10]) == [40, 0, 50]\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],queries = [15, 10, 25, 20]) == [225, 255, 315, 245]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [25, 95, 195, 295, 395, 495, 595, 695, 795, 895]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [25, 75, 50]) == [340, 290, 250]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [25, 35, 15, 45]) == [125, 135, 155, 185]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],queries = [10, 15, 20]) == [125, 112, 125]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],queries = [10, 20, 30]) == [250, 200, 250]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [5, 10, 1]) == [20, 45, 36]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [1, 5, 9]) == [36, 20, 36]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [90, 74, 62, 54, 50, 50, 54, 62, 74, 90]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [1, 8, 15]) == [105, 56, 105]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [55, 65]) == [250, 260]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [500, 410, 340, 290, 260, 250, 260, 290, 340, 410]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5]) == [0, 10, 20, 30, 40]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [10, 15, 5, 20]) == [100, 120, 130, 190]\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000],queries = [500000000, 1000000000, 1]) == [2999999997, 2999999997, 2999999997]\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9],queries = [1000000000, 5, 1, 10]) == [8999999955, 1000000015, 1000000035, 1000000035]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [10, 1, 5]) == [90, 0, 40]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [5, 3, 7]) == [20, 24, 24]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 10, 1]) == [25, 45, 45]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [1, 55, 101]) == [540, 250, 460]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [55, 85, 105, 125]) == [625, 565, 625, 765]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 3, 7, 1]) == [25, 31, 27, 45]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],queries = [25, 50, 75]) == [650, 500, 600]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],queries = [3, 7, 11, 1]) == [62, 54, 110, 90]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 5, 10]) == [45, 25, 45]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [1, 5, 9]) == [36, 20, 36]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 30]) == [210, 184, 162, 144, 130, 120, 114, 112, 114, 120, 130, 144, 162, 184, 210, 225]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [5, 10, 1]) == [0, 50, 40]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [3, 4, 2, 1]) == [12, 14, 14, 20]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [1, 10]) == [40, 50]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [2, 6, 10, 14, 18]) == [82, 58, 50, 58, 82]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [10, 55, 100]) == [450, 250, 450]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [10, 15, 5, 25]) == [100, 120, 130, 290]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],queries = [999999993, 500000000]) == [31, 4999999955]\n assert candidate(nums = [500000000, 600000000, 700000000, 800000000, 900000000],queries = [400000000, 1000000000]) == [1500000000, 1500000000]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],queries = [1000000000, 1, 1953125]) == [8001953125, 1998046865, 1978515625]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [5, 3, 7, 10]) == [25, 31, 27, 45]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2, 3]) == [0, 10, 20]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [1, 2, 3, 4, 5]) == [20, 14, 12, 14, 20]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],queries = [999999995, 999999998, 1000000000]) == [15, 6, 10]\n assert candidate(nums = [1, 3, 5, 7, 9],queries = [2, 4, 6, 8, 10]) == [17, 13, 13, 17, 25]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [82, 68, 58, 52, 50, 52, 58, 68, 82, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [1, 20, 10, 15]) == [190, 190, 100, 120]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 1, 10, 3]) == [25, 45, 45, 31]\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],queries = [12, 13, 14]) == [157, 156, 157]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2]) == [0, 20]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [7, 14]) == [57, 92]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [500, 50000, 5000000, 500000000]) == [1111108889, 1111088889, 1128888889, 4888888889]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [11, 12, 13, 14, 15]) == [55, 65, 75, 85, 95]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 15]) == [25, 95]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [10, 20, 30]) == [100, 190, 390]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [5, 10, 15]) == [130, 100, 120]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [3, 4]) == [12, 14]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],queries = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [21, 33, 20, 33, 21, 55, 26, 28, 21, 21, 21]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [3, 7, 10]) == [20, 20, 50]\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],queries = [1, 13, 25]) == [300, 156, 300]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [10, 15, 20]) == [100, 120, 190]\n", "comparison": "exact"}, "public_tests": ["[3,1,6,8]\n[1,5]", "[2,9,6,3]\n[10]"], "hints": ["For each query, you should decrease all elements greater than queries[i] and increase all elements less than queries[i].", "The answer is the sum of absolute differences between queries[i] and every element of the array. How do you calculate that optimally?"], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:46+00:00", "tests_total": 107, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "binary-search", "sorting", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums, queries)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2603, "task_id": "collect-coins-in-a-tree", "difficulty": "Hard", "problem_description": "There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. You are also given an array coins of size n where coins[i] can be either 0 or 1, where 1 indicates the presence of a coin in the vertex i.\n\nInitially, you choose to start at any vertex in the tree. Then, you can perform the following operations any number of times:\n\n- Collect all the coins that are at a distance of at most 2 from the current vertex, or\n- Move to any adjacent vertex in the tree.\n\nFind the minimum number of edges you need to go through to collect all the coins and go back to the initial vertex.\n\nNote that if you pass an edge several times, you need to count it into the answer several times.\n\nExample 1:\n\nInput: coins = [1,0,0,0,0,1], edges = [[0,1],[1,2],[2,3],[3,4],[4,5]]\nOutput: 2\nExplanation: Start at vertex 2, collect the coin at vertex 0, move to vertex 3, collect the coin at vertex 5 then move back to vertex 2.\n\nExample 2:\n\nInput: coins = [0,0,0,1,1,0,0,1], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]\nOutput: 2\nExplanation: Start at vertex 0, collect the coins at vertices 4 and 3, move to vertex 2, collect the coin at vertex 7, then move back to vertex 0.\n\nConstraints:\n\n- n == coins.length\n- 1 <= n <= 3 * 10^4\n- 0 <= coins[i] <= 1\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= a_i, b_i < n\n- a_i != b_i\n- edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(coins = [0, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]]) == 0\n assert candidate(coins = [0, 0, 0, 0, 0, 0, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(coins = [1, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(coins = [1, 1, 0, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4]]) == 0\n assert candidate(coins = [1, 1, 0, 0, 1, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == 0\n assert candidate(coins = [0, 0, 0, 1, 1, 0, 0, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [5, 6], [5, 7]]) == 2\n assert candidate(coins = [1, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(coins = [0, 0, 1, 0, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4]]) == 0\n assert candidate(coins = [1, 1, 1, 1, 1, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == 0\n assert candidate(coins = [1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 4\n assert candidate(coins = [1, 1, 0, 0],edges = [[0, 1], [1, 2], [1, 3]]) == 0\n assert candidate(coins = [0, 0, 0, 0, 0, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(coins = [1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6]]) == 0\n assert candidate(coins = [1, 1, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 4\n assert candidate(coins = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 8\n assert candidate(coins = [0, 0, 1, 1, 1, 0, 1, 0, 0, 0],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [7, 8], [7, 9]]) == 0\n assert candidate(coins = [0, 0, 1, 0, 1, 1, 0, 0, 1, 0],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 4\n assert candidate(coins = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 28\n assert candidate(coins = [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 8\n assert candidate(coins = [1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 14\n assert candidate(coins = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 32\n assert candidate(coins = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24]]) == 2\n assert candidate(coins = [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12]]) == 2\n assert candidate(coins = [1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 8\n assert candidate(coins = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [2, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 2\n assert candidate(coins = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [5, 8], [5, 9], [8, 10]]) == 2\n assert candidate(coins = [1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [3, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 10\n assert candidate(coins = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 20\n assert candidate(coins = [1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11]]) == 2\n assert candidate(coins = [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [7, 12], [7, 13], [11, 14]]) == 0\n assert candidate(coins = [1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]]) == 4\n assert candidate(coins = [1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 20\n assert candidate(coins = [0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 6\n assert candidate(coins = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16]]) == 20\n assert candidate(coins = [0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == 4\n assert candidate(coins = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 0\n assert candidate(coins = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 22\n assert candidate(coins = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 8\n assert candidate(coins = [1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 12\n assert candidate(coins = [1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == 4\n assert candidate(coins = [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 10\n assert candidate(coins = [1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 20\n assert candidate(coins = [1, 0, 0, 1, 0, 0, 1, 0, 1, 0],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 2\n assert candidate(coins = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [5, 10], [7, 11]]) == 4\n assert candidate(coins = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 0\n assert candidate(coins = [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == 12\n assert candidate(coins = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 30\n assert candidate(coins = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 32\n assert candidate(coins = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16]]) == 24\n assert candidate(coins = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24]]) == 40\n assert candidate(coins = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == 16\n assert candidate(coins = [0, 1, 1, 0, 0, 1, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [4, 5], [4, 6], [6, 7], [7, 8], [8, 9]]) == 6\n assert candidate(coins = [0, 1, 1, 1, 0, 0, 0, 1, 0, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 8\n assert candidate(coins = [0, 0, 1, 0, 1, 1, 0, 0, 1, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 4\n assert candidate(coins = [1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 20\n assert candidate(coins = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 6\n", "comparison": "exact"}, "public_tests": ["[1,0,0,0,0,1]\n[[0,1],[1,2],[2,3],[3,4],[4,5]]", "[0,0,0,1,1,0,0,1]\n[[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]"], "hints": ["All leaves that do not have a coin are redundant and can be deleted from the tree.", "Remove the leaves that do not have coins on them, so that the resulting tree will have a coin on every leaf.", "In the remaining tree, remove each leaf node and its parent from the tree. The remaining nodes in the tree are the ones that must be visited. Hence, the answer is equal to (# remaining nodes -1) * 2"], "metadata": {"canonical_parameter_names": ["coins", "edges"], "leetcode_dataset_entry_point": "Solution().collectTheCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:48+00:00", "tests_total": 65, "tests_dropped": 9, "flags": ["has_images"], "topic_tags": ["array", "tree", "graph", "topological-sort"]}, "language": "ruby", "interface": {"raw_signature": "def collect_the_coins(coins, edges)", "container": null, "callable": "collect_the_coins", "parameters": [{"name": "coins", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2605, "task_id": "form-smallest-number-from-two-digit-arrays", "difficulty": "Easy", "problem_description": "Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.\n\nExample 1:\n\nInput: nums1 = [4,1,3], nums2 = [5,7]\nOutput: 15\nExplanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest number we can have.\n\nExample 2:\n\nInput: nums1 = [3,5,2,6], nums2 = [3,1,7]\nOutput: 3\nExplanation: The number 3 contains the digit 3 which exists in both arrays.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 9\n- 1 <= nums1[i], nums2[i] <= 9\n- All digits in each array are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 4, 5]) == 3\n assert candidate(nums1 = [1, 2],nums2 = [3, 4]) == 13\n assert candidate(nums1 = [1, 9],nums2 = [2, 8]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9]) == 16\n assert candidate(nums1 = [9, 8, 7],nums2 = [6, 5, 4]) == 47\n assert candidate(nums1 = [1],nums2 = [2]) == 12\n assert candidate(nums1 = [2],nums2 = [3]) == 23\n assert candidate(nums1 = [7, 8, 9],nums2 = [9, 8, 7]) == 7\n assert candidate(nums1 = [9, 8],nums2 = [7, 6]) == 68\n assert candidate(nums1 = [3, 5, 2, 6],nums2 = [3, 1, 7]) == 3\n assert candidate(nums1 = [5],nums2 = [5]) == 5\n assert candidate(nums1 = [7, 3],nums2 = [3, 7]) == 3\n assert candidate(nums1 = [1],nums2 = [9]) == 19\n assert candidate(nums1 = [9],nums2 = [1]) == 19\n assert candidate(nums1 = [2, 4, 6],nums2 = [1, 3, 5]) == 12\n assert candidate(nums1 = [4, 1, 3],nums2 = [5, 7]) == 15\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == 14\n assert candidate(nums1 = [1, 4, 7],nums2 = [2, 5, 8, 9]) == 12\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [2, 4, 6, 8]) == 12\n assert candidate(nums1 = [2, 4, 6, 8],nums2 = [3, 5, 7, 9, 1]) == 12\n assert candidate(nums1 = [8, 9],nums2 = [8, 9, 1, 2]) == 8\n assert candidate(nums1 = [2, 3, 5],nums2 = [2, 3, 4]) == 2\n assert candidate(nums1 = [7, 9, 1],nums2 = [2, 4, 6]) == 12\n assert candidate(nums1 = [7, 8, 9],nums2 = [2, 4, 6]) == 27\n assert candidate(nums1 = [1, 4, 7],nums2 = [2, 5, 8]) == 12\n assert candidate(nums1 = [3, 1, 4],nums2 = [1, 5, 9]) == 1\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [2, 4, 6, 8]) == 2\n assert candidate(nums1 = [5, 7, 9],nums2 = [5, 3, 8, 2]) == 5\n assert candidate(nums1 = [2, 3, 6, 9],nums2 = [1, 4, 7]) == 12\n assert candidate(nums1 = [8, 2, 4, 6],nums2 = [7, 3, 9, 1]) == 12\n assert candidate(nums1 = [3, 4, 5],nums2 = [3, 4, 5]) == 3\n assert candidate(nums1 = [1],nums2 = [1]) == 1\n assert candidate(nums1 = [5, 9],nums2 = [5, 3]) == 5\n assert candidate(nums1 = [8, 2, 4],nums2 = [5, 6, 7, 9]) == 25\n assert candidate(nums1 = [2, 4, 6, 8],nums2 = [1, 3, 5, 7]) == 12\n assert candidate(nums1 = [9, 8, 7, 6, 5],nums2 = [4, 3, 2, 1]) == 15\n assert candidate(nums1 = [7, 3, 8],nums2 = [9, 4, 1]) == 13\n assert candidate(nums1 = [1, 4, 7],nums2 = [2, 5, 8]) == 12\n assert candidate(nums1 = [9, 7, 5],nums2 = [3, 1]) == 15\n assert candidate(nums1 = [9],nums2 = [1, 2, 3, 4, 5, 6, 7, 8]) == 19\n assert candidate(nums1 = [5, 6, 1],nums2 = [6, 7, 2]) == 6\n assert candidate(nums1 = [4, 5, 6],nums2 = [6, 7, 8]) == 6\n assert candidate(nums1 = [1, 5, 9],nums2 = [2, 6, 8]) == 12\n assert candidate(nums1 = [3, 6, 9],nums2 = [3, 5, 8]) == 3\n assert candidate(nums1 = [2, 5, 9],nums2 = [5, 8, 3]) == 5\n assert candidate(nums1 = [9, 8, 7, 6],nums2 = [5, 4, 3, 2, 1]) == 16\n assert candidate(nums1 = [5, 3, 7],nums2 = [8, 5, 3]) == 3\n assert candidate(nums1 = [6, 3, 1],nums2 = [7, 5, 9, 2, 4]) == 12\n assert candidate(nums1 = [4, 5],nums2 = [4, 5, 6]) == 4\n assert candidate(nums1 = [1, 2],nums2 = [3, 4, 5, 6, 7, 8, 9]) == 13\n assert candidate(nums1 = [3, 7, 1, 5],nums2 = [1, 9, 6, 8]) == 1\n assert candidate(nums1 = [1],nums2 = [9, 8, 7, 6, 5, 4, 3, 2]) == 12\n assert candidate(nums1 = [7, 8, 9],nums2 = [1, 2, 3]) == 17\n assert candidate(nums1 = [3, 5, 7],nums2 = [5, 7, 9]) == 5\n assert candidate(nums1 = [3, 6, 9],nums2 = [3, 6, 9]) == 3\n assert candidate(nums1 = [7, 2, 9],nums2 = [3, 2, 8]) == 2\n assert candidate(nums1 = [8, 6, 2],nums2 = [4, 2, 9]) == 2\n assert candidate(nums1 = [2, 4, 6, 8],nums2 = [1, 3, 5, 7, 9]) == 12\n assert candidate(nums1 = [3],nums2 = [9, 8, 7, 6, 5, 4, 2, 1]) == 13\n assert candidate(nums1 = [9, 7, 5],nums2 = [8, 6, 4]) == 45\n assert candidate(nums1 = [1, 6],nums2 = [5, 6]) == 6\n assert candidate(nums1 = [1, 5, 9],nums2 = [1, 5, 9]) == 1\n assert candidate(nums1 = [9, 8, 7],nums2 = [6, 5, 4]) == 47\n assert candidate(nums1 = [5, 3, 8, 1],nums2 = [4, 7, 6, 2, 9]) == 12\n assert candidate(nums1 = [2, 3, 5, 7],nums2 = [1, 4, 6, 8, 9]) == 12\n assert candidate(nums1 = [5],nums2 = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2],nums2 = [1]) == 12\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8]) == 12\n assert candidate(nums1 = [1, 3, 7, 9],nums2 = [2, 4, 6, 8]) == 12\n assert candidate(nums1 = [3, 7, 9],nums2 = [3, 4, 5]) == 3\n assert candidate(nums1 = [5, 3, 8],nums2 = [8, 2, 7]) == 8\n assert candidate(nums1 = [3, 6, 8],nums2 = [2, 5, 7]) == 23\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9]) == 9\n assert candidate(nums1 = [1, 3, 5, 7],nums2 = [2, 4, 6, 8]) == 12\n assert candidate(nums1 = [8, 9],nums2 = [1, 2, 3, 4, 5]) == 18\n assert candidate(nums1 = [5, 9],nums2 = [5, 7]) == 5\n assert candidate(nums1 = [9, 7, 5, 3],nums2 = [8, 6, 4, 2, 1]) == 13\n assert candidate(nums1 = [1, 2],nums2 = [2, 3]) == 2\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [3, 4, 5, 6, 7]) == 3\n assert candidate(nums1 = [4],nums2 = [4]) == 4\n assert candidate(nums1 = [2, 4, 6, 8],nums2 = [4]) == 4\n assert candidate(nums1 = [7, 8, 9],nums2 = [1, 2, 3, 4, 5, 6]) == 17\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 6, 7, 8, 9]) == 5\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8]) == 12\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 4, 5]) == 3\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 4, 5, 6, 7]) == 3\n assert candidate(nums1 = [1],nums2 = [9, 8, 7, 6, 5, 4, 3, 2]) == 12\n assert candidate(nums1 = [5, 6, 7],nums2 = [1, 2, 3, 4]) == 15\n assert candidate(nums1 = [4, 8],nums2 = [5, 7, 9]) == 45\n assert candidate(nums1 = [7, 5, 3, 1],nums2 = [8, 6, 4, 2]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums1 = [2, 8, 6],nums2 = [7, 4, 1]) == 12\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [4, 5, 6, 7]) == 4\n assert candidate(nums1 = [3, 6, 9],nums2 = [3, 5, 7]) == 3\n", "comparison": "exact"}, "public_tests": ["[4,1,3]\n[5,7]", "[3,5,2,6]\n[3,1,7]"], "hints": ["How many digits will the resulting number have at most?", "The resulting number will have either one or two digits. Try to find when each case is possible."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:53+00:00", "tests_total": 97, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def min_number(nums1, nums2)", "container": null, "callable": "min_number", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2606, "task_id": "find-the-substring-with-maximum-cost", "difficulty": "Medium", "problem_description": "You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.\n\nThe cost of the substring is the sum of the values of each character in the substring. The cost of an empty string is considered 0.\n\nThe value of the character is defined in the following way:\n\n- If the character is not in the string chars, then its value is its corresponding position (1-indexed) in the alphabet.\n - For example, the value of 'a' is 1, the value of 'b' is 2, and so on. The value of 'z' is 26.\n- Otherwise, assuming i is the index where the character occurs in the string chars, then its value is vals[i].\n\nReturn the maximum cost among all substrings of the string s.\n\nExample 1:\n\nInput: s = \"adaa\", chars = \"d\", vals = [-1000]\nOutput: 2\nExplanation: The value of the characters \"a\" and \"d\" is 1 and -1000 respectively.\nThe substring with the maximum cost is \"aa\" and its cost is 1 + 1 = 2.\nIt can be proven that 2 is the maximum cost.\n\nExample 2:\n\nInput: s = \"abc\", chars = \"abc\", vals = [-1,-1,-1]\nOutput: 0\nExplanation: The value of the characters \"a\", \"b\" and \"c\" is -1, -1, and -1 respectively.\nThe substring with the maximum cost is the empty substring \"\" and its cost is 0.\nIt can be proven that 0 is the maximum cost.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consist of lowercase English letters.\n- 1 <= chars.length <= 26\n- chars consist of distinct lowercase English letters.\n- vals.length == chars.length\n- -1000 <= vals[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"programming\",chars = \"pg\",vals = [-1, -2]) == 99\n assert candidate(s = \"a\",chars = \"a\",vals = [-1]) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-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(s = \"zzzzz\",chars = \"z\",vals = [26]) == 130\n assert candidate(s = \"xyz\",chars = \"xyz\",vals = [24, 25, 26]) == 75\n assert candidate(s = \"adaa\",chars = \"d\",vals = [-1000]) == 2\n assert candidate(s = \"abacaba\",chars = \"abc\",vals = [1, 2, 3]) == 11\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [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]) == 351\n assert candidate(s = \"zzzz\",chars = \"z\",vals = [26]) == 104\n assert candidate(s = \"hello\",chars = \"he\",vals = [5, 10]) == 54\n assert candidate(s = \"abc\",chars = \"abc\",vals = [-1, -1, -1]) == 0\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-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]) == 0\n assert candidate(s = \"abc\",chars = \"abc\",vals = [-1, -1, -1]) == 0\n assert candidate(s = \"zzyx\",chars = \"zxy\",vals = [100, 200, 300]) == 700\n assert candidate(s = \"aaa\",chars = \"a\",vals = [1]) == 3\n assert candidate(s = \"hello\",chars = \"aeiou\",vals = [1, 2, 3, 4, 5]) == 38\n assert candidate(s = \"programming\",chars = \"pg\",vals = [-5, -10]) == 91\n assert candidate(s = \"zzz\",chars = \"z\",vals = [1000]) == 3000\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [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]) == 351\n assert candidate(s = \"hello\",chars = \"helo\",vals = [5, 10, 15, 20]) == 65\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",chars = \"a\",vals = [1000]) == 2350\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-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]) == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [1000]) == 26000\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [100]) == 2800\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [-1]) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"z\",vals = [-26]) == 325\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [-1, -2, -3]) == 4\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [3, 2, 1]) == 38\n assert candidate(s = \"aaaabbbbcccc\",chars = \"abc\",vals = [1, -2, 3]) == 12\n assert candidate(s = \"zzyyxx\",chars = \"xyz\",vals = [100, 200, -300]) == 600\n assert candidate(s = \"xyzzyxzyxzyxzyxzyxzyx\",chars = \"xyz\",vals = [10, 20, 30]) == 420\n assert candidate(s = \"hello\",chars = \"lo\",vals = [-1, -2]) == 13\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"abcdefghijklmnopqrstuvwxy\",vals = [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]) == 702\n assert candidate(s = \"mnopqr\",chars = \"mnopqr\",vals = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(s = \"hellohellohello\",chars = \"he\",vals = [10, -5]) == 132\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [26]) == 520\n assert candidate(s = \"abcdefgxyz\",chars = \"xyz\",vals = [100, 100, 100]) == 328\n assert candidate(s = \"aabbccddeeffgg\",chars = \"abcdefg\",vals = [-1, -2, -3, -4, -5, -6, -7]) == 0\n assert candidate(s = \"mnopqrstuvwxyzaaa\",chars = \"mno\",vals = [13, 14, 15]) == 276\n assert candidate(s = \"abcxyz\",chars = \"abcxyz\",vals = [-1, -2, -3, -4, -5, -6]) == 0\n assert candidate(s = \"thisisatemporarystring\",chars = \"aeiou\",vals = [1, -1, 2, -2, 3]) == 259\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [-1]) == 0\n assert candidate(s = \"abcdefabcdefabcdef\",chars = \"def\",vals = [100, 200, 300]) == 1818\n assert candidate(s = \"zzzzzzzzzzz\",chars = \"z\",vals = [1000]) == 11000\n assert candidate(s = \"abcdef\",chars = \"abcde\",vals = [-1, -2, -3, -4, -5]) == 6\n assert candidate(s = \"xyzzzzyx\",chars = \"xyz\",vals = [-1, -2, -3]) == 0\n assert candidate(s = \"qwpwoeirutyiuyweoiuqweoiuyt\",chars = \"qwertyuiopasdfghjklzxcvbnm\",vals = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 0\n assert candidate(s = \"mnopqr\",chars = \"mno\",vals = [10, 20, -30]) == 51\n assert candidate(s = \"babababababababababababa\",chars = \"ab\",vals = [-1, 1]) == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-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(s = \"mississippi\",chars = \"ism\",vals = [-1, -2, 10]) == 32\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"def\",vals = [-10, 0, 5]) == 335\n assert candidate(s = \"abcdefghijklm\",chars = \"def\",vals = [10, 20, 30]) == 136\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [10, 20, 30]) == 224\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",chars = \"qwertyuiop\",vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 732\n assert candidate(s = \"aaaabaaa\",chars = \"a\",vals = [5]) == 37\n assert candidate(s = \"zzzzzzzzzz\",chars = \"z\",vals = [100]) == 1000\n assert candidate(s = \"v\",chars = \"v\",vals = [1000]) == 1000\n assert candidate(s = \"xyzabc\",chars = \"xyzabc\",vals = [6, 5, 4, 3, 2, 1]) == 21\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"abcdefghijklmnopqrstuvwxy\",vals = [-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]) == 52\n assert candidate(s = \"abcdefghijklm\",chars = \"def\",vals = [-5, -6, -7]) == 70\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"acegikmoqsuwy\",vals = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13]) == 378\n assert candidate(s = \"aaaaabbbbbccccc\",chars = \"abc\",vals = [1, -1, 0]) == 5\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [-1, -1, -1]) == 4\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",chars = \"a\",vals = [1]) == 32\n assert candidate(s = \"aaaaabaaaabaaaa\",chars = \"a\",vals = [-1]) == 2\n assert candidate(s = \"aabaaaabaaaaaaab\",chars = \"a\",vals = [-1]) == 2\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [3, -2, 1]) == 22\n assert candidate(s = \"aabaaaabaaaaaaab\",chars = \"a\",vals = [1]) == 19\n assert candidate(s = \"abababababababababababababab\",chars = \"ab\",vals = [1000, -1000]) == 1000\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [-1, 2, 3]) == 12\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [-5]) == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [0]) == 0\n assert candidate(s = \"abcdefg\",chars = \"xyz\",vals = [10, 20, 30]) == 28\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",chars = \"abc\",vals = [10, 20, 30]) == 600\n assert candidate(s = \"abcdefgxyz\",chars = \"adg\",vals = [10, -5, 20]) == 116\n assert candidate(s = \"abcabcabc\",chars = \"abc\",vals = [-1, -1, -1]) == 0\n assert candidate(s = \"thisisateststring\",chars = \"test\",vals = [-1, -2, -3, -4]) == 49\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [-26]) == 0\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",chars = \"qz\",vals = [-100, 100]) == 408\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",chars = \"zyx\",vals = [26, 25, 24]) == 351\n assert candidate(s = \"abcdexyz\",chars = \"xyz\",vals = [-1, -2, -3]) == 15\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [1, -2, 3]) == 12\n assert candidate(s = \"abcdefgxyz\",chars = \"aceg\",vals = [-1, -2, -3, -4]) == 78\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"a\",vals = [-1]) == 350\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [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]) == 702\n assert candidate(s = \"zzzzzzzzzz\",chars = \"z\",vals = [-1]) == 0\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [5, -1, 10]) == 60\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",chars = \"qwertyuiopasdfghjklzxcvbnm\",vals = [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]) == 13\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\",chars = \"aeiou\",vals = [-10, -20, -30, -40, -50]) == 53\n assert candidate(s = \"mnopqrstuvwxyz\",chars = \"mnop\",vals = [10, 20, 30, 40]) == 315\n assert candidate(s = \"abcabcabcabcabc\",chars = \"abc\",vals = [1, 2, 3]) == 30\n assert candidate(s = \"bananabananabanana\",chars = \"ban\",vals = [1, -1, 2]) == 7\n assert candidate(s = \"hellohellohello\",chars = \"ehllo\",vals = [-100, 10, 20, 30, -5]) == 65\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"aeiou\",vals = [10, 20, 30, 40, 50]) == 900\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",chars = \"zyxwvutsrqponmlkjihgfedcba\",vals = [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]) == 351\n assert candidate(s = \"abcdxyz\",chars = \"abcd\",vals = [4, 3, 2, 1]) == 85\n assert candidate(s = \"xyzzzzzzzzzyx\",chars = \"z\",vals = [-5]) == 53\n assert candidate(s = \"aabbccddeeff\",chars = \"abcdef\",vals = [-1, -2, -3, -4, -5, -6]) == 0\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",chars = \"qwerty\",vals = [-1, -2, -3, -4, -5, -6]) == 243\n assert candidate(s = \"abcdefgabcdefg\",chars = \"aceg\",vals = [-1, -2, -3, -4]) == 9\n assert candidate(s = \"mississippi\",chars = \"sip\",vals = [1, 2, -3]) == 23\n assert candidate(s = \"mississippi\",chars = \"sip\",vals = [10, -5, 15]) == 68\n assert candidate(s = \"abcdabcdabcdabcd\",chars = \"abcd\",vals = [1, -1, 2, -2]) == 2\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [-1, 2, -3]) == 6\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"a\",vals = [26]) == 376\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",chars = \"z\",vals = [-500]) == 0\n assert candidate(s = \"qwertypoiuytrewq\",chars = \"qwertyuiop\",vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 76\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [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]) == 702\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",chars = \"z\",vals = [1000]) == 1325\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",chars = \"abcdefghijklmnopqrstuvwxyz\",vals = [-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]) == 0\n assert candidate(s = \"mnopqrstu\",chars = \"mnopqrstu\",vals = [-1, -2, -3, -4, -5, -6, -7, -8, -9]) == 0\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",chars = \"aeiou\",vals = [5, 5, 5, 5, 5]) == 401\n assert candidate(s = \"aaabbbccc\",chars = \"abc\",vals = [-1, -2, -3]) == 0\n assert candidate(s = \"abacabadabacaba\",chars = \"abc\",vals = [-1, 3, -2]) == 8\n assert candidate(s = \"baaabbbccc\",chars = \"abc\",vals = [26, 25, 24]) == 250\n", "comparison": "exact"}, "public_tests": ["\"adaa\"\n\"d\"\n[-1000]", "\"abc\"\n\"abc\"\n[-1,-1,-1]"], "hints": ["Create a new integer array where arr[i] denotes the value of character s[i].", "We can use Kadane’s maximum subarray sum algorithm to find the maximum cost."], "metadata": {"canonical_parameter_names": ["s", "chars", "vals"], "leetcode_dataset_entry_point": "Solution().maximumCostSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:55+00:00", "tests_total": 127, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "hash-table", "string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_cost_substring(s, chars, vals)", "container": null, "callable": "maximum_cost_substring", "parameters": [{"name": "s", "type": "String"}, {"name": "chars", "type": "String"}, {"name": "vals", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2607, "task_id": "make-k-subarray-sums-equal", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element.\n\nYou can do the following operation any number of times:\n\n- Pick any element from arr and increase or decrease it by 1.\n\nReturn the minimum number of operations such that the sum of each subarray of length k is equal.\n\nA subarray is a contiguous part of the array.\n\nExample 1:\n\nInput: arr = [1,4,1,3], k = 2\nOutput: 1\nExplanation: we can do one operation on index 1 to make its value equal to 3.\nThe array after the operation is [1,3,1,3]\n- Subarray starts at index 0 is [1, 3], and its sum is 4\n- Subarray starts at index 1 is [3, 1], and its sum is 4\n- Subarray starts at index 2 is [1, 3], and its sum is 4\n- Subarray starts at index 3 is [3, 1], and its sum is 4\n\nExample 2:\n\nInput: arr = [2,5,5,7], k = 3\nOutput: 5\nExplanation: we can do three operations on index 0 to make its value equal to 5 and two operations on index 3 to make its value equal to 5.\nThe array after the operations is [5,5,5,5]\n- Subarray starts at index 0 is [5, 5, 5], and its sum is 15\n- Subarray starts at index 1 is [5, 5, 5], and its sum is 15\n- Subarray starts at index 2 is [5, 5, 5], and its sum is 15\n- Subarray starts at index 3 is [5, 5, 5], and its sum is 15\n\nConstraints:\n\n- 1 <= k <= arr.length <= 10^5\n- 1 <= arr[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = [1, 2, 3, 4, 5],k = 1) == 6\n assert candidate(arr = [5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(arr = [1, 4, 1, 3],k = 2) == 1\n assert candidate(arr = [10, 20, 30, 40, 50],k = 5) == 0\n assert candidate(arr = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6],k = 2) == 8\n assert candidate(arr = [10, 20, 30, 40, 50],k = 2) == 60\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 25\n assert candidate(arr = [2, 5, 5, 7],k = 3) == 5\n assert candidate(arr = [1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 6) == 1000\n assert candidate(arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 4) == 12\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 50\n assert candidate(arr = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 2500\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 3) == 180\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 25\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 25\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 0\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 10) == 200\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10) == 1000\n assert candidate(arr = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 3) == 50\n assert candidate(arr = [2, 4, 2, 4, 2, 4, 2, 4],k = 2) == 0\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 48\n assert candidate(arr = [10, 20, 30, 10, 20, 30, 10, 20, 30],k = 3) == 0\n assert candidate(arr = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 10) == 0\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 7) == 0\n assert candidate(arr = [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],k = 8) == 156\n assert candidate(arr = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300],k = 7) == 4200\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 125\n assert candidate(arr = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10],k = 4) == 20\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 250\n assert candidate(arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 2) == 12\n assert candidate(arr = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 2) == 0\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5],k = 13) == 70\n assert candidate(arr = [3, 8, 15, 7, 5, 12],k = 3) == 10\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 0\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 2) == 18\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 4) == 96\n assert candidate(arr = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 2500\n assert candidate(arr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 3) == 187\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1) == 100\n assert candidate(arr = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],k = 5) == 2500\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 10) == 0\n assert candidate(arr = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12],k = 11) == 52\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 5) == 500\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 4) == 16\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 50\n assert candidate(arr = [4, 3, 2, 1, 5, 6, 7, 8, 9, 10],k = 4) == 24\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 25) == 0\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 7) == 50\n assert candidate(arr = [7, 3, 5, 2, 8, 6, 4, 9, 1, 10],k = 5) == 9\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == 12\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 50\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 6) == 180\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 7) == 0\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 10) == 100\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 6) == 0\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 24\n assert candidate(arr = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 2) == 240\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 100\n assert candidate(arr = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 4) == 240\n assert candidate(arr = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50],k = 3) == 120\n assert candidate(arr = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 3) == 9\n assert candidate(arr = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 8) == 36\n assert candidate(arr = [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(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 6) == 360\n assert candidate(arr = [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 = 10) == 200\n assert candidate(arr = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10],k = 3) == 70\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 48\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 6) == 36\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 0\n assert candidate(arr = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],k = 6) == 54\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 20\n assert candidate(arr = [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],k = 5) == 150\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 25\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 7) == 112\n assert candidate(arr = [9, 1, 8, 2, 7, 3, 6, 4, 5],k = 9) == 0\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 5) == 100\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 4) == 0\n assert candidate(arr = [123, 456, 789, 101, 202, 303, 404, 505, 606, 707],k = 5) == 1526\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2],k = 4) == 0\n assert candidate(arr = [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],k = 31) == 0\n assert candidate(arr = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1],k = 13) == 52\n assert candidate(arr = [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],k = 3) == 75\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 19) == 200\n assert candidate(arr = [1, 3, 5, 7, 9, 11],k = 3) == 18\n assert candidate(arr = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 4) == 2400\n assert candidate(arr = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],k = 5) == 25\n assert candidate(arr = [1, 3, 2, 4, 6, 5, 7, 8, 10, 9],k = 4) == 24\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 6) == 150\n assert candidate(arr = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 6) == 64\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6],k = 5) == 25\n assert candidate(arr = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1) == 100\n assert candidate(arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5],k = 7) == 65\n assert candidate(arr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 7) == 381\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 5) == 100\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 100\n", "comparison": "exact"}, "public_tests": ["[1,4,1,3]\n2", "[2,5,5,7]\n3"], "hints": ["Think about gcd(n, k). How will it help to calculate the answer?", "indices i and j are in the same group if gcd(n, k) mod i = gcd(n, k) mod j. Each group should have equal elements. Think about the minimum number of operations for each group", "The minimum number of operations for each group equals the summation of differences between the elements and the median of elements inside the group."], "metadata": {"canonical_parameter_names": ["arr", "k"], "leetcode_dataset_entry_point": "Solution().makeSubKSumEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:58:58+00:00", "tests_total": 102, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "math", "greedy", "sorting", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def make_sub_k_sum_equal(arr, k)", "container": null, "callable": "make_sub_k_sum_equal", "parameters": [{"name": "arr", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2608, "task_id": "shortest-cycle-in-a-graph", "difficulty": "Hard", "problem_description": "There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [u_i, v_i] denotes an edge between vertex u_i and vertex v_i. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.\n\nReturn the length of the shortest cycle in the graph. If no cycle exists, return -1.\n\nA cycle is a path that starts and ends at the same node, and each edge in the path is used only once.\n\nExample 1:\n\nInput: n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]\nOutput: 3\nExplanation: The cycle with the smallest length is : 0 -> 1 -> 2 -> 0\n\nExample 2:\n\nInput: n = 4, edges = [[0,1],[0,2]]\nOutput: -1\nExplanation: There are no cycles in this graph.\n\nConstraints:\n\n- 2 <= n <= 1000\n- 1 <= edges.length <= 1000\n- edges[i].length == 2\n- 0 <= u_i, v_i < n\n- u_i != v_i\n- There are no repeated edges.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5]]) == 4\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4]]) == 4\n assert candidate(n = 3,edges = [[0, 1], [1, 2], [2, 0]]) == 3\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [4, 5]]) == 3\n assert candidate(n = 4,edges = [[0, 1], [0, 2]]) == -1\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4]]) == 4\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0]]) == 8\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == 10\n assert candidate(n = 10,edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) == -1\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]) == 6\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 3]]) == 5\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == 5\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [3, 4], [4, 5], [5, 3]]) == 3\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == -1\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == -1\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 4], [4, 3], [3, 0], [0, 2]]) == 3\n assert candidate(n = 3,edges = [[0, 1], [1, 2]]) == -1\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 6], [6, 3]]) == 3\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3]]) == 3\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 5], [2, 7]]) == 6\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7]]) == 3\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 0], [5, 15], [10, 2]]) == 9\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 0], [0, 6], [3, 9]]) == 7\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0], [1, 3], [2, 8], [5, 10]]) == 3\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 0], [0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]]) == 4\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [1, 3], [3, 5], [5, 7]]) == 3\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [0, 3], [2, 4], [1, 5], [6, 11], [7, 9], [8, 10]]) == 3\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 5]]) == 6\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0], [1, 7], [4, 11]]) == 7\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 0], [0, 10], [2, 12], [4, 14], [6, 16], [8, 18]]) == 6\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0], [0, 7], [3, 6], [5, 10]]) == 4\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0], [7, 11]]) == 5\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5]]) == 5\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0], [4, 10]]) == 7\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [0, 9], [1, 4], [4, 7], [7, 2], [2, 5], [5, 8], [8, 3], [3, 6], [6, 0]]) == 3\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 5], [9, 5], [9, 6]]) == 3\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 6], [0, 8]]) == 6\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 0], [0, 10], [5, 15], [10, 15]]) == 6\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 3], [0, 6]]) == 7\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [1, 3]]) == 3\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [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, 15], [0, 15], [5, 20], [7, 19]]) == 5\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 0], [0, 15], [5, 20]]) == 12\n assert candidate(n = 18,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14], [14, 16]]) == 3\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5], [11, 12], [12, 13], [13, 14], [14, 11], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 15], [21, 22], [22, 23], [23, 24], [24, 21], [0, 10], [1, 20], [2, 22], [12, 19], [7, 21], [14, 24]]) == 4\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 6]]) == 4\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 5], [5, 6], [6, 7], [7, 8], [8, 5], [1, 6], [2, 7], [3, 8], [4, 5]]) == 3\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 10], [10, 11], [11, 7], [0, 7]]) == 3\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12]]) == 3\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 0], [0, 3], [3, 6], [6, 9]]) == 4\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 5], [0, 10], [3, 7]]) == 5\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5], [10, 11], [11, 12], [12, 13], [13, 10], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 14], [0, 5], [7, 12], [11, 16], [14, 2], [17, 0]]) == 4\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 18], [0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == 3\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 0], [0, 15], [5, 20], [10, 25]]) == 12\n assert candidate(n = 18,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 0], [0, 8], [4, 12], [7, 15]]) == 6\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15], [0, 9], [5, 12], [7, 17]]) == 5\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 0], [0, 6], [2, 8], [4, 10]]) == 6\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [0, 8], [1, 7], [2, 6], [3, 5], [4, 0], [5, 1], [6, 2], [7, 3], [8, 4]]) == 3\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0], [0, 7], [2, 9], [4, 11], [6, 13]]) == 5\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 0], [0, 12], [5, 18]]) == 13\n assert candidate(n = 14,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 0], [0, 7], [4, 11], [2, 8]]) == 5\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [0, 12], [5, 9]]) == 3\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [0, 4], [2, 6], [1, 5], [3, 7]]) == 4\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 0], [0, 10], [5, 15]]) == 11\n assert candidate(n = 11,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 0], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == 4\n", "comparison": "exact"}, "public_tests": ["7\n[[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]", "4\n[[0,1],[0,2]]"], "hints": ["How can BFS be used?", "For each vertex u, calculate the length of the shortest cycle that contains vertex u using BFS"], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().findShortestCycle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:00+00:00", "tests_total": 64, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["breadth-first-search", "graph"]}, "language": "ruby", "interface": {"raw_signature": "def find_shortest_cycle(n, edges)", "container": null, "callable": "find_shortest_cycle", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2609, "task_id": "find-the-longest-balanced-substring-of-a-binary-string", "difficulty": "Easy", "problem_description": "You are given a binary string s consisting only of zeroes and ones.\n\nA substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring.\n\nReturn the length of the longest balanced substring of s.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"01000111\"\nOutput: 6\nExplanation: The longest balanced substring is \"000111\", which has length 6.\n\nExample 2:\n\nInput: s = \"00111\"\nOutput: 4\nExplanation: The longest balanced substring is \"0011\", which has length 4.\n\nExample 3:\n\nInput: s = \"111\"\nOutput: 0\nExplanation: There is no balanced substring except the empty substring, so the answer is 0.\n\nConstraints:\n\n- 1 <= s.length <= 50\n- '0' <= s[i] <= '1'\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"000000111111\") == 12\n assert candidate(s = \"000111000111\") == 6\n assert candidate(s = \"000110\") == 4\n assert candidate(s = \"01\") == 2\n assert candidate(s = \"00111\") == 4\n assert candidate(s = \"0001100111\") == 4\n assert candidate(s = \"111\") == 0\n assert candidate(s = \"111111\") == 0\n assert candidate(s = \"0\") == 0\n assert candidate(s = \"111111000000\") == 0\n assert candidate(s = \"1100\") == 0\n assert candidate(s = \"00001111\") == 8\n assert candidate(s = \"000000\") == 0\n assert candidate(s = \"10\") == 0\n assert candidate(s = \"01010101\") == 2\n assert candidate(s = \"010101\") == 2\n assert candidate(s = \"1\") == 0\n assert candidate(s = \"101010\") == 2\n assert candidate(s = \"01000111\") == 6\n assert candidate(s = \"0000000001111111110000000111111\") == 18\n assert candidate(s = \"101010101010101010\") == 2\n assert candidate(s = \"0000111100000000111111110000000011111111\") == 16\n assert candidate(s = \"111111111111111111111111\") == 0\n assert candidate(s = \"111000111000111000\") == 6\n assert candidate(s = \"0001110000111100001111\") == 8\n assert candidate(s = \"000000011111110000011111\") == 14\n assert candidate(s = \"0000000000000011111111111111\") == 28\n assert candidate(s = \"0000000000111111111100000000001111111111\") == 20\n assert candidate(s = \"00111111001111110011111100111111\") == 4\n assert candidate(s = \"10101010101010101010101010101010101010101010101010\") == 2\n assert candidate(s = \"11111111110000000000000000000000\") == 0\n assert candidate(s = \"0001000100010001000100010001000100010001\") == 2\n assert candidate(s = \"110011001100110011001100\") == 4\n assert candidate(s = \"000111000111000111000111000111000111000111000111\") == 6\n assert candidate(s = \"010101010101010101010101\") == 2\n assert candidate(s = \"00000000111111110000000011111111\") == 16\n assert candidate(s = \"000000000000111111111111\") == 24\n assert candidate(s = \"00000000001111111111000111\") == 20\n assert candidate(s = \"00000000000000001111111111111111\") == 32\n assert candidate(s = \"11000111000111000111\") == 6\n assert candidate(s = \"001100110011001100110011\") == 4\n assert candidate(s = \"111111111100000000001111\") == 8\n assert candidate(s = \"0000000111110011000111\") == 10\n assert candidate(s = \"000111000111000111\") == 6\n assert candidate(s = \"101010101010101010101010\") == 2\n assert candidate(s = \"0001110111000111000111\") == 6\n assert candidate(s = \"0100010001000100010001000100010\") == 2\n assert candidate(s = \"000000000000000000001111111111111111\") == 32\n assert candidate(s = \"110000001111111111\") == 12\n assert candidate(s = \"00110011000000111111000000\") == 12\n assert candidate(s = \"1010101010\") == 2\n assert candidate(s = \"010101010101010101\") == 2\n assert candidate(s = \"110000111100000011111100000000011111\") == 12\n assert candidate(s = \"111000111000111000111000111000\") == 6\n assert candidate(s = \"000111000111000111000111\") == 6\n assert candidate(s = \"000000011111110000000111111100000001111111\") == 14\n assert candidate(s = \"01010101010101010101010101010101010101\") == 2\n assert candidate(s = \"000000111111000000111111000000111111\") == 12\n assert candidate(s = \"000111000011110000011111000000111111\") == 12\n assert candidate(s = \"111100001111000011110000\") == 8\n assert candidate(s = \"10001100110011\") == 4\n assert candidate(s = \"11000011000011000011000011000011\") == 4\n assert candidate(s = \"0000111100011100001111\") == 8\n assert candidate(s = \"111111111110000000000000000\") == 0\n assert candidate(s = \"111111111111111111110000000000000000\") == 0\n assert candidate(s = \"0011001100110011\") == 4\n assert candidate(s = \"000001110000011100000111\") == 6\n assert candidate(s = \"0000111100110011\") == 8\n assert candidate(s = \"10101010101010101010101\") == 2\n assert candidate(s = \"000000000001111111111111111\") == 22\n assert candidate(s = \"0000111100001111000011110000\") == 8\n assert candidate(s = \"0000000111111000011111\") == 12\n assert candidate(s = \"000100010001000100010001\") == 2\n assert candidate(s = \"111111111111\") == 0\n assert candidate(s = \"000011100110001110011000111\") == 6\n assert candidate(s = \"00011000110001100011000110001100011\") == 4\n assert candidate(s = \"10101010101010101010101010101010101010\") == 2\n assert candidate(s = \"00110001100011000110001100011\") == 4\n assert candidate(s = \"101010101010\") == 2\n assert candidate(s = \"00000001111111\") == 14\n assert candidate(s = \"0110110110110110110110\") == 2\n assert candidate(s = \"100000001000000010000000\") == 2\n assert candidate(s = \"000111000001111000000111110000000111111\") == 12\n assert candidate(s = \"000011000011000011000011\") == 4\n assert candidate(s = \"111000111000111000111000111000111\") == 6\n assert candidate(s = \"00010001000111111111\") == 6\n assert candidate(s = \"000000000111111111\") == 18\n assert candidate(s = \"0001110000111000111000111\") == 6\n assert candidate(s = \"11111100000000000000111111111111\") == 24\n assert candidate(s = \"1110000111100001111000\") == 8\n assert candidate(s = \"11111100000000000000\") == 0\n assert candidate(s = \"111111000000000000000000\") == 0\n assert candidate(s = \"1111110000001111000000\") == 8\n assert candidate(s = \"1010101010101010101010101010101010\") == 2\n assert candidate(s = \"00000000001111111111\") == 20\n assert candidate(s = \"00000111110000011111\") == 10\n assert candidate(s = \"00000000000111111111100000000001111111\") == 20\n assert candidate(s = \"000000000111100000001111000000001111\") == 8\n assert candidate(s = \"0000000011111111000000001111111100000000\") == 16\n assert candidate(s = \"111000111000111000111\") == 6\n assert candidate(s = \"010010001000010000001\") == 2\n assert candidate(s = \"1001001001001001\") == 2\n assert candidate(s = \"00000011111000000011111000000011111\") == 10\n assert candidate(s = \"11111111110000000000\") == 0\n assert candidate(s = \"1111000000111111\") == 12\n assert candidate(s = \"01010101010101010101010101010101\") == 2\n assert candidate(s = \"11001100110011001100\") == 4\n assert candidate(s = \"0101010101010101010101010101010101010101\") == 2\n assert candidate(s = \"1111111100000000111111110000000011111111\") == 16\n assert candidate(s = \"1111000001111000001111000001111000001111\") == 8\n assert candidate(s = \"0000000111111100000001111111\") == 14\n assert candidate(s = \"011111110111111101111111\") == 2\n assert candidate(s = \"1100110011001100110011001100\") == 4\n assert candidate(s = \"010101010101\") == 2\n assert candidate(s = \"111110000001111100000111110000011111\") == 10\n assert candidate(s = \"11000110001100011000110001100011\") == 4\n assert candidate(s = \"0101010101010101\") == 2\n assert candidate(s = \"00000011111111\") == 12\n assert candidate(s = \"000000000000000000000000\") == 0\n assert candidate(s = \"000111000111000111000111000111\") == 6\n assert candidate(s = \"00010001000100010001\") == 2\n assert candidate(s = \"1100001111000011111\") == 8\n assert candidate(s = \"000011000011000011000011000011\") == 4\n assert candidate(s = \"000011110000111100001111\") == 8\n assert candidate(s = \"10000000001111111111\") == 18\n assert candidate(s = \"0101010101\") == 2\n assert candidate(s = \"00001111000011110000111100001111\") == 8\n assert candidate(s = \"000110001100011\") == 4\n assert candidate(s = \"111111000000111111000000111111000000\") == 12\n assert candidate(s = \"00110011001100110011\") == 4\n assert candidate(s = \"00001111000111\") == 8\n assert candidate(s = \"0000001111100111\") == 10\n assert candidate(s = \"0110011001100110011\") == 4\n assert candidate(s = \"0000000011111111\") == 16\n assert candidate(s = \"1001001001001001001001001\") == 2\n assert candidate(s = \"111111111111111111111110000000000000000000000000\") == 0\n assert candidate(s = \"0101010101010101010101010101010101010101010101\") == 2\n assert candidate(s = \"0000000011111100000111110000011111\") == 12\n assert candidate(s = \"000000000000000000000001111111111111111111111111\") == 46\n assert candidate(s = \"1010101010101010101010101010101010101010101010\") == 2\n assert candidate(s = \"001001001001001001001001001001001001001\") == 2\n assert candidate(s = \"00000111100001110011\") == 8\n assert candidate(s = \"1001001001001\") == 2\n assert candidate(s = \"010010010010010010010010010010010010010\") == 2\n assert candidate(s = \"001010110011000111\") == 6\n assert candidate(s = \"111000111000111000111000111000111000111000111\") == 6\n assert candidate(s = \"0110011001100110\") == 4\n assert candidate(s = \"00000000000000111111111111111111\") == 28\n assert candidate(s = \"00011100001111\") == 8\n assert candidate(s = \"01010101010101010101010101010101010101010101\") == 2\n assert candidate(s = \"001001001001\") == 2\n assert candidate(s = \"0011001100110011001100110011\") == 4\n assert candidate(s = \"01010101010101010101\") == 2\n assert candidate(s = \"11001100110011\") == 4\n assert candidate(s = \"1001001001001001001001001001\") == 2\n assert candidate(s = \"000111010001110011\") == 6\n assert candidate(s = \"0000011111111100000000111111000000\") == 12\n assert candidate(s = \"000001111100000111110000011111\") == 10\n assert candidate(s = \"000000000011111111111111\") == 20\n assert candidate(s = \"1110000000111000000111\") == 6\n assert candidate(s = \"11111111111111110000000000000000\") == 0\n assert candidate(s = \"10101010101010101010\") == 2\n assert candidate(s = \"000110000111000001111\") == 8\n assert candidate(s = \"10101010101010\") == 2\n assert candidate(s = \"111111000000000000111111111\") == 18\n assert candidate(s = \"111000111000111000111000\") == 6\n assert candidate(s = \"11001100110011001100110011\") == 4\n assert candidate(s = \"000000011111000000011111000000011111\") == 10\n assert candidate(s = \"0000000000011111111111\") == 22\n assert candidate(s = \"010010001000010000000100000000001\") == 2\n assert candidate(s = \"00111000111000111000111000111\") == 6\n assert candidate(s = \"001100110011\") == 4\n assert candidate(s = \"0000111100001111\") == 8\n", "comparison": "exact"}, "public_tests": ["\"01000111\"", "\"00111\"", "\"111\""], "hints": ["Consider iterating over each subarray and checking if it’s balanced or not.", "Among all balanced subarrays, the answer is the longest one of them."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().findTheLongestBalancedSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:02+00:00", "tests_total": 185, "tests_dropped": 12, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def find_the_longest_balanced_substring(s)", "container": null, "callable": "find_the_longest_balanced_substring", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2610, "task_id": "convert-an-array-into-a-2d-array-with-conditions", "difficulty": "Medium", "problem_description": "You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:\n\n- The 2D array should contain only the elements of the array nums.\n- Each row in the 2D array contains distinct integers.\n- The number of rows in the 2D array should be minimal.\n\nReturn the resulting array. If there are multiple answers, return any of them.\n\nNote that the 2D array can have a different number of elements on each row.\n\nExample 1:\n\nInput: nums = [1,3,4,1,2,3,1]\nOutput: [[1,3,4,2],[1,3],[1]]\nExplanation: We can create a 2D array that contains the following rows:\n- 1,3,4,2\n- 1,3\n- 1\nAll elements of nums were used, and each row of the 2D array contains distinct integers, so it is a valid answer.\nIt can be shown that we cannot have less than 3 rows in a valid array.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: [[4,3,2,1]]\nExplanation: All elements of the array are distinct, so we can keep all of them in the first row of the 2D array.\n\nConstraints:\n\n- 1 <= nums.length <= 200\n- 1 <= nums[i] <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [[1, 2, 3, 4], [2, 3, 4], [3, 4], [4]]\n assert candidate(nums = [1, 2, 3, 4]) == [[1, 2, 3, 4]]\n assert candidate(nums = [10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == [[10, 1, 2, 9, 3, 8, 4, 7, 5, 6]]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == [[1, 2, 3, 4], [1, 2, 3, 4]]\n assert candidate(nums = [1, 1, 1, 1]) == [[1], [1], [1], [1]]\n assert candidate(nums = [1, 2, 1, 3, 4, 2, 3]) == [[1, 2, 3, 4], [1, 2, 3]]\n assert candidate(nums = [5, 3, 3, 2, 1, 2, 4, 5]) == [[5, 3, 2, 1, 4], [5, 3, 2]]\n assert candidate(nums = [5, 5, 5, 5, 5]) == [[5], [5], [5], [5], [5]]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [[7], [7], [7], [7], [7], [7], [7], [7], [7], [7]]\n assert candidate(nums = [1, 3, 4, 1, 2, 3, 1]) == [[1, 3, 4, 2], [1, 3], [1]]\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]) == [[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]]\n assert candidate(nums = [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]) == [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]\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]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]\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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5]) == [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5]]\n assert candidate(nums = [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, 5, 4, 3, 2, 1]) == [[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]]\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]) == [[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]]\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]]\n assert candidate(nums = [200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 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]) == [[200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 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]]\n assert candidate(nums = [3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [[3, 2, 1, 4, 5], [3, 2, 1, 4, 5], [3, 2, 1, 4, 5], [3, 2, 1, 5], [3, 5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5]]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [[7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7], [7]]\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]]\n assert candidate(nums = [1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5], [1, 2, 3, 4], [1, 2, 3], [1, 2], [1]]\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]]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]\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, 6]) == [[1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6], [3, 4, 5, 6], [4, 5, 6], [5, 6], [6], [6]]\n assert candidate(nums = [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, 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, 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]) == [[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], [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], [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]]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [[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], [1, 2, 3, 4, 5]]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18]) == [[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [20, 19, 18]]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == [[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 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]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]\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]]\n assert candidate(nums = [5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9]) == [[5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [5, 6, 7, 8, 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]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6]) == [[5, 6], [5, 6], [5, 6], [5, 6], [5, 6], [5, 6]]\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]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]\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]) == [[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]]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3], [1, 2, 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]) == [[1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 1, 3, 3, 2, 2, 1, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == [[3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1]]\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]) == [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5], [1, 2, 3, 4], [1, 2, 3], [1, 2], [1]]\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, 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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11]) == [[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [15, 14, 13, 12, 11]]\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, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1]) == [[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5], [1, 2, 3, 4], [1, 2, 3], [1, 2], [1]]\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]) == [[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]]\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]) == [[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]]\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]]\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]) == [[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]]\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [[3, 2, 1], [3, 2, 1], [3, 2, 1], [2, 1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]\n assert candidate(nums = [1, 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, 6, 6, 6, 6, 6, 6, 6, 6]) == [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6], [3, 4, 5, 6], [4, 5, 6], [5, 6], [5, 6], [6], [6], [6], [6], [6], [6], [6], [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, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]) == [[1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 4, 5, 6, 7, 8], [3, 4, 5, 6, 7, 8], [4, 5, 6, 7, 8], [5, 6, 7, 8], [6, 7, 8], [7, 8], [8]]\n assert candidate(nums = [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]]\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]) == [[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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]\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]) == [[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]]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [[5], [5], [5], [5], [5], [5], [5], [5], [5], [5]]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [[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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 2, 2, 2, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6]) == [[3, 1, 2, 4, 5, 6], [3, 1, 2, 4, 5, 6], [3, 1, 2, 4, 5, 6], [3, 2, 5], [3, 2, 5], [3, 2, 5]]\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, 1, 2, 3, 4, 5]) == [[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], [1, 2, 3, 4, 5]]\n assert candidate(nums = [1, 2, 2, 1, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9, 10, 9, 10, 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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\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]) == [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [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]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]]\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 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, 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]) == [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 4, 5], [1, 4, 5], [4, 5], [4, 5], [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], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5], [5]]\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]]\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, 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], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]\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]]\n assert candidate(nums = [15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == [[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]\n", "comparison": "exact"}, "public_tests": ["[1,3,4,1,2,3,1]", "[2,1,1]"], "hints": ["Process the elements in the array one by one in any order and only create a new row in the matrix when we cannot put it into the existing rows", "We can simply iterate over the existing rows of the matrix to see if we can place each element."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:04+00:00", "tests_total": 79, "tests_dropped": 10, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def find_matrix(nums)", "container": null, "callable": "find_matrix", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2611, "task_id": "mice-and-cheese", "difficulty": "Medium", "problem_description": "There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.\n\nA point of the cheese with index i (0-indexed) is:\n\n- reward1[i] if the first mouse eats it.\n- reward2[i] if the second mouse eats it.\n\nYou are given a positive integer array reward1, a positive integer array reward2, and a non-negative integer k.\n\nReturn the maximum points the mice can achieve if the first mouse eats exactly k types of cheese.\n\nExample 1:\n\nInput: reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2\nOutput: 15\nExplanation: In this example, the first mouse eats the 2^nd (0-indexed) and the 3^rd types of cheese, and the second mouse eats the 0^th and the 1^st types of cheese.\nThe total points are 4 + 4 + 3 + 4 = 15.\nIt can be proven that 15 is the maximum total points that the mice can achieve.\n\nExample 2:\n\nInput: reward1 = [1,1], reward2 = [1,1], k = 2\nOutput: 2\nExplanation: In this example, the first mouse eats the 0^th (0-indexed) and 1^st types of cheese, and the second mouse does not eat any cheese.\nThe total points are 1 + 1 = 2.\nIt can be proven that 2 is the maximum total points that the mice can achieve.\n\nConstraints:\n\n- 1 <= n == reward1.length == reward2.length <= 10^5\n- 1 <= reward1[i], reward2[i] <= 1000\n- 0 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(reward1 = [10, 20, 30, 40],reward2 = [40, 30, 20, 10],k = 3) == 130\n assert candidate(reward1 = [5, 4, 3, 2, 1],reward2 = [1, 2, 3, 4, 5],k = 3) == 21\n assert candidate(reward1 = [10, 20, 30],reward2 = [40, 50, 60],k = 0) == 150\n assert candidate(reward1 = [1, 2, 3, 4, 5],reward2 = [5, 4, 3, 2, 1],k = 3) == 21\n assert candidate(reward1 = [5, 4, 3],reward2 = [1, 2, 3],k = 1) == 10\n assert candidate(reward1 = [7, 8, 9],reward2 = [10, 11, 12],k = 3) == 24\n assert candidate(reward1 = [100, 100, 100],reward2 = [1, 1, 1],k = 0) == 3\n assert candidate(reward1 = [10, 20, 30],reward2 = [30, 20, 10],k = 2) == 80\n assert candidate(reward1 = [7, 8, 9],reward2 = [1, 2, 3],k = 3) == 24\n assert candidate(reward1 = [1, 1, 3, 4],reward2 = [4, 4, 1, 1],k = 2) == 15\n assert candidate(reward1 = [5, 4, 3],reward2 = [1, 1, 1],k = 1) == 7\n assert candidate(reward1 = [1, 2, 3, 4, 5],reward2 = [5, 4, 3, 2, 1],k = 5) == 15\n assert candidate(reward1 = [100, 200, 300, 400],reward2 = [400, 300, 200, 100],k = 2) == 1400\n assert candidate(reward1 = [10, 20, 30],reward2 = [3, 6, 9],k = 0) == 18\n assert candidate(reward1 = [10, 20, 30],reward2 = [30, 20, 10],k = 0) == 60\n assert candidate(reward1 = [1, 1],reward2 = [1, 1],k = 2) == 2\n assert candidate(reward1 = [1, 3, 5, 7, 9],reward2 = [2, 4, 6, 8, 10],k = 2) == 28\n assert candidate(reward1 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],reward2 = [21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2],k = 10) == 330\n assert candidate(reward1 = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],reward2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 10\n assert candidate(reward1 = [1, 3, 5, 7, 9, 11, 13, 15],reward2 = [2, 4, 6, 8, 10, 12, 14, 16],k = 4) == 68\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],reward2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 0) == 550\n assert candidate(reward1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 55\n assert candidate(reward1 = [100, 200, 300, 400, 500, 600],reward2 = [10, 20, 30, 40, 50, 60],k = 2) == 1200\n assert candidate(reward1 = [100, 200, 300, 400, 500],reward2 = [10, 20, 30, 40, 50],k = 2) == 960\n assert candidate(reward1 = [50, 40, 30, 20, 10],reward2 = [10, 20, 30, 40, 50],k = 0) == 150\n assert candidate(reward1 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 4040\n assert candidate(reward1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],reward2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 176\n assert candidate(reward1 = [100, 200, 300, 400, 500],reward2 = [5, 10, 15, 20, 25],k = 2) == 930\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1],reward2 = [999, 999, 999, 999, 999, 999],k = 3) == 3000\n assert candidate(reward1 = [5, 5, 5, 5, 5],reward2 = [1, 2, 3, 4, 5],k = 5) == 25\n assert candidate(reward1 = [999, 1, 1, 1, 1, 1],reward2 = [1, 999, 1, 1, 1, 1],k = 1) == 2002\n assert candidate(reward1 = [500, 500, 500, 500, 500],reward2 = [500, 500, 500, 500, 500],k = 2) == 2500\n assert candidate(reward1 = [1, 2, 3, 4, 5],reward2 = [200, 200, 200, 200, 200],k = 3) == 412\n assert candidate(reward1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],reward2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 0) == 55\n assert candidate(reward1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],reward2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 0) == 110\n assert candidate(reward1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],reward2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 55\n assert candidate(reward1 = [100, 200, 300, 400, 500],reward2 = [90, 190, 290, 390, 490],k = 2) == 1470\n assert candidate(reward1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],reward2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 800\n assert candidate(reward1 = [500, 400, 300, 200, 100],reward2 = [100, 200, 300, 400, 500],k = 0) == 1500\n assert candidate(reward1 = [500, 400, 300, 200, 100],reward2 = [50, 100, 150, 200, 250],k = 4) == 1650\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],reward2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 405\n assert candidate(reward1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],reward2 = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 5) == 42\n assert candidate(reward1 = [100, 200, 300, 400, 500],reward2 = [500, 400, 300, 200, 100],k = 0) == 1500\n assert candidate(reward1 = [200, 200, 200, 200, 200],reward2 = [1, 2, 3, 4, 5],k = 2) == 412\n assert candidate(reward1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],reward2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 30\n assert candidate(reward1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 5500\n assert candidate(reward1 = [1000, 1000, 1000, 1000],reward2 = [1, 1, 1, 1],k = 0) == 4\n assert candidate(reward1 = [1, 3, 5, 7, 9, 11, 13, 15],reward2 = [2, 4, 6, 8, 10, 12, 14, 16],k = 4) == 68\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],reward2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(reward1 = [90, 80, 70, 60, 50],reward2 = [10, 20, 30, 40, 50],k = 2) == 290\n assert candidate(reward1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 415\n assert candidate(reward1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 550\n assert candidate(reward1 = [100, 100, 100, 100, 100],reward2 = [1, 2, 3, 4, 5],k = 3) == 309\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],reward2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 30\n assert candidate(reward1 = [1, 2, 3, 4, 5],reward2 = [5, 4, 3, 2, 1],k = 5) == 15\n assert candidate(reward1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == 65\n assert candidate(reward1 = [100, 100, 100, 100],reward2 = [50, 50, 50, 50],k = 2) == 300\n assert candidate(reward1 = [1000, 1000, 1000, 1000, 1000],reward2 = [900, 900, 900, 900, 900],k = 5) == 5000\n assert candidate(reward1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],reward2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 5) == 105\n assert candidate(reward1 = [10, 20, 30, 40, 50],reward2 = [5, 15, 25, 35, 45],k = 3) == 140\n assert candidate(reward1 = [900, 800, 700, 600, 500],reward2 = [100, 200, 300, 400, 500],k = 2) == 2900\n assert candidate(reward1 = [800, 900, 700, 600, 500],reward2 = [100, 200, 300, 400, 500],k = 1) == 2200\n assert candidate(reward1 = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 5025\n assert candidate(reward1 = [10, 20, 30, 40, 50],reward2 = [500, 400, 300, 200, 100],k = 2) == 1290\n assert candidate(reward1 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],reward2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 5500\n assert candidate(reward1 = [500, 400, 300, 200, 100],reward2 = [1000, 900, 800, 700, 600],k = 5) == 1500\n assert candidate(reward1 = [9, 18, 27, 36, 45, 54],reward2 = [6, 12, 18, 24, 30, 36],k = 2) == 159\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],reward2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 55\n assert candidate(reward1 = [100, 200, 300, 400, 500],reward2 = [500, 400, 300, 200, 100],k = 3) == 2100\n assert candidate(reward1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],reward2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 80\n assert candidate(reward1 = [5, 5, 5, 5, 5],reward2 = [100, 200, 300, 400, 500],k = 0) == 1500\n assert candidate(reward1 = [50, 40, 30, 20, 10],reward2 = [10, 20, 30, 40, 50],k = 0) == 150\n assert candidate(reward1 = [100, 100, 100],reward2 = [10, 20, 30],k = 0) == 60\n assert candidate(reward1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 55\n assert candidate(reward1 = [1000, 900, 800, 700, 600],reward2 = [10, 20, 30, 40, 50],k = 3) == 2790\n assert candidate(reward1 = [50, 30, 10, 20, 40],reward2 = [40, 20, 30, 10, 50],k = 4) == 170\n assert candidate(reward1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],reward2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 50\n assert candidate(reward1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],reward2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 176\n assert candidate(reward1 = [500, 400, 300, 200, 100],reward2 = [1, 2, 3, 4, 5],k = 5) == 1500\n assert candidate(reward1 = [1, 2, 3, 4, 5],reward2 = [500, 400, 300, 200, 100],k = 0) == 1500\n assert candidate(reward1 = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 55\n assert candidate(reward1 = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],reward2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 3043\n assert candidate(reward1 = [1000, 900, 800, 700, 600],reward2 = [500, 600, 700, 800, 900],k = 5) == 4000\n assert candidate(reward1 = [900, 800, 700, 600, 500],reward2 = [100, 200, 300, 400, 500],k = 4) == 3500\n assert candidate(reward1 = [100, 200, 300, 400, 500],reward2 = [50, 150, 250, 350, 450],k = 3) == 1400\n assert candidate(reward1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],reward2 = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],k = 3) == 7003\n assert candidate(reward1 = [10, 20, 30, 40, 50],reward2 = [5, 15, 25, 35, 45],k = 3) == 140\n assert candidate(reward1 = [100, 90, 80, 70, 60],reward2 = [10, 20, 30, 40, 50],k = 2) == 310\n assert candidate(reward1 = [10, 10, 10, 10, 10, 10],reward2 = [9, 9, 9, 9, 9, 9],k = 3) == 57\n assert candidate(reward1 = [100, 200, 300, 400, 500, 600],reward2 = [60, 50, 40, 30, 20, 10],k = 2) == 1280\n assert candidate(reward1 = [300, 200, 100],reward2 = [100, 200, 300],k = 1) == 800\n assert candidate(reward1 = [100, 200, 300, 400],reward2 = [150, 250, 350, 450],k = 1) == 1150\n assert candidate(reward1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],reward2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 272\n", "comparison": "exact"}, "public_tests": ["[1,1,3,4]\n[4,4,1,1]\n2", "[1,1]\n[1,1]\n2"], "hints": ["The intended solution uses greedy approach.", "Imagine at first that the second mouse eats all the cheese, then we should choose k types of cheese with the maximum sum of - reward2[i] + reward1[i]."], "metadata": {"canonical_parameter_names": ["reward1", "reward2", "k"], "leetcode_dataset_entry_point": "Solution().miceAndCheese", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:07+00:00", "tests_total": 96, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "greedy", "sorting", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def mice_and_cheese(reward1, reward2, k)", "container": null, "callable": "mice_and_cheese", "parameters": [{"name": "reward1", "type": "Integer[]"}, {"name": "reward2", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2614, "task_id": "prime-in-diagonal", "difficulty": "Easy", "problem_description": "You are given a 0-indexed two-dimensional integer array nums.\n\nReturn the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.\n\nNote that:\n\n- An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 and itself.\n- An integer val is on one of the diagonals of nums if there exists an integer i for which nums[i][i] = val or an i for which nums[i][nums.length - i - 1] = val.\n\nIn the above diagram, one diagonal is [1,5,9] and another diagonal is [3,5,7].\n\nExample 1:\n\nInput: nums = [[1,2,3],[5,6,7],[9,10,11]]\nOutput: 11\nExplanation: The numbers 1, 3, 6, 9, and 11 are the only numbers present on at least one of the diagonals. Since 11 is the largest prime, we return 11.\n\nExample 2:\n\nInput: nums = [[1,2,3],[5,17,7],[9,11,10]]\nOutput: 17\nExplanation: The numbers 1, 3, 9, 10, and 17 are all present on at least one of the diagonals. 17 is the largest prime, so we return 17.\n\nConstraints:\n\n- 1 <= nums.length <= 300\n- nums.length == nums_i.length\n- 1 <= nums[i][j] <= 4*10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [[4, 6, 8], [10, 12, 14], [16, 18, 20]]) == 0\n assert candidate(nums = [[3, 1, 4], [1, 5, 9], [2, 6, 5]]) == 5\n assert candidate(nums = [[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12], [13, 14, 15, 16]]) == 13\n assert candidate(nums = [[31, 33, 35], [37, 39, 41], [43, 45, 47]]) == 47\n assert candidate(nums = [[31, 12, 43], [55, 67, 79], [81, 97, 101]]) == 101\n assert candidate(nums = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 0\n assert candidate(nums = [[2, 3, 5], [3, 5, 7], [5, 7, 11]]) == 11\n assert candidate(nums = [[1, 2, 3], [5, 6, 7], [9, 10, 11]]) == 11\n assert candidate(nums = [[1, 2, 3], [5, 17, 7], [9, 11, 10]]) == 17\n assert candidate(nums = [[2, 3, 5], [7, 11, 13], [17, 19, 23]]) == 23\n assert candidate(nums = [[2, 4, 6, 8, 10], [11, 13, 15, 17, 19], [20, 22, 23, 25, 27], [28, 30, 31, 32, 34], [35, 36, 37, 38, 39]]) == 23\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 13, 17, 19, 23, 29, 31, 37, 41, 43], [47, 53, 59, 61, 67, 71, 73, 79, 83, 89], [97, 101, 103, 107, 109, 113, 127, 131, 137, 139], [149, 151, 157, 163, 167, 173, 179, 181, 191, 193], [197, 199, 211, 223, 227, 229, 233, 239, 241, 251], [257, 263, 269, 271, 277, 281, 283, 293, 307, 311], [313, 317, 331, 337, 347, 349, 353, 359, 367, 373], [379, 383, 389, 397, 401, 409, 419, 421, 431, 433], [439, 443, 449, 457, 461, 463, 467, 479, 487, 491]]) == 491\n assert candidate(nums = [[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]]) == 0\n assert candidate(nums = [[4, 6, 8, 10, 12, 14], [16, 18, 20, 22, 24, 26], [28, 30, 31, 32, 34, 36], [38, 40, 41, 42, 44, 46], [48, 50, 51, 52, 54, 56], [58, 60, 61, 62, 64, 66]]) == 41\n assert candidate(nums = [[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]]) == 97\n assert candidate(nums = [[1009, 1010, 1011, 1012], [1013, 1014, 1015, 1016], [1017, 1018, 1019, 1020], [1021, 1022, 1023, 1024]]) == 1021\n assert candidate(nums = [[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]]) == 29\n assert candidate(nums = [[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]]) == 29\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2], [3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3], [4, 5, 6, 7, 8, 9, 10]]) == 7\n assert candidate(nums = [[79, 83, 89, 97, 101], [83, 89, 97, 101, 103], [89, 97, 101, 103, 107], [97, 101, 103, 107, 109], [101, 103, 107, 109, 113]]) == 113\n assert candidate(nums = [[2, 1, 1, 1, 2], [1, 2, 1, 2, 1], [1, 1, 2, 1, 1], [1, 2, 1, 2, 1], [2, 1, 1, 1, 2]]) == 2\n assert candidate(nums = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 13, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 17, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 19, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 23, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 29, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 41, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 43]]) == 43\n assert candidate(nums = [[3, 7, 11, 13, 17, 19], [7, 11, 13, 17, 19, 23], [11, 13, 17, 19, 23, 29], [13, 17, 19, 23, 29, 31], [17, 19, 23, 29, 31, 37], [19, 23, 29, 31, 37, 41]]) == 41\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, 47, 46, 45, 48, 49, 50], [51, 52, 53, 54, 55, 59, 57, 58, 59, 60], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 101]]) == 101\n assert candidate(nums = [[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31], [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 37], [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81], [82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92], [93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], [104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114], [115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125], [126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 137]]) == 137\n assert candidate(nums = [[4, 6, 8, 10, 12, 14], [16, 18, 20, 22, 24, 26], [28, 30, 31, 32, 34, 36], [38, 40, 42, 43, 44, 46], [48, 50, 52, 54, 56, 58], [60, 62, 64, 66, 68, 70]]) == 43\n assert candidate(nums = [[2, 1, 1, 1, 1, 1, 3], [1, 2, 1, 1, 1, 3, 1], [1, 1, 2, 1, 3, 1, 1], [1, 1, 1, 2, 1, 1, 1], [1, 1, 3, 1, 2, 1, 1], [1, 3, 1, 1, 1, 2, 1], [3, 1, 1, 1, 1, 1, 2]]) == 3\n assert candidate(nums = [[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]]) == 97\n assert candidate(nums = [[101, 102, 103, 104, 105, 106, 107, 108, 109], [110, 111, 112, 113, 114, 115, 116, 117, 118], [119, 121, 127, 131, 137, 139, 149, 151, 157], [163, 167, 173, 179, 181, 191, 193, 197, 199], [211, 223, 227, 229, 233, 239, 241, 251, 257], [263, 269, 271, 277, 281, 283, 293, 307, 311], [313, 317, 331, 337, 347, 349, 353, 359, 367], [373, 379, 383, 389, 397, 401, 409, 419, 421], [431, 433, 439, 443, 449, 457, 461, 463, 467]]) == 467\n assert candidate(nums = [[73, 79, 83, 89, 97], [101, 103, 107, 109, 113], [127, 131, 137, 139, 149], [151, 157, 163, 167, 173], [179, 181, 191, 193, 197]]) == 197\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], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 101]]) == 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, 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, 61, 62, 63, 64]]) == 43\n assert candidate(nums = [[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31], [37, 39, 41, 43, 47, 51, 53, 57, 59, 61, 67], [71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113], [127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179], [181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239], [241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307], [311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373], [379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439], [443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503], [509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587], [593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647]]) == 647\n assert candidate(nums = [[1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 3, 1], [1, 1, 1, 1, 5, 1, 1], [1, 1, 1, 7, 1, 1, 1], [1, 1, 11, 1, 1, 1, 1], [1, 13, 1, 1, 1, 1, 1]]) == 0\n assert candidate(nums = [[331, 337, 347, 349, 353], [359, 367, 373, 379, 383], [389, 397, 401, 409, 419], [421, 431, 433, 439, 443], [449, 457, 461, 463, 467]]) == 467\n assert candidate(nums = [[1000003, 1000009, 1000019, 1000021], [1000031, 1000033, 1000037, 1000039], [1000043, 1000049, 1000051, 1000061], [1000063, 1000067, 1000069, 1000073]]) == 1000037\n assert candidate(nums = [[1, 4, 9, 16, 25], [4, 9, 16, 25, 36], [9, 16, 25, 36, 49], [16, 25, 36, 49, 64], [25, 36, 49, 64, 81]]) == 0\n assert candidate(nums = [[13, 21, 34, 55, 89, 144, 233], [1, 2, 3, 5, 8, 13, 21], [2, 3, 5, 8, 13, 21, 34], [3, 5, 8, 13, 21, 34, 55], [5, 8, 13, 21, 34, 55, 89], [8, 13, 21, 34, 55, 89, 144], [13, 21, 34, 55, 89, 144, 233]]) == 233\n assert candidate(nums = [[2, 18, 22, 26, 30], [19, 23, 29, 33, 37], [24, 28, 31, 35, 39], [27, 32, 36, 38, 42], [34, 36, 40, 44, 47]]) == 47\n assert candidate(nums = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 2, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 2\n assert candidate(nums = [[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, 101, 103, 107, 109, 113], [127, 131, 137, 139, 149, 151]]) == 151\n assert candidate(nums = [[961, 962, 963, 964, 965], [966, 967, 968, 969, 970], [971, 972, 973, 974, 975], [976, 977, 978, 979, 980], [981, 982, 983, 984, 985]]) == 977\n assert candidate(nums = [[4, 2, 6, 8, 10, 12, 14], [3, 5, 7, 9, 11, 13, 15], [6, 7, 11, 13, 17, 19, 23], [8, 9, 13, 17, 19, 23, 29], [10, 11, 17, 19, 23, 29, 31], [12, 13, 19, 23, 29, 31, 37], [14, 15, 23, 29, 31, 37, 41]]) == 41\n assert candidate(nums = [[4, 6, 8, 10, 12], [3, 5, 7, 9, 11], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [2, 3, 5, 7, 11]]) == 11\n assert candidate(nums = [[4, 6, 8, 10], [12, 14, 16, 18], [20, 22, 24, 26], [28, 30, 32, 34]]) == 0\n assert candidate(nums = [[2, 4, 6, 8, 10], [3, 5, 7, 11, 13], [17, 19, 23, 29, 31], [37, 41, 43, 47, 53], [59, 61, 67, 71, 73]]) == 73\n assert candidate(nums = [[2, 4, 6, 8, 10], [12, 14, 16, 18, 20], [22, 24, 29, 26, 28], [30, 32, 34, 36, 38], [40, 42, 44, 46, 48]]) == 29\n assert candidate(nums = [[4, 6, 8, 10, 12, 14], [6, 9, 12, 15, 18, 21], [8, 12, 15, 18, 21, 24], [10, 15, 18, 22, 25, 28], [12, 18, 21, 25, 29, 32], [14, 21, 24, 28, 32, 35]]) == 29\n assert candidate(nums = [[1000003, 1000007, 1000009], [1000013, 1000019, 1000021], [1000027, 1000031, 1000033]]) == 1000033\n assert candidate(nums = [[1000001, 1000003, 1000007, 1000009, 1000021], [1000033, 1000037, 1000039, 1000043, 1000049], [1000051, 1000061, 1000063, 1000067, 1000069], [1000073, 1000079, 1000081, 1000087, 1000093], [1000099, 1000103, 1000111, 1000123, 1000139]]) == 1000099\n assert candidate(nums = [[14, 16, 18, 20, 22], [13, 15, 17, 19, 21], [12, 14, 16, 18, 20], [11, 13, 15, 17, 19], [10, 12, 14, 16, 17]]) == 19\n assert candidate(nums = [[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]]) == 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], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36, 37, 38, 39, 40], [41, 42, 43, 44, 47, 46, 49, 50, 51, 52], [53, 54, 55, 56, 57, 59, 61, 62, 63, 64], [65, 66, 67, 68, 69, 70, 71, 72, 73, 74], [75, 76, 77, 78, 79, 80, 81, 82, 83, 84], [85, 86, 87, 88, 89, 90, 91, 92, 93, 94], [95, 96, 97, 98, 99, 100, 101, 102, 103, 104]]) == 71\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]]) == 43\n assert candidate(nums = [[9973, 9972, 9971, 9970, 9969, 9968, 9967], [9966, 9965, 9964, 9963, 9962, 9961, 9960], [9959, 9958, 9957, 9956, 9955, 9954, 9953], [9952, 9951, 9950, 9949, 9948, 9947, 9946], [9945, 9944, 9943, 9942, 9941, 9940, 9939], [9938, 9937, 9936, 9935, 9934, 9933, 9932], [9931, 9930, 9929, 9928, 9927, 9926, 9925]]) == 9973\n assert candidate(nums = [[29, 23, 19, 17, 13], [11, 7, 5, 3, 2], [41, 37, 31, 29, 23], [47, 53, 59, 61, 67], [71, 73, 79, 83, 89]]) == 89\n assert candidate(nums = [[991, 997, 1009, 1013], [1019, 1021, 1031, 1033], [1039, 1049, 1051, 1061], [1063, 1069, 1087, 1091]]) == 1091\n assert candidate(nums = [[233, 239, 241, 251], [257, 263, 269, 271], [277, 281, 283, 293], [307, 311, 313, 317]]) == 317\n assert candidate(nums = [[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, 101, 103, 107, 109, 113], [127, 131, 137, 139, 149, 151, 157, 163, 167, 173], [179, 181, 191, 193, 197, 199, 211, 223, 227, 229], [233, 239, 241, 251, 257, 263, 269, 271, 277, 281], [283, 293, 307, 311, 313, 317, 331, 337, 347, 349], [353, 359, 367, 373, 379, 383, 389, 397, 401, 409], [419, 421, 431, 433, 439, 443, 449, 457, 461, 463], [467, 479, 487, 491, 499, 503, 509, 521, 523, 541]]) == 541\n assert candidate(nums = [[101, 103, 107, 109, 113], [127, 131, 137, 139, 149], [151, 157, 163, 167, 173], [179, 181, 191, 193, 197], [199, 211, 223, 227, 229]]) == 229\n assert candidate(nums = [[983, 1019, 1031, 1049, 1061, 1069], [1087, 1091, 1093, 1097, 1103, 1109], [1117, 1123, 1129, 1151, 1153, 1163], [1171, 1181, 1187, 1193, 1201, 1213], [1217, 1223, 1229, 1231, 1237, 1249], [1259, 1277, 1279, 1283, 1289, 1291]]) == 1291\n assert candidate(nums = [[29, 31, 37, 41, 43], [47, 53, 59, 61, 67], [71, 73, 79, 83, 89], [97, 101, 103, 107, 109], [113, 127, 131, 137, 139]]) == 139\n assert candidate(nums = [[101, 103, 105, 107, 109], [111, 113, 115, 117, 119], [121, 123, 127, 129, 131], [133, 135, 137, 139, 141], [143, 145, 147, 149, 151]]) == 151\n assert candidate(nums = [[101, 103, 107, 109, 113, 127], [131, 137, 139, 149, 151, 157], [163, 167, 173, 179, 181, 191], [193, 197, 199, 211, 223, 227], [229, 233, 239, 241, 251, 257], [263, 269, 271, 277, 281, 283]]) == 283\n assert candidate(nums = [[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, 101, 103, 107], [109, 113, 127, 131, 137, 139, 149], [151, 157, 163, 167, 173, 179, 181], [191, 193, 197, 199, 211, 223, 227]]) == 227\n assert candidate(nums = [[29, 23, 19, 17], [13, 11, 7, 5], [3, 2, 2, 3], [5, 7, 11, 13]]) == 29\n assert candidate(nums = [[101, 103, 107, 109, 113], [119, 121, 127, 131, 137], [139, 149, 151, 157, 163], [167, 173, 179, 181, 191], [193, 197, 199, 211, 223]]) == 223\n assert candidate(nums = [[1, 1, 1, 1, 1], [1, 2, 3, 5, 1], [1, 3, 5, 7, 1], [1, 5, 7, 11, 1], [1, 1, 1, 1, 1]]) == 11\n assert candidate(nums = [[29, 31, 37, 41, 43, 47, 53, 59], [61, 67, 71, 73, 79, 83, 89, 97], [101, 103, 107, 109, 113, 127, 131, 137], [139, 149, 151, 157, 163, 167, 173, 179], [181, 191, 193, 197, 199, 211, 223, 227], [229, 233, 239, 241, 251, 257, 263, 269], [271, 277, 281, 283, 293, 307, 311, 313], [317, 331, 337, 347, 349, 353, 359, 367]]) == 367\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[5,6,7],[9,10,11]]", "[[1,2,3],[5,17,7],[9,11,10]]"], "hints": ["Iterate over the diagonals of the matrix and check for each element.", "Check if the element is prime or not in O(sqrt(n)) time."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().diagonalPrime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:11+00:00", "tests_total": 73, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "math", "matrix", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def diagonal_prime(nums)", "container": null, "callable": "diagonal_prime", "parameters": [{"name": "nums", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2615, "task_id": "sum-of-distances", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums.\n\nThere exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.\n\nReturn the array arr.\n\nExample 1:\n\nInput: nums = [1,3,1,1,2]\nOutput: [5,0,3,4,0]\nExplanation:\nWhen i = 0, nums[0] == nums[2] and nums[0] == nums[3]. Therefore, arr[0] = |0 - 2| + |0 - 3| = 5.\nWhen i = 1, arr[1] = 0 because there is no other index with value 3.\nWhen i = 2, nums[2] == nums[0] and nums[2] == nums[3]. Therefore, arr[2] = |2 - 0| + |2 - 3| = 3.\nWhen i = 3, nums[3] == nums[0] and nums[3] == nums[2]. Therefore, arr[3] = |3 - 0| + |3 - 2| = 4.\nWhen i = 4, arr[4] = 0 because there is no other index with value 2.\n\nExample 2:\n\nInput: nums = [0,5,3]\nOutput: [0,0,0]\nExplanation: Since each element in nums is distinct, arr[i] = 0 for all i.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^9\n\nNote: This question is the same as 2121: Intervals Between Identical Elements.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 5, 3]) == [0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [1]) == [0]\n assert candidate(nums = [10, 10, 10, 10]) == [6, 4, 4, 6]\n assert candidate(nums = [5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10]) == [12, 0, 8, 0, 8, 0, 12]\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [1, 1, 1, 1, 1]) == [10, 7, 6, 7, 10]\n assert candidate(nums = [10, 20, 10, 10, 30, 20, 10]) == [11, 4, 7, 7, 0, 4, 13]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == [9, 0, 0, 0, 0, 0, 0, 0, 0, 9]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [1, 3, 1, 1, 2]) == [5, 0, 3, 4, 0]\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1]) == [14, 10, 6, 8, 10, 2, 0, 2, 6, 14, 16]\n assert candidate(nums = [2, 1, 3, 1, 2, 3, 3]) == [4, 2, 7, 2, 4, 4, 5]\n assert candidate(nums = [2, 2, 2, 2]) == [6, 4, 4, 6]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [27, 27, 27, 27, 27, 27, 27, 27, 27, 18, 18, 18, 18, 18, 18, 18, 18, 18, 27, 27, 27, 27, 27, 27, 27, 27, 27]\n assert candidate(nums = [50, 50, 40, 40, 40, 30, 30, 30, 30, 20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 10]) == [1, 1, 3, 2, 3, 6, 4, 4, 6, 10, 7, 6, 7, 10, 15, 11, 9, 9, 11, 15]\n assert candidate(nums = [5, 3, 2, 5, 3, 5, 2, 5, 3]) == [15, 10, 4, 9, 7, 9, 4, 13, 11]\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10, 90, 10, 100, 10, 110]) == [90, 0, 74, 0, 62, 0, 54, 0, 50, 0, 50, 0, 54, 0, 62, 0, 74, 0, 90, 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]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45, 45, 37, 31, 27, 25, 25, 27, 31, 37, 45, 45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1000000000, 999999999, 1000000000, 999999999, 1000000000, 999999999]) == [6, 6, 4, 4, 6, 6]\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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15]\n assert candidate(nums = [1000000000, 500000000, 1000000000, 250000000, 1000000000, 750000000, 1000000000]) == [12, 0, 8, 0, 8, 0, 12]\n assert candidate(nums = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 50, 50, 50, 50, 50]) == [10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\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]) == [406, 379, 354, 331, 310, 291, 274, 259, 246, 235, 226, 219, 214, 211, 210, 211, 214, 219, 226, 235, 246, 259, 274, 291, 310, 331, 354, 379, 406]\n assert candidate(nums = [10, 20, 10, 30, 40, 10, 50, 60, 10, 70, 80, 10, 90, 100, 10, 110, 120, 10, 130, 140]) == [57, 0, 47, 0, 0, 38, 0, 0, 35, 0, 0, 38, 0, 0, 47, 0, 0, 62, 0, 0]\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]) == [10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [10, 14, 9, 13, 8, 12, 7, 11, 6, 10, 10, 9, 8, 7, 6, 14, 13, 12, 11, 10]\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]) == [3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3]\n assert candidate(nums = [100, 200, 100, 300, 200, 100, 400, 300, 200, 100, 500, 400, 300, 200, 100]) == [30, 22, 24, 13, 16, 21, 5, 9, 16, 25, 0, 5, 14, 26, 40]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1]) == [210, 0, 184, 0, 162, 0, 144, 0, 130, 0, 120, 0, 114, 0, 112, 0, 114, 0, 120, 0, 130, 0, 144, 0, 162, 0, 184, 0, 210]\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]) == [3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [190, 172, 156, 142, 130, 120, 112, 106, 102, 100, 100, 102, 106, 112, 120, 130, 142, 156, 172, 190]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == [21, 15, 9, 11, 13, 6, 11, 13, 9, 17, 19]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2]) == [27, 27, 9, 9, 9, 9, 9, 9, 9, 18, 18, 9, 9, 9, 9, 9, 9, 9, 27, 27]\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]) == [135, 135, 135, 111, 111, 111, 93, 93, 93, 81, 81, 81, 75, 75, 75, 75, 75, 75, 81, 81, 81, 93, 93, 93, 111, 111, 111, 135, 135, 135]\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\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, 1, 2, 3, 4, 5]) == [60, 60, 60, 60, 60, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 20, 20, 20, 20, 20, 40, 40, 40, 40, 40, 30, 30, 30, 30, 30, 60, 60, 60, 60, 60]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [55, 46, 39, 34, 31, 30, 31, 34, 39, 46, 55]\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]) == [75, 75, 75, 75, 75, 55, 55, 55, 55, 55, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 55, 55, 55, 55, 55, 75, 75, 75, 75, 75]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == [10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50]) == [30, 30, 30, 30, 30, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 30, 30, 30, 30, 30]\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10, 90, 10]) == [72, 0, 58, 0, 48, 0, 42, 0, 40, 0, 42, 0, 48, 0, 58, 0, 72]\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]) == [0, 1, 1, 3, 2, 3, 6, 4, 4, 6, 10, 7, 6, 7, 10, 15, 11, 9, 9, 11, 15]\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]) == [435, 407, 381, 357, 335, 315, 297, 281, 267, 255, 245, 237, 231, 227, 225, 225, 227, 231, 237, 245, 255, 267, 281, 297, 315, 335, 357, 381, 407, 435]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2]) == [42, 40, 42, 40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 40, 42, 40, 42]\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]) == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 1000000000, 999999999, 999999998, 1000000000]) == [11, 4, 4, 0, 7, 4, 4, 10]\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, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [210, 192, 194, 168, 171, 176, 140, 144, 151, 160, 110, 115, 124, 136, 150, 80, 86, 97, 112, 130, 150, 52, 59, 72, 90, 112, 137, 164, 28, 36, 51, 72, 98, 128, 161, 196, 10, 19, 36, 60, 90, 125, 164, 206, 250, 0, 10, 29, 56, 90, 130, 175, 224, 276, 330]\n assert candidate(nums = [1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 0]) == [20, 20, 14, 14, 12, 12, 14, 14, 20, 20]\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1]) == [90, 0, 74, 0, 62, 0, 54, 0, 50, 0, 50, 0, 54, 0, 62, 0, 74, 0, 90]\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, 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]\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]) == [3, 2, 3, 6, 4, 4, 6, 10, 7, 6, 7, 10, 15, 11, 9, 9, 11, 15, 21, 16, 13, 12, 13, 16, 21]\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, 1, 1, 1, 2, 2, 2]) == [96, 92, 90, 96, 92, 90, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 90, 92, 96, 90, 92, 96]\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300, 100, 200, 300]) == [18, 18, 18, 12, 12, 12, 12, 12, 12, 18, 18, 18]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [100, 200, 100, 300, 100, 400, 100, 500, 100]) == [20, 0, 14, 0, 12, 0, 14, 0, 20]\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]) == [30, 30, 30, 30, 30, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 30, 30, 30, 30, 30]\n assert candidate(nums = [100, 200, 100, 300, 100, 400, 100, 500, 100, 600, 100, 700, 100, 800, 100]) == [56, 0, 44, 0, 36, 0, 32, 0, 32, 0, 36, 0, 44, 0, 56]\n assert candidate(nums = [100, 200, 100, 300, 400, 100, 200, 300, 400, 100]) == [16, 5, 12, 4, 4, 12, 5, 4, 4, 20]\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60]\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10, 90, 10]) == [72, 0, 58, 0, 48, 0, 42, 0, 40, 0, 42, 0, 48, 0, 58, 0, 72]\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == [15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15]\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]) == [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\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]) == [3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3]\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [3, 2, 3, 1, 1, 3, 2, 3, 6, 4, 4, 6]\n assert candidate(nums = [1000000000, 999999999, 1000000000, 999999998, 1000000000, 999999997, 1000000000, 999999996, 1000000000, 999999995]) == [20, 0, 14, 0, 12, 0, 14, 0, 20, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 10]) == [2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2]\n assert candidate(nums = [5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == [10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 10, 10, 7, 6, 7, 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]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\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]) == [78, 72, 66, 60, 27, 52, 50, 48, 46, 44, 42, 40, 38, 18, 38, 40, 42, 44, 46, 48, 50, 52, 27, 60, 66, 72, 78]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 10]) == [20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20]\n assert candidate(nums = [1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == [100, 91, 72, 77, 58, 67, 48, 61, 42, 59, 40, 61, 42, 67, 48, 77, 58, 91, 72, 109]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == [9, 0, 0, 0, 0, 0, 0, 0, 0, 9]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [0, 1, 1, 3, 2, 3, 6, 4, 4, 6]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [63, 59, 63, 59, 63, 59, 63, 59, 63, 59, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 59, 63, 59, 63, 59, 63, 59, 63, 59, 63]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\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, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1]) == [112, 98, 100, 80, 83, 88, 60, 64, 71, 80, 40, 45, 54, 66, 80, 22, 28, 39, 54, 72, 92, 8, 15, 28, 46, 68, 93, 120, 0, 8, 23, 44, 70, 100, 133, 168]\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1000000000]) == [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [190, 172, 156, 142, 130, 120, 112, 106, 102, 100, 100, 102, 106, 112, 120, 130, 142, 156, 172, 190]\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]) == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [7, 3, 7, 7, 10, 3, 7, 3, 7, 7, 7, 10, 3, 7, 3, 7, 7, 7, 10, 3]) == [99, 52, 81, 74, 21, 36, 59, 32, 53, 52, 53, 14, 32, 62, 36, 72, 79, 88, 21, 56]\n", "comparison": "exact"}, "public_tests": ["[1,3,1,1,2]", "[0,5,3]"], "hints": ["Can we use the prefix sum here?", "For each number x, collect all the indices where x occurs, and calculate the prefix sum of the array.", "For each occurrence of x, the indices to the right will be regular subtraction while the indices to the left will be reversed subtraction."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().distance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:14+00:00", "tests_total": 105, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def distance(nums)", "container": null, "callable": "distance", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2616, "task_id": "minimize-the-maximum-difference-of-pairs", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.\n\nNote that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.\n\nReturn the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.\n\nExample 1:\n\nInput: nums = [10,1,2,7,1,3], p = 2\nOutput: 1\nExplanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5.\nThe maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.\n\nExample 2:\n\nInput: nums = [4,2,1,2], p = 1\nOutput: 0\nExplanation: Let the indices 1 and 3 form a pair. The difference of that pair is |2 - 2| = 0, which is the minimum we can attain.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^9\n- 0 <= p <= (nums.length)/2\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 8, 10],p = 2) == 2\n assert candidate(nums = [5, 3, 8, 4, 9, 1],p = 3) == 2\n assert candidate(nums = [5, 5, 5, 5, 5],p = 2) == 0\n assert candidate(nums = [7, 1, 3, 4, 2, 5],p = 0) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1],p = 2) == 0\n assert candidate(nums = [5, 4, 2, 2, 1, 3, 3, 5],p = 3) == 0\n assert candidate(nums = [1, 3, 5, 7, 9],p = 2) == 2\n assert candidate(nums = [1, 3, 6, 9, 12, 15],p = 2) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],p = 4) == 0\n assert candidate(nums = [1, 3, 6, 19, 20],p = 2) == 2\n assert candidate(nums = [8, 4, 2, 6, 10, 12],p = 3) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],p = 3) == 1\n assert candidate(nums = [10, 1, 2, 7, 1, 3],p = 2) == 1\n assert candidate(nums = [4, 2, 1, 2],p = 1) == 0\n assert candidate(nums = [5, 3, 2, 4, 1],p = 2) == 1\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10, 12, 13, 15, 14, 16, 17, 19, 18, 20],p = 10) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],p = 5) == 10\n assert candidate(nums = [5, 1, 9, 3, 7, 6, 8, 2, 4, 10],p = 5) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],p = 9) == 0\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],p = 25) == 2\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],p = 15) == 5\n assert candidate(nums = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27],p = 4) == 3\n assert candidate(nums = [2, 3, 1, 5, 4, 6, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19],p = 5) == 1\n assert candidate(nums = [5, 8, 12, 15, 19, 22, 26, 30, 35, 40, 45, 50, 55, 60, 65, 70],p = 7) == 5\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],p = 12) == 0\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],p = 10) == 0\n assert candidate(nums = [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],p = 10) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 14, 15, 16, 17, 18, 19, 20],p = 8) == 1\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],p = 10) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],p = 5) == 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],p = 5) == 0\n assert candidate(nums = [1000000000, 0, 500000000, 250000000, 750000000, 125000000, 625000000, 312500000, 875000000, 937500000],p = 4) == 125000000\n assert candidate(nums = [1, 3, 6, 19, 20, 25, 30, 32, 40, 50],p = 4) == 8\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],p = 10) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],p = 5) == 1\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57],p = 5) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],p = 5) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],p = 4) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],p = 5) == 256\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],p = 2) == 900\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],p = 8) == 10\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],p = 15) == 1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119],p = 10) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],p = 10) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],p = 10) == 10\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],p = 7) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],p = 9) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],p = 2) == 1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119],p = 9) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],p = 10) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],p = 10) == 1\n assert candidate(nums = [9, 1, 10, 15, 2, 11, 16, 3, 12, 17, 4, 13, 18, 5, 14, 19, 6, 20, 7, 8],p = 7) == 1\n assert candidate(nums = [1, 100, 101, 102, 103, 104, 105, 106, 107, 108],p = 3) == 1\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91],p = 5) == 1\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],p = 12) == 2\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],p = 5) == 0\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],p = 5) == 1\n assert candidate(nums = [1, 2, 3, 100, 101, 102, 200, 201, 202, 300],p = 4) == 97\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],p = 5) == 0\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019],p = 10) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],p = 5) == 1\n assert candidate(nums = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70],p = 15) == 1\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51],p = 10) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],p = 8) == 0\n assert candidate(nums = [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],p = 12) == 1\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],p = 15) == 1\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],p = 5) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],p = 5) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],p = 5) == 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],p = 5) == 0\n assert candidate(nums = [100, 101, 102, 103, 104, 200, 201, 202, 203, 204],p = 4) == 1\n assert candidate(nums = [1, 5, 3, 7, 2, 6, 4, 8, 9, 13, 11, 15, 10, 14, 12, 16, 17, 21, 19, 23],p = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],p = 5) == 1\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],p = 8) == 0\n assert candidate(nums = [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, 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, 2, 2, 2],p = 10) == 0\n assert candidate(nums = [8, 1, 4, 3, 2, 7, 5, 6, 9, 10],p = 4) == 1\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],p = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],p = 5) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],p = 5) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],p = 9) == 10\n assert candidate(nums = [4, 8, 2, 15, 16, 23, 42, 10],p = 3) == 2\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115],p = 7) == 1\n assert candidate(nums = [100, 200, 300, 10, 20, 30, 150, 250, 50, 350],p = 4) == 50\n assert candidate(nums = [1, 3, 6, 8, 12, 14, 17, 20, 23, 26, 29, 31, 34, 37, 40, 42],p = 5) == 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],p = 10) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],p = 5) == 0\n assert candidate(nums = [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],p = 12) == 0\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, 10],p = 15) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],p = 0) == 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, 21, 22, 23, 24, 25],p = 10) == 1\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],p = 10) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],p = 7) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],p = 7) == 2\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],p = 8) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],p = 6) == 2\n assert candidate(nums = [1000000000, 0, 500000000, 250000000, 750000000],p = 2) == 250000000\n assert candidate(nums = [100, 3, 5, 15, 1, 200, 8, 2, 7, 6],p = 4) == 7\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],p = 3) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],p = 5) == 0\n assert candidate(nums = [1, 3, 6, 19, 20, 22, 30, 31, 33, 40, 41, 43, 50],p = 4) == 2\n", "comparison": "exact"}, "public_tests": ["[10,1,2,7,1,3]\n2", "[4,2,1,2]\n1"], "hints": ["To minimize the answer, the array should be sorted first.", "Can we use binary search here?"], "metadata": {"canonical_parameter_names": ["nums", "p"], "leetcode_dataset_entry_point": "Solution().minimizeMax", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:16+00:00", "tests_total": 106, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimize_max(nums, p)", "container": null, "callable": "minimize_max", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "p", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2617, "task_id": "minimum-number-of-visited-cells-in-a-grid", "difficulty": "Hard", "problem_description": "You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0).\n\nStarting from the cell (i, j), you can move to one of the following cells:\n\n- Cells (i, k) with j < k <= grid[i][j] + j (rightward movement), or\n- Cells (k, j) with i < k <= grid[i][j] + i (downward movement).\n\nReturn the minimum number of cells you need to visit to reach the bottom-right cell (m - 1, n - 1). If there is no valid path, return -1.\n\nExample 1:\n\nInput: grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]\nOutput: 4\nExplanation: The image above shows one of the paths that visits exactly 4 cells.\n\nExample 2:\n\nInput: grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]\nOutput: 3\nExplanation: The image above shows one of the paths that visits exactly 3 cells.\n\nExample 3:\n\nInput: grid = [[2,1,0],[1,0,0]]\nOutput: -1\nExplanation: It can be proven that no path exists.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 10^5\n- 1 <= m * n <= 10^5\n- 0 <= grid[i][j] < m * n\n- grid[m - 1][n - 1] == 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[2, 0, 0], [1, 3, 1], [0, 1, 0]]) == 5\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 4, 2, 1], [4, 2, 3, 1], [2, 1, 0, 0], [2, 4, 0, 0]]) == 4\n assert candidate(grid = [[3, 4, 2, 1], [4, 2, 1, 1], [2, 1, 1, 0], [3, 4, 1, 0]]) == 3\n assert candidate(grid = [[0, 0], [0, 0]]) == -1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 0]]) == 5\n assert candidate(grid = [[2, 1, 0], [1, 0, 0]]) == -1\n assert candidate(grid = [[0]]) == 1\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == -1\n assert candidate(grid = [[1, 0], [0, 0]]) == -1\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 0], [3, 4, 5, 0, 0], [4, 5, 0, 0, 0], [5, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[3, 2, 1, 4, 0], [4, 1, 2, 3, 1], [2, 3, 0, 1, 0], [3, 0, 2, 0, 1], [0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[2, 0, 0], [0, 2, 0], [0, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 0]]) == -1\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 1, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 2, 2, 2, 2], [2, 1, 1, 1, 2], [2, 1, 0, 1, 2], [2, 1, 1, 1, 2], [2, 2, 2, 2, 0]]) == 5\n assert candidate(grid = [[2, 2, 1, 1], [1, 2, 2, 1], [1, 1, 2, 2], [1, 1, 1, 0]]) == 5\n assert candidate(grid = [[2, 2, 0, 0], [2, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 3], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]) == 4\n assert candidate(grid = [[3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 0]]) == 3\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[2, 3, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0]]) == -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, 0]]) == 9\n assert candidate(grid = [[0, 1, 2, 3, 4], [1, 0, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 0, 1], [4, 3, 2, 1, 0]]) == -1\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, 3, 3], [3, 3, 3, 3, 3, 0]]) == 5\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 0]]) == 4\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]]) == -1\n assert candidate(grid = [[3, 3, 0, 2, 1, 1], [2, 2, 0, 1, 1, 0], [1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) == -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], [0, 0, 0, 0, 0, 0]]) == 11\n assert candidate(grid = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 0]]) == 4\n assert candidate(grid = [[1, 2, 3, 4, 5], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [5, 4, 3, 2, 0]]) == 5\n assert candidate(grid = [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 0]]) == 5\n assert candidate(grid = [[3, 0, 0, 1], [0, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 0]]) == 5\n assert candidate(grid = [[5, 0, 0, 0, 0], [4, 0, 0, 0, 0], [3, 0, 0, 0, 0], [2, 0, 0, 0, 0], [1, 0, 0, 0, 0]]) == -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, 0]]) == 13\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], [0, 1, 0, 1, 0, 0]]) == -1\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 0]]) == 5\n assert candidate(grid = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 1, 4, 3], [3, 4, 1, 0]]) == 4\n assert candidate(grid = [[3, 2, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 0]]) == 7\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 11\n assert candidate(grid = [[2, 1, 0, 0], [0, 2, 1, 0], [1, 0, 2, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 0, 2, 1, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 0]]) == -1\n assert candidate(grid = [[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 0], [3, 0, 0, 0]]) == -1\n assert candidate(grid = [[5, 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]]) == -1\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 0]]) == 7\n assert candidate(grid = [[2, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 3, 1, 1, 4], [2, 2, 2, 2, 2], [1, 1, 2, 1, 2], [2, 2, 2, 2, 2], [0, 0, 0, 0, 0]]) == 4\n assert candidate(grid = [[2, 3, 0, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[4, 3, 2, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 1, 0, 2, 0], [0, 1, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 0], [2, 3, 4, 5, 0, 5], [3, 4, 5, 0, 5, 4], [4, 5, 0, 5, 4, 3], [5, 0, 5, 4, 3, 0]]) == -1\n assert candidate(grid = [[3, 2, 1, 0], [2, 2, 2, 2], [1, 2, 2, 2], [0, 2, 2, 0]]) == 5\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 0]]) == 7\n assert candidate(grid = [[2, 3, 1, 1, 1], [1, 2, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 0]]) == 7\n assert candidate(grid = [[5, 4, 3, 2, 1, 0], [4, 3, 2, 1, 0, 0], [3, 2, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 19\n assert candidate(grid = [[5, 3, 2, 1], [2, 2, 2, 1], [1, 1, 1, 1], [0, 0, 0, 0]]) == 5\n assert candidate(grid = [[10, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 2, 2, 1], [1, 2, 3, 4], [2, 3, 1, 1], [1, 1, 1, 0]]) == 4\n assert candidate(grid = [[3, 1, 2, 1, 1], [2, 2, 1, 1, 2], [1, 1, 2, 1, 1], [1, 2, 1, 2, 1], [0, 0, 0, 0, 0]]) == 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, 0]]) == 11\n assert candidate(grid = [[2, 0, 2, 0, 1, 0], [0, 2, 0, 2, 0, 2], [2, 0, 2, 0, 2, 0], [0, 2, 0, 2, 0, 2], [1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 2, 2], [2, 0, 2], [2, 2, 0]]) == -1\n assert candidate(grid = [[5, 4, 3, 2, 1], [4, 3, 2, 1, 0], [3, 2, 1, 0, 0], [2, 1, 0, 0, 0], [1, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0], [0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 0]]) == 3\n assert candidate(grid = [[4, 3, 2, 1, 0], [3, 3, 3, 3, 3], [2, 3, 2, 3, 2], [1, 3, 2, 3, 1], [0, 3, 2, 3, 0]]) == 5\n assert candidate(grid = [[4, 4, 4, 4, 4], [4, 4, 4, 4, 4], [4, 4, 4, 4, 4], [4, 4, 4, 4, 4], [4, 4, 4, 4, 0]]) == 3\n assert candidate(grid = [[2, 2, 2, 2], [2, 0, 0, 2], [2, 0, 0, 2], [2, 2, 2, 0]]) == 5\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[3, 1, 2, 3, 2], [1, 1, 1, 1, 1], [2, 1, 2, 1, 2], [1, 2, 1, 2, 1], [2, 1, 1, 1, 0]]) == 5\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 0]]) == 11\n assert candidate(grid = [[4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 0]]) == 3\n assert candidate(grid = [[2, 3, 3, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[2, 2, 1, 2], [2, 2, 2, 1], [1, 2, 2, 2], [2, 1, 1, 0]]) == 5\n assert candidate(grid = [[3, 2, 1, 1, 2], [2, 2, 3, 1, 1], [1, 3, 2, 1, 1], [1, 1, 1, 2, 3], [1, 1, 1, 1, 0]]) == 6\n assert candidate(grid = [[3, 2, 1, 0], [2, 3, 1, 0], [1, 1, 0, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[5, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 1, 2, 1, 2], [1, 2, 1, 2, 1], [2, 1, 2, 1, 2], [1, 2, 1, 2, 1], [0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 3, 4, 5, 6], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 4\n assert candidate(grid = [[2, 0, 3, 0, 0], [1, 0, 0, 0, 4], [0, 0, 0, 0, 0], [3, 0, 0, 0, 2], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[4, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[2, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 3, 3], [3, 0, 0], [3, 0, 0]]) == 3\n assert candidate(grid = [[5, 5, 5, 5, 5], [5, 0, 0, 0, 0], [5, 0, 0, 0, 0], [5, 0, 0, 0, 0], [5, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[3, 2, 1, 4, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[3, 2, 1, 0, 0], [2, 2, 0, 1, 0], [0, 1, 0, 2, 3], [1, 0, 0, 0, 4], [0, 0, 0, 0, 0]]) == 7\n assert candidate(grid = [[1, 1, 1], [1, 0, 0], [1, 0, 0]]) == -1\n assert candidate(grid = [[4, 2, 0, 0, 0], [2, 2, 2, 0, 0], [0, 2, 2, 2, 0], [0, 0, 2, 2, 2], [0, 0, 0, 2, 0]]) == 6\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]]) == -1\n assert candidate(grid = [[2, 1, 2], [1, 2, 1], [2, 1, 0]]) == 3\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]]) == -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, 0]]) == 9\n", "comparison": "exact"}, "public_tests": ["[[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]", "[[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]", "[[2,1,0],[1,0,0]]"], "hints": ["For each cell (i,j), it is critical to find out the minimum number of steps to reach (i,j), denoted dis[i][j], quickly, given the tight constraint.", "Calculate dis[i][j] going left to right, top to bottom.", "Suppose we want to calculate dis[i][j], keep track of a priority queue that stores (dis[i][k], i, k) for all k ≤ j, and another priority queue that stores (dis[k][j], k, j) for all k ≤ i."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumVisitedCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:19+00:00", "tests_total": 103, "tests_dropped": 7, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "stack", "breadth-first-search", "union-find", "heap-priority-queue", "matrix", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_visited_cells(grid)", "container": null, "callable": "minimum_visited_cells", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2639, "task_id": "find-the-width-of-columns-of-a-grid", "difficulty": "Easy", "problem_description": "You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.\n\n- For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.\n\nReturn an integer array ans of size n where ans[i] is the width of the i^th column.\n\nThe length of an integer x with len digits is equal to len if x is non-negative, and len + 1 otherwise.\n\nExample 1:\n\nInput: grid = [[1],[22],[333]]\nOutput: [3]\nExplanation: In the 0^th column, 333 is of length 3.\n\nExample 2:\n\nInput: grid = [[-15,1,3],[15,7,12],[5,6,-2]]\nOutput: [3,1,2]\nExplanation:\nIn the 0^th column, only -15 is of length 3.\nIn the 1^st column, all integers are of length 1.\nIn the 2^nd column, both 12 and -2 are of length 2.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 100\n- -10^9 <= grid[r][c] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[12345], [67890]]) == [5]\n assert candidate(grid = [[1], [22], [333]]) == [3]\n assert candidate(grid = [[1000], [-1000], [100], [-100], [10], [-10], [1], [-1]]) == [5]\n assert candidate(grid = [[-15, 1, 3], [15, 7, 12], [5, 6, -2]]) == [3, 1, 2]\n assert candidate(grid = [[123456789, -123456789], [987654321, 123456789]]) == [9, 10]\n assert candidate(grid = [[-1, -2, -3], [10, 20, 30], [100, 200, 300]]) == [3, 3, 3]\n assert candidate(grid = [[-1, -2, -3, -4], [-5, -6, -7, -8], [-9, -10, -11, -12]]) == [2, 3, 3, 3]\n assert candidate(grid = [[-1000000000, 1000000000], [999999999, -999999999]]) == [11, 10]\n assert candidate(grid = [[123, 456, 789], [987, 654, 321], [111, 222, 333]]) == [3, 3, 3]\n assert candidate(grid = [[123, 456, 789], [987, 654, 321], [111, 222, 333]]) == [3, 3, 3]\n assert candidate(grid = [[123456789, 123456789, 123456789], [1, 2, 3], [987654321, 987654321, 987654321]]) == [9, 9, 9]\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == [1, 1, 1]\n assert candidate(grid = [[-1, -22, -333], [-4444, -55555, -666666], [-7777777, -88888888, -999999999]]) == [8, 9, 10]\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == [1, 1, 1]\n assert candidate(grid = [[-1000000000, 1000000000], [999999999, -999999999]]) == [11, 10]\n assert candidate(grid = [[0, 0, 0], [0, 0, 0]]) == [1, 1, 1]\n assert candidate(grid = [[123, 4567, 89], [12, 34, 5678], [9, 876, 5432], [101112, 131415, 161718], [192021, 222324, 252627]]) == [6, 6, 6]\n assert candidate(grid = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == [2]\n assert candidate(grid = [[123456789, -987654321, 123], [111, 222, 333], [0, 0, 0]]) == [9, 10, 3]\n assert candidate(grid = [[-123456789, 987654321, -111], [222, 333, 444], [555, 666, 777]]) == [10, 9, 4]\n assert candidate(grid = [[1, -1], [2, -2], [3, -3], [4, -4], [5, -5], [6, -6], [7, -7], [8, -8], [9, -9], [10, -10]]) == [2, 3]\n assert candidate(grid = [[-1000000000, 1000000000, -999999999, 999999999], [999999998, -999999998, 999999997, -999999997]]) == [11, 10, 10, 10]\n assert candidate(grid = [[-1, 2, -3, 4, -5], [-10, 20, -30, 40, -50], [-100, 200, -300, 400, -500], [-1000, 2000, -3000, 4000, -5000]]) == [5, 4, 5, 4, 5]\n assert candidate(grid = [[10000, 1000, 100, 10, 1], [1, 10, 100, 1000, 10000], [1, -2, 3, -4, 5], [-6, 7, -8, 9, -10]]) == [5, 4, 3, 4, 5]\n assert candidate(grid = [[-123456789, 987654321, -111111111], [222222222, -333333333, 444444444], [555555555, -666666666, 777777777]]) == [10, 10, 10]\n assert candidate(grid = [[1, -2, 3, -4, 5], [6, -7, 8, -9, 10], [11, -12, 13, -14, 15], [16, -17, 18, -19, 20]]) == [2, 3, 2, 3, 2]\n assert candidate(grid = [[-1, 0, 1], [-10, 0, 10], [-100, 0, 100], [-1000, 0, 1000], [-10000, 0, 10000]]) == [6, 1, 5]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [-10, -9, -8, -7, -6]]) == [3, 2, 2, 2, 2]\n assert candidate(grid = [[0, -1000000000, 1000000000], [123456789, -987654321, 111111111], [987654321, 123456789, 0]]) == [9, 11, 10]\n assert candidate(grid = [[12345, 67890], [-12345, 67890], [12345, -67890], [-12345, -67890], [0, 0]]) == [6, 6]\n assert candidate(grid = [[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]]) == [1, 2, 1, 2, 1]\n assert candidate(grid = [[123, 456, 789], [-987, -654, -321], [111, 222, 333], [-444, -555, -666]]) == [4, 4, 4]\n assert candidate(grid = [[1000000000], [100000000], [10000000], [1000000], [100000], [10000], [1000], [100], [10], [1]]) == [10]\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]]) == [1, 1, 1, 1, 1]\n assert candidate(grid = [[12, -123, 1234, -12345, 123456], [654, -789, 101112, -13141516, 17181920], [21, -22, 23, -24, 25]]) == [3, 4, 6, 9, 8]\n assert candidate(grid = [[1, 10, 100, 1000], [2, 20, 200, 2000], [3, 30, 300, 3000], [4, 40, 400, 4000], [5, 50, 500, 5000]]) == [1, 2, 3, 4]\n assert candidate(grid = [[1, -10, 100, -1000, 10000, -100000, 1000000, -10000000, 100000000, -1000000000]]) == [1, 3, 3, 5, 5, 7, 7, 9, 9, 11]\n assert candidate(grid = [[12, 34, 56], [78, 90, 12], [34, 56, 78], [90, 12, 34], [56, 78, 90]]) == [2, 2, 2]\n assert candidate(grid = [[-9, 8, -7, 6, -5], [4, -3, 2, -1, 0], [1, -2, 3, -4, 5], [6, -7, 8, -9, 10], [-11, 12, -13, 14, -15]]) == [3, 2, 3, 2, 3]\n assert candidate(grid = [[-123456789, 987654321, 123456789], [111111111, -222222222, 333333333], [444444444, 555555555, 666666666]]) == [10, 10, 9]\n assert candidate(grid = [[987654321, -123456789, 0, 98765432, -12345678, 9876543, -1234567, 987654, -123456, 98765], [-98765, 12345, -6789, 6789, -5432, 5432, -4321, 4321, -3210, 3210], [987, -654, 321, -987, 654, -321, 789, -456, 123, -1]]) == [9, 10, 5, 8, 9, 7, 8, 6, 7, 5]\n assert candidate(grid = [[-1, 0, 1, -10, 10], [100, -100, 1000, -1000, 10000], [100000, -100000, 1000000, -1000000, 10000000]]) == [6, 7, 7, 8, 8]\n assert candidate(grid = [[1, 22, 333, 4444, 55555], [98765, 4321, 987, 6543, 21], [11, 222, 3333, 44444, 555555]]) == [5, 4, 4, 5, 6]\n assert candidate(grid = [[1000000000, 999999999, 888888888, 777777777, 666666666], [555555555, 444444444, 333333333, 222222222, 111111111]]) == [10, 9, 9, 9, 9]\n assert candidate(grid = [[12345, 6789, -101112], [-131415, 161718, 192021], [222324, -252627, 282930], [313233, 343536, -373839]]) == [7, 7, 7]\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]]) == [1, 1, 1, 1, 1]\n assert candidate(grid = [[-987654321, 987654321], [123456789, -123456789], [1, 2], [-1, -2], [10, -10], [100, -100]]) == [10, 10]\n assert candidate(grid = [[-1, -10, -100, -1000, -10000], [2, 20, 200, 2000, 20000], [3, 30, 300, 3000, 30000]]) == [2, 3, 4, 5, 6]\n assert candidate(grid = [[123, 456, -789], [987, 654, 321], [-111, 222, -333], [100, -200, 300]]) == [4, 4, 4]\n assert candidate(grid = [[111, -222, 333], [444, -555, 666], [-777, 888, -999], [1000, -1000, 1000], [-10000, 10000, -10000]]) == [6, 5, 6]\n assert candidate(grid = [[-123, 456, -789], [100000, 200000, 300000], [1, -2, 3], [-4, 5, -6], [7, -8, 9]]) == [6, 6, 6]\n assert candidate(grid = [[-123456789, 234567890, -345678901], [456789012, -567890123, 678901234], [789012345, -890123456, 901234567]]) == [10, 10, 10]\n assert candidate(grid = [[123, 456, 789, 101112, -131415], [161718, 192021, 222324, -252627, 282930], [-313233, 343536, 373839, 404142, 434445]]) == [7, 6, 6, 7, 7]\n assert candidate(grid = [[-123, 456, -789], [1011, -1213, 1415], [-1617, 1819, -2021], [2223, -2425, 2627], [-2829, 3031, -3233]]) == [5, 5, 5]\n assert candidate(grid = [[123456789, 123456789, 123456789], [987654321, 987654321, 987654321], [111111111, 111111111, 111111111]]) == [9, 9, 9]\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, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 1]\n assert candidate(grid = [[-99999999, 99999999, 9999999], [99999998, -99999998, 9999998], [99999997, 99999997, -9999997], [-99999996, 99999996, 9999996], [99999995, -99999995, 9999995], [99999994, 99999994, -9999994], [-99999993, 99999993, 9999993], [99999992, -99999992, 9999992], [99999991, 99999991, -9999991], [99999990, -99999990, 9999990]]) == [9, 9, 8]\n assert candidate(grid = [[-1000000000], [1000000000], [123456789], [-987654321], [111111111], [-222222222]]) == [11]\n assert candidate(grid = [[-1, 2, -3, 4, -5], [5, -4, 3, -2, 1], [-10, 20, -30, 40, -50], [50, -40, 30, -20, 10]]) == [3, 3, 3, 3, 3]\n assert candidate(grid = [[-1, 2, -3, 4, -5], [5, -4, 3, -2, 1], [11, -22, 33, -44, 55], [-55, 44, -33, 22, -11]]) == [3, 3, 3, 3, 3]\n assert candidate(grid = [[123456789, -987654321, 100000000], [111111111, 222222222, -333333333], [999999999, 888888888, 777777777]]) == [9, 10, 10]\n assert candidate(grid = [[9, 88, 777, 6666], [55555, 4444, 333, 22], [1, -10, -100, -1000]]) == [5, 4, 4, 5]\n assert candidate(grid = [[-1, -22, -333, -4444, -55555], [55555, 4444, 333, 22, -1], [-55555, -4444, -333, -22, -1]]) == [6, 5, 4, 5, 6]\n assert candidate(grid = [[123456789, -987654321], [987654321, 123456789], [-111111111, 222222222], [333333333, -444444444]]) == [10, 10]\n assert candidate(grid = [[0, 1000000000, -1000000000], [100000000, -10000000, 1000000], [10000000, -1000000, 100000], [1000000, -100000, 10000], [100000, -10000, 1000], [10000, -1000, 100], [1000, -100, 10], [100, -10, 1], [10, -1, 0]]) == [9, 10, 11]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 3]\n assert candidate(grid = [[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]]) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(grid = [[-123456789, 0, 123456789], [1000000000, -1000000000, 0], [123456789, 0, -123456789]]) == [10, 11, 10]\n assert candidate(grid = [[0, 0, 0, 0, 0], [-1, -2, -3, -4, -5], [999999999, 888888888, 777777777, 666666666, 555555555]]) == [9, 9, 9, 9, 9]\n assert candidate(grid = [[-987654321, 123456789, 111111111], [98765432, -12345678, 222222222], [9876543, 1234567, -333333333]]) == [10, 9, 10]\n assert candidate(grid = [[-1000000000], [-100000000], [-10000000], [-1000000], [-100000], [-10000], [-1000], [-100], [-10], [-1]]) == [11]\n assert candidate(grid = [[1000000000], [-999999999], [123456789], [-123456789], [987654321], [-987654321]]) == [10]\n assert candidate(grid = [[-999999999, 1000000000, 123456789], [987654321, -876543210, 123], [1, 22, 333]]) == [10, 10, 9]\n assert candidate(grid = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15]]) == [2]\n assert candidate(grid = [[-1, 2, -3, 4, -5], [10, -20, 30, -40, 50], [100, -200, 300, -400, 500], [-1000, 2000, -3000, 4000, -5000]]) == [5, 4, 5, 4, 5]\n assert candidate(grid = [[-1, -20, -300, -4000, -50000], [-600000, 70000, -8000, 900, -100], [1, 2, 3, 4, 5], [-6, -7, -8, -9, -10]]) == [7, 5, 5, 5, 6]\n assert candidate(grid = [[987654321, 987654321, 987654321], [-123456789, -123456789, -123456789], [0, 0, 0], [1, -1, 2], [2, -2, 3], [3, -3, 4]]) == [10, 10, 10]\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]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(grid = [[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]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1]\n assert candidate(grid = [[12345, -67890, 11122], [-33344, 55566, -77788], [99900, -12131, 44455], [66677, -88899, 0]]) == [6, 6, 6]\n assert candidate(grid = [[1], [-22], [333], [-4444], [55555], [-666666], [7777777], [-88888888], [999999999], [-1000000000]]) == [11]\n assert candidate(grid = [[-999999999, -888888888, -777777777], [666666666, 555555555, 444444444], [333333333, 222222222, 111111111]]) == [10, 10, 10]\n assert candidate(grid = [[-9, -99, -999, -9999], [8, 88, 888, 8888], [7, 77, 777, 7777], [6, 66, 666, 6666]]) == [2, 3, 4, 5]\n assert candidate(grid = [[1000000000], [-1000000000], [999999999], [-999999999], [1], [-1]]) == [11]\n assert candidate(grid = [[1111, 2222, 3333], [-1111, -2222, -3333], [999, 888, 777], [-999, -888, -777], [1234, -1234, 2345]]) == [5, 5, 5]\n assert candidate(grid = [[0, 0, 0, 0], [-1, 0, 1, 0], [0, -1, 0, 1], [10, -10, 100, -100], [-123, 0, 123, 0], [0, 123, 0, -123]]) == [4, 3, 3, 4]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 3]\n assert candidate(grid = [[-1, 100000000, 0], [123456789, -98765432, 999999999], [0, 1, -1000000]]) == [9, 9, 9]\n assert candidate(grid = [[0, 123456789, -987654321], [987654321, 0, 123456789], [-123456789, -987654321, 0]]) == [10, 10, 10]\n", "comparison": "exact"}, "public_tests": ["[[1],[22],[333]]", "[[-15,1,3],[15,7,12],[5,6,-2]]"], "hints": ["You can find the length of a number by dividing it by 10 and then rounding it down again and again until this number becomes equal to 0. Add 1 if this number is negative.", "Traverse the matrix column-wise to find the maximum length in each column."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().findColumnWidth", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:23+00:00", "tests_total": 96, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def find_column_width(grid)", "container": null, "callable": "find_column_width", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2640, "task_id": "find-the-score-of-all-prefixes-of-an-array", "difficulty": "Medium", "problem_description": "We define the conversion array conver of an array arr as follows:\n\n- conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.\n\nWe also define the score of an array arr as the sum of the values of the conversion array of arr.\n\nGiven a 0-indexed integer array nums of length n, return an array ans of length n where ans[i] is the score of the prefix nums[0..i].\n\nExample 1:\n\nInput: nums = [2,3,7,5,10]\nOutput: [4,10,24,36,56]\nExplanation:\nFor the prefix [2], the conversion array is [4] hence the score is 4\nFor the prefix [2, 3], the conversion array is [4, 6] hence the score is 10\nFor the prefix [2, 3, 7], the conversion array is [4, 6, 14] hence the score is 24\nFor the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12] hence the score is 36\nFor the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20] hence the score is 56\n\nExample 2:\n\nInput: nums = [1,1,2,4,8,16]\nOutput: [2,4,8,16,32,64]\nExplanation:\nFor the prefix [1], the conversion array is [2] hence the score is 2\nFor the prefix [1, 1], the conversion array is [2, 2] hence the score is 4\nFor the prefix [1, 1, 2], the conversion array is [2, 2, 4] hence the score is 8\nFor the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8] hence the score is 16\nFor the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16] hence the score is 32\nFor the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32] hence the score is 64\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == [10, 19, 27, 34, 40]\n assert candidate(nums = [1]) == [2]\n assert candidate(nums = [1000000000]) == [2000000000]\n assert candidate(nums = [1, 1, 2, 4, 8, 16]) == [2, 4, 8, 16, 32, 64]\n assert candidate(nums = [2, 3, 7, 5, 10]) == [4, 10, 24, 36, 56]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046]\n assert candidate(nums = [5, 5, 5, 5, 5]) == [10, 20, 30, 40, 50]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [20, 39, 57, 74, 90, 105, 119, 132, 144, 155]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [2, 6, 12, 20, 30]\n assert candidate(nums = [10, 9, 8, 7, 6]) == [20, 39, 57, 74, 90]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 6, 12, 20, 30, 42, 56, 72, 90, 110]\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]) == [2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600, 650, 702, 756, 812, 870, 930, 992, 1056, 1122, 1190, 1260, 1332, 1406, 1482, 1560, 1640, 1722, 1806, 1892, 1980, 2070, 2162, 2256, 2352, 2450, 2550]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == [2000000000, 4000000000, 6000000000, 8000000000, 10000000000]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) == [2, 22, 222, 2222, 22222, 222222, 2222222]\n assert candidate(nums = [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]) == [58, 115, 171, 226, 280, 333, 385, 436, 486, 535, 583, 630, 676, 721, 765, 808, 850, 891, 931, 970, 1008, 1045, 1081, 1116, 1150, 1183, 1215, 1246, 1276]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == [2, 8, 18, 32, 50, 72, 98, 128, 162, 200, 242, 288, 338, 392, 450, 512]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [200, 600, 1200, 2000, 3000, 4200, 5600, 7200, 9000, 11000]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046, 4094, 8190, 16382, 32766, 65534, 131070, 262142, 524286, 1048574, 2097150]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == [2000000000, 4000000000, 6000000000, 8000000000, 10000000000]\n assert candidate(nums = [31, 41, 59, 26, 53, 58, 97, 93, 23, 84, 62, 64, 33, 83, 27]) == [62, 144, 262, 347, 459, 576, 770, 960, 1080, 1261, 1420, 1581, 1711, 1891, 2015]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1]) == [18, 35, 51, 66, 80, 93, 105, 116, 126, 136, 147, 159, 172, 186, 201, 217, 234, 252, 262, 272]\n assert candidate(nums = [100, 200, 100, 300, 200, 400, 300, 500, 400, 600, 500, 700, 600, 800, 700]) == [200, 600, 900, 1500, 2000, 2800, 3500, 4500, 5400, 6600, 7700, 9100, 10400, 12000, 13500]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [2, 8, 18, 32, 50, 72, 98, 128, 162, 200, 242, 288, 338, 392, 450]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == [2, 8, 13, 23, 32, 46, 59, 77, 94, 114]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == [6, 10, 18, 23, 33, 51, 62, 77, 91, 103, 117, 135, 151, 169, 181, 192, 204, 221, 234, 249]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [2, 8, 18, 32, 50, 72, 98, 128, 162, 200, 242, 288, 338, 392, 450, 512, 578, 648, 722, 800]\n assert candidate(nums = [5, 3, 8, 1, 4, 9, 2, 7, 6, 10]) == [10, 18, 34, 43, 55, 73, 84, 100, 115, 135]\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]) == [50, 99, 147, 194, 240, 285, 329, 372, 414, 455, 495, 534, 572, 609, 645, 680, 714, 747, 779, 810, 840, 869, 897, 924, 950]\n assert candidate(nums = [999999999, 1, 999999998, 2, 999999997, 3, 999999996, 4, 999999995, 5, 999999994, 6, 999999993, 7, 999999992, 8]) == [1999999998, 2999999998, 4999999995, 5999999996, 7999999992, 8999999994, 10999999989, 11999999992, 13999999986, 14999999990, 16999999983, 17999999988, 19999999980, 20999999986, 22999999977, 23999999984]\n assert candidate(nums = [5, 1, 4, 2, 8, 6, 3, 7, 9]) == [10, 16, 25, 32, 48, 62, 73, 88, 106]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [10, 30, 60, 100, 150, 210, 280, 360, 450, 550]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [20, 40, 60, 80, 100, 120, 140, 160, 180, 200]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == [20, 60, 90, 130, 160, 200, 230, 270, 300, 340, 370, 410, 440, 480, 510, 550, 580, 620, 650, 690]\n assert candidate(nums = [5, 3, 8, 6, 2, 9, 1, 4, 7, 10]) == [10, 18, 34, 48, 58, 76, 86, 99, 115, 135]\n assert candidate(nums = [1000000000, 900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000]) == [2000000000, 3900000000, 5700000000, 7400000000, 9000000000, 10500000000, 11900000000, 13200000000, 14400000000, 15500000000]\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]) == [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, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == [2, 6, 12, 16, 21, 27, 31, 36, 42, 46]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == [6, 10, 18, 23, 33, 51, 62, 77, 91, 103, 117, 135]\n assert candidate(nums = [5, 3, 8, 1, 9, 2, 7, 6, 4, 10]) == [10, 18, 34, 43, 61, 72, 88, 103, 116, 136]\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6, 70, 7, 80, 8, 90, 9, 100, 10]) == [20, 31, 71, 93, 153, 186, 266, 310, 410, 465, 585, 651, 791, 868, 1028, 1116, 1296, 1395, 1595, 1705]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [10, 30, 60, 100, 150, 210, 280, 360, 450, 550]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [2, 4, 8, 12, 18, 24, 32, 40, 50, 60, 72, 84, 98, 112, 128, 144, 162, 180, 200, 220]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5]) == [18, 35, 51, 66, 80, 93, 105, 116, 126, 146, 165, 183, 200, 216, 231]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [2, 4, 8, 12, 18, 24, 32, 40, 50, 60]\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == [10, 19, 27, 34, 40, 46, 53, 61, 70, 80]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == [2000000000, 3999999999, 5999999997, 7999999994, 9999999990, 11999999985, 13999999979, 15999999972, 17999999964, 19999999955]\n assert candidate(nums = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [78, 154, 228, 300, 370, 438, 504, 568, 630, 690, 748, 804, 858, 910, 960, 1008, 1054, 1098, 1140, 1180]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [18, 35, 51, 66, 80, 93, 105, 116, 126, 146, 165, 183, 200, 216, 231, 245, 258, 270, 281]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046, 4094, 8190, 16382, 32766, 65534]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [200, 390, 570, 740, 900, 1050, 1190, 1320, 1440, 1550]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == [2, 6, 10, 16, 22, 28, 36, 44, 52, 60, 70, 80, 90, 100, 110]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [14, 28, 42, 56, 70, 84, 98, 112, 126, 140, 154, 168, 182, 196, 210, 224, 238, 252, 266, 280]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == [2, 4, 6, 8, 10, 14, 18, 22, 26, 30, 36, 42, 48, 54, 60, 68, 76, 84, 92, 100]\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [2, 8, 20, 40, 70, 112, 168, 240, 330, 440]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [2, 6, 12, 20, 30, 36, 43, 51, 60, 70, 76, 83, 91, 100, 110, 116, 123, 131, 140, 150]\n assert candidate(nums = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [4, 12, 24, 40, 60, 71, 84, 99, 116, 135, 157, 183, 213, 247, 285, 327, 373, 423, 477, 535]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == [2, 22, 222, 2222, 22222, 222222, 2222222, 22222222, 222222222, 2222222222]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [2, 8, 18, 32, 50, 72, 98, 128, 162, 200]\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]) == [2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600, 650]\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10]) == [20, 60, 90, 150, 190, 270, 320, 420, 480, 600, 670, 810, 890, 1050, 1140]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == [20, 60, 120, 200, 300, 420, 560, 720, 900, 1100, 1320, 1560, 1820, 2100, 2400, 2720, 3060, 3420, 3800, 4200]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [200, 390, 570, 740, 900, 1050, 1190, 1320, 1440, 1550, 1750, 1940, 2120, 2290, 2450, 2600, 2740, 2870, 2990, 3100]\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]) == [2, 4, 8, 14, 24, 40, 66, 108, 176, 286, 464, 752, 1218, 1972, 3192, 5166, 8360, 13528, 21890, 35420]\n assert candidate(nums = [20, 10, 30, 25, 40, 35, 50, 45, 60, 55, 70, 65, 80, 75, 90, 85, 100, 95, 110, 105]) == [40, 70, 130, 185, 265, 340, 440, 535, 655, 770, 910, 1045, 1205, 1360, 1540, 1715, 1915, 2110, 2330, 2545]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [20, 60, 120, 200, 300, 420, 560, 720, 900, 1100, 1290, 1470, 1640, 1800, 1950, 2090, 2220, 2340, 2450]\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]) == [2, 6, 12, 22, 38, 64, 106, 174, 284, 462, 750, 1216, 1970, 3190, 5164]\n assert candidate(nums = [10, 20, 30, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == [20, 60, 120, 200, 270, 330, 380, 440, 510, 590, 690, 810, 950, 1110, 1290]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [200, 390, 570, 740, 900, 1050, 1190, 1320, 1440, 1550]\n assert candidate(nums = [1, 100, 10000, 1000000, 100000000]) == [2, 202, 20202, 2020202, 202020202]\n assert candidate(nums = [500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000]) == [1000000000, 2000000000, 3000000000, 4000000000, 5000000000, 6000000000, 7000000000, 8000000000, 9000000000, 10000000000]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [2, 8, 18, 32, 50, 72, 98, 128, 162, 200, 242, 288, 338, 392, 450, 512, 578, 648, 722, 800]\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == [2, 22, 33, 53, 64, 84, 95, 115, 126, 146, 157, 177, 188, 208, 219, 239, 250, 270, 281, 301]\n assert candidate(nums = [5, 3, 9, 2, 8, 1, 7, 6, 4, 10]) == [10, 18, 36, 47, 64, 74, 90, 105, 118, 138]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046, 4094]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [20, 60, 120, 200, 300, 420, 560, 720, 900, 1100]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == [2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046, 4094, 8190, 16382]\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300]) == [30, 90, 180, 300, 450, 630, 840, 1080, 1350, 1650, 1980, 2340, 2730, 3150, 3600, 4080, 4590, 5130, 5700, 6300]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == [2, 8, 13, 23, 32, 46, 59, 77, 94, 116, 137, 163, 188, 218, 247, 281, 314, 352, 389, 429]\n assert candidate(nums = [5, 1, 3, 7, 2, 8, 4, 6, 10, 9, 11, 12, 13, 14, 15]) == [10, 16, 24, 38, 47, 63, 75, 89, 109, 128, 150, 174, 200, 228, 258]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [200, 600, 1200, 2000, 3000, 4200, 5600, 7200, 9000, 11000]\n", "comparison": "exact"}, "public_tests": ["[2,3,7,5,10]", "[1,1,2,4,8,16]"], "hints": ["Keep track of the prefix maximum of the array", "Establish a relationship between ans[i] and ans[i-1]", "for 0 < i < n, ans[i] = ans[i-1]+conver[i]. In other words, array ans is the prefix sum array of the conversion array"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findPrefixScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:26+00:00", "tests_total": 94, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def find_prefix_score(nums)", "container": null, "callable": "find_prefix_score", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2643, "task_id": "row-with-maximum-ones", "difficulty": "Easy", "problem_description": "Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.\n\nIn case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.\n\nReturn an array containing the index of the row, and the number of ones in it.\n\nExample 1:\n\nInput: mat = [[0,1],[1,0]]\nOutput: [0,1]\nExplanation: Both rows have the same number of 1's. So we return the index of the smaller row, 0, and the maximum count of ones (1). So, the answer is [0,1].\n\nExample 2:\n\nInput: mat = [[0,0,0],[0,1,1]]\nOutput: [1,2]\nExplanation: The row indexed 1 has the maximum count of ones (2). So we return its index, 1, and the count. So, the answer is [1,2].\n\nExample 3:\n\nInput: mat = [[0,0],[1,1],[0,0]]\nOutput: [1,2]\nExplanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2].\n\nConstraints:\n\n- m == mat.length\n- n == mat[i].length\n- 1 <= m, n <= 100\n- mat[i][j] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[0, 1], [1, 0]]) == [0, 1]\n assert candidate(mat = [[1, 1, 1], [0, 1, 1], [1, 0, 0]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 0], [0, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 1]]) == [2, 4]\n assert candidate(mat = [[0, 0, 0], [0, 1, 1]]) == [1, 2]\n assert candidate(mat = [[0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0]]) == [2, 1]\n assert candidate(mat = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == [0, 0]\n assert candidate(mat = [[0, 0], [1, 1], [0, 0]]) == [1, 2]\n assert candidate(mat = [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1]]) == [3, 3]\n assert candidate(mat = [[1, 1, 1], [0, 1, 0], [1, 0, 0]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == [0, 4]\n assert candidate(mat = [[1, 1, 1], [1, 0, 1], [0, 0, 0]]) == [0, 3]\n assert candidate(mat = [[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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [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, 1]]) == [1, 31]\n assert candidate(mat = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0]]) == [4, 11]\n assert candidate(mat = [[0, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]) == [1, 10]\n assert candidate(mat = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 0, 0, 0]]) == [2, 5]\n assert candidate(mat = [[1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 1, 0]]) == [0, 5]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [1, 20]\n assert candidate(mat = [[1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == [3, 8]\n assert candidate(mat = [[1, 1, 1, 0, 0, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == [1, 8]\n assert candidate(mat = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == [0, 1]\n assert candidate(mat = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0, 1, 1]]) == [2, 4]\n assert candidate(mat = [[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]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]]) == [2, 6]\n assert candidate(mat = [[1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [0, 1, 0, 1, 0, 1]]) == [0, 5]\n assert candidate(mat = [[1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1, 1]]) == [0, 4]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [2, 10]\n assert candidate(mat = [[1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == [2, 4]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [3, 10]\n assert candidate(mat = [[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 1, 0, 0, 1], [0, 0, 0, 1, 0]]) == [0, 3]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1]]) == [3, 1]\n assert candidate(mat = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 0], [1, 1, 1, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0]]) == [0, 5]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1]]) == [4, 4]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == [0, 20]\n assert candidate(mat = [[1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == [0, 2]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]) == [6, 7]\n assert candidate(mat = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1]]) == [0, 4]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [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, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]]) == [0, 15]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [0, 12]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == [0, 10]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == [1, 11]\n assert candidate(mat = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1], [1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0]]) == [0, 4]\n assert candidate(mat = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == [0, 1]\n assert candidate(mat = [[0, 1, 1, 1, 1, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0]]) == [1, 8]\n assert candidate(mat = [[1, 1, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) == [0, 3]\n assert candidate(mat = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 1, 1], [0, 0, 1, 1, 1], [0, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == [5, 5]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1]]) == [0, 4]\n assert candidate(mat = [[0, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1]]) == [0, 5]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0]]) == [0, 10]\n assert candidate(mat = [[1, 0, 0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0]]) == [2, 6]\n assert candidate(mat = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0]]) == [3, 8]\n assert candidate(mat = [[1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1], [0, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]]) == [3, 6]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0]]) == [0, 5]\n assert candidate(mat = [[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 1, 0, 0, 1], [0, 0, 0, 0, 1]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [0, 20]\n assert candidate(mat = [[0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1]]) == [3, 3]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [9, 20]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]]) == [2, 11]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0]]) == [0, 7]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [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], [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, 1, 0, 1, 0]]) == [0, 32]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]) == [3, 7]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 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, 20]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]]) == [0, 10]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]) == [0, 6]\n assert candidate(mat = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [3, 10]\n assert candidate(mat = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == [0, 3]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == [0, 20]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [2, 10]\n assert candidate(mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == [9, 9]\n assert candidate(mat = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == [2, 6]\n", "comparison": "exact"}, "public_tests": ["[[0,1],[1,0]]", "[[0,0,0],[0,1,1]]", "[[0,0],[1,1],[0,0]]"], "hints": ["Iterate through each row and keep the count of ones."], "metadata": {"canonical_parameter_names": ["mat"], "leetcode_dataset_entry_point": "Solution().rowAndMaximumOnes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:30+00:00", "tests_total": 71, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def row_and_maximum_ones(mat)", "container": null, "callable": "row_and_maximum_ones", "parameters": [{"name": "mat", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2644, "task_id": "find-the-maximum-divisibility-score", "difficulty": "Easy", "problem_description": "You are given two integer arrays nums and divisors.\n\nThe divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].\n\nReturn the integer divisors[i] with the maximum divisibility score. If multiple integers have the maximum score, return the smallest one.\n\nExample 1:\n\nInput: nums = [2,9,15,50], divisors = [5,3,7,2]\nOutput: 2\nExplanation:\nThe divisibility score of divisors[0] is 2 since nums[2] and nums[3] are divisible by 5.\nThe divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 3.\nThe divisibility score of divisors[2] is 0 since none of the numbers in nums is divisible by 7.\nThe divisibility score of divisors[3] is 2 since nums[0] and nums[3] are divisible by 2.\nAs divisors[0], divisors[1], and divisors[3] have the same divisibility score, we return the smaller one which is divisors[3].\n\nExample 2:\n\nInput: nums = [4,7,9,3,9], divisors = [5,2,3]\nOutput: 3\nExplanation:\nThe divisibility score of divisors[0] is 0 since none of numbers in nums is divisible by 5.\nThe divisibility score of divisors[1] is 1 since only nums[0] is divisible by 2.\nThe divisibility score of divisors[2] is 3 since nums[2], nums[3] and nums[4] are divisible by 3.\n\nExample 3:\n\nInput: nums = [20,14,21,10], divisors = [10,16,20]\nOutput: 10\nExplanation:\nThe divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 10.\nThe divisibility score of divisors[1] is 0 since none of the numbers in nums is divisible by 16.\nThe divisibility score of divisors[2] is 1 since nums[0] is divisible by 20.\n\nConstraints:\n\n- 1 <= nums.length, divisors.length <= 1000\n- 1 <= nums[i], divisors[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [20, 14, 21, 10],divisors = [10, 16, 20]) == 10\n assert candidate(nums = [7, 14, 28, 35],divisors = [7, 14, 28, 35]) == 7\n assert candidate(nums = [12, 24, 36, 48],divisors = [3, 6, 12, 24]) == 3\n assert candidate(nums = [15, 30, 45, 60, 75],divisors = [5, 10, 15, 20, 25]) == 5\n assert candidate(nums = [100, 200, 300],divisors = [10, 20, 50]) == 10\n assert candidate(nums = [9, 18, 27, 36, 45],divisors = [9, 18, 27]) == 9\n assert candidate(nums = [11, 22, 33, 44, 55],divisors = [11, 22, 33, 44, 55]) == 11\n assert candidate(nums = [9, 18, 27, 36],divisors = [3, 6, 9, 18]) == 3\n assert candidate(nums = [3, 6, 9, 12],divisors = [3, 6, 9]) == 3\n assert candidate(nums = [7, 14, 21, 28],divisors = [7, 14]) == 7\n assert candidate(nums = [7, 14, 21, 28, 35],divisors = [7, 14]) == 7\n assert candidate(nums = [12, 24, 36, 48, 60],divisors = [2, 3, 4, 5, 6]) == 2\n assert candidate(nums = [8, 16, 24, 32, 40],divisors = [2, 4, 8, 16, 32]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5],divisors = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6],divisors = [1, 2, 3, 4, 5, 6]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55],divisors = [11, 22, 33]) == 11\n assert candidate(nums = [5, 10, 15, 20, 25],divisors = [5]) == 5\n assert candidate(nums = [5, 10, 15, 20, 25],divisors = [5, 10, 15, 20, 25]) == 5\n assert candidate(nums = [100, 200, 300, 400, 500],divisors = [10, 20, 30, 40, 50]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1],divisors = [1]) == 1\n assert candidate(nums = [13, 17, 19, 23, 29],divisors = [13, 17, 19, 23, 29]) == 13\n assert candidate(nums = [15, 30, 45, 60],divisors = [5, 10, 15, 30]) == 5\n assert candidate(nums = [100, 200, 300],divisors = [10, 20, 30, 40]) == 10\n assert candidate(nums = [100, 200, 300, 400],divisors = [10, 20, 30, 40]) == 10\n assert candidate(nums = [5, 5, 5, 5],divisors = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [7, 14, 21, 28],divisors = [7, 14, 28]) == 7\n assert candidate(nums = [2, 9, 15, 50],divisors = [5, 3, 7, 2]) == 2\n assert candidate(nums = [8, 16, 24, 32, 40],divisors = [4, 8, 16, 24, 32]) == 4\n assert candidate(nums = [8, 16, 24, 32],divisors = [2, 4, 8, 16]) == 2\n assert candidate(nums = [3, 6, 9, 12],divisors = [2, 3, 4]) == 3\n assert candidate(nums = [13, 17, 19],divisors = [2, 3, 5, 7, 11]) == 2\n assert candidate(nums = [7, 7, 7, 7, 7],divisors = [2, 3, 5, 7, 11]) == 7\n assert candidate(nums = [4, 7, 9, 3, 9],divisors = [5, 2, 3]) == 3\n assert candidate(nums = [12, 24, 36],divisors = [2, 3, 4, 6, 8]) == 2\n assert candidate(nums = [101, 202, 303, 404, 505],divisors = [1, 2, 3, 4, 5, 101]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(nums = [500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],divisors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 2\n assert candidate(nums = [101, 202, 303, 404, 505],divisors = [1, 101, 202, 303, 404]) == 1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],divisors = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == 101\n assert candidate(nums = [100, 200, 300, 400, 500],divisors = [10, 20, 30, 40, 50, 100]) == 10\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],divisors = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == 101\n assert candidate(nums = [1234, 2345, 3456, 4567, 5678, 6789, 7890, 8901, 9012, 10123, 11234, 12345, 13456, 14567, 15678, 16789, 17890, 18901, 19012, 20123],divisors = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1012]) == 234\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],divisors = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == 11\n assert candidate(nums = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110],divisors = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 101\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555],divisors = [11, 22, 33, 44, 55, 111111111]) == 111111111\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54],divisors = [2, 3, 4, 6, 9, 12, 18, 24, 36]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],divisors = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000],divisors = [100000000, 50000000, 25000000, 12500000]) == 12500000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],divisors = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [29, 58, 87, 116, 145],divisors = [1, 29, 58, 87, 116, 145, 5, 11, 19, 23]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],divisors = [13, 26, 39, 52, 65]) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],divisors = [2, 3, 4, 5, 6, 7, 8, 9, 10, 12]) == 2\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049],divisors = [3, 9, 27, 81, 243, 729]) == 3\n assert candidate(nums = [987, 654, 321, 654, 987],divisors = [13, 29, 37, 53, 17]) == 13\n assert candidate(nums = [101, 202, 303, 404, 505],divisors = [1, 2, 3, 4, 5, 10, 20, 50]) == 1\n assert candidate(nums = [98, 196, 294, 392, 490],divisors = [7, 14, 28, 49, 98]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [8, 15, 24, 35, 48, 63, 80, 99, 120, 143, 168, 195, 224, 253, 288, 325, 364, 405, 448, 495],divisors = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]) == 8\n assert candidate(nums = [123456789, 987654321, 246813579, 864209753],divisors = [3, 9, 27, 81, 243]) == 3\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],divisors = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207],divisors = [23, 46, 69, 92, 115, 138, 161, 184, 207]) == 23\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],divisors = [30, 60, 90, 120, 150, 180, 210, 240, 270, 300]) == 30\n assert candidate(nums = [55, 110, 220, 440, 880, 1760, 3520, 7040, 14080, 28160],divisors = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120]) == 10\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543],divisors = [98765, 87654, 76543, 65432, 54321, 43210, 32109, 21098, 10987]) == 10987\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],divisors = [2, 4, 5, 8, 10, 20, 25, 40, 50, 100]) == 2\n assert candidate(nums = [123456, 234567, 345678, 456789, 567890],divisors = [123, 234, 345, 456, 567]) == 123\n assert candidate(nums = [123456789, 246913578, 370370370, 493827162],divisors = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 9\n assert candidate(nums = [13, 19, 23, 29, 31, 37, 41, 43, 47, 53],divisors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 13\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000],divisors = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 1000\n assert candidate(nums = [123456, 789012, 345678, 901234, 567890],divisors = [123, 456, 789, 101112, 131415]) == 123\n assert candidate(nums = [29, 29, 29, 29, 29],divisors = [29, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],divisors = [3, 5, 6, 9, 10]) == 3\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],divisors = [1, 2, 3, 4, 5, 10, 20, 50, 100, 101]) == 1\n assert candidate(nums = [9, 81, 729, 6561, 59049],divisors = [3, 9, 27, 81, 243]) == 3\n assert candidate(nums = [17, 19, 23, 29, 31],divisors = [2, 3, 5, 7, 11, 13, 17]) == 17\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149],divisors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500],divisors = [10, 20, 25, 50, 100]) == 10\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],divisors = [2, 3, 4, 6, 8, 12, 16, 24, 32, 48]) == 2\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333],divisors = [1, 3, 9, 27, 81, 243, 729]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],divisors = [1, 2, 3, 4, 5, 10, 13, 26, 52, 65, 130]) == 1\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60],divisors = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 2, 3, 4, 5]) == 2\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],divisors = [101, 202, 303, 404, 505]) == 101\n assert candidate(nums = [12345, 12345, 12345, 12345, 12345],divisors = [1, 2, 3, 5, 15, 30, 4115, 12345]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],divisors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 2\n assert candidate(nums = [81, 162, 243, 324, 405, 486, 567, 648, 729, 810],divisors = [3, 6, 9, 18, 27, 54, 81, 162, 243, 486, 810]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666],divisors = [3, 9, 27, 81]) == 3\n assert candidate(nums = [42, 84, 126, 168, 210, 252],divisors = [6, 12, 18, 24, 30, 36]) == 6\n assert candidate(nums = [123456789, 987654321, 135792468, 246813579],divisors = [123, 456, 789, 1234, 5678, 9876]) == 123\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260],divisors = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130]) == 13\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111],divisors = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 111\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],divisors = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987],divisors = [98765432, 87654321, 76543210, 65432109, 54321098]) == 87654321\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],divisors = [3, 4, 6, 8, 12, 15, 20, 24, 30, 40]) == 3\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555],divisors = [99999999, 88888888, 77777777, 66666666, 55555555]) == 55555555\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576],divisors = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],divisors = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43]) == 11\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],divisors = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],divisors = [11, 22, 33, 44, 55]) == 11\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909],divisors = [101, 202, 303, 404]) == 101\n assert candidate(nums = [49, 98, 147, 196, 245, 294, 343, 392, 441, 490],divisors = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 7\n assert candidate(nums = [97, 89, 83, 79, 73, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],divisors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 73, 79, 83, 89, 97]) == 2\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000],divisors = [125000000, 250000000, 500000000, 1000000000]) == 125000000\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378],divisors = [6, 12, 18, 24]) == 6\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],divisors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],divisors = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [37, 74, 111, 148, 185],divisors = [37, 74, 111, 148, 185, 35, 142, 194, 226, 370]) == 37\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555],divisors = [111, 222, 333, 444, 555]) == 111\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],divisors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666],divisors = [1000000000, 999999999, 500000000, 250000000, 100000000]) == 100000000\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],divisors = [2, 3, 5, 7, 11]) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],divisors = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 3\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],divisors = [1, 13, 26, 39, 52, 65, 78, 91, 104, 117, 130]) == 1\n assert candidate(nums = [33, 66, 99, 132, 165],divisors = [11, 22, 33, 44, 55]) == 11\n assert candidate(nums = [17, 19, 23, 29, 31, 37, 41, 43, 47],divisors = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 17\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],divisors = [1, 2, 3, 4, 5, 6, 8, 9, 10, 12]) == 1\n assert candidate(nums = [77, 77, 77, 77, 77, 77, 77, 77, 77, 77],divisors = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41]) == 7\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220],divisors = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == 11\n assert candidate(nums = [123456, 234567, 345678, 456789, 567890, 678901, 789012, 890123, 901234, 1012345],divisors = [11111, 22222, 33333, 44444, 55555]) == 11111\n", "comparison": "exact"}, "public_tests": ["[2,9,15,50]\n[5,3,7,2]", "[4,7,9,3,9]\n[5,2,3]", "[20,14,21,10]\n[10,16,20]"], "hints": ["Consider counting for each element in divisors the count of elements in nums divisible by it using bruteforce.", "After counting for each divisor, take the one with the maximum count. In case of a tie, take the minimum one of them."], "metadata": {"canonical_parameter_names": ["nums", "divisors"], "leetcode_dataset_entry_point": "Solution().maxDivScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:33+00:00", "tests_total": 131, "tests_dropped": 9, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def max_div_score(nums, divisors)", "container": null, "callable": "max_div_score", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "divisors", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2645, "task_id": "minimum-additions-to-make-valid-string", "difficulty": "Medium", "problem_description": "Given a string word to which you can insert letters \"a\", \"b\" or \"c\" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.\n\nA string is called valid if it can be formed by concatenating the string \"abc\" several times.\n\nExample 1:\n\nInput: word = \"b\"\nOutput: 2\nExplanation: Insert the letter \"a\" right before \"b\", and the letter \"c\" right next to \"b\" to obtain the valid string \"abc\".\n\nExample 2:\n\nInput: word = \"aaa\"\nOutput: 6\nExplanation: Insert letters \"b\" and \"c\" next to each \"a\" to obtain the valid string \"abcabcabc\".\n\nExample 3:\n\nInput: word = \"abc\"\nOutput: 0\nExplanation: word is already valid. No modifications are needed.\n\nConstraints:\n\n- 1 <= word.length <= 50\n- word consists of letters \"a\", \"b\" and \"c\" only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aab\") == 3\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"bacbac\") == 6\n assert candidate(word = \"aabbcc\") == 6\n assert candidate(word = \"acbac\") == 4\n assert candidate(word = \"aababacaba\") == 8\n assert candidate(word = \"abcabc\") == 0\n assert candidate(word = \"bbcc\") == 5\n assert candidate(word = \"cccc\") == 8\n assert candidate(word = \"aaaaa\") == 10\n assert candidate(word = \"cab\") == 3\n assert candidate(word = \"bb\") == 4\n assert candidate(word = \"aaa\") == 6\n assert candidate(word = \"b\") == 2\n assert candidate(word = \"ac\") == 1\n assert candidate(word = \"aaabbbccc\") == 12\n assert candidate(word = \"abac\") == 2\n assert candidate(word = \"bbbbbbb\") == 14\n assert candidate(word = \"aabccba\") == 8\n assert candidate(word = \"bbccaa\") == 9\n assert candidate(word = \"cba\") == 6\n assert candidate(word = \"ccbaab\") == 9\n assert candidate(word = \"ccc\") == 6\n assert candidate(word = \"bcab\") == 2\n assert candidate(word = \"ccccab\") == 9\n assert candidate(word = \"aababab\") == 5\n assert candidate(word = \"aaaaaabbbbbc\") == 18\n assert candidate(word = \"cccbbaaa\") == 16\n assert candidate(word = \"cbac\") == 5\n assert candidate(word = \"abcabcabc\") == 0\n assert candidate(word = \"ba\") == 4\n assert candidate(word = \"cccccccc\") == 16\n assert candidate(word = \"abbbccca\") == 10\n assert candidate(word = \"abcbac\") == 3\n assert candidate(word = \"bbbb\") == 8\n assert candidate(word = \"caabbac\") == 8\n assert candidate(word = \"babbabcabcbacbacbacb\") == 16\n assert candidate(word = \"aaaab\") == 7\n assert candidate(word = \"bcaabc\") == 3\n assert candidate(word = \"bbbbbb\") == 12\n assert candidate(word = \"cabababc\") == 4\n assert candidate(word = \"bacbacbac\") == 9\n assert candidate(word = \"bcaacb\") == 6\n assert candidate(word = \"abcababc\") == 1\n assert candidate(word = \"abacbacbac\") == 8\n assert candidate(word = \"bcbcbc\") == 3\n assert candidate(word = \"aaaaaaaa\") == 16\n assert candidate(word = \"bbbaccc\") == 11\n assert candidate(word = \"babcbcbcabc\") == 4\n assert candidate(word = \"bcbcb\") == 4\n assert candidate(word = \"aacaabbc\") == 7\n assert candidate(word = \"abacbac\") == 5\n assert candidate(word = \"aaaaaa\") == 12\n assert candidate(word = \"acb\") == 3\n assert candidate(word = \"ababab\") == 3\n assert candidate(word = \"cabcabc\") == 2\n assert candidate(word = \"aabbccabc\") == 6\n assert candidate(word = \"abab\") == 2\n assert candidate(word = \"abacab\") == 3\n assert candidate(word = \"bcabc\") == 1\n assert candidate(word = \"accba\") == 7\n assert candidate(word = \"aabacbac\") == 7\n assert candidate(word = \"bababab\") == 5\n assert candidate(word = \"bbbbbbbb\") == 16\n assert candidate(word = \"acbabc\") == 3\n assert candidate(word = \"aabcbc\") == 3\n assert candidate(word = \"abcaabcbacbacb\") == 10\n assert candidate(word = \"aabcbabccba\") == 10\n assert candidate(word = \"abccccba\") == 10\n assert candidate(word = \"baabbcc\") == 8\n assert candidate(word = \"cabcab\") == 3\n assert candidate(word = \"cbacba\") == 9\n assert candidate(word = \"bac\") == 3\n assert candidate(word = \"aaaa\") == 8\n assert candidate(word = \"abcbbca\") == 5\n assert candidate(word = \"bca\") == 3\n assert candidate(word = \"ababac\") == 3\n assert candidate(word = \"cbacbacb\") == 10\n assert candidate(word = \"abccba\") == 6\n assert candidate(word = \"cabcabcab\") == 3\n assert candidate(word = \"abcabcabcabcabc\") == 0\n assert candidate(word = \"bbbacabc\") == 7\n assert candidate(word = \"acbacbac\") == 7\n assert candidate(word = \"aaac\") == 5\n assert candidate(word = \"bbaaac\") == 9\n assert candidate(word = \"abcacbac\") == 4\n assert candidate(word = \"abacbc\") == 3\n assert candidate(word = \"ccca\") == 8\n assert candidate(word = \"cccccc\") == 12\n assert candidate(word = \"aabbaacc\") == 10\n assert candidate(word = \"acbacbacbac\") == 10\n assert candidate(word = \"abcba\") == 4\n assert candidate(word = \"acbacbacb\") == 9\n assert candidate(word = \"ccccbbbaaa\") == 20\n assert candidate(word = \"acabca\") == 3\n assert candidate(word = \"abbbcccaa\") == 12\n assert candidate(word = \"aabbbccc\") == 10\n assert candidate(word = \"abcabcbac\") == 3\n assert candidate(word = \"abcabca\") == 2\n assert candidate(word = \"ccababca\") == 7\n assert candidate(word = \"bababacbcabc\") == 6\n assert candidate(word = \"accab\") == 4\n assert candidate(word = \"abbbac\") == 6\n assert candidate(word = \"acbbca\") == 6\n assert candidate(word = \"bcabca\") == 3\n assert candidate(word = \"bcbcbcbc\") == 4\n assert candidate(word = \"aabcbcbc\") == 4\n assert candidate(word = \"abcabcabcabc\") == 0\n", "comparison": "exact"}, "public_tests": ["\"b\"", "\"aaa\"", "\"abc\""], "hints": ["Maintain a pointer on word and another pointer on string “abc”.", "If the two characters that are being pointed to differ, Increment the answer and the pointer to the string “abc” by one."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().addMinimum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:35+00:00", "tests_total": 108, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "stack", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def add_minimum(word)", "container": null, "callable": "add_minimum", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2646, "task_id": "minimize-the-total-price-of-the-trips", "difficulty": "Hard", "problem_description": "There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.\n\nEach node has an associated price. You are given an integer array price, where price[i] is the price of the i^th node.\n\nThe price sum of a given path is the sum of the prices of all nodes lying on that path.\n\nAdditionally, you are given a 2D integer array trips, where trips[i] = [start_i, end_i] indicates that you start the i^th trip from the node start_i and travel to the node end_i by any path you like.\n\nBefore performing your first trip, you can choose some non-adjacent nodes and halve the prices.\n\nReturn the minimum total price sum to perform all the given trips.\n\nExample 1:\n\nInput: n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]]\nOutput: 23\nExplanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0, 2, and 3, and making their price half.\nFor the 1^st trip, we choose path [0,1,3]. The price sum of that path is 1 + 2 + 3 = 6.\nFor the 2^nd trip, we choose path [2,1]. The price sum of that path is 2 + 5 = 7.\nFor the 3^rd trip, we choose path [2,1,3]. The price sum of that path is 5 + 2 + 3 = 10.\nThe total price sum of all trips is 6 + 7 + 10 = 23.\nIt can be proven, that 23 is the minimum answer that we can achieve.\n\nExample 2:\n\nInput: n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]]\nOutput: 1\nExplanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.\nFor the 1^st trip, we choose path [0]. The price sum of that path is 1.\nThe total price sum of all trips is 1. It can be proven, that 1 is the minimum answer that we can achieve.\n\nConstraints:\n\n- 1 <= n <= 50\n- edges.length == n - 1\n- 0 <= a_i, b_i <= n - 1\n- edges represents a valid tree.\n- price.length == n\n- price[i] is an even integer.\n- 1 <= price[i] <= 1000\n- 1 <= trips.length <= 100\n- 0 <= start_i, end_i <= n - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [10, 10, 10],trips = [[0, 2], [0, 1], [1, 2]]) == 50\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [1, 3], [3, 4]],price = [2, 4, 6, 8, 10],trips = [[0, 4], [1, 2]]) == 25\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [2, 4, 6, 8, 10, 12],trips = [[0, 3], [1, 5], [2, 4]]) == 42\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [6, 4, 2],trips = [[0, 2], [1, 1], [2, 0]]) == 20\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [6, 8, 10],trips = [[0, 1], [1, 2], [0, 2]]) == 40\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],price = [2, 2, 10, 6],trips = [[0, 3], [2, 1], [2, 3]]) == 23\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [2, 4, 6, 8, 10],trips = [[0, 3], [2, 4], [3, 4]]) == 37\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [2, 4, 6, 8, 10, 12],trips = [[0, 5], [1, 3], [2, 4], [3, 4]]) == 50\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [1, 3], [3, 4]],price = [10, 20, 30, 40, 50],trips = [[0, 2], [1, 4], [2, 3]]) == 185\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [4, 2, 10, 3, 5],trips = [[0, 4], [1, 3], [2, 0]]) == 20\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [4, 6, 8],trips = [[0, 2], [1, 1]]) == 18\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]],price = [2, 4, 6, 8, 10],trips = [[0, 2], [1, 3], [2, 4]]) == 39\n assert candidate(n = 2,edges = [[0, 1]],price = [2, 2],trips = [[0, 0]]) == 1\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],price = [4, 2, 8, 6, 3],trips = [[0, 3], [0, 4], [2, 3], [2, 4]]) == 41\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],price = [4, 6, 8],trips = [[0, 2], [1, 2], [0, 1]]) == 30\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [1, 3], [3, 4]],price = [4, 2, 3, 6, 5],trips = [[0, 1], [1, 4], [2, 4]]) == 25\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]],price = [8, 4, 2, 6, 3, 1],trips = [[0, 5], [2, 4], [1, 3]]) == 30\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9],trips = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 0]]) == 43\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [2, 6, 4, 10, 8, 12, 14],trips = [[0, 3], [1, 6], [2, 4], [4, 6], [5, 1]]) == 84\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [100, 200, 300, 400, 500, 600, 700],trips = [[0, 3], [1, 6], [2, 4], [3, 5], [4, 6]]) == 4350\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trips = [[0, 9], [1, 5], [2, 8], [3, 7], [4, 6]]) == 595\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trips = [[0, 5], [1, 8], [2, 9], [3, 6], [4, 7], [5, 0], [6, 1], [7, 2], [8, 3], [9, 4]]) == 1050\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],price = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],trips = [[0, 7], [1, 8], [2, 9], [3, 4], [4, 5], [5, 6], [6, 0], [7, 1], [8, 2], [9, 3]]) == 214\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7]],price = [5, 15, 25, 35, 45, 55, 65, 75],trips = [[0, 4], [1, 5], [2, 6], [3, 7], [0, 7], [1, 6], [2, 5]]) == 586\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],trips = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == 2525\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [200, 100, 50, 25, 125, 75, 150],trips = [[0, 6], [1, 5], [2, 3]]) == 774\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],price = [5, 10, 15, 20, 25, 30, 35, 40],trips = [[0, 7], [1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [6, 1], [7, 0], [0, 4], [1, 5], [2, 6], [3, 7], [4, 0], [5, 1], [6, 2], [7, 3]]) == 620\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],price = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],trips = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == 240\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],price = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],trips = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 246\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300],trips = [[0, 13], [1, 12], [2, 10], [3, 9]]) == 1230\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [4, 6], [4, 7], [5, 8], [5, 9], [6, 10], [6, 11], [7, 12], [7, 13], [8, 14]],price = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120],trips = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10]]) == 860\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],price = [2, 4, 6, 8, 10, 12, 14, 16],trips = [[0, 4], [1, 6], [2, 5], [3, 7], [0, 7], [1, 5], [2, 6]]) == 117\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],trips = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7]]) == 242\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [10, 20, 30, 40, 50, 60],trips = [[0, 3], [1, 5], [2, 4], [3, 4], [5, 0]]) == 340\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [10, 20, 30, 40, 50, 60, 70],trips = [[0, 6], [1, 4], [2, 3], [3, 5]]) == 295\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7]],price = [8, 16, 24, 32, 40, 48, 56, 64],trips = [[0, 7], [1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [6, 1], [7, 0]]) == 576\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],trips = [[0, 7], [1, 8], [2, 9], [3, 4], [4, 5], [5, 6], [6, 0], [7, 1], [8, 2], [9, 3], [10, 11], [11, 0]]) == 316\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],price = [8, 16, 24, 32, 40, 48, 56, 64, 72],trips = [[0, 8], [1, 7], [2, 6], [3, 5]]) == 720\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],price = [100, 200, 300, 400, 500, 600, 700, 800, 900],trips = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [5, 3], [6, 2], [7, 1], [8, 0], [0, 7], [1, 8], [2, 5], [3, 6], [4, 3], [5, 4], [6, 1], [7, 2], [8, 3]]) == 36100\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [6, 2, 4, 10, 8, 12],trips = [[0, 3], [1, 5], [2, 4], [3, 0], [4, 5], [5, 1]]) == 82\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],trips = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 8], [1, 9], [2, 10], [3, 11], [4, 12], [5, 13], [6, 14]]) == 2290\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [100, 200, 150, 50, 120, 70],trips = [[0, 5], [3, 4], [0, 2]]) == 690\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [2, 4, 6, 8, 10, 12],trips = [[0, 3], [1, 5], [2, 4], [3, 0], [4, 1], [5, 2], [0, 2], [1, 4], [2, 0]]) == 95\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],trips = [[0, 11], [1, 9], [2, 7], [3, 6]]) == 257\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 7], [3, 8], [3, 9]],price = [10, 12, 15, 20, 22, 25, 30, 35, 40, 45],trips = [[0, 4], [1, 7], [2, 8], [3, 9], [5, 6]]) == 243\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [500, 400, 300, 200, 100, 50],trips = [[0, 5], [1, 4], [2, 3], [3, 1], [4, 0], [5, 2], [0, 2], [1, 3]]) == 4500\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [10, 20, 30, 40, 50, 60, 70],trips = [[0, 3], [1, 5], [2, 6], [3, 1], [4, 0], [5, 2], [6, 4]]) == 460\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],price = [5, 10, 15, 20, 25, 30, 35],trips = [[0, 3], [1, 6], [2, 4], [3, 5], [4, 6], [5, 0]]) == 250\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trips = [[0, 9], [3, 5], [2, 7]]) == 370\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trips = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 1230\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],price = [2, 4, 6, 8, 10, 12, 14, 16],trips = [[0, 4], [1, 7], [2, 6], [3, 5], [4, 7], [5, 0], [6, 1], [7, 2]]) == 164\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],trips = [[0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [11, 0]]) == 153\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],price = [5, 10, 15, 20, 25, 30, 35, 40],trips = [[0, 7], [1, 6], [2, 5], [3, 4], [0, 4], [1, 5], [2, 6], [3, 7]]) == 670\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11]],price = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],trips = [[0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 810\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],price = [2, 4, 6, 8, 10, 12, 14, 16],trips = [[0, 7], [1, 6], [2, 5], [3, 4]]) == 134\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],trips = [[0, 11], [1, 10], [2, 9], [3, 8], [4, 7]]) == 254\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],price = [2, 4, 6, 8, 10, 12],trips = [[0, 3], [1, 5], [2, 4], [3, 0]]) == 51\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11]],price = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],trips = [[0, 7], [1, 8], [2, 9], [3, 10], [4, 11], [0, 8], [1, 9], [2, 10], [3, 11]]) == 642\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],price = [100, 200, 300, 400, 500, 600, 700, 800],trips = [[0, 7], [1, 6], [2, 5], [3, 4], [0, 2]]) == 3750\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],price = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],trips = [[0, 7], [1, 8], [2, 9], [3, 4], [5, 6]]) == 279\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [4, 6], [5, 7]],price = [2, 4, 6, 8, 10, 12, 14, 16],trips = [[0, 7], [2, 6], [1, 5], [4, 3], [0, 3]]) == 100\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],price = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],trips = [[0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]]) == 289\n", "comparison": "exact"}, "public_tests": ["4\n[[0,1],[1,2],[1,3]]\n[2,2,10,6]\n[[0,3],[2,1],[2,3]]", "2\n[[0,1]]\n[2,2]\n[[0,0]]"], "hints": ["The final answer is the price[i] * freq[i], where freq[i] is the number of times node i was visited during the trip, and price[i] is the final price.", "To find freq[i] we will use dfs or bfs for each trip and update every node on the path start and end.", "Finally, to find the final price[i] we will use dynamic programming on the tree. Let dp(v, 0/1) denote the minimum total price with the node v’s price being halved or not."], "metadata": {"canonical_parameter_names": ["n", "edges", "price", "trips"], "leetcode_dataset_entry_point": "Solution().minimumTotalPrice", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:37+00:00", "tests_total": 65, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "tree", "depth-first-search", "graph"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_total_price(n, edges, price, trips)", "container": null, "callable": "minimum_total_price", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "price", "type": "Integer[]"}, {"name": "trips", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2651, "task_id": "calculate-delayed-arrival-time", "difficulty": "Easy", "problem_description": "You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours.\n\nReturn the time when the train will arrive at the station.\n\nNote that the time in this problem is in 24-hours format.\n\nExample 1:\n\nInput: arrivalTime = 15, delayedTime = 5\nOutput: 20\nExplanation: Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).\n\nExample 2:\n\nInput: arrivalTime = 13, delayedTime = 11\nOutput: 0\nExplanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0).\n\nConstraints:\n\n- 1 <= arrivaltime < 24\n- 1 <= delayedTime <= 24\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arrivalTime = 5,delayedTime = 19) == 0\n assert candidate(arrivalTime = 8,delayedTime = 16) == 0\n assert candidate(arrivalTime = 13,delayedTime = 11) == 0\n assert candidate(arrivalTime = 15,delayedTime = 5) == 20\n assert candidate(arrivalTime = 1,delayedTime = 1) == 2\n assert candidate(arrivalTime = 12,delayedTime = 12) == 0\n assert candidate(arrivalTime = 1,delayedTime = 23) == 0\n assert candidate(arrivalTime = 0,delayedTime = 24) == 0\n assert candidate(arrivalTime = 23,delayedTime = 2) == 1\n assert candidate(arrivalTime = 5,delayedTime = 20) == 1\n assert candidate(arrivalTime = 19,delayedTime = 5) == 0\n assert candidate(arrivalTime = 18,delayedTime = 6) == 0\n assert candidate(arrivalTime = 2,delayedTime = 22) == 0\n assert candidate(arrivalTime = 20,delayedTime = 4) == 0\n assert candidate(arrivalTime = 3,delayedTime = 21) == 0\n assert candidate(arrivalTime = 20,delayedTime = 5) == 1\n assert candidate(arrivalTime = 6,delayedTime = 18) == 0\n assert candidate(arrivalTime = 9,delayedTime = 15) == 0\n assert candidate(arrivalTime = 17,delayedTime = 8) == 1\n assert candidate(arrivalTime = 7,delayedTime = 17) == 0\n assert candidate(arrivalTime = 20,delayedTime = 8) == 4\n assert candidate(arrivalTime = 7,delayedTime = 18) == 1\n assert candidate(arrivalTime = 18,delayedTime = 7) == 1\n assert candidate(arrivalTime = 15,delayedTime = 9) == 0\n assert candidate(arrivalTime = 10,delayedTime = 14) == 0\n assert candidate(arrivalTime = 19,delayedTime = 6) == 1\n assert candidate(arrivalTime = 20,delayedTime = 6) == 2\n assert candidate(arrivalTime = 16,delayedTime = 8) == 0\n assert candidate(arrivalTime = 11,delayedTime = 14) == 1\n assert candidate(arrivalTime = 17,delayedTime = 7) == 0\n assert candidate(arrivalTime = 14,delayedTime = 10) == 0\n", "comparison": "exact"}, "public_tests": ["15\n5", "13\n11"], "hints": ["Use the modulo operator to handle the case when the arrival time plus the delayed time goes beyond 24 hours.", "If the arrival time plus the delayed time is greater than or equal to 24, you can also subtract 24 to get the time in the 24-hour format."], "metadata": {"canonical_parameter_names": ["arrivalTime", "delayedTime"], "leetcode_dataset_entry_point": "Solution().findDelayedArrivalTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:42+00:00", "tests_total": 31, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def find_delayed_arrival_time(arrival_time, delayed_time)", "container": null, "callable": "find_delayed_arrival_time", "parameters": [{"name": "arrival_time", "type": "Integer"}, {"name": "delayed_time", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2652, "task_id": "sum-multiples", "difficulty": "Easy", "problem_description": "Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.\n\nReturn an integer denoting the sum of all numbers in the given range satisfying the constraint.\n\nExample 1:\n\nInput: n = 7\nOutput: 21\nExplanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.\n\nExample 2:\n\nInput: n = 10\nOutput: 40\nExplanation: Numbers in the range [1, 10] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9, 10. The sum of these numbers is 40.\n\nExample 3:\n\nInput: n = 9\nOutput: 30\nExplanation: Numbers in the range [1, 9] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9. The sum of these numbers is 30.\n\nConstraints:\n\n- 1 <= n <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 9) == 30\n assert candidate(n = 1) == 0\n assert candidate(n = 1000) == 272066\n assert candidate(n = 7) == 21\n assert candidate(n = 10) == 40\n assert candidate(n = 210) == 12075\n assert candidate(n = 666) == 121023\n assert candidate(n = 315) == 27090\n assert candidate(n = 100) == 2838\n assert candidate(n = 50) == 691\n assert candidate(n = 300) == 24321\n assert candidate(n = 333) == 30339\n assert candidate(n = 60) == 1024\n assert candidate(n = 30) == 274\n assert candidate(n = 550) == 82614\n assert candidate(n = 103) == 2940\n assert candidate(n = 840) == 191940\n assert candidate(n = 42) == 499\n assert candidate(n = 888) == 213532\n assert candidate(n = 101) == 2838\n assert candidate(n = 250) == 17152\n assert candidate(n = 789) == 169111\n assert candidate(n = 630) == 108045\n assert candidate(n = 999) == 271066\n assert candidate(n = 256) == 17659\n assert candidate(n = 20) == 119\n assert candidate(n = 150) == 6109\n assert candidate(n = 800) == 173877\n assert candidate(n = 15) == 81\n assert candidate(n = 200) == 10845\n assert candidate(n = 512) == 70927\n assert candidate(n = 750) == 153696\n assert candidate(n = 120) == 4071\n assert candidate(n = 499) == 67389\n assert candidate(n = 700) == 133342\n assert candidate(n = 500) == 67889\n assert candidate(n = 420) == 48090\n assert candidate(n = 84) == 1904\n", "comparison": "exact"}, "public_tests": ["7", "10", "9"], "hints": ["Iterate through the range 1 to n and count numbers divisible by either 3, 5, or 7."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().sumOfMultiples", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:44+00:00", "tests_total": 38, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_multiples(n)", "container": null, "callable": "sum_of_multiples", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2653, "task_id": "sliding-subarray-beauty", "difficulty": "Medium", "problem_description": "Given an integer array nums containing n integers, find the beauty of each subarray of size k.\n\nThe beauty of a subarray is the x^th smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.\n\nReturn an integer array containing n - k + 1 integers, which denote the beauty of the subarrays in order from the first index in the array.\n\n-\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,-1,-3,-2,3], k = 3, x = 2\nOutput: [-1,-2,-2]\nExplanation: There are 3 subarrays with size k = 3.\nThe first subarray is [1, -1, -3] and the 2^nd smallest negative integer is -1.\nThe second subarray is [-1, -3, -2] and the 2^nd smallest negative integer is -2.\nThe third subarray is [-3, -2, 3] and the 2^nd smallest negative integer is -2.\n\nExample 2:\n\nInput: nums = [-1,-2,-3,-4,-5], k = 2, x = 2\nOutput: [-1,-2,-3,-4]\nExplanation: There are 4 subarrays with size k = 2.\nFor [-1, -2], the 2^nd smallest negative integer is -1.\nFor [-2, -3], the 2^nd smallest negative integer is -2.\nFor [-3, -4], the 2^nd smallest negative integer is -3.\nFor [-4, -5], the 2^nd smallest negative integer is -4.\n\nExample 3:\n\nInput: nums = [-3,1,2,-3,0,-3], k = 2, x = 1\nOutput: [-3,0,-3,-3,-3]\nExplanation: There are 5 subarrays with size k = 2.\nFor [-3, 1], the 1^st smallest negative integer is -3.\nFor [1, 2], there is no negative integer so the beauty is 0.\nFor [2, -3], the 1^st smallest negative integer is -3.\nFor [-3, 0], the 1^st smallest negative integer is -3.\nFor [0, -3], the 1^st smallest negative integer is -3.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- 1 <= k <= n\n- 1 <= x <= k\n- -50 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 6, 7, 8, 9],k = 3,x = 2) == [0, 0, 0]\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 2,x = 2) == [-1, -2, -3, -4]\n assert candidate(nums = [1, -1, -3, -2, 3],k = 3,x = 2) == [-1, -2, -2]\n assert candidate(nums = [5, 6, 7, 8, 9],k = 3,x = 1) == [0, 0, 0]\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 4,x = 3) == [-20, -30]\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 3,x = 3) == [-10, -20, -30]\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 4,x = 2) == [-30, -40]\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2,x = 2) == [0, 0, 0, 0]\n assert candidate(nums = [-3, 1, 2, -3, 0, -3],k = 2,x = 1) == [-3, 0, -3, -3, -3]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 8,x = 4) == [-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7]\n assert candidate(nums = [-50, -49, -48, -47, -46, -45, -44, -43, -42, -41],k = 5,x = 2) == [-49, -48, -47, -46, -45, -44]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4, -5],k = 5,x = 1) == [0, 0, 0, 0, 0, 0, -1, -2, -3, -4, -5]\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 3,x = 1) == [-1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [0, -1, 0, -2, 0, -3, 0, -4, 0, -5, 0, -6, 0, -7, 0, -8, 0, -9, 0, -10],k = 4,x = 2) == [-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8, -9]\n assert candidate(nums = [49, 48, 47, 46, 45, 44, 43, 42, 41, 40],k = 5,x = 2) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 5,x = 3) == [0, -1, 0, -2, 0, -3]\n assert candidate(nums = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50],k = 5,x = 5) == [-5, -10, -15, -20, -25, -30]\n assert candidate(nums = [-5, -10, 5, -15, 20, -25, 0, 30, -35],k = 4,x = 2) == [-10, -10, -15, -15, 0, -25]\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, -10, 10],k = 10,x = 5) == [-1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 6,x = 2) == [-5, -6, -7, -8, -9, -10, -11, -12, -13, -14]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 5,x = 2) == [-1, -2, -2, -3, -3, -4]\n assert candidate(nums = [-10, -20, -30, -40, -50, 50, 40, 30, 20, 10],k = 5,x = 2) == [-40, -40, -40, -40, 0, 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 = 10,x = 5) == [0, 0, 0, 0, 0, -1, -2, -3, -4, -5, -6]\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 = 10,x = 5) == [-6, -6, -6, -6, -6, -6, 0, 0, 0, 0, 0]\n assert candidate(nums = [50, -50, 49, -49, 48, -48, 47, -47, 46, -46, 45, -45],k = 7,x = 4) == [0, -47, 0, -46, 0, -45]\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 = 10,x = 1) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -13, 14, -14, 15, -15, 16, -16],k = 6,x = 3) == [-2, -2, -4, -4, -6, -6, -8, -8, -10, -10, -12, -12, -13, -13, -14]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 5,x = 2) == [-4, -5, -6, -7, -8, -9]\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],k = 4,x = 3) == [0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-10, -20, -30, -40, -50, 10, 20, 30, 40, 50],k = 4,x = 3) == [-20, -30, -30, 0, 0, 0, 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 = 10,x = 5) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5],k = 6,x = 4) == [-2, -1, 0, 0, 0]\n assert candidate(nums = [-10, -20, -30, -40, -50, 50, 40, 30, 20, 10],k = 5,x = 3) == [-30, -30, -30, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3,x = 2) == [0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, -1, -2, 0, -3, 0, -4, 0, -5, 0],k = 3,x = 2) == [-1, -1, -2, 0, -3, 0, -4, 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 = 10,x = 5) == [-6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16]\n assert candidate(nums = [-1, -2, -3, 4, 5, -6, -7, 8, 9, -10],k = 4,x = 2) == [-2, -2, -3, -6, -6, -6, -7]\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 5,x = 3) == [0, -10, 0, -20, 0, -30]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8],k = 6,x = 3) == [-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6]\n assert candidate(nums = [-1, 0, 1, -2, 0, 2, -3, 0, 3, -4, 0, 4],k = 3,x = 1) == [-1, -2, -2, -2, -3, -3, -3, -4, -4, -4]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5,x = 2) == [0, 0, 0, 0, 0, 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 = 10,x = 3) == [0, 0, 0, -1, -2, -3, -4, -5, -6, -7, -8]\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 6,x = 4) == [0, 0, 0, 0, 0]\n assert candidate(nums = [0, -1, 1, -2, 2, -3, 3, -4, 4],k = 4,x = 2) == [-1, -1, -2, -2, -3, -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],k = 6,x = 3) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [50, -10, 40, -20, 30, -30, 20, -40, 10, -50, 0, 5, -5, 15, -15, 25, -25, 35, -35, 45],k = 5,x = 2) == [-10, -20, -20, -30, -30, -40, -40, -40, -5, -5, -5, -5, -15, -15, -25, -25]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],k = 6,x = 1) == [0, 0, 0, 0, 0, 0, -1, -2, -3, -4, -5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4,x = 1) == [0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1],k = 5,x = 2) == [0, 0, -4, -4, -4, -4]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6],k = 7,x = 5) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40],k = 4,x = 2) == [-10, -10, -20, -20, -30]\n assert candidate(nums = [-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50],k = 5,x = 2) == [-40, -30, -20, -10, 0, 0, 0]\n assert candidate(nums = [10, -5, 3, -1, 7, -8, 2, -6, 4, -9],k = 4,x = 2) == [-1, -1, -1, -1, -6, -6, -6]\n assert candidate(nums = [5, 10, -5, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40, 45, -45, 50, -50],k = 7,x = 4) == [0, -5, -5, -10, 0, -15, 0, -20, 0, -25, 0, -30, 0, -35]\n assert candidate(nums = [-5, 0, 5, -10, 15, -20, 25, -30, 35, -40],k = 4,x = 2) == [-5, 0, -10, -10, -20, -20, -30]\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 5,x = 3) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [0, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5],k = 6,x = 4) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [50, -50, 49, -49, 48, -48, 47, -47, 46, -46],k = 5,x = 3) == [0, -48, 0, -47, 0, -46]\n assert candidate(nums = [50, -50, 49, -49, 48, -48, 47, -47, 46, -46],k = 7,x = 5) == [0, 0, 0, 0]\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5],k = 5,x = 2) == [-1, -2, -2, -3, -3, -4, -4]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 2,x = 1) == [0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 4,x = 2) == [-2, -3, -4, -5, -6, -7, -8, -9]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5,x = 1) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [50, -50, 49, -49, 48, -48, 47, -47, 46, -46],k = 6,x = 4) == [0, 0, 0, 0, 0]\n assert candidate(nums = [-50, -40, -30, -20, -10, 0, 10, 20, 30, 40],k = 6,x = 4) == [-20, -10, 0, 0, 0]\n assert candidate(nums = [50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50],k = 5,x = 4) == [0, 0, 0, 0, 0, -10, -20]\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5],k = 5,x = 3) == [-1, 0, -2, 0, -3, 0]\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15],k = 8,x = 4) == [-1, -3, -3, -5, -5, -7, -7, -9]\n assert candidate(nums = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 4,x = 3) == [-1, -2, -3, -4, -5, -6, -7, -8]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 3,x = 2) == [0, -1, 0, -1, 0, -1, 0, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10,x = 5) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1],k = 5,x = 3) == [-1, -1, -1, -1]\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15],k = 6,x = 3) == [-1, -3, -3, -5, -5, -7, -7, -9, -9, -11]\n assert candidate(nums = [5, 10, -5, -10, 15, -15, 20, -20, 25, -25, 30],k = 4,x = 2) == [-5, -5, -10, -10, -15, -15, -20, -20]\n assert candidate(nums = [2, 3, -1, -2, 5, -3, 6, -4, 8, -5, 9, -6, 10, -7, 11, -8, 12, -9, 13, -10],k = 5,x = 3) == [0, -1, -1, -2, 0, -3, 0, -4, 0, -5, 0, -6, 0, -7, 0, -8]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 3,x = 1) == [-1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 7,x = 5) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 4,x = 2) == [-1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [-1, 0, 1, -2, 0, 2, -3, 0, 3, -4, 0, 4],k = 5,x = 2) == [-1, 0, -2, -2, 0, -3, -3, 0]\n assert candidate(nums = [-50, 0, 50, -49, 0, 49, -48, 0, 48, -47, 0, 47],k = 5,x = 3) == [0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-50, 0, 50, -49, 49, -48, 48, -47, 47],k = 6,x = 4) == [0, 0, 0, 0]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],k = 5,x = 4) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 5,x = 3) == [0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, -4, -5, -6, -7, -8]\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 4,x = 2) == [-10, -10, -20, -20, -30, -30, -40]\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40],k = 5,x = 4) == [0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7,x = 3) == [0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 4,x = 1) == [0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5,x = 2) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-10, -20, -30, 0, 10, 20, 30, -40, 40, -50, 50],k = 6,x = 3) == [-10, 0, 0, 0, 0, 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,x = 3) == [-1, 0, -3, 0, -5, 0, -7, 0, -9, 0, -11, 0, -13, 0, -15, 0]\n assert candidate(nums = [0, -1, 1, -2, 2, -3, 3, -4, 4],k = 5,x = 3) == [0, -1, 0, -2, 0]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 5,x = 5) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12],k = 8,x = 6) == [0, 0, 0, 0, 0]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 5,x = 3) == [-3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13]\n assert candidate(nums = [0, 0, 0, 0, 0, -1, 0, 0, 0, 0],k = 4,x = 1) == [0, 0, -1, -1, -1, -1, 0]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5,x = 1) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 = 10,x = 3) == [-5, -7, -7, -9, -9, -11, -11, -13, -13, -15, -15]\n assert candidate(nums = [3, -3, 6, -6, 9, -9, 12, -12, 15, -15],k = 7,x = 3) == [-3, -6, -6, -9]\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 5,x = 2) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, -10, -20, -30, 10, 20, 30, -10, -20, -30],k = 6,x = 3) == [-10, -10, -10, -10, -10, -10, -10]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 3,x = 1) == [0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [-1, 0, 1, -2, 0, 2, -3, 0, 3, -4],k = 3,x = 1) == [-1, -2, -2, -2, -3, -3, -3, -4]\n assert candidate(nums = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50],k = 3,x = 2) == [-10, -15, -20, -25, -30, -35, -40, -45]\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0],k = 6,x = 2) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [3, -2, -3, 1, -4, 5, -6, 7, -8],k = 3,x = 2) == [-2, -2, -3, 0, -4, 0, -6]\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50],k = 5,x = 3) == [-10, 0, -20, 0, -30, 0]\n", "comparison": "exact"}, "public_tests": ["[1,-1,-3,-2,3]\n3\n2", "[-1,-2,-3,-4,-5]\n2\n2", "[-3,1,2,-3,0,-3]\n2\n1"], "hints": ["Try to maintain the frequency of negative numbers in the current window of size k.", "The x^th smallest negative integer can be gotten by iterating through the frequencies of the numbers in order."], "metadata": {"canonical_parameter_names": ["nums", "k", "x"], "leetcode_dataset_entry_point": "Solution().getSubarrayBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:46+00:00", "tests_total": 106, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def get_subarray_beauty(nums, k, x)", "container": null, "callable": "get_subarray_beauty", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}, {"name": "x", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2654, "task_id": "minimum-number-of-operations-to-make-all-array-elements-equal-to-1", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums consisting of positive integers. You can do the following operation on the array any number of times:\n\n- Select an index i such that 0 <= i < n - 1 and replace either of nums[i] or nums[i+1] with their gcd value.\n\nReturn the minimum number of operations to make all elements of nums equal to 1. If it is impossible, return -1.\n\nThe gcd of two integers is the greatest common divisor of the two integers.\n\nExample 1:\n\nInput: nums = [2,6,3,4]\nOutput: 4\nExplanation: We can do the following operations:\n- Choose index i = 2 and replace nums[2] with gcd(3,4) = 1. Now we have nums = [2,6,1,4].\n- Choose index i = 1 and replace nums[1] with gcd(6,1) = 1. Now we have nums = [2,1,1,4].\n- Choose index i = 0 and replace nums[0] with gcd(2,1) = 1. Now we have nums = [1,1,1,4].\n- Choose index i = 2 and replace nums[3] with gcd(1,4) = 1. Now we have nums = [1,1,1,1].\n\nExample 2:\n\nInput: nums = [2,10,6,14]\nOutput: -1\nExplanation: It can be shown that it is impossible to make all the elements equal to 1.\n\nConstraints:\n\n- 2 <= nums.length <= 50\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 1]) == 3\n assert candidate(nums = [100, 200, 300, 400]) == -1\n assert candidate(nums = [1, 2, 2, 3]) == 3\n assert candidate(nums = [7, 21, 35, 49, 63]) == -1\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == -1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21]) == -1\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 15, 25]) == -1\n assert candidate(nums = [2, 4, 6, 8, 10]) == -1\n assert candidate(nums = [3, 6, 9, 12]) == -1\n assert candidate(nums = [2, 6, 3, 4]) == 4\n assert candidate(nums = [2, 10, 6, 14]) == -1\n assert candidate(nums = [5, 15, 25, 35]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50]) == -1\n assert candidate(nums = [15, 9, 3, 6]) == -1\n assert candidate(nums = [5, 5, 5, 5]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [3, 5, 7, 11]) == 4\n assert candidate(nums = [10, 15, 20, 25]) == -1\n assert candidate(nums = [2, 3, 5, 7]) == 4\n assert candidate(nums = [3, 9, 3, 3]) == -1\n assert candidate(nums = [2, 2, 2, 2]) == -1\n assert candidate(nums = [6, 9, 12, 15]) == -1\n assert candidate(nums = [3, 3, 3, 3, 3]) == -1\n assert candidate(nums = [7, 14, 21, 28]) == -1\n assert candidate(nums = [2, 4, 6, 8]) == -1\n assert candidate(nums = [33, 55, 11, 22, 88, 44, 66]) == -1\n assert candidate(nums = [33, 66, 99, 132, 165, 198, 231, 264, 297, 330]) == -1\n assert candidate(nums = [48, 64, 80, 96, 112]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30]) == -1\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == -1\n assert candidate(nums = [100, 150, 200, 250, 300, 350]) == -1\n assert candidate(nums = [17, 34, 51, 68, 85]) == -1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91]) == -1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == -1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == -1\n assert candidate(nums = [7, 14, 28, 42, 56]) == -1\n assert candidate(nums = [8, 12, 18, 24, 30, 36]) == -1\n assert candidate(nums = [9, 12, 15, 18, 21]) == -1\n assert candidate(nums = [21, 28, 35, 42, 49]) == -1\n assert candidate(nums = [29, 58, 87, 116, 145, 174, 203, 232, 261, 290, 319, 348, 377, 406, 435, 464]) == -1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == -1\n assert candidate(nums = [10, 15, 25, 50]) == -1\n assert candidate(nums = [13, 17, 19, 23, 29, 31, 37]) == 7\n assert candidate(nums = [7, 14, 21, 28, 35, 42]) == -1\n assert candidate(nums = [33, 66, 99, 132, 165]) == -1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 15\n assert candidate(nums = [42, 70, 105, 140, 210]) == -1\n assert candidate(nums = [1000, 1500, 2000, 2500]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == -1\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500]) == -1\n assert candidate(nums = [8, 16, 24, 32, 40, 48]) == -1\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20]) == -1\n assert candidate(nums = [9, 27, 81, 243, 729]) == -1\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210]) == -1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204]) == -1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255]) == -1\n assert candidate(nums = [4, 8, 12, 16, 20, 24]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500]) == -1\n assert candidate(nums = [8, 12, 16, 20, 24, 28]) == -1\n assert candidate(nums = [1024, 2048, 3072, 4096, 5120, 6144]) == -1\n assert candidate(nums = [3, 6, 9, 12, 15, 18]) == -1\n assert candidate(nums = [15, 25, 35, 5]) == -1\n assert candidate(nums = [3, 5, 7, 9, 11]) == 5\n assert candidate(nums = [18, 27, 36, 45, 54]) == -1\n assert candidate(nums = [14, 21, 28, 35, 42]) == -1\n assert candidate(nums = [7, 14, 21, 28, 35]) == -1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220]) == -1\n assert candidate(nums = [12, 15, 18, 21, 24]) == -1\n assert candidate(nums = [103, 206, 309, 412, 515, 618, 721, 824, 927, 1030, 1133, 1236, 1339, 1442, 1545, 1648, 1751, 1854, 1957, 2060, 2163, 2266, 2369]) == -1\n assert candidate(nums = [6, 18, 30, 42, 54, 66, 78]) == -1\n assert candidate(nums = [13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 10\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77]) == -1\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40]) == -1\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65]) == -1\n assert candidate(nums = [45, 90, 135, 180, 225, 270]) == -1\n assert candidate(nums = [5, 10, 20, 40, 80, 160]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500]) == -1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77]) == -1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64]) == -1\n assert candidate(nums = [18, 24, 30, 36, 42]) == -1\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266, 285]) == -1\n assert candidate(nums = [21, 42, 7, 14, 28, 35]) == -1\n assert candidate(nums = [15, 25, 35, 45]) == -1\n assert candidate(nums = [13, 26, 39, 52, 65]) == -1\n assert candidate(nums = [17, 51, 85, 102, 136]) == -1\n assert candidate(nums = [109, 218, 327, 436, 545, 654, 763, 872, 981, 1090, 1199, 1308, 1417, 1526, 1635, 1744, 1853, 1962, 2071, 2180, 2289, 2398, 2507, 2616, 2725, 2834, 2943]) == -1\n assert candidate(nums = [3, 9, 27, 81, 243, 729]) == -1\n assert candidate(nums = [21, 35, 49, 63, 77, 91, 105]) == -1\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230]) == -1\n assert candidate(nums = [3, 9, 27, 81]) == -1\n assert candidate(nums = [97, 194, 291, 388, 485, 582]) == -1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == -1\n assert candidate(nums = [3, 9, 27, 81, 243]) == -1\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 10\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130]) == -1\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230, 253, 276, 299, 322, 345, 368, 391, 414, 437, 460, 483, 506]) == -1\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]) == 29\n assert candidate(nums = [123456, 234567, 345678, 456789, 567890]) == 5\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128]) == -1\n assert candidate(nums = [107, 214, 321, 428, 535, 642, 749, 856, 963, 1070, 1177, 1284, 1391, 1498, 1605, 1712, 1819, 1926, 2033, 2140, 2247, 2354, 2461, 2568, 2675]) == -1\n assert candidate(nums = [29, 58, 87, 116, 145, 174, 203, 232, 261, 290, 319, 348, 377, 406, 435, 464, 493, 522, 551, 580, 609, 638, 667, 696, 725]) == -1\n assert candidate(nums = [15, 20, 25, 30]) == -1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170]) == -1\n assert candidate(nums = [18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144]) == -1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21]) == -1\n assert candidate(nums = [7, 49, 91, 35, 119, 56]) == -1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == -1\n assert candidate(nums = [49, 98, 147, 196, 245, 294]) == -1\n assert candidate(nums = [61, 122, 183, 244, 305, 366, 427, 488, 549, 610, 671, 732, 793, 854, 915, 976]) == -1\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230, 253, 276, 299, 322]) == -1\n assert candidate(nums = [15, 9, 21, 6, 12]) == -1\n assert candidate(nums = [12, 18, 24, 30, 36]) == -1\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96]) == -1\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 10\n assert candidate(nums = [15, 25, 35, 45, 55]) == -1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143]) == -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]) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128]) == -1\n assert candidate(nums = [7, 14, 21, 35, 42]) == -1\n assert candidate(nums = [8, 12, 16, 20, 24, 28, 32, 36, 40]) == -1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260]) == -1\n assert candidate(nums = [42, 56, 70, 84, 98]) == -1\n assert candidate(nums = [41, 82, 123, 164, 205, 246, 287, 328, 369, 410, 451, 492, 533, 574, 615, 656, 697, 738, 779, 820]) == -1\n assert candidate(nums = [6, 18, 30, 42, 54, 66, 78, 90]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19\n assert candidate(nums = [21, 42, 63, 84, 105]) == -1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111]) == -1\n assert candidate(nums = [15, 25, 35, 45, 55]) == -1\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == -1\n assert candidate(nums = [1023, 2046, 3069, 4092, 5115, 6138, 7161, 8184, 9207, 10230]) == -1\n assert candidate(nums = [3, 5, 7, 11, 13]) == 5\n assert candidate(nums = [49, 98, 147, 196, 245, 294, 343]) == -1\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247]) == -1\n assert candidate(nums = [4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256]) == 15\n assert candidate(nums = [100, 150, 200, 250, 300]) == -1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255]) == -1\n assert candidate(nums = [35, 55, 77, 99, 121, 143, 165]) == 8\n assert candidate(nums = [15, 25, 35, 5, 10]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == -1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49]) == -1\n assert candidate(nums = [24, 36, 48, 60, 72, 84, 96, 108, 120, 132]) == -1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 10\n assert candidate(nums = [8, 16, 32, 64, 128]) == -1\n assert candidate(nums = [7, 14, 21, 28, 35]) == -1\n assert candidate(nums = [11, 22, 33, 44, 55, 66]) == -1\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42]) == -1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 272, 289, 306, 323, 340]) == -1\n assert candidate(nums = [997, 1994, 2991, 3988, 4985, 5982, 6979, 7976, 8973, 9970]) == -1\n assert candidate(nums = [3, 5, 9, 15, 21]) == 5\n assert candidate(nums = [100, 101, 102, 103, 104]) == 5\n", "comparison": "exact"}, "public_tests": ["[2,6,3,4]", "[2,10,6,14]"], "hints": ["Note that if you have at least one occurrence of 1 in the array, then you can make all the other elements equal to 1 with one operation each.", "Try finding the shortest subarray with a gcd equal to 1."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:49+00:00", "tests_total": 157, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2656, "task_id": "maximum-sum-with-exactly-k-elements", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score:\n\n1. Select an element m from nums.\n2. Remove the selected element m from the array.\n3. Add a new element with a value of m + 1 to the array.\n4. Increase your score by m.\n\nReturn the maximum score you can achieve after performing the operation exactly k times.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], k = 3\nOutput: 18\nExplanation: We need to choose exactly 3 elements from nums to maximize the sum.\nFor the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6]\nFor the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7]\nFor the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8]\nSo, we will return 18.\nIt can be proven, that 18 is the maximum answer that we can achieve.\n\nExample 2:\n\nInput: nums = [5,5,5], k = 2\nOutput: 11\nExplanation: We need to choose exactly 2 elements from nums to maximize the sum.\nFor the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6]\nFor the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7]\nSo, we will return 11.\nIt can be proven, that 11 is the maximum answer that we can achieve.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n- 1 <= k <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 18\n assert candidate(nums = [5, 5, 5],k = 2) == 11\n assert candidate(nums = [1, 1, 1, 1],k = 4) == 10\n assert candidate(nums = [10, 20, 30],k = 1) == 30\n assert candidate(nums = [100],k = 1) == 100\n assert candidate(nums = [1, 1, 1, 1, 1],k = 10) == 55\n assert candidate(nums = [100],k = 100) == 14950\n assert candidate(nums = [10, 20, 30],k = 4) == 126\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [1, 1, 1, 1],k = 5) == 15\n assert candidate(nums = [100, 100, 100, 100],k = 100) == 14950\n assert candidate(nums = [10, 20, 30],k = 5) == 160\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96],k = 60) == 7530\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],k = 50) == 6225\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42],k = 7) == 315\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 15) == 165\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50],k = 10) == 545\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 15) == 390\n assert candidate(nums = [1],k = 100) == 5050\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 = 30) == 1035\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 20) == 290\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 100) == 6950\n assert candidate(nums = [1, 3, 5, 7, 9],k = 7) == 84\n assert candidate(nums = [25, 50, 75, 100],k = 15) == 1605\n assert candidate(nums = [1, 3, 5, 7, 9],k = 7) == 84\n assert candidate(nums = [50, 40, 30, 20, 10],k = 30) == 1935\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 15) == 405\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 = 50) == 3725\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],k = 16) == 760\n assert candidate(nums = [99, 98, 97, 96, 95],k = 10) == 1035\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 50) == 1575\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 75) == 10275\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 145\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 1045\n assert candidate(nums = [55, 55, 55, 55, 55, 55, 55, 55, 55, 55],k = 100) == 10450\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 15) == 180\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 30) == 1035\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 91\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 6225\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 20) == 210\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 12) == 306\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 100) == 14950\n assert candidate(nums = [50],k = 100) == 9950\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],k = 50) == 6125\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 20) == 590\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 100) == 5750\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 10) == 245\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 40) == 1980\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 50) == 6225\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 75) == 6525\n assert candidate(nums = [99, 98, 97, 96, 95],k = 20) == 2170\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 10) == 155\n assert candidate(nums = [50, 51, 52, 53, 54],k = 8) == 460\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 25) == 550\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 = 20) == 210\n assert candidate(nums = [90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100],k = 11) == 1155\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 75) == 4200\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],k = 50) == 1275\n assert candidate(nums = [1, 3, 5, 7, 9],k = 10) == 135\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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100],k = 100) == 14950\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 20) == 2190\n assert candidate(nums = [90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 460\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],k = 15) == 1605\n assert candidate(nums = [42],k = 100) == 9150\n assert candidate(nums = [10, 20, 30, 40, 50, 60],k = 10) == 645\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 15) == 1590\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 50) == 1325\n assert candidate(nums = [1, 2, 3, 4, 5],k = 100) == 5450\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],k = 30) == 1545\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],k = 100) == 14850\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 = 50) == 2225\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30],k = 9) == 306\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1) == 100\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 25) == 325\n assert candidate(nums = [91, 92, 93, 94, 95, 96, 97, 98, 99, 100],k = 75) == 10275\n assert candidate(nums = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99],k = 100) == 14850\n assert candidate(nums = [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],k = 75) == 10200\n assert candidate(nums = [50, 40, 30, 20, 10],k = 15) == 855\n assert candidate(nums = [2, 4, 6, 8, 10, 12],k = 15) == 285\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 20) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 1725\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 = 20) == 590\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],k = 100) == 7450\n assert candidate(nums = [90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100],k = 20) == 2190\n assert candidate(nums = [1, 3, 5, 7, 9],k = 5) == 55\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50],k = 7) == 371\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 25) == 2800\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 30) == 3405\n assert candidate(nums = [99, 98, 97, 96, 95],k = 25) == 2775\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 15) == 1605\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],k = 25) == 2800\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == 145\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 = 50) == 3725\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]\n3", "[5,5,5]\n2"], "hints": [], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximizeSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:53+00:00", "tests_total": 97, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def maximize_sum(nums, k)", "container": null, "callable": "maximize_sum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2657, "task_id": "find-the-prefix-common-array-of-two-arrays", "difficulty": "Medium", "problem_description": "You are given two 0-indexed integer permutations A and B of length n.\n\nA prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.\n\nReturn the prefix common array of A and B.\n\nA sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.\n\nExample 1:\n\nInput: A = [1,3,2,4], B = [3,1,2,4]\nOutput: [0,2,3,4]\nExplanation: At i = 0: no number is common, so C[0] = 0.\nAt i = 1: 1 and 3 are common in A and B, so C[1] = 2.\nAt i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.\nAt i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.\n\nExample 2:\n\nInput: A = [2,3,1], B = [3,1,2]\nOutput: [0,1,3]\nExplanation: At i = 0: no number is common, so C[0] = 0.\nAt i = 1: only 3 is common in A and B, so C[1] = 1.\nAt i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.\n\nConstraints:\n\n- 1 <= A.length == B.length == n <= 50\n- 1 <= A[i], B[i] <= n\n- It is guaranteed that A and B are both a permutation of n integers.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(A = [1, 3, 2, 4],B = [3, 1, 2, 4]) == [0, 2, 3, 4]\n assert candidate(A = [1, 2, 3],B = [3, 2, 1]) == [0, 1, 3]\n assert candidate(A = [2, 3, 1],B = [3, 1, 2]) == [0, 1, 3]\n assert candidate(A = [5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5]) == [0, 0, 1, 3, 5]\n assert candidate(A = [1, 2, 3, 4, 5],B = [5, 4, 3, 2, 1]) == [0, 0, 1, 3, 5]\n assert candidate(A = [4, 1, 3, 2],B = [2, 3, 4, 1]) == [0, 0, 2, 4]\n assert candidate(A = [4, 3, 2, 1],B = [1, 4, 2, 3]) == [0, 1, 2, 4]\n assert candidate(A = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2],B = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [0, 2, 2, 2, 2, 2, 4, 6, 8, 10]\n assert candidate(A = [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, 30, 29, 28, 27, 26],B = [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, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30]\n assert candidate(A = [3, 1, 2],B = [2, 3, 1]) == [0, 1, 3]\n assert candidate(A = [1, 5, 9, 13, 17, 21, 2, 6, 10, 14, 18, 22, 3, 7, 11, 15, 19, 23, 4, 8, 12, 16, 20, 24],B = [24, 20, 16, 12, 8, 4, 23, 19, 15, 11, 7, 3, 22, 18, 14, 10, 6, 2, 21, 17, 13, 9, 5, 1]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]\n assert candidate(A = [9, 8, 7, 6, 5, 4, 3, 2, 1],B = [2, 4, 6, 8, 1, 3, 5, 7, 9]) == [0, 0, 0, 2, 2, 3, 5, 7, 9]\n assert candidate(A = [2, 5, 4, 1, 3],B = [3, 5, 4, 1, 2]) == [0, 1, 2, 3, 5]\n assert candidate(A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],B = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(A = [7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7]) == [0, 0, 0, 1, 3, 5, 7]\n assert candidate(A = [5, 2, 9, 1, 7, 6, 8, 4, 3],B = [3, 4, 8, 6, 7, 1, 9, 2, 5]) == [0, 0, 0, 0, 1, 3, 5, 7, 9]\n assert candidate(A = [2, 1, 3, 4, 5],B = [3, 5, 1, 2, 4]) == [0, 0, 2, 3, 5]\n assert candidate(A = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [15, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 14],B = [14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15]) == [0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(A = [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],B = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]\n assert candidate(A = [3, 1, 4, 2],B = [4, 2, 3, 1]) == [0, 0, 2, 4]\n assert candidate(A = [5, 1, 2, 4, 3],B = [3, 2, 1, 5, 4]) == [0, 0, 2, 3, 5]\n assert candidate(A = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],B = [9, 10, 7, 8, 5, 6, 3, 4, 1, 2]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [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],B = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]\n assert candidate(A = [2, 3, 5, 4, 1],B = [1, 5, 2, 3, 4]) == [0, 0, 2, 3, 5]\n assert candidate(A = [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],B = [10, 20, 30, 1, 11, 21, 2, 12, 22, 3, 13, 23, 4, 14, 24, 5, 15, 25, 6, 16, 26, 7, 17, 27, 8, 18, 28, 9, 19, 29]) == [0, 0, 0, 1, 1, 1, 2, 2, 2, 4, 5, 6, 8, 9, 9, 10, 11, 11, 12, 14, 15, 17, 19, 20, 22, 24, 25, 27, 28, 30]\n assert candidate(A = [7, 5, 3, 1, 2, 4, 6],B = [6, 4, 2, 1, 3, 5, 7]) == [0, 0, 0, 1, 3, 5, 7]\n assert candidate(A = [3, 6, 5, 1, 8, 2, 9, 4, 7],B = [7, 4, 9, 2, 1, 8, 5, 6, 3]) == [0, 0, 0, 0, 1, 3, 5, 7, 9]\n assert candidate(A = [4, 1, 7, 2, 3, 6, 5],B = [5, 6, 3, 2, 1, 4, 7]) == [0, 0, 0, 1, 3, 5, 7]\n assert candidate(A = [2, 1, 4, 3],B = [3, 4, 1, 2]) == [0, 0, 2, 4]\n assert candidate(A = [7, 5, 3, 1, 9, 6, 4, 8, 2],B = [9, 6, 4, 8, 7, 5, 3, 1, 2]) == [0, 0, 0, 0, 2, 4, 6, 8, 9]\n assert candidate(A = [15, 10, 5, 1, 6, 11, 16, 2, 7, 12, 17, 3, 8, 13, 18, 4, 9, 14, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],B = [25, 20, 15, 10, 5, 1, 6, 11, 16, 2, 7, 12, 17, 3, 8, 13, 18, 4, 9, 14, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30]) == [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30]\n assert candidate(A = [13, 1, 8, 6, 5, 12, 9, 3, 7, 4, 10, 11, 2],B = [2, 11, 10, 4, 7, 3, 9, 12, 5, 6, 8, 1, 13]) == [0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13]\n assert candidate(A = [5, 1, 4, 3, 2],B = [2, 1, 5, 4, 3]) == [0, 1, 2, 3, 5]\n assert candidate(A = [3, 1, 5, 4, 2],B = [2, 4, 1, 5, 3]) == [0, 0, 1, 3, 5]\n assert candidate(A = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 0, 0, 1, 2, 4, 6, 8, 10]\n assert candidate(A = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9],B = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [5, 3, 8, 6, 2, 7, 4, 1],B = [1, 4, 7, 2, 6, 8, 3, 5]) == [0, 0, 0, 0, 2, 4, 6, 8]\n assert candidate(A = [7, 5, 9, 1, 3, 6, 8, 4, 2, 10],B = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [1, 2, 3, 5, 4],B = [5, 4, 1, 2, 3]) == [0, 0, 1, 3, 5]\n assert candidate(A = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],B = [6, 5, 7, 4, 8, 3, 9, 2, 10, 1]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [3, 2, 1, 4, 5],B = [4, 3, 1, 2, 5]) == [0, 1, 2, 4, 5]\n assert candidate(A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],B = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(A = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(A = [1, 5, 3, 4, 2],B = [5, 3, 2, 1, 4]) == [0, 1, 2, 3, 5]\n assert candidate(A = [3, 5, 1, 4, 2],B = [2, 1, 4, 5, 3]) == [0, 0, 1, 3, 5]\n assert candidate(A = [4, 1, 2, 3],B = [3, 2, 1, 4]) == [0, 0, 2, 4]\n assert candidate(A = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [5, 1, 4, 2, 3],B = [3, 4, 2, 5, 1]) == [0, 0, 1, 3, 5]\n assert candidate(A = [2, 1, 4, 3],B = [3, 4, 1, 2]) == [0, 0, 2, 4]\n assert candidate(A = [4, 1, 5, 3, 2],B = [2, 5, 3, 4, 1]) == [0, 0, 1, 3, 5]\n assert candidate(A = [8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8]) == [0, 0, 0, 0, 2, 4, 6, 8]\n assert candidate(A = [1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27, 4, 8, 12, 16, 20, 24, 28, 29, 30],B = [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, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 4, 6, 6, 6, 7, 9, 10, 12, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(A = [3, 7, 5, 1, 9, 4, 2, 8, 6],B = [9, 1, 2, 5, 8, 3, 4, 7, 6]) == [0, 0, 0, 2, 3, 4, 6, 8, 9]\n assert candidate(A = [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],B = [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]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45]\n assert candidate(A = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 5, 5, 6, 8, 10]\n assert candidate(A = [8, 3, 5, 7, 2, 6, 4, 1],B = [1, 2, 3, 4, 5, 6, 7, 8]) == [0, 0, 1, 1, 3, 4, 6, 8]\n assert candidate(A = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [0, 0, 0, 0, 0, 0, 0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(A = [9, 8, 7, 6, 5, 4, 3, 2, 1],B = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [0, 0, 0, 0, 1, 3, 5, 7, 9]\n assert candidate(A = [1, 5, 3, 2, 4],B = [2, 3, 4, 5, 1]) == [0, 0, 1, 3, 5]\n assert candidate(A = [5, 1, 9, 3, 7, 2, 8, 6, 4, 10],B = [10, 4, 6, 8, 2, 7, 3, 9, 1, 5]) == [0, 0, 0, 0, 0, 2, 4, 6, 8, 10]\n assert candidate(A = [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],B = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]\n assert candidate(A = [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],B = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]\n assert candidate(A = [5, 1, 9, 3, 7, 2, 8, 6, 4],B = [4, 6, 8, 2, 7, 3, 9, 1, 5]) == [0, 0, 0, 0, 1, 3, 5, 7, 9]\n assert candidate(A = [1, 5, 3, 2, 4],B = [4, 5, 2, 3, 1]) == [0, 1, 1, 3, 5]\n assert candidate(A = [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],B = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(A = [7, 3, 5, 1, 9, 8, 2, 6, 4],B = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [0, 0, 1, 2, 3, 3, 5, 7, 9]\n", "comparison": "exact"}, "public_tests": ["[1,3,2,4]\n[3,1,2,4]", "[2,3,1]\n[3,1,2]"], "hints": ["Consider keeping a frequency array that stores the count of occurrences of each number till index i.", "If a number occurred two times, it means it occurred in both A and B since they’re both permutations so add one to the answer."], "metadata": {"canonical_parameter_names": ["A", "B"], "leetcode_dataset_entry_point": "Solution().findThePrefixCommonArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:56+00:00", "tests_total": 72, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_the_prefix_common_array(a, b)", "container": null, "callable": "find_the_prefix_common_array", "parameters": [{"name": "a", "type": "Integer[]"}, {"name": "b", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2658, "task_id": "maximum-number-of-fish-in-a-grid", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:\n\n- A land cell if grid[r][c] = 0, or\n- A water cell containing grid[r][c] fish, if grid[r][c] > 0.\n\nA fisher can start at any water cell (r, c) and can do the following operations any number of times:\n\n- Catch all the fish at cell (r, c), or\n- Move to any adjacent water cell.\n\nReturn the maximum number of fish the fisher can catch if he chooses his starting cell optimally, or 0 if no water cell exists.\n\nAn adjacent cell of the cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) or (r - 1, c) if it exists.\n\nExample 1:\n\nInput: grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]\nOutput: 7\nExplanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3) and collect 4 fish.\n\nExample 2:\n\nInput: grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]\nOutput: 1\nExplanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 10\n- 0 <= grid[i][j] <= 10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[1, 2, 3], [0, 0, 0], [4, 5, 6]]) == 15\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 45\n assert candidate(grid = [[10, 0, 0], [0, 0, 0], [0, 0, 10]]) == 10\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == 1\n assert candidate(grid = [[0, 2, 1, 0], [4, 0, 0, 3], [1, 0, 0, 4], [0, 3, 2, 0]]) == 7\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) == 1\n assert candidate(grid = [[5, 5, 5], [5, 0, 5], [5, 5, 5]]) == 40\n assert candidate(grid = [[10, 10, 10], [10, 0, 10], [10, 10, 10]]) == 80\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0\n assert candidate(grid = [[5, 0, 3], [0, 2, 0], [1, 0, 4]]) == 5\n assert candidate(grid = [[10, 0, 10], [0, 0, 0], [10, 0, 10]]) == 10\n assert candidate(grid = [[0]]) == 0\n assert candidate(grid = [[10, 0, 10], [0, 10, 0], [10, 0, 10]]) == 10\n assert candidate(grid = [[1]]) == 1\n assert candidate(grid = [[1, 2], [3, 4]]) == 10\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 16\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) == 4\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 45\n assert candidate(grid = [[5, 0, 0, 0, 0, 0, 0, 0, 0, 5], [0, 4, 0, 0, 0, 0, 0, 0, 4, 0], [0, 0, 3, 0, 0, 0, 0, 3, 0, 0], [0, 0, 0, 2, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 2, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 3, 0, 0], [0, 4, 0, 0, 0, 0, 0, 0, 4, 0], [5, 0, 0, 0, 0, 0, 0, 0, 0, 5]]) == 5\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, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[0, 5, 0, 0, 8], [0, 0, 0, 0, 0], [4, 0, 0, 0, 7], [0, 0, 0, 0, 0], [6, 0, 0, 0, 9]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 2, 1, 0], [0, 2, 3, 2, 0], [0, 1, 2, 1, 0], [0, 0, 0, 0, 0]]) == 15\n assert candidate(grid = [[0, 0, 1, 3, 0], [2, 0, 0, 0, 0], [0, 4, 1, 2, 0], [0, 0, 0, 0, 5], [6, 0, 0, 0, 0]]) == 7\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 5, 6, 5, 0], [0, 6, 0, 6, 0], [0, 5, 6, 5, 0], [0, 0, 0, 0, 0]]) == 44\n assert candidate(grid = [[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\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == 28\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, 1, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 5, 0, 1, 0], [2, 0, 3, 0, 0], [0, 4, 0, 0, 6], [0, 0, 7, 0, 0], [0, 0, 0, 8, 0]]) == 8\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]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 2, 3, 0, 0], [0, 0, 0, 4, 0, 5, 0, 0], [0, 0, 0, 6, 7, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 28\n assert candidate(grid = [[0, 3, 0, 5, 0], [2, 0, 0, 0, 4], [0, 1, 0, 6, 0], [7, 0, 8, 0, 9], [0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[0, 0, 0, 0], [0, 9, 8, 0], [0, 7, 6, 0], [0, 5, 4, 0], [0, 3, 2, 0], [0, 1, 0, 0]]) == 45\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 9\n assert candidate(grid = [[0, 1, 0, 2, 0, 3, 0, 4, 0, 5], [5, 0, 4, 0, 3, 0, 2, 0, 1, 0], [0, 1, 0, 2, 0, 3, 0, 4, 0, 5], [5, 0, 4, 0, 3, 0, 2, 0, 1, 0], [0, 1, 0, 2, 0, 3, 0, 4, 0, 5], [5, 0, 4, 0, 3, 0, 2, 0, 1, 0]]) == 5\n assert candidate(grid = [[3, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 5, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 6]]) == 6\n assert candidate(grid = [[1, 0, 2, 0, 3, 0, 4, 0, 5, 0], [0, 6, 0, 7, 0, 8, 0, 9, 0, 10], [1, 0, 2, 0, 3, 0, 4, 0, 5, 0], [0, 6, 0, 7, 0, 8, 0, 9, 0, 10], [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]]) == 10\n assert candidate(grid = [[1, 0, 2, 0, 3, 0, 4, 0, 5, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5, 0, 4, 0, 3, 0, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [9, 0, 8, 0, 7, 0, 6, 0, 5, 0]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 26\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 2, 3, 0], [0, 4, 0, 5, 0], [0, 6, 7, 0, 8], [0, 0, 0, 0, 0], [0, 9, 0, 10, 0], [0, 0, 0, 0, 0]]) == 28\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 5, 3, 1, 0, 0], [0, 2, 0, 0, 4, 0], [0, 0, 6, 0, 0, 0], [0, 0, 0, 7, 0, 0]]) == 11\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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 275\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[3, 3, 0, 0, 3, 3], [3, 0, 3, 3, 0, 3], [0, 3, 0, 0, 3, 0], [3, 0, 3, 3, 0, 3], [3, 3, 0, 0, 3, 3], [0, 0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[2, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 0, 5, 0], [0, 0, 0, 0, 0, 0, 6]]) == 6\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0], [0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 7]]) == 7\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 19\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 55\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 2, 1, 0], [0, 2, 0, 2, 0], [0, 1, 2, 1, 0], [0, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[5, 0, 0, 0, 0], [0, 4, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 2, 0], [0, 0, 0, 0, 1]]) == 5\n assert candidate(grid = [[0, 1, 2, 0, 1], [0, 0, 0, 0, 0], [2, 1, 0, 1, 2], [0, 0, 0, 0, 0], [1, 2, 0, 2, 1]]) == 3\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 5, 3, 0, 0], [0, 2, 0, 1, 0], [0, 0, 6, 0, 0], [0, 0, 0, 0, 0]]) == 10\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 0], [0, 0, 3, 0, 0, 0], [0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 2, 0], [0, 3, 4, 0], [0, 0, 5, 0], [0, 6, 0, 0]]) == 15\n assert candidate(grid = [[3, 0, 0, 4, 0, 0, 5], [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], [6, 0, 0, 7, 0, 0, 8]]) == 8\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 0, 0], [0, 0, 4, 0, 5, 0, 0], [0, 0, 0, 6, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 15\n assert candidate(grid = [[8, 0, 0, 0, 7], [0, 6, 0, 5, 0], [0, 0, 4, 0, 0], [0, 3, 0, 2, 0], [1, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]]) == 125\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 0], [0, 6, 7, 8, 9, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 45\n assert candidate(grid = [[7, 0, 8, 0, 9, 0, 10], [0, 0, 0, 0, 0, 0, 0], [6, 0, 7, 0, 8, 0, 9], [0, 0, 0, 0, 0, 0, 0], [5, 0, 6, 0, 7, 0, 8], [0, 0, 0, 0, 0, 0, 0], [4, 0, 5, 0, 6, 0, 7]]) == 10\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 2, 3, 0], [0, 4, 5, 6, 0], [0, 7, 8, 9, 0], [0, 0, 0, 0, 0]]) == 45\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 9, 0, 0], [0, 9, 0, 9, 0], [0, 0, 9, 0, 0], [0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]) == 1\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 7, 1], [3, 4, 5, 6, 7, 1, 2], [4, 5, 6, 7, 1, 2, 3], [5, 6, 7, 1, 2, 3, 4], [6, 7, 1, 2, 3, 4, 5], [7, 1, 2, 3, 4, 5, 6]]) == 196\n assert candidate(grid = [[0, 1, 0, 2, 0, 3], [1, 0, 2, 0, 3, 0], [0, 2, 0, 3, 0, 4], [2, 0, 3, 0, 4, 0], [0, 3, 0, 4, 0, 5], [3, 0, 4, 0, 5, 0]]) == 5\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 45\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 0], [0, 0, 4, 5, 6, 0], [0, 0, 7, 8, 9, 0], [0, 0, 0, 0, 0, 0]]) == 45\n assert candidate(grid = [[1, 2, 3, 4, 5], [0, 0, 0, 0, 0], [5, 4, 3, 2, 1], [0, 0, 0, 0, 0], [1, 3, 5, 7, 9]]) == 25\n assert candidate(grid = [[9, 8, 7, 6, 5], [4, 3, 2, 1, 0], [0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) == 90\n assert candidate(grid = [[5, 5, 5, 5, 5, 5], [5, 0, 0, 0, 0, 5], [5, 0, 10, 10, 0, 5], [5, 0, 10, 10, 0, 5], [5, 0, 0, 0, 0, 5], [5, 5, 5, 5, 5, 5]]) == 100\n assert candidate(grid = [[0, 9, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 3, 2, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]) == 6\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 2, 3, 0], [0, 4, 0, 5, 0], [0, 6, 7, 0, 8], [0, 0, 0, 0, 0]]) == 28\n assert candidate(grid = [[8, 0, 0, 0, 9], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [9, 0, 0, 0, 8]]) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]]) == 84\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, 10]]) == 10\n assert candidate(grid = [[5, 0, 0, 0, 0, 0, 3], [0, 0, 4, 0, 5, 0, 0], [0, 6, 0, 0, 0, 7, 0], [8, 0, 0, 9, 0, 0, 10]]) == 10\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 2, 0, 2, 0], [1, 0, 1, 0, 1], [0, 2, 0, 2, 0], [1, 0, 1, 0, 1]]) == 2\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 2, 3, 2, 0, 0], [0, 3, 4, 3, 0, 0], [0, 2, 3, 2, 0, 0], [0, 0, 0, 0, 0, 0]]) == 24\n assert candidate(grid = [[5, 5, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 5]]) == 10\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, 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\n assert candidate(grid = [[1, 2, 3, 4, 5], [0, 1, 2, 3, 4], [5, 4, 3, 2, 1], [4, 3, 2, 1, 0], [3, 2, 1, 0, 9]]) == 56\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 4, 5, 6, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 21\n assert candidate(grid = [[0, 1, 0, 2, 0, 3], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 2], [0, 3, 0, 4, 0, 1], [0, 0, 0, 0, 0, 0], [2, 0, 3, 0, 1, 0]]) == 4\n assert candidate(grid = [[0, 0, 10, 0, 0], [0, 5, 0, 6, 0], [10, 0, 0, 0, 10], [0, 6, 0, 5, 0], [0, 0, 10, 0, 0]]) == 10\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 9, 0, 0, 0, 0], [0, 0, 8, 0, 0, 0], [0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 5]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 2, 1], [0, 2, 3, 4, 3, 2], [0, 1, 2, 3, 2, 1], [0, 0, 0, 0, 0, 0]]) == 32\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 0], [0, 2, 3, 4, 5, 6, 0], [0, 3, 4, 5, 6, 7, 0], [0, 4, 5, 6, 7, 8, 0], [0, 5, 6, 7, 8, 9, 0], [0, 0, 0, 0, 0, 0, 0]]) == 125\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 2, 3, 4, 5]]) == 15\n assert candidate(grid = [[3, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 2]]) == 3\n assert candidate(grid = [[1, 2, 3, 4, 5], [0, 0, 0, 0, 0], [5, 4, 3, 2, 1], [0, 0, 0, 0, 0], [1, 2, 3, 4, 5]]) == 15\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\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [1, 1, 1], [1, 1, 1], [0, 0, 0], [0, 0, 0]]) == 6\n", "comparison": "exact"}, "public_tests": ["[[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]", "[[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]"], "hints": ["Run DFS from each non-zero cell.", "Each time you pick a cell to start from, add up the number of fish contained in the cells you visit."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().findMaxFish", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:59:58+00:00", "tests_total": 105, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "depth-first-search", "breadth-first-search", "union-find", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def find_max_fish(grid)", "container": null, "callable": "find_max_fish", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2659, "task_id": "make-array-empty", "difficulty": "Hard", "problem_description": "You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:\n\n- If the first element has the smallest value, remove it\n- Otherwise, put the first element at the end of the array.\n\nReturn an integer denoting the number of operations it takes to make nums empty.\n\nExample 1:\n\nInput: nums = [3,4,-1]\nOutput: 5\n\nOperation | Array\n1 | [4, -1, 3]\n2 | [-1, 3, 4]\n3 | [3, 4]\n4 | [4]\n5 | []\n\nExample 2:\n\nInput: nums = [1,2,4,3]\nOutput: 5\n\nOperation | Array\n1 | [2, 4, 3]\n2 | [4, 3]\n3 | [3, 4]\n4 | [4]\n5 | []\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 3\n\nOperation | Array\n1 | [2, 3]\n2 | [3]\n3 | []\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^9<= nums[i] <= 10^9\n- All values in nums are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 55\n assert candidate(nums = [-3, -1, -2, -4]) == 8\n assert candidate(nums = [10, 20, -10, 0]) == 6\n assert candidate(nums = [0, 10, -10, 5, -5]) == 9\n assert candidate(nums = [-3, -1, 0, 2, 4]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 3, 2]) == 4\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 28\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 15\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [-3, -2, -1]) == 3\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3]) == 22\n assert candidate(nums = [0, 1, -1, 2, -2]) == 12\n assert candidate(nums = [5, 1, 3, 2, 4]) == 9\n assert candidate(nums = [1, 3, 2]) == 4\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000]) == 7\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 55\n assert candidate(nums = [-3, -1, 0, 2, 5]) == 5\n assert candidate(nums = [5, 1, 2, 4, 3]) == 8\n assert candidate(nums = [100, 200, 300, 400, 500]) == 5\n assert candidate(nums = [1, 2, 4, 3]) == 5\n assert candidate(nums = [5, 2, 6, 1, 4]) == 11\n assert candidate(nums = [1, 2, 3]) == 3\n assert candidate(nums = [3, 4, -1]) == 5\n assert candidate(nums = [-100, -200, -300, -400, -500]) == 15\n assert candidate(nums = [5, 3, 1, 2, 4]) == 9\n assert candidate(nums = [-5, -1, -3, -2, -4]) == 9\n assert candidate(nums = [50, 40, 30, 20, 10]) == 15\n assert candidate(nums = [100, 50, 25, 125, 200]) == 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]) == 20\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16]) == 57\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 50, 150, 250, 350, 450, 650, 750, 850, 950, 550]) == 120\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 10\n assert candidate(nums = [0, 2, 1, 4, 3, 6, 5, 8, 7, 9]) == 30\n assert candidate(nums = [50, 40, 30, 20, 10, 0, -10, -20, -30, -40]) == 55\n assert candidate(nums = [1, -10, 10, -20, 20, -30, 30, -40, 40, -50, 50]) == 51\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 6, 4, 0]) == 35\n assert candidate(nums = [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9]) == 31\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 210\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5]) == 45\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 50\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 15\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997]) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [10, 20, 5, 15, 25, 30]) == 14\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4]) == 26\n assert candidate(nums = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50]) == 55\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1]) == 26\n assert candidate(nums = [-100, -200, -300, -50, -25, -125, -62, -31, -156, -78, -39]) == 48\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]) == 465\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 1]) == 19\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]) == 41\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20]) == 165\n assert candidate(nums = [8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 3, 6, 12, 24, 48, 96]) == 132\n assert candidate(nums = [-1, -10, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000]) == 55\n assert candidate(nums = [9, 7, 5, 3, 1, 8, 6, 4, 2, 0, 11, 13, 15, 17, 19, 12, 14, 16, 18, 20]) == 115\n assert candidate(nums = [1, 11, 2, 12, 3, 13, 4, 14, 5, 15]) == 15\n assert candidate(nums = [10, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == 35\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1]) == 19\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 55\n assert candidate(nums = [20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10]) == 75\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 30\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 55\n assert candidate(nums = [-10, 100, -20, 200, -30, 300, -40, 400, -50, 500]) == 40\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 55\n assert candidate(nums = [5, 3, 1, 4, 2, 6, 8, 7]) == 19\n assert candidate(nums = [-9, -7, -5, -3, -1, 1, 3, 5, 7, 9]) == 10\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 250000000, -250000000]) == 12\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]) == 55\n assert candidate(nums = [5, 3, 1, 4, 2]) == 9\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 55\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 22\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]) == 30\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 6, 4, 10]) == 30\n assert candidate(nums = [10, 5, 20, 15, 30, 25, 40, 35, 50, 45]) == 35\n assert candidate(nums = [-50, -40, -30, -20, -10, 0, 10, 20, 30, 40]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 165\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 10\n assert candidate(nums = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10]) == 10\n assert candidate(nums = [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]) == 25\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 30\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 144\n assert candidate(nums = [7, 10, 4, 3, 20, 15]) == 16\n assert candidate(nums = [100, 50, 25, 125, 62, 31, 156, 78, 39]) == 18\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 20\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 35, 50, 45, 60, 55, 70, 65, 80, 75, 90, 85, 100, 95, 110]) == 110\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 101, 201, 301, 401, 501, 601, 701, 801, 901, 1001]) == 110\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 41\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995]) == 21\n assert candidate(nums = [3, 1, 2, 5, 4, 6, 8, 7, 9]) == 23\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 250000000]) == 8\n assert candidate(nums = [1, -1000000000, 2, -999999999, 3, -999999998, 4, -999999997]) == 12\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 98\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9]) == 190\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 20\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5]) == 15\n assert candidate(nums = [1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 55\n assert candidate(nums = [1, 10, 2, 20, 3, 30, 4, 40, 5, 50, 6, 60, 7, 70, 8, 80, 9, 90]) == 27\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 55\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, -10, 10]) == 165\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 45\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 1, -1]) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [-1, 1000000000, 1, -1000000000, 2, -999999999, 3, -999999998, 4, -999999997]) == 17\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6]) == 25\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 120\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5]) == 40\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, 10]) == 54\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 55\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 15\n assert candidate(nums = [1000000000, 500000000, -500000000, -1000000000]) == 10\n assert candidate(nums = [999999999, -999999999, 999999998, -999999998, 999999997, -999999997]) == 12\n assert candidate(nums = [5, 1, 4, 2, 3]) == 8\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3]) == 7\n assert candidate(nums = [5, 2, 3, 1, 4]) == 10\n assert candidate(nums = [5, 2, 6, 1, 3, 4]) == 13\n assert candidate(nums = [1000000000, -1000000000, 0]) == 4\n assert candidate(nums = [1, 2, 4, 3]) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 55\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 0]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50]) == 5\n assert candidate(nums = [-1, -2, -3, -4]) == 10\n assert candidate(nums = [1, 3, 5, 2, 4, 6]) == 12\n assert candidate(nums = [1000000000, -1000000000, 500000000, 0, 250000000]) == 8\n assert candidate(nums = [1, 3, 2, 5, 4]) == 9\n assert candidate(nums = [-10, 100, 50, 20, -20]) == 12\n assert candidate(nums = [-10, 10, 0, 5, 3]) == 8\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 18\n assert candidate(nums = [100, -100, 50, -50, 25, -25]) == 12\n assert candidate(nums = [1, 1000000000, -1000000000]) == 5\n assert candidate(nums = [10, 20, 30, 5, 15, 25]) == 15\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 55\n assert candidate(nums = [5, 1, 2, 3, 4]) == 6\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3]) == 7\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 10\n assert candidate(nums = [50, 40, 30, 20, 10]) == 15\n assert candidate(nums = [5, 3, 8, 6, 2]) == 13\n assert candidate(nums = [5, 1, 4, 2, 3]) == 8\n assert candidate(nums = [1, -2, 3, -4, 5]) == 12\n assert candidate(nums = [5]) == 1\n assert candidate(nums = [5, 2, 4, 1, 3]) == 12\n assert candidate(nums = [1000000000, -1000000000, 500000000]) == 4\n assert candidate(nums = [-10, -20, -30, -5, -15, -25]) == 12\n assert candidate(nums = [0, 1, -1, 2, -2]) == 12\n assert candidate(nums = [-5, 1, 2, 0, 3]) == 8\n assert candidate(nums = [10, 5, 3, 8, 2]) == 13\n assert candidate(nums = [-10, 100, 5, 2, 0]) == 11\n assert candidate(nums = [-10, 100, 0, 5]) == 5\n assert candidate(nums = [1000000000, -1000000000]) == 3\n assert candidate(nums = [-3, -1, -2]) == 4\n assert candidate(nums = [10, -10, 20, -20, 30, -30]) == 18\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [7, 3, 5, 2, 4, 6, 1]) == 22\n assert candidate(nums = [5, 3, 8, 1, 4]) == 11\n assert candidate(nums = [-5, 1, 2, 0]) == 6\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997]) == 10\n assert candidate(nums = [5, 4, 3, 2, 1]) == 15\n assert candidate(nums = [5, 3, 1, 2, 4]) == 9\n assert candidate(nums = [-5, 10, 0, 7, -3]) == 9\n assert candidate(nums = [-3, -1, -4, -2]) == 8\n assert candidate(nums = [10, -10, 0]) == 4\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 10\n assert candidate(nums = [0]) == 1\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 51\n assert candidate(nums = [3, 4, -1]) == 5\n assert candidate(nums = [-10, 100, 0, 5, 3]) == 8\n assert candidate(nums = [-5, 1, 2, 0, -1]) == 10\n assert candidate(nums = [-5, -3, -1, -2, -4]) == 9\n assert candidate(nums = [10, -5, 3, 8, 2]) == 9\n assert candidate(nums = [0, -1, 1]) == 5\n assert candidate(nums = [5, 3, 2, 1, 4]) == 13\n assert candidate(nums = [-5, -3, -1, -4, -2]) == 9\n assert candidate(nums = [0, -1, 1, -2, 2]) == 12\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 28\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 10\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, -1, -2]) == 55\n assert candidate(nums = [1000000000, -1000000000, 500000000]) == 4\n assert candidate(nums = [-5, -1, -4, -2, -3]) == 8\n assert candidate(nums = [-10, -20, -30, -40, -50]) == 15\n assert candidate(nums = [1, 2, 3]) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 55\n assert candidate(nums = [-5, -3, -1, 2, 4]) == 5\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 18\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [7, 3, 5, 1, 9, 2, 4, 6, 8]) == 25\n assert candidate(nums = [-10, -20, -30, -40, -50]) == 15\n assert candidate(nums = [-5, -3, -1, 1, 3, 5]) == 6\n assert candidate(nums = [5, 1, 9, 3, 7]) == 9\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [9, 7, 5, 3, 1]) == 15\n assert candidate(nums = [42]) == 1\n assert candidate(nums = [-5, -3, -2, -4, -1]) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) == 35\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3]) == 22\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7]) == 120\n assert candidate(nums = [-5, 3, -2, 1, 4]) == 7\n assert candidate(nums = [1, 2]) == 2\n assert candidate(nums = [7, 5, 6, 3, 4, 1, 2]) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 30\n assert candidate(nums = [-10, 100, 0, 5, -5]) == 9\n assert candidate(nums = [5, 4, 3, 2, 1]) == 15\n", "comparison": "exact"}, "public_tests": ["[3,4,-1]", "[1,2,4,3]", "[1,2,3]"], "hints": ["Understand the order in which the indices are removed from the array.", "We don’t really need to delete or move the elements, only the array length matters.", "Upon removing an index, decide how many steps it takes to move to the next one.", "Use a data structure to speed up the calculation."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countOperationsToEmptyArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:00+00:00", "tests_total": 216, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "binary-indexed-tree", "segment-tree", "sorting", "ordered-set"]}, "language": "ruby", "interface": {"raw_signature": "def count_operations_to_empty_array(nums)", "container": null, "callable": "count_operations_to_empty_array", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2660, "task_id": "determine-the-winner-of-a-bowling-game", "difficulty": "Easy", "problem_description": "You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.\n\nThe bowling game consists of n turns, and the number of pins in each turn is exactly 10.\n\nAssume a player hits x_i pins in the i^th turn. The value of the i^th turn for the player is:\n\n- 2x_i if the player hits 10 pins in either (i - 1)^th or (i - 2)^th turn.\n- Otherwise, it is x_i.\n\nThe score of the player is the sum of the values of their n turns.\n\nReturn\n\n- 1 if the score of player 1 is more than the score of player 2,\n- 2 if the score of player 2 is more than the score of player 1, and\n- 0 in case of a draw.\n\nExample 1:\n\nInput: player1 = [5,10,3,2], player2 = [6,5,7,3]\nOutput: 1\nExplanation:\nThe score of player 1 is 5 + 10 + 2*3 + 2*2 = 25.\nThe score of player 2 is 6 + 5 + 7 + 3 = 21.\n\nExample 2:\n\nInput: player1 = [3,5,7,6], player2 = [8,10,10,2]\nOutput: 2\nExplanation:\nThe score of player 1 is 3 + 5 + 7 + 6 = 21.\nThe score of player 2 is 8 + 10 + 2*10 + 2*2 = 42.\n\nExample 3:\n\nInput: player1 = [2,3], player2 = [4,1]\nOutput: 0\nExplanation:\nThe score of player1 is 2 + 3 = 5.\nThe score of player2 is 4 + 1 = 5.\n\nExample 4:\n\nInput: player1 = [1,1,1,10,10,10,10], player2 = [10,10,10,10,1,1,1]\nOutput: 2\nExplanation:\nThe score of player1 is 1 + 1 + 1 + 10 + 2*10 + 2*10 + 2*10 = 73.\nThe score of player2 is 10 + 2*10 + 2*10 + 2*10 + 2*1 + 2*1 + 1 = 75.\n\nConstraints:\n\n- n == player1.length == player2.length\n- 1 <= n <= 1000\n- 0 <= player1[i], player2[i] <= 10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(player1 = [5, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [2, 3],player2 = [4, 1]) == 0\n assert candidate(player1 = [5, 10, 3, 2],player2 = [6, 5, 7, 3]) == 1\n assert candidate(player1 = [5, 5, 5, 5],player2 = [10, 0, 10, 0]) == 2\n assert candidate(player1 = [10, 10, 10],player2 = [10, 10, 10]) == 0\n assert candidate(player1 = [3, 5, 7, 6],player2 = [8, 10, 10, 2]) == 2\n assert candidate(player1 = [0, 0, 0, 0],player2 = [0, 0, 0, 0]) == 0\n assert candidate(player1 = [1, 1, 1, 10, 10, 10, 10],player2 = [10, 10, 10, 10, 1, 1, 1]) == 2\n assert candidate(player1 = [10, 10, 10, 10],player2 = [10, 10, 10, 10]) == 0\n assert candidate(player1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],player2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(player1 = [10, 0, 10, 0, 10],player2 = [0, 10, 0, 10, 0]) == 1\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10],player2 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == 0\n assert candidate(player1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],player2 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(player1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 10],player2 = [10, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(player1 = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5],player2 = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10]) == 1\n assert candidate(player1 = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],player2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 1]) == 1\n assert candidate(player1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],player2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(player1 = [3, 6, 9, 10, 3, 6, 9, 10, 3, 6, 9, 10],player2 = [10, 3, 6, 9, 10, 3, 6, 9, 10, 3, 6, 9]) == 2\n assert candidate(player1 = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],player2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5]) == 2\n assert candidate(player1 = [1, 2, 3, 4, 5, 10, 6, 7, 8, 9],player2 = [9, 8, 7, 6, 10, 5, 4, 3, 2, 1]) == 1\n assert candidate(player1 = [0, 10, 5, 10, 3, 0, 10, 2],player2 = [10, 0, 10, 5, 10, 3, 0, 10]) == 2\n assert candidate(player1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],player2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(player1 = [0, 0, 10, 0, 0, 0, 0, 0, 0, 0],player2 = [0, 0, 0, 0, 10, 0, 0, 0, 0, 0]) == 0\n assert candidate(player1 = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5],player2 = [0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == 1\n assert candidate(player1 = [5, 5, 5, 5, 10, 5, 5, 5, 5, 10],player2 = [10, 5, 5, 5, 5, 10, 5, 5, 5, 5]) == 2\n assert candidate(player1 = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],player2 = [7, 7, 7, 7, 10, 7, 7, 7, 7, 7]) == 2\n assert candidate(player1 = [9, 10, 10, 9, 10, 9, 10],player2 = [10, 9, 10, 9, 10, 9, 9]) == 2\n assert candidate(player1 = [1, 10, 2, 10, 3, 10, 4, 10],player2 = [10, 1, 10, 2, 10, 3, 10, 4]) == 2\n assert candidate(player1 = [10, 10, 10, 0, 0, 0, 0, 0, 0, 0],player2 = [0, 0, 0, 0, 0, 0, 10, 10, 10, 0]) == 0\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10]) == 2\n assert candidate(player1 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],player2 = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10]) == 0\n assert candidate(player1 = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10],player2 = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 2\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == 2\n assert candidate(player1 = [0, 0, 10, 0, 0, 10, 0, 0],player2 = [1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(player1 = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10],player2 = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 2\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],player2 = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 0\n assert candidate(player1 = [7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],player2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 7]) == 2\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 2\n assert candidate(player1 = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0],player2 = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(player1 = [7, 8, 9, 10, 8, 7, 6, 5, 4, 3, 2, 1],player2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 7]) == 0\n assert candidate(player1 = [3, 6, 9, 2, 5, 8, 1, 4, 7, 10],player2 = [10, 7, 4, 1, 8, 5, 2, 9, 6, 3]) == 2\n assert candidate(player1 = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0],player2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]) == 0\n assert candidate(player1 = [0, 0, 0, 0, 10, 0, 0, 0],player2 = [0, 0, 0, 0, 0, 10, 0, 0]) == 0\n assert candidate(player1 = [10, 0, 0, 10, 0, 0, 10, 0, 0, 10],player2 = [0, 0, 10, 0, 0, 10, 0, 0, 10, 0]) == 1\n assert candidate(player1 = [10, 10, 0, 10, 10, 0, 10, 10, 0, 10, 10, 0, 10, 10, 0],player2 = [0, 10, 10, 0, 10, 10, 0, 10, 10, 0, 10, 10, 0, 10, 10]) == 0\n assert candidate(player1 = [0, 10, 0, 0, 10, 0, 0, 10, 0, 0],player2 = [0, 0, 10, 0, 0, 10, 0, 0, 10, 0]) == 0\n assert candidate(player1 = [5, 6, 7, 8, 9, 10],player2 = [10, 9, 8, 7, 6, 5]) == 2\n assert candidate(player1 = [5, 0, 10, 5, 2, 3],player2 = [3, 0, 0, 10, 10, 1]) == 2\n assert candidate(player1 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],player2 = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10]) == 0\n assert candidate(player1 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10],player2 = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == 1\n assert candidate(player1 = [5, 10, 5, 10, 5, 10, 5, 10],player2 = [10, 5, 10, 5, 10, 5, 10, 5]) == 2\n assert candidate(player1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],player2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(player1 = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0],player2 = [0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5]) == 0\n assert candidate(player1 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0],player2 = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10]) == 0\n assert candidate(player1 = [5, 5, 5, 5, 5, 10, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5, 5, 5, 10, 5, 5]) == 0\n assert candidate(player1 = [0, 10, 0, 10, 0, 10, 0, 10],player2 = [10, 0, 10, 0, 10, 0, 10, 0]) == 0\n assert candidate(player1 = [3, 6, 9, 10, 2, 5, 8, 10, 4, 7],player2 = [7, 4, 8, 10, 5, 2, 10, 9, 6, 3]) == 2\n assert candidate(player1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],player2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) == 1\n assert candidate(player1 = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0],player2 = [0, 5, 0, 5, 0, 5, 0, 5, 0, 5]) == 0\n assert candidate(player1 = [10, 10, 0, 10, 0, 10, 0, 10, 0, 10],player2 = [0, 10, 10, 0, 10, 10, 0, 10, 10, 0]) == 0\n assert candidate(player1 = [0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0],player2 = [10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0]) == 2\n assert candidate(player1 = [5, 5, 10, 5, 5],player2 = [10, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],player2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == 1\n assert candidate(player1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],player2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(player1 = [5, 0, 10, 3, 6, 10, 2],player2 = [10, 5, 0, 7, 3, 0, 10]) == 1\n assert candidate(player1 = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],player2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 1\n assert candidate(player1 = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10],player2 = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == 0\n assert candidate(player1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],player2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(player1 = [10, 0, 10, 0, 10, 0, 10],player2 = [0, 10, 0, 10, 0, 10, 0]) == 1\n assert candidate(player1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],player2 = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 2\n assert candidate(player1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],player2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(player1 = [10, 5, 5, 10, 2, 3, 4],player2 = [5, 10, 10, 5, 6, 7, 8]) == 2\n assert candidate(player1 = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10],player2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]) == 1\n assert candidate(player1 = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0],player2 = [10, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1, 0]) == 2\n assert candidate(player1 = [0, 10, 0, 0, 0, 10, 0, 0, 0, 10],player2 = [10, 0, 0, 0, 10, 0, 0, 0, 10, 0]) == 0\n assert candidate(player1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],player2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(player1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],player2 = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == 2\n assert candidate(player1 = [5, 0, 10, 3, 2, 10, 4],player2 = [6, 5, 7, 3, 10, 1, 10]) == 2\n assert candidate(player1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],player2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 2\n assert candidate(player1 = [3, 6, 9, 10, 3, 6, 9, 10, 3, 6],player2 = [6, 3, 9, 10, 6, 3, 9, 10, 6, 3]) == 0\n assert candidate(player1 = [0, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10],player2 = [10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0]) == 0\n assert candidate(player1 = [10, 10, 0, 0, 0, 0, 0, 0, 0, 10],player2 = [0, 0, 0, 0, 0, 0, 0, 0, 10, 10]) == 1\n assert candidate(player1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],player2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(player1 = [10, 0, 0, 10, 0, 0, 10, 0, 0, 10],player2 = [0, 10, 0, 0, 10, 0, 0, 10, 0, 0]) == 1\n assert candidate(player1 = [5, 6, 7, 8, 9, 10, 3, 2],player2 = [4, 7, 6, 5, 8, 9, 4, 1]) == 1\n assert candidate(player1 = [1, 1, 1, 10, 1, 1, 1, 10, 1, 1],player2 = [1, 1, 1, 1, 10, 1, 1, 1, 10, 1]) == 1\n assert candidate(player1 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],player2 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(player1 = [0, 10, 5, 0, 10, 8, 3],player2 = [10, 0, 10, 5, 0, 10, 2]) == 2\n assert candidate(player1 = [3, 3, 3, 10, 10, 3, 3],player2 = [10, 3, 3, 3, 3, 10, 3]) == 1\n", "comparison": "exact"}, "public_tests": ["[5,10,3,2]\n[6,5,7,3]", "[3,5,7,6]\n[8,10,10,2]", "[2,3]\n[4,1]", "[1,1,1,10,10,10,10]\n[10,10,10,10,1,1,1]"], "hints": ["Think about simulating the process to calculate the answer.", "Iterate over each element and check the previous two elements. See if one of them is 10 and can affect the score."], "metadata": {"canonical_parameter_names": ["player1", "player2"], "leetcode_dataset_entry_point": "Solution().isWinner", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:03+00:00", "tests_total": 93, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def is_winner(player1, player2)", "container": null, "callable": "is_winner", "parameters": [{"name": "player1", "type": "Integer[]"}, {"name": "player2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2661, "task_id": "first-completely-painted-row-or-column", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].\n\nGo through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].\n\nReturn the smallest index i at which either a row or a column will be completely painted in mat.\n\nExample 1:\n\nInput: arr = [1,3,4,2], mat = [[1,4],[2,3]]\nOutput: 2\nExplanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].\n\nExample 2:\n\nInput: arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]]\nOutput: 3\nExplanation: The second column becomes fully painted at arr[3].\n\nConstraints:\n\n- m == mat.length\n- n = mat[i].length\n- arr.length == m * n\n- 1 <= m, n <= 10^5\n- 1 <= m * n <= 10^5\n- 1 <= arr[i], mat[r][c] <= m * n\n- All the integers of arr are unique.\n- All the integers of mat are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = [15, 13, 14, 12, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 1],mat = [[13, 14, 15], [10, 11, 12], [7, 8, 9], [4, 5, 6], [1, 2, 3]]) == 2\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) == 3\n assert candidate(arr = [6, 5, 4, 3, 2, 1],mat = [[1, 2], [3, 4], [5, 6]]) == 1\n assert candidate(arr = [5, 1, 9, 11, 2, 6, 3, 10, 7, 4, 8, 12],mat = [[5, 1, 9, 11], [2, 6, 3, 10], [7, 4, 8, 12]]) == 3\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],mat = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 2\n assert candidate(arr = [5, 1, 9, 3, 2, 6, 8, 7, 4],mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 4\n assert candidate(arr = [2, 8, 7, 4, 1, 3, 5, 6, 9],mat = [[3, 2, 5], [1, 4, 6], [8, 7, 9]]) == 3\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 0, 0]]) == 3\n assert candidate(arr = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) == 3\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 0, 0]]) == 3\n assert candidate(arr = [1, 3, 4, 2],mat = [[1, 4], [2, 3]]) == 2\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1],mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 2\n assert candidate(arr = [15, 13, 14, 12, 10, 11, 8, 9, 7, 5, 6, 3, 4, 2, 1],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]) == 5\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],mat = [[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]]) == 3\n assert candidate(arr = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9],mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 0, 0]]) == 4\n assert candidate(arr = [1, 11, 21, 31, 2, 12, 22, 32, 3, 13, 23, 33, 4, 14, 24, 34, 5, 15, 25, 35, 6, 16, 26, 36, 7, 17, 27, 37, 8, 18, 28, 38, 9, 19, 29, 39, 10, 20, 30, 40],mat = [[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]]) == 16\n assert candidate(arr = [3, 6, 9, 12, 15, 18, 21, 24, 27, 2, 5, 8, 11, 14, 17, 20, 23, 26, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 29, 30],mat = [[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]]) == 8\n assert candidate(arr = [49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48],mat = [[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]]) == 20\n assert candidate(arr = [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],mat = [[1, 5, 9, 13, 17], [2, 6, 10, 14, 18], [3, 7, 11, 15, 19], [4, 8, 12, 16, 20], [21, 22, 23, 24, 25]]) == 16\n assert candidate(arr = [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],mat = [[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]]) == 4\n assert candidate(arr = [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],mat = [[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]]) == 4\n assert candidate(arr = [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],mat = [[21, 22, 23, 24, 25], [16, 17, 18, 19, 20], [11, 12, 13, 14, 15], [6, 7, 8, 9, 10], [1, 2, 3, 4, 5]]) == 4\n assert candidate(arr = [5, 10, 15, 20, 25, 4, 9, 14, 19, 24, 3, 8, 13, 18, 23, 2, 7, 12, 17, 22, 1, 6, 11, 16, 21],mat = [[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]]) == 4\n assert candidate(arr = [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],mat = [[5, 4, 3, 2, 1], [10, 9, 8, 7, 6], [15, 14, 13, 12, 11], [20, 19, 18, 17, 16], [25, 24, 23, 22, 21]]) == 4\n assert candidate(arr = [1, 16, 2, 17, 3, 18, 4, 19, 5, 20, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 8\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 4\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 4\n assert candidate(arr = [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],mat = [[1, 5, 9, 13, 17], [2, 6, 10, 14, 18], [3, 7, 11, 15, 19], [4, 8, 12, 16, 20], [21, 22, 23, 24, 25]]) == 4\n assert candidate(arr = [25, 1, 24, 2, 23, 3, 22, 4, 21, 5, 20, 6, 19, 7, 18, 8, 17, 9, 16, 10, 15, 11, 14, 12, 13],mat = [[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]]) == 8\n assert candidate(arr = [5, 10, 15, 20, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24, 25],mat = [[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]]) == 7\n assert candidate(arr = [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],mat = [[1, 6, 11, 16, 21], [2, 7, 12, 17, 22], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24], [5, 10, 15, 20, 25]]) == 4\n assert candidate(arr = [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],mat = [[1, 2, 3, 4, 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]]) == 4\n assert candidate(arr = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91, 11, 90, 12, 89, 13, 88, 14, 87, 15, 86, 16, 85, 17, 84, 18, 83, 19, 82, 20, 81, 21, 80, 22, 79, 23, 78, 24, 77, 25, 76, 26, 75, 27, 74, 28, 73, 29, 72, 30, 71, 31, 70, 32, 69, 33, 68, 34, 67, 35, 66, 36, 65, 37, 64, 38, 63, 39, 62, 40, 61, 41, 60, 42, 59, 43, 58, 44, 57, 45, 56, 46, 55, 47, 54, 48, 53, 49, 52, 50, 51],mat = [[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], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 100]]) == 18\n assert candidate(arr = [6, 2, 8, 4, 10, 1, 3, 5, 7, 9],mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == 6\n assert candidate(arr = [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],mat = [[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]]) == 4\n assert candidate(arr = [1, 5, 9, 13, 17, 2, 6, 10, 14, 18, 3, 7, 11, 15, 19, 4, 8, 12, 16, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 15\n assert candidate(arr = [1, 17, 33, 49, 5, 21, 37, 53, 3, 19, 35, 51, 9, 25, 41, 57, 7, 23, 39, 55, 11, 27, 43, 59, 13, 29, 45, 61, 15, 31, 47, 63, 2, 18, 34, 50, 6, 22, 38, 54, 4, 20, 36, 52, 8, 24, 40, 56, 10, 26, 42, 58, 12, 28, 44, 60, 14, 30, 46, 62, 16, 32, 48, 64],mat = [[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, 61, 62, 63, 64]]) == 15\n assert candidate(arr = [1, 7, 13, 19, 25, 2, 8, 14, 20, 21, 3, 9, 15, 22, 4, 10, 16, 23, 5, 11, 17, 24, 6, 12, 18],mat = [[1, 6, 11, 16, 21], [2, 7, 12, 17, 22], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24], [5, 10, 15, 20, 25]]) == 18\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 4\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 11\n assert candidate(arr = [30, 28, 27, 29, 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],mat = [[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(arr = [96, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95],mat = [[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], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 100]]) == 10\n assert candidate(arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 12, 14, 16, 18, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 6\n assert candidate(arr = [5, 25, 13, 1, 29, 3, 17, 19, 7, 21, 11, 23, 9, 27, 15, 2, 26, 14, 28, 6, 20, 12, 24, 8, 30, 4, 18, 10, 22, 16],mat = [[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]]) == 8\n assert candidate(arr = [1, 6, 11, 16, 21, 2, 7, 12, 17, 22, 3, 8, 13, 18, 23, 4, 9, 14, 19, 24, 5, 10, 15, 20, 25],mat = [[1, 6, 11, 16, 21], [2, 7, 12, 17, 22], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24], [5, 10, 15, 20, 25]]) == 4\n assert candidate(arr = [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],mat = [[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]]) == 4\n assert candidate(arr = [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],mat = [[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]]) == 4\n assert candidate(arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 11, 13, 15, 17, 19, 12, 14, 16, 18, 20, 21, 23, 25, 22, 24],mat = [[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]]) == 6\n assert candidate(arr = [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],mat = [[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]]) == 5\n assert candidate(arr = [20, 18, 19, 17, 15, 16, 13, 14, 11, 12, 9, 10, 7, 8, 5, 6, 3, 4, 1, 2],mat = [[18, 19, 20], [15, 16, 17], [12, 13, 14], [9, 10, 11], [6, 7, 8], [3, 4, 5], [1, 2, 3]]) == 2\n assert candidate(arr = [25, 18, 19, 20, 21, 22, 23, 24, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],mat = [[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]]) == 7\n assert candidate(arr = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 5\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 11\n assert candidate(arr = [1, 5, 9, 13, 17, 2, 6, 10, 14, 18, 3, 7, 11, 15, 19, 4, 8, 12, 16, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 15\n assert candidate(arr = [30, 25, 20, 15, 10, 5, 29, 24, 19, 14, 9, 4, 28, 23, 18, 13, 8, 3, 27, 22, 17, 12, 7, 2, 26, 21, 16, 11, 6, 1],mat = [[5, 10, 15, 20, 25], [4, 9, 14, 19, 24], [3, 8, 13, 18, 23], [2, 7, 12, 17, 22], [1, 6, 11, 16, 30]]) == 5\n assert candidate(arr = [10, 20, 30, 40, 50, 11, 21, 31, 41, 51, 12, 22, 32, 42, 52, 13, 23, 33, 43, 53, 14, 24, 34, 44, 54, 15, 25, 35, 45, 55],mat = [[10, 11, 12, 13, 14, 15], [20, 21, 22, 23, 24, 25], [30, 31, 32, 33, 34, 35], [40, 41, 42, 43, 44, 45], [50, 51, 52, 53, 54, 55]]) == 4\n assert candidate(arr = [81, 66, 71, 76, 86, 91, 96, 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 62, 67, 72, 77, 82, 87, 92, 97, 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 63, 68, 73, 78, 83, 88, 93, 98, 3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 64, 69, 74, 79, 84, 89, 94, 99, 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 65, 70, 75, 80, 85, 90, 95, 100],mat = [[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], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 100]]) == 18\n assert candidate(arr = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 11\n assert candidate(arr = [1, 9, 17, 25, 2, 10, 18, 24, 3, 11, 19, 23, 4, 12, 20, 22, 5, 13, 16, 21, 6, 14, 15, 7, 8],mat = [[1, 6, 11, 16, 21], [2, 7, 12, 17, 22], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24], [5, 10, 15, 20, 25]]) == 16\n assert candidate(arr = [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],mat = [[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]]) == 3\n assert candidate(arr = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16, 25, 24, 23, 22, 21],mat = [[1, 6, 11, 16, 21], [2, 7, 12, 17, 22], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24], [5, 10, 15, 20, 25]]) == 4\n assert candidate(arr = [9, 18, 27, 36, 45, 1, 10, 19, 28, 37, 46, 2, 11, 20, 29, 38, 47, 3, 12, 21, 30, 39, 48, 4, 13, 22, 31, 40, 49, 5, 14, 23, 32, 41, 50, 6, 15, 24, 33, 42, 51, 7, 16, 25, 34, 43, 52, 8, 17, 26, 35, 44, 53],mat = [[9, 18, 27, 36, 45], [1, 10, 19, 28, 37], [2, 11, 20, 29, 38], [3, 12, 21, 30, 39], [4, 13, 22, 31, 40], [5, 14, 23, 32, 41], [6, 15, 24, 33, 42], [7, 16, 25, 34, 43], [8, 17, 26, 35, 44]]) == 4\n assert candidate(arr = [4, 8, 12, 16, 1, 2, 3, 5, 9, 13, 17, 21, 6, 10, 14, 18, 22, 7, 11, 15, 19, 23, 20, 24, 25],mat = [[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, 0, 0]]) == 6\n assert candidate(arr = [1, 13, 25, 37, 49, 61, 73, 85, 97, 2, 14, 26, 38, 50, 62, 74, 86, 98, 3, 15, 27, 39, 51, 63, 75, 87, 99, 4, 16, 28, 40, 52, 64, 76, 88, 100, 5, 17, 29, 41, 53, 65, 77, 89, 6, 18, 30, 42, 54, 66, 78, 90, 7, 19, 31, 43, 55, 67, 79, 91, 8, 20, 32, 44, 56, 68, 80, 92, 9, 21, 33, 45, 57, 69, 81, 93, 10, 22, 34, 46, 58, 70, 82, 94, 11, 23, 35, 47, 59, 71, 83, 95, 12, 24, 36, 48, 60, 72, 84, 96],mat = [[1, 13, 25, 37, 49], [61, 73, 85, 97, 2], [14, 26, 38, 50, 62], [74, 86, 98, 3, 15], [27, 39, 51, 63, 75], [87, 99, 4, 16, 28], [40, 52, 64, 76, 88], [90, 5, 17, 29, 41], [53, 65, 77, 89, 6], [18, 30, 42, 54, 66], [78, 90, 7, 19, 31], [43, 55, 67, 79, 91], [8, 20, 32, 44, 56], [68, 80, 92, 9, 21], [33, 45, 57, 69, 81], [93, 10, 22, 34, 46], [58, 70, 82, 94, 11], [23, 35, 47, 59, 71], [83, 95, 12, 24, 36], [48, 60, 72, 84, 96]]) == 4\n assert candidate(arr = [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],mat = [[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]]) == 4\n assert candidate(arr = [25, 1, 24, 2, 23, 3, 22, 4, 21, 5, 20, 6, 19, 7, 18, 8, 17, 9, 16, 10, 15, 11, 14, 12, 13],mat = [[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]]) == 8\n assert candidate(arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 11, 13, 15, 17, 19],mat = [[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]]) == 7\n assert candidate(arr = [1, 6, 11, 16, 2, 7, 12, 17, 3, 8, 13, 18, 4, 9, 14, 19, 5, 10, 15, 20],mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 3\n", "comparison": "exact"}, "public_tests": ["[1,3,4,2]\n[[1,4],[2,3]]", "[2,8,7,4,1,3,5,6,9]\n[[3,2,5],[1,4,6],[8,7,9]]"], "hints": ["Can we use a frequency array?", "Pre-process the positions of the values in the matrix.", "Traverse the array and increment the corresponding row and column frequency using the pre-processed positions.", "If the row frequency becomes equal to the number of columns, or vice-versa return the current index."], "metadata": {"canonical_parameter_names": ["arr", "mat"], "leetcode_dataset_entry_point": "Solution().firstCompleteIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:05+00:00", "tests_total": 71, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def first_complete_index(arr, mat)", "container": null, "callable": "first_complete_index", "parameters": [{"name": "arr", "type": "Integer[]"}, {"name": "mat", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2662, "task_id": "minimum-cost-of-a-path-with-special-roads", "difficulty": "Medium", "problem_description": "You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY).\n\nThe cost of going from a position (x1, y1) to any other position in the space (x2, y2) is |x2 - x1| + |y2 - y1|.\n\nThere are also some special roads. You are given a 2D array specialRoads where specialRoads[i] = [x1_i, y1_i, x2_i, y2_i, cost_i] indicates that the i^th special road goes in one direction from (x1_i, y1_i) to (x2_i, y2_i) with a cost equal to cost_i. You can use each special road any number of times.\n\nReturn the minimum cost required to go from (startX, startY) to (targetX, targetY).\n\nExample 1:\n\nInput: start = [1,1], target = [4,5], specialRoads = [[1,2,3,3,2],[3,4,4,5,1]]\nOutput: 5\nExplanation:\n1. (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.\n2. (1,2) to (3,3). Use specialRoads[0] with the cost 2.\n3. (3,3) to (3,4) with a cost of |3 - 3| + |4 - 3| = 1.\n4. (3,4) to (4,5). Use specialRoads[1] with the cost 1.\n\nSo the total cost is 1 + 2 + 1 + 1 = 5.\n\nExample 2:\n\nInput: start = [3,2], target = [5,7], specialRoads = [[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]]\nOutput: 7\nExplanation:\nIt is optimal not to use any special edges and go directly from the starting to the ending position with a cost |5 - 3| + |7 - 2| = 7.\nNote that the specialRoads[0] is directed from (5,7) to (3,2).\n\nExample 3:\n\nInput: start = [1,1], target = [10,4], specialRoads = [[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]]\nOutput: 8\nExplanation:\n1. (1,1) to (1,2) with a cost of |1 - 1| + |2 - 1| = 1.\n2. (1,2) to (7,4). Use specialRoads[1] with the cost 4.\n3. (7,4) to (10,4) with a cost of |10 - 7| + |4 - 4| = 3.\n\nConstraints:\n\n- start.length == target.length == 2\n- 1 <= startX <= targetX <= 10^5\n- 1 <= startY <= targetY <= 10^5\n- 1 <= specialRoads.length <= 200\n- specialRoads[i].length == 5\n- startX <= x1_i, x2_i <= targetX\n- startY <= y1_i, y2_i <= targetY\n- 1 <= cost_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(start = [3, 2],target = [5, 7],specialRoads = [[5, 7, 3, 2, 1], [3, 2, 3, 4, 4], [3, 3, 5, 5, 5], [3, 4, 5, 6, 6]]) == 7\n assert candidate(start = [1, 1],target = [4, 5],specialRoads = [[1, 2, 3, 3, 2], [3, 4, 4, 5, 1]]) == 5\n assert candidate(start = [1, 1],target = [10, 4],specialRoads = [[4, 2, 1, 1, 3], [1, 2, 7, 4, 4], [10, 3, 6, 1, 2], [6, 1, 1, 2, 3]]) == 8\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[10, 10, 20, 20, 10], [20, 20, 30, 30, 15], [30, 30, 40, 40, 20], [40, 40, 50, 50, 25], [50, 50, 60, 60, 30], [60, 60, 70, 70, 35], [70, 70, 80, 80, 40], [80, 80, 90, 90, 45], [90, 90, 100, 100, 50]]) == 183\n assert candidate(start = [1, 1],target = [200, 200],specialRoads = [[10, 10, 30, 30, 15], [30, 30, 50, 50, 20], [50, 50, 70, 70, 25], [70, 70, 90, 90, 30], [90, 90, 110, 110, 35], [110, 110, 130, 130, 40], [130, 130, 150, 150, 45], [150, 150, 170, 170, 50], [170, 170, 190, 190, 55], [190, 190, 200, 200, 60], [10, 50, 30, 70, 20], [30, 70, 50, 90, 25], [50, 90, 70, 110, 30], [70, 110, 90, 130, 35], [90, 130, 110, 150, 40], [110, 150, 130, 170, 45], [130, 170, 150, 190, 50], [150, 190, 170, 200, 55]]) == 323\n assert candidate(start = [1, 1],target = [20, 20],specialRoads = [[2, 2, 3, 3, 1], [3, 3, 4, 4, 1], [4, 4, 5, 5, 1], [5, 5, 6, 6, 1], [6, 6, 7, 7, 1], [7, 7, 8, 8, 1], [8, 8, 9, 9, 1], [9, 9, 10, 10, 1], [10, 10, 11, 11, 1], [11, 11, 12, 12, 1], [12, 12, 13, 13, 1], [13, 13, 14, 14, 1], [14, 14, 15, 15, 1], [15, 15, 16, 16, 1], [16, 16, 17, 17, 1], [17, 17, 18, 18, 1], [18, 18, 19, 19, 1], [19, 19, 20, 20, 1]]) == 20\n assert candidate(start = [5, 5],target = [20, 20],specialRoads = [[5, 5, 10, 10, 5], [10, 10, 15, 15, 3], [15, 15, 20, 20, 2], [10, 15, 15, 20, 4]]) == 10\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[1, 2, 3, 4, 2], [5, 6, 7, 8, 3], [9, 10, 11, 12, 4], [13, 14, 15, 16, 5], [17, 18, 19, 20, 6]]) == 195\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[1, 1, 25, 25, 50], [25, 25, 50, 50, 100], [50, 50, 75, 75, 150], [75, 75, 100, 100, 200], [1, 1, 50, 50, 150], [50, 50, 100, 100, 250], [100, 100, 75, 75, 200], [75, 75, 50, 50, 150], [50, 50, 25, 25, 100]]) == 198\n assert candidate(start = [10, 10],target = [100, 100],specialRoads = [[10, 10, 20, 20, 30], [20, 20, 30, 30, 35], [30, 30, 40, 40, 40], [40, 40, 50, 50, 45], [50, 50, 60, 60, 50], [60, 60, 70, 70, 55], [70, 70, 80, 80, 60], [80, 80, 90, 90, 65], [90, 90, 100, 100, 70]]) == 180\n assert candidate(start = [1, 1],target = [15, 15],specialRoads = [[1, 1, 5, 5, 8], [5, 5, 10, 10, 10], [10, 10, 15, 15, 12], [1, 5, 5, 10, 15], [5, 10, 10, 15, 20]]) == 28\n assert candidate(start = [1, 1],target = [20, 20],specialRoads = [[2, 2, 18, 18, 10], [3, 3, 17, 17, 10], [4, 4, 16, 16, 10], [5, 5, 15, 15, 10], [6, 6, 14, 14, 10], [7, 7, 13, 13, 10], [8, 8, 12, 12, 10], [9, 9, 11, 11, 10], [10, 10, 10, 10, 10], [11, 11, 9, 9, 10], [12, 12, 8, 8, 10], [13, 13, 7, 7, 10], [14, 14, 6, 6, 10], [15, 15, 5, 5, 10], [16, 16, 4, 4, 10], [17, 17, 3, 3, 10], [18, 18, 2, 2, 10]]) == 16\n assert candidate(start = [10, 10],target = [50, 50],specialRoads = [[15, 15, 25, 25, 10], [25, 25, 35, 35, 20], [35, 35, 45, 45, 30], [45, 45, 55, 55, 40], [15, 25, 25, 35, 5], [25, 35, 35, 45, 15], [35, 45, 45, 55, 25], [15, 35, 35, 45, 35], [25, 45, 45, 55, 45], [15, 45, 45, 55, 55], [10, 25, 25, 35, 5], [25, 35, 35, 45, 15], [35, 45, 45, 55, 25], [15, 45, 45, 55, 35], [25, 55, 55, 65, 45], [35, 55, 55, 65, 55], [45, 55, 55, 65, 65], [15, 55, 55, 65, 75], [25, 55, 55, 65, 85], [10, 50, 50, 50, 10], [20, 50, 50, 50, 20], [30, 50, 50, 50, 30], [40, 50, 50, 50, 40], [50, 50, 50, 50, 50], [60, 50, 50, 50, 60], [70, 50, 50, 50, 70]]) == 50\n assert candidate(start = [10, 10],target = [30, 30],specialRoads = [[15, 15, 20, 20, 10], [20, 20, 25, 25, 5], [25, 25, 30, 30, 2], [12, 12, 18, 18, 8], [18, 18, 24, 24, 6], [24, 24, 29, 29, 4]]) == 22\n assert candidate(start = [5, 5],target = [95, 95],specialRoads = [[10, 10, 20, 20, 10], [20, 20, 30, 30, 20], [30, 30, 40, 40, 30], [40, 40, 50, 50, 40], [50, 50, 60, 60, 50], [60, 60, 70, 70, 60], [70, 70, 80, 80, 70], [80, 80, 90, 90, 80], [90, 90, 100, 100, 90], [100, 100, 110, 110, 100], [110, 110, 120, 120, 110], [120, 120, 130, 130, 120], [130, 130, 140, 140, 130], [140, 140, 150, 150, 140], [150, 150, 160, 160, 150], [160, 160, 170, 170, 160], [170, 170, 180, 180, 170], [180, 180, 190, 190, 180], [190, 190, 200, 200, 190], [200, 200, 210, 210, 200], [210, 210, 220, 220, 210], [220, 220, 230, 230, 220], [230, 230, 240, 240, 230], [240, 240, 250, 250, 240], [250, 250, 260, 260, 250], [260, 260, 270, 270, 260], [270, 270, 280, 280, 270], [280, 280, 290, 290, 280], [290, 290, 300, 300, 290], [300, 300, 310, 310, 300], [310, 310, 320, 320, 310], [320, 320, 330, 330, 320], [330, 330, 340, 340, 330], [340, 340, 350, 350, 340], [350, 350, 360, 360, 350], [360, 360, 370, 370, 360], [370, 370, 380, 380, 370], [380, 380, 390, 390, 380], [390, 390, 400, 400, 390], [400, 400, 410, 410, 400], [410, 410, 420, 420, 410], [420, 420, 430, 430, 420], [430, 430, 440, 440, 430], [440, 440, 450, 450, 440], [450, 450, 460, 460, 450], [460, 460, 470, 470, 460], [470, 470, 480, 480, 470], [480, 480, 490, 490, 480], [490, 490, 500, 500, 490], [500, 500, 510, 510, 500], [510, 510, 520, 520, 510], [520, 520, 530, 530, 520], [530, 530, 540, 540, 530], [540, 540, 550, 550, 540], [550, 550, 560, 560, 550], [560, 560, 570, 570, 560], [570, 570, 580, 580, 570], [580, 580, 590, 590, 580], [590, 590, 600, 600, 590], [600, 600, 610, 610, 600], [610, 610, 620, 620, 610], [620, 620, 630, 630, 620], [630, 630, 640, 640, 630], [640, 640, 650, 650, 640], [650, 650, 660, 660, 650], [660, 660, 670, 670, 660], [670, 670, 680, 680, 670], [680, 680, 690, 690, 680], [690, 690, 700, 700, 690], [700, 700, 710, 710, 700], [710, 710, 720, 720, 710], [720, 720, 730, 730, 720], [730, 730, 740, 740, 730], [740, 740, 750, 750, 740], [750, 750, 760, 760, 750], [760, 760, 770, 770, 760], [770, 770, 780, 780, 770], [780, 780, 790, 790, 780], [790, 790, 800, 800, 790], [800, 800, 810, 810, 800], [810, 810, 820, 820, 810], [820, 820, 830, 830, 820], [830, 830, 840, 840, 830], [840, 840, 850, 850, 840], [850, 850, 860, 860, 850], [860, 860, 870, 870, 860], [870, 870, 880, 880, 870], [880, 880, 890, 890, 880], [890, 890, 900, 900, 890], [900, 900, 910, 910, 900], [910, 910, 920, 920, 910], [920, 920, 930, 930, 920], [930, 930, 940, 940, 930], [940, 940, 950, 950, 940]]) == 170\n assert candidate(start = [1, 1],target = [200, 200],specialRoads = [[10, 10, 30, 30, 20], [50, 50, 70, 70, 30], [90, 90, 110, 110, 40], [130, 130, 150, 150, 50], [170, 170, 190, 190, 60]]) == 368\n assert candidate(start = [2, 2],target = [20, 20],specialRoads = [[2, 2, 6, 6, 5], [6, 6, 10, 10, 7], [10, 10, 14, 14, 6], [14, 14, 18, 18, 8], [18, 18, 20, 20, 9]]) == 30\n assert candidate(start = [1, 1],target = [10, 10],specialRoads = [[2, 2, 3, 3, 1], [3, 3, 4, 4, 2], [4, 4, 5, 5, 3], [5, 5, 6, 6, 4], [6, 6, 7, 7, 5], [7, 7, 8, 8, 6], [8, 8, 9, 9, 7], [9, 9, 10, 10, 8]]) == 17\n assert candidate(start = [10, 10],target = [50, 50],specialRoads = [[10, 10, 20, 20, 15], [20, 20, 30, 30, 10], [30, 30, 40, 40, 5], [40, 40, 50, 50, 3], [20, 30, 30, 40, 2], [30, 40, 40, 50, 1]]) == 33\n assert candidate(start = [10, 10],target = [150, 150],specialRoads = [[20, 20, 40, 40, 10], [40, 40, 60, 60, 15], [60, 60, 80, 80, 20], [80, 80, 100, 100, 25], [100, 100, 120, 120, 30], [120, 120, 140, 140, 35], [140, 140, 160, 160, 40], [160, 160, 180, 180, 45], [180, 180, 200, 200, 50], [20, 60, 40, 80, 20], [40, 80, 60, 100, 25], [60, 100, 80, 120, 30], [80, 120, 100, 140, 35], [100, 140, 120, 160, 40], [120, 160, 140, 180, 45], [140, 180, 160, 200, 50]]) == 175\n assert candidate(start = [10, 10],target = [90, 90],specialRoads = [[10, 10, 20, 20, 15], [20, 20, 30, 30, 10], [30, 30, 40, 40, 5], [40, 40, 50, 50, 3], [50, 50, 60, 60, 15], [60, 60, 70, 70, 10], [70, 70, 80, 80, 5], [80, 80, 90, 90, 3], [20, 30, 30, 40, 2], [30, 40, 40, 50, 1], [40, 50, 50, 60, 2], [50, 60, 60, 70, 1], [60, 70, 70, 80, 2], [70, 80, 80, 90, 1]]) == 44\n assert candidate(start = [1, 1],target = [12, 12],specialRoads = [[1, 1, 3, 3, 4], [3, 3, 6, 6, 5], [6, 6, 9, 9, 6], [9, 9, 12, 12, 7], [1, 6, 6, 11, 8], [6, 11, 11, 16, 9], [11, 16, 16, 21, 10]]) == 20\n assert candidate(start = [50, 50],target = [100, 100],specialRoads = [[50, 50, 60, 60, 5], [60, 60, 70, 70, 5], [70, 70, 80, 80, 5], [80, 80, 90, 90, 5], [90, 90, 100, 100, 5], [50, 60, 70, 80, 10], [60, 70, 80, 90, 10], [70, 80, 90, 100, 10]]) == 25\n assert candidate(start = [1, 1],target = [50, 50],specialRoads = [[1, 2, 3, 3, 1], [3, 4, 4, 5, 1], [5, 6, 6, 7, 1], [7, 8, 8, 9, 1], [9, 10, 10, 11, 1], [11, 12, 12, 13, 1], [13, 14, 14, 15, 1], [15, 16, 16, 17, 1], [17, 18, 18, 19, 1], [19, 20, 20, 21, 1], [21, 22, 22, 23, 1], [23, 24, 24, 25, 1], [25, 26, 26, 27, 1], [27, 28, 28, 29, 1], [29, 30, 30, 31, 1], [31, 32, 32, 33, 1], [33, 34, 34, 35, 1], [35, 36, 36, 37, 1], [37, 38, 38, 39, 1], [39, 40, 40, 41, 1], [41, 42, 42, 43, 1], [43, 44, 44, 45, 1], [45, 46, 46, 47, 1], [47, 48, 48, 49, 1], [49, 50, 50, 51, 1]]) == 73\n assert candidate(start = [1, 1],target = [10, 10],specialRoads = [[1, 1, 5, 5, 10], [5, 5, 10, 10, 10], [1, 5, 5, 10, 10], [5, 1, 10, 5, 10], [1, 1, 10, 10, 30]]) == 18\n assert candidate(start = [5, 5],target = [50, 50],specialRoads = [[5, 5, 20, 20, 10], [20, 20, 30, 30, 5], [30, 30, 40, 40, 12], [40, 40, 50, 50, 7], [5, 50, 25, 25, 18]]) == 34\n assert candidate(start = [1, 1],target = [15, 15],specialRoads = [[1, 1, 4, 4, 5], [5, 5, 8, 8, 6], [9, 9, 12, 12, 7], [13, 13, 15, 15, 8]]) == 27\n assert candidate(start = [5, 5],target = [20, 20],specialRoads = [[6, 6, 10, 10, 15], [10, 10, 15, 15, 10], [15, 15, 20, 20, 5], [5, 5, 10, 10, 20], [10, 10, 12, 12, 1], [12, 12, 15, 15, 5]]) == 21\n assert candidate(start = [1, 1],target = [10, 10],specialRoads = [[1, 2, 3, 4, 5], [4, 5, 6, 7, 6], [7, 8, 9, 10, 7], [1, 5, 3, 9, 8], [5, 6, 8, 10, 9], [2, 6, 4, 10, 10]]) == 18\n assert candidate(start = [1, 1],target = [100, 1],specialRoads = [[10, 1, 20, 1, 5], [20, 1, 30, 1, 5], [30, 1, 40, 1, 5], [40, 1, 50, 1, 5], [50, 1, 60, 1, 5], [60, 1, 70, 1, 5], [70, 1, 80, 1, 5], [80, 1, 90, 1, 5], [90, 1, 100, 1, 5]]) == 54\n assert candidate(start = [10, 10],target = [100, 100],specialRoads = [[10, 10, 20, 20, 50], [20, 20, 30, 30, 55], [30, 30, 40, 40, 60], [40, 40, 50, 50, 65], [50, 50, 60, 60, 70], [60, 60, 70, 70, 75], [70, 70, 80, 80, 80], [80, 80, 90, 90, 85], [90, 90, 100, 100, 90]]) == 180\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[10, 10, 20, 20, 50], [20, 20, 30, 30, 40], [30, 30, 40, 40, 30], [40, 40, 50, 50, 20], [50, 50, 60, 60, 10], [60, 60, 70, 70, 15], [70, 70, 80, 80, 25], [80, 80, 90, 90, 35], [90, 90, 100, 100, 45]]) == 183\n assert candidate(start = [1, 1],target = [50, 50],specialRoads = [[1, 1, 10, 10, 10], [10, 10, 20, 20, 20], [20, 20, 30, 30, 30], [30, 30, 40, 40, 40], [40, 40, 50, 50, 50], [50, 50, 45, 45, 60], [45, 45, 40, 40, 70], [40, 40, 35, 35, 80], [35, 35, 30, 30, 90], [30, 30, 25, 25, 100], [25, 25, 20, 20, 110], [20, 20, 15, 15, 120], [15, 15, 10, 10, 130], [10, 10, 1, 1, 140]]) == 90\n assert candidate(start = [1, 1],target = [50, 50],specialRoads = [[2, 2, 3, 3, 1], [3, 3, 4, 4, 2], [4, 4, 5, 5, 3], [5, 5, 6, 6, 4], [6, 6, 7, 7, 5], [7, 7, 8, 8, 6], [8, 8, 9, 9, 7], [9, 9, 10, 10, 8], [10, 10, 11, 11, 9], [11, 11, 12, 12, 10], [12, 12, 13, 13, 11], [13, 13, 14, 14, 12], [14, 14, 15, 15, 13], [15, 15, 16, 16, 14], [16, 16, 17, 17, 15], [17, 17, 18, 18, 16], [18, 18, 19, 19, 17], [19, 19, 20, 20, 18], [20, 20, 21, 21, 19], [21, 21, 22, 22, 20], [22, 22, 23, 23, 21], [23, 23, 24, 24, 22], [24, 24, 25, 25, 23], [25, 25, 26, 26, 24], [26, 26, 27, 27, 25], [27, 27, 28, 28, 26], [28, 28, 29, 29, 27], [29, 29, 30, 30, 28], [30, 30, 31, 31, 29], [31, 31, 32, 32, 30], [32, 32, 33, 33, 31], [33, 33, 34, 34, 32], [34, 34, 35, 35, 33], [35, 35, 36, 36, 34], [36, 36, 37, 37, 35], [37, 37, 38, 38, 36], [38, 38, 39, 39, 37], [39, 39, 40, 40, 38], [40, 40, 41, 41, 39], [41, 41, 42, 42, 40], [42, 42, 43, 43, 41], [43, 43, 44, 44, 42], [44, 44, 45, 45, 43], [45, 45, 46, 46, 44], [46, 46, 47, 47, 45], [47, 47, 48, 48, 46], [48, 48, 49, 49, 47], [49, 49, 50, 50, 48]]) == 97\n assert candidate(start = [10, 10],target = [100, 100],specialRoads = [[15, 15, 20, 20, 5], [20, 20, 25, 25, 5], [25, 25, 30, 30, 5], [30, 30, 35, 35, 5], [35, 35, 40, 40, 5], [40, 40, 45, 45, 5], [45, 45, 50, 50, 5], [50, 50, 55, 55, 5], [55, 55, 60, 60, 5], [60, 60, 65, 65, 5], [65, 65, 70, 70, 5], [70, 70, 75, 75, 5], [75, 75, 80, 80, 5], [80, 80, 85, 85, 5], [85, 85, 90, 90, 5], [90, 90, 95, 95, 5], [95, 95, 100, 100, 5], [10, 30, 20, 40, 10], [20, 40, 30, 50, 10], [30, 50, 40, 60, 10], [40, 60, 50, 70, 10], [50, 70, 60, 80, 10], [60, 80, 70, 90, 10], [70, 90, 80, 100, 10]]) == 95\n assert candidate(start = [1, 1],target = [15, 15],specialRoads = [[1, 2, 2, 3, 1], [2, 3, 3, 4, 1], [3, 4, 4, 5, 1], [4, 5, 5, 6, 1], [5, 6, 6, 7, 1], [6, 7, 7, 8, 1], [7, 8, 8, 9, 1], [8, 9, 9, 10, 1], [9, 10, 10, 11, 1], [10, 11, 11, 12, 1], [11, 12, 12, 13, 1], [12, 13, 13, 14, 1], [13, 14, 14, 15, 1]]) == 15\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[1, 1, 50, 50, 50], [50, 50, 75, 75, 40], [75, 75, 100, 100, 60], [1, 1, 75, 75, 100], [50, 50, 100, 100, 150]]) == 140\n assert candidate(start = [5, 5],target = [95, 95],specialRoads = [[10, 10, 20, 20, 15], [20, 20, 30, 30, 20], [30, 30, 40, 40, 25], [40, 40, 50, 50, 30], [50, 50, 60, 60, 35], [60, 60, 70, 70, 40], [70, 70, 80, 80, 45], [80, 80, 90, 90, 50], [90, 90, 100, 100, 55], [10, 30, 20, 40, 10], [20, 40, 30, 50, 15], [30, 50, 40, 60, 20], [40, 60, 50, 70, 25], [50, 70, 60, 80, 30], [60, 80, 70, 90, 35], [70, 90, 80, 100, 40], [80, 100, 90, 95, 45], [90, 95, 100, 95, 50]]) == 165\n assert candidate(start = [50, 50],target = [100, 100],specialRoads = [[50, 50, 60, 60, 10], [60, 60, 70, 70, 10], [70, 70, 80, 80, 10], [80, 80, 90, 90, 10], [90, 90, 100, 100, 10], [60, 60, 70, 70, 5], [70, 70, 80, 80, 5], [80, 80, 90, 90, 5], [90, 90, 100, 100, 5], [70, 70, 80, 80, 2], [80, 80, 90, 90, 2], [90, 90, 100, 100, 2]]) == 21\n assert candidate(start = [5, 5],target = [50, 50],specialRoads = [[5, 5, 15, 15, 20], [15, 15, 25, 25, 25], [25, 25, 35, 35, 30], [35, 35, 45, 45, 35], [45, 45, 50, 50, 40], [5, 15, 15, 25, 50], [15, 25, 25, 35, 55], [25, 35, 35, 45, 60], [35, 45, 45, 50, 65]]) == 90\n assert candidate(start = [10, 10],target = [100, 100],specialRoads = [[10, 20, 30, 40, 15], [30, 50, 60, 70, 20], [60, 80, 90, 100, 25]]) == 100\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[2, 2, 50, 50, 100], [50, 50, 75, 75, 150], [75, 75, 100, 100, 50], [50, 50, 100, 100, 200], [75, 75, 25, 25, 50], [25, 25, 1, 1, 10]]) == 198\n assert candidate(start = [10, 10],target = [10, 30],specialRoads = [[10, 11, 10, 15, 5], [10, 16, 10, 20, 4], [10, 21, 10, 25, 3], [10, 26, 10, 30, 2]]) == 17\n assert candidate(start = [10, 10],target = [50, 50],specialRoads = [[15, 15, 20, 20, 5], [25, 25, 30, 30, 5], [35, 35, 40, 40, 5], [45, 45, 50, 50, 5], [5, 5, 10, 10, 5], [10, 10, 15, 15, 5], [15, 15, 10, 10, 5], [20, 20, 15, 15, 5], [25, 25, 20, 20, 5], [30, 30, 25, 25, 5], [35, 35, 30, 30, 5], [40, 40, 35, 35, 5], [45, 45, 40, 40, 5]]) == 55\n assert candidate(start = [1, 1],target = [100000, 100000],specialRoads = [[1, 1, 100000, 100000, 50000], [50000, 50000, 75000, 75000, 10000]]) == 50000\n assert candidate(start = [10, 10],target = [50, 50],specialRoads = [[10, 20, 30, 40, 25], [30, 50, 40, 60, 30], [40, 60, 50, 70, 35], [50, 70, 60, 80, 40], [60, 80, 70, 90, 45]]) == 65\n assert candidate(start = [1, 1],target = [100, 100],specialRoads = [[10, 10, 20, 20, 15], [20, 20, 30, 30, 25], [50, 50, 70, 70, 45], [70, 70, 90, 90, 55], [90, 90, 100, 100, 5]]) == 178\n assert candidate(start = [3, 3],target = [30, 30],specialRoads = [[3, 3, 9, 9, 15], [9, 9, 15, 15, 20], [15, 15, 21, 21, 25], [21, 21, 27, 27, 30], [27, 27, 30, 30, 35], [3, 9, 9, 15, 40], [9, 15, 15, 21, 45], [15, 21, 21, 27, 50], [21, 27, 27, 30, 55]]) == 54\n assert candidate(start = [5, 5],target = [150, 150],specialRoads = [[10, 10, 15, 15, 10], [15, 15, 20, 20, 12], [20, 20, 25, 25, 14], [25, 25, 30, 30, 16], [30, 30, 35, 35, 18], [35, 35, 40, 40, 20], [40, 40, 45, 45, 22], [45, 45, 50, 50, 24], [50, 50, 55, 55, 26], [55, 55, 60, 60, 28], [60, 60, 65, 65, 30], [65, 65, 70, 70, 32], [70, 70, 75, 75, 34], [75, 75, 80, 80, 36], [80, 80, 85, 85, 38], [85, 85, 90, 90, 40], [90, 90, 95, 95, 42], [95, 95, 100, 100, 44], [100, 100, 105, 105, 46], [105, 105, 110, 110, 48], [110, 110, 115, 115, 50], [115, 115, 120, 120, 52], [120, 120, 125, 125, 54], [125, 125, 130, 130, 56], [130, 130, 135, 135, 58], [135, 135, 140, 140, 60], [140, 140, 145, 145, 62], [145, 145, 150, 150, 64]]) == 290\n assert candidate(start = [5, 5],target = [30, 5],specialRoads = [[6, 5, 10, 5, 5], [11, 5, 15, 5, 4], [16, 5, 20, 5, 3], [21, 5, 25, 5, 2], [26, 5, 30, 5, 1]]) == 19\n assert candidate(start = [10, 10],target = [50, 50],specialRoads = [[10, 10, 20, 20, 20], [20, 20, 30, 30, 30], [30, 30, 40, 40, 40], [40, 40, 50, 50, 50], [50, 50, 40, 40, 60], [40, 40, 30, 30, 70], [30, 30, 20, 20, 80], [20, 20, 10, 10, 90]]) == 80\n assert candidate(start = [5, 5],target = [200, 200],specialRoads = [[10, 10, 20, 20, 5], [20, 20, 30, 30, 5], [30, 30, 40, 40, 5], [40, 40, 50, 50, 5], [50, 50, 60, 60, 5], [60, 60, 70, 70, 5], [70, 70, 80, 80, 5], [80, 80, 90, 90, 5], [90, 90, 100, 100, 5], [100, 100, 110, 110, 5], [110, 110, 120, 120, 5], [120, 120, 130, 130, 5], [130, 130, 140, 140, 5], [140, 140, 150, 150, 5], [150, 150, 160, 160, 5], [160, 160, 170, 170, 5], [170, 170, 180, 180, 5], [180, 180, 190, 190, 5], [190, 190, 200, 200, 5], [1, 1, 200, 200, 1000]]) == 105\n assert candidate(start = [5, 5],target = [50, 50],specialRoads = [[5, 5, 10, 10, 10], [10, 10, 15, 15, 10], [15, 15, 20, 20, 10], [20, 20, 25, 25, 10], [25, 25, 30, 30, 10], [30, 30, 35, 35, 10], [35, 35, 40, 40, 10], [40, 40, 45, 45, 10], [45, 45, 50, 50, 10]]) == 90\n assert candidate(start = [5, 5],target = [25, 25],specialRoads = [[5, 5, 10, 10, 10], [10, 10, 15, 15, 15], [15, 15, 20, 20, 20], [20, 20, 25, 25, 25]]) == 40\n", "comparison": "exact"}, "public_tests": ["[1,1]\n[4,5]\n[[1,2,3,3,2],[3,4,4,5,1]]", "[3,2]\n[5,7]\n[[5,7,3,2,1],[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]]", "[1,1]\n[10,4]\n[[4,2,1,1,3],[1,2,7,4,4],[10,3,6,1,2],[6,1,1,2,3]]"], "hints": ["It can be proven that it is optimal to go only to the positions that are either the start or the end of a special road or the target position.", "Consider all positions given to you as nodes in a graph, and the edges of the graph are the special roads.", "Now the problem is equivalent to finding the shortest path in a directed graph."], "metadata": {"canonical_parameter_names": ["start", "target", "specialRoads"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:08+00:00", "tests_total": 54, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "graph", "heap-priority-queue", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(start, target, special_roads)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "start", "type": "Integer[]"}, {"name": "target", "type": "Integer[]"}, {"name": "special_roads", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2663, "task_id": "lexicographically-smallest-beautiful-string", "difficulty": "Hard", "problem_description": "A string is beautiful if:\n\n- It consists of the first k letters of the English lowercase alphabet.\n- It does not contain any substring of length 2 or more which is a palindrome.\n\nYou are given a beautiful string s of length n and a positive integer k.\n\nReturn the lexicographically smallest string of length n, which is larger than s and is beautiful. If there is no such string, return an empty string.\n\nA string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n\n- For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n\nExample 1:\n\nInput: s = \"abcz\", k = 26\nOutput: \"abda\"\nExplanation: The string \"abda\" is beautiful and lexicographically larger than the string \"abcz\".\nIt can be proven that there is no string that is lexicographically larger than the string \"abcz\", beautiful, and lexicographically smaller than the string \"abda\".\n\nExample 2:\n\nInput: s = \"dc\", k = 4\nOutput: \"\"\nExplanation: It can be proven that there is no string that is lexicographically larger than the string \"dc\" and is beautiful.\n\nConstraints:\n\n- 1 <= n == s.length <= 10^5\n- 4 <= k <= 26\n- s is a beautiful string.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcd\",k = 5) == \"abce\"\n assert candidate(s = \"aabbcc\",k = 6) == \"aabbcd\"\n assert candidate(s = \"zyx\",k = 26) == \"\"\n assert candidate(s = \"abcz\",k = 26) == \"abda\"\n assert candidate(s = \"aaa\",k = 4) == \"aab\"\n assert candidate(s = \"dc\",k = 4) == \"\"\n assert candidate(s = \"abcd\",k = 4) == \"abda\"\n assert candidate(s = \"xyz\",k = 26) == \"xza\"\n assert candidate(s = \"aabb\",k = 4) == \"aabc\"\n assert candidate(s = \"azzzz\",k = 26) == \"bacba\"\n assert candidate(s = \"abcabca\",k = 26) == \"abcabcd\"\n assert candidate(s = \"aabababa\",k = 6) == \"aabababc\"\n assert candidate(s = \"zzzzz\",k = 26) == \"\"\n assert candidate(s = \"abcabcabcabc\",k = 26) == \"abcabcabcabd\"\n assert candidate(s = \"zyxzyxzyxzyx\",k = 26) == \"\"\n assert candidate(s = \"wxyz\",k = 26) == \"wxza\"\n assert candidate(s = \"zzzzzzzzzz\",k = 26) == \"\"\n assert candidate(s = \"mnopqrstuvw\",k = 21) == \"mnopqrsuabc\"\n assert candidate(s = \"zyxwvutsr\",k = 19) == \"\"\n assert candidate(s = \"abcdefg\",k = 7) == \"abcdega\"\n assert candidate(s = \"abcdefghijklmnop\",k = 26) == \"abcdefghijklmnoq\"\n assert candidate(s = \"mnopqr\",k = 18) == \"mnopra\"\n assert candidate(s = \"lkjihgf\",k = 12) == \"lkjihgi\"\n assert candidate(s = \"abcdefghij\",k = 10) == \"abcdefghja\"\n assert candidate(s = \"aabccba\",k = 15) == \"aabccbd\"\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewq\",k = 26) == \"mnbvcxzlkjhgfdsapoiuytrewr\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",k = 26) == \"abcdefghijklmnopqrstuvwxyzb\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 20) == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrstabcabcabcabcab\"\n assert candidate(s = \"abcdefghijklmnopqrstuv\",k = 21) == \"abcdefghijklmnopqrsuab\"\n assert candidate(s = \"zzzzzz\",k = 4) == \"\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 26) == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyzab\"\n assert candidate(s = \"abcdabcd\",k = 4) == \"abcdabda\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzz\",k = 26) == \"\"\n assert candidate(s = \"abcaabcd\",k = 26) == \"abcaabce\"\n assert candidate(s = \"mnopqrlmno\",k = 14) == \"mnopqrlnab\"\n assert candidate(s = \"abcdcba\",k = 10) == \"abcdcbd\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxzz\",k = 26) == \"abcdefghijklmnopqrstuvwyab\"\n assert candidate(s = \"abcdefghijk\",k = 12) == \"abcdefghijl\"\n assert candidate(s = \"abcdefghijk\",k = 11) == \"abcdefghika\"\n assert candidate(s = \"abba\",k = 26) == \"abbc\"\n assert candidate(s = \"abababababab\",k = 26) == \"abababababac\"\n assert candidate(s = \"aaaabbbbccccdddd\",k = 26) == \"aaaabbbbccccddde\"\n assert candidate(s = \"abcdcba\",k = 26) == \"abcdcbd\"\n assert candidate(s = \"abcdexyz\",k = 26) == \"abcdexza\"\n assert candidate(s = \"pqrs\",k = 18) == \"prab\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",k = 26) == \"qwertyuiopasdfghjklzxcvbno\"\n assert candidate(s = \"xyzabc\",k = 26) == \"xyzabd\"\n assert candidate(s = \"abacabadabacaba\",k = 26) == \"abacabadabacabc\"\n assert candidate(s = \"aabbccdd\",k = 6) == \"aabbccde\"\n assert candidate(s = \"zzzz\",k = 4) == \"\"\n assert candidate(s = \"aabbaabbaabb\",k = 6) == \"aabbaabbaabc\"\n assert candidate(s = \"abcde\",k = 5) == \"abcea\"\n assert candidate(s = \"mnopqrstuvw\",k = 22) == \"mnopqrstvab\"\n assert candidate(s = \"abcdexyzabcd\",k = 26) == \"abcdexyzabce\"\n assert candidate(s = \"abacabadabc\",k = 26) == \"abacabadabd\"\n assert candidate(s = \"xyzxyzxyzxyz\",k = 26) == \"xzabcabcabca\"\n assert candidate(s = \"abcdefghij\",k = 26) == \"abcdefghik\"\n assert candidate(s = \"abac\",k = 4) == \"abad\"\n assert candidate(s = \"abcabcabc\",k = 26) == \"abcabcabd\"\n assert candidate(s = \"abcdefghi\",k = 10) == \"abcdefghj\"\n assert candidate(s = \"aabbaa\",k = 6) == \"aabbac\"\n assert candidate(s = \"abcdefghi\",k = 9) == \"abcdefgia\"\n assert candidate(s = \"zyxcba\",k = 6) == \"zyxcbd\"\n assert candidate(s = \"mnopqrstuvwxyzz\",k = 26) == \"mnopqrstuvwxzab\"\n assert candidate(s = \"zzzzzzzzz\",k = 26) == \"\"\n assert candidate(s = \"aabbccddeeffgg\",k = 6) == \"aabbccddefabca\"\n assert candidate(s = \"abacabadabacaba\",k = 15) == \"abacabadabacabc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy\",k = 26) == \"abcdefghijklmnopqrstuvwxz\"\n assert candidate(s = \"abcdabc\",k = 26) == \"abcdabd\"\n assert candidate(s = \"fedcba\",k = 6) == \"fedcbd\"\n assert candidate(s = \"aabbccddeeffgg\",k = 10) == \"aabbccddeeffgh\"\n assert candidate(s = \"mnopqrstu\",k = 20) == \"mnopqrtab\"\n assert candidate(s = \"abcdefg\",k = 8) == \"abcdefh\"\n assert candidate(s = \"abcddcba\",k = 20) == \"abcddcbd\"\n assert candidate(s = \"abacaba\",k = 7) == \"abacabc\"\n assert candidate(s = \"abcdefghijklmnop\",k = 20) == \"abcdefghijklmnoq\"\n assert candidate(s = \"aabababacababaca\",k = 26) == \"aabababacababacb\"\n assert candidate(s = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhaaggeeffddccbb\",k = 26) == \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhaaggeeffddccbd\"\n assert candidate(s = \"abacabad\",k = 4) == \"abacabca\"\n assert candidate(s = \"zyxzyxzyx\",k = 26) == \"\"\n assert candidate(s = \"aabbccddeeff\",k = 26) == \"aabbccddeefg\"\n assert candidate(s = \"abcbac\",k = 26) == \"abcbad\"\n assert candidate(s = \"abcdefghijklmnop\",k = 16) == \"abcdefghijklmnpa\"\n assert candidate(s = \"abcabcabcabc\",k = 6) == \"abcabcabcabd\"\n assert candidate(s = \"abacaba\",k = 26) == \"abacabc\"\n assert candidate(s = \"abacbacbac\",k = 5) == \"abacbacbad\"\n assert candidate(s = \"abcdcba\",k = 5) == \"abcdcbd\"\n assert candidate(s = \"abcdefgabcdefg\",k = 26) == \"abcdefgabcdefh\"\n assert candidate(s = \"abcdabcdabcd\",k = 4) == \"abcdabcdabda\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 26) == \"zyxwvutsrqponmlkjihgfedcbd\"\n", "comparison": "exact"}, "public_tests": ["\"abcz\"\n26", "\"dc\"\n4"], "hints": ["If the string does not contain any palindromic substrings of lengths 2 and 3, then the string does not contain any palindromic substrings at all.", "Iterate from right to left and if it is possible to increase character at index i without creating any palindromic substrings of lengths 2 and 3, then increase it.", "After increasing the character at index i, set every character after index i equal to character a. With this, we will ensure that we have created a lexicographically larger string than s, which does not contain any palindromes before index i and is lexicographically the smallest.", "Finally, we are just left with a case to fix palindromic substrings, which come after index i. This can be done with a similar method mentioned in the second hint."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().smallestBeautifulString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:10+00:00", "tests_total": 103, "tests_dropped": 13, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def smallest_beautiful_string(s, k)", "container": null, "callable": "smallest_beautiful_string", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2670, "task_id": "find-the-distinct-difference-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array nums of length n.\n\nThe distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i].\n\nReturn the distinct difference array of nums.\n\nNote that nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j inclusive. Particularly, if i > j then nums[i, ..., j] denotes an empty subarray.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: [-3,-1,1,3,5]\nExplanation: For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3.\nFor index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.\nFor index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1.\nFor index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3.\nFor index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5.\n\nExample 2:\n\nInput: nums = [3,2,3,4,2]\nOutput: [-2,-1,0,2,3]\nExplanation: For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2.\nFor index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.\nFor index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0.\nFor index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2.\nFor index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3.\n\nConstraints:\n\n- 1 <= n == nums.length <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [10, 20, 10, 20, 10]) == [-1, 0, 0, 1, 2]\n assert candidate(nums = [1, 1, 2, 2, 3]) == [-2, -1, 0, 1, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [1]) == [1]\n assert candidate(nums = [50, 49, 48, 47, 46]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [5, 5, 5, 5, 5]) == [0, 0, 0, 0, 1]\n assert candidate(nums = [42, 42, 42, 42, 42]) == [0, 0, 0, 0, 1]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [1, 2, 2, 3, 3]) == [-1, 0, 1, 2, 3]\n assert candidate(nums = [1, 1, 1, 1, 1]) == [0, 0, 0, 0, 1]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [-2, -1, 0, 1, 1, 2, 3, 3, 3, 4]\n assert candidate(nums = [3, 2, 3, 4, 2]) == [-2, -1, 0, 2, 3]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [1, 2, 3, 2, 1]) == [-2, -1, 1, 2, 3]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [1, 2, 1, 2, 1]) == [-1, 0, 0, 1, 2]\n assert candidate(nums = [50, 40, 30, 20, 10]) == [-3, -1, 1, 3, 5]\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [-13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(nums = [42, 13, 24, 35, 42, 13, 24, 35]) == [-3, -2, -1, 0, 1, 2, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30, 20, 10, 30, 20, 10]) == [-2, -1, 0, 0, 0, 1, 2, 3]\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]) == [-2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == [-3, -3, -3, -2, -1, -1, -1, 0, 1, 1, 1, 2, 3, 3, 3, 4]\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == [-2, -1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == [-2, -2, -2, -2, -1, 0, 0, 0, 0, 1, 2, 2, 2, 2, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 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]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [-13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == [-4, -3, -2, -1, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\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]) == [-28, -26, -24, -22, -20, -18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == [-2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [-4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 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, 5, 5, 5, 5, 5]) == [-4, -4, -4, -4, -3, -2, -2, -2, -2, -1, 0, 0, 0, 0, 1, 2, 2, 2, 2, 3, 4, 4, 4, 4, 5]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 1, 3, 2, 4, 5]) == [-9, -8, -7, -6, -5, -3, -1, 1, 3, 5, 6, 7, 8, 9, 10]\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]) == [-9, -9, -8, -7, -7, -6, -5, -5, -4, -3, -3, -2, -1, -1, 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == [-1, 0, 0, 0, 0, 0, 0, 0, 1, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [-13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == [-3, -2, -1, 0, 0, 0, 0, 0, 1, 2, 3, 4]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == [-2, -1, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == [-9, -8, -7, -6, -5, -3, -1, 1, 3, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == [-2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 3, 3, 2, 2, 1, 1, 4, 4, 3, 3, 2, 2, 1, 1, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == [-4, -4, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5]\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]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\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, 42, 42, 42, 42, 42, 42]) == [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, 1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 3, 2, 3, 4, 3, 5, 6, 7, 8, 9]) == [-7, -6, -4, -4, -2, -1, 1, 3, 5, 7, 9]\n assert candidate(nums = [1, 3, 2, 3, 1, 4, 1, 3, 2, 3, 4, 2, 1, 3, 4, 2, 1, 3, 2, 4, 1]) == [-3, -2, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]) == [-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == [-8, -7, -6, -5, -4, -3, -2, -1, -1, -1, 0, 0, 2, 3, 3, 4, 5, 7, 8, 9]\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14, 16, 15, 17, 16, 18, 17, 19, 18, 20, 19]) == [-19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == [-3, -3, -3, -3, -2, -1, -1, -1, -1, 0, 1, 1, 1, 1, 2, 3, 3, 3, 3, 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]) == [-2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10]) == [-10, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [-18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40]) == [-9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11]\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == [-13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(nums = [42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21]) == [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == [-5, -4, -3, -2, -1, 0, 1, 3, 4, 6]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == [-3, -3, -2, -1, -1, 0, 1, 1, 2, 3, 3, 4]\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]) == [-28, -26, -24, -22, -20, -18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [50, 40, 30, 20, 10, 10, 20, 30, 40, 50]) == [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 20, 10, 30, 30, 40, 40, 50, 50]) == [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [50, 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]) == [-48, -46, -44, -42, -40, -38, -36, -34, -32, -30, -28, -26, -24, -22, -20, -18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 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]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [-8, -6, -4, -2, 0, 2, 4, 6, 8, 10]\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [-4, -2, -2, 0, 0, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\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]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 3, 4, 5]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == [-4, -4, -3, -2, -2, -1, 0, 0, 1, 2, 2, 3, 4, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == [0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == [-3, -3, -2, -1, -1, 0, 1, 1, 2, 3, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [15, 15, 10, 10, 5, 5, 1, 1, 20, 20, 25, 25, 30, 30, 35, 35]) == [-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 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]) == [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7]) == [-2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3]\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == [-2, -1, 0, 0, 0, 0, 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, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [-4, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]\n assert candidate(nums = [7, 7, 7, 8, 8, 8, 9, 9, 9, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == [-7, -7, -6, -5, -5, -4, -3, -3, -2, -1, -1, 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == [-9, -8, -7, -6, -5, -3, -1, 1, 3, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1]) == [-4, -3, -2, -2, -2, -1, 1, 2, 3, 4, 5]\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[3,2,3,4,2]"], "hints": ["Which data structure will help you maintain distinct elements?", "Iterate over all possible prefix sizes. Then, use a nested loop to add the elements of the prefix to a set, and another nested loop to add the elements of the suffix to another set."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().distinctDifferenceArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:15+00:00", "tests_total": 107, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def distinct_difference_array(nums)", "container": null, "callable": "distinct_difference_array", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2672, "task_id": "number-of-adjacent-elements-with-the-same-color", "difficulty": "Medium", "problem_description": "You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [index_i, color_i]. For the i^th query:\n\n- Set colors[index_i] to color_i.\n- Count the number of adjacent pairs in colors which have the same color (regardless of color_i).\n\nReturn an array answer of the same length as queries where answer[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]\nOutput: [0,1,1,0,2]\nExplanation:\n- Initially array colors = [0,0,0,0], where 0 denotes uncolored elements of the array.\n- After the 1^st query colors = [2,0,0,0]. The count of adjacent pairs with the same color is 0.\n- After the 2^nd query colors = [2,2,0,0]. The count of adjacent pairs with the same color is 1.\n- After the 3^rd query colors = [2,2,0,1]. The count of adjacent pairs with the same color is 1.\n- After the 4^th query colors = [2,1,0,1]. The count of adjacent pairs with the same color is 0.\n- After the 5^th query colors = [2,1,1,1]. The count of adjacent pairs with the same color is 2.\n\nExample 2:\n\nInput: n = 1, queries = [[0,100000]]\nOutput: [0]\nExplanation:\nAfter the 1^st query colors = [100000]. The count of adjacent pairs with the same color is 0.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- 1 <= queries.length <= 10^5\n- queries[i].length == 2\n- 0 <= index_i <= n - 1\n- 1 <= color_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,queries = [[0, 2], [1, 2], [2, 2]]) == [0, 1, 2]\n assert candidate(n = 1,queries = [[0, 100000]]) == [0]\n assert candidate(n = 10,queries = [[5, 3], [6, 3], [5, 3], [4, 3], [3, 3], [2, 3], [1, 3], [0, 3], [8, 3], [9, 3]]) == [0, 1, 1, 2, 3, 4, 5, 6, 6, 7]\n assert candidate(n = 6,queries = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [0, 2]]) == [0, 1, 2, 3, 4, 5]\n assert candidate(n = 3,queries = [[0, 1], [1, 2], [2, 1], [1, 1]]) == [0, 0, 0, 2]\n assert candidate(n = 10,queries = [[0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 3,queries = [[0, 1], [1, 2], [2, 3]]) == [0, 0, 0]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1]]) == [0, 1, 2, 3, 4]\n assert candidate(n = 4,queries = [[0, 2], [1, 2], [3, 1], [1, 1], [2, 1]]) == [0, 1, 1, 0, 2]\n assert candidate(n = 6,queries = [[0, 2], [1, 2], [2, 2], [3, 3], [4, 3], [5, 3]]) == [0, 1, 2, 2, 3, 4]\n assert candidate(n = 5,queries = [[0, 3], [1, 3], [1, 4], [2, 4], [3, 3], [4, 3], [0, 4], [1, 3]]) == [0, 1, 0, 1, 1, 2, 3, 1]\n assert candidate(n = 6,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]]) == [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]\n assert candidate(n = 10,queries = [[0, 1], [1, 1], [2, 1], [3, 2], [4, 2], [5, 2], [6, 3], [7, 3], [8, 3], [9, 3]]) == [0, 1, 2, 2, 3, 4, 4, 5, 6, 7]\n assert candidate(n = 7,queries = [[0, 3], [1, 3], [2, 4], [3, 4], [4, 3], [5, 4], [6, 3]]) == [0, 1, 1, 2, 2, 2, 2]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 2], [1, 2], [2, 1], [1, 1], [2, 2], [1, 2], [0, 1], [4, 1]]) == [0, 1, 1, 1, 0, 2, 1, 1, 1, 1]\n assert candidate(n = 10,queries = [[0, 1], [1, 2], [2, 1], [1, 1], [2, 1], [3, 2], [4, 2], [3, 2], [4, 2], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [0, 0, 0, 2, 2, 2, 3, 3, 3, 3, 4, 5, 6, 7]\n assert candidate(n = 50000,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 10,queries = [[0, 100000], [1, 100000], [2, 100000], [3, 100000], [4, 100000], [5, 100000], [6, 100000], [7, 100000], [8, 100000], [9, 100000]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 12,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 1]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 6,queries = [[0, 3], [1, 3], [2, 4], [3, 4], [4, 3], [5, 4], [2, 3], [3, 3], [4, 4], [5, 3]]) == [0, 1, 1, 2, 2, 2, 2, 4, 4, 3]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [0, 1], [1, 1], [2, 1], [3, 1], [4, 1]]) == [0, 1, 2, 3, 4, 4, 4, 4, 4, 4]\n assert candidate(n = 6,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == [0, 0, 0, 0, 0, 0]\n assert candidate(n = 20,queries = [[0, 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], [16, 5], [17, 5], [18, 5], [19, 5]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(n = 10,queries = [[0, 1], [9, 1], [0, 2], [9, 2], [4, 3], [5, 3], [4, 4], [5, 4], [3, 5], [6, 5]]) == [0, 0, 0, 0, 0, 1, 0, 1, 1, 1]\n assert candidate(n = 15,queries = [[0, 3], [1, 3], [2, 3], [3, 3], [4, 4], [5, 4], [6, 4], [7, 4], [8, 4], [9, 4], [10, 4], [11, 4], [12, 4], [13, 4], [14, 4]]) == [0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(n = 20,queries = [[0, 1], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 1], [11, 1], [12, 2], [13, 3], [14, 4], [15, 5], [16, 6], [17, 7], [18, 8], [19, 9]]) == [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 20,queries = [[0, 9], [1, 9], [2, 10], [3, 10], [4, 9], [5, 10], [6, 9], [7, 10], [8, 9], [9, 10], [10, 9], [11, 10], [12, 9], [13, 10], [14, 9], [15, 10], [16, 9], [17, 10], [18, 9], [19, 10]]) == [0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 10,queries = [[0, 1], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [8, 9], [7, 9], [6, 9], [5, 9], [4, 9], [3, 9], [2, 9], [1, 9], [0, 9]]) == [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9]\n assert candidate(n = 7,queries = [[0, 2], [1, 2], [2, 3], [3, 2], [4, 2], [5, 3], [6, 2]]) == [0, 1, 1, 1, 2, 2, 2]\n assert candidate(n = 1000,queries = [[500, 1], [501, 1], [502, 1], [500, 2], [501, 2], [502, 2], [500, 1], [501, 1], [502, 1]]) == [0, 1, 2, 1, 1, 2, 1, 1, 2]\n assert candidate(n = 6,queries = [[0, 1], [1, 1], [2, 2], [3, 2], [4, 2], [5, 1], [4, 1], [3, 1], [2, 1], [1, 1], [0, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == [0, 1, 1, 2, 3, 3, 3, 3, 5, 5, 5, 3, 3, 3, 3, 4]\n assert candidate(n = 6,queries = [[0, 3], [1, 3], [2, 3], [3, 4], [4, 4], [5, 4], [2, 3], [3, 3], [4, 3]]) == [0, 1, 2, 2, 3, 4, 4, 4, 4]\n assert candidate(n = 5,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(n = 7,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 1], [6, 2]]) == [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2]]) == [0, 1, 2, 3, 4, 3, 3, 3, 3, 4]\n assert candidate(n = 20,queries = [[0, 1], [1, 1], [2, 2], [3, 2], [4, 1], [5, 1], [6, 2], [7, 2], [8, 1], [9, 1], [10, 3], [11, 3], [12, 4], [13, 4], [14, 5], [15, 5], [16, 3], [17, 3], [18, 4], [19, 4]]) == [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10]\n assert candidate(n = 10,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [3, 2], [2, 2], [1, 2], [0, 2], [5, 2]]) == [0, 1, 2, 3, 4, 2, 2, 2, 3, 3]\n assert candidate(n = 5,queries = [[0, 1], [1, 2], [2, 1], [3, 2], [4, 1], [0, 2], [1, 1], [2, 2], [3, 1], [4, 2]]) == [0, 0, 0, 0, 0, 1, 1, 1, 1, 0]\n assert candidate(n = 10,queries = [[0, 1], [1, 1], [2, 2], [3, 2], [4, 3], [5, 4], [6, 4], [7, 3], [8, 2], [9, 1]]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 3]\n assert candidate(n = 9,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100000,queries = [[0, 100000], [1, 100000], [2, 100000], [3, 100000], [4, 100000], [5, 100000], [6, 100000], [7, 100000], [8, 100000], [9, 100000]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 10,queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 10,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 8,queries = [[0, 2], [1, 3], [2, 2], [3, 2], [4, 3], [5, 3], [6, 2], [7, 2], [2, 3], [3, 3], [4, 2], [5, 2]]) == [0, 0, 0, 1, 1, 2, 2, 3, 3, 5, 3, 5]\n assert candidate(n = 5,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 1], [3, 1], [2, 1], [1, 1], [0, 1]]) == [0, 0, 0, 0, 0, 1, 2, 4, 4]\n assert candidate(n = 10,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 5,queries = [[0, 1], [1, 2], [1, 3], [2, 2], [2, 3]]) == [0, 0, 0, 0, 1]\n assert candidate(n = 10,queries = [[0, 5], [1, 5], [2, 6], [3, 6], [4, 6], [5, 7], [6, 7], [7, 7], [8, 8], [9, 8], [5, 6]]) == [0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 6]\n assert candidate(n = 7,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [5, 1], [4, 1], [3, 1], [2, 1], [1, 1], [0, 1]]) == [0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 6]\n assert candidate(n = 100,queries = [[0, 1], [99, 2], [49, 3], [50, 3], [48, 3], [51, 3], [25, 4], [75, 4], [50, 5], [49, 5]]) == [0, 0, 0, 1, 2, 3, 3, 3, 1, 1]\n assert candidate(n = 6,queries = [[0, 2], [1, 2], [2, 3], [3, 3], [4, 2], [5, 2]]) == [0, 1, 1, 2, 2, 3]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 1], [3, 2], [4, 2], [3, 1], [4, 1]]) == [0, 1, 2, 2, 3, 3, 4]\n assert candidate(n = 7,queries = [[0, 1], [1, 1], [2, 2], [3, 2], [4, 3], [5, 3], [6, 3], [1, 2], [2, 2], [3, 2], [4, 4], [5, 4], [6, 4]]) == [0, 1, 1, 2, 2, 3, 4, 4, 4, 4, 3, 3, 4]\n assert candidate(n = 20,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 1], [1, 2], [1, 1]]) == [0, 1, 2, 0, 2]\n assert candidate(n = 9,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 1], [1, 2], [2, 3], [3, 4]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 10,queries = [[0, 1], [1, 2], [2, 1], [3, 2], [4, 1], [5, 2], [6, 1], [7, 2], [8, 1], [9, 2]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 8,queries = [[0, 1], [1, 2], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1]]) == [0, 0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(n = 15,queries = [[0, 7], [1, 7], [2, 8], [3, 8], [4, 7], [5, 8], [6, 7], [7, 8], [8, 7], [9, 8], [10, 7], [11, 8], [12, 7], [13, 8], [14, 7]]) == [0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 7,queries = [[0, 3], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [0, 4], [1, 4], [2, 4]]) == [0, 1, 2, 3, 4, 5, 6, 5, 5, 5]\n assert candidate(n = 15,queries = [[0, 3], [1, 3], [2, 3], [3, 3], [4, 4], [5, 4], [6, 4], [7, 4], [8, 4], [9, 4], [10, 5], [11, 5], [12, 5], [13, 5], [14, 5]]) == [0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12]\n assert candidate(n = 20,queries = [[0, 1], [2, 1], [4, 1], [6, 1], [8, 1], [10, 1], [12, 1], [14, 1], [16, 1], [18, 1], [19, 1], [19, 2], [18, 2], [17, 2], [16, 2], [15, 2], [14, 2], [13, 2], [12, 2], [11, 2]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(n = 5,queries = [[0, 1], [1, 1], [2, 2], [3, 2], [4, 2], [1, 2], [2, 2]]) == [0, 1, 1, 2, 3, 3, 3]\n assert candidate(n = 1000,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(n = 5,queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(n = 10,queries = [[0, 10], [1, 10], [2, 20], [3, 20], [4, 10], [5, 10], [6, 20], [7, 20], [8, 10], [9, 10]]) == [0, 1, 1, 2, 2, 3, 3, 4, 4, 5]\n assert candidate(n = 5,queries = [[0, 1], [1, 2], [2, 1], [1, 1], [2, 1], [3, 2], [4, 2], [3, 2], [4, 2]]) == [0, 0, 0, 2, 2, 2, 3, 3, 3]\n assert candidate(n = 8,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 2], [5, 2], [6, 2], [7, 2], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1]]) == [0, 1, 2, 3, 3, 4, 5, 6, 6, 6, 6, 6, 7]\n assert candidate(n = 20,queries = [[0, 1], [1, 2], [2, 1], [3, 2], [4, 1], [5, 2], [6, 1], [7, 2], [8, 1], [9, 2], [10, 1], [11, 2], [12, 1], [13, 2], [14, 1], [15, 2], [16, 1], [17, 2], [18, 1], [19, 2]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 8,queries = [[0, 1], [1, 1], [2, 1], [3, 2], [4, 2], [5, 1], [6, 1], [7, 2]]) == [0, 1, 2, 2, 3, 3, 4, 4]\n assert candidate(n = 10,queries = [[0, 1], [2, 1], [4, 1], [6, 1], [8, 1], [1, 2], [3, 2], [5, 2], [7, 2], [9, 2]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 10,queries = [[0, 1], [1, 1], [2, 2], [3, 2], [4, 1], [5, 1], [6, 2], [7, 2], [8, 1], [9, 1]]) == [0, 1, 1, 2, 2, 3, 3, 4, 4, 5]\n assert candidate(n = 15,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [14, 2], [13, 2], [12, 2], [11, 2], [10, 2], [9, 2], [8, 2], [7, 2], [6, 2], [5, 2], [4, 2], [3, 2], [2, 2], [1, 2], [0, 2]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14]\n assert candidate(n = 7,queries = [[0, 2], [1, 2], [2, 3], [3, 3], [4, 3], [5, 2], [6, 2]]) == [0, 1, 1, 2, 3, 3, 4]\n", "comparison": "exact"}, "public_tests": ["4\n[[0,2],[1,2],[3,1],[1,1],[2,1]]", "1\n[[0,100000]]"], "hints": ["Since at each query, only one element is being recolored, we just need to focus on its neighbors.", "If an element that is changed on the i-th query had the same color as its right element answer decreases by 1. Similarly contributes its left element too.", "After changing the color, if the element has the same color as its right element answer increases by 1. Similarly contributes its left element too."], "metadata": {"canonical_parameter_names": ["n", "queries"], "leetcode_dataset_entry_point": "Solution().colorTheArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:18+00:00", "tests_total": 74, "tests_dropped": 0, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def color_the_array(n, queries)", "container": null, "callable": "color_the_array", "parameters": [{"name": "n", "type": "Integer"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2673, "task_id": "make-costs-of-paths-equal-in-a-binary-tree", "difficulty": "Medium", "problem_description": "You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left child is the node 2 * i and the right child is 2 * i + 1.\n\nEach node in the tree also has a cost represented by a given 0-indexed integer array cost of size n where cost[i] is the cost of node i + 1. You are allowed to increment the cost of any node by 1 any number of times.\n\nReturn the minimum number of increments you need to make the cost of paths from the root to each leaf node equal.\n\nNote:\n\n- A perfect binary tree is a tree where each node, except the leaf nodes, has exactly 2 children.\n- The cost of a path is the sum of costs of nodes in the path.\n\nExample 1:\n\nInput: n = 7, cost = [1,5,2,2,3,3,1]\nOutput: 6\nExplanation: We can do the following increments:\n- Increase the cost of node 4 one time.\n- Increase the cost of node 3 three times.\n- Increase the cost of node 7 two times.\nEach path from the root to a leaf will have a total cost of 9.\nThe total increments we did is 1 + 3 + 2 = 6.\nIt can be shown that this is the minimum answer we can achieve.\n\nExample 2:\n\nInput: n = 3, cost = [5,3,3]\nOutput: 0\nExplanation: The two paths already have equal total costs, so no increments are needed.\n\nConstraints:\n\n- 3 <= n <= 10^5\n- n + 1 is a power of 2\n- cost.length == n\n- 1 <= cost[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 31,cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(n = 7,cost = [1, 5, 2, 2, 3, 3, 1]) == 6\n assert candidate(n = 31,cost = [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]) == 49\n assert candidate(n = 15,cost = [1, 3, 2, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7]) == 11\n assert candidate(n = 15,cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 17\n assert candidate(n = 3,cost = [5, 3, 3]) == 0\n assert candidate(n = 7,cost = [10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(n = 7,cost = [10, 9, 9, 8, 8, 8, 8]) == 0\n assert candidate(n = 31,cost = [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]) == 49\n assert candidate(n = 31,cost = [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]) == 32\n assert candidate(n = 15,cost = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 21\n assert candidate(n = 31,cost = [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, 310]) == 490\n assert candidate(n = 7,cost = [1000, 200, 300, 400, 500, 600, 700]) == 500\n assert candidate(n = 15,cost = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 21\n assert candidate(n = 15,cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 17\n assert candidate(n = 63,cost = [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, 61, 62, 63]) == 129\n assert candidate(n = 15,cost = [100, 10, 50, 20, 30, 60, 40, 70, 80, 90, 100, 110, 120, 130, 140]) == 160\n assert candidate(n = 15,cost = [1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17]) == 17\n assert candidate(n = 7,cost = [100, 200, 300, 400, 500, 600, 700]) == 500\n assert candidate(n = 31,cost = [10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 0\n assert candidate(n = 15,cost = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 10\n assert candidate(n = 127,cost = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]) == 321\n assert candidate(n = 63,cost = [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]) == 129\n assert candidate(n = 15,cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 170\n assert candidate(n = 15,cost = [1, 3, 2, 4, 5, 6, 2, 8, 9, 10, 11, 12, 13, 14, 15]) == 11\n assert candidate(n = 15,cost = [1, 3, 2, 4, 6, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 16\n assert candidate(n = 31,cost = [1, 5, 2, 2, 3, 3, 1, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == 10\n assert candidate(n = 15,cost = [1, 3, 2, 1, 3, 2, 1, 2, 3, 1, 4, 2, 3, 4, 5]) == 12\n assert candidate(n = 15,cost = [10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(n = 31,cost = [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]) == 49\n assert candidate(n = 15,cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(n = 127,cost = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]) == 321\n assert candidate(n = 63,cost = [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, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630]) == 1290\n assert candidate(n = 31,cost = [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]) == 49\n assert candidate(n = 3,cost = [100, 99, 99]) == 0\n", "comparison": "exact"}, "public_tests": ["7\n[1,5,2,2,3,3,1]", "3\n[5,3,3]"], "hints": ["The path from the root to a leaf that has the maximum cost should not be modified.", "The optimal way is to increase all other paths to make their costs equal to the path with maximum cost."], "metadata": {"canonical_parameter_names": ["n", "cost"], "leetcode_dataset_entry_point": "Solution().minIncrements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:21+00:00", "tests_total": 50, "tests_dropped": 15, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "greedy", "tree", "binary-tree"]}, "language": "ruby", "interface": {"raw_signature": "def min_increments(n, cost)", "container": null, "callable": "min_increments", "parameters": [{"name": "n", "type": "Integer"}, {"name": "cost", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2678, "task_id": "number-of-senior-citizens", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:\n\n- The first ten characters consist of the phone number of passengers.\n- The next character denotes the gender of the person.\n- The following two characters are used to indicate the age of the person.\n- The last two characters determine the seat allotted to that person.\n\nReturn the number of passengers who are strictly more than 60 years old.\n\nExample 1:\n\nInput: details = [\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]\nOutput: 2\nExplanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.\n\nExample 2:\n\nInput: details = [\"1313579440F2036\",\"2921522980M5644\"]\nOutput: 0\nExplanation: None of the passengers are older than 60.\n\nConstraints:\n\n- 1 <= details.length <= 100\n- details[i].length == 15\n- details[i] consists of digits from '0' to '9'.\n- details[i][10] is either 'M' or 'F' or 'O'.\n- The phone numbers and seat numbers of the passengers are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(details = ['0000000000M5500', '1111111111F5999', '2222222222O6100']) == 1\n assert candidate(details = ['1234567890M5999', '0987654321F6000']) == 0\n assert candidate(details = ['1111111111M5999', '2222222222F6000', '3333333333M6001']) == 0\n assert candidate(details = ['1234567890M6100', '0987654321F6501', '1122334455O6602']) == 3\n assert candidate(details = ['1234567890M6100', '0987654321F6200', '1122334455O6300']) == 3\n assert candidate(details = ['7868190130M7522', '5303914400F9211', '9273338290F4010']) == 2\n assert candidate(details = ['1111111111F5999', '2222222222M6000', '3333333333F6001']) == 0\n assert candidate(details = ['0000000000M5999', '1111111111F6000', '2222222222O6001']) == 0\n assert candidate(details = ['1234567890M6101', '0987654321F6202', '1122334455O6303']) == 3\n assert candidate(details = ['8473928467M6585', '3748293748F6143', '9374583947M8921', '2937458394F7823']) == 4\n assert candidate(details = ['8456123450M6112', '1234567890F6213', '0987654321O6314']) == 3\n assert candidate(details = ['1313579440F2036', '2921522980M5644']) == 0\n assert candidate(details = ['1234567890M6000', '0987654321F6101', '9876543210M6202', '8765432109F6303', '7654321098O6404', '6543210987M6505', '5432109876F6606', '4321098765O6707']) == 7\n assert candidate(details = ['1010101010M6011', '2020202020F6022', '3030303030O6033', '4040404040M6044', '5050505050F6055', '6060606060O6066', '7070707070M6077', '8080808080F6088', '9090909090O6099']) == 0\n assert candidate(details = ['9876543210F6101', '1111111111M6202', '2222222222O6303', '3333333333F6404', '4444444444M6505', '5555555555O6606', '6666666666F6707', '7777777777M6808', '8888888888O6909', '9999999999F7010']) == 10\n assert candidate(details = ['1111111111M4545', '2222222222F4949', '3333333333O5555', '4444444444M5959', '5555555555F6060', '6666666666O6161', '7777777777M6262', '8888888888F6363', '9999999999O6464', '0000000000M6565']) == 5\n assert candidate(details = ['9876543210F6512', '1234567890M6134', '0987654321O6600', '1122334455F5999', '5566778899M6245']) == 4\n assert candidate(details = ['9876543210F2021', '1234567890M6522', '5555555555O6623', '1111111111M6724']) == 3\n assert candidate(details = ['1234567890M5999', '0987654321F5998', '1122334455O5997', '2233445566M5996', '3344556677F5995', '4455667788O5994', '5566778899M5993', '6677889900F5992', '7788990011O5991', '8899001122M6000']) == 0\n assert candidate(details = ['1010101010F2011', '2020202020M2112', '3030303030O2213', '4040404040F2314', '5050505050M7215', '6060606060O7316']) == 2\n assert candidate(details = ['1098765432F6500', '2109876543M6601', '3210987654F6702', '4321098765M6803', '5432109876F6904']) == 5\n assert candidate(details = ['9876543210F7007', '8765432109M7108', '7654321098F7209', '6543210987M7310', '5432109876F7411', '4321098765O7512', '3210987654M7613', '2109876543F7714', '1098765432O7815']) == 9\n assert candidate(details = ['1111111111M5999', '2222222222F6000', '3333333333O6001', '4444444444M6002', '5555555555F6003', '6666666666O6004', '7777777777M6005', '8888888888F6006', '9999999999O6007', '0000000000M6008', '1111111111F6009', '2222222222O6010', '3333333333M6011', '4444444444F6012', '5555555555O6013', '6666666666M6014', '7777777777F6015', '8888888888O6016', '9999999999M6017', '0000000000F6018', '1111111111O6019']) == 0\n assert candidate(details = ['1234567890M5500', '0987654321F6600', '1122334455O6700', '2233445566M6800', '3344556677F6900', '4455667788O7000', '5566778899M7100', '6677889900F7200', '7788990011O7300', '8899001122M7400', '9900112233F7500', '0011223344O7600', '1122334455M7700', '2233445566F7800', '3344556677O7900']) == 14\n assert candidate(details = ['1234567890M6000', '0987654321F6001', '1122334455O6002', '2233445566M6003', '3344556677F6004', '4455667788O6005', '5566778899M6006', '6677889900F6007', '7788990011O6008', '8899001122M6009', '9900112233F6010']) == 0\n assert candidate(details = ['1234567890M5999', '0987654321F6101', '1122334455O7522', '2233445566M8000', '3344556677F9001']) == 4\n assert candidate(details = ['2222222222M6000', '3333333333F6001', '4444444444M5999', '5555555555O7000', '6666666666F7101']) == 2\n assert candidate(details = ['1122334455M5500', '2233445566F5601', '3344556677M5702', '4455667788F5803', '5566778899M5904', '6677889900F6005', '7788990011O6106', '8899001122M6207', '9900112233F6308', '0011223344O6409', '1122334455M6510', '2233445566F6611', '3344556677M6712', '4455667788F6813', '5566778899O6914']) == 9\n assert candidate(details = ['1234567890M5999', '0987654321F6000', '9876543210M6101', '8765432109F6202', '7654321098O6303', '6543210987M6404', '5432109876F6505', '4321098765O6606', '3210987654M6707', '2109876543F6808', '1098765432O6909', '0987654321M7010']) == 10\n assert candidate(details = ['1111111111F5555', '2222222222F5656', '3333333333F5757', '4444444444F5858', '5555555555F5959', '6666666666M6161', '7777777777M6262', '8888888888M6363', '9999999999M6464', '0000000000M6565', '1234567890M6666', '0987654321F6767', '1122334455O6868', '2233445566M6969', '3344556677F7070']) == 10\n assert candidate(details = ['9012345678M6060', '8012345678F6161', '7012345678M6262', '6012345678F6363', '5012345678O6464', '4012345678M6565', '3012345678F6666', '2012345678O6767', '1012345678M6868', '0012345678F6969', '9112345678O7070', '8112345678M7171', '7112345678F7272', '6112345678O7373', '5112345678M7474', '4112345678F7575', '3112345678O7676', '2112345678M7777', '1112345678F7878', '0112345678O7979']) == 19\n assert candidate(details = ['1010101010M6222', '2020202020F6333', '3030303030O6444', '4040404040F6555', '5050505050M6666']) == 5\n assert candidate(details = ['1111111111F6001', '2222222222M6002', '3333333333F6003', '4444444444O6004', '5555555555M6005', '6666666666F6006', '7777777777O6007', '8888888888M6008', '9999999999F6009']) == 0\n assert candidate(details = ['1234567890M5501', '0987654321F6502', '1122334455O7003', '2468013579F6204', '9753108642M6805']) == 4\n assert candidate(details = ['1111111111F6111', '2222222222M6222', '3333333333F6333', '4444444444O6444', '5555555555M6555', '6666666666F6666']) == 6\n assert candidate(details = ['1111111111F5999', '2222222222M6000', '3333333333F6001', '4444444444O6002', '5555555555M6003', '6666666666F6004', '7777777777O6005']) == 0\n assert candidate(details = ['1111111111M5999', '2222222222M6000', '3333333333F6001', '4444444444M6202', '5555555555F6303', '6666666666O6404', '7777777777M6505', '8888888888F6606', '9999999999O6707']) == 6\n assert candidate(details = ['1212121212M6777', '2121212121F6888', '3131313131O6999', '4141414141F7000', '5151515151M7111']) == 5\n assert candidate(details = ['6677889900F6060', '7788990011M6161', '8899001122O6262', '9900112233F6363', '0011223344M6464']) == 4\n assert candidate(details = ['1111111111F5022', '2222222222M6133', '3333333333O6244', '4444444444M6355', '5555555555F6466', '6666666666M6577', '7777777777F6688', '8888888888O6799', '9999999999M6800', '0000000000F6911']) == 9\n assert candidate(details = ['8888888888M7025', '7777777777F6524', '6666666666O7123', '5555555555M6322', '4444444444F6021']) == 4\n assert candidate(details = ['5432109876O6550', '6543210987F7000', '7654321098M7450', '8765432109F7500', '9876543210O7550', '0987654321M7600', '1098765432F7650', '2109876543O7700', '3210987654M7750', '4321098765F7800', '5432109876O7850']) == 11\n assert candidate(details = ['1111111111F5999', '2222222222M6000', '3333333333F6001', '4444444444M6101', '5555555555F6202', '6666666666O6303', '7777777777M6404', '8888888888F6505', '9999999999O6606']) == 6\n assert candidate(details = ['1111111111M6522', '2222222222F6633', '3333333333O6744', '4444444444M6855', '5555555555F6966']) == 5\n assert candidate(details = ['1111111111M7101', '2222222222M7202', '3333333333M7303', '4444444444M7404', '5555555555M7505', '6666666666M7606', '7777777777M7707', '8888888888M7808', '9999999999M7909', '0000000000F8080', '1234567890F8181', '0987654321F8282', '1122334455O8383', '2233445566M8484', '3344556677F8585', '4455667788M8686', '5566778899F8787', '6677889900O8888', '7788990011M8989', '8899001122F9090']) == 20\n assert candidate(details = ['0000000000F6000', '9999999999M6100', '1111111111O6001', '2222222222F5999', '3333333333M6222']) == 2\n assert candidate(details = ['9876543210M5959', '8765432109F5858', '7654321098O5757', '6543210987M5656', '5432109876F5555', '4321098765M5454', '3210987654F5353', '2109876543M5252', '1098765432F5151', '0987654321O5050']) == 0\n assert candidate(details = ['1313579440F6000', '2921522980M5999', '9876543210F7000', '0123456789M6101', '1122334455O6202']) == 3\n assert candidate(details = ['1111111111F5899', '2222222222M5900', '3333333333F6001', '4444444444O6102', '5555555555M6203', '6666666666F6304', '7777777777O6405', '8888888888M6506', '9999999999F6607', '0000000000O6708']) == 7\n assert candidate(details = ['1122334455F6767', '9988776655M6868', '4433221100F5555', '6655443322M6363', '7766554433O6464']) == 4\n assert candidate(details = ['1111111111M7000', '2222222222F6000', '3333333333F6000', '4444444444F6000', '5555555555F6000', '6666666666F6000', '7777777777F6000', '8888888888F6000', '9999999999F6000', '0000000000F6000']) == 1\n assert candidate(details = ['1231231231F5001', '3213213213M6702', '5555555555O7003', '4444444444F5504', '6666666666M5705', '7777777777O5806', '8888888888F5907', '9999999999M6008', '0000000000O6109', '1111111111F6210', '2222222222M6311', '3333333333O6412', '4444444444F6513', '5555555555M6614', '6666666666O6715']) == 9\n assert candidate(details = ['1234567890M6501', '0987654321F6402', '9876543210M6303', '8765432109F6204', '7654321098O6105', '6543210987M6006']) == 5\n assert candidate(details = ['1111111111M6500', '2222222222F7001', '3333333333O6102', '4444444444M5999', '5555555555F6603']) == 4\n assert candidate(details = ['5555555555M7000', '6666666666F7111', '7777777777O7222', '8888888888M7333', '9999999999F7444']) == 5\n assert candidate(details = ['8888888888F7222', '7777777777M7333', '6666666666O7444', '5555555555F7555', '4444444444M7666']) == 5\n assert candidate(details = ['1234567890M6111', '0987654321F6222', '1122334455O6333', '2233445566M6444', '3344556677F6555', '4455667788O6666', '5566778899M6777']) == 7\n assert candidate(details = ['0000000000F6010', '1111111111M6011', '2222222222F6012', '3333333333O6013', '4444444444M6014', '5555555555F6015', '6666666666O6016', '7777777777M6017', '8888888888F6018', '9999999999O6019']) == 0\n assert candidate(details = ['1122334455F7890', '2233445566M7901', '3344556677O8012', '4455667788F8123', '5566778899M8234']) == 5\n assert candidate(details = ['1234567890M6060', '0987654321F6161', '1122334455O6262', '2468013579F6363', '9753108642M6464', '8642097531F6565', '0864209753M6666']) == 6\n assert candidate(details = ['1111111111F5999', '2222222222M6000', '3333333333F6101', '4444444444M6202', '5555555555F6303', '6666666666M6404', '7777777777F6505', '8888888888M6606', '9999999999F6707', '0000000000M6808']) == 8\n assert candidate(details = ['1234567890M4500', '0987654321F5501', '1122334455O6502', '2233445566M7503', '3344556677F8504', '4455667788O9505']) == 4\n assert candidate(details = ['2222222222F7345', '1111111111M7456', '3333333333O7567', '4444444444F7678', '5555555555M7789']) == 5\n assert candidate(details = ['9876543210M7220', '8765432109F7521', '7654321098O7822', '6543210987M8023']) == 4\n assert candidate(details = ['1111111111M6501', '2222222222F6602', '3333333333O6703', '4444444444M6804', '5555555555F6905']) == 5\n assert candidate(details = ['1111111111F6000', '2222222222M6001', '3333333333O6002', '4444444444F6003', '5555555555M6004', '6666666666O6005', '7777777777F6006', '8888888888M6007', '9999999999O6008', '0000000000F6009']) == 0\n assert candidate(details = ['1234567890M4501', '0987654321F5502', '1122334455O6003', '2233445566M6104', '3344556677F6205', '4455667788O6306', '5566778899M6407', '6677889900F6508', '7788990011O6609', '8899001122M6710', '9900112233F6811']) == 8\n assert candidate(details = ['1234567890M6000', '0987654321F6001', '9876543210M6002', '8765432109F6003', '7654321098O6004', '6543210987M6005', '5432109876F6006', '4321098765O6007', '3210987654M6008', '2109876543F6009', '1098765432O6010', '0987654321M6011', '9876543210F6012', '8765432109O6013', '7654321098M6014', '6543210987F6015', '5432109876O6016', '4321098765M6017', '3210987654F6018', '2109876543O6019']) == 0\n assert candidate(details = ['0000000000M5999', '1111111111F6000', '2222222222M6101', '3333333333F6202', '4444444444O6303', '5555555555M6404', '6666666666F6505', '7777777777O6606', '8888888888M6707', '9999999999F6808', '0000000000O6909', '1111111111M7010', '2222222222F7111', '3333333333O7212', '4444444444M7313', '5555555555F7414', '6666666666O7515', '7777777777M7616', '8888888888F7717', '9999999999O7818']) == 18\n assert candidate(details = ['0000000000M5999', '0000000001F6000', '0000000002M6101', '0000000003F6202', '0000000004O6303', '0000000005M6404', '0000000006F6505', '0000000007O6606', '0000000008M6707', '0000000009F6808', '0000000010O6909', '0000000011M7010', '0000000012F7111', '0000000013O7212', '0000000014M7313', '0000000015F7414', '0000000016O7515', '0000000017M7616', '0000000018F7717', '0000000019O7818', '0000000020M7919']) == 19\n assert candidate(details = ['9999999999M5001', '8888888888F5502', '7777777777O5903', '6666666666M6004', '5555555555F6105']) == 1\n assert candidate(details = ['1234567890M5999', '1234567891F6000', '1234567892M6001', '1234567893F6002', '1234567894O6003', '1234567895M6004', '1234567896F6005', '1234567897O6006', '1234567898M6007', '1234567899F6008', '1234567800O6009', '1234567801M6010', '1234567802F6011', '1234567803O6012', '1234567804M6013', '1234567805F6014', '1234567806O6015', '1234567807M6016', '1234567808F6017', '1234567809O6018']) == 0\n assert candidate(details = ['1234567890M6000', '0987654321F6101', '1122334455O6202', '2233445566M6303', '3344556677F6404', '4455667788O6505', '5566778899M6606', '6677889900F6707', '7788990011O6808', '8899001122M6909', '9900112233F7010', '0011223344O7111', '1122334455M7212', '2233445566F7313', '3344556677O7414', '4455667788M7515', '5566778899F7616', '6677889900O7717', '7788990011M7818', '8899001122F7919', '9900112233O8020']) == 20\n assert candidate(details = ['1234567890M5959', '0987654321F6000', '1122334455O6001', '9876543210M7002', '8765432109F6103', '7654321098O7504']) == 3\n assert candidate(details = ['0123456789F5899', '9876543210M5998', '1357924680O6097', '8642097531F6196', '0864209753M6295', '1975308642F6394', '2097531864O6493']) == 4\n assert candidate(details = ['5555555555F5900', '6666666666M6001', '7777777777F6102', '8888888888O6203', '9999999999M6304', '0000000000F6405', '1111111111O6506']) == 5\n assert candidate(details = ['0000000000M5999', '1111111111F6000', '2222222222O6100', '3333333333M6200', '4444444444F6300', '5555555555O6400', '6666666666M6500', '7777777777F6600', '8888888888O6700', '9999999999M6800', '0102030405F6900']) == 9\n assert candidate(details = ['0000000000F2000', '1111111111M2101', '2222222222F2202', '3333333333O2303', '4444444444M2404', '5555555555F6105']) == 1\n", "comparison": "exact"}, "public_tests": ["[\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]", "[\"1313579440F2036\",\"2921522980M5644\"]"], "hints": ["Convert the value at index 11 and 12 to a numerical value.", "The age of the person at index i is equal to details[i][11]*10+details[i][12]."], "metadata": {"canonical_parameter_names": ["details"], "leetcode_dataset_entry_point": "Solution().countSeniors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:23+00:00", "tests_total": 78, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string"]}, "language": "ruby", "interface": {"raw_signature": "def count_seniors(details)", "container": null, "callable": "count_seniors", "parameters": [{"name": "details", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2679, "task_id": "sum-in-a-matrix", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:\n\n1. From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.\n2. Identify the highest number amongst all those removed in step 1. Add that number to your score.\n\nReturn the final score.\n\nExample 1:\n\nInput: nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]\nOutput: 15\nExplanation: In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.\n\nExample 2:\n\nInput: nums = [[1]]\nOutput: 1\nExplanation: We remove 1 and add it to the answer. We return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 300\n- 1 <= nums[i].length <= 500\n- 0 <= nums[i][j] <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [[1]]) == 1\n assert candidate(nums = [[5, 4, 3], [1, 2, 3], [3, 2, 1]]) == 12\n assert candidate(nums = [[5, 3, 1], [4, 2, 1], [3, 2, 1]]) == 9\n assert candidate(nums = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(nums = [[10, 6, 9, 1], [7, 5, 8, 2], [12, 11, 10, 3]]) == 36\n assert candidate(nums = [[3, 1, 4], [1, 5, 9], [2, 6, 5]]) == 16\n assert candidate(nums = [[100, 99, 98], [97, 96, 95], [94, 93, 92]]) == 297\n assert candidate(nums = [[10, 20, 30], [5, 15, 25], [1, 2, 3]]) == 60\n assert candidate(nums = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 24\n assert candidate(nums = [[5, 4, 3], [8, 7, 6], [9, 8, 7]]) == 24\n assert candidate(nums = [[5, 2, 3], [1, 6, 4], [7, 8, 9]]) == 24\n assert candidate(nums = [[7, 2, 1], [6, 4, 2], [6, 5, 3], [3, 2, 1]]) == 15\n assert candidate(nums = [[1, 2], [3, 4], [5, 6]]) == 11\n assert candidate(nums = [[3, 6, 9, 12], [2, 5, 8, 11], [1, 4, 7, 10]]) == 30\n assert candidate(nums = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == 25\n assert candidate(nums = [[10, 10, 10], [10, 10, 10], [10, 10, 10]]) == 30\n assert candidate(nums = [[10, 6, 9, 1], [7, 5, 8, 1], [4, 3, 7, 1]]) == 26\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]]) == 579\n assert candidate(nums = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 39\n assert candidate(nums = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [0, 11, 12, 13, 14], [15, 16, 17, 18, 19]]) == 85\n assert candidate(nums = [[10, 20, 30], [5, 15, 25], [1, 11, 21], [6, 16, 26], [11, 21, 31]]) == 63\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == 155\n assert candidate(nums = [[300, 200, 100, 0], [250, 150, 50, 0], [200, 100, 0, 0], [150, 50, 0, 0]]) == 600\n assert candidate(nums = [[5, 3, 8], [2, 6, 9], [1, 7, 4], [10, 1, 12], [11, 0, 13]]) == 27\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]]) == 25\n assert candidate(nums = [[100, 200, 300], [50, 150, 250], [10, 80, 160]]) == 600\n assert candidate(nums = [[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\n assert candidate(nums = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 4\n assert candidate(nums = [[9, 8, 7, 6, 5], [4, 3, 2, 1, 0], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1]]) == 40\n assert candidate(nums = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2]]) == 6\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]]) == 5\n assert candidate(nums = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0\n assert candidate(nums = [[500, 501, 502, 503, 504, 505, 506, 507, 508, 509], [510, 511, 512, 513, 514, 515, 516, 517, 518, 519], [520, 521, 522, 523, 524, 525, 526, 527, 528, 529]]) == 5245\n assert candidate(nums = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [9, 8, 7, 6, 5]]) == 150\n assert candidate(nums = [[9, 7, 5, 3, 1], [8, 6, 4, 2, 0], [7, 5, 3, 1, 0]]) == 25\n assert candidate(nums = [[100, 99, 98, 97], [96, 95, 94, 93], [92, 91, 90, 89], [88, 87, 86, 85]]) == 394\n assert candidate(nums = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [9, 8, 7, 6, 5]]) == 36\n assert candidate(nums = [[3, 2, 1], [2, 1, 0], [1, 0, 0], [0, 0, 0]]) == 6\n assert candidate(nums = [[9, 8, 7], [6, 5, 4], [3, 2, 1], [0, 0, 0], [0, 0, 0]]) == 24\n assert candidate(nums = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41], [0, 10, 20, 30, 40]]) == 150\n assert candidate(nums = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19], [21, 23, 25, 27, 29], [31, 33, 35, 37, 39]]) == 175\n assert candidate(nums = [[50, 25, 0], [49, 24, 1], [48, 23, 2], [47, 22, 3], [46, 21, 4]]) == 79\n assert candidate(nums = [[9, 7, 5, 3, 1], [8, 6, 4, 2, 0], [9, 8, 7, 6, 5], [4, 3, 2, 1, 0]]) == 35\n assert candidate(nums = [[100, 200, 300, 400], [400, 300, 200, 100], [1, 2, 3, 4], [4, 3, 2, 1]]) == 1000\n assert candidate(nums = [[100, 200, 300, 400], [150, 250, 350, 450], [125, 225, 325, 425], [175, 275, 375, 475]]) == 1300\n assert candidate(nums = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 20\n assert candidate(nums = [[15, 20, 25, 30], [14, 19, 24, 29], [13, 18, 23, 28], [12, 17, 22, 27], [11, 16, 21, 26]]) == 90\n assert candidate(nums = [[300, 299, 298, 297, 296, 295, 294, 293, 292, 291], [290, 289, 288, 287, 286, 285, 284, 283, 282, 281], [280, 279, 278, 277, 276, 275, 274, 273, 272, 271], [270, 269, 268, 267, 266, 265, 264, 263, 262, 261], [260, 259, 258, 257, 256, 255, 254, 253, 252, 251], [250, 249, 248, 247, 246, 245, 244, 243, 242, 241], [240, 239, 238, 237, 236, 235, 234, 233, 232, 231], [230, 229, 228, 227, 226, 225, 224, 223, 222, 221], [220, 219, 218, 217, 216, 215, 214, 213, 212, 211], [210, 209, 208, 207, 206, 205, 204, 203, 202, 201]]) == 2955\n assert candidate(nums = [[300, 200, 100], [299, 199, 99], [298, 198, 98], [297, 197, 97], [296, 196, 96]]) == 600\n assert candidate(nums = [[3, 2, 1], [6, 5, 4], [9, 8, 7], [12, 11, 10], [15, 14, 13], [18, 17, 16], [21, 20, 19]]) == 60\n assert candidate(nums = [[500, 400, 300, 200, 100], [499, 399, 299, 199, 99], [498, 398, 298, 198, 98], [497, 397, 297, 197, 97]]) == 1500\n assert candidate(nums = [[100, 99, 98], [97, 96, 95], [94, 93, 92], [91, 90, 89]]) == 297\n assert candidate(nums = [[5, 5, 5, 5, 5], [4, 4, 4, 4, 4], [3, 3, 3, 3, 3], [2, 2, 2, 2, 2], [1, 1, 1, 1, 1]]) == 25\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]]) == 10\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 55\n assert candidate(nums = [[1000, 900, 800], [700, 600, 500], [400, 300, 200], [100, 0, 1]]) == 2700\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]]) == 110\n assert candidate(nums = [[9, 5, 1, 8], [7, 4, 2, 6], [3, 8, 6, 4], [10, 3, 7, 5]]) == 26\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]]) == 20\n assert candidate(nums = [[3], [2], [1], [4], [5], [6]]) == 6\n assert candidate(nums = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0\n assert candidate(nums = [[999, 1000, 998, 997, 996], [995, 994, 993, 992, 991], [990, 989, 988, 987, 986], [985, 984, 983, 982, 981]]) == 4990\n assert candidate(nums = [[1, 1000, 999], [2, 998, 997], [3, 996, 995], [4, 994, 993], [5, 992, 991]]) == 2004\n assert candidate(nums = [[1000, 500, 250, 125, 62, 31, 15, 7, 3, 1], [999, 499, 249, 124, 62, 31, 15, 7, 3, 1], [998, 498, 248, 124, 62, 31, 15, 7, 3, 1], [997, 497, 247, 123, 61, 31, 15, 7, 3, 1]]) == 1994\n assert candidate(nums = [[500, 499, 498, 497, 496, 495, 494, 493, 492, 491], [490, 489, 488, 487, 486, 485, 484, 483, 482, 481], [480, 479, 478, 477, 476, 475, 474, 473, 472, 471]]) == 4955\n assert candidate(nums = [[5, 10, 15, 20, 25], [25, 20, 15, 10, 5], [30, 35, 40, 45, 50], [50, 45, 40, 35, 30], [55, 60, 65, 70, 75]]) == 325\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]]) == 55\n assert candidate(nums = [[1000, 0, 0], [0, 1000, 0], [0, 0, 1000]]) == 1000\n assert candidate(nums = [[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1, 6, 9, 3, 9, 9, 3, 7, 5, 1, 0, 5, 8, 2, 0, 9, 7, 4, 9, 4, 4, 5, 9, 2, 3, 0, 7, 8, 1, 6, 4, 0, 6, 2, 8, 6, 2, 0, 8, 9, 9, 8, 6, 2, 8, 0, 3, 4, 8, 2, 5, 3, 4, 2, 1, 1, 7, 0, 1, 0, 5, 3, 0, 9, 8, 9, 9, 9, 0, 1, 2, 3, 8, 5, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1, 6, 9, 3, 9, 9, 3, 7, 5, 1, 0, 5, 8, 2, 0, 9, 7, 4, 9, 4, 4, 5, 9, 2, 3, 0, 7, 8, 1, 6, 4, 0, 6, 2, 8, 6, 2, 0, 8, 9, 9, 8, 6, 2, 8]]) == 835\n assert candidate(nums = [[3, 1, 4, 1, 5], [9, 2, 6, 5, 3], [5, 8, 9, 7, 9], [2, 6, 5, 3, 5]]) == 38\n assert candidate(nums = [[5, 15, 25, 35], [10, 20, 30, 40], [15, 25, 35, 45], [20, 30, 40, 50]]) == 140\n assert candidate(nums = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [20, 10, 40, 30, 50], [30, 50, 10, 40, 20], [40, 30, 50, 20, 10]]) == 150\n assert candidate(nums = [[15, 25, 5, 10], [30, 20, 25, 15], [5, 5, 5, 5], [40, 10, 30, 20]]) == 105\n assert candidate(nums = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 9, 8, 7, 6, 5, 4, 3, 2]]) == 54\n assert candidate(nums = [[300, 200, 100], [250, 150, 50], [200, 100, 0], [150, 50, 0]]) == 600\n assert candidate(nums = [[999, 998, 997], [996, 995, 994], [993, 992, 991], [990, 989, 988], [987, 986, 985]]) == 2994\n assert candidate(nums = [[10, 20], [20, 10], [30, 40], [40, 30], [50, 60], [60, 50], [70, 80], [80, 70]]) == 150\n assert candidate(nums = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 55\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]]) == 25\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 4, 6, 8, 10, 1, 3, 5, 7, 9], [9, 7, 5, 3, 1, 10, 8, 6, 4, 2]]) == 55\n assert candidate(nums = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 4\n assert candidate(nums = [[300, 200, 100], [299, 199, 99], [298, 198, 98], [297, 197, 97], [296, 196, 96], [295, 195, 95], [294, 194, 94], [293, 193, 93], [292, 192, 92], [291, 191, 91]]) == 600\n assert candidate(nums = [[10, 20, 30], [30, 20, 10], [10, 30, 20]]) == 60\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]]) == 275\n assert candidate(nums = [[1000, 999, 998, 997], [996, 995, 994, 993], [992, 991, 990, 989], [988, 987, 986, 985], [984, 983, 982, 981]]) == 3994\n assert candidate(nums = [[1, 1000], [1, 999], [1, 998], [1, 997], [1, 996], [1, 995], [1, 994], [1, 993], [1, 992], [1, 991], [1, 990], [1, 989], [1, 988], [1, 987], [1, 986], [1, 985], [1, 984], [1, 983], [1, 982], [1, 981]]) == 1001\n assert candidate(nums = [[9, 15, 3, 11], [8, 14, 4, 12], [7, 13, 5, 10], [6, 10, 6, 9], [5, 9, 7, 8], [4, 8, 8, 7], [3, 7, 9, 6], [2, 6, 10, 5], [1, 5, 11, 4]]) == 42\n assert candidate(nums = [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]) == 4\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 55\n assert candidate(nums = [[100, 101, 102, 103, 104], [200, 201, 202, 203, 204], [300, 301, 302, 303, 304], [400, 401, 402, 403, 404], [500, 501, 502, 503, 504]]) == 2510\n assert candidate(nums = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15]]) == 65\n assert candidate(nums = [[99, 98, 97], [96, 95, 94], [93, 92, 91], [90, 89, 88], [87, 86, 85]]) == 294\n assert candidate(nums = [[1, 1000, 1], [1, 1000, 1], [1, 1000, 1], [1, 1000, 1], [1, 1000, 1]]) == 1002\n assert candidate(nums = [[100, 200, 300], [50, 150, 250], [20, 120, 220], [10, 110, 210]]) == 600\n assert candidate(nums = [[100, 200, 300], [90, 180, 270], [80, 160, 240], [70, 140, 210], [60, 120, 180], [50, 100, 150]]) == 600\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]]) == 255\n assert candidate(nums = [[999, 998, 997, 996, 995, 994, 993, 992, 991, 990], [989, 988, 987, 986, 985, 984, 983, 982, 981, 980], [979, 978, 977, 976, 975, 974, 973, 972, 971, 970]]) == 9945\n assert candidate(nums = [[50, 40, 30, 20, 10], [51, 41, 31, 21, 11], [52, 42, 32, 22, 12], [53, 43, 33, 23, 13], [54, 44, 34, 24, 14], [55, 45, 35, 25, 15], [56, 46, 36, 26, 16], [57, 47, 37, 27, 17], [58, 48, 38, 28, 18], [59, 49, 39, 29, 19]]) == 195\n assert candidate(nums = [[100, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 100], [100, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 100], [21, 22, 23, 24, 25, 100]]) == 215\n assert candidate(nums = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == 10\n", "comparison": "exact"}, "public_tests": ["[[7,2,1],[6,4,2],[6,5,3],[3,2,1]]", "[[1]]"], "hints": ["Sort the numbers in each row in decreasing order.", "The answer is the summation of the max number in every column after sorting the rows."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().matrixSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:25+00:00", "tests_total": 103, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "sorting", "heap-priority-queue", "matrix", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def matrix_sum(nums)", "container": null, "callable": "matrix_sum", "parameters": [{"name": "nums", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2680, "task_id": "maximum-or", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.\n\nReturn the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times.\n\nNote that a | b denotes the bitwise or between two integers a and b.\n\nExample 1:\n\nInput: nums = [12,9], k = 1\nOutput: 30\nExplanation: If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.\n\nExample 2:\n\nInput: nums = [8,1,2], k = 2\nOutput: 35\nExplanation: If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 31\n assert candidate(nums = [1, 2, 4, 8, 16],k = 3) == 143\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 8) == 256554748416\n assert candidate(nums = [3, 5, 7, 9],k = 4) == 151\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 11) == 10245\n assert candidate(nums = [5, 10, 15],k = 5) == 495\n assert candidate(nums = [1, 2, 4, 8],k = 3) == 71\n assert candidate(nums = [31, 15, 7, 3, 1],k = 7) == 3983\n assert candidate(nums = [127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127],k = 15) == 4161663\n assert candidate(nums = [8, 1, 2],k = 2) == 35\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 9231\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 13) == 253983\n assert candidate(nums = [1000000000],k = 15) == 32768000000000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 12) == 118815\n assert candidate(nums = [1, 1000000000, 1],k = 5) == 32000000001\n assert candidate(nums = [1, 1, 1, 1, 1],k = 6) == 65\n assert candidate(nums = [2, 4, 6, 8, 10],k = 10) == 10254\n assert candidate(nums = [9, 18, 27, 36],k = 13) == 294939\n assert candidate(nums = [11, 22, 33, 44, 55],k = 14) == 901183\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 = 9) == 513\n assert candidate(nums = [12, 9],k = 1) == 30\n assert candidate(nums = [1024, 512, 256],k = 5) == 33536\n assert candidate(nums = [7, 11, 13, 17],k = 7) == 2191\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 5125\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 11) == 2098174\n assert candidate(nums = [3, 3, 3, 3],k = 4) == 51\n assert candidate(nums = [63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63],k = 14) == 1032255\n assert candidate(nums = [13, 14, 15, 16],k = 9) == 8207\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 6) == 455\n assert candidate(nums = [1023, 512, 256, 128, 64],k = 7) == 131008\n assert candidate(nums = [6, 12, 18, 24, 30],k = 15) == 983070\n assert candidate(nums = [7, 14, 21, 28],k = 12) == 114719\n assert candidate(nums = [1000000000, 500000000, 250000000],k = 8) == 256086374272\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],k = 8) == 12607\n assert candidate(nums = [21, 42, 84, 168, 336, 672, 1344, 2688, 5376, 10752],k = 7) == 1384447\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127],k = 10) == 67108863\n assert candidate(nums = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 13) == 8590983167\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333],k = 10) == 3416063\n assert candidate(nums = [13, 26, 52, 104, 208, 416, 832, 1664, 3328, 6656],k = 15) == 218107903\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 5) == 16895\n assert candidate(nums = [987654321, 876543219, 765432198, 654321987, 543219876],k = 8) == 253403069943\n assert candidate(nums = [987654321, 123456789, 876543210, 98765432, 8765432, 765432, 65432, 5432, 432, 32],k = 10) == 1011464798207\n assert candidate(nums = [15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143],k = 10) == 268435455\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 15) == 16777727\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 10) == 92287\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],k = 7) == 128849005055\n assert candidate(nums = [3, 5, 9, 15, 31, 63, 127, 255, 511, 1023],k = 10) == 1048063\n assert candidate(nums = [31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],k = 3) == 255\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 15) == 32768452971519\n assert candidate(nums = [31, 15, 7, 3, 1],k = 15) == 1015823\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095],k = 10) == 4194303\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 12) == 127007\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576],k = 12) == 4296015870\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000],k = 5) == 32142772737\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],k = 7) == 126701535231\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],k = 10) == 1011464798207\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 2048, 4096, 8192, 16384],k = 13) == 134234111\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 8) == 257020\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 15) == 2147483647\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 2097151\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 15) == 33555455\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 10) == 30751\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 1) == 27\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55],k = 7) == 7103\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 14) == 16778239\n assert candidate(nums = [23, 47, 94, 188, 376, 752, 1504, 3008, 6016, 12032],k = 5) == 393215\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576],k = 14) == 17180917758\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 32764\n assert candidate(nums = [131071, 262143, 524287, 1048575],k = 12) == 4294967295\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 10) == 1024278055424\n assert candidate(nums = [999999999, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89],k = 15) == 32768016775167\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900],k = 8) == 231420\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 10) == 1024349700095\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 5) == 1023\n assert candidate(nums = [536870911, 268435455, 134217727, 67108863, 33554431],k = 10) == 549755813887\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 15) == 17180392448\n assert candidate(nums = [233, 322, 411, 500, 599, 688, 777, 866, 955],k = 5) == 30719\n assert candidate(nums = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 10) == 1074790399\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930],k = 8) == 72613887\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],k = 12) == 4096318765567\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 4) == 24572\n assert candidate(nums = [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, 101, 103, 107, 109, 113],k = 15) == 3702911\n assert candidate(nums = [13, 29, 41, 53, 67, 83, 97],k = 12) == 397439\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767],k = 15) == 1073725439\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 10) == 524799\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 8) == 262143\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 10) == 1049599\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 335\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13],k = 3) == 109\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 12) == 67125247\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555],k = 15) == 32768452984571\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999],k = 15) == 32768452971007\n assert candidate(nums = [131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 14) == 2147614719\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765],k = 10) == 6930431\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 7) == 128312147936\n assert candidate(nums = [1023, 2047, 4095, 8191],k = 10) == 8388607\n assert candidate(nums = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 14) == 8389119\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255],k = 14) == 4178175\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 12) == 268435455\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999],k = 5) == 32142786559\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383],k = 3) == 131071\n assert candidate(nums = [123456789, 987654321, 135792468, 246813579, 864201357],k = 5) == 32212254719\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 = 10) == 20511\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 12) == 204863\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000],k = 10) == 1024349700088\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 491535\n assert candidate(nums = [123456789, 987654321, 135792468, 246813579, 369258147],k = 15) == 32363652317183\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 8) == 38654\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984, 3968, 7936, 15872],k = 5) == 516095\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 14) == 1474687\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765],k = 13) == 55427071\n", "comparison": "exact"}, "public_tests": ["[12,9]\n1", "[8,1,2]\n2"], "hints": ["The optimal solution should apply all the k operations on a single number.", "Calculate the prefix or and the suffix or and perform k operations over each element, and maximize the answer."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumOr", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:28+00:00", "tests_total": 114, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "greedy", "bit-manipulation", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_or(nums, k)", "container": null, "callable": "maximum_or", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2681, "task_id": "power-of-heroes", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:\n\n- Let i_0, i_1, ... ,i_k be the indices of the heroes in a group. Then, the power of this group is max(nums[i_0], nums[i_1], ... ,nums[i_k])^2 * min(nums[i_0], nums[i_1], ... ,nums[i_k]).\n\nReturn the sum of the power of all non-empty groups of heroes possible. Since the sum could be very large, return it modulo 10^9+ 7.\n\nExample 1:\n\nInput: nums = [2,1,4]\nOutput: 141\nExplanation:\n1^st group: [2] has power = 2^2 * 2 = 8.\n2^nd group: [1] has power = 1^2 * 1 = 1.\n3^rd group: [4] has power = 4^2 * 4 = 64.\n4^th group: [2,1] has power = 2^2 * 1 = 4.\n5^th group: [2,4] has power = 4^2 * 2 = 32.\n6^th group: [1,4] has power = 4^2 * 1 = 16.\n7^th group: [2,1,4] has power = 4^2 * 1 = 16.\nThe sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.\n\nExample 2:\n\nInput: nums = [1,1,1]\nOutput: 7\nExplanation: A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 5, 7, 2]) == 1627\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1000000000]) == 999999664\n assert candidate(nums = [3, 2, 5, 6]) == 1253\n assert candidate(nums = [3, 5, 2, 8]) == 2081\n assert candidate(nums = [2, 4, 6, 8, 10]) == 8728\n assert candidate(nums = [2, 1, 4]) == 141\n assert candidate(nums = [1, 1, 1]) == 7\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 999997606\n assert candidate(nums = [10, 20, 30, 40, 50]) == 1091000\n assert candidate(nums = [3, 2, 1]) == 76\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 169593\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1091\n assert candidate(nums = [10, 9, 8, 7, 6]) == 18136\n assert candidate(nums = [1, 3, 5, 7, 9]) == 5091\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 169593\n assert candidate(nums = [5, 5, 5, 5]) == 1875\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 166909229\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 903174621\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 157911835\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 36487\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 592998817\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 832697741\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 737896832\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 161550\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 67293\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000]) == 917238506\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 1328831\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12974882\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]) == 531216836\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 106980543\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 393212152\n assert candidate(nums = [500000000, 500000001, 500000002, 500000003, 500000004, 500000005]) == 124999698\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 230175231\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 26056\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 1023000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 12974882\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 1]) == 790083522\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 294671159\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 998989732\n assert candidate(nums = [29, 23, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137]) == 238366021\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 350889\n assert candidate(nums = [5, 2, 8, 3, 6]) == 4581\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993]) == 8160960\n assert candidate(nums = [999999999, 1, 999999998, 2, 999999997, 3, 999999996, 4, 999999995, 5]) == 113649\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500]) == 738979242\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 131265795\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 686474720\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 131265795\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993]) == 999864374\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 998644298\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]) == 2097151\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 169593\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 998989732\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 234860208\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]) == 788917595\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 381440876\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 113709125\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 127875\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]) == 991029025\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 761263300\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 686474720\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 13545400\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]) == 328693133\n assert candidate(nums = [999999937, 999999938, 999999939, 999999940, 999999941]) == 990418583\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 282942875\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 9123243\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 473671145\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 661581886\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 999649118\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 169593000\n assert candidate(nums = [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]) == 273859741\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 12974882\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 263294673\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 90106358\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683]) == 751798588\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 761263300\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 169593\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5]) == 16421\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 473671145\n assert candidate(nums = [500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000]) == 874956145\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 67293\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 331646057\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 210, 311, 412, 513, 614, 715, 816, 917, 1018, 1119]) == 219998389\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 975216922\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 169593000\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 127875\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994]) == 999900627\n assert candidate(nums = [2, 5, 3, 10, 1, 8, 4]) == 18451\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 974881916\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 1000000000]) == 56941830\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 4095875\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000]) == 36487\n", "comparison": "exact"}, "public_tests": ["[2,1,4]", "[1,1,1]"], "hints": ["Try something with sorting the array.", "For a pair of array elements nums[i] and nums[j] (i < j), the power would be nums[i]*nums[j]^2 regardless of how many elements in between are included.", "The number of subsets with the above as power will correspond to 2^(j-i-1).", "Try collecting the terms for nums[0], nums[1], …, nums[j-1] when computing the power of heroes ending at index j to get the power in a single pass."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumOfPower", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:30+00:00", "tests_total": 93, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "dynamic-programming", "sorting", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_power(nums)", "container": null, "callable": "sum_of_power", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2682, "task_id": "find-the-losers-of-the-circular-game", "difficulty": "Easy", "problem_description": "There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend.\n\nThe rules of the game are as follows:\n\n1^st friend receives the ball.\n\n- After that, 1^st friend passes it to the friend who is k steps away from them in the clockwise direction.\n- After that, the friend who receives the ball should pass it to the friend who is 2 * k steps away from them in the clockwise direction.\n- After that, the friend who receives the ball should pass it to the friend who is 3 * k steps away from them in the clockwise direction, and so on and so forth.\n\nIn other words, on the i^th turn, the friend holding the ball should pass it to the friend who is i * k steps away from them in the clockwise direction.\n\nThe game is finished when some friend receives the ball for the second time.\n\nThe losers of the game are friends who did not receive the ball in the entire game.\n\nGiven the number of friends, n, and an integer k, return the array answer, which contains the losers of the game in the ascending order.\n\nExample 1:\n\nInput: n = 5, k = 2\nOutput: [4,5]\nExplanation: The game goes as follows:\n1) Start at 1^st friend and pass the ball to the friend who is 2 steps away from them - 3^rd friend.\n2) 3^rd friend passes the ball to the friend who is 4 steps away from them - 2^nd friend.\n3) 2^nd friend passes the ball to the friend who is 6 steps away from them - 3^rd friend.\n4) The game ends as 3^rd friend receives the ball for the second time.\n\nExample 2:\n\nInput: n = 4, k = 4\nOutput: [2,3,4]\nExplanation: The game goes as follows:\n1) Start at the 1^st friend and pass the ball to the friend who is 4 steps away from them - 1^st friend.\n2) The game ends as 1^st friend receives the ball for the second time.\n\nConstraints:\n\n- 1 <= k <= n <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,k = 5) == [2, 3, 4, 5, 7, 8, 9, 10]\n assert candidate(n = 4,k = 4) == [2, 3, 4]\n assert candidate(n = 5,k = 2) == [4, 5]\n assert candidate(n = 7,k = 3) == [2, 6, 7]\n assert candidate(n = 6,k = 1) == [3, 5, 6]\n assert candidate(n = 10,k = 3) == [2, 3, 5, 6, 7, 8]\n assert candidate(n = 7,k = 5) == [4, 5, 7]\n assert candidate(n = 40,k = 9) == [2, 3, 4, 7, 8, 9, 12, 14, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]\n assert candidate(n = 35,k = 17) == [2, 3, 4, 5, 6, 7, 9, 10, 12, 13, 14, 15, 16, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 35]\n assert candidate(n = 22,k = 7) == [2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 19, 20]\n assert candidate(n = 37,k = 5) == [3, 7, 10, 11, 13, 18, 19, 20, 22, 23, 24, 25, 27, 28, 29, 34, 36, 37]\n assert candidate(n = 15,k = 14) == [2, 3, 4, 5, 7, 8, 9, 11, 12, 14]\n assert candidate(n = 35,k = 6) == [3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 23, 24, 25, 27, 28, 30, 31, 32, 33, 34, 35]\n assert candidate(n = 28,k = 10) == [2, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]\n assert candidate(n = 50,k = 1) == [3, 5, 8, 9, 10, 12, 13, 14, 15, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50]\n assert candidate(n = 20,k = 19) == [2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 17, 19]\n assert candidate(n = 40,k = 15) == [2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 25, 27, 28, 29, 30, 32, 33, 34, 35, 37, 38, 39, 40]\n assert candidate(n = 25,k = 7) == [2, 3, 4, 5, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 24, 25]\n assert candidate(n = 25,k = 10) == [2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n assert candidate(n = 35,k = 12) == [4, 5, 7, 9, 10, 11, 12, 14, 15, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]\n assert candidate(n = 50,k = 7) == [2, 4, 5, 7, 9, 10, 11, 12, 14, 15, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 44, 45, 46, 49, 50]\n assert candidate(n = 20,k = 11) == [2, 3, 4, 5, 8, 9, 10, 13, 15, 16, 17, 18, 19, 20]\n assert candidate(n = 30,k = 9) == [2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 29, 30]\n assert candidate(n = 49,k = 16) == [2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 39, 40, 41, 42, 44, 46, 47]\n assert candidate(n = 12,k = 8) == [2, 3, 4, 5, 6, 7, 8, 10, 11, 12]\n assert candidate(n = 30,k = 7) == [2, 3, 4, 5, 6, 7, 9, 10, 12, 14, 15, 18, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30]\n assert candidate(n = 40,k = 20) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]\n assert candidate(n = 50,k = 10) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n assert candidate(n = 18,k = 6) == [2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]\n assert candidate(n = 49,k = 15) == [3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 47, 48, 49]\n assert candidate(n = 17,k = 13) == [3, 4, 5, 7, 13, 15, 16, 17]\n assert candidate(n = 15,k = 4) == [2, 3, 4, 6, 7, 8, 9, 12, 14, 15]\n assert candidate(n = 18,k = 2) == [2, 4, 5, 6, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18]\n assert candidate(n = 45,k = 11) == [2, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 35, 36, 38, 40, 41, 42, 43, 44, 45]\n assert candidate(n = 45,k = 10) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45]\n assert candidate(n = 45,k = 8) == [2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 33, 35, 37, 38, 39, 40, 41, 42, 43, 44]\n assert candidate(n = 45,k = 13) == [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 15, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 42, 43, 44, 45]\n assert candidate(n = 38,k = 19) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38]\n assert candidate(n = 28,k = 14) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]\n assert candidate(n = 49,k = 13) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 31, 32, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48]\n assert candidate(n = 40,k = 17) == [2, 3, 4, 5, 7, 8, 9, 10, 14, 15, 17, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 39, 40]\n assert candidate(n = 49,k = 14) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49]\n assert candidate(n = 35,k = 9) == [2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27, 29, 30, 32, 33, 34, 35]\n assert candidate(n = 20,k = 7) == [4, 5, 7, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(n = 13,k = 5) == [4, 7, 8, 9, 10, 13]\n assert candidate(n = 25,k = 5) == [2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n assert candidate(n = 30,k = 6) == [2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]\n assert candidate(n = 49,k = 5) == [3, 4, 5, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49]\n assert candidate(n = 20,k = 5) == [2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20]\n assert candidate(n = 25,k = 6) == [3, 4, 5, 6, 8, 9, 10, 13, 14, 15, 17, 18, 20, 21, 22, 23, 24, 25]\n assert candidate(n = 25,k = 23) == [2, 3, 4, 5, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 22, 23, 25]\n assert candidate(n = 25,k = 9) == [2, 4, 6, 7, 8, 9, 12, 13, 14, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n assert candidate(n = 15,k = 5) == [2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(n = 40,k = 13) == [2, 3, 4, 6, 7, 8, 9, 10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 30, 31, 32, 33, 35, 37, 38]\n assert candidate(n = 40,k = 11) == [2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30, 33, 35, 36, 38, 39, 40]\n assert candidate(n = 37,k = 13) == [2, 6, 9, 10, 12, 17, 18, 19, 21, 22, 23, 24, 26, 27, 28, 33, 35, 36]\n assert candidate(n = 50,k = 13) == [2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 32, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50]\n assert candidate(n = 28,k = 13) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 16, 17, 18, 20, 21, 24, 25, 26, 27]\n assert candidate(n = 31,k = 29) == [3, 6, 10, 11, 13, 14, 16, 17, 18, 19, 23, 25, 27, 28, 29]\n assert candidate(n = 22,k = 6) == [2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 21, 22]\n assert candidate(n = 12,k = 4) == [2, 3, 4, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(n = 30,k = 8) == [2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 23, 24, 26, 27, 28, 29, 30]\n assert candidate(n = 40,k = 3) == [2, 3, 7, 8, 9, 11, 12, 13, 14, 15, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40]\n assert candidate(n = 50,k = 11) == [2, 3, 4, 5, 7, 8, 10, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 48, 49, 50]\n assert candidate(n = 30,k = 11) == [2, 3, 5, 6, 8, 10, 11, 13, 14, 15, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30]\n assert candidate(n = 18,k = 4) == [2, 3, 4, 6, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18]\n assert candidate(n = 45,k = 15) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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]\n assert candidate(n = 30,k = 17) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 17, 19, 20, 23, 24, 25, 26, 29, 30]\n assert candidate(n = 50,k = 17) == [4, 5, 7, 9, 10, 11, 12, 14, 15, 17, 19, 20, 22, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n assert candidate(n = 30,k = 29) == [2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 26, 27, 29]\n assert candidate(n = 49,k = 6) == [2, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 20, 23, 24, 25, 27, 28, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49]\n assert candidate(n = 50,k = 25) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n assert candidate(n = 48,k = 14) == [2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 16, 17, 18, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 44, 46, 47, 48]\n", "comparison": "exact"}, "public_tests": ["5\n2", "4\n4"], "hints": ["Simulate the whole game until a player receives the ball for the second time."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().circularGameLosers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:32+00:00", "tests_total": 73, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def circular_game_losers(n, k)", "container": null, "callable": "circular_game_losers", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2683, "task_id": "neighboring-bitwise-xor", "difficulty": "Medium", "problem_description": "A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.\n\nSpecifically, for each index i in the range [0, n - 1]:\n\n- If i = n - 1, then derived[i] = original[i] ⊕ original[0].\n- Otherwise, derived[i] = original[i] ⊕ original[i + 1].\n\nGiven an array derived, your task is to determine whether there exists a valid binary array original that could have formed derived.\n\nReturn true if such an array exists or false otherwise.\n\n- A binary array is an array containing only 0's and 1's\n\nExample 1:\n\nInput: derived = [1,1,0]\nOutput: true\nExplanation: A valid original array that gives derived is [0,1,0].\nderived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1\nderived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1\nderived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0\n\nExample 2:\n\nInput: derived = [1,1]\nOutput: true\nExplanation: A valid original array that gives derived is [0,1].\nderived[0] = original[0] ⊕ original[1] = 1\nderived[1] = original[1] ⊕ original[0] = 1\n\nExample 3:\n\nInput: derived = [1,0]\nOutput: false\nExplanation: There is no valid original array that gives derived.\n\nConstraints:\n\n- n == derived.length\n- 1 <= n <= 10^5\n- The values in derived are either 0's or 1's\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(derived = [0, 0, 0]) == True\n assert candidate(derived = [0, 0, 1, 1]) == True\n assert candidate(derived = [0, 1, 1, 0, 1]) == False\n assert candidate(derived = [1, 0, 1, 0]) == True\n assert candidate(derived = [0, 1, 0, 1]) == True\n assert candidate(derived = [1, 0, 0, 1]) == True\n assert candidate(derived = [0, 1, 1, 0]) == True\n assert candidate(derived = [1]) == False\n assert candidate(derived = [0]) == True\n assert candidate(derived = [1, 1, 1, 1, 1]) == False\n assert candidate(derived = [1, 0]) == False\n assert candidate(derived = [1, 1, 1, 1]) == True\n assert candidate(derived = [1, 0, 1, 0, 1]) == False\n assert candidate(derived = [1, 1]) == True\n assert candidate(derived = [0, 1, 0, 1, 0]) == True\n assert candidate(derived = [1, 1, 0]) == True\n assert candidate(derived = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == True\n assert candidate(derived = [1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1]) == False\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(derived = [0, 0, 1, 0, 1, 0, 1, 0]) == False\n assert candidate(derived = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) == True\n assert candidate(derived = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == True\n assert candidate(derived = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == True\n assert candidate(derived = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(derived = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(derived = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == True\n assert candidate(derived = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == True\n assert candidate(derived = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(derived = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == False\n assert candidate(derived = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == True\n assert candidate(derived = [0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(derived = [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, 1, 0, 1, 0]) == True\n assert candidate(derived = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0]) == True\n assert candidate(derived = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == False\n assert candidate(derived = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [1, 1, 0, 1, 0, 1, 1, 0]) == False\n assert candidate(derived = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == True\n assert candidate(derived = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(derived = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == True\n assert candidate(derived = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == True\n assert candidate(derived = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1]) == False\n assert candidate(derived = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == False\n assert candidate(derived = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == True\n assert candidate(derived = [1, 0, 1, 1, 0, 1, 1, 0]) == False\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == False\n assert candidate(derived = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(derived = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == False\n assert candidate(derived = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == True\n assert candidate(derived = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == False\n assert candidate(derived = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == True\n assert candidate(derived = [1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1]) == False\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(derived = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0]) == True\n assert candidate(derived = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == True\n assert candidate(derived = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == False\n assert candidate(derived = [1, 1, 0, 0, 1, 1, 0, 0, 1]) == False\n assert candidate(derived = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == True\n assert candidate(derived = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == False\n assert candidate(derived = [0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1]) == False\n assert candidate(derived = [0, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(derived = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == True\n assert candidate(derived = [1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == False\n assert candidate(derived = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1]) == False\n assert candidate(derived = [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]) == True\n assert candidate(derived = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(derived = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(derived = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == True\n assert candidate(derived = [1, 1, 0, 0, 1, 1, 0, 0]) == True\n assert candidate(derived = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(derived = [1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1]) == False\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == True\n assert candidate(derived = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == False\n assert candidate(derived = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == True\n assert candidate(derived = [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0]) == True\n assert candidate(derived = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == True\n assert candidate(derived = [0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1]) == True\n assert candidate(derived = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == False\n assert candidate(derived = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1]) == True\n assert candidate(derived = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == True\n assert candidate(derived = [1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1]) == True\n", "comparison": "exact"}, "public_tests": ["[1,1,0]", "[1,1]", "[1,0]"], "hints": ["Understand that from the original element, we are using each element twice to construct the derived array", "The xor-sum of the derived array should be 0 since there is always a duplicate occurrence of each element."], "metadata": {"canonical_parameter_names": ["derived"], "leetcode_dataset_entry_point": "Solution().doesValidArrayExist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:35+00:00", "tests_total": 91, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def does_valid_array_exist(derived)", "container": null, "callable": "does_valid_array_exist", "parameters": [{"name": "derived", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2684, "task_id": "maximum-number-of-moves-in-a-grid", "difficulty": "Medium", "problem_description": "You are given a 0-indexed m x n matrix grid consisting of positive integers.\n\nYou can start at any cell in the first column of the matrix, and traverse the grid in the following way:\n\n- From a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the value of the cell you move to, should be strictly bigger than the value of the current cell.\n\nReturn the maximum number of moves that you can perform.\n\nExample 1:\n\nInput: grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]\nOutput: 3\nExplanation: We can start at the cell (0, 0) and make the following moves:\n- (0, 0) -> (0, 1).\n- (0, 1) -> (1, 2).\n- (1, 2) -> (2, 3).\nIt can be shown that it is the maximum number of moves that can be made.\n\nExample 2:\n\nInput: grid = [[3,2,4],[2,1,9],[1,1,7]]\nOutput: 0\nExplanation: Starting from any cell in the first column we cannot perform any moves.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 1000\n- 4 <= m * n <= 10^5\n- 1 <= grid[i][j] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 3, 5, 7], [2, 4, 6, 8], [1, 3, 5, 7]]) == 3\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 2\n assert candidate(grid = [[10, 15, 20], [5, 9, 12], [7, 8, 10]]) == 2\n assert candidate(grid = [[5, 3, 2, 1], [4, 3, 2, 1], [5, 4, 3, 2], [4, 3, 2, 1]]) == 0\n assert candidate(grid = [[3, 2, 4], [2, 1, 9], [1, 1, 7]]) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]) == 4\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 2\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[10, 11, 16, 14, 7, 6], [9, 7, 6, 17, 4, 8], [1, 19, 5, 11, 1, 5], [14, 3, 16, 11, 22, 9]]) == 4\n assert candidate(grid = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]) == 4\n assert candidate(grid = [[2, 4, 3, 5], [5, 4, 9, 3], [3, 4, 2, 11], [10, 9, 13, 15]]) == 3\n assert candidate(grid = [[1, 20, 3, 40, 5], [10, 2, 30, 4, 50], [11, 12, 1, 40, 51], [20, 19, 30, 14, 52], [21, 22, 23, 4, 53]]) == 4\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, 3, 5, 7, 9, 2, 4, 6, 8, 10], [10, 8, 6, 4, 2, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 1, 3, 5, 7, 9], [9, 7, 5, 3, 1, 10, 8, 6, 4, 2]]) == 9\n assert candidate(grid = [[1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12], [3, 5, 7, 9, 11, 13], [4, 6, 8, 10, 12, 14]]) == 5\n assert candidate(grid = [[5, 8, 6, 7, 4, 9, 2, 3], [4, 7, 5, 6, 3, 8, 1, 2], [3, 6, 4, 5, 2, 7, 8, 9], [2, 5, 3, 4, 1, 6, 7, 8], [1, 4, 2, 3, 9, 5, 6, 7]]) == 1\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]]) == 9\n assert candidate(grid = [[9, 10, 1, 8, 2, 7, 3, 6, 4, 5], [10, 1, 8, 2, 7, 3, 6, 4, 5, 9], [1, 8, 2, 7, 3, 6, 4, 5, 9, 10], [8, 2, 7, 3, 6, 4, 5, 9, 10, 1], [2, 7, 3, 6, 4, 5, 9, 10, 1, 8], [7, 3, 6, 4, 5, 9, 10, 1, 8, 2], [3, 6, 4, 5, 9, 10, 1, 8, 2, 7], [6, 4, 5, 9, 10, 1, 8, 2, 7, 3], [4, 5, 9, 10, 1, 8, 2, 7, 3, 6], [5, 9, 10, 1, 8, 2, 7, 3, 6, 4]]) == 6\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 4, 3, 2, 1, 9, 8, 7, 6], [6, 7, 8, 9, 1, 5, 4, 3, 2], [2, 3, 1, 4, 6, 8, 7, 5, 9]]) == 8\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23], [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24], [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]]) == 10\n assert candidate(grid = [[1, 100, 200, 300, 400], [2, 99, 199, 299, 399], [3, 98, 198, 298, 398], [4, 97, 197, 297, 397], [5, 96, 196, 296, 396]]) == 4\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 9\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 1\n assert candidate(grid = [[1, 20, 19, 18, 17, 16, 15, 14, 13, 12], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18, 19, 20, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 9\n assert candidate(grid = [[1, 3, 2, 4, 5], [2, 1, 5, 3, 4], [3, 4, 6, 2, 7], [4, 5, 7, 6, 8], [5, 6, 8, 7, 9]]) == 2\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [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]]) == 9\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == 3\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 10, 19, 28, 37, 46, 55, 64, 73, 82], [3, 18, 27, 36, 45, 54, 63, 72, 81, 90], [4, 26, 35, 44, 53, 62, 71, 80, 89, 98], [5, 34, 43, 52, 61, 70, 79, 88, 97, 106], [6, 42, 51, 60, 69, 78, 87, 96, 105, 114], [7, 50, 59, 68, 77, 86, 95, 104, 113, 122], [8, 58, 67, 76, 85, 94, 103, 112, 121, 130], [9, 66, 75, 84, 93, 102, 111, 120, 129, 138], [10, 74, 83, 92, 101, 110, 119, 128, 137, 146]]) == 9\n assert candidate(grid = [[1, 100, 2, 99, 3, 98, 4, 97], [1, 96, 2, 95, 3, 94, 4, 93], [1, 92, 2, 91, 3, 90, 4, 89], [1, 88, 2, 87, 3, 86, 4, 85]]) == 1\n assert candidate(grid = [[1, 1000, 1, 1000, 1], [1000, 1, 1000, 1, 1000], [1, 1000, 1, 1000, 1], [1000, 1, 1000, 1, 1000], [1, 1000, 1, 1000, 1]]) == 1\n assert candidate(grid = [[1, 10, 20, 30, 40, 50], [10, 9, 8, 7, 6, 5], [20, 30, 40, 50, 60, 70], [30, 20, 10, 1, 2, 3]]) == 5\n assert candidate(grid = [[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3]]) == 10\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [10, 9, 8, 7, 6]]) == 4\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]]) == 4\n assert candidate(grid = [[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9], [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8], [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7], [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 8\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2], [11, 10, 9, 8, 7, 6, 5, 4, 3], [12, 11, 10, 9, 8, 7, 6, 5, 4]]) == 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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 9\n assert candidate(grid = [[1, 5, 3, 6, 2], [2, 4, 1, 2, 4], [6, 4, 7, 3, 5], [2, 4, 9, 6, 3]]) == 2\n assert candidate(grid = [[10, 20, 30, 40], [25, 35, 45, 50], [40, 50, 60, 70], [50, 60, 70, 80]]) == 3\n assert candidate(grid = [[5, 12, 15, 20, 25], [3, 10, 14, 18, 22], [1, 6, 9, 13, 17], [4, 7, 11, 16, 21], [2, 8, 12, 19, 24]]) == 4\n assert candidate(grid = [[1000000, 999999, 999998], [999997, 999996, 999995], [999994, 999993, 999992]]) == 2\n assert candidate(grid = [[5, 5, 5, 5, 5], [4, 4, 4, 4, 4], [3, 3, 3, 3, 3], [2, 2, 2, 2, 2], [1, 1, 1, 1, 1]]) == 4\n assert candidate(grid = [[1, 10, 19, 28, 37], [2, 11, 20, 29, 38], [3, 12, 21, 30, 39], [4, 13, 22, 31, 40], [5, 14, 23, 32, 41]]) == 4\n assert candidate(grid = [[1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]]) == 10\n assert candidate(grid = [[1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2]]) == 1\n assert candidate(grid = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41], [6, 16, 26, 36, 46], [11, 21, 31, 41, 51]]) == 4\n assert candidate(grid = [[5, 15, 25, 35, 45, 55], [4, 14, 24, 34, 44, 54], [3, 13, 23, 33, 43, 53], [2, 12, 22, 32, 42, 52], [1, 11, 21, 31, 41, 51], [6, 16, 26, 36, 46, 56]]) == 5\n assert candidate(grid = [[9, 11, 10, 12, 14, 13, 15, 17, 16, 18], [8, 7, 9, 10, 12, 11, 13, 15, 14, 16], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 9\n assert candidate(grid = [[9, 8, 7, 6, 5, 4], [1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 6, 5], [3, 4, 1, 2, 5, 6]]) == 5\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]]) == 9\n assert candidate(grid = [[1, 11, 21, 31, 41], [2, 12, 22, 32, 42], [3, 13, 23, 33, 43], [4, 14, 24, 34, 44], [5, 15, 25, 35, 45]]) == 4\n assert candidate(grid = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [100, 90, 80, 70, 60, 50, 40, 30, 20, 10], [11, 21, 31, 41, 51, 61, 71, 81, 91, 101], [101, 91, 81, 71, 61, 51, 41, 31, 21, 11], [12, 22, 32, 42, 52, 62, 72, 82, 92, 102], [102, 92, 82, 72, 62, 52, 42, 32, 22, 12]]) == 9\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]) == 2\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]]) == 9\n assert candidate(grid = [[9, 5, 1, 2], [10, 6, 3, 4], [11, 7, 5, 6], [12, 8, 7, 8]]) == 0\n assert candidate(grid = [[2, 3, 1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11], [11, 10, 9, 8, 7, 6, 5, 4, 3]]) == 8\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20], [5, 10, 15, 20, 25]]) == 4\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [8, 7, 6, 5, 4, 3, 2, 1, 9], [7, 6, 5, 4, 3, 2, 1, 9, 8], [6, 5, 4, 3, 2, 1, 9, 8, 7]]) == 0\n assert candidate(grid = [[5, 10, 15, 20, 25], [2, 6, 12, 18, 24], [3, 8, 13, 19, 26], [4, 9, 14, 21, 23], [7, 11, 16, 22, 27]]) == 4\n assert candidate(grid = [[10, 9, 8, 7, 6], [9, 8, 7, 6, 5], [8, 7, 6, 5, 4], [7, 6, 5, 4, 3], [6, 5, 4, 3, 2], [5, 4, 3, 2, 1]]) == 0\n assert candidate(grid = [[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]]) == 3\n assert candidate(grid = [[1, 10, 11, 12, 13, 14, 15, 16, 17, 18], [2, 9, 8, 7, 6, 5, 4, 3, 2, 1], [3, 10, 11, 12, 13, 14, 15, 16, 17, 18], [4, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 10, 11, 12, 13, 14, 15, 16, 17, 18]]) == 9\n assert candidate(grid = [[20, 21, 22, 23, 24, 25], [15, 16, 17, 18, 19, 26], [10, 11, 12, 13, 14, 27], [5, 6, 7, 8, 9, 28], [1, 2, 3, 4, 29, 30]]) == 5\n assert candidate(grid = [[5, 15, 25, 35, 45], [4, 14, 24, 34, 44], [3, 13, 23, 33, 43], [2, 12, 22, 32, 42], [1, 11, 21, 31, 41]]) == 4\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [8, 9, 10, 11, 12, 13, 14], [14, 13, 12, 11, 10, 9, 8]]) == 6\n assert candidate(grid = [[3, 3, 3, 10], [1, 1, 1, 1], [3, 3, 3, 5], [1, 1, 1, 1]]) == 1\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]]) == 9\n assert candidate(grid = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 111], [1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 112], [113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 124]]) == 10\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 19\n assert candidate(grid = [[5, 10, 15, 20, 25], [2, 7, 12, 17, 22], [1, 6, 11, 16, 21], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24]]) == 4\n assert candidate(grid = [[5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6]]) == 9\n assert candidate(grid = [[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], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]]) == 5\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]]) == 9\n assert candidate(grid = [[1, 5, 9, 13, 17, 21, 25, 29, 33, 37], [2, 6, 10, 14, 18, 22, 26, 30, 34, 38], [3, 7, 11, 15, 19, 23, 27, 31, 35, 39], [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]]) == 9\n assert candidate(grid = [[3, 1, 2, 3, 4, 5], [1, 3, 4, 5, 6, 7], [2, 4, 5, 6, 7, 8], [3, 5, 6, 7, 8, 9], [4, 6, 7, 8, 9, 10]]) == 5\n assert candidate(grid = [[5, 3, 8, 7, 9], [6, 2, 9, 5, 10], [7, 1, 10, 6, 11], [8, 4, 11, 7, 12], [9, 5, 12, 8, 13]]) == 0\n assert candidate(grid = [[5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [5, 6, 7, 8, 9], [4, 5, 6, 7, 8], [3, 4, 5, 6, 7]]) == 4\n assert candidate(grid = [[1, 2, 10, 4, 5, 6], [2, 3, 11, 5, 6, 7], [3, 4, 12, 6, 7, 8], [4, 5, 13, 7, 8, 9], [5, 6, 14, 8, 9, 10]]) == 2\n assert candidate(grid = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15], [20, 19, 18, 17, 16], [21, 22, 23, 24, 25]]) == 4\n assert candidate(grid = [[1, 10, 19, 28, 37, 46], [2, 9, 18, 27, 36, 45], [3, 8, 17, 26, 35, 44], [4, 7, 16, 25, 34, 43], [5, 6, 15, 24, 33, 42], [6, 5, 14, 23, 32, 41], [7, 4, 13, 22, 31, 40], [8, 3, 12, 21, 30, 39], [9, 2, 11, 20, 29, 38]]) == 5\n assert candidate(grid = [[1, 5, 9, 14, 20], [2, 6, 10, 15, 21], [3, 7, 11, 16, 22], [4, 8, 12, 17, 23], [5, 9, 13, 18, 24]]) == 4\n", "comparison": "exact"}, "public_tests": ["[[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]", "[[3,2,4],[2,1,9],[1,1,7]]"], "hints": ["Consider using dynamic programming to find the maximum number of moves that can be made from each cell.", "The final answer will be the maximum value in cells of the first column."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maxMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:38+00:00", "tests_total": 81, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def max_moves(grid)", "container": null, "callable": "max_moves", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2685, "task_id": "count-the-number-of-complete-components", "difficulty": "Medium", "problem_description": "You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting vertices a_i and b_i.\n\nReturn the number of complete connected components of the graph.\n\nA connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.\n\nA connected component is said to be complete if there exists an edge between every pair of its vertices.\n\nExample 1:\n\nInput: n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]\nOutput: 3\nExplanation: From the picture above, one can see that all of the components of this graph are complete.\n\nExample 2:\n\nInput: n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]\nOutput: 1\nExplanation: The component containing vertices 0, 1, and 2 is complete since there is an edge between every pair of two vertices. On the other hand, the component containing vertices 3, 4, and 5 is not complete since there is no edge between vertices 4 and 5. Thus, the number of complete components in this graph is 1.\n\nConstraints:\n\n- 1 <= n <= 50\n- 0 <= edges.length <= n * (n - 1) / 2\n- edges[i].length == 2\n- 0 <= a_i, b_i <= n - 1\n- a_i != b_i\n- There are no repeated edges.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,edges = [[0, 1]]) == 1\n assert candidate(n = 1,edges = []) == 1\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2], [2, 4], [1, 3]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5]]) == 1\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [2, 3]]) == 0\n assert candidate(n = 4,edges = [[0, 1], [2, 3]]) == 2\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(n = 3,edges = [[0, 1], [1, 2], [2, 0]]) == 1\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [2, 3], [3, 0]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 3]]) == 1\n assert candidate(n = 4,edges = [[0, 1], [1, 2]]) == 1\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]]) == 2\n assert candidate(n = 5,edges = []) == 5\n assert candidate(n = 3,edges = [[0, 1], [1, 2]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 2], [3, 4]]) == 3\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 0], [3, 4]]) == 2\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [7, 8], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [7, 9]]) == 3\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5], [10, 11], [11, 12], [12, 13], [13, 14], [14, 10], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15], [20, 21], [21, 22], [22, 23], [23, 24], [24, 20], [25, 26], [26, 27], [27, 28], [28, 29], [29, 25], [3, 15], [10, 25]]) == 0\n assert candidate(n = 40,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39]]) == 0\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 5], [8, 9], [9, 10], [10, 11], [11, 8], [12, 13], [13, 14], [14, 12], [1, 5], [1, 11]]) == 1\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [0, 9], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14]]) == 1\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [5, 7], [6, 7], [8, 9], [9, 10], [10, 11], [11, 8], [12, 13], [13, 14], [14, 15], [15, 12], [16, 17], [17, 18], [18, 19], [19, 16], [20, 21], [21, 22], [22, 23], [23, 24], [24, 20]]) == 1\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15]]) == 2\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7]]) == 0\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [11, 12], [12, 10], [13, 14], [14, 15], [15, 13], [16, 17], [17, 18], [18, 16], [19, 20], [20, 21], [21, 19], [22, 23], [23, 24], [24, 22]]) == 7\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [3, 6], [4, 7], [5, 8]]) == 1\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [0, 5]]) == 2\n assert candidate(n = 35,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5], [10, 11], [11, 12], [12, 13], [13, 14], [14, 10], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15], [20, 21], [21, 22], [22, 23], [23, 24], [24, 20], [25, 26], [26, 27], [27, 28], [28, 29], [29, 25], [30, 31], [31, 32], [32, 33], [33, 34], [34, 30], [3, 9], [14, 29], [24, 34]]) == 0\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [8, 9], [9, 10], [10, 11], [11, 8], [0, 8], [1, 9], [2, 10], [3, 11]]) == 0\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [8, 9], [9, 10], [10, 8], [11, 12], [12, 13], [13, 14], [14, 11]]) == 1\n assert candidate(n = 35,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 18], [18, 15], [19, 20], [20, 21], [21, 19], [22, 23], [23, 24], [24, 22], [25, 26], [26, 27], [27, 25], [28, 29], [29, 30], [30, 28], [31, 32], [32, 33], [33, 34], [34, 31], [3, 6], [9, 12], [15, 18], [24, 27], [30, 33]]) == 1\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10], [13, 14], [14, 15], [15, 13], [16, 17], [17, 18], [18, 16], [19, 0], [1, 19], [2, 18], [3, 17], [4, 16], [5, 15]]) == 2\n assert candidate(n = 35,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 20], [20, 18], [21, 22], [22, 23], [23, 21], [24, 25], [25, 26], [26, 24], [27, 28], [28, 29], [29, 27], [30, 31], [31, 32], [32, 30], [33, 34], [34, 33]]) == 11\n assert candidate(n = 40,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5], [10, 11], [11, 12], [12, 13], [13, 14], [14, 10], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15], [20, 21], [21, 22], [22, 23], [23, 24], [24, 20], [25, 26], [26, 27], [27, 28], [28, 29], [29, 25], [30, 31], [31, 32], [32, 33], [33, 34], [34, 30], [35, 36], [36, 37], [37, 38], [38, 39], [39, 35]]) == 0\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 18], [0, 15], [1, 16], [2, 17], [3, 18], [4, 19], [5, 18], [6, 19], [7, 18], [8, 19]]) == 2\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 6], [6, 3], [4, 6]]) == 1\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [0, 9], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 11], [7, 12], [8, 13]]) == 0\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29]]) == 0\n assert candidate(n = 30,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [13, 14], [15, 16], [15, 17], [15, 18], [15, 19], [16, 17], [16, 18], [16, 19], [17, 18], [17, 19], [18, 19], [20, 21], [20, 22], [20, 23], [20, 24], [21, 22], [21, 23], [21, 24], [22, 23], [22, 24], [23, 24], [25, 26], [25, 27], [25, 28], [25, 29], [26, 27], [26, 28], [26, 29], [27, 28], [27, 29], [28, 29]]) == 6\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 20], [20, 18], [21, 22], [22, 23], [23, 21], [24, 0]]) == 7\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15], [16, 17], [16, 18], [16, 19], [17, 18], [17, 19], [18, 19], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23], [22, 23], [24, 23]]) == 5\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 2], [3, 4], [4, 5], [3, 5], [6, 7], [7, 8], [6, 8], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [12, 14]]) == 5\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 6], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 12]]) == 0\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [13, 14], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 20], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20]]) == 8\n assert candidate(n = 30,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [13, 14], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 20], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 21]]) == 4\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9], [11, 12], [12, 11], [13, 14], [14, 13]]) == 1\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [13, 14]]) == 4\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 20], [20, 18], [21, 22], [22, 23], [23, 21], [24, 0], [1, 24], [2, 23], [3, 22], [4, 21], [5, 20]]) == 4\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 0\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [4, 6], [5, 7]]) == 1\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 20], [20, 18], [21, 22], [22, 23], [23, 21], [24, 25], [25, 26], [26, 24], [27, 28], [28, 29], [29, 27], [0, 27], [1, 28], [2, 29], [3, 26], [4, 25], [5, 24]]) == 6\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [3, 5], [6, 7], [7, 8], [6, 8], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [12, 14], [15, 16], [16, 17], [15, 17], [18, 19], [19, 20], [18, 20], [21, 22], [22, 23], [21, 23], [24, 25], [25, 26], [24, 26], [27, 28], [28, 29], [27, 29]]) == 10\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 0\n assert candidate(n = 40,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [10, 11], [11, 12], [12, 13], [13, 14], [14, 10], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15], [20, 21], [21, 22], [22, 23], [23, 24], [24, 20], [25, 26], [26, 27], [27, 28], [28, 29], [29, 25], [30, 31], [31, 32], [32, 33], [33, 34], [34, 30], [35, 36], [36, 37], [37, 38], [38, 39], [39, 35], [1, 25], [10, 30]]) == 0\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [3, 5], [6, 7], [7, 8], [6, 8], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [12, 14], [15, 16], [16, 17], [15, 17], [18, 19]]) == 7\n assert candidate(n = 50,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5], [10, 11], [11, 12], [12, 13], [13, 14], [14, 10], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15], [20, 21], [21, 22], [22, 23], [23, 24], [24, 20], [25, 26], [26, 27], [27, 28], [28, 29], [29, 25], [30, 31], [31, 32], [32, 33], [33, 34], [34, 30], [35, 36], [36, 37], [37, 38], [38, 39], [39, 35], [40, 41], [41, 42], [42, 43], [43, 44], [44, 40], [45, 46], [46, 47], [47, 48], [48, 49], [49, 45]]) == 0\n assert candidate(n = 30,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [9, 10], [10, 11], [11, 9], [12, 13], [13, 14], [14, 12], [15, 16], [16, 17], [17, 15], [18, 19], [19, 20], [20, 18], [21, 22], [22, 23], [23, 21], [24, 25], [25, 26], [26, 24], [27, 28], [28, 29], [29, 27]]) == 10\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15]]) == 8\n assert candidate(n = 50,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49]]) == 0\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 13], [13, 10], [14, 15], [15, 16], [16, 17], [17, 14], [18, 19]]) == 1\n", "comparison": "exact"}, "public_tests": ["6\n[[0,1],[0,2],[1,2],[3,4]]", "6\n[[0,1],[0,2],[1,2],[3,4],[3,5]]"], "hints": ["Find the connected components of an undirected graph using depth-first search (DFS) or breadth-first search (BFS).", "For each connected component, count the number of nodes and edges in the component.", "A connected component is complete if and only if the number of edges in the component is equal to m*(m-1)/2, where m is the number of nodes in the component."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().countCompleteComponents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:40+00:00", "tests_total": 69, "tests_dropped": 7, "flags": ["figure_reference", "has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "union-find", "graph"]}, "language": "ruby", "interface": {"raw_signature": "def count_complete_components(n, edges)", "container": null, "callable": "count_complete_components", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2696, "task_id": "minimum-string-length-after-removing-substrings", "difficulty": "Easy", "problem_description": "You are given a string s consisting only of uppercase English letters.\n\nYou can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings \"AB\" or \"CD\" from s.\n\nReturn the minimum possible length of the resulting string that you can obtain.\n\nNote that the string concatenates after removing the substring and could produce new \"AB\" or \"CD\" substrings.\n\nExample 1:\n\nInput: s = \"ABFCACDB\"\nOutput: 2\nExplanation: We can do the following operations:\n- Remove the substring \"ABFCACDB\", so s = \"FCACDB\".\n- Remove the substring \"FCACDB\", so s = \"FCAB\".\n- Remove the substring \"FCAB\", so s = \"FC\".\nSo the resulting length of the string is 2.\nIt can be shown that it is the minimum length that we can obtain.\n\nExample 2:\n\nInput: s = \"ACBBD\"\nOutput: 5\nExplanation: We cannot do any operations on the string so the length remains the same.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists only of uppercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"ABCDBA\") == 2\n assert candidate(s = \"CDCDCD\") == 0\n assert candidate(s = \"ABABAB\") == 0\n assert candidate(s = \"ACBBD\") == 5\n assert candidate(s = \"ABFCACDB\") == 2\n assert candidate(s = \"AAAA\") == 4\n assert candidate(s = \"BACD\") == 2\n assert candidate(s = \"ABCDABCD\") == 0\n assert candidate(s = \"ABACDBACDB\") == 0\n assert candidate(s = \"ABABABABABABABABAB\") == 0\n assert candidate(s = \"ACDBABCDACDB\") == 0\n assert candidate(s = \"ABCDBCDBCDCDBABCDB\") == 4\n assert candidate(s = \"FCABABCDABCDF\") == 3\n assert candidate(s = \"CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD\") == 0\n assert candidate(s = \"ABCABCABCABC\") == 4\n assert candidate(s = \"CDCDCDCDCDCDCD\") == 0\n assert candidate(s = \"ABABCDABABCD\") == 0\n assert candidate(s = \"ABCDABCDBABCDABCDB\") == 2\n assert candidate(s = \"CCCCCCCC\") == 8\n assert candidate(s = \"CDABCDAB\") == 0\n assert candidate(s = \"DDDDDDDD\") == 8\n assert candidate(s = \"CDCDCDCD\") == 0\n assert candidate(s = \"ACBDCDBDCB\") == 8\n assert candidate(s = \"ABABABAB\") == 0\n assert candidate(s = \"CDCDCDCDCDCDCDCD\") == 0\n assert candidate(s = \"AAABBBCCCDDD\") == 0\n assert candidate(s = \"CDCDCDCDABABABAB\") == 0\n assert candidate(s = \"ABABABABAB\") == 0\n assert candidate(s = \"ABABABCDCDABCDCD\") == 0\n assert candidate(s = \"ABCDABCDBACDBACDABCD\") == 2\n assert candidate(s = \"AABBCCDDBBAA\") == 4\n assert candidate(s = \"ABCDABCDAB\") == 0\n assert candidate(s = \"DCABDCABDCABDCAB\") == 2\n assert candidate(s = \"DCABDCABDCABDCABDCABDCABDCABDCAB\") == 2\n assert candidate(s = \"CDCDCDCDCDAB\") == 0\n assert candidate(s = \"DCBADCBAABCDDC\") == 10\n assert candidate(s = \"ABCDABCDCDABCDABCDCD\") == 0\n assert candidate(s = \"ABCDBACDBACD\") == 2\n assert candidate(s = \"DCBA\") == 4\n assert candidate(s = \"FCABFCABFCABFCABFCABFCABFCABFCABFCAB\") == 18\n assert candidate(s = \"DBABABCD\") == 2\n assert candidate(s = \"ABABABABABAB\") == 0\n assert candidate(s = \"BACDBACDBACDAB\") == 2\n assert candidate(s = \"AAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBB\") == 0\n assert candidate(s = \"ACDBCDABABCD\") == 0\n assert candidate(s = \"ACDBABABCDACDB\") == 0\n assert candidate(s = \"BACDBACD\") == 2\n assert candidate(s = \"ABCDBACDAB\") == 2\n assert candidate(s = \"ABCDBCDBCDAB\") == 2\n assert candidate(s = \"BACDBACDBACDBACDB\") == 1\n assert candidate(s = \"ABCDABCDCDABCD\") == 0\n assert candidate(s = \"ABCDABCDCD\") == 0\n assert candidate(s = \"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\") == 40\n assert candidate(s = \"ABCDCDAB\") == 0\n assert candidate(s = \"ABABABABABCDABCD\") == 0\n assert candidate(s = \"ABCDABCDBABCDBAB\") == 2\n assert candidate(s = \"CDCDCDCDCD\") == 0\n assert candidate(s = \"ABABABABABABABABABCDCDCDCD\") == 0\n assert candidate(s = \"ABCDABCDBAB\") == 1\n assert candidate(s = \"CDCDCDABABCDABABCDABABCD\") == 0\n assert candidate(s = \"ABABCDABABCDABABCDABABCDAB\") == 0\n assert candidate(s = \"ACDBACDBACDBACDBACDB\") == 0\n assert candidate(s = \"CDABCDABCDABCD\") == 0\n assert candidate(s = \"ACDBABABABCDAB\") == 0\n assert candidate(s = \"DCABDCAB\") == 2\n assert candidate(s = \"ABABABABABABAB\") == 0\n assert candidate(s = \"ABCDCBAABCDBCDABCDCBAABCDBCD\") == 4\n assert candidate(s = \"ABCDABCDBABCDABCDBABCDABCDBABCDABCDB\") == 4\n assert candidate(s = \"ACDBACDBACDBACDBACDBACDBACDBACDBACDB\") == 0\n assert candidate(s = \"DBACBADC\") == 8\n assert candidate(s = \"ACDBACDBACDBACDB\") == 0\n assert candidate(s = \"BACDBACDBACDBACDBACD\") == 2\n assert candidate(s = \"AAAAAAAA\") == 8\n assert candidate(s = \"CDABCDABCDABCDABCDAB\") == 0\n assert candidate(s = \"CDABCDABCDABCDABCDABCDABCDABCDABCDAB\") == 0\n assert candidate(s = \"CDCDCDCDCDCD\") == 0\n assert candidate(s = \"ABACBCADCD\") == 6\n assert candidate(s = \"ABCDABCDBACDBACD\") == 2\n assert candidate(s = \"ABABCDABABCDAB\") == 0\n assert candidate(s = \"ABCDDCBA\") == 4\n assert candidate(s = \"ABCDABCDABCDABCDABCDABCDABCDABCD\") == 0\n assert candidate(s = \"BACDBACDBACDBACD\") == 2\n assert candidate(s = \"XYZ\") == 3\n assert candidate(s = \"ABABABABABABABABABAB\") == 0\n assert candidate(s = \"BBBBBBBBBBBBBBBB\") == 16\n assert candidate(s = \"CDCDCDABABCD\") == 0\n assert candidate(s = \"AAAAAAAAAAAAAAAA\") == 16\n assert candidate(s = \"BBBBBBBB\") == 8\n assert candidate(s = \"CDCDABAB\") == 0\n assert candidate(s = \"CDABCDABCDAB\") == 0\n assert candidate(s = \"ABCDABCDABCD\") == 0\n assert candidate(s = \"CDABCDABCD\") == 0\n assert candidate(s = \"ABCDABCDABCDBACD\") == 2\n assert candidate(s = \"ACBDCDBDCBDCB\") == 11\n assert candidate(s = \"ABABABABABCD\") == 0\n assert candidate(s = \"AAAAABBBBB\") == 0\n assert candidate(s = \"ABCDBCDABCDBCDABCDBCDABCDBCD\") == 4\n assert candidate(s = \"ABABABABABABABABABABABABABABABABABAB\") == 0\n assert candidate(s = \"BBCCCDDDAABB\") == 2\n assert candidate(s = \"ABCCBAABCCBA\") == 8\n assert candidate(s = \"ACBDABFCDC\") == 6\n assert candidate(s = \"ABCDABCDABCDAB\") == 0\n assert candidate(s = \"BBBBBAAAAA\") == 10\n assert candidate(s = \"FFFFFFFFFFFFFFFF\") == 16\n assert candidate(s = \"CABACDBABC\") == 2\n assert candidate(s = \"CDCDCDCDCDABABABAB\") == 0\n assert candidate(s = \"ABABDCDCCCDA\") == 4\n assert candidate(s = \"ACBDACBDACBD\") == 12\n assert candidate(s = \"AACBBCCDAD\") == 8\n assert candidate(s = \"ABCDCBAABCDBCD\") == 2\n assert candidate(s = \"ABCDABCDBACD\") == 2\n assert candidate(s = \"DCBADCBABC\") == 8\n assert candidate(s = \"BACDBACDBACDB\") == 1\n assert candidate(s = \"ABCDABCDBACDAB\") == 2\n assert candidate(s = \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\") == 40\n assert candidate(s = \"FCABFCABFCABFCABFCAB\") == 10\n assert candidate(s = \"FCABFCABFCAB\") == 6\n assert candidate(s = \"BACDBACDBACDBACDBACDBACDBACDBACDBACDB\") == 1\n assert candidate(s = \"ABCDABCDBABD\") == 2\n assert candidate(s = \"ACBACDBCDB\") == 4\n assert candidate(s = \"ABACDABACDABACD\") == 3\n assert candidate(s = \"BACDBACDBACDBACDBACDBACD\") == 2\n assert candidate(s = \"ABABABABABABABABABABABABAB\") == 0\n assert candidate(s = \"BACDBACDBACD\") == 2\n assert candidate(s = \"CDCDCDCDCDCDCDCDCD\") == 0\n assert candidate(s = \"ABCDBCDBCDABCDBCDABCDBCDABCDBCD\") == 5\n assert candidate(s = \"ABCDABCDBABC\") == 2\n assert candidate(s = \"ABCDABCDBABCDABCDBABCDABCDBAB\") == 3\n assert candidate(s = \"ABCDABCDCDAB\") == 0\n assert candidate(s = \"ABCDEFGHABCD\") == 4\n assert candidate(s = \"AAAAAAAAAABBBBBBBBBB\") == 0\n assert candidate(s = \"BBBBBBBBBAAAAAAAAABBBBBBBBBBAAAAAAAAAA\") == 20\n assert candidate(s = \"AABABBCCDDBBCC\") == 4\n assert candidate(s = \"ABCDABCDABCDABCD\") == 0\n assert candidate(s = \"ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\") == 0\n assert candidate(s = \"ACDBACDBACDB\") == 0\n assert candidate(s = \"BACDBACDBABCDABCD\") == 1\n assert candidate(s = \"DCABDCABDCABDCABDCABDCABDCABDCABDCABDCABDCAB\") == 2\n assert candidate(s = \"ABACADABAD\") == 6\n assert candidate(s = \"ABCD\") == 0\n assert candidate(s = \"BBBBBBBBBAAAAAAAAA\") == 18\n assert candidate(s = \"ABCDABCDABCDABCDABCD\") == 0\n assert candidate(s = \"ABABABABABCDABCDBACDBACD\") == 2\n assert candidate(s = \"DCDABABABABABABCD\") == 1\n assert candidate(s = \"ABABABABCDABCDBACDBACDABABABAB\") == 2\n assert candidate(s = \"CDCDCDCDCDCDCDCDCDCDCDCD\") == 0\n assert candidate(s = \"ACDBACDB\") == 0\n assert candidate(s = \"ABABCDABCD\") == 0\n assert candidate(s = \"AACBBCCCDD\") == 6\n assert candidate(s = \"ABABABABABABCD\") == 0\n assert candidate(s = \"AACCBBAADD\") == 10\n assert candidate(s = \"ABABCDABABCDABCD\") == 0\n", "comparison": "exact"}, "public_tests": ["\"ABFCACDB\"", "\"ACBBD\""], "hints": ["Can we use brute force to solve the problem?", "Repeatedly traverse the string to find and remove the substrings “AB” and “CD” until no more occurrences exist.", "Can the solution be optimized using a stack?"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:42+00:00", "tests_total": 153, "tests_dropped": 1, "flags": [], "topic_tags": ["string", "stack", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_length(s)", "container": null, "callable": "min_length", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2697, "task_id": "lexicographically-smallest-palindrome", "difficulty": "Easy", "problem_description": "You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.\n\nYour task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.\n\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n\nReturn the resulting palindrome string.\n\nExample 1:\n\nInput: s = \"egcfe\"\nOutput: \"efcfe\"\nExplanation: The minimum number of operations to make \"egcfe\" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is \"efcfe\", by changing 'g'.\n\nExample 2:\n\nInput: s = \"abcd\"\nOutput: \"abba\"\nExplanation: The minimum number of operations to make \"abcd\" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is \"abba\".\n\nExample 3:\n\nInput: s = \"seven\"\nOutput: \"neven\"\nExplanation: The minimum number of operations to make \"seven\" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is \"neven\".\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == \"abcba\"\n assert candidate(s = \"madam\") == \"madam\"\n assert candidate(s = \"abac\") == \"aaaa\"\n assert candidate(s = \"aabbaa\") == \"aabbaa\"\n assert candidate(s = \"abcdcba\") == \"abcdcba\"\n assert candidate(s = \"zyxwvutsrponmlkjihgfedcba\") == \"abcdefghijklmlkjihgfedcba\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"xyzyx\") == \"xyzyx\"\n assert candidate(s = \"ab\") == \"aa\"\n assert candidate(s = \"abcde\") == \"abcba\"\n assert candidate(s = \"zyxwvutsrqp\") == \"pqrstutsrqp\"\n assert candidate(s = \"racecar\") == \"racecar\"\n assert candidate(s = \"egcfe\") == \"efcfe\"\n assert candidate(s = \"race\") == \"eaae\"\n assert candidate(s = \"abc\") == \"aba\"\n assert candidate(s = \"abcd\") == \"abba\"\n assert candidate(s = \"pqrqs\") == \"pqrqp\"\n assert candidate(s = \"hello\") == \"heleh\"\n assert candidate(s = \"seven\") == \"neven\"\n assert candidate(s = \"xyzzyx\") == \"xyzzyx\"\n assert candidate(s = \"abcdefg\") == \"abcdcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijklnopqrsrqpnlkjihgfedcba\") == \"abcdefghijklnopqrrqponlkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijklnopqrstuvutsrqpnlkjihgfedcba\") == \"abcdefghijklnopqrstuutsrqponlkjihgfedcba\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyetanditwilltakealotofchangesanditwillbeinterestingtosolveanditwillbeaveryinterestingproblemtofigureoutanditwillbeanevenmoreinterestingproblemtosolveanditwillrequirealotofthoughtandcreativity\") == \"thisisaeecdlanggtohnfohalaeedsqebeladeadaaendoomebelboipgniteeaediieillnakeaaeblfchaideaanderugifbeielboepgiigserelneandiaebllbeaidnaenleresgiigpeobleiebfigurednaaediahcflbeaaekanllieiideaeetingpioblebemoodneaadaedalebeqsdeealahofnhotggnaldceeasisiht\"\n assert candidate(s = \"reddering\") == \"geddeddeg\"\n assert candidate(s = \"abcdefghijklnopqrstuvwxyyxwvutsrqpnlkjihgfedcba\") == \"abcdefghijklnopqrstuvwxyxwvutsrqponlkjihgfedcba\"\n assert candidate(s = \"kooking\") == \"gniking\"\n assert candidate(s = \"rotorrotor\") == \"rotorrotor\"\n assert candidate(s = \"abracadabra\") == \"abbacacabba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"palindromeisaveryinterestingwordandshouldbecomeapalindromewithevenmorecharacters\") == \"paeicarahcerameevehteremoidgiladaedocebddbecodeadaligdiomeretheveemarecharacieap\"\n assert candidate(s = \"thisisaverylongstringthatwillrequiremanychangesandshouldresultinastrongpalindrome\") == \"ehirdnalapglongsaningthardillhednaregaahchaagerandehllidrahtgninasgnolgpalandrihe\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"thisisaverylongstringthatweneedtopalindromify\") == \"tfimiranelalondeenengahagneneednolalenarimift\"\n assert candidate(s = \"racecarx\") == \"raaccaar\"\n assert candidate(s = \"referenced\") == \"deceeeeced\"\n assert candidate(s = \"leveling\") == \"geieeieg\"\n assert candidate(s = \"zxyyz\") == \"zxyxz\"\n assert candidate(s = \"abcdpqrsstuvqponmlkjihgfedcba\") == \"abcdefghijklmnonmlkjihgfedcba\"\n assert candidate(s = \"zzzzzzzzzz\") == \"zzzzzzzzzz\"\n assert candidate(s = \"xyzzzzyxzyxzyzxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxz\") == \"xxyzxyyxyyxyyxxzxxzxxzxxzxxzxxzxxzxxzxxzxxzxxyyxyyxyyxzyxx\"\n assert candidate(s = \"xyzzzxy\") == \"xxzzzxx\"\n assert candidate(s = \"repaid\") == \"deaaed\"\n assert candidate(s = \"palindromemordnilap\") == \"palindromemordnilap\"\n assert candidate(s = \"palindromeisaveryinterestingword\") == \"daligdiomeieanerrenaeiemoidgilad\"\n assert candidate(s = \"qwertyuiopoiuytrewq\") == \"qwertyuiopoiuytrewq\"\n assert candidate(s = \"algorithm\") == \"ahgirigha\"\n assert candidate(s = \"wow\") == \"wow\"\n assert candidate(s = \"abcdefghijkllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllkjihgfedcba\"\n assert candidate(s = \"redder\") == \"redder\"\n assert candidate(s = \"aaaaabbbbbccccdddd\") == \"aaaaabbbbbbbbaaaaa\"\n assert candidate(s = \"zzzzz\") == \"zzzzz\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"zxcvbnmnbvcxz\") == \"zxcvbnmnbvcxz\"\n assert candidate(s = \"peep\") == \"peep\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"rotavator\") == \"rotavator\"\n assert candidate(s = \"aabbccddeeeeffgghhiijj\") == \"aabbccddeeeeeeddccbbaa\"\n assert candidate(s = \"releveler\") == \"releveler\"\n assert candidate(s = \"sagas\") == \"sagas\"\n assert candidate(s = \"abcdefghijkllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"palindrome\") == \"ealiddilae\"\n assert candidate(s = \"kook\") == \"kook\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"aaaaabaaaa\") == \"aaaaaaaaaa\"\n assert candidate(s = \"kayak\") == \"kayak\"\n assert candidate(s = \"abcdefghijklnmlkjihgfedcba\") == \"abcdefghijklmmlkjihgfedcba\"\n assert candidate(s = \"palindromeisaveryinterestingwordandshouldbecomeapalindromewithaverylongstringandmorecharacters\") == \"paeicarahceramdnagnieregnilgreraandsemoldbecamaamacebdlomesdnaarerglingereingandmarecharacieap\"\n assert candidate(s = \"racecarxracecar\") == \"racecarxracecar\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"aabbbaaa\") == \"aaabbaaa\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"xyzzzyx\") == \"xyzzzyx\"\n assert candidate(s = \"referencing\") == \"gefcnencfeg\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllkjihgfedcba\") == \"abcdefghijkllllllkjihgfedcba\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyetanditwilltakealotofchangesanditwillbeinterestingtosolveanditwillbeaveryinterestingproblemtofigureout\") == \"thieisaieotlelborpgngthareeedsrebaeadeapaidnaeolebotgnisnereenaebiliilidaaeagnahcchangaeaadiliilibeaneerensingtobeloeandiapaedaeabersdeeerahtgngprobleltoeiasieiht\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"abcdeedcba\") == \"abcdeedcba\"\n assert candidate(s = \"deeding\") == \"deedeed\"\n assert candidate(s = \"noon\") == \"noon\"\n assert candidate(s = \"abacaxbba\") == \"abacacaba\"\n assert candidate(s = \"aabbccddeeeeffgg\") == \"aabbccddddccbbaa\"\n assert candidate(s = \"deeee\") == \"deeed\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"revileddidilver\") == \"reviidddddiiver\"\n assert candidate(s = \"abacaxabayabaz\") == \"aaaaaaaaaaaaaa\"\n assert candidate(s = \"reviling\") == \"geiiiieg\"\n assert candidate(s = \"revolover\") == \"revolover\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyet\") == \"teisinaieitlbegordiigahaedaedboobdeadeahagiidrogebltieianisiet\"\n assert candidate(s = \"abcdeffedcba\") == \"abcdeffedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"wasitacaroracatisaw\") == \"wasitacaroracatisaw\"\n assert candidate(s = \"levellevel\") == \"levellevel\"\n assert candidate(s = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == \"aabbccddeeffgghhiijjkkllmmmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"xerox\") == \"xerex\"\n assert candidate(s = \"aibohphobia\") == \"aibohphobia\"\n assert candidate(s = \"abcdefghijklnopqponmlkjihgfedcba\") == \"abcdefghijklmnopponmlkjihgfedcba\"\n assert candidate(s = \"abcdefedcba\") == \"abcdefedcba\"\n assert candidate(s = \"programming\") == \"gnigmamging\"\n assert candidate(s = \"level\") == \"level\"\n assert candidate(s = \"abcdefghijklnopqrstuvwxyzzyxwvutsrqpnlkjihgfedcba\") == \"abcdefghijklnopqrstuvwxyzyxwvutsrqponlkjihgfedcba\"\n assert candidate(s = \"aabbccdd\") == \"aabbbbaa\"\n assert candidate(s = \"stats\") == \"stats\"\n assert candidate(s = \"deedful\") == \"deedeed\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyetanditwilltakealotofchangesanditwillbeinterestingtosolve\") == \"ehioioageitlenesniebglhatideasegbahadeaoaaekarllebtidnaseotoesanditbellrakeaaoaedahabgesaeditahlgbeinseneltiegaoioihe\"\n assert candidate(s = \"xyxzyxzyxzyx\") == \"xyxxyxxyxxyx\"\n assert candidate(s = \"abcdefghijjihgfedcba\") == \"abcdefghijjihgfedcba\"\n assert candidate(s = \"abcdefghijk\") == \"abcdefedcba\"\n assert candidate(s = \"aabccbaa\") == \"aabccbaa\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyyxwwvvuuttssrrqppoonnmlllkkkjjjiihhggffeeeeddccbbaa\") == \"aabbccddeeeeffgghhiijjjkkklllmnnooppqrrssttuuvvwwxyyzyyxwwvvuuttssrrqppoonnmlllkkkjjjiihhggffeeeeddccbbaa\"\n assert candidate(s = \"abcdefgihgfedcba\") == \"abcdefghhgfedcba\"\n assert candidate(s = \"palindromeisaveryinterestingwordandshouldbecomeapalindrome\") == \"ealiddilaeaeaocebdltehednadgoogdandehetldbecoaeaealiddilae\"\n assert candidate(s = \"abacabadabacaba\") == \"abacabadabacaba\"\n assert candidate(s = \"abcdefghijkjihgfedcba\") == \"abcdefghijkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"sommersommers\") == \"soemeosoemeos\"\n assert candidate(s = \"rotator\") == \"rotator\"\n assert candidate(s = \"aabbccddeeeeffgghhiijjkkll\") == \"aabbccddeeeeffeeeeddccbbaa\"\n assert candidate(s = \"redivider\") == \"redivider\"\n assert candidate(s = \"racecarabc\") == \"caaeaaeaac\"\n assert candidate(s = \"abcdefghijihgfedcba\") == \"abcdefghijihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllkjihgfedcba\"\n assert candidate(s = \"peeping\") == \"geepeeg\"\n assert candidate(s = \"abcdefghijklnopqrstuvwxwvutsrqpnlkjihgfedcba\") == \"abcdefghijklnopqrstuvwwvutsrqponlkjihgfedcba\"\n assert candidate(s = \"thisisaverylongstringthatwillrequiremanychangesandshouldresultinastrongpalindromewithlongtext\") == \"thesgnalerilemgrdnilapgaorilaneqliremaluchadgasagdahculamerilqenaliroagpalindrgmelirelangseht\"\n assert candidate(s = \"deifiedly\") == \"dedeieded\"\n assert candidate(s = \"abcdefghijkllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllkjihgfedcba\"\n assert candidate(s = \"banana\") == \"aaaaaa\"\n assert candidate(s = \"abcdefghijkmlkjihgfedcba\") == \"abcdefghijkllkjihgfedcba\"\n assert candidate(s = \"palindromeisaveryinterestingwordandshouldbecomeapalindromewithaverylongstring\") == \"gaiindgnmeiravahtineeoednilapaedacdbdluldbdcadeapalindeoeenithavariemngdniiag\"\n assert candidate(s = \"radar\") == \"radar\"\n assert candidate(s = \"aabaaa\") == \"aaaaaa\"\n assert candidate(s = \"reviledly\") == \"redeleder\"\n assert candidate(s = \"aabbccddeeffgg\") == \"aabbccddccbbaa\"\n assert candidate(s = \"detartrated\") == \"detartrated\"\n assert candidate(s = \"abccba\") == \"abccba\"\n assert candidate(s = \"amazingracecar\") == \"aaaecaggaceaaa\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"repapering\") == \"geiaeeaieg\"\n assert candidate(s = \"reviver\") == \"reviver\"\n assert candidate(s = \"palindromic\") == \"calindnilac\"\n assert candidate(s = \"madamimadam\") == \"madamimadam\"\n assert candidate(s = \"aabbccddeeeeffgghhiijjkkllmm\") == \"aabbccddeeeeffffeeeeddccbbaa\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aabbccddeeffgghhiijjkkllmmmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"aabbccddeeeeffgghh\") == \"aabbccddeeddccbbaa\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"amanaplanacanalpanama\") == \"amanaplanacanalpanama\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyetanditwilltakealotofchangesanditwillbeinterestingtosolveanditwillbeaveryinterestingproblem\") == \"meibirageitlenesniinetaableedsidbaeadeaoagiidremebniebiliotidnandgnahcfoakeaekaofchangdnanditoilibeinbemerdiigaoaedaeabdisdeelbaateniinseneltiegaribiem\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == \"abcdefghijklmmlkjihgfedcba\"\n assert candidate(s = \"aaaabbbbccccdddd\") == \"aaaabbbbbbbbaaaa\"\n assert candidate(s = \"rotorst\") == \"rororor\"\n assert candidate(s = \"zxyxzyxzyxz\") == \"zxyxxyxxyxz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmmlkjihgfedcba\"\n assert candidate(s = \"deified\") == \"deified\"\n assert candidate(s = \"abcdefghijkllllllllkjihgfedcba\") == \"abcdefghijkllllllllkjihgfedcba\"\n assert candidate(s = \"aabbccddeeddffgg\") == \"aabbccddddccbbaa\"\n assert candidate(s = \"repaper\") == \"repaper\"\n assert candidate(s = \"rotated\") == \"detated\"\n assert candidate(s = \"abcdedcba\") == \"abcdedcba\"\n assert candidate(s = \"abcdefghijkllkjihgfedcba\") == \"abcdefghijkllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"xyloxyloxyloxylo\") == \"olloolloolloollo\"\n assert candidate(s = \"palindromeisaveryinterestingwordandshouldbecomeapalindromewithadditionalcharacters\") == \"paeicarahciaaoeriddaereseingdnidanaehocebbecoheanadindgniesereaddireoaaicharacieap\"\n assert candidate(s = \"kayaking\") == \"gaiaaiag\"\n assert candidate(s = \"abcdefghijkllllkjihgfedcba\") == \"abcdefghijkllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijklnopqrqponmlkjihgfedcba\") == \"abcdefghijklmnopqqponmlkjihgfedcba\"\n assert candidate(s = \"abcddcba\") == \"abcddcba\"\n assert candidate(s = \"aaaaabaaa\") == \"aaaaaaaaa\"\n assert candidate(s = \"rotor\") == \"rotor\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyz\") == \"aabbccddeeffgghhiijjkkllmmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"civic\") == \"civic\"\n assert candidate(s = \"abcdefghihgfedcba\") == \"abcdefghihgfedcba\"\n assert candidate(s = \"aaabbbbccccc\") == \"aaabbbbbbaaa\"\n assert candidate(s = \"abcdefghijkmmmlkjihgfedcba\") == \"abcdefghijklmmlkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydog\") == \"aodicabehtneoojpmpjooenthebacidoa\"\n assert candidate(s = \"xyxzyx\") == \"xyxxyx\"\n assert candidate(s = \"noonday\") == \"nadndan\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindrome\") == \"ehirdnalapaedageboindeeataeedniobegadeapalandrihe\"\n assert candidate(s = \"reviled\") == \"deliled\"\n assert candidate(s = \"aabbccddeeaabbccdd\") == \"aabbbbaaeeaabbbbaa\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyetanditwilltakealotofchangesanditwillbeinterestingtosolveanditwillbeaveryinterestingproblemtofigureoutanditwillbeanevenmoreinterestingproblemtosolve\") == \"ehioioamelblongniriegehaieeedneobeaabeaialiddaomebrtgifonmelboandiitieleakealetaebhaigeianaetlillbeiiteeeetiiebllilteanaiegiahbeatelaekaeleitiidnaoblemnofigtrbemoaddilaiaebaaeboendeeeiahegeiringnolblemaoioihe\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"civicly\") == \"cicicic\"\n assert candidate(s = \"abcdefghijklimnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == \"abcdefghijklimnopqrstuvwxyyxwvutsrqponmilkjihgfedcba\"\n assert candidate(s = \"aabbccddeeeeffgghhiijjkk\") == \"aabbccddeeeeeeeeddccbbaa\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijhgfedcba\") == \"abcdefghiihgfedcba\"\n assert candidate(s = \"aabbcc\") == \"aabbaa\"\n assert candidate(s = \"mississippi\") == \"iipiisiipii\"\n assert candidate(s = \"abcdefghijklnopqrstuvwutvqpnlkjihgfedcba\") == \"abcdefghijklnopqrstuutsrqponlkjihgfedcba\"\n assert candidate(s = \"solos\") == \"solos\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyyxwwvvttuussrrqqponnmlllkkjjiihhggffeeddccbaabbaa\") == \"aabbaabccddeeffgghhiijjkklllmnnopqqrrsstuttvvwwxyyzzzyyxwwvvttutssrrqqponnmlllkkjjiihhggffeeddccbaabbaa\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"abcdefghijkllllllllllllllllllllllllllllkjihgfedcba\") == \"abcdefghijkllllllllllllllllllllllllllllkjihgfedcba\"\n assert candidate(s = \"aabbccddeeeffggghhiiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aabbccddeeeffggghhiiijjkkllmllkkjjiiihhgggffeeeddccbbaa\"\n assert candidate(s = \"thisisaverylongstringthatneedstobemadeapalindromebutitisnotyetanditwilltakealotofchanges\") == \"segnahaferolaegatliigthanaeedsonbemadeaealiddilaeaedamebnosdeeanahtgiiltagealorefahanges\"\n assert candidate(s = \"abcdefdcba\") == \"abcdeedcba\"\n assert candidate(s = \"deed\") == \"deed\"\n assert candidate(s = \"abacaxaba\") == \"abacacaba\"\n assert candidate(s = \"neveroddoreven\") == \"neveroddoreven\"\n assert candidate(s = \"abcdefghijklnopqrstsrqponmlkjihgfedcba\") == \"abcdefghijklmnopqrssrqponmlkjihgfedcba\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"refer\") == \"refer\"\n", "comparison": "exact"}, "public_tests": ["\"egcfe\"", "\"abcd\"", "\"seven\""], "hints": ["We can make any string a palindrome, by simply making any character at index i equal to the character at index length - i - 1 (using 0-based indexing).", "To make it lexicographically smallest we can change the character with maximum ASCII value to the one with minimum ASCII value."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().makeSmallestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:44+00:00", "tests_total": 216, "tests_dropped": 0, "flags": [], "topic_tags": ["two-pointers", "string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def make_smallest_palindrome(s)", "container": null, "callable": "make_smallest_palindrome", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2698, "task_id": "find-the-punishment-number-of-an-integer", "difficulty": "Medium", "problem_description": "Given a positive integer n, return the punishment number of n.\n\nThe punishment number of n is defined as the sum of the squares of all integers i such that:\n\n- 1 <= i <= n\n- The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i.\n\nExample 1:\n\nInput: n = 10\nOutput: 182\nExplanation: There are exactly 3 integers i in the range [1, 10] that satisfy the conditions in the statement:\n- 1 since 1 * 1 = 1\n- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 and 1 with a sum equal to 8 + 1 == 9.\n- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 and 0 with a sum equal to 10 + 0 == 10.\nHence, the punishment number of 10 is 1 + 81 + 100 = 182\n\nExample 2:\n\nInput: n = 37\nOutput: 1478\nExplanation: There are exactly 4 integers i in the range [1, 37] that satisfy the conditions in the statement:\n- 1 since 1 * 1 = 1.\n- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.\n- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.\n- 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.\nHence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478\n\nConstraints:\n\n- 1 <= n <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 700) == 1660140\n assert candidate(n = 800) == 3353149\n assert candidate(n = 100) == 41334\n assert candidate(n = 600) == 772866\n assert candidate(n = 37) == 1478\n assert candidate(n = 200) == 41334\n assert candidate(n = 400) == 601470\n assert candidate(n = 900) == 3353149\n assert candidate(n = 9) == 82\n assert candidate(n = 2) == 1\n assert candidate(n = 25) == 182\n assert candidate(n = 1) == 1\n assert candidate(n = 500) == 772866\n assert candidate(n = 1000) == 10804657\n assert candidate(n = 10) == 182\n assert candidate(n = 300) == 184768\n assert candidate(n = 50) == 3503\n assert candidate(n = 625) == 772866\n assert candidate(n = 999) == 9804657\n assert candidate(n = 750) == 2154349\n assert candidate(n = 150) == 41334\n", "comparison": "exact"}, "public_tests": ["10", "37"], "hints": ["Can we generate all possible partitions of a number?", "Use a recursive algorithm that splits the number into two parts, generates all possible partitions of each part recursively, and then combines them in all possible ways."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().punishmentNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:47+00:00", "tests_total": 21, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "backtracking"]}, "language": "ruby", "interface": {"raw_signature": "def punishment_number(n)", "container": null, "callable": "punishment_number", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2699, "task_id": "modify-graph-edge-weights", "difficulty": "Hard", "problem_description": "You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [a_i, b_i, w_i] indicates that there is an edge between nodes a_i and b_i with weight w_i.\n\nSome edges have a weight of -1 (w_i = -1), while others have a positive weight (w_i > 0).\n\nYour task is to modify all edges with a weight of -1 by assigning them positive integer values in the range [1, 2 * 10^9] so that the shortest distance between the nodes source and destination becomes equal to an integer target. If there are multiple modifications that make the shortest distance between source and destination equal to target, any of them will be considered correct.\n\nReturn an array containing all edges (even unmodified ones) in any order if it is possible to make the shortest distance from source to destination equal to target, or an empty array if it's impossible.\n\nNote: You are not allowed to modify the weights of edges with initial positive weights.\n\nExample 1:\n\nInput: n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5\nOutput: [[4,1,1],[2,0,1],[0,3,3],[4,3,1]]\nExplanation: The graph above shows a possible modification to the edges, making the distance from 0 to 1 equal to 5.\n\nExample 2:\n\nInput: n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6\nOutput: []\nExplanation: The graph above contains the initial edges. It is not possible to make the distance from 0 to 2 equal to 6 by modifying the edge with weight -1. So, an empty array is returned.\n\nExample 3:\n\nInput: n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6\nOutput: [[1,0,4],[1,2,3],[2,3,5],[0,3,1]]\nExplanation: The graph above shows a modified graph having the shortest distance from 0 to 2 as 6.\n\nConstraints:\n\n- 1 <= n <= 100\n- 1 <= edges.length <= n * (n - 1) / 2\n- edges[i].length == 3\n- 0 <= a_i, b_i< n\n- w_i = -1 or 1 <= w_i<= 10^7\n- a_i!= b_i\n- 0 <= source, destination < n\n- source != destination\n- 1 <= target <= 10^9\n- The graph is connected, and there are no self-loops or repeated edges\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(n=2, edges=[[0, 1, -1]], source=0, destination=1, target=1), [[0, 1, 1]])\n assert answers_match(candidate(n=4, edges=[[1, 0, 4], [1, 2, 3], [2, 3, 5], [0, 3, -1]], source=0, destination=2, target=6), [[1, 0, 4], [1, 2, 3], [2, 3, 5], [0, 3, 1]])\n assert answers_match(candidate(n=6, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 0, -1]], source=0, destination=3, target=12), [[0, 1, 1], [1, 2, 1], [2, 3, 10], [3, 4, 2000000000], [4, 5, 2000000000], [5, 0, 2000000000]])\n assert answers_match(candidate(n=4, edges=[[0, 1, 2], [1, 2, -1], [2, 3, -1], [3, 0, -1]], source=0, destination=3, target=5), [[0, 1, 2], [1, 2, 1], [2, 3, 2], [3, 0, 2000000000]])\n assert answers_match(candidate(n=3, edges=[[0, 1, 1], [1, 2, -1]], source=0, destination=2, target=4), [[0, 1, 1], [1, 2, 3]])\n assert answers_match(candidate(n=6, edges=[[0, 1, 2], [1, 2, 3], [2, 3, -1], [3, 4, -1], [4, 5, -1]], source=0, destination=5, target=15), [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 1], [4, 5, 8]])\n assert answers_match(candidate(n=4, edges=[[0, 1, -1], [0, 2, -1], [1, 2, -1], [1, 3, -1], [2, 3, -1]], source=0, destination=3, target=3), [[0, 1, 1], [0, 2, 1], [1, 2, 1], [1, 3, 2], [2, 3, 2000000000]])\n assert answers_match(candidate(n=5, edges=[[4, 1, -1], [2, 0, -1], [0, 3, -1], [4, 3, -1]], source=0, destination=1, target=5), [[4, 1, 1], [2, 0, 1], [0, 3, 1], [4, 3, 3]])\n assert answers_match(candidate(n=6, edges=[[0, 1, 2], [1, 2, 3], [2, 3, -1], [3, 4, -1], [4, 5, -1]], source=0, destination=5, target=12), [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 1], [4, 5, 5]])\n assert answers_match(candidate(n=3, edges=[[0, 1, -1], [0, 2, 5]], source=0, destination=2, target=6), [])\n assert answers_match(candidate(n=4, edges=[[0, 1, 1], [1, 2, -1], [2, 3, -1], [0, 3, -1]], source=0, destination=3, target=3), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [0, 3, 2000000000]])\n assert answers_match(candidate(n=9, edges=[[0, 1, 1], [1, 2, 2], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, 3], [6, 7, -1], [7, 8, -1], [8, 0, 4], [0, 3, -1], [1, 4, -1], [2, 5, -1], [3, 6, 5], [4, 7, -1], [5, 8, -1]], source=0, destination=8, target=25), [])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 0, -1], [0, 4, 8]], source=0, destination=5, target=25), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 21], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 0, 2000000000], [0, 4, 8]])\n assert answers_match(candidate(n=10, edges=[[0, 1, 5], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=0, destination=5, target=30), [[0, 1, 5], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 22], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=7, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 0, -1], [0, 3, 5], [1, 4, 6], [2, 5, 7]], source=0, destination=6, target=28), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 23], [6, 0, 2000000000], [0, 3, 5], [1, 4, 6], [2, 5, 7]])\n assert answers_match(candidate(n=10, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1], [0, 5, 10]], source=0, destination=7, target=30), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 24], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000], [0, 5, 10]])\n assert answers_match(candidate(n=7, edges=[[0, 1, 1], [0, 2, -1], [1, 3, -1], [1, 4, -1], [2, 5, 3], [2, 6, -1], [3, 4, 2], [4, 5, -1], [5, 6, 1]], source=0, destination=6, target=18), [[0, 1, 1], [0, 2, 14], [1, 3, 2000000000], [1, 4, 2000000000], [2, 5, 3], [2, 6, 2000000000], [3, 4, 2], [4, 5, 2000000000], [5, 6, 1]])\n assert answers_match(candidate(n=10, edges=[[0, 1, 1], [1, 2, -1], [2, 3, 2], [3, 4, -1], [4, 5, 3], [5, 6, -1], [6, 7, 4], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=0, destination=5, target=20), [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 13], [4, 5, 3], [5, 6, 2000000000], [6, 7, 4], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=13, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 0, -1]], source=0, destination=12, target=52), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 12, 41], [12, 0, 2000000000]])\n assert answers_match(candidate(n=6, edges=[[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 0, 1]], source=0, destination=3, target=10), [])\n assert answers_match(candidate(n=15, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 0, -1]], source=2, destination=11, target=30), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 22], [11, 12, 2000000000], [12, 13, 2000000000], [13, 14, 2000000000], [14, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1], [0, 2, -1], [1, 3, -1], [2, 4, -1], [3, 5, -1], [4, 6, -1], [5, 7, -1]], source=0, destination=7, target=32), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 26], [7, 0, 2000000000], [0, 2, 2000000000], [1, 3, 2000000000], [2, 4, 2000000000], [3, 5, 2000000000], [4, 6, 2000000000], [5, 7, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, -1], [1, 2, -1], [2, 3, 2], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1]], source=0, destination=6, target=20), [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 5, 1], [5, 6, 14], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000]])\n assert answers_match(candidate(n=20, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 15, -1], [15, 16, -1], [16, 17, -1], [17, 18, -1], [18, 19, -1], [19, 0, -1]], source=0, destination=15, target=60), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 12, 1], [12, 13, 1], [13, 14, 1], [14, 15, 46], [15, 16, 2000000000], [16, 17, 2000000000], [17, 18, 2000000000], [18, 19, 2000000000], [19, 0, 2000000000]])\n assert answers_match(candidate(n=15, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 0, -1]], source=0, destination=14, target=60), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 12, 1], [12, 13, 1], [13, 14, 47], [14, 0, 2000000000]])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 0, -1], [1, 3, 6], [3, 5, 7], [5, 7, 8]], source=0, destination=7, target=35), [[0, 1, 14], [1, 2, 2000000000], [2, 3, 2000000000], [3, 4, 2000000000], [4, 5, 2000000000], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 0, 2000000000], [1, 3, 6], [3, 5, 7], [5, 7, 8]])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 0, -1], [0, 4, -1], [4, 8, -1], [8, 3, -1], [3, 7, -1], [7, 1, -1], [1, 5, -1], [5, 2, -1], [2, 6, -1]], source=0, destination=6, target=30), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 25], [6, 7, 2000000000], [7, 8, 2000000000], [8, 0, 2000000000], [0, 4, 2000000000], [4, 8, 2000000000], [8, 3, 2000000000], [3, 7, 2000000000], [7, 1, 2000000000], [1, 5, 2000000000], [5, 2, 2000000000], [2, 6, 2000000000]])\n assert answers_match(candidate(n=15, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 0, -1], [0, 7, 10], [2, 9, 11], [4, 11, 12], [6, 13, 13]], source=0, destination=10, target=50), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 41], [10, 11, 2000000000], [11, 12, 2000000000], [12, 13, 2000000000], [13, 14, 2000000000], [14, 0, 2000000000], [0, 7, 10], [2, 9, 11], [4, 11, 12], [6, 13, 13]])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 0, -1], [0, 4, 5], [1, 5, -1], [2, 6, -1], [3, 7, -1], [4, 8, -1], [5, 0, -1], [6, 1, -1], [7, 2, -1], [8, 3, -1]], source=0, destination=4, target=15), [])\n assert answers_match(candidate(n=10, edges=[[0, 1, 2], [1, 2, -1], [2, 3, -1], [3, 4, 4], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=0, destination=6, target=18), [[0, 1, 2], [1, 2, 1], [2, 3, 1], [3, 4, 4], [4, 5, 1], [5, 6, 9], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=11, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 0, -1]], source=0, destination=5, target=15), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 11], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 10, 2000000000], [10, 0, 2000000000]])\n assert answers_match(candidate(n=9, edges=[[0, 1, 7], [1, 2, -1], [2, 3, 5], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 0, -1]], source=0, destination=5, target=20), [[0, 1, 7], [1, 2, 1], [2, 3, 5], [3, 4, 1], [4, 5, 6], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 0, 2000000000]])\n assert answers_match(candidate(n=7, edges=[[0, 1, -1], [1, 2, 1], [2, 3, -1], [3, 4, 2], [4, 5, -1], [5, 6, 3], [6, 0, -1], [0, 3, -1], [1, 4, -1], [2, 5, -1], [3, 6, -1], [4, 0, -1], [5, 1, -1], [6, 2, -1]], source=0, destination=5, target=20), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 2], [4, 5, 15], [5, 6, 3], [6, 0, 2000000000], [0, 3, 2000000000], [1, 4, 2000000000], [2, 5, 2000000000], [3, 6, 2000000000], [4, 0, 2000000000], [5, 1, 2000000000], [6, 2, 2000000000]])\n assert answers_match(candidate(n=11, edges=[[0, 1, -1], [1, 2, -1], [2, 3, 3], [3, 4, -1], [4, 5, 5], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, 9], [9, 10, -1]], source=0, destination=10, target=40), [[0, 1, 1], [1, 2, 1], [2, 3, 3], [3, 4, 1], [4, 5, 5], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 9], [9, 10, 17]])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, 5], [5, 6, 3], [6, 7, 2], [7, 8, -1], [8, 0, -1]], source=0, destination=7, target=13), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 5], [5, 6, 3], [6, 7, 2], [7, 8, 1], [8, 0, 12]])\n assert answers_match(candidate(n=7, edges=[[0, 1, 5], [1, 2, 3], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 0, -1]], source=0, destination=4, target=12), [[0, 1, 5], [1, 2, 3], [2, 3, 1], [3, 4, 3], [4, 5, 2000000000], [5, 6, 2000000000], [6, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, 5], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1], [0, 3, 7]], source=0, destination=6, target=20), [[0, 1, 5], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 11], [6, 7, 2000000000], [7, 0, 2000000000], [0, 3, 7]])\n assert answers_match(candidate(n=10, edges=[[0, 1, 7], [1, 2, -1], [2, 3, 10], [3, 4, -1], [4, 5, -1], [5, 6, 8], [6, 7, -1], [7, 8, -1], [8, 9, -1], [0, 9, -1]], source=0, destination=9, target=40), [[0, 1, 7], [1, 2, 1], [2, 3, 10], [3, 4, 1], [4, 5, 1], [5, 6, 8], [6, 7, 1], [7, 8, 1], [8, 9, 10], [0, 9, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, 2], [1, 2, -1], [2, 3, 3], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1], [0, 4, -1], [1, 5, -1], [2, 6, -1], [3, 7, -1]], source=0, destination=6, target=25), [[0, 1, 2], [1, 2, 1], [2, 3, 3], [3, 4, 1], [4, 5, 1], [5, 6, 17], [6, 7, 2000000000], [7, 0, 2000000000], [0, 4, 2000000000], [1, 5, 2000000000], [2, 6, 2000000000], [3, 7, 2000000000]])\n assert answers_match(candidate(n=7, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 0, -1], [0, 3, 7], [1, 4, 8], [2, 5, 9]], source=0, destination=4, target=20), [[0, 1, 12], [1, 2, 2000000000], [2, 3, 2000000000], [3, 4, 2000000000], [4, 5, 2000000000], [5, 6, 2000000000], [6, 0, 2000000000], [0, 3, 7], [1, 4, 8], [2, 5, 9]])\n assert answers_match(candidate(n=7, edges=[[0, 1, 5], [1, 2, -1], [2, 3, 7], [3, 4, -1], [4, 5, 9], [5, 6, -1], [6, 0, -1]], source=0, destination=4, target=20), [[0, 1, 5], [1, 2, 1], [2, 3, 7], [3, 4, 7], [4, 5, 9], [5, 6, 2000000000], [6, 0, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, 3], [1, 2, -1], [2, 3, 2], [3, 4, -1], [4, 5, 4], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1], [0, 6, 5], [1, 7, 6], [2, 8, -1], [3, 9, -1], [4, 10, -1], [5, 11, -1]], source=0, destination=8, target=30), [[0, 1, 3], [1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 5, 4], [5, 6, 1], [6, 7, 1], [7, 8, 24], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000], [0, 6, 5], [1, 7, 6], [2, 8, 2000000000], [3, 9, 2000000000], [4, 10, 2000000000], [5, 11, 2000000000]])\n assert answers_match(candidate(n=7, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 0, -1], [0, 3, -1], [1, 4, -1], [2, 5, -1]], source=0, destination=5, target=15), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 11], [5, 6, 2000000000], [6, 0, 2000000000], [0, 3, 2000000000], [1, 4, 2000000000], [2, 5, 2000000000]])\n assert answers_match(candidate(n=11, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 0, -1], [0, 6, 12]], source=0, destination=8, target=35), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 28], [8, 9, 2000000000], [9, 10, 2000000000], [10, 0, 2000000000], [0, 6, 12]])\n assert answers_match(candidate(n=10, edges=[[0, 1, -1], [1, 2, -1], [2, 3, 5], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, 9], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=1, destination=8, target=40), [[0, 1, 1], [1, 2, 1], [2, 3, 5], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 9], [7, 8, 22], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, 1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1]], source=1, destination=9, target=25), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 18], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, 3], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1], [0, 6, 5], [2, 8, 4]], source=0, destination=8, target=30), [[0, 1, 3], [1, 2, 23], [2, 3, 2000000000], [3, 4, 2000000000], [4, 5, 2000000000], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000], [0, 6, 5], [2, 8, 4]])\n assert answers_match(candidate(n=8, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1]], source=0, destination=7, target=24), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 18], [7, 0, 2000000000]])\n assert answers_match(candidate(n=20, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 15, -1], [15, 16, -1], [16, 17, -1], [17, 18, -1], [18, 19, -1], [19, 0, -1]], source=5, destination=15, target=50), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 12, 1], [12, 13, 1], [13, 14, 1], [14, 15, 41], [15, 16, 2000000000], [16, 17, 2000000000], [17, 18, 2000000000], [18, 19, 2000000000], [19, 0, 2000000000]])\n assert answers_match(candidate(n=5, edges=[[0, 1, 1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 0, -1], [0, 2, -1], [1, 3, -1], [2, 4, -1]], source=0, destination=4, target=10), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 7], [4, 0, 2000000000], [0, 2, 2000000000], [1, 3, 2000000000], [2, 4, 2000000000]])\n assert answers_match(candidate(n=10, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, 1]], source=0, destination=5, target=12), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 8], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 1]])\n assert answers_match(candidate(n=12, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1], [0, 7, 15]], source=0, destination=9, target=40), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 32], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000], [0, 7, 15]])\n assert answers_match(candidate(n=15, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 0, -1]], source=0, destination=7, target=49), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 43], [7, 8, 2000000000], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 12, 2000000000], [12, 13, 2000000000], [13, 14, 2000000000], [14, 0, 2000000000]])\n assert answers_match(candidate(n=15, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 0, -1]], source=0, destination=7, target=50), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 44], [7, 8, 2000000000], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 12, 2000000000], [12, 13, 2000000000], [13, 14, 2000000000], [14, 0, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, 1], [1, 2, -1], [2, 3, 3], [3, 4, -1], [4, 5, 5], [5, 6, -1], [6, 7, 7], [7, 8, -1], [8, 9, 9], [9, 10, -1], [10, 11, -1], [11, 0, -1]], source=0, destination=10, target=45), [[0, 1, 1], [1, 2, 1], [2, 3, 3], [3, 4, 1], [4, 5, 5], [5, 6, 1], [6, 7, 7], [7, 8, 1], [8, 9, 9], [9, 10, 16], [10, 11, 2000000000], [11, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, -1], [1, 2, -1], [2, 3, 6], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1]], source=1, destination=6, target=15), [[0, 1, 1], [1, 2, 1], [2, 3, 6], [3, 4, 1], [4, 5, 1], [5, 6, 6], [6, 7, 2000000000], [7, 0, 2000000000]])\n assert answers_match(candidate(n=13, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 0, -1], [0, 8, 20]], source=0, destination=10, target=45), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 36], [10, 11, 2000000000], [11, 12, 2000000000], [12, 0, 2000000000], [0, 8, 20]])\n assert answers_match(candidate(n=10, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=0, destination=5, target=20), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 16], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=7, edges=[[0, 1, -1], [1, 2, -1], [2, 3, 2], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 0, -1]], source=0, destination=4, target=10), [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 6], [4, 5, 2000000000], [5, 6, 2000000000], [6, 0, 2000000000]])\n assert answers_match(candidate(n=10, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=0, destination=5, target=25), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 21], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=10, edges=[[0, 1, 2], [1, 2, 3], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=0, destination=5, target=25), [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 1], [4, 5, 18], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, 2], [1, 2, 3], [2, 3, -1], [3, 4, -1], [4, 5, 5], [5, 6, -1], [6, 7, -1], [7, 0, -1]], source=1, destination=6, target=25), [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 1], [4, 5, 5], [5, 6, 15], [6, 7, 2000000000], [7, 0, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, 3], [1, 2, 2], [2, 3, 1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1]], source=0, destination=6, target=18), [[0, 1, 3], [1, 2, 2], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 10], [6, 7, 2000000000], [7, 8, 2000000000], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000]])\n assert answers_match(candidate(n=5, edges=[[0, 1, 10], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 0, -1]], source=0, destination=2, target=15), [[0, 1, 10], [1, 2, 5], [2, 3, 2000000000], [3, 4, 2000000000], [4, 0, 2000000000]])\n assert answers_match(candidate(n=20, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 12, -1], [12, 13, -1], [13, 14, -1], [14, 15, -1], [15, 16, -1], [16, 17, -1], [17, 18, -1], [18, 19, -1], [19, 0, -1], [0, 10, 15], [2, 12, 16], [4, 14, 17], [6, 16, 18], [8, 18, 19]], source=0, destination=15, target=75), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 12, 1], [12, 13, 1], [13, 14, 1], [14, 15, 61], [15, 16, 2000000000], [16, 17, 2000000000], [17, 18, 2000000000], [18, 19, 2000000000], [19, 0, 2000000000], [0, 10, 15], [2, 12, 16], [4, 14, 17], [6, 16, 18], [8, 18, 19]])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 0, -1]], source=0, destination=4, target=15), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 12], [4, 5, 2000000000], [5, 6, 2000000000], [6, 7, 2000000000], [7, 8, 2000000000], [8, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, 2], [1, 2, -1], [2, 3, -1], [3, 4, 4], [4, 5, -1], [5, 6, 6], [6, 7, -1], [7, 0, 8]], source=0, destination=6, target=20), [[0, 1, 2], [1, 2, 1], [2, 3, 1], [3, 4, 4], [4, 5, 6], [5, 6, 6], [6, 7, 2000000000], [7, 0, 8]])\n assert answers_match(candidate(n=12, edges=[[0, 1, 1], [1, 2, -1], [2, 3, 2], [3, 4, -1], [4, 5, 3], [5, 6, -1], [6, 7, 4], [7, 8, -1], [8, 9, 5], [9, 10, -1], [10, 11, -1], [11, 0, -1]], source=0, destination=10, target=33), [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 5, 3], [5, 6, 1], [6, 7, 4], [7, 8, 1], [8, 9, 5], [9, 10, 14], [10, 11, 2000000000], [11, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, -1], [1, 2, 5], [2, 3, -1], [3, 4, -1], [4, 5, 3], [5, 6, -1], [6, 7, -1], [7, 0, -1]], source=0, destination=5, target=12), [[0, 1, 1], [1, 2, 5], [2, 3, 1], [3, 4, 2], [4, 5, 3], [5, 6, 2000000000], [6, 7, 2000000000], [7, 0, 2000000000]])\n assert answers_match(candidate(n=12, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 10, -1], [10, 11, -1], [11, 0, -1], [0, 5, -1], [5, 10, -1], [10, 3, -1], [3, 8, -1]], source=0, destination=8, target=50), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 43], [8, 9, 2000000000], [9, 10, 2000000000], [10, 11, 2000000000], [11, 0, 2000000000], [0, 5, 2000000000], [5, 10, 2000000000], [10, 3, 2000000000], [3, 8, 2000000000]])\n assert answers_match(candidate(n=10, edges=[[0, 1, 2], [0, 2, -1], [1, 3, 4], [1, 4, -1], [2, 5, 6], [2, 6, -1], [3, 7, -1], [4, 8, -1], [5, 9, -1], [6, 8, -1], [7, 9, 5]], source=0, destination=9, target=20), [[0, 1, 2], [0, 2, 1], [1, 3, 4], [1, 4, 1], [2, 5, 6], [2, 6, 1], [3, 7, 9], [4, 8, 2000000000], [5, 9, 2000000000], [6, 8, 2000000000], [7, 9, 5]])\n assert answers_match(candidate(n=7, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 0, -1]], source=0, destination=4, target=18), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 15], [4, 5, 2000000000], [5, 6, 2000000000], [6, 0, 2000000000]])\n assert answers_match(candidate(n=9, edges=[[0, 1, -1], [1, 2, -1], [2, 3, 4], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, 6], [7, 8, -1], [8, 0, -1]], source=0, destination=5, target=30), [[0, 1, 1], [1, 2, 1], [2, 3, 4], [3, 4, 1], [4, 5, 23], [5, 6, 2000000000], [6, 7, 6], [7, 8, 2000000000], [8, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1], [0, 2, -1], [2, 4, -1], [4, 6, -1], [6, 1, -1]], source=0, destination=6, target=25), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 20], [6, 7, 2000000000], [7, 0, 2000000000], [0, 2, 2000000000], [2, 4, 2000000000], [4, 6, 2000000000], [6, 1, 2000000000]])\n assert answers_match(candidate(n=10, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, 7], [5, 6, 8], [6, 7, -1], [7, 8, -1], [8, 9, -1], [9, 0, -1]], source=2, destination=7, target=35), [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 7], [5, 6, 8], [6, 7, 18], [7, 8, 2000000000], [8, 9, 2000000000], [9, 0, 2000000000]])\n assert answers_match(candidate(n=7, edges=[[0, 1, 2], [1, 2, -1], [2, 3, 4], [3, 4, -1], [4, 5, -1], [5, 6, 1], [6, 0, -1]], source=0, destination=4, target=10), [[0, 1, 2], [1, 2, 1], [2, 3, 4], [3, 4, 3], [4, 5, 2000000000], [5, 6, 1], [6, 0, 2000000000]])\n assert answers_match(candidate(n=8, edges=[[0, 1, -1], [1, 2, -1], [2, 3, -1], [3, 4, -1], [4, 5, -1], [5, 6, -1], [6, 7, -1], [7, 0, -1], [1, 3, 4], [3, 6, 5]], source=0, destination=6, target=20), [[0, 1, 11], [1, 2, 2000000000], [2, 3, 2000000000], [3, 4, 2000000000], [4, 5, 2000000000], [5, 6, 2000000000], [6, 7, 2000000000], [7, 0, 2000000000], [1, 3, 4], [3, 6, 5]])\n", "comparison": "unordered"}, "public_tests": ["5\n[[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]]\n0\n1\n5", "3\n[[0,1,-1],[0,2,5]]\n0\n2\n6", "4\n[[1,0,4],[1,2,3],[2,3,5],[0,3,-1]]\n0\n2\n6"], "hints": ["Firstly, check that it’s actually possible to make the shortest path from source to destination equal to the target.", "If the shortest path from source to destination without the edges to be modified, is less than the target, then it is not possible.", "If the shortest path from source to destination including the edges to be modified and assigning them a temporary weight of 1, is greater than the target, then it is also not possible.", "Suppose we can find a modifiable edge (u, v) such that the length of the shortest path from source to u (dis1) plus the length of the shortest path from v to destination (dis2) is less than target (dis1 + dis2 < target), then we can change its weight to “target - dis1 - dis2”.", "For all the other edges that still have the weight “-1”, change the weights into sufficient large number (target, target + 1 or 200000000 etc.)."], "metadata": {"canonical_parameter_names": ["n", "edges", "source", "destination", "target"], "leetcode_dataset_entry_point": "Solution().modifiedGraphEdges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:49+00:00", "tests_total": 77, "tests_dropped": 0, "flags": ["any_order", "has_images"], "topic_tags": ["graph", "heap-priority-queue", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def modified_graph_edges(n, edges, source, destination, target)", "container": null, "callable": "modified_graph_edges", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "source", "type": "Integer"}, {"name": "destination", "type": "Integer"}, {"name": "target", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2706, "task_id": "buy-two-chocolates", "difficulty": "Easy", "problem_description": "You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.\n\nYou must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.\n\nReturn the amount of money you will have leftover after buying the two chocolates. If there is no way for you to buy two chocolates without ending up in debt, return money. Note that the leftover must be non-negative.\n\nExample 1:\n\nInput: prices = [1,2,2], money = 3\nOutput: 0\nExplanation: Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.\n\nExample 2:\n\nInput: prices = [3,2,3], money = 3\nOutput: 3\nExplanation: You cannot buy 2 chocolates without going in debt, so we return 3.\n\nConstraints:\n\n- 2 <= prices.length <= 50\n- 1 <= prices[i] <= 100\n- 1 <= money <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(prices = [99, 1],money = 100) == 0\n assert candidate(prices = [5, 4, 3, 2, 1],money = 10) == 7\n assert candidate(prices = [1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [1, 1],money = 3) == 1\n assert candidate(prices = [1, 2, 2],money = 3) == 0\n assert candidate(prices = [1, 1, 1, 1, 1],money = 1) == 1\n assert candidate(prices = [1, 1, 1, 1, 1],money = 1) == 1\n assert candidate(prices = [50, 50],money = 100) == 0\n assert candidate(prices = [1, 2, 3, 4, 5],money = 8) == 5\n assert candidate(prices = [5, 5, 5, 5],money = 10) == 0\n assert candidate(prices = [10, 5, 7, 3],money = 15) == 7\n assert candidate(prices = [10, 20, 30],money = 50) == 20\n assert candidate(prices = [10, 20, 30, 40],money = 60) == 30\n assert candidate(prices = [3, 2, 3],money = 3) == 3\n assert candidate(prices = [10, 20, 30],money = 50) == 20\n assert candidate(prices = [10, 20, 30],money = 25) == 25\n assert candidate(prices = [5, 5, 5, 5],money = 10) == 0\n assert candidate(prices = [2, 2, 2, 2, 2],money = 5) == 1\n assert candidate(prices = [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],money = 98) == 87\n assert candidate(prices = [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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],money = 8) == 0\n assert candidate(prices = [4, 1, 2, 3, 5, 6, 7, 8, 9, 10],money = 11) == 8\n assert candidate(prices = [50, 50, 50, 50, 50],money = 99) == 99\n assert candidate(prices = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],money = 100) == 0\n assert candidate(prices = [5, 3, 7, 9, 2, 6, 8, 1, 4, 10],money = 12) == 9\n assert candidate(prices = [50, 1, 50, 2, 3, 4, 5],money = 52) == 49\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],money = 11) == 8\n assert candidate(prices = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],money = 50) == 45\n assert candidate(prices = [5, 4, 3, 2, 1],money = 10) == 7\n assert candidate(prices = [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],money = 10) == 0\n assert candidate(prices = [1, 99, 1, 98, 1, 97, 1, 96, 1, 95],money = 100) == 98\n assert candidate(prices = [1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],money = 11) == 8\n assert candidate(prices = [50, 50, 50, 50, 50],money = 100) == 0\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [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],money = 29) == 26\n assert candidate(prices = [50, 25, 75, 100, 20],money = 100) == 55\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],money = 18) == 15\n assert candidate(prices = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],money = 90) == 75\n assert candidate(prices = [5, 4, 3, 2, 1],money = 3) == 0\n assert candidate(prices = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],money = 10) == 10\n assert candidate(prices = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],money = 100) == 100\n assert candidate(prices = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],money = 99) == 99\n assert candidate(prices = [50, 51, 49, 48, 52, 53, 47, 46, 54, 55],money = 100) == 7\n assert candidate(prices = [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],money = 10) == 0\n assert candidate(prices = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],money = 5) == 5\n assert candidate(prices = [50, 10, 15, 20, 25],money = 55) == 30\n assert candidate(prices = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],money = 60) == 51\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],money = 30) == 27\n assert candidate(prices = [40, 30, 20, 10, 5, 15, 25, 35, 45, 50],money = 60) == 45\n assert candidate(prices = [45, 22, 13, 8, 3],money = 60) == 49\n assert candidate(prices = [80, 10, 50, 20, 30],money = 60) == 30\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [10, 15, 20, 25, 30, 35, 40],money = 60) == 35\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],money = 39) == 36\n assert candidate(prices = [75, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],money = 100) == 50\n assert candidate(prices = [1, 99, 1, 98],money = 100) == 98\n assert candidate(prices = [33, 33, 33, 33, 33, 33, 33, 33, 33, 33],money = 66) == 0\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],money = 15) == 12\n assert candidate(prices = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],money = 20) == 0\n assert candidate(prices = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],money = 100) == 80\n assert candidate(prices = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],money = 100) == 0\n assert candidate(prices = [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],money = 3) == 1\n assert candidate(prices = [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],money = 100) == 97\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],money = 2) == 0\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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],money = 3) == 1\n assert candidate(prices = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],money = 80) == 65\n assert candidate(prices = [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],money = 31) == 28\n assert candidate(prices = [99, 50, 50, 1, 1],money = 100) == 98\n assert candidate(prices = [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],money = 11) == 1\n assert candidate(prices = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],money = 100) == 96\n assert candidate(prices = [5, 8, 12, 18, 22, 25],money = 40) == 27\n assert candidate(prices = [3, 6, 5, 8, 9, 2, 4, 7, 1, 10],money = 12) == 9\n", "comparison": "exact"}, "public_tests": ["[1,2,2]\n3", "[3,2,3]\n3"], "hints": ["Sort the array and check if the money is more than or equal to the sum of the two cheapest elements."], "metadata": {"canonical_parameter_names": ["prices", "money"], "leetcode_dataset_entry_point": "Solution().buyChoco", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:54+00:00", "tests_total": 111, "tests_dropped": 39, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def buy_choco(prices, money)", "container": null, "callable": "buy_choco", "parameters": [{"name": "prices", "type": "Integer[]"}, {"name": "money", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2707, "task_id": "extra-characters-in-a-string", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.\n\nReturn the minimum number of extra characters left over if you break up s optimally.\n\nExample 1:\n\nInput: s = \"leetscode\", dictionary = [\"leet\",\"code\",\"leetcode\"]\nOutput: 1\nExplanation: We can break s in two substrings: \"leet\" from index 0 to 3 and \"code\" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.\n\nExample 2:\n\nInput: s = \"sayhelloworld\", dictionary = [\"hello\",\"world\"]\nOutput: 3\nExplanation: We can break s in two substrings: \"hello\" from index 3 to 7 and \"world\" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.\n\nConstraints:\n\n- 1 <= s.length <= 50\n- 1 <= dictionary.length <= 50\n- 1 <= dictionary[i].length <= 50\n- dictionary[i] and s consists of only lowercase English letters\n- dictionary contains distinct words\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",dictionary = ['a', 'b', 'c']) == 0\n assert candidate(s = \"sayhelloworld\",dictionary = ['hello', 'world']) == 3\n assert candidate(s = \"abc\",dictionary = ['d', 'e']) == 3\n assert candidate(s = \"abcabcabc\",dictionary = ['abcabc', 'abc']) == 0\n assert candidate(s = \"abracadabra\",dictionary = ['abra', 'cadabra', 'abc']) == 0\n assert candidate(s = \"abc\",dictionary = ['d', 'e', 'f']) == 3\n assert candidate(s = \"applepenapple\",dictionary = ['apple', 'pen']) == 0\n assert candidate(s = \"catsandog\",dictionary = ['cats', 'dog', 'sand', 'and', 'cat']) == 2\n assert candidate(s = \"ab\",dictionary = ['abc', 'def']) == 2\n assert candidate(s = \"abcde\",dictionary = ['a', 'b', 'c', 'd', 'e']) == 0\n assert candidate(s = \"programming\",dictionary = ['pro', 'gram', 'ming']) == 0\n assert candidate(s = \"a\",dictionary = ['b']) == 1\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'is', 'ip', 'i', 'p']) == 2\n assert candidate(s = \"leetscode\",dictionary = ['leet', 'code', 'leetcode']) == 1\n assert candidate(s = \"aabbcc\",dictionary = ['a', 'b', 'c']) == 0\n assert candidate(s = \"programmingisfun\",dictionary = ['pro', 'gram', 'ming', 'is', 'fun', 'prog', 'am', 'ing', 'pr', 'gramm', 'ingis', 'funs']) == 0\n assert candidate(s = \"dynamicprogramming\",dictionary = ['dyn', 'ami', 'cpro', 'gram', 'ming', 'pro', 'gramming']) == 0\n assert candidate(s = \"algorithm\",dictionary = ['algo', 'rith', 'm', 'alg', 'ith', 'o', 'g', 'a', 'l', 'th', 'or', 'thm', 'al']) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",dictionary = ['a', 'z', 'abc', 'xyz', 'mnopqr', 'uvw', 'def', 'jkl']) == 5\n assert candidate(s = \"substringsearch\",dictionary = ['sub', 'string', 'search', 'substri', 'ngsea', 'rch', 'str', 'sea', 'subsearc', 'ubstringse']) == 0\n assert candidate(s = \"encyclopedia\",dictionary = ['ency', 'clop', 'edia', 'lo', 'pedia', 'cycle', 'en', 'dec', 'clo', 'opaedia']) == 0\n assert candidate(s = \"thisisateststring\",dictionary = ['this', 'is', 'a', 'test', 'string', 'isatest', 'teststr', 'str', 'ring', 'thi', 'sta', 'tes', 'ing', 'est', 'at']) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",dictionary = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']) == 0\n assert candidate(s = \"optimization\",dictionary = ['opt', 'imiz', 'tio', 'n', 'zat', 'ion', 'optim']) == 1\n assert candidate(s = \"programmingisfun\",dictionary = ['pro', 'gram', 'ming', 'is', 'fun', 'gramm', 'ing', 'program', 'mingis', 'funn']) == 0\n assert candidate(s = \"thisisatest\",dictionary = ['this', 'is', 'a', 'test', 'ate', 'st']) == 0\n assert candidate(s = \"programmingchallenge\",dictionary = ['pro', 'gram', 'ming', 'chall', 'lenge', 'ge']) == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",dictionary = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']) == 0\n assert candidate(s = \"encyclopedia\",dictionary = ['ency', 'clopedia', 'encyclo', 'pedia', 'encyclope', 'dopia', 'edia', 'a', 'ei', 'lo', 'ope', 'dic', 'lope', 'dia', 'edia']) == 0\n assert candidate(s = \"minimizingextra\",dictionary = ['mini', 'min', 'zing', 'extra', 'ze', 'tra', 'minimize']) == 2\n assert candidate(s = \"repeatedcharacters\",dictionary = ['re', 'pe', 'at', 'ed', 'cha', 'rac', 'ters', 'ter', 'char', 'acters']) == 0\n assert candidate(s = \"findingthesolution\",dictionary = ['find', 'ing', 'the', 'solu', 'tion', 'solution', 'thesolu', 'tingthe', 'thesolu', 'solu', 'tionfind', 'ingthe', 'thesolution', 'ingthes']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'sis', 'ip', 'i', 'ss', 'p']) == 1\n assert candidate(s = \"aaaaabbbbb\",dictionary = ['a', 'b', 'aa', 'bb', 'ab', 'ba', 'aaa', 'bbb', 'aab', 'bba', 'aba', 'bab']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['issi', 'ssippi', 'miss', 'ippi', 'is', 's', 'pi', 'p']) == 0\n assert candidate(s = \"subsequences\",dictionary = ['sub', 'seq', 'uen', 'ce', 's', 'quence', 'quencece']) == 0\n assert candidate(s = \"backtracking\",dictionary = ['back', 'track', 'ing', 'backtr', 'acking', 'tracki', 'ing']) == 0\n assert candidate(s = \"abcdefghijk\",dictionary = ['abc', 'def', 'gh', 'ijk', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']) == 0\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",dictionary = ['abc', 'def', 'ghi', 'j', 'abcdefghij', 'abcdefgh', 'abcde', 'fghij', 'ab', 'cd', 'ef', 'gh', 'ij']) == 0\n assert candidate(s = \"thisisaverylongstring\",dictionary = ['this', 'is', 'a', 'very', 'long', 'string', 'thi', 'sis', 'verylong']) == 0\n assert candidate(s = \"optimallybreakingstrings\",dictionary = ['opti', 'mally', 'breaking', 'strings', 'opt', 'im', 'ally', 'break', 'ing', 'str', 'ing', 's', 'optimal', 'breaks', 'allybreak']) == 0\n assert candidate(s = \"abracadabra\",dictionary = ['abra', 'cad', 'bra', 'abc', 'rac']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'si', 'issi', 'pi', 'ppi', 'pis', 'missis', 'sippi', 'ippi', 'issipp']) == 0\n assert candidate(s = \"xylophone\",dictionary = ['xy', 'lo', 'phone', 'ph', 'one', 'xo', 'xyl', 'ylo', 'ho', 'ne', 'pho']) == 0\n assert candidate(s = \"subsequences\",dictionary = ['sub', 'seq', 'en', 'ce', 'qu', 'subseq', 'quence']) == 2\n assert candidate(s = \"thecodinginterview\",dictionary = ['the', 'coding', 'in', 'terview', 'inter', 'view', 'codingin', 'erview', 'viewint', 'nterview', 'inerview']) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",dictionary = ['a', 'z', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']) == 0\n assert candidate(s = \"abracadabra\",dictionary = ['abra', 'cad', 'bra', 'rac', 'ab', 'ad', 'a', 'b', 'c', 'd', 'r']) == 0\n assert candidate(s = \"optimization\",dictionary = ['opti', 'miz', 'ation', 'iza', 'ti', 'on']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'sis', 'ip', 'i', 'ss', 'is', 'pi', 'pp']) == 1\n assert candidate(s = \"dynamicprogramming\",dictionary = ['dynamic', 'program', 'gram', 'ming', 'pro', 'gramming']) == 0\n assert candidate(s = \"constraints\",dictionary = ['con', 'straint', 'stra', 'ints', 't', 'res', 'trai', 'ns', 'constra']) == 0\n assert candidate(s = \"abcdabcdabcd\",dictionary = ['ab', 'cd', 'abcd', 'abc', 'bcd', 'dabc']) == 0\n assert candidate(s = \"watermelon\",dictionary = ['water', 'melon', 'wa', 'ter', 'melon', 'wa', 'me', 'lo', 'on', 'terme', 'lono', 'wate', 'rme', 'lo', 'non', 'w', 'a', 't', 'e', 'r', 'm', 'e', 'l', 'o', 'n']) == 0\n assert candidate(s = \"breakfast\",dictionary = ['break', 'fast', 'bre', 'ak', 'fastbreak', 'breakfa', 'st']) == 0\n assert candidate(s = \"subsequence\",dictionary = ['sub', 'sequence', 'seq', 'uen', 'ce', 'subse', 'quen']) == 0\n assert candidate(s = \"optimization\",dictionary = ['opti', 'mize', 'optim', 'on', 'ize', 'miz', 'ization']) == 0\n assert candidate(s = \"programming\",dictionary = ['pro', 'gram', 'ming', 'ing', 'progr', 'amming']) == 0\n assert candidate(s = \"alibabacloud\",dictionary = ['ali', 'ba', 'bacloud', 'cloud', 'ib', 'baclou', 'bacla', 'baba', 'clouds', 'alibaba']) == 0\n assert candidate(s = \"segmentation\",dictionary = ['seg', 'men', 'tation', 'ment', 'entation', 'segmen', 't', 'ation']) == 0\n assert candidate(s = \"algorithm\",dictionary = ['algo', 'rithm', 'log', 'ith', 'm', 'a', 'thm', 'gor', 'orithm', 'ithm', 'gori', 'thmi']) == 0\n assert candidate(s = \"beautiful\",dictionary = ['be', 'autiful', 'aut', 'ful', 'at', 'beau', 'ti', 'ful', 'b', 'e', 'a', 'u', 't', 'i', 'f', 'u', 'l', 'beauti', 'ful', 'auti', 'ful', 'beaut', 'iful', 'bea', 'utiful', 'be', 'autiful', 'ti', 'ful', 'bea', 'ut', 'iful', 'beau', 'tiful', 'beaut', 'ifu', 'l']) == 0\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",dictionary = ['quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog', 'qu', 'ick', 'br', 'own', 'fo', 'x', 'ump', 'so', 'ver', 'el', 'az', 'y']) == 0\n assert candidate(s = \"example\",dictionary = ['ex', 'ample', 'am', 'ple', 'e', 'xample']) == 0\n assert candidate(s = \"dynamicprogramming\",dictionary = ['dyn', 'amic', 'prog', 'ram', 'ming', 'gramming', 'pro', 'dynamic', 'grampro', 'mingprog', 'rammi']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'sis', 'sip', 'issi', 'ippi']) == 1\n assert candidate(s = \"subsequence\",dictionary = ['sub', 'seq', 'en', 'ce', 'subse', 'quence']) == 0\n assert candidate(s = \"overlapping\",dictionary = ['over', 'lap', 'ping', 'lap', 'pingo', 'ver', 'lap', 'laplap']) == 0\n assert candidate(s = \"dynamicprogramming\",dictionary = ['dyn', 'amic', 'pro', 'gram', 'ming', 'prog', 'dyna', 'micpro', 'grammi', 'amming']) == 0\n assert candidate(s = \"partitioning\",dictionary = ['parti', 'tion', 'ion', 'part', 'itioning', 'parti', 'tion', 'ing']) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",dictionary = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']) == 0\n assert candidate(s = \"optimization\",dictionary = ['opt', 'im', 'iz', 'ation', 'iza', 'tio']) == 0\n assert candidate(s = \"breakintothepieces\",dictionary = ['break', 'into', 'the', 'pie', 'ces', 'iece', 'to', 'pieces', 'breakin', 'intothep']) == 0\n assert candidate(s = \"fuzzywuzzy\",dictionary = ['fuz', 'zy', 'wuz', 'z', 'wuzz', 'fuzzy', 'wuzzywuzz']) == 0\n assert candidate(s = \"programmingcontest\",dictionary = ['pro', 'gram', 'ming', 'con', 'test', 'gramming', 'est']) == 0\n assert candidate(s = \"abcdefgabcdefg\",dictionary = ['abc', 'def', 'gh', 'abcdef', 'bcde', 'fgh', 'abcd', 'efg', 'fg', 'abcdab', 'bcdefg']) == 0\n assert candidate(s = \"pythonprogramming\",dictionary = ['py', 'thon', 'pro', 'gram', 'ming', 'prog', 'python', 'gramming', 'ron', 'th', 'ing']) == 0\n assert candidate(s = \"helloworld\",dictionary = ['hello', 'wor', 'ld', 'hell', 'world', 'owor', 'orl', 'rld', 'hel', 'wo', 'rld', 'worl', 'hello', 'world', 'worldly', 'or', 'wor', 'ld', 'hell', 'world', 'hellworld', 'hell', 'wo', 'rld', 'hello', 'world']) == 0\n assert candidate(s = \"programmingcontest\",dictionary = ['pro', 'gram', 'ming', 'con', 'test', 'gramming', 'est', 'on', 'gramcon', 'estcontest']) == 0\n assert candidate(s = \"onomatopoeia\",dictionary = ['ono', 'mato', 'poei', 'a', 'ia', 'oeia', 'opoe', 'oe', 'onom', 'atopoeia']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'issi', 'ippi', 'sip', 'iss', 'is', 'i', 'pi', 'missis', 'sippi']) == 0\n assert candidate(s = \"loremipsum\",dictionary = ['lor', 'em', 'ip', 'sum', 'lorem', 'rem', 'ems', 'mip', 'ips', 'pum', 'ipsum']) == 0\n assert candidate(s = \"interview\",dictionary = ['inter', 'view', 'ter', 'iew', 'in', 'terview', 'nterv', 'vieww']) == 0\n assert candidate(s = \"abracadabra\",dictionary = ['ab', 'ra', 'cad', 'abra', 'brac']) == 0\n assert candidate(s = \"programmingcontest\",dictionary = ['pro', 'gram', 'ming', 'con', 'test', 'est', 'contest']) == 0\n assert candidate(s = \"mississippi\",dictionary = ['mis', 'sis', 'sip', 'i', 'ss', 'pi', 'pp']) == 0\n assert candidate(s = \"dynamicprogramming\",dictionary = ['dyn', 'amic', 'pro', 'gram', 'ming', 'gramm', 'prog', 'dyna', 'progr']) == 0\n assert candidate(s = \"supercalifragilisticexpialidocious\",dictionary = ['super', 'cali', 'fragilistic', 'expiali', 'docious', 'ex', 'pi', 'ali', 'ous']) == 0\n assert candidate(s = \"supercalifragilisticexpialidocious\",dictionary = ['super', 'cali', 'fragilistic', 'expiali', 'docious', 'superca', 'lifrag', 'istic', 'expialido', 'cious', 'superca', 'li', 'frag', 'ilistic', 'ex', 'pialido', 'california', 'super', 'superdocus']) == 0\n assert candidate(s = \"supercalifragilisticexpialidocious\",dictionary = ['super', 'cali', 'fragilistic', 'expiali', 'docious', 'frag', 'listic', 'exp', 'ali', 'do', 'cious', 'superca', 'li', 'fragi', 'list', 'expialidoc', 'supercalifrag', 'supercalifragilisticexpi', 'alidocious', 'istic', 'expialidoci', 'superca', 'lifragilisti', 'cexpialid', 'alidoc', 'expialido', 'fragilisticexpialidocious']) == 0\n assert candidate(s = \"optimizationproblems\",dictionary = ['opt', 'im', 'ization', 'prob', 'lems', 'ob', 'lem', 'pro', 'blem', 'blempro']) == 0\n assert candidate(s = \"breakfast\",dictionary = ['break', 'fast', 'bre', 'ak', 'fast', 'reak']) == 0\n assert candidate(s = \"dictionary\",dictionary = ['dic', 'tion', 'tio', 'nary', 'dict', 'ionar', 'ictionary', 'dictio', 'n']) == 0\n assert candidate(s = \"backtracking\",dictionary = ['back', 'track', 'ing', 'bac', 'ktrack', 'king']) == 0\n assert candidate(s = \"algorithms\",dictionary = ['algo', 'rithm', 'thms', 'log', 'rith', 'ms', 'algothm', 'rithms']) == 0\n assert candidate(s = \"optimization\",dictionary = ['opt', 'im', 'ization', 'iz', 'ation', 'optim', 'ize']) == 0\n", "comparison": "exact"}, "public_tests": ["\"leetscode\"\n[\"leet\",\"code\",\"leetcode\"]", "\"sayhelloworld\"\n[\"hello\",\"world\"]"], "hints": ["Can we use Dynamic Programming here?", "Define DP[i] as the min extra character if breaking up s[0:i] optimally."], "metadata": {"canonical_parameter_names": ["s", "dictionary"], "leetcode_dataset_entry_point": "Solution().minExtraChar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:56+00:00", "tests_total": 97, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "string", "dynamic-programming", "trie"]}, "language": "ruby", "interface": {"raw_signature": "def min_extra_char(s, dictionary)", "container": null, "callable": "min_extra_char", "parameters": [{"name": "s", "type": "String"}, {"name": "dictionary", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2708, "task_id": "maximum-strength-of-a-group", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i_0, i_1, i_2, ... , i_k is defined as nums[i_0] * nums[i_1] * nums[i_2] * ... * nums[i_k].\n\nReturn the maximum strength of a group the teacher can create.\n\nExample 1:\n\nInput: nums = [3,-1,-5,2,5,-9]\nOutput: 1350\nExplanation: One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.\n\nExample 2:\n\nInput: nums = [-4,-5,-4]\nOutput: 20\nExplanation: Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.\n\nConstraints:\n\n- 1 <= nums.length <= 13\n- -9 <= nums[i] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 36\n assert candidate(nums = [-9]) == -9\n assert candidate(nums = [0, 0, 0, 1, -1]) == 1\n assert candidate(nums = [-4, -5, -4]) == 20\n assert candidate(nums = [0, 2, 3, 4]) == 24\n assert candidate(nums = [0, 1, -1]) == 1\n assert candidate(nums = [-1]) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 362880\n assert candidate(nums = [-3, 0, 3]) == 3\n assert candidate(nums = [9]) == 9\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, -1, 1, -1]) == 1\n assert candidate(nums = [1, -1]) == 1\n assert candidate(nums = [1, 2, 0, 3, 4]) == 24\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 120\n assert candidate(nums = [5, 5, 5, 5, 5]) == 3125\n assert candidate(nums = [1, 2, 3, 4, 5]) == 120\n assert candidate(nums = [0, 1, -1, 2, -2]) == 4\n assert candidate(nums = [0, 0, 0]) == 0\n assert candidate(nums = [-1, -1, 0, 1, 1]) == 1\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9]) == 362880\n assert candidate(nums = [2, 3, -1, -2, -3]) == 36\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [-1, -2, -3, -4]) == 24\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1]) == 362880\n assert candidate(nums = [3, -1, -5, 2, 5, -9]) == 1350\n assert candidate(nums = [-1, 1, 0]) == 1\n assert candidate(nums = [-1, 0, 1]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0]) == 362880\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, -9, -8, -7, -6]) == 1097349120\n assert candidate(nums = [7, 3, -2, -5, 0, 1, 4, -6]) == 2520\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 531441\n assert candidate(nums = [-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2]) == 4096\n assert candidate(nums = [-9, 9, 0, -1, 1, -2, 2]) == 324\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [3, -1, -5, 2, 5, -9, 7]) == 9450\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1220703125\n assert candidate(nums = [9, -8, 7, -6, 5, -4, 3, -2, 1, -9]) == 1632960\n assert candidate(nums = [-1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1]) == 1\n assert candidate(nums = [1, -2, 3, -4, 5, -6]) == 360\n assert candidate(nums = [0, 1, -1, 2, -2, 3]) == 12\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1]) == 362880\n assert candidate(nums = [0, -1, 2, -2, 3, -3]) == 36\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3]) == 36\n assert candidate(nums = [-1, 0, 1]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [9, 7, 5, 3, 1, -1, -3, -5, -7, -9]) == 893025\n assert candidate(nums = [-1, -3, -5, -7, -9]) == 945\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [-8, -6, -4, -2, 0, 2, 4, 6, 8]) == 147456\n assert candidate(nums = [0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3]) == 2177280\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [7, -8, 9, -2, 3, 0, 4, -5, 6, -1]) == 362880\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2]) == 725760\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [9, -9, 8, -8, 7, -7]) == 36288\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 14400\n assert candidate(nums = [-3, -3, -3, -3, -3, -3, -3, -3, -3]) == 6561\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 362880\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4]) == 576\n assert candidate(nums = [3, -1, 0, -5, 2, 5, -9, 0, 4, -2, 6, -8, 7]) == 3628800\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 1, -1, 2, -2, 3, -3, 4]) == 144\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6]) == 518400\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3]) == 36\n assert candidate(nums = [-5, 0, 5]) == 5\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 120\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7]) == 5040\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7]) == 2520\n assert candidate(nums = [-2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8]) == 101606400\n assert candidate(nums = [-1, 0, 0, 0, 0, 0, -2]) == 2\n assert candidate(nums = [-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [3, -1, -5, 2, 5, -9, 7, -8]) == 75600\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2177280\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 8192\n assert candidate(nums = [3, -3, 3, -3, 3, -3, 3, -3, 3, -3, 3, -3, 3]) == 1594323\n assert candidate(nums = [1, 0, -1, 0, 1, 0, -1, 0]) == 1\n assert candidate(nums = [9, -8, 7, -6, 5, -4, 3, -2, 1, 0, -1, 2, -3]) == 2177280\n assert candidate(nums = [9, 0, -9, 0, 9, -9, 9, -9, 9]) == 531441\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4]) == 8709120\n assert candidate(nums = [3, -1, 0, 5, -2, 4, -6]) == 720\n assert candidate(nums = [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3]) == 531441\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [-2, -3, -4, 0, 0, 0, 0, 0, 0]) == 12\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3]) == 2177280\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [-1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7]) == 3628800\n assert candidate(nums = [-1, -2, -3, -4, -5, 0, 1, 2, 3, 4, 5]) == 14400\n assert candidate(nums = [5, -1, 3, -2, 0, 4, -3]) == 360\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 362880\n assert candidate(nums = [-3, 3, -3, 3, -3, 3, -3, 3, -3, 3, -3, 3, -3]) == 531441\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 14400\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9]) == 362880\n assert candidate(nums = [5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8]) == 609638400\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9]) == 362880\n assert candidate(nums = [9, -8, 7, -6, 5, -4, 3, -2, 1]) == 362880\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 1594323\n assert candidate(nums = [2, -3, 4, -5, 6, -7, 8, -9, 1]) == 362880\n assert candidate(nums = [-2, -3, -4, -5, -6, -7, -8, -9]) == 362880\n assert candidate(nums = [-9, 9, -8, 8, -7, 7, -6, 6, -5, 5, -4, 4, -3]) == 3657830400\n assert candidate(nums = [-2, -3, -5, 0, 0, 0, 0, 0, 0]) == 15\n assert candidate(nums = [9, -8, 7, -6, 5, -4, 3, -2, 1, -1, 0]) == 362880\n assert candidate(nums = [1, 0, -1, 2, 0, -2, 3, 0, -3]) == 36\n assert candidate(nums = [-9, 8, -7, 6, -5, 4, -3, 2, -1]) == 362880\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4]) == 8709120\n", "comparison": "exact"}, "public_tests": ["[3,-1,-5,2,5,-9]", "[-4,-5,-4]"], "hints": ["Try to generate all pairs of subsets and check which group provides maximal strength.", "It can also be solved in O(NlogN) by sorting the array and using all positive integers.", "Use negative integers only in pairs such that their product becomes positive."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxStrength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:00:59+00:00", "tests_total": 123, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "dynamic-programming", "backtracking", "greedy", "bit-manipulation", "sorting", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def max_strength(nums)", "container": null, "callable": "max_strength", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2709, "task_id": "greatest-common-divisor-traversal", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.\n\nYour task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j.\n\nReturn true if it is possible to traverse between all such pairs of indices, or false otherwise.\n\nExample 1:\n\nInput: nums = [2,3,6]\nOutput: true\nExplanation: In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).\nTo go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.\nTo go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.\n\nExample 2:\n\nInput: nums = [3,9,5]\nOutput: false\nExplanation: No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.\n\nExample 3:\n\nInput: nums = [4,3,12,8]\nOutput: true\nExplanation: There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 6]) == True\n assert candidate(nums = [100, 200, 300, 400]) == True\n assert candidate(nums = [1, 1, 1]) == False\n assert candidate(nums = [1, 1, 1, 1]) == False\n assert candidate(nums = [7, 14, 21, 35]) == True\n assert candidate(nums = [30, 15, 10, 5]) == True\n assert candidate(nums = [2, 4, 6, 8, 10]) == True\n assert candidate(nums = [2, 6, 8, 12, 18, 24]) == True\n assert candidate(nums = [3, 9, 5]) == False\n assert candidate(nums = [7, 11, 13, 17]) == False\n assert candidate(nums = [1]) == True\n assert candidate(nums = [2, 5, 7, 11, 13]) == False\n assert candidate(nums = [1, 2, 3, 4, 5]) == False\n assert candidate(nums = [2, 4, 8, 16]) == True\n assert candidate(nums = [13, 17, 19, 23, 29]) == False\n assert candidate(nums = [60, 120, 180, 240]) == True\n assert candidate(nums = [10, 15, 20, 25]) == True\n assert candidate(nums = [4, 3, 12, 8]) == True\n assert candidate(nums = [2, 2, 2, 2]) == True\n assert candidate(nums = [7, 11, 13, 17, 19]) == False\n assert candidate(nums = [60, 30, 20, 10]) == True\n assert candidate(nums = [100000]) == True\n assert candidate(nums = [5, 10, 15, 20, 25]) == True\n assert candidate(nums = [5, 10, 15, 20]) == True\n assert candidate(nums = [11, 22, 33, 44, 55]) == True\n assert candidate(nums = [3, 5, 7, 11, 13, 17]) == False\n assert candidate(nums = [30, 42, 70, 105]) == True\n assert candidate(nums = [7, 14, 28, 35]) == True\n assert candidate(nums = [100000, 100000, 100000, 100000]) == True\n assert candidate(nums = [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29]) == False\n assert candidate(nums = [30, 42, 70, 105, 210]) == True\n assert candidate(nums = [30, 42, 56, 70, 84, 98, 112, 126, 140, 154]) == True\n assert candidate(nums = [220, 330, 440, 550, 660, 770, 880, 990, 1100, 1210]) == True\n assert candidate(nums = [143, 169, 187, 221, 247, 299, 323, 341, 377, 391, 413, 437, 451, 473, 517, 551, 583, 611, 629, 667]) == False\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == True\n assert candidate(nums = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == False\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == True\n assert candidate(nums = [49, 147, 245, 343, 7203]) == True\n assert candidate(nums = [30, 45, 60, 75, 90, 105]) == True\n assert candidate(nums = [30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240]) == True\n assert candidate(nums = [20, 25, 40, 50, 100]) == True\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == True\n assert candidate(nums = [44, 55, 66, 77, 88, 99, 110, 121]) == True\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == True\n assert candidate(nums = [2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480]) == True\n assert candidate(nums = [121, 143, 169, 187, 209, 221, 247, 253]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127]) == False\n assert candidate(nums = [49, 98, 147, 196, 245, 294, 343, 392, 441, 490]) == True\n assert candidate(nums = [105, 210, 315, 420, 525, 630, 735]) == True\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400]) == True\n assert candidate(nums = [10, 15, 21, 35, 70, 105]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197]) == False\n assert candidate(nums = [30, 42, 70, 105]) == True\n assert candidate(nums = [2, 3, 5, 6, 10, 15, 30]) == True\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150]) == True\n assert candidate(nums = [840, 1680, 2520, 3360, 4200]) == True\n assert candidate(nums = [42, 56, 70, 84, 98, 112, 126, 140]) == True\n assert candidate(nums = [31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]) == False\n assert candidate(nums = [100, 200, 300, 400, 500]) == True\n assert candidate(nums = [81, 121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961, 1089]) == False\n assert candidate(nums = [6, 10, 15, 21, 26, 33, 35, 39, 42, 55]) == True\n assert candidate(nums = [2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30, 31, 33]) == False\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126]) == True\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(nums = [21, 35, 70, 105]) == True\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == False\n assert candidate(nums = [14, 21, 28, 35, 42, 49, 56]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == False\n assert candidate(nums = [30, 45, 60, 75, 90, 105, 120, 135, 150, 165]) == True\n assert candidate(nums = [30, 45, 60, 75, 90]) == True\n assert candidate(nums = [99, 100, 101, 102, 103, 104, 105]) == False\n assert candidate(nums = [84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131]) == False\n assert candidate(nums = [6, 10, 15, 21, 25, 35]) == True\n assert candidate(nums = [49, 98, 147, 196, 245, 294]) == True\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024]) == True\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == True\n assert candidate(nums = [4, 6, 8, 12, 18, 24, 36, 48, 72, 144]) == True\n assert candidate(nums = [10001, 10003, 10007, 10009, 10013, 10021, 10031, 10037, 10039, 10061]) == False\n assert candidate(nums = [10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009]) == False\n assert candidate(nums = [72, 108, 144, 180, 216, 252, 288, 324, 360, 396, 432, 468, 504, 540, 576]) == True\n assert candidate(nums = [24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192]) == True\n assert candidate(nums = [33, 55, 77, 99, 121, 143, 165, 187, 209, 231]) == True\n assert candidate(nums = [84, 90, 120, 140, 210]) == True\n assert candidate(nums = [24, 36, 48, 60, 72, 84, 96, 108, 120]) == True\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == True\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114]) == False\n assert candidate(nums = [6, 10, 15, 30, 60, 120]) == True\n assert candidate(nums = [210, 330, 420, 550, 660, 770, 880, 990, 1100, 1210]) == True\n assert candidate(nums = [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]) == False\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]) == True\n assert candidate(nums = [210, 231, 273, 308, 330, 364]) == True\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [49, 441, 729, 1029, 1323, 1681, 2079, 2521, 2997, 3529, 4041, 4561]) == False\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == False\n assert candidate(nums = [15, 25, 35, 45, 55]) == True\n assert candidate(nums = [2310, 2730, 2310, 2730, 2310, 2730, 2310, 2730, 2310, 2730]) == True\n assert candidate(nums = [18, 24, 30, 36, 42, 48, 54, 60]) == True\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]) == False\n assert candidate(nums = [15, 21, 35, 105]) == True\n assert candidate(nums = [42, 77, 105, 140, 175, 210, 245, 280, 315, 350]) == True\n assert candidate(nums = [21, 35, 49, 63, 105]) == True\n assert candidate(nums = [48, 72, 108, 144, 180, 216]) == True\n assert candidate(nums = [18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102]) == True\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == False\n assert candidate(nums = [84, 126, 168, 210, 252, 294, 336, 378, 420, 462]) == True\n assert candidate(nums = [210, 420, 630, 840, 1050, 1260, 1470, 1680, 1890, 2100, 2310, 2520, 2730, 2940, 3150, 3360, 3570, 3780, 3990, 4200]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(nums = [36, 48, 60, 72, 84, 96, 108, 120, 132, 144]) == True\n assert candidate(nums = [210, 154, 385, 770]) == True\n assert candidate(nums = [315, 630, 945, 1260, 1575, 1890, 2205, 2520, 2835, 3150]) == True\n assert candidate(nums = [44, 88, 132, 176, 220]) == True\n assert candidate(nums = [12, 15, 20, 25, 30, 35, 40, 45, 50, 60]) == True\n assert candidate(nums = [1, 1, 1, 1, 1]) == False\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == True\n assert candidate(nums = [9, 27, 81, 243, 729, 2187, 6561, 19683]) == True\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173]) == False\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == False\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == True\n assert candidate(nums = [6, 15, 10, 30, 21, 42, 70, 105, 140, 210]) == True\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == True\n assert candidate(nums = [4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19]) == False\n", "comparison": "exact"}, "public_tests": ["[2,3,6]", "[3,9,5]", "[4,3,12,8]"], "hints": ["Create a (prime) factor-numbers list for all the indices.", "Add an edge between the neighbors of the (prime) factor-numbers list. The order of the numbers doesn’t matter. We only need edges between 2 neighbors instead of edges for all pairs.", "The problem is now similar to checking if all the numbers (nodes of the graph) are in the same connected component.", "Any algorithm (i.e., BFS, DFS, or Union-Find Set) should work to find or check connected components"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().canTraverseAllPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:01+00:00", "tests_total": 134, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "math", "union-find", "number-theory", "prime-factorization", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "ruby", "interface": {"raw_signature": "def can_traverse_all_pairs(nums)", "container": null, "callable": "can_traverse_all_pairs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2710, "task_id": "remove-trailing-zeros-from-a-string", "difficulty": "Easy", "problem_description": "Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.\n\nExample 1:\n\nInput: num = \"51230100\"\nOutput: \"512301\"\nExplanation: Integer \"51230100\" has 2 trailing zeros, we remove them and return integer \"512301\".\n\nExample 2:\n\nInput: num = \"123\"\nOutput: \"123\"\nExplanation: Integer \"123\" has no trailing zeros, we return integer \"123\".\n\nConstraints:\n\n- 1 <= num.length <= 1000\n- num consists of only digits.\n- num doesn't have any leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"100100\") == \"1001\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n assert candidate(num = \"1000\") == \"1\"\n assert candidate(num = \"1\") == \"1\"\n assert candidate(num = \"9876543210\") == \"987654321\"\n assert candidate(num = \"10500\") == \"105\"\n assert candidate(num = \"0\") == \"\"\n assert candidate(num = \"51230100\") == \"512301\"\n assert candidate(num = \"10101000\") == \"10101\"\n assert candidate(num = \"987654321000\") == \"987654321\"\n assert candidate(num = \"000000000000000000000\") == \"\"\n assert candidate(num = \"123\") == \"123\"\n assert candidate(num = \"999999999999999999999\") == \"999999999999999999999\"\n assert candidate(num = \"1000000000000000000001\") == \"1000000000000000000001\"\n assert candidate(num = \"1010101010\") == \"101010101\"\n assert candidate(num = \"999999999900\") == \"9999999999\"\n assert candidate(num = \"10000\") == \"1\"\n assert candidate(num = \"1001001000\") == \"1001001\"\n assert candidate(num = \"1000000000\") == \"1\"\n assert candidate(num = \"100100100\") == \"1001001\"\n assert candidate(num = \"9999999999\") == \"9999999999\"\n assert candidate(num = \"00001\") == \"00001\"\n assert candidate(num = \"100000\") == \"1\"\n", "comparison": "exact"}, "public_tests": ["\"51230100\"", "\"123\""], "hints": ["Find the last non-zero digit in num."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().removeTrailingZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:03+00:00", "tests_total": 24, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def remove_trailing_zeros(num)", "container": null, "callable": "remove_trailing_zeros", "parameters": [{"name": "num", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2711, "task_id": "difference-of-number-of-distinct-values-on-diagonals", "difficulty": "Medium", "problem_description": "Given a 2D grid of size m x n, you should find the matrix answer of size m x n.\n\nThe cell answer[r][c] is calculated by looking at the diagonal values of the cell grid[r][c]:\n\n- Let leftAbove[r][c] be the number of distinct values on the diagonal to the left and above the cell grid[r][c] not including the cell grid[r][c] itself.\n- Let rightBelow[r][c] be the number of distinct values on the diagonal to the right and below the cell grid[r][c], not including the cell grid[r][c] itself.\n- Then answer[r][c] = |leftAbove[r][c] - rightBelow[r][c]|.\n\nA matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until the end of the matrix is reached.\n\n- For example, in the below diagram the diagonal is highlighted using the cell with indices (2, 3) colored gray:\n - Red-colored cells are left and above the cell.\n - Blue-colored cells are right and below the cell.\n\nReturn the matrix answer.\n\nExample 1:\n\nInput: grid = [[1,2,3],[3,1,5],[3,2,1]]\nOutput: Output: [[1,1,0],[1,0,1],[0,1,1]]\nExplanation:\nTo calculate the answer cells:\n\nanswer | left-above elements | leftAbove | right-below elements | rightBelow | |leftAbove - rightBelow|\n[0][0] | [] | 0 | [grid[1][1], grid[2][2]] | |{1, 1}| = 1 | 1\n[0][1] | [] | 0 | [grid[1][2]] | |{5}| = 1 | 1\n[0][2] | [] | 0 | [] | 0 | 0\n[1][0] | [] | 0 | [grid[2][1]] | |{2}| = 1 | 1\n[1][1] | [grid[0][0]] | |{1}| = 1 | [grid[2][2]] | |{1}| = 1 | 0\n[1][2] | [grid[0][1]] | |{2}| = 1 | [] | 0 | 1\n[2][0] | [] | 0 | [] | 0 | 0\n[2][1] | [grid[1][0]] | |{3}| = 1 | [] | 0 | 1\n[2][2] | [grid[0][0], grid[1][1]] | |{1, 1}| = 1 | [] | 0 | 1\n\nExample 2:\n\nInput: grid = [[1]]\nOutput: Output: [[0]]\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n, grid[i][j] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == [[1, 1, 0], [1, 0, 1], [0, 1, 1]]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 1, 2, 2], [1, 1, 2, 2], [3, 3, 4, 4], [3, 3, 4, 4]]) == [[2, 2, 1, 0], [2, 0, 0, 1], [1, 0, 0, 2], [0, 1, 2, 2]]\n assert candidate(grid = [[1, 2], [2, 1], [3, 4]]) == [[1, 0], [1, 1], [0, 1]]\n assert candidate(grid = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [[1, 0], [1, 1], [1, 1], [0, 1]]\n assert candidate(grid = [[1]]) == [[0]]\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == [[1, 1, 0], [1, 0, 1], [0, 1, 1]]\n assert candidate(grid = [[4, 5], [5, 4]]) == [[1, 0], [0, 1]]\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 2], [3, 4]]) == [[1, 0], [0, 1]]\n assert candidate(grid = [[4, 4], [4, 4]]) == [[1, 0], [0, 1]]\n assert candidate(grid = [[1, 2], [2, 3]]) == [[1, 0], [0, 1]]\n assert candidate(grid = [[1, 3, 5, 7], [2, 4, 6, 8], [3, 5, 7, 9]]) == [[2, 2, 1, 0], [1, 0, 0, 1], [0, 1, 2, 2]]\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 2, 3], [3, 1, 5], [3, 2, 1]]) == [[1, 1, 0], [1, 0, 1], [0, 1, 1]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [[2, 1, 0], [1, 0, 1], [0, 1, 2]]\n assert candidate(grid = [[4, 3, 2, 1], [5, 6, 7, 8], [9, 10, 11, 12]]) == [[2, 2, 1, 0], [1, 0, 0, 1], [0, 1, 2, 2]]\n assert candidate(grid = [[1, 1, 2, 2, 3], [1, 2, 2, 3, 3], [2, 2, 3, 3, 4], [2, 3, 3, 4, 4], [3, 3, 4, 4, 5]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) == [[2, 1, 0], [2, 0, 1], [2, 0, 2], [2, 0, 2], [1, 0, 2], [0, 1, 2]]\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == [[1, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 1]]\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == [[4, 4, 3, 4, 3, 4, 3, 2, 1, 0], [3, 2, 2, 1, 2, 2, 2, 1, 0, 1], [2, 1, 0, 0, 0, 0, 1, 0, 1, 2], [1, 0, 1, 2, 2, 2, 2, 1, 2, 3], [0, 1, 2, 3, 4, 4, 3, 4, 2, 4]]\n assert candidate(grid = [[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]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == [[1, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 1]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]) == [[3, 2, 2, 1, 0], [2, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 2], [0, 1, 2, 2, 3]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 1, 1, 1, 1]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[5, 9, 3, 7], [3, 4, 8, 6], [1, 7, 2, 5], [6, 8, 4, 3]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[5, 3, 8, 3, 9], [3, 5, 9, 10, 8], [8, 9, 5, 3, 3], [3, 10, 5, 3, 8], [9, 8, 3, 5, 9]]) == [[3, 3, 2, 1, 0], [2, 2, 1, 0, 1], [2, 0, 1, 1, 2], [1, 0, 1, 0, 2], [0, 1, 2, 3, 2]]\n assert candidate(grid = [[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]]) == [[6, 5, 4, 3, 2, 1, 0], [5, 4, 3, 2, 1, 0, 1], [4, 3, 2, 1, 0, 1, 2], [3, 2, 1, 0, 1, 2, 3], [2, 1, 0, 1, 2, 3, 4], [1, 0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17], [17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18]]) == [[4, 3, 4, 3, 4, 3, 2, 1, 0], [3, 2, 2, 2, 2, 2, 1, 0, 1], [2, 1, 0, 0, 0, 0, 0, 1, 2], [1, 0, 1, 2, 1, 2, 2, 2, 3], [0, 1, 2, 3, 4, 3, 4, 3, 4]]\n assert candidate(grid = [[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]]) == [[5, 4, 3, 2, 1, 0], [4, 3, 2, 1, 0, 1], [3, 2, 1, 0, 1, 2], [2, 1, 0, 1, 2, 3], [1, 0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21], [21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]]) == [[3, 4, 4, 4, 4, 3, 4, 3, 2, 1, 0], [3, 2, 2, 2, 2, 2, 2, 2, 1, 0, 1], [2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2], [1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 3], [0, 1, 2, 3, 4, 4, 4, 4, 4, 3, 4]]\n assert candidate(grid = [[5, 1, 3], [4, 1, 5], [1, 5, 1], [3, 5, 4]]) == [[1, 1, 0], [2, 0, 1], [1, 0, 2], [0, 1, 2]]\n assert candidate(grid = [[5, 3, 8, 1], [3, 5, 1, 8], [8, 1, 3, 5], [1, 8, 5, 3]]) == [[2, 2, 1, 0], [2, 0, 0, 1], [1, 0, 0, 2], [0, 1, 2, 2]]\n assert candidate(grid = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 3, 2], [1, 2, 2, 1]]) == [[3, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 4, 3, 2], [1, 2, 3, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == [[5, 4, 3, 2, 2, 2, 1, 0], [4, 4, 3, 1, 1, 1, 0, 1], [4, 2, 3, 1, 0, 1, 1, 2], [3, 2, 1, 1, 0, 1, 2, 2], [3, 1, 1, 0, 1, 2, 2, 3], [2, 1, 0, 1, 2, 3, 3, 3], [1, 0, 1, 2, 3, 3, 4, 4], [0, 1, 2, 3, 3, 4, 4, 5]]\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 1, 2, 2], [1, 2, 2, 1], [2, 1, 1, 2], [2, 2, 1, 1]]) == [[2, 1, 1, 0], [1, 0, 0, 1], [1, 0, 1, 2], [0, 1, 1, 2]]\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]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11], [4, 6, 8, 10, 12], [5, 7, 9, 11, 13]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[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]]) == [[5, 4, 3, 2, 1, 0], [4, 3, 2, 1, 0, 1], [3, 2, 1, 0, 1, 2], [2, 1, 0, 1, 2, 3], [1, 0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5]]\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, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 1]]\n assert candidate(grid = [[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]]) == [[4, 4, 4, 4, 4, 4, 3, 2, 1, 0], [3, 2, 2, 2, 2, 2, 2, 1, 0, 1], [2, 1, 0, 0, 0, 0, 0, 0, 1, 2], [1, 0, 1, 2, 2, 2, 2, 2, 2, 3], [0, 1, 2, 3, 4, 4, 4, 4, 4, 4]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 2, 1], [1, 2, 3, 4, 3, 2, 1], [1, 2, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]]) == [[4, 3, 3, 2, 2, 1, 0], [3, 3, 2, 2, 1, 0, 1], [3, 2, 2, 1, 0, 1, 2], [2, 2, 1, 0, 1, 2, 2], [2, 1, 0, 1, 2, 2, 3], [1, 0, 1, 2, 2, 3, 3], [0, 1, 2, 2, 3, 3, 4]]\n assert candidate(grid = [[1, 1, 2, 2, 3, 3], [3, 3, 1, 1, 2, 2], [2, 2, 3, 3, 1, 1], [1, 1, 2, 2, 3, 3], [3, 3, 1, 1, 2, 2]]) == [[2, 3, 2, 2, 1, 0], [2, 1, 1, 1, 0, 1], [1, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 2], [0, 1, 2, 2, 3, 2]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]) == [[4, 3, 3, 4, 4, 4, 3, 2, 1, 0], [3, 2, 2, 1, 2, 2, 2, 1, 0, 1], [2, 1, 0, 0, 0, 0, 1, 0, 1, 2], [1, 0, 1, 2, 2, 2, 2, 1, 2, 3], [0, 1, 2, 3, 4, 4, 3, 4, 3, 4]]\n assert candidate(grid = [[5, 4, 3, 2, 1], [4, 3, 2, 1, 5], [3, 2, 1, 5, 4], [2, 1, 5, 4, 3], [1, 5, 4, 3, 2]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 1, 2, 2, 3, 3, 4, 4, 5, 5], [5, 5, 4, 4, 3, 3, 2, 2, 1, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == [[3, 2, 2, 3, 2, 2, 3, 2, 1, 0], [2, 1, 1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1, 1, 2], [0, 1, 2, 3, 2, 3, 3, 2, 3, 3]]\n assert candidate(grid = [[1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2], [2, 2, 2, 1, 1, 1], [2, 2, 2, 1, 1, 1], [2, 2, 2, 1, 1, 1]]) == [[1, 2, 2, 1, 1, 0], [2, 0, 1, 1, 0, 1], [2, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 2], [1, 0, 1, 1, 0, 2], [0, 1, 1, 2, 2, 1]]\n assert candidate(grid = [[7, 8, 9, 10], [11, 12, 13, 14], [15, 16, 17, 18], [19, 20, 21, 22]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[3, 2, 1], [6, 5, 4], [9, 8, 7], [12, 11, 10]]) == [[2, 1, 0], [2, 0, 1], [1, 0, 2], [0, 1, 2]]\n assert candidate(grid = [[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]]) == [[1, 1, 1, 1, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 1]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 2, 4], [4, 2, 1, 3, 5], [5, 1, 4, 2, 3]]) == [[3, 3, 2, 1, 0], [3, 1, 1, 0, 1], [2, 1, 1, 1, 2], [1, 0, 1, 2, 2], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[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]]) == [[3, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 3]]\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [20, 18, 16, 14, 12, 10, 8, 6, 4, 2], [3, 6, 9, 12, 15, 18, 21, 24, 27, 30], [30, 27, 24, 21, 18, 15, 12, 9, 6, 3], [4, 8, 12, 16, 20, 24, 28, 32, 36, 40], [40, 36, 32, 28, 24, 20, 16, 12, 8, 4]]) == [[7, 7, 6, 6, 4, 4, 3, 2, 1, 0], [6, 6, 6, 4, 4, 3, 2, 1, 0, 1], [6, 4, 4, 4, 3, 2, 2, 0, 1, 2], [5, 4, 2, 2, 2, 1, 0, 0, 2, 3], [4, 3, 2, 1, 1, 0, 0, 2, 1, 4], [3, 2, 2, 0, 0, 1, 2, 2, 4, 3], [3, 1, 0, 0, 1, 2, 2, 3, 4, 5], [2, 1, 0, 2, 2, 3, 4, 4, 5, 6], [1, 0, 1, 2, 3, 4, 4, 5, 5, 7], [0, 1, 2, 3, 4, 5, 6, 6, 7, 7]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 1], [3, 4, 5, 6, 1, 2], [4, 5, 6, 1, 2, 3], [5, 6, 1, 2, 3, 4], [6, 1, 2, 3, 4, 5]]) == [[3, 3, 3, 2, 1, 0], [3, 2, 2, 1, 0, 1], [3, 2, 1, 0, 1, 2], [2, 1, 0, 1, 2, 3], [1, 0, 1, 2, 2, 3], [0, 1, 2, 3, 3, 3]]\n assert candidate(grid = [[10, 11, 12, 13, 14, 15], [9, 10, 11, 12, 13, 14], [8, 9, 10, 11, 12, 13], [7, 8, 9, 10, 11, 12], [6, 7, 8, 9, 10, 11], [5, 6, 7, 8, 9, 10]]) == [[1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1]]\n assert candidate(grid = [[9, 2, 8, 6], [3, 5, 7, 1], [4, 6, 3, 5], [8, 7, 4, 6]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 3, 1], [1, 1, 1, 1]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[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]]) == [[1, 1, 1, 1, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 1]]\n assert candidate(grid = [[7, 8, 9], [8, 9, 10], [9, 10, 11], [10, 11, 12]]) == [[2, 1, 0], [2, 0, 1], [1, 0, 2], [0, 1, 2]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2], [3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3]]) == [[4, 4, 3, 2, 1, 0], [4, 2, 2, 1, 0, 1], [2, 2, 1, 0, 0, 2], [2, 0, 0, 1, 2, 2], [1, 0, 1, 2, 2, 4], [0, 1, 2, 3, 3, 4]]\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 9, 8, 7, 6, 5, 4, 3, 2], [2, 1, 9, 8, 7, 6, 5, 4, 3], [3, 2, 1, 9, 8, 7, 6, 5, 4], [4, 3, 2, 1, 9, 8, 7, 6, 5], [5, 4, 3, 2, 1, 9, 8, 7, 6], [6, 5, 4, 3, 2, 1, 9, 8, 7], [7, 6, 5, 4, 3, 2, 1, 9, 8], [8, 7, 6, 5, 4, 3, 2, 1, 9]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1]]\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]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[7, 1, 4, 9], [5, 2, 6, 3], [10, 8, 11, 12], [1, 4, 7, 8]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8]]) == [[3, 3, 2, 1, 0], [2, 1, 1, 0, 1], [1, 0, 1, 1, 2], [0, 1, 2, 3, 3]]\n assert candidate(grid = [[7, 7, 7, 7, 7, 7], [7, 8, 8, 8, 8, 7], [7, 8, 9, 9, 8, 7], [7, 8, 9, 10, 9, 8], [7, 8, 9, 9, 8, 7], [7, 8, 8, 8, 8, 7]]) == [[4, 3, 1, 2, 1, 0], [2, 3, 1, 0, 0, 1], [2, 1, 1, 0, 1, 2], [1, 1, 0, 1, 2, 2], [1, 0, 1, 2, 3, 3], [0, 1, 2, 3, 3, 4]]\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, 3, 3]]) == [[1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1]]\n assert candidate(grid = [[10, 20, 30, 40, 50], [20, 30, 40, 50, 10], [30, 40, 50, 10, 20], [40, 50, 10, 20, 30], [50, 10, 20, 30, 40]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[10, 20, 30, 40], [40, 30, 20, 10], [10, 30, 20, 40], [40, 20, 30, 10]]) == [[3, 2, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [2, 4, 6, 8, 10]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 2, 4]]\n assert candidate(grid = [[7, 7, 7, 7], [7, 8, 8, 8], [7, 8, 9, 9], [7, 8, 9, 10]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]]) == [[4, 3, 2, 1, 0], [3, 2, 1, 0, 1], [2, 1, 0, 1, 2], [1, 0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(grid = [[1, 5, 3, 7], [8, 2, 6, 4], [3, 7, 1, 5], [4, 6, 8, 2], [5, 1, 4, 7]]) == [[2, 2, 1, 0], [2, 1, 0, 1], [2, 1, 1, 2], [1, 0, 1, 2], [0, 1, 2, 2]]\n assert candidate(grid = [[5, 4, 3, 2, 1], [6, 5, 4, 3, 2], [7, 6, 5, 4, 3], [8, 7, 6, 5, 4], [9, 8, 7, 6, 5]]) == [[1, 1, 1, 1, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 1]]\n assert candidate(grid = [[1, 10, 3, 8], [9, 2, 5, 6], [4, 7, 1, 3], [2, 8, 6, 4]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 2]]\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [[1, 0], [1, 1], [1, 1], [1, 1], [0, 1]]\n assert candidate(grid = [[7, 7, 7, 7, 7, 7], [7, 6, 6, 6, 6, 7], [7, 6, 5, 5, 6, 7], [7, 6, 5, 4, 5, 7], [7, 6, 5, 5, 6, 7], [7, 7, 7, 7, 7, 7]]) == [[4, 3, 2, 2, 1, 0], [3, 3, 1, 1, 0, 1], [3, 1, 1, 0, 1, 2], [2, 1, 0, 1, 2, 2], [1, 0, 1, 2, 3, 3], [0, 1, 2, 3, 3, 4]]\n assert candidate(grid = [[1, 2, 3], [6, 5, 4], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == [[2, 1, 0], [2, 0, 1], [2, 0, 2], [1, 0, 2], [0, 1, 2]]\n assert candidate(grid = [[7, 6, 5, 4], [8, 7, 6, 5], [9, 8, 7, 6], [10, 9, 8, 7]]) == [[1, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 1]]\n assert candidate(grid = [[1, 1, 2, 2], [2, 2, 1, 1], [1, 1, 2, 2], [2, 2, 1, 1]]) == [[2, 2, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 2, 2]]\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 30, 50, 20, 40], [40, 20, 10, 50, 30]]) == [[2, 2, 2, 1, 0], [2, 0, 1, 0, 1], [1, 0, 1, 1, 2], [0, 1, 2, 3, 2]]\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[3,1,5],[3,2,1]]", "[[1]]"], "hints": ["Use the set to count the number of distinct elements on diagonals."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().differenceOfDistinctValues", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:06+00:00", "tests_total": 91, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def difference_of_distinct_values(grid)", "container": null, "callable": "difference_of_distinct_values", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2712, "task_id": "minimum-cost-to-make-all-characters-equal", "difficulty": "Medium", "problem_description": "You are given a 0-indexed binary string s of length n on which you can apply two types of operations:\n\n- Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1\n- Choose an index i and invert all characters from index i to index n - 1 (both inclusive), with a cost of n - i\n\nReturn the minimum cost to make all characters of the string equal.\n\nInvert a character means if its value is '0' it becomes '1' and vice-versa.\n\nExample 1:\n\nInput: s = \"0011\"\nOutput: 2\nExplanation: Apply the second operation with i = 2 to obtain s = \"0000\" for a cost of 2. It can be shown that 2 is the minimum cost to make all characters equal.\n\nExample 2:\n\nInput: s = \"010101\"\nOutput: 9\nExplanation: Apply the first operation with i = 2 to obtain s = \"101101\" for a cost of 3.\nApply the first operation with i = 1 to obtain s = \"011101\" for a cost of 2.\nApply the first operation with i = 0 to obtain s = \"111101\" for a cost of 1.\nApply the second operation with i = 4 to obtain s = \"111110\" for a cost of 2.\nApply the second operation with i = 5 to obtain s = \"111111\" for a cost of 1.\nThe total cost to make all characters equal is 9. It can be shown that 9 is the minimum cost to make all characters equal.\n\nConstraints:\n\n- 1 <= s.length == n <= 10^5\n- s[i] is either '0' or '1'\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"100100100\") == 13\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"110011\") == 4\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"1000100010001\") == 20\n assert candidate(s = \"111000\") == 3\n assert candidate(s = \"101010101010\") == 36\n assert candidate(s = \"0100100100\") == 17\n assert candidate(s = \"1111111111\") == 0\n assert candidate(s = \"000111\") == 3\n assert candidate(s = \"11111\") == 0\n assert candidate(s = \"0101010101010101010101010101\") == 196\n assert candidate(s = \"01010101010\") == 30\n assert candidate(s = \"1010101010\") == 25\n assert candidate(s = \"010101\") == 9\n assert candidate(s = \"010101010101010101\") == 81\n assert candidate(s = \"0000000000\") == 0\n assert candidate(s = \"1100110011\") == 12\n assert candidate(s = \"101010\") == 9\n assert candidate(s = \"0011\") == 2\n assert candidate(s = \"0101010101\") == 25\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"101010101010101010\") == 81\n assert candidate(s = \"0000111100001111000011110000111100001111000011110000111100001111\") == 256\n assert candidate(s = \"101010101010101\") == 56\n assert candidate(s = \"000000111111000000\") == 12\n assert candidate(s = \"00000000001\") == 1\n assert candidate(s = \"10101010101\") == 30\n assert candidate(s = \"010101010101010101010101010101010101\") == 324\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111111111101\") == 3\n assert candidate(s = \"0110011001100110011001100110\") == 98\n assert candidate(s = \"1111100001111100001111100001111100001111100001111100001111100001\") == 228\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111111111010\") == 6\n assert candidate(s = \"010101010101010101010101\") == 144\n assert candidate(s = \"0100100100100100100100100100\") == 131\n assert candidate(s = \"0110110110\") == 16\n assert candidate(s = \"10101010101010101010101010\") == 169\n assert candidate(s = \"00000111111\") == 5\n assert candidate(s = \"111000111000111\") == 18\n assert candidate(s = \"0000000000000000000000000000000011111111111111111111\") == 20\n assert candidate(s = \"101010101010101010101010\") == 144\n assert candidate(s = \"00000000001000000000\") == 19\n assert candidate(s = \"00000000000000\") == 0\n assert candidate(s = \"11001100110011001100110011001100\") == 128\n assert candidate(s = \"101010101010101010101010101010\") == 225\n assert candidate(s = \"000000111111000000111111000000111111\") == 54\n assert candidate(s = \"111100001111000011110000111100001111\") == 80\n assert candidate(s = \"111100001111000011110000\") == 36\n assert candidate(s = \"111111111111111111110\") == 1\n assert candidate(s = \"000000000000000000001\") == 1\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000010\") == 3\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"100100100100100100100100\") == 96\n assert candidate(s = \"0011001100110011001100110011001100110011\") == 200\n assert candidate(s = \"0000111100001111000011110000\") == 48\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"00110011001100110011001100110011\") == 128\n assert candidate(s = \"111111111111\") == 0\n assert candidate(s = \"1001001001001001001001001001001\") == 160\n assert candidate(s = \"11110000111100001111\") == 24\n assert candidate(s = \"01010101010101010101010101\") == 169\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"1011011011011011011011011011\") == 131\n assert candidate(s = \"010101010101010101010101010101010101010101010101\") == 576\n assert candidate(s = \"111111111100000000001111111111\") == 20\n assert candidate(s = \"111111000000111111\") == 12\n assert candidate(s = \"010010010010010010010010010010\") == 150\n assert candidate(s = \"1111000011110000111100001111000011110000111100001111000011110000\") == 256\n assert candidate(s = \"0000011111\") == 5\n assert candidate(s = \"11111111111111111111\") == 0\n assert candidate(s = \"000011110000\") == 8\n assert candidate(s = \"101010010101010\") == 50\n assert candidate(s = \"1001001001\") == 16\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"111111111111111111\") == 0\n assert candidate(s = \"11110000001111000000\") == 20\n assert candidate(s = \"000001111000001111000001111000001111000001111000001111000001111\") == 220\n assert candidate(s = \"1010101010101010101010101010101010\") == 289\n assert candidate(s = \"10010010010010\") == 33\n assert candidate(s = \"111111000000111111000000111111\") == 36\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010\") == 1024\n assert candidate(s = \"000000000000\") == 0\n assert candidate(s = \"010101010101010101010101010101\") == 225\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010101010100\") == 1055\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"1001001001001001\") == 42\n assert candidate(s = \"1111111111111111000000000000\") == 12\n assert candidate(s = \"0110011001100110011001100\") == 78\n assert candidate(s = \"11001100110011001100\") == 50\n assert candidate(s = \"110011110011001111001100111100110011\") == 130\n assert candidate(s = \"01010101010101010101010101010101\") == 256\n assert candidate(s = \"0101010101010101010101010101010101010101\") == 400\n assert candidate(s = \"1010101010101010101010101010\") == 196\n assert candidate(s = \"1000000000000000000000000000000000000000\") == 1\n assert candidate(s = \"111000111000\") == 12\n assert candidate(s = \"1111111100000000\") == 8\n assert candidate(s = \"111100001111\") == 8\n assert candidate(s = \"1100110011001100110011001100\") == 98\n assert candidate(s = \"10101001010101010101010101010101\") == 250\n assert candidate(s = \"11110000111100001111000011110000\") == 64\n assert candidate(s = \"010101010101\") == 36\n assert candidate(s = \"111111111100000000111111111100000000\") == 36\n assert candidate(s = \"11011011011011011011\") == 66\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101011\") == 1088\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000101\") == 6\n assert candidate(s = \"0101010101010101\") == 64\n assert candidate(s = \"1111111111111111111111111111\") == 0\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101\") == 1024\n assert candidate(s = \"111111110000000011111111\") == 16\n assert candidate(s = \"010101010101010101010101010101010101010101010101010101\") == 729\n assert candidate(s = \"01001010010100101001010010100101001010010100101001010010100101000\") == 843\n assert candidate(s = \"111100001111000011\") == 20\n assert candidate(s = \"011001100110\") == 18\n assert candidate(s = \"000011110000111100001111\") == 36\n assert candidate(s = \"000000000011111111110000000000\") == 20\n assert candidate(s = \"10011001100110011001100110011001\") == 128\n assert candidate(s = \"11111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"00001111000011110000111100001111\") == 64\n assert candidate(s = \"0100110011001100110011\") == 61\n assert candidate(s = \"1100101100\") == 17\n assert candidate(s = \"00110011001100110011\") == 50\n assert candidate(s = \"11111111110\") == 1\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"1111100000\") == 5\n assert candidate(s = \"0000000011111111\") == 8\n assert candidate(s = \"1001001001001001001001001\") == 104\n assert candidate(s = \"0000000000000000111111111111\") == 12\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"000000000000000000\") == 0\n assert candidate(s = \"01010101010101\") == 49\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"01010110101010101010101010101010\") == 250\n assert candidate(s = \"001100110011001\") == 28\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 400\n assert candidate(s = \"0100101001010010100101001010010100101001010010100101001010010100\") == 819\n assert candidate(s = \"000001111111\") == 5\n assert candidate(s = \"100100100100\") == 24\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101010101010\") == 1056\n assert candidate(s = \"11111000001111\") == 9\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\") == 676\n assert candidate(s = \"110011001100110011001100110011\") == 112\n assert candidate(s = \"01010101010101010101\") == 100\n assert candidate(s = \"01111111111111111110\") == 2\n assert candidate(s = \"11001100110011\") == 24\n assert candidate(s = \"111110000000\") == 5\n assert candidate(s = \"0110011001100110011001100110011\") == 120\n assert candidate(s = \"10000000000000000001\") == 2\n assert candidate(s = \"11111000000\") == 5\n assert candidate(s = \"0000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"11111111111111\") == 0\n assert candidate(s = \"010101010101010\") == 56\n assert candidate(s = \"11111111111111110000000000000000\") == 16\n assert candidate(s = \"10101010101010101010\") == 100\n assert candidate(s = \"1101010101\") == 24\n assert candidate(s = \"000000111111000000111111000000\") == 36\n assert candidate(s = \"00100100100100100100\") == 66\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111110\") == 1\n assert candidate(s = \"0110110110110110110110110110110\") == 160\n assert candidate(s = \"0000000000000000000000000000\") == 0\n assert candidate(s = \"001100110011001100110011001100\") == 112\n assert candidate(s = \"000111000111000\") == 18\n assert candidate(s = \"0000111100001111\") == 16\n", "comparison": "exact"}, "public_tests": ["\"0011\"", "\"010101\""], "hints": ["For every index i, calculate the number of operations required to make the prefix [0, i - 1] equal to the character at index i, denoted prefix[i].", "For every index i, calculate the number of operations required to make the suffix [i + 1, n - 1] equal to the character at index i, denoted suffix[i].", "The final string will contain at least one character that is left unchanged; Therefore, the answer is the minimum of prefix[i] + suffix[i] for every i in [0, n - 1]."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:08+00:00", "tests_total": 162, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(s)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2713, "task_id": "maximum-strictly-increasing-cells-in-a-matrix", "difficulty": "Hard", "problem_description": "Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell.\n\nFrom the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.\n\nYour task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.\n\nReturn an integer denoting the maximum number of cells that can be visited.\n\nExample 1:\n\nInput: mat = [[3,1],[3,4]]\nOutput: 2\nExplanation: The image shows how we can visit 2 cells starting from row 1, column 2. It can be shown that we cannot visit more than 2 cells no matter where we start from, so the answer is 2.\n\nExample 2:\n\nInput: mat = [[1,1],[1,1]]\nOutput: 1\nExplanation: Since the cells must be strictly increasing, we can only visit one cell in this example.\n\nExample 3:\n\nInput: mat = [[3,1,6],[-9,5,7]]\nOutput: 4\nExplanation: The image above shows how we can visit 4 cells starting from row 2, column 1. It can be shown that we cannot visit more than 4 cells no matter where we start from, so the answer is 4.\n\nConstraints:\n\n- m == mat.length\n- n == mat[i].length\n- 1 <= m, n <= 10^5\n- 1 <= m * n <= 10^5\n- -10^5 <= mat[i][j] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[10, 20, 30], [15, 25, 35], [20, 30, 40]]) == 5\n assert candidate(mat = [[1]]) == 1\n assert candidate(mat = [[-100000, 100000], [-100000, 100000]]) == 2\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 1\n assert candidate(mat = [[10, 9, 8, 7, 6], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10]]) == 10\n assert candidate(mat = [[3, 1], [3, 4]]) == 2\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) == 6\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == 6\n assert candidate(mat = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 5\n assert candidate(mat = [[10, 9, 8, 7], [6, 5, 4, 3], [2, 1, 0, -1]]) == 6\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 5\n assert candidate(mat = [[-1, -2, -3], [-2, -3, -4], [-3, -4, -5]]) == 5\n assert candidate(mat = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) == 5\n assert candidate(mat = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]) == 6\n assert candidate(mat = [[1, 1], [1, 1]]) == 1\n assert candidate(mat = [[1, 3, 5], [2, 4, 6], [3, 5, 7]]) == 5\n assert candidate(mat = [[10, 9, 8], [7, 6, 5], [4, 3, 2], [1, 1, 1]]) == 6\n assert candidate(mat = [[3, 1, 6], [-9, 5, 7]]) == 4\n assert candidate(mat = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]]) == 6\n assert candidate(mat = [[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], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29], [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]]) == 21\n assert candidate(mat = [[-1, -2, -3, -4, -5], [-6, -7, -8, -9, -10], [-11, -12, -13, -14, -15], [-16, -17, -18, -19, -20]]) == 8\n assert candidate(mat = [[1, 10, 3, 4, 5], [10, 1, 8, 7, 6], [3, 8, 1, 14, 15], [18, 7, 14, 1, 16]]) == 10\n assert candidate(mat = [[10, 20, 30], [30, 20, 10], [10, 20, 30], [30, 20, 10], [10, 20, 30]]) == 3\n assert candidate(mat = [[-5, -4, -3, -2, -1], [-4, -3, -2, -1, 0], [-3, -2, -1, 0, 1], [-2, -1, 0, 1, 2], [-1, 0, 1, 2, 3]]) == 9\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1], [9, 10, 11, 12, 13, 14, 15, 16], [16, 15, 14, 13, 12, 11, 10, 9]]) == 16\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]]) == 12\n assert candidate(mat = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [19, 18, 17, 16, 15, 14, 13, 12, 11, 10], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]]) == 14\n assert candidate(mat = [[-5, -4, -3, -2, -1], [0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) == 7\n assert candidate(mat = [[-1, -2, -3, -4], [-4, -3, -2, -1], [-5, -6, -7, -8], [-8, -7, -6, -5]]) == 8\n assert candidate(mat = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 1\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 1\n assert candidate(mat = [[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]]) == 13\n assert candidate(mat = [[100, 200, 300], [150, 250, 350], [200, 300, 400]]) == 5\n assert candidate(mat = [[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]]) == 9\n assert candidate(mat = [[100, 200, 300], [150, 250, 350], [200, 300, 400]]) == 5\n assert candidate(mat = [[1, 10, 1, 10, 1, 10], [10, 1, 10, 1, 10, 1], [1, 10, 1, 10, 1, 10], [10, 1, 10, 1, 10, 1], [1, 10, 1, 10, 1, 10]]) == 2\n assert candidate(mat = [[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\n assert candidate(mat = [[-10, -9, -8, -7], [-6, -5, -4, -3], [-2, -1, 0, 1], [2, 3, 4, 5]]) == 7\n assert candidate(mat = [[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]]) == 12\n assert candidate(mat = [[1, 1, 1, 1], [1, 2, 3, 1], [1, 3, 1, 1], [1, 1, 1, 1]]) == 3\n assert candidate(mat = [[-1, 0, 1, 2], [3, 4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14]]) == 7\n assert candidate(mat = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]]) == 9\n assert candidate(mat = [[5, 3, 1, 4], [6, 2, 8, 7], [9, 11, 13, 12], [10, 15, 14, 16]]) == 12\n assert candidate(mat = [[1, 10, 3, 11, 5], [12, 6, 7, 8, 9], [13, 14, 15, 16, 17], [18, 19, 20, 21, 22]]) == 12\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 7\n assert candidate(mat = [[10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10]]) == 1\n assert candidate(mat = [[5, 3, 8, 2, 9], [1, 6, 4, 7, 3], [9, 1, 8, 2, 5], [2, 7, 3, 8, 4], [8, 2, 9, 4, 1]]) == 7\n assert candidate(mat = [[1, 2, 3, 4, 5], [4, 3, 2, 1, 0], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 1, 1, 1, 1]]) == 8\n assert candidate(mat = [[1, 2, 3, 4, 5], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [10, 8, 6, 4, 2], [9, 7, 5, 3, 1]]) == 7\n assert candidate(mat = [[-10, -20, -30], [-20, -30, -40], [-30, -40, -50]]) == 5\n assert candidate(mat = [[1, 3, 2, 4, 5], [6, 5, 4, 3, 2], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16]]) == 11\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11], [11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12]]) == 9\n assert candidate(mat = [[5, 5, 5, 5, 5], [5, 1, 5, 1, 5], [5, 1, 10, 1, 5], [5, 1, 5, 1, 5], [5, 5, 5, 5, 5]]) == 3\n assert candidate(mat = [[1, 3, 2, 4, 5], [6, 8, 7, 9, 10], [11, 13, 12, 15, 14], [19, 18, 17, 20, 21], [22, 23, 24, 25, 26]]) == 12\n assert candidate(mat = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]]) == 7\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]) == 5\n assert candidate(mat = [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]) == 3\n assert candidate(mat = [[5, 5, 5, 5, 5], [5, 1, 2, 3, 5], [5, 4, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]]) == 4\n assert candidate(mat = [[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]]) == 5\n assert candidate(mat = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == 10\n assert candidate(mat = [[3, 1, 4, 1, 5], [9, 2, 6, 5, 3], [5, 8, 9, 7, 9], [3, 2, 3, 8, 4]]) == 7\n assert candidate(mat = [[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\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 100]]) == 2\n assert candidate(mat = [[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]]) == 17\n assert candidate(mat = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 3, 1], [1, 1, 1, 1]]) == 3\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11], [12, 10, 8, 6, 4, 2]]) == 8\n assert candidate(mat = [[3, 3, 3, 3, 3], [3, 2, 2, 2, 3], [3, 2, 1, 2, 3], [3, 2, 2, 2, 3], [3, 3, 3, 3, 3]]) == 3\n assert candidate(mat = [[-1, -2, -3, -4], [-5, -6, -7, -8], [-9, -10, -11, -12], [-13, -14, -15, -16]]) == 7\n assert candidate(mat = [[3, 1, 4, 1, 5, 9], [2, 6, 5, 3, 5, 9], [5, 8, 9, 7, 9, 3], [2, 8, 0, 3, 1, 4]]) == 9\n assert candidate(mat = [[10, 15, 20], [25, 30, 35], [40, 45, 50], [55, 60, 65], [70, 75, 80]]) == 7\n assert candidate(mat = [[1, 100, 2, 99, 3, 98, 4, 97, 5, 96], [6, 95, 7, 94, 8, 93, 9, 92, 10, 91]]) == 12\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]) == 12\n assert candidate(mat = [[1, 100, 1], [100, 1, 100], [1, 100, 1]]) == 2\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11], [4, 6, 8, 10, 12], [5, 7, 9, 11, 13]]) == 9\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]]) == 10\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 14\n assert candidate(mat = [[5, 2, 3, 4, 1], [1, 2, 6, 7, 8], [3, 4, 5, 6, 9], [9, 8, 7, 6, 5]]) == 8\n assert candidate(mat = [[-10, -20, -30], [-30, -20, -10], [-10, -30, -20]]) == 3\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8, 10], [10, 8, 6, 4, 2, 9, 7, 5, 3, 1]]) == 10\n assert candidate(mat = [[-10, -20, -30, -40], [-40, -30, -20, -10], [-50, -60, -70, -80], [-80, -70, -60, -50]]) == 8\n assert candidate(mat = [[1, 5, 3, 6, 2], [9, 8, 7, 10, 11], [4, 13, 12, 15, 14], [19, 18, 17, 20, 21]]) == 12\n assert candidate(mat = [[-1, -2, -3, -4], [-5, -6, -7, -8], [-9, -10, -11, -12], [-13, -14, -15, -16]]) == 7\n assert candidate(mat = [[1, 1, 1, 1, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 5\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1]]) == 6\n assert candidate(mat = [[5, 3, 1, 2], [4, 6, 2, 3], [7, 5, 3, 4], [8, 6, 4, 5]]) == 7\n assert candidate(mat = [[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]]) == 5\n assert candidate(mat = [[10, 20, 30, 40], [15, 25, 35, 45], [20, 30, 40, 50], [25, 35, 45, 55]]) == 7\n assert candidate(mat = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 1\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [2, 4, 6, 8, 10]]) == 7\n assert candidate(mat = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15], [20, 19, 18, 17, 16]]) == 20\n assert candidate(mat = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) == 6\n assert candidate(mat = [[-10, -20, -30, -40], [-35, -25, -15, -5], [-50, -45, -40, -35], [-60, -55, -50, -45]]) == 8\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11], [30, 29, 28, 27, 26, 25, 24, 23, 22, 21]]) == 21\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]]) == 8\n assert candidate(mat = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15], [20, 19, 18, 17, 16], [21, 22, 23, 24, 25]]) == 25\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]) == 5\n assert candidate(mat = [[1, 1000, 2, 999], [3, 998, 4, 997], [5, 996, 6, 995], [7, 994, 8, 993]]) == 10\n assert candidate(mat = [[5, 3, 9, 1], [1, 7, 6, 8], [2, 9, 5, 1], [8, 5, 4, 6]]) == 6\n assert candidate(mat = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15], [20, 19, 18, 17, 16], [21, 22, 23, 24, 25], [26, 27, 28, 29, 30]]) == 26\n assert candidate(mat = [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]]) == 11\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 14\n assert candidate(mat = [[1, 2, 3, 4], [4, 3, 2, 1], [1, 2, 3, 4], [4, 3, 2, 1]]) == 4\n assert candidate(mat = [[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\n assert candidate(mat = [[-1, -2, -3], [-3, -2, -1], [1, 0, -1], [-2, -3, -4]]) == 5\n assert candidate(mat = [[100, -100, 200, -200, 300], [-300, 300, -400, 400, -500], [500, -500, 600, -600, 700]]) == 7\n assert candidate(mat = [[100, -100, 200, -200, 300], [-100, 200, -200, 300, -300], [200, -200, 300, -300, 400], [0, 0, 0, 0, 0]]) == 8\n", "comparison": "exact"}, "public_tests": ["[[3,1],[3,4]]", "[[1,1],[1,1]]", "[[3,1,6],[-9,5,7]]"], "hints": ["We can try to build the answer in a bottom-up fashion, starting from the smallest values and increasing to the larger values.", "Going through the values in sorted order, we can store the maximum path we have seen so far for a row/column.", "When we are at a cell, we check its row and column to find out the best previous smaller value that we’ve got so far, and we use it to increment the current value of the row and column."], "metadata": {"canonical_parameter_names": ["mat"], "leetcode_dataset_entry_point": "Solution().maxIncreasingCells", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:11+00:00", "tests_total": 106, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "binary-search", "dynamic-programming", "memoization", "sorting", "matrix", "ordered-set"]}, "language": "ruby", "interface": {"raw_signature": "def max_increasing_cells(mat)", "container": null, "callable": "max_increasing_cells", "parameters": [{"name": "mat", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2716, "task_id": "minimize-string-length", "difficulty": "Easy", "problem_description": "Given a string s, you have two types of operation:\n\n1. Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if exists).\n2. Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the right of i (if exists).\n\nYour task is to minimize the length of s by performing the above operations zero or more times.\n\nReturn an integer denoting the length of the minimized string.\n\nExample 1:\n\nInput: s = \"aaabc\"\nOutput: 3\nExplanation:\n1. Operation 2: we choose i = 1 so c is 'a', then we remove s[2] as it is closest 'a' character to the right of s[1].\ns becomes \"aabc\" after this.\n2. Operation 1: we choose i = 1 so c is 'a', then we remove s[0] as it is closest 'a' character to the left of s[1].\ns becomes \"abc\" after this.\n\nExample 2:\n\nInput: s = \"cbbd\"\nOutput: 3\nExplanation:\n1. Operation 1: we choose i = 2 so c is 'b', then we remove s[1] as it is closest 'b' character to the left of s[1].\ns becomes \"cbd\" after this.\n\nExample 3:\n\nInput: s = \"baadccab\"\nOutput: 4\nExplanation:\n1. Operation 1: we choose i = 6 so c is 'a', then we remove s[2] as it is closest 'a' character to the left of s[6].\ns becomes \"badccab\" after this.\n2. Operation 2: we choose i = 0 so c is 'b', then we remove s[6] as it is closest 'b' character to the right of s[0].\ns becomes \"badcca\" fter this.\n3. Operation 2: we choose i = 3 so c is 'c', then we remove s[4] as it is closest 'c' character to the right of s[3].\ns becomes \"badca\" after this.\n4. Operation 1: we choose i = 4 so c is 'a', then we remove s[1] as it is closest 'a' character to the left of s[4].\ns becomes \"bdca\" after this.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s contains only lowercase English letters\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaabc\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abacabadabacaba\") == 4\n assert candidate(s = \"abcabcabc\") == 3\n assert candidate(s = \"zzzz\") == 1\n assert candidate(s = \"cbbd\") == 3\n assert candidate(s = \"abcabc\") == 3\n assert candidate(s = \"xyz\") == 3\n assert candidate(s = \"aabb\") == 2\n assert candidate(s = \"world\") == 5\n assert candidate(s = \"zyxzyxzyx\") == 3\n assert candidate(s = \"baadccab\") == 4\n assert candidate(s = \"abcd\") == 4\n assert candidate(s = \"hello\") == 4\n assert candidate(s = \"abcdeabcde\") == 5\n assert candidate(s = \"aabbcc\") == 3\n assert candidate(s = \"zzzzz\") == 1\n assert candidate(s = \"programming\") == 8\n assert candidate(s = \"aabbccdd\") == 4\n assert candidate(s = \"abcdefg\") == 7\n assert candidate(s = \"aaaaaabbbbbcccccdddddeeeeeffffffggggg\") == 7\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzz\") == 3\n assert candidate(s = \"abracadabra\") == 5\n assert candidate(s = \"abcabcabcabc\") == 3\n assert candidate(s = \"tattarrattat\") == 3\n assert candidate(s = \"abcdefghigklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"abracadabraabracadabraabracadabraabracadabra\") == 5\n assert candidate(s = \"nervosysystem\") == 9\n assert candidate(s = \"bbaaccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 26\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 3\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\") == 10\n assert candidate(s = \"aaaaabbbbccccdddd\") == 4\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"xyzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxz\") == 3\n assert candidate(s = \"fakemakesfakeakesakesakefake\") == 6\n assert candidate(s = \"abcabcabcabcabcabcabc\") == 3\n assert candidate(s = \"kayak\") == 3\n assert candidate(s = \"aaaabbbbccccdddeeefffggghhhhiiijjjjkkkkllllmmmmmnnnnnooooo\") == 15\n assert candidate(s = \"xyzzzxyyyxyxxxyyxx\") == 3\n assert candidate(s = \"mnopqrspomnopqrspomnopqrspomnopqrspomnopqrspomnopqrspomnopqrspomn\") == 7\n assert candidate(s = \"aabcccccaaaa\") == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyyyy\") == 26\n assert candidate(s = \"abracadabraabracadabraabracadabra\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 26\n assert candidate(s = \"noon\") == 2\n assert candidate(s = \"abcdefghijkabcdefghi\") == 11\n assert candidate(s = \"ababababababababab\") == 2\n assert candidate(s = \"abcdefghijkabcdefghijk\") == 11\n assert candidate(s = \"nanaanananananananana\") == 2\n assert candidate(s = \"abcdefghijkabcdefghijkabcdefghijk\") == 11\n assert candidate(s = \"abcdabcdabcdabcd\") == 4\n assert candidate(s = \"level\") == 3\n assert candidate(s = \"abababababababababababababab\") == 2\n assert candidate(s = \"aaaaabbbbbbccccccccdddddddd\") == 4\n assert candidate(s = \"zzzyyyyyxxxxwwwvvvuuutttsssrrqqppoonnmmmlllkkkjjjiiihhggffeeddccbbaa\") == 26\n assert candidate(s = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 3\n assert candidate(s = \"abababababababababab\") == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxy\") == 2\n assert candidate(s = \"abcdefghijkabcdefg\") == 11\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"xyzzzzyx\") == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"hellohellohellohellohellohellohellohellohellohello\") == 4\n assert candidate(s = \"aabaaabbbcccddddeeeeffffgggghhhhiiiiijjjjkkkklllmmnnnnooopppqqrrrsssttttuuuuvvvvwwwwxxxxxyyyyzzzz\") == 26\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefgabcdefg\") == 7\n assert candidate(s = \"aabbccddeeefffggghhhhiiiiijjjjjkkkkklmmmmmnnnnnoooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 26\n assert candidate(s = \"banana\") == 3\n assert candidate(s = \"thisisaverylongstringwithseveralcharacters\") == 15\n assert candidate(s = \"thisisaverylongstringwithmanyalphabetsandduplicates\") == 20\n assert candidate(s = \"aaaaaabbbbbbccccccdddddeeeeeeffffffff\") == 6\n assert candidate(s = \"ababababababababababababab\") == 2\n assert candidate(s = \"elephant\") == 7\n assert candidate(s = \"abcdefghijkab\") == 11\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 26\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"aabbccddeeffaabbccddeeff\") == 6\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\") == 26\n assert candidate(s = \"aaaabbbbccccdddd\") == 4\n assert candidate(s = \"zzyyxwwvvuuttssrrqqppoonnmlkjihgfedcba\") == 26\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzz\") == 26\n assert candidate(s = \"deified\") == 4\n assert candidate(s = \"repaper\") == 4\n assert candidate(s = \"ppppqqqqrrrrssssttttuuuuvvvvwwwwwxxxxxyyyyyzzzzz\") == 11\n assert candidate(s = \"aabbaabbccddeeffaabbccddeeff\") == 6\n assert candidate(s = \"nolemonnomelon\") == 5\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 26\n assert candidate(s = \"ababababab\") == 2\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyz\") == 3\n assert candidate(s = \"abcdefghijkabcde\") == 11\n assert candidate(s = \"civic\") == 3\n assert candidate(s = \"rotor\") == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyz\") == 26\n assert candidate(s = \"racecar\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabc\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\") == 2\n assert candidate(s = \"abbcccddddeeeee\") == 5\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"aabbccddeeefff\") == 6\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzz\") == 26\n assert candidate(s = \"abcdefghijkabcdefghijkabcdefghij\") == 11\n assert candidate(s = \"mississippi\") == 4\n assert candidate(s = \"unique\") == 5\n assert candidate(s = \"abcabcabcabcabc\") == 3\n assert candidate(s = \"aabbbcccddd\") == 4\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcd\") == 4\n", "comparison": "exact"}, "public_tests": ["\"aaabc\"", "\"cbbd\"", "\"baadccab\""], "hints": ["The minimized string will not contain duplicate characters.", "The minimized string will contain all distinct characters of the original string."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimizedStringLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:15+00:00", "tests_total": 112, "tests_dropped": 3, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "ruby", "interface": {"raw_signature": "def minimized_string_length(s)", "container": null, "callable": "minimized_string_length", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2717, "task_id": "semi-ordered-permutation", "difficulty": "Easy", "problem_description": "You are given a 0-indexed permutation of n integers nums.\n\nA permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:\n\n- Pick two adjacent elements in nums, then swap them.\n\nReturn the minimum number of operations to make nums a semi-ordered permutation.\n\nA permutation is a sequence of integers from 1 to n of length n containing each number exactly once.\n\nExample 1:\n\nInput: nums = [2,1,4,3]\nOutput: 2\nExplanation: We can make the permutation semi-ordered using these sequence of operations:\n1 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].\n2 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].\nIt can be proved that there is no sequence of less than two operations that make nums a semi-ordered permutation.\n\nExample 2:\n\nInput: nums = [2,4,1,3]\nOutput: 3\nExplanation: We can make the permutation semi-ordered using these sequence of operations:\n1 - swap i = 1 and j = 2. The permutation becomes [2,1,4,3].\n2 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].\n3 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].\nIt can be proved that there is no sequence of less than three operations that make nums a semi-ordered permutation.\n\nExample 3:\n\nInput: nums = [1,3,4,2,5]\nOutput: 0\nExplanation: The permutation is already a semi-ordered permutation.\n\nConstraints:\n\n- 2 <= nums.length == n <= 50\n- 1 <= nums[i] <= 50\n- nums is a permutation.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 7\n assert candidate(nums = [2, 4, 1, 3]) == 3\n assert candidate(nums = [3, 5, 4, 1, 2]) == 5\n assert candidate(nums = [3, 1, 2, 5, 4]) == 2\n assert candidate(nums = [1, 5, 4, 3, 2]) == 3\n assert candidate(nums = [3, 2, 5, 4, 1]) == 5\n assert candidate(nums = [4, 1, 2, 5, 3]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [2, 3, 4, 5, 1]) == 4\n assert candidate(nums = [4, 5, 3, 1, 2]) == 5\n assert candidate(nums = [1, 3, 4, 2, 5]) == 0\n assert candidate(nums = [2, 1, 4, 3]) == 2\n assert candidate(nums = [3, 2, 1, 5, 4]) == 3\n assert candidate(nums = [10, 1, 9, 8, 7, 6, 5, 4, 3, 2]) == 9\n assert candidate(nums = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 20, 19, 18, 17, 2]) == 18\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16]) == 18\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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]) == 14\n assert candidate(nums = [4, 2, 5, 1, 3]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 2, 1]) == 10\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 37\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 37\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == 9\n assert candidate(nums = [5, 1, 2, 3, 4, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [4, 3, 5, 1, 2]) == 4\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]) == 97\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]) == 47\n assert candidate(nums = [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, 1, 2]) == 49\n assert candidate(nums = [48, 29, 10, 34, 32, 15, 19, 2, 25, 47, 35, 13, 44, 12, 8, 41, 17, 40, 21, 4, 42, 18, 33, 36, 22, 39, 26, 7, 5, 43, 6, 37, 31, 27, 30, 24, 20, 1, 23, 38, 9, 28, 16, 3, 11, 14, 45, 46, 49, 50]) == 37\n assert candidate(nums = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 8\n assert candidate(nums = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 8\n assert candidate(nums = [1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 18\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]) == 57\n assert candidate(nums = [15, 1, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 14\n assert candidate(nums = [4, 5, 1, 3, 2]) == 4\n assert candidate(nums = [5, 3, 2, 1, 4]) == 6\n assert candidate(nums = [23, 15, 32, 1, 10, 45, 2, 11, 50, 8, 13, 19, 6, 9, 17, 27, 20, 21, 22, 3, 24, 25, 26, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49]) == 8\n assert candidate(nums = [1, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 23\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, 31]) == 29\n assert candidate(nums = [49, 1, 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]) == 48\n assert candidate(nums = [49, 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, 1, 50]) == 48\n assert candidate(nums = [48, 49, 50, 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, 1, 2, 3]) == 93\n assert candidate(nums = [4, 5, 2, 3, 1]) == 6\n assert candidate(nums = [7, 5, 6, 4, 1, 3, 2]) == 9\n assert candidate(nums = [5, 1, 4, 2, 3]) == 4\n assert candidate(nums = [5, 2, 3, 4, 1]) == 7\n assert candidate(nums = [4, 5, 3, 2, 1]) == 6\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]) == 97\n assert candidate(nums = [2, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1]) == 46\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 9\n assert candidate(nums = [4, 1, 3, 5, 2]) == 2\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == 9\n assert candidate(nums = [2, 10, 9, 8, 7, 6, 5, 4, 3, 1]) == 16\n assert candidate(nums = [10, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 17\n assert candidate(nums = [25, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 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]) == 1\n assert candidate(nums = [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]) == 77\n assert candidate(nums = [2, 5, 4, 1, 3]) == 5\n assert candidate(nums = [49, 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, 1]) == 95\n assert candidate(nums = [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, 1]) == 48\n assert candidate(nums = [45, 1, 2, 3, 46, 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]) == 1\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 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]) == 9\n assert candidate(nums = [2, 19, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1]) == 35\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 17\n assert candidate(nums = [3, 5, 2, 4, 1]) == 6\n assert candidate(nums = [47, 48, 49, 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]) == 48\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 17\n assert candidate(nums = [2, 5, 4, 1, 3]) == 5\n assert candidate(nums = [2, 3, 5, 4, 1]) == 5\n assert candidate(nums = [5, 2, 3, 1, 4]) == 6\n assert candidate(nums = [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, 46]) == 44\n assert candidate(nums = [5, 1, 2, 3, 4, 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]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [2, 5, 4, 3, 1]) == 6\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, 26, 27, 28, 29, 30, 1]) == 29\n assert candidate(nums = [5, 3, 4, 1, 2]) == 6\n assert candidate(nums = [48, 49, 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\n assert candidate(nums = [3, 5, 1, 4, 2]) == 4\n assert candidate(nums = [1, 50, 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]) == 48\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, 26]) == 24\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 = [5, 1, 2, 3, 4]) == 4\n assert candidate(nums = [45, 1, 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]) == 44\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == 9\n assert candidate(nums = [3, 2, 5, 4, 1, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [2, 3, 1, 5, 4]) == 3\n assert candidate(nums = [4, 3, 2, 1, 5]) == 3\n assert candidate(nums = [47, 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, 48, 49, 50, 1]) == 49\n assert candidate(nums = [3, 5, 1, 4, 2]) == 4\n assert candidate(nums = [1, 5, 3, 4, 2]) == 3\n assert candidate(nums = [4, 2, 3, 1, 5]) == 3\n assert candidate(nums = [10, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 17\n assert candidate(nums = [2, 1, 3, 5, 4, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [47, 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, 1]) == 91\n assert candidate(nums = [4, 3, 5, 1, 2]) == 4\n assert candidate(nums = [4, 5, 1, 2, 3]) == 4\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 7, 8, 9, 10]) == 5\n assert candidate(nums = [5, 1, 4, 3, 2]) == 4\n", "comparison": "exact"}, "public_tests": ["[2,1,4,3]", "[2,4,1,3]", "[1,3,4,2,5]"], "hints": ["Find the index of elements 1 and n.", "Let x be the position of 1 and y be the position of n. the answer is x + (n-y-1) if x < y and x + (n-y-1) - 1 if x > y."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().semiOrderedPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:17+00:00", "tests_total": 99, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def semi_ordered_permutation(nums)", "container": null, "callable": "semi_ordered_permutation", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2718, "task_id": "sum-of-matrix-after-queries", "difficulty": "Medium", "problem_description": "You are given an integer n and a 0-indexed 2D array queries where queries[i] = [type_i, index_i, val_i].\n\nInitially, there is a 0-indexed n x n matrix filled with 0's. For each query, you must apply one of the following changes:\n\n- if type_i == 0, set the values in the row with index_i to val_i, overwriting any previous values.\n- if type_i == 1, set the values in the column with index_i to val_i, overwriting any previous values.\n\nReturn the sum of integers in the matrix after all queries are applied.\n\nExample 1:\n\nInput: n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]]\nOutput: 23\nExplanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 23.\n\nExample 2:\n\nInput: n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]\nOutput: 17\nExplanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17.\n\nConstraints:\n\n- 1 <= n <= 10^4\n- 1 <= queries.length <= 5 * 10^4\n- queries[i].length == 3\n- 0 <= type_i <= 1\n- 0 <= index_i < n\n- 0 <= val_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4]]) == 13\n assert candidate(n = 5,queries = [[0, 1, 10], [1, 2, 5], [0, 4, 7], [1, 0, 3]]) == 93\n assert candidate(n = 4,queries = [[1, 3, 2], [0, 1, 5], [1, 0, 3], [0, 2, 4]]) == 44\n assert candidate(n = 1,queries = [[0, 0, 10], [1, 0, 20]]) == 20\n assert candidate(n = 2,queries = [[0, 0, 1], [0, 1, 2], [1, 0, 3], [1, 1, 4]]) == 14\n assert candidate(n = 1,queries = [[0, 0, 100]]) == 100\n assert candidate(n = 3,queries = [[0, 0, 4], [0, 1, 2], [1, 0, 1], [0, 2, 3], [1, 2, 1]]) == 17\n assert candidate(n = 2,queries = [[1, 0, 5], [1, 1, 10], [0, 0, 15], [0, 1, 20]]) == 70\n assert candidate(n = 5,queries = [[1, 0, 10], [0, 2, 3], [1, 4, 5]]) == 77\n assert candidate(n = 3,queries = [[0, 0, 1], [1, 2, 2], [0, 2, 3], [1, 0, 4]]) == 23\n assert candidate(n = 4,queries = [[0, 1, 5], [1, 3, 2], [0, 3, 1]]) == 25\n assert candidate(n = 5,queries = [[0, 1, 5], [1, 3, 4], [0, 2, 6], [1, 0, 2], [0, 0, 3]]) == 74\n assert candidate(n = 10000,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4], [0, 2, 5], [1, 2, 6], [0, 3, 7], [1, 3, 8], [0, 4, 9], [1, 4, 10]]) == 549905\n assert candidate(n = 5,queries = [[1, 0, 10], [0, 0, 5], [1, 1, 20], [0, 1, 10], [1, 2, 30], [0, 2, 15], [1, 3, 40], [0, 3, 20], [1, 4, 50], [0, 4, 25]]) == 675\n assert candidate(n = 10,queries = [[0, 0, 10], [1, 0, 20], [0, 1, 30], [1, 1, 40], [0, 2, 50], [1, 2, 60], [0, 3, 70], [1, 3, 80], [0, 4, 90], [1, 4, 100], [0, 5, 110], [1, 5, 120], [0, 6, 130], [1, 6, 140], [0, 7, 150], [1, 7, 160], [0, 8, 170], [1, 8, 180], [0, 9, 190], [1, 9, 200]]) == 13850\n assert candidate(n = 8,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 7], [0, 7, 8], [1, 0, 9], [1, 1, 10], [1, 2, 11], [1, 3, 12], [1, 4, 13], [1, 5, 14], [1, 6, 15], [1, 7, 16]]) == 800\n assert candidate(n = 4,queries = [[0, 0, 5], [1, 1, 3], [0, 2, 2], [1, 3, 1], [0, 0, 4], [1, 2, 6]]) == 49\n assert candidate(n = 6,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [1, 0, 1], [1, 1, 2], [1, 2, 3], [1, 3, 4], [1, 4, 5], [1, 5, 6]]) == 126\n assert candidate(n = 1000,queries = [[0, 0, 100000], [1, 0, 100000], [0, 1, 100000], [1, 1, 100000], [0, 2, 100000], [1, 2, 100000]]) == 599100000\n assert candidate(n = 5,queries = [[0, 0, 1], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 4, 5]]) == 62\n assert candidate(n = 10,queries = [[0, 0, 1], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 4, 5], [1, 5, 6], [0, 6, 7], [1, 7, 8], [0, 8, 9], [1, 9, 10]]) == 455\n assert candidate(n = 10,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 9], [0, 9, 10], [1, 0, 10], [1, 1, 9], [1, 2, 8], [1, 3, 7], [1, 4, 6], [1, 5, 5], [1, 6, 4], [1, 7, 3], [1, 8, 2], [1, 9, 1]]) == 550\n assert candidate(n = 10,queries = [[0, 0, 100], [1, 1, 200], [0, 2, 300], [1, 3, 400], [0, 4, 500], [1, 0, 600], [0, 5, 700], [1, 2, 800], [0, 6, 900], [1, 3, 1000]]) == 43100\n assert candidate(n = 7,queries = [[0, 6, 1], [0, 5, 2], [0, 4, 3], [0, 3, 4], [0, 2, 5], [0, 1, 6], [0, 0, 7], [1, 0, 8], [1, 1, 9], [1, 2, 10], [1, 3, 11], [1, 4, 12], [1, 5, 13], [1, 6, 14]]) == 539\n assert candidate(n = 10,queries = [[0, 3, 7], [1, 4, 9], [0, 2, 5], [1, 1, 3], [0, 5, 6], [1, 8, 2], [0, 9, 8], [1, 0, 4]]) == 342\n assert candidate(n = 4,queries = [[0, 0, 5], [1, 0, 5], [0, 1, 10], [1, 1, 10], [0, 2, 15], [1, 2, 15], [0, 3, 20], [1, 3, 20]]) == 250\n assert candidate(n = 5,queries = [[0, 0, 10], [1, 1, 20], [0, 2, 30], [1, 3, 40], [0, 4, 50], [1, 0, 60], [0, 1, 70], [1, 2, 80], [0, 3, 90], [1, 4, 100]]) == 1800\n assert candidate(n = 5,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4], [0, 2, 5], [1, 2, 6], [0, 3, 7], [1, 3, 8], [0, 4, 9], [1, 4, 10]]) == 180\n assert candidate(n = 8,queries = [[1, 0, 1], [1, 1, 2], [1, 2, 3], [1, 3, 4], [1, 4, 5], [1, 5, 6], [1, 6, 7], [1, 7, 8], [0, 0, 10], [0, 1, 20], [0, 2, 30], [0, 3, 40], [0, 4, 50], [0, 5, 60], [0, 6, 70], [0, 7, 80]]) == 2880\n assert candidate(n = 5,queries = [[0, 1, 3], [1, 2, 4], [0, 3, 5], [1, 4, 6], [0, 0, 7], [1, 0, 8], [0, 2, 9]]) == 152\n assert candidate(n = 4,queries = [[0, 0, 1], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 1, 5], [1, 0, 6], [0, 3, 7], [1, 2, 8]]) == 94\n assert candidate(n = 8,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4], [0, 2, 5], [1, 2, 6], [0, 3, 7], [1, 3, 8], [0, 4, 9], [1, 4, 10], [0, 5, 11], [1, 5, 12], [0, 6, 13], [1, 6, 14], [0, 7, 15], [1, 7, 16]]) == 716\n assert candidate(n = 8,queries = [[0, 0, 20], [1, 0, 21], [0, 1, 22], [1, 1, 23], [0, 2, 24], [1, 2, 25], [0, 3, 26], [1, 3, 27], [0, 4, 28], [1, 4, 29], [0, 5, 30], [1, 5, 31], [0, 6, 32], [1, 6, 33], [0, 7, 34], [1, 7, 35]]) == 1932\n assert candidate(n = 6,queries = [[0, 1, 100], [1, 3, 200], [0, 2, 50], [1, 1, 150], [0, 4, 250], [1, 0, 300]]) == 5100\n assert candidate(n = 4,queries = [[1, 0, 10], [0, 0, 20], [1, 1, 30], [0, 1, 40], [1, 2, 50], [0, 2, 60], [1, 3, 70], [0, 3, 80]]) == 940\n assert candidate(n = 4,queries = [[0, 1, 5], [1, 2, 8], [0, 3, 9], [1, 0, 4], [0, 2, 6], [1, 1, 7]]) == 97\n assert candidate(n = 3,queries = [[0, 0, 1], [1, 2, 2], [0, 2, 3], [1, 0, 4], [0, 1, 5], [1, 1, 6]]) == 41\n assert candidate(n = 3,queries = [[0, 0, 10], [1, 0, 20], [0, 1, 30], [1, 1, 40], [0, 2, 50], [1, 2, 60]]) == 410\n assert candidate(n = 5,queries = [[0, 0, 10], [1, 1, 5], [0, 2, 3], [1, 3, 7], [0, 4, 2], [1, 0, 8]]) == 120\n assert candidate(n = 8,queries = [[0, 7, 5], [1, 6, 4], [0, 5, 3], [1, 4, 2], [0, 3, 1], [1, 2, 6], [0, 1, 7], [1, 0, 8], [0, 6, 9], [1, 7, 10]]) == 335\n assert candidate(n = 7,queries = [[0, 6, 11], [1, 5, 12], [0, 4, 13], [1, 3, 14], [0, 2, 15], [1, 1, 16], [0, 0, 17], [1, 6, 18], [0, 5, 19], [1, 4, 20]]) == 740\n assert candidate(n = 10,queries = [[0, 9, 1], [1, 8, 2], [0, 7, 3], [1, 6, 4], [0, 5, 5], [1, 4, 6], [0, 3, 7], [1, 2, 8], [0, 1, 9], [1, 0, 10], [0, 8, 11], [1, 7, 12], [0, 6, 13], [1, 5, 14], [0, 4, 15], [1, 3, 16], [0, 2, 17], [1, 1, 18], [0, 0, 19], [1, 9, 20]]) == 1385\n assert candidate(n = 9,queries = [[0, 0, 2], [1, 0, 3], [0, 1, 4], [1, 1, 5], [0, 2, 6], [1, 2, 7], [0, 3, 8], [1, 3, 9], [0, 4, 10], [1, 4, 11], [0, 5, 12], [1, 5, 13], [0, 6, 14], [1, 6, 15], [0, 7, 16], [1, 7, 17], [0, 8, 18], [1, 8, 19]]) == 1095\n assert candidate(n = 5,queries = [[0, 0, 5], [1, 1, 3], [0, 2, 8], [1, 3, 2], [0, 4, 1], [1, 0, 4]]) == 75\n assert candidate(n = 6,queries = [[0, 2, 100], [1, 3, 200], [0, 0, 300], [1, 1, 400], [0, 4, 500], [1, 5, 600], [0, 5, 700], [1, 0, 800]]) == 16600\n assert candidate(n = 4,queries = [[0, 0, 1], [0, 0, 2], [0, 0, 3], [1, 0, 4], [1, 0, 5], [1, 0, 6], [0, 1, 7], [1, 1, 8], [0, 2, 9], [1, 2, 10], [0, 3, 11], [1, 3, 12]]) == 158\n assert candidate(n = 4,queries = [[0, 0, 5], [1, 1, 6], [0, 2, 7], [1, 3, 8], [0, 1, 9]]) == 103\n assert candidate(n = 5000,queries = [[0, 0, 1], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 4, 5], [1, 0, 6], [0, 3, 7], [1, 2, 8], [0, 1, 9], [1, 4, 10]]) == 274905\n assert candidate(n = 6,queries = [[0, 0, 1], [1, 5, 2], [0, 4, 3], [1, 3, 4], [0, 2, 5], [1, 1, 6], [0, 1, 7], [1, 0, 8]]) == 166\n assert candidate(n = 3,queries = [[1, 0, 1], [0, 0, 2], [1, 1, 3], [0, 1, 4], [1, 2, 5], [0, 2, 6]]) == 41\n assert candidate(n = 4,queries = [[0, 0, 5], [1, 1, 10], [0, 2, 20], [1, 3, 30], [0, 1, 50], [1, 0, 60]]) == 545\n assert candidate(n = 3,queries = [[0, 0, 5], [0, 1, 5], [0, 2, 5], [1, 0, 5], [1, 1, 5], [1, 2, 5]]) == 45\n assert candidate(n = 7,queries = [[0, 6, 70], [1, 5, 60], [0, 4, 50], [1, 3, 40], [0, 2, 30], [1, 1, 20], [0, 0, 10], [1, 0, 0], [0, 1, 1], [1, 2, 2], [0, 3, 3], [1, 4, 4], [0, 5, 5], [1, 6, 6]]) == 465\n assert candidate(n = 5,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [1, 0, 6], [1, 1, 7], [1, 2, 8], [1, 3, 9], [1, 4, 10], [0, 0, 11], [0, 1, 12], [0, 2, 13], [0, 3, 14], [0, 4, 15], [1, 0, 16], [1, 1, 17], [1, 2, 18], [1, 3, 19], [1, 4, 20]]) == 450\n assert candidate(n = 10,queries = [[1, 0, 1], [1, 1, 2], [1, 2, 3], [1, 3, 4], [1, 4, 5], [1, 5, 6], [1, 6, 7], [1, 7, 8], [1, 8, 9], [1, 9, 10]]) == 550\n assert candidate(n = 1000,queries = [[0, 500, 1], [1, 500, 2], [0, 499, 3], [1, 499, 4], [0, 498, 5], [1, 498, 6], [0, 497, 7], [1, 497, 8], [0, 496, 9], [1, 496, 10]]) == 54905\n assert candidate(n = 5000,queries = [[0, 2500, 1], [1, 2500, 2], [0, 2499, 3], [1, 2499, 4], [0, 2498, 5], [1, 2498, 6], [0, 2497, 7], [1, 2497, 8], [0, 2496, 9], [1, 2496, 10]]) == 274905\n assert candidate(n = 1000,queries = [[0, 500, 5], [1, 250, 10], [0, 750, 20], [1, 0, 30], [0, 999, 50], [1, 500, 60]]) == 174845\n assert candidate(n = 3,queries = [[0, 0, 10], [1, 0, 20], [0, 1, 30], [1, 1, 40], [0, 2, 50], [1, 2, 60], [0, 0, 70], [1, 0, 80]]) == 590\n assert candidate(n = 5,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [1, 0, 6], [1, 1, 7], [1, 2, 8], [1, 3, 9], [1, 4, 10]]) == 200\n assert candidate(n = 4,queries = [[0, 0, 10], [1, 2, 5], [0, 3, 3], [1, 1, 7], [0, 2, 8], [1, 3, 2]]) == 79\n assert candidate(n = 100,queries = [[0, 50, 10], [1, 50, 20], [0, 25, 15], [1, 75, 25], [0, 75, 30], [1, 25, 35], [0, 0, 5], [1, 99, 50]]) == 18705\n assert candidate(n = 3,queries = [[0, 0, 1], [1, 2, 2], [0, 2, 3], [1, 0, 4], [0, 1, 5], [1, 1, 6], [0, 0, 7], [1, 2, 8]]) == 59\n assert candidate(n = 10,queries = [[0, 5, 9], [1, 4, 8], [0, 9, 7], [1, 3, 6], [0, 2, 5], [1, 1, 4], [0, 0, 3], [1, 8, 2], [0, 7, 1], [1, 6, 0]]) == 295\n assert candidate(n = 10,queries = [[0, 0, 10], [1, 0, 10], [0, 1, 20], [1, 1, 20], [0, 2, 30], [1, 2, 30], [0, 3, 40], [1, 3, 40], [0, 4, 50], [1, 4, 50], [0, 5, 60], [1, 5, 60], [0, 6, 70], [1, 6, 70], [0, 7, 80], [1, 7, 80], [0, 8, 90], [1, 8, 90], [0, 9, 100], [1, 9, 100]]) == 7150\n assert candidate(n = 5,queries = [[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1]]) == 25\n assert candidate(n = 7,queries = [[0, 0, 1], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 4, 5], [1, 5, 6], [0, 6, 7], [1, 6, 8], [0, 5, 9], [1, 4, 10]]) == 290\n assert candidate(n = 6,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [1, 0, 6], [1, 1, 5], [1, 2, 4], [1, 3, 3], [1, 4, 2], [1, 5, 1]]) == 126\n assert candidate(n = 6,queries = [[0, 5, 50], [1, 4, 40], [0, 3, 30], [1, 2, 20], [0, 1, 10], [1, 0, 0], [0, 4, 400], [1, 5, 500], [0, 2, 200], [1, 3, 300]]) == 7180\n assert candidate(n = 5,queries = [[0, 0, 10], [1, 1, 20], [0, 2, 30], [1, 3, 40], [0, 4, 50]]) == 620\n assert candidate(n = 5,queries = [[1, 0, 1], [1, 1, 2], [1, 2, 3], [1, 3, 4], [1, 4, 5], [0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]]) == 75\n assert candidate(n = 7,queries = [[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1], [1, 6, 1]]) == 49\n assert candidate(n = 10,queries = [[0, 9, 100], [1, 8, 90], [0, 7, 80], [1, 6, 70], [0, 5, 60], [1, 4, 50], [0, 3, 40], [1, 2, 30], [0, 1, 20], [1, 0, 10]]) == 3700\n assert candidate(n = 1000,queries = [[0, 500, 1], [1, 500, 2], [0, 499, 3], [1, 499, 4], [0, 501, 5], [1, 501, 6], [0, 0, 10], [1, 999, 20]]) == 50947\n assert candidate(n = 7,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4], [0, 2, 5], [1, 2, 6], [0, 3, 7], [1, 3, 8], [0, 4, 9], [1, 4, 10], [0, 5, 11], [1, 5, 12], [0, 6, 13], [1, 6, 14]]) == 483\n assert candidate(n = 4,queries = [[0, 0, 5], [1, 1, 10], [0, 2, 15], [1, 3, 20], [0, 3, 25]]) == 235\n assert candidate(n = 10,queries = [[0, 0, 1], [0, 1, 2], [1, 0, 3], [1, 1, 4], [0, 2, 5], [1, 2, 6], [0, 3, 7], [1, 3, 8], [0, 4, 9], [1, 4, 10]]) == 456\n assert candidate(n = 6,queries = [[0, 0, 1], [1, 1, 1], [0, 2, 1], [1, 3, 1], [0, 4, 1], [1, 5, 1], [0, 5, 1], [1, 0, 1], [0, 1, 1], [1, 2, 1], [0, 3, 1], [1, 4, 1]]) == 36\n assert candidate(n = 10,queries = [[0, 0, 10], [1, 1, 20], [0, 2, 30], [1, 3, 40], [0, 4, 50], [1, 5, 60], [0, 6, 70], [1, 7, 80], [0, 8, 90], [1, 9, 100]]) == 4550\n assert candidate(n = 9,queries = [[0, 0, 1], [1, 8, 9], [0, 1, 2], [1, 7, 8], [0, 2, 3], [1, 6, 7], [0, 3, 4], [1, 5, 6], [0, 4, 5]]) == 305\n assert candidate(n = 7,queries = [[0, 0, 1], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 4, 5], [1, 5, 6], [0, 6, 7], [1, 0, 8], [0, 1, 9], [1, 2, 10], [0, 3, 11], [1, 4, 12], [0, 5, 13], [1, 6, 14], [0, 0, 15], [1, 1, 16], [0, 2, 17], [1, 3, 18], [0, 4, 19], [1, 5, 20], [0, 6, 21], [1, 0, 22]]) == 875\n assert candidate(n = 3,queries = [[0, 0, 1], [1, 0, 2], [0, 0, 3], [1, 0, 4], [0, 0, 5], [1, 0, 6], [0, 0, 7], [1, 0, 8]]) == 38\n assert candidate(n = 4,queries = [[0, 2, 5], [1, 1, 3], [0, 0, 2], [1, 2, 8], [0, 3, 1]]) == 50\n assert candidate(n = 5,queries = [[0, 0, 1], [0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5], [1, 0, 1], [1, 0, 2], [1, 0, 3], [1, 0, 4], [1, 0, 5]]) == 45\n assert candidate(n = 6,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [1, 0, 10], [1, 1, 20], [1, 2, 30], [1, 3, 40], [1, 4, 50], [1, 5, 60]]) == 1260\n assert candidate(n = 10,queries = [[0, 0, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 9], [0, 9, 10]]) == 550\n assert candidate(n = 3,queries = [[0, 0, 1], [1, 0, 2], [0, 1, 3], [1, 1, 4], [0, 2, 5], [1, 2, 6], [0, 0, 7], [1, 0, 8], [0, 1, 9], [1, 1, 10]]) == 77\n assert candidate(n = 3,queries = [[0, 0, 100], [0, 0, 200], [0, 0, 300], [1, 1, 100], [1, 1, 200], [1, 1, 300], [0, 1, 100], [0, 2, 200], [1, 0, 300], [1, 2, 400]]) == 2700\n assert candidate(n = 5000,queries = [[0, 2500, 5], [1, 1250, 10], [0, 3750, 20], [1, 0, 30], [0, 4999, 50], [1, 2500, 60]]) == 874845\n assert candidate(n = 4,queries = [[0, 0, 5], [1, 1, 2], [0, 2, 3], [1, 3, 4], [0, 3, 1], [1, 0, 6]]) == 54\n assert candidate(n = 500,queries = [[0, 0, 100], [1, 0, 200], [0, 100, 150], [1, 200, 250], [0, 300, 300], [1, 400, 400], [0, 1, 10], [1, 2, 20], [0, 3, 30], [1, 4, 40]]) == 745580\n", "comparison": "exact"}, "public_tests": ["3\n[[0,0,1],[1,2,2],[0,2,3],[1,0,4]]", "3\n[[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]"], "hints": ["Process queries in reversed order, as the latest queries represent the most recent changes in the matrix.", "Once you encounter an operation on some row/column, no further operations will affect the values in this row/column. Keep track of seen rows and columns with a set.", "When operating on an unseen row/column, the number of affected cells is the number of columns/rows you haven’t previously seen."], "metadata": {"canonical_parameter_names": ["n", "queries"], "leetcode_dataset_entry_point": "Solution().matrixSumQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:20+00:00", "tests_total": 91, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def matrix_sum_queries(n, queries)", "container": null, "callable": "matrix_sum_queries", "parameters": [{"name": "n", "type": "Integer"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2719, "task_id": "count-of-integers", "difficulty": "Hard", "problem_description": "You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:\n\n- num1 <= x <= num2\n- min_sum <= digit_sum(x) <= max_sum.\n\nReturn the number of good integers. Since the answer may be large, return it modulo 10^9 + 7.\n\nNote that digit_sum(x) denotes the sum of the digits of x.\n\nExample 1:\n\nInput: num1 = \"1\", num2 = \"12\", min_sum = 1, max_sum = 8\nOutput: 11\nExplanation: There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.\n\nExample 2:\n\nInput: num1 = \"1\", num2 = \"5\", min_sum = 1, max_sum = 5\nOutput: 5\nExplanation: The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5.\n\nConstraints:\n\n- 1 <= num1 <= num2 <= 10^22\n- 1 <= min_sum <= max_sum <= 400\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num1 = \"1\",num2 = \"5\",min_sum = 1,max_sum = 5) == 5\n assert candidate(num1 = \"1\",num2 = \"1000000000000000000000000000000\",min_sum = 300,max_sum = 400) == 0\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 1,max_sum = 400) == 2\n assert candidate(num1 = \"123456789012345678901234567890\",num2 = \"987654321098765432109876543210\",min_sum = 100,max_sum = 200) == 559200081\n assert candidate(num1 = \"1\",num2 = \"1000000000000000000000000000000\",min_sum = 1,max_sum = 1) == 31\n assert candidate(num1 = \"10\",num2 = \"100\",min_sum = 2,max_sum = 10) == 53\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"999999999999999999999999999999\",min_sum = 81,max_sum = 81) == 0\n assert candidate(num1 = \"1000\",num2 = \"2000\",min_sum = 10,max_sum = 20) == 715\n assert candidate(num1 = \"50\",num2 = \"150\",min_sum = 5,max_sum = 20) == 91\n assert candidate(num1 = \"1000\",num2 = \"2000\",min_sum = 10,max_sum = 30) == 835\n assert candidate(num1 = \"50\",num2 = \"150\",min_sum = 5,max_sum = 15) == 85\n assert candidate(num1 = \"1\",num2 = \"12\",min_sum = 1,max_sum = 8) == 11\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 100,max_sum = 200) == 0\n assert candidate(num1 = \"11111111111111111111111111111\",num2 = \"22222222222222222222222222222\",min_sum = 30,max_sum = 60) == 182368529\n assert candidate(num1 = \"1000000000000000000000000000000\",num2 = \"999999999999999999999999999999\",min_sum = 1,max_sum = 400) == 0\n assert candidate(num1 = \"500000000000000000000000000000\",num2 = \"500000000000000000000000000001\",min_sum = 50,max_sum = 50) == 0\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"200000000000000000000000000000\",min_sum = 150,max_sum = 250) == 752538386\n assert candidate(num1 = \"1\",num2 = \"100000000000000000000000000000\",min_sum = 1,max_sum = 100) == 663692512\n assert candidate(num1 = \"1000000000000000000000000000000000000000\",num2 = \"1000000000000000000000000000000000000010\",min_sum = 1,max_sum = 10) == 11\n assert candidate(num1 = \"1\",num2 = \"1000000000000000000000000000000\",min_sum = 1,max_sum = 200) == 48265017\n assert candidate(num1 = \"1010101010101010101010101010101\",num2 = \"9090909090909090909090909090909\",min_sum = 50,max_sum = 150) == 762258132\n assert candidate(num1 = \"111111111111111111111111111110\",num2 = \"111111111111111111111111111119\",min_sum = 5,max_sum = 50) == 10\n assert candidate(num1 = \"555555555555555555555555555555\",num2 = \"666666666666666666666666666666\",min_sum = 120,max_sum = 130) == 562403818\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"200000000000000000000000000000\",min_sum = 10,max_sum = 20) == 81870141\n assert candidate(num1 = \"200000000000000000000000000000\",num2 = \"200000000000000000000000000005\",min_sum = 5,max_sum = 15) == 3\n assert candidate(num1 = \"1234567890\",num2 = \"9876543210\",min_sum = 1,max_sum = 99) == 641975265\n assert candidate(num1 = \"1000000000\",num2 = \"10000000000000000000\",min_sum = 1,max_sum = 400) == 498\n assert candidate(num1 = \"999999999999999999999999999990\",num2 = \"999999999999999999999999999999\",min_sum = 81,max_sum = 89) == 0\n assert candidate(num1 = \"2000000000000000000000000000000\",num2 = \"2999999999999999999999999999999\",min_sum = 100,max_sum = 200) == 648249887\n assert candidate(num1 = \"1000000000000000000000000000000\",num2 = \"1000000000000000000000000000001\",min_sum = 1,max_sum = 1) == 1\n assert candidate(num1 = \"1000000000000000000000000000000000000000\",num2 = \"2000000000000000000000000000000000000000\",min_sum = 100,max_sum = 200) == 416584880\n assert candidate(num1 = \"100000000000000000000000000000000000000000000000000000000000\",num2 = \"100000000000000000000000000000000000000000000000000000000001\",min_sum = 1,max_sum = 1) == 1\n assert candidate(num1 = \"123456789012345678901234567890\",num2 = \"987654321098765432109876543210\",min_sum = 180,max_sum = 220) == 514957697\n assert candidate(num1 = \"1234567890123456789012345678901\",num2 = \"9876543210987654321098765432109\",min_sum = 100,max_sum = 300) == 216561067\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"999999999999999999999999999999\",min_sum = 200,max_sum = 300) == 838989111\n assert candidate(num1 = \"500000000000000000000000000000\",num2 = \"600000000000000000000000000000\",min_sum = 150,max_sum = 250) == 690064938\n assert candidate(num1 = \"99999999999999999999999999999\",num2 = \"999999999999999999999999999999\",min_sum = 250,max_sum = 350) == 470298279\n assert candidate(num1 = \"500000000000000000000000000000\",num2 = \"500000000000000000000000000001\",min_sum = 100,max_sum = 100) == 0\n assert candidate(num1 = \"11111111111111111111\",num2 = \"22222222222222222222\",min_sum = 20,max_sum = 30) == 14575096\n assert candidate(num1 = \"555555555555555555555555555555\",num2 = \"555555555555555555555555555560\",min_sum = 150,max_sum = 250) == 5\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 200,max_sum = 300) == 1\n assert candidate(num1 = \"123456789012345678901234567890\",num2 = \"123456789012345678901234567890\",min_sum = 45,max_sum = 45) == 0\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"888888888888888888888888888888\",min_sum = 200,max_sum = 300) == 785167291\n assert candidate(num1 = \"1234567890123456789012345678901234567890\",num2 = \"9876543210987654321098765432109876543210\",min_sum = 150,max_sum = 250) == 254920565\n assert candidate(num1 = \"3000000000000000000000000000000\",num2 = \"3100000000000000000000000000000\",min_sum = 30,max_sum = 60) == 62608771\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"222222222222222222222222222222\",min_sum = 36,max_sum = 72) == 886258813\n assert candidate(num1 = \"900000000000000000000000000000\",num2 = \"9000000000000000000000000000001\",min_sum = 18,max_sum = 18) == 792480562\n assert candidate(num1 = \"9999999999999999999999999999999999999999\",num2 = \"9999999999999999999999999999999999999999\",min_sum = 180,max_sum = 200) == 0\n assert candidate(num1 = \"123456789\",num2 = \"987654321\",min_sum = 10,max_sum = 50) == 748923377\n assert candidate(num1 = \"500000000000000000000000000000\",num2 = \"500000000000000000000000000001\",min_sum = 25,max_sum = 50) == 0\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 1,max_sum = 9) == 1\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"999999999999999999999999999999\",min_sum = 1,max_sum = 400) == 999691307\n assert candidate(num1 = \"500000000000000000000000000000\",num2 = \"599999999999999999999999999999\",min_sum = 200,max_sum = 250) == 121684856\n assert candidate(num1 = \"1000000000000000000000000000000\",num2 = \"1000000000000000000000000000001\",min_sum = 1,max_sum = 9) == 2\n assert candidate(num1 = \"500000000000000000000000000000\",num2 = \"600000000000000000000000000000\",min_sum = 100,max_sum = 120) == 792681732\n assert candidate(num1 = \"50000000000000000000\",num2 = \"50000000000000000005\",min_sum = 25,max_sum = 35) == 0\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"110000000000000000000000000000\",min_sum = 1,max_sum = 10) == 124403621\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 81,max_sum = 81) == 0\n assert candidate(num1 = \"99999999999999999999\",num2 = \"100000000000000000000\",min_sum = 90,max_sum = 100) == 0\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"222222222222222222222222222222\",min_sum = 10,max_sum = 20) == 605921476\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"100000000000000000000000000010\",min_sum = 1,max_sum = 10) == 11\n assert candidate(num1 = \"123456789012345678901234567890123456789012345678901234567890\",num2 = \"987654321098765432109876543210987654321098765432109876543210\",min_sum = 150,max_sum = 250) == 623296612\n assert candidate(num1 = \"999999999999999999999999999990\",num2 = \"999999999999999999999999999999\",min_sum = 270,max_sum = 280) == 1\n assert candidate(num1 = \"123456789012345678901234567890\",num2 = \"123456789012345678901234567891\",min_sum = 1,max_sum = 400) == 2\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"200000000000000000000000000000\",min_sum = 1,max_sum = 1) == 1\n assert candidate(num1 = \"100000000000000000000000000001\",num2 = \"100000000000000000000000000010\",min_sum = 1,max_sum = 10) == 10\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"222222222222222222222222222222\",min_sum = 33,max_sum = 66) == 780304934\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 150,max_sum = 250) == 0\n assert candidate(num1 = \"222222222222222222222222222222\",num2 = \"333333333333333333333333333333\",min_sum = 44,max_sum = 66) == 688650163\n assert candidate(num1 = \"999999999999999999999999999999\",num2 = \"1000000000000000000000000000000\",min_sum = 270,max_sum = 271) == 1\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"200000000000000000000000000000\",min_sum = 50,max_sum = 150) == 113411552\n assert candidate(num1 = \"1111111111111111111111111111111111111111\",num2 = \"1111111111111111111111111111111111111111\",min_sum = 36,max_sum = 36) == 0\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"222222222222222222222222222222\",min_sum = 50,max_sum = 150) == 531163588\n assert candidate(num1 = \"987654321098765432109876543210\",num2 = \"987654321098765432109876543211\",min_sum = 1,max_sum = 400) == 2\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"222222222222222222222222222222\",min_sum = 15,max_sum = 30) == 312163769\n assert candidate(num1 = \"123456789\",num2 = \"987654321\",min_sum = 50,max_sum = 150) == 138991812\n assert candidate(num1 = \"123456789012345678901234567891\",num2 = \"987654321098765432109876543211\",min_sum = 150,max_sum = 250) == 442169096\n assert candidate(num1 = \"1\",num2 = \"1000000000000000000000000000000000000000\",min_sum = 1,max_sum = 400) == 2401000\n assert candidate(num1 = \"900000000000000000000000000000\",num2 = \"900000000000000000000000000010\",min_sum = 100,max_sum = 150) == 0\n assert candidate(num1 = \"123456789012345678901234567890\",num2 = \"234567890123456789012345678901\",min_sum = 50,max_sum = 100) == 518837468\n assert candidate(num1 = \"1000000000000000000000000000000\",num2 = \"1000000000000000000000000000000\",min_sum = 1,max_sum = 99) == 1\n assert candidate(num1 = \"123456789012345678901234567890\",num2 = \"123456789012345678901234567891\",min_sum = 45,max_sum = 45) == 0\n assert candidate(num1 = \"111111111111111111111111111111\",num2 = \"222222222222222222222222222222\",min_sum = 150,max_sum = 160) == 662198333\n assert candidate(num1 = \"888888888888888888888888888888\",num2 = \"999999999999999999999999999999\",min_sum = 250,max_sum = 260) == 162413701\n assert candidate(num1 = \"100000000000000000000000000000\",num2 = \"100000000000000000000000000001\",min_sum = 1,max_sum = 1) == 1\n", "comparison": "exact"}, "public_tests": ["\"1\"\n\"12\"\n1\n8", "\"1\"\n\"5\"\n1\n5"], "hints": ["Let f(n, l, r) denotes the number of integers from 1 to n with the sum of digits between l and r.", "The answer is f(num2, min_sum, max_sum) - f(num1-1, min_sum, max_sum).", "You can calculate f(n, l, r) using digit dp."], "metadata": {"canonical_parameter_names": ["num1", "num2", "min_sum", "max_sum"], "leetcode_dataset_entry_point": "Solution().count", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:22+00:00", "tests_total": 85, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def count(num1, num2, min_sum, max_sum)", "container": null, "callable": "count", "parameters": [{"name": "num1", "type": "String"}, {"name": "num2", "type": "String"}, {"name": "min_sum", "type": "Integer"}, {"name": "max_sum", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2729, "task_id": "check-if-the-number-is-fascinating", "difficulty": "Easy", "problem_description": "You are given an integer n that consists of exactly 3 digits.\n\nWe call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not contain any 0's:\n\n- Concatenate n with the numbers 2 * n and 3 * n.\n\nReturn true if n is fascinating, or false otherwise.\n\nConcatenating two numbers means joining them together. For example, the concatenation of 121 and 371 is 121371.\n\nExample 1:\n\nInput: n = 192\nOutput: true\nExplanation: We concatenate the numbers n = 192 and 2 * n = 384 and 3 * n = 576. The resulting number is 192384576. This number contains all the digits from 1 to 9 exactly once.\n\nExample 2:\n\nInput: n = 100\nOutput: false\nExplanation: We concatenate the numbers n = 100 and 2 * n = 200 and 3 * n = 300. The resulting number is 100200300. This number does not satisfy any of the conditions.\n\nConstraints:\n\n- 100 <= n <= 999\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 933) == False\n assert candidate(n = 147) == False\n assert candidate(n = 576) == False\n assert candidate(n = 789) == False\n assert candidate(n = 579) == False\n assert candidate(n = 273) == True\n assert candidate(n = 327) == True\n assert candidate(n = 192) == True\n assert candidate(n = 369) == False\n assert candidate(n = 258) == False\n assert candidate(n = 932) == False\n assert candidate(n = 100) == False\n assert candidate(n = 819) == False\n assert candidate(n = 735) == False\n assert candidate(n = 342) == False\n assert candidate(n = 269) == False\n assert candidate(n = 135) == False\n assert candidate(n = 729) == False\n assert candidate(n = 639) == False\n assert candidate(n = 657) == False\n assert candidate(n = 846) == False\n assert candidate(n = 964) == False\n assert candidate(n = 402) == False\n assert candidate(n = 123) == False\n assert candidate(n = 396) == False\n assert candidate(n = 300) == False\n assert candidate(n = 854) == False\n assert candidate(n = 852) == False\n assert candidate(n = 439) == False\n assert candidate(n = 673) == False\n assert candidate(n = 384) == False\n assert candidate(n = 621) == False\n assert candidate(n = 270) == False\n assert candidate(n = 471) == False\n assert candidate(n = 741) == False\n assert candidate(n = 594) == False\n assert candidate(n = 783) == False\n assert candidate(n = 186) == False\n assert candidate(n = 654) == False\n assert candidate(n = 873) == False\n assert candidate(n = 297) == False\n assert candidate(n = 927) == False\n assert candidate(n = 725) == False\n assert candidate(n = 999) == False\n assert candidate(n = 294) == False\n assert candidate(n = 519) == False\n assert candidate(n = 518) == False\n assert candidate(n = 140) == False\n assert candidate(n = 513) == False\n assert candidate(n = 504) == False\n assert candidate(n = 693) == False\n assert candidate(n = 843) == False\n assert candidate(n = 918) == False\n assert candidate(n = 534) == False\n assert candidate(n = 624) == False\n assert candidate(n = 183) == False\n assert candidate(n = 753) == False\n assert candidate(n = 486) == False\n assert candidate(n = 243) == False\n assert candidate(n = 924) == False\n", "comparison": "exact"}, "public_tests": ["192", "100"], "hints": ["Consider changing the number to the way it is described in the statement.", "Check if the resulting number contains all the digits from 1 to 9 exactly once."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().isFascinating", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:25+00:00", "tests_total": 60, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "math"]}, "language": "ruby", "interface": {"raw_signature": "def is_fascinating(n)", "container": null, "callable": "is_fascinating", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2730, "task_id": "find-the-longest-semi-repetitive-substring", "difficulty": "Medium", "problem_description": "You are given a digit string s that consists of digits from 0 to 9.\n\nA string is called semi-repetitive if there is at most one adjacent pair of the same digit. For example, \"0010\", \"002020\", \"0123\", \"2002\", and \"54944\" are semi-repetitive while the following are not: \"00101022\" (adjacent same digit pairs are 00 and 22), and \"1101234883\" (adjacent same digit pairs are 11 and 88).\n\nReturn the length of the longest semi-repetitive substring of s.\n\nExample 1:\n\nInput: s = \"52233\"\nOutput: 4\nExplanation:\nThe longest semi-repetitive substring is \"5223\". Picking the whole string \"52233\" has two adjacent same digit pairs 22 and 33, but at most one is allowed.\n\nExample 2:\n\nInput: s = \"5494\"\nOutput: 4\nExplanation:\ns is a semi-repetitive string.\n\nExample 3:\n\nInput: s = \"1111111\"\nOutput: 2\nExplanation:\nThe longest semi-repetitive substring is \"11\". Picking the substring \"111\" has two adjacent same digit pairs, but at most one is allowed.\n\nConstraints:\n\n- 1 <= s.length <= 50\n- '0' <= s[i] <= '9'\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 2\n assert candidate(s = \"9876543210\") == 10\n assert candidate(s = \"111222333\") == 3\n assert candidate(s = \"88888888888\") == 2\n assert candidate(s = \"87878787878787878\") == 17\n assert candidate(s = \"101010101\") == 9\n assert candidate(s = \"10101010101\") == 11\n assert candidate(s = \"0101010\") == 7\n assert candidate(s = \"54944\") == 5\n assert candidate(s = \"122112211\") == 4\n assert candidate(s = \"22222\") == 2\n assert candidate(s = \"1234567890\") == 10\n assert candidate(s = \"0000000\") == 2\n assert candidate(s = \"1001001\") == 5\n assert candidate(s = \"1122334455\") == 4\n assert candidate(s = \"656565656565656\") == 15\n assert candidate(s = \"002020\") == 6\n assert candidate(s = \"0\") == 1\n assert candidate(s = \"52233\") == 4\n assert candidate(s = \"989898989898989898\") == 18\n assert candidate(s = \"4343434343434\") == 13\n assert candidate(s = \"1111111\") == 2\n assert candidate(s = \"323232323232\") == 12\n assert candidate(s = \"0123\") == 4\n assert candidate(s = \"999999999999\") == 2\n assert candidate(s = \"2002\") == 4\n assert candidate(s = \"0010\") == 4\n assert candidate(s = \"666666666\") == 2\n assert candidate(s = \"22\") == 2\n assert candidate(s = \"1010101010\") == 10\n assert candidate(s = \"1221221221\") == 6\n assert candidate(s = \"101010\") == 6\n assert candidate(s = \"9999999999\") == 2\n assert candidate(s = \"0101010101\") == 10\n assert candidate(s = \"333333\") == 2\n assert candidate(s = \"4444444\") == 2\n assert candidate(s = \"55555555\") == 2\n assert candidate(s = \"5494\") == 4\n assert candidate(s = \"1101234883\") == 9\n assert candidate(s = \"7676767676767676\") == 16\n assert candidate(s = \"123212321\") == 9\n assert candidate(s = \"00000\") == 2\n assert candidate(s = \"7777777777\") == 2\n assert candidate(s = \"1221221\") == 5\n assert candidate(s = \"21212121212\") == 11\n assert candidate(s = \"54545454545454\") == 14\n assert candidate(s = \"121212\") == 6\n assert candidate(s = \"9999999999111111111122222222223333333333\") == 3\n assert candidate(s = \"12121212121212121212\") == 20\n assert candidate(s = \"112233445566778899001122334455667788990011\") == 4\n assert candidate(s = \"0011223344556677889900\") == 4\n assert candidate(s = \"12321321321321321321321321321321\") == 32\n assert candidate(s = \"1233211233211233211233211233\") == 6\n assert candidate(s = \"123123123123123123123123123\") == 27\n assert candidate(s = \"123345567890\") == 9\n assert candidate(s = \"12211221122\") == 4\n assert candidate(s = \"55443322110011223344556677889900112233\") == 4\n assert candidate(s = \"5544332211009988776655\") == 4\n assert candidate(s = \"1232123212321232123212321\") == 25\n assert candidate(s = \"12345678901234567890123456789012345678901234567890\") == 50\n assert candidate(s = \"990099009900990099009900990099\") == 4\n assert candidate(s = \"123123123123123123123123123123123123123123123\") == 45\n assert candidate(s = \"12345543211234554321\") == 10\n assert candidate(s = \"000000000000000000000000000000\") == 2\n assert candidate(s = \"9876543210000000000098765432\") == 11\n assert candidate(s = \"98765432101234567890\") == 20\n assert candidate(s = \"12345678900000000000000000000000000000000000\") == 11\n assert candidate(s = \"1123456789009876543211\") == 20\n assert candidate(s = \"123455567890123456789\") == 16\n assert candidate(s = \"1122334455667788990011223344\") == 4\n assert candidate(s = \"987654321098765432109\") == 21\n assert candidate(s = \"987654321012345678909876543210\") == 30\n assert candidate(s = \"9876543210123456789876543210\") == 28\n assert candidate(s = \"123456789012345678901\") == 21\n assert candidate(s = \"101010101010101010101\") == 21\n assert candidate(s = \"12233445566778899123456789\") == 12\n assert candidate(s = \"1223344556677889900\") == 4\n assert candidate(s = \"1234567890987654321012345678909876543210\") == 40\n assert candidate(s = \"111111111111111111112\") == 3\n assert candidate(s = \"101010101010101010101010101010\") == 30\n assert candidate(s = \"112221122211222112221122211222\") == 4\n assert candidate(s = \"888877776666555544443333222211110000\") == 3\n assert candidate(s = \"1234555432123456789987654321\") == 22\n assert candidate(s = \"987654321000000000000000000000000000\") == 11\n assert candidate(s = \"9876543210000000000\") == 11\n assert candidate(s = \"98989898989898989898989898989898989898989898\") == 44\n assert candidate(s = \"11223344556677889900112233\") == 4\n assert candidate(s = \"12312312312312312312\") == 20\n assert candidate(s = \"000000000000000000000\") == 2\n assert candidate(s = \"98765432109876543210987654321098765432109876\") == 44\n assert candidate(s = \"99887766554433221100112233445566778899\") == 4\n assert candidate(s = \"987654321123456788765432112345678\") == 17\n assert candidate(s = \"0101010101010101010101010101010101\") == 34\n assert candidate(s = \"12345554321112345678998765432100\") == 19\n assert candidate(s = \"1123456789012345678901234567890\") == 31\n assert candidate(s = \"000000000011111111112222222222\") == 3\n assert candidate(s = \"121212121212121212121212121212121212\") == 36\n assert candidate(s = \"1234567890123456789012345678901234567890\") == 40\n assert candidate(s = \"543210102030405060708090090807060504030201\") == 42\n assert candidate(s = \"1001001001001001001001001001001\") == 6\n assert candidate(s = \"0000000000000000000000000000000000000000\") == 2\n assert candidate(s = \"123123123123123123123123123123\") == 30\n assert candidate(s = \"012345678987654321012345678987654321\") == 36\n assert candidate(s = \"01234567890123456789\") == 20\n assert candidate(s = \"9876543210012345678998765432100123456789\") == 20\n assert candidate(s = \"99999999999999999999\") == 2\n assert candidate(s = \"012345678901234567890123456789\") == 30\n assert candidate(s = \"11221122112211221122\") == 4\n assert candidate(s = \"10203040506070809000\") == 19\n assert candidate(s = \"11111111111111111111\") == 2\n assert candidate(s = \"55555555555555555559\") == 3\n assert candidate(s = \"11223344556677889900\") == 4\n assert candidate(s = \"1111111111111111111111111111111111111111111111\") == 2\n assert candidate(s = \"001001001001001001001001\") == 6\n assert candidate(s = \"11223344556677889900112233445566\") == 4\n assert candidate(s = \"0000123456789000\") == 12\n assert candidate(s = \"010203040506070809001\") == 21\n assert candidate(s = \"12345678901234567890123456789012\") == 32\n assert candidate(s = \"98989898989898989898\") == 20\n assert candidate(s = \"01234567890123456789012345678901234567890123\") == 44\n assert candidate(s = \"12345678901234567890\") == 20\n assert candidate(s = \"55555555555555555555555555555555555555555555\") == 2\n assert candidate(s = \"1233211233211233211\") == 6\n assert candidate(s = \"9876543210987654321098765432109876543210\") == 40\n assert candidate(s = \"001122334455667788990011223344\") == 4\n assert candidate(s = \"9988776655443322110001122334455\") == 4\n assert candidate(s = \"00112233445566778899001122334455\") == 4\n assert candidate(s = \"98765432109876543210\") == 20\n assert candidate(s = \"5432112345543211234554321123\") == 10\n assert candidate(s = \"22334455667788990011\") == 4\n assert candidate(s = \"000010002000300040005\") == 4\n assert candidate(s = \"123456789098765432109876543210\") == 30\n assert candidate(s = \"9876543219876543219876543219\") == 28\n assert candidate(s = \"1010101010101010101010101010\") == 28\n assert candidate(s = \"122112211221122112211221122112211221\") == 4\n assert candidate(s = \"1234567899999999999999999999999999999999\") == 10\n assert candidate(s = \"01234567898765432101234567890\") == 29\n assert candidate(s = \"98765432100123456789\") == 20\n assert candidate(s = \"111222333444555666777\") == 3\n assert candidate(s = \"12332132123123321321231233213212312332132123\") == 22\n assert candidate(s = \"000000000000000000000000000000000000000000001111\") == 3\n assert candidate(s = \"123455678990123456789012\") == 19\n assert candidate(s = \"1111112111112111112\") == 4\n assert candidate(s = \"123456789987654321123456789987654321\") == 18\n assert candidate(s = \"112233445566778899001122\") == 4\n assert candidate(s = \"12345678900123456789\") == 20\n assert candidate(s = \"000011112222333344445555\") == 3\n assert candidate(s = \"001001001001001001001001001001\") == 6\n assert candidate(s = \"1001001001001001001\") == 6\n assert candidate(s = \"122334455667788990011\") == 4\n assert candidate(s = \"111222333444555666777888999000\") == 3\n assert candidate(s = \"90909090909090909090\") == 20\n assert candidate(s = \"12345678909876543210\") == 20\n assert candidate(s = \"11111111111111111111111111111111111111111111\") == 2\n assert candidate(s = \"0011223344556677889900112233\") == 4\n assert candidate(s = \"12345678909876543210123456789098765432101234\") == 44\n assert candidate(s = \"549444444444444444444\") == 5\n assert candidate(s = \"999999999999999999991\") == 3\n assert candidate(s = \"112233445566778899009900\") == 4\n assert candidate(s = \"9876543210102030405060708090\") == 28\n assert candidate(s = \"121212121212121212121\") == 21\n assert candidate(s = \"1111111111111111111111111111111111111111\") == 2\n assert candidate(s = \"112233445544556677889900112233\") == 4\n assert candidate(s = \"55555555555555555555\") == 2\n assert candidate(s = \"111111222222333333444444555555666666\") == 3\n assert candidate(s = \"00000000000000000000\") == 2\n assert candidate(s = \"10101010101010101010101010101010\") == 32\n assert candidate(s = \"98765432100000000000\") == 11\n assert candidate(s = \"01234567899876543210\") == 20\n assert candidate(s = \"1111222233334444555566667777888899990000\") == 3\n assert candidate(s = \"11222333444555666777888999\") == 3\n assert candidate(s = \"1222222222222222222222222222222222222222\") == 3\n assert candidate(s = \"0101010101010101010101010101010101010101010101\") == 46\n assert candidate(s = \"12345678900987654321001234567890\") == 22\n assert candidate(s = \"999888777666555444333222111000111222333444\") == 3\n assert candidate(s = \"1122334455667788990011223344556677889900\") == 4\n assert candidate(s = \"987654321001234567899\") == 20\n assert candidate(s = \"112233445566778899001122334455\") == 4\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 40\n assert candidate(s = \"123456789001234567890\") == 21\n assert candidate(s = \"00112233445566778899\") == 4\n assert candidate(s = \"44444444444444444444444444444444444444444444\") == 2\n assert candidate(s = \"555555555555555555555555555555555\") == 2\n assert candidate(s = \"01010101010101010101\") == 20\n assert candidate(s = \"111122223333444455556666777788889999\") == 3\n assert candidate(s = \"000111222333444555666\") == 3\n assert candidate(s = \"000000111111222222333333444444555555\") == 3\n assert candidate(s = \"10101010101010101010\") == 20\n assert candidate(s = \"9876543210123456789012345678901234567890\") == 40\n assert candidate(s = \"987654321001234567899876543210\") == 20\n assert candidate(s = \"22223333444455556666777788889999000011112222\") == 3\n assert candidate(s = \"123456789012345678901234567890\") == 30\n assert candidate(s = \"001100110011001100110011001100\") == 4\n assert candidate(s = \"010101010101010101010101010101010101010101010\") == 45\n", "comparison": "exact"}, "public_tests": ["\"52233\"", "\"5494\"", "\"1111111\""], "hints": ["Since n is small, we can just check every substring, and if the substring is semi-repetitive, maximize the answer with its length."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().longestSemiRepetitiveSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:27+00:00", "tests_total": 197, "tests_dropped": 3, "flags": [], "topic_tags": ["string", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def longest_semi_repetitive_substring(s)", "container": null, "callable": "longest_semi_repetitive_substring", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2731, "task_id": "movement-of-robots", "difficulty": "Medium", "problem_description": "Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance each second.\n\nYou are given a string s denoting the direction in which robots will move on command. 'L' means the robot will move towards the left side or negative side of the number line, whereas 'R' means the robot will move towards the right side or positive side of the number line.\n\nIf two robots collide, they will start moving in opposite directions.\n\nReturn the sum of distances between all the pairs of robots d seconds after the command. Since the sum can be very large, return it modulo 10^9 + 7.\n\nNote:\n\n- For two robots at the index i and j, pair (i,j) and pair (j,i) are considered the same pair.\n- When robots collide, they instantly change their directions without wasting any time.\n- Collision happens when two robots share the same place in a moment.\n - For example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.\n - For example, if a robot is positioned in 0 going to the right and another is positioned in 1 going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.\n\nExample 1:\n\nInput: nums = [-2,0,2], s = \"RLL\", d = 3\nOutput: 8\nExplanation:\nAfter 1 second, the positions are [-1,-1,1]. Now, the robot at index 0 will move left, and the robot at index 1 will move right.\nAfter 2 seconds, the positions are [-2,0,0]. Now, the robot at index 1 will move left, and the robot at index 2 will move right.\nAfter 3 seconds, the positions are [-3,-1,1].\nThe distance between the robot at index 0 and 1 is abs(-3 - (-1)) = 2.\nThe distance between the robot at index 0 and 2 is abs(-3 - 1) = 4.\nThe distance between the robot at index 1 and 2 is abs(-1 - 1) = 2.\nThe sum of the pairs of all distances = 2 + 4 + 2 = 8.\n\nExample 2:\n\nInput: nums = [1,0], s = \"RL\", d = 2\nOutput: 5\nExplanation:\nAfter 1 second, the positions are [2,-1].\nAfter 2 seconds, the positions are [3,-2].\nThe distance between the two robots is abs(-2 - 3) = 5.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- -2 * 10^9 <= nums[i] <= 2 * 10^9\n- 0 <= d <= 10^9\n- nums.length == s.length\n- s consists of 'L' and 'R' only\n- nums[i] will be unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 2, -3, 4],s = \"RLRL\",d = 5) == 24\n assert candidate(nums = [-5, 1, 4],s = \"RLR\",d = 4) == 22\n assert candidate(nums = [-5, -1, 0, 3, 7],s = \"RLLLR\",d = 5) == 82\n assert candidate(nums = [-10, -20, -30],s = \"LLL\",d = 1) == 40\n assert candidate(nums = [0, 1, 2, 3, 4],s = \"RRRRR\",d = 1) == 20\n assert candidate(nums = [-2, 0, 2],s = \"RLL\",d = 3) == 8\n assert candidate(nums = [2, -1, 0],s = \"LRR\",d = 5) == 16\n assert candidate(nums = [10, -10, 0],s = \"RLR\",d = 10) == 80\n assert candidate(nums = [-2, 0, 2],s = \"RLL\",d = 3) == 8\n assert candidate(nums = [10, 20, 30],s = \"RRR\",d = 1) == 40\n assert candidate(nums = [-1, 2, -3, 4],s = \"LRRL\",d = 5) == 42\n assert candidate(nums = [10, -10, 0],s = \"RLR\",d = 5) == 60\n assert candidate(nums = [1, 0],s = \"RL\",d = 2) == 5\n assert candidate(nums = [-5, 1, 3],s = \"RRL\",d = 4) == 12\n assert candidate(nums = [1, 0],s = \"RL\",d = 2) == 5\n assert candidate(nums = [0, 0, 0, 0],s = \"RRLL\",d = 1) == 8\n assert candidate(nums = [3, 2, 1],s = \"RRR\",d = 1) == 4\n assert candidate(nums = [10, -10, 20, -20],s = \"RLRL\",d = 10) == 220\n assert candidate(nums = [-10, -5, 0, 5, 10],s = \"RRRLL\",d = 7) == 50\n assert candidate(nums = [1, -1, 2, -2, 3, -3],s = \"RLRLRL\",d = 15) == 314\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],s = \"RLRLRLRLRL\",d = 5) == 165\n assert candidate(nums = [-1, 2, -3, 4, -5],s = \"RLLRL\",d = 3) == 76\n assert candidate(nums = [-10, -5, 0, 5, 10, 15, 20, 25, 30],s = \"LRRLLRRLL\",d = 10) == 680\n assert candidate(nums = [1, 2, 3, 4, 5],s = \"RLRLR\",d = 2) == 34\n assert candidate(nums = [-1000000000, 0, 1000000000],s = \"RLR\",d = 500000000) == 999999979\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],s = \"RRRRRRRRRR\",d = 5) == 165\n assert candidate(nums = [-1000, -800, -600, -400, -200, 200, 400, 600, 800, 1000],s = \"RRRRRRRRRR\",d = 300) == 38000\n assert candidate(nums = [-20, -10, 0, 10, 20],s = \"LRRLL\",d = 15) == 220\n assert candidate(nums = [-10, -5, -1, 0, 1, 5, 10],s = \"LRRLLRR\",d = 7) == 304\n assert candidate(nums = [-1000, -500, 0, 500, 1000],s = \"RLRLR\",d = 500) == 12000\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],s = \"RRRRRRRRRRRRRRRRRRRR\",d = 2) == 1330\n assert candidate(nums = [100, 200, 300, 400, 500],s = \"RRRRR\",d = 1) == 2000\n assert candidate(nums = [-10, -5, 0, 5, 10],s = \"LRLRL\",d = 5) == 120\n assert candidate(nums = [-10, -5, 0, 5, 10],s = \"RLRLR\",d = 7) == 136\n assert candidate(nums = [-10, -5, 0, 5, 10],s = \"RLRRL\",d = 3) == 92\n assert candidate(nums = [-5, 0, 5, 10],s = \"RLRR\",d = 20) == 160\n assert candidate(nums = [-500, -300, -100, 100, 300, 500],s = \"LLRRLR\",d = 10) == 7100\n assert candidate(nums = [-2, -1, 0, 1, 2],s = \"RLRLR\",d = 7) == 94\n assert candidate(nums = [-20, -10, 0, 10, 20, 30, 40, 50, 60, 70],s = \"LRRLLRRLLR\",d = 15) == 1840\n assert candidate(nums = [-50, -25, 0, 25, 50],s = \"LRRRL\",d = 25) == 550\n assert candidate(nums = [-9, -7, -5, -3, -1, 1, 3, 5, 7, 9],s = \"RRRRRRRRRR\",d = 2) == 330\n assert candidate(nums = [-9, -6, -3, 0, 3, 6, 9],s = \"RRRRRRR\",d = 4) == 168\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5],s = \"RLRLRLRLRL\",d = 3) == 80\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],s = \"RRRRRRRRRR\",d = 1) == 165\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18],s = \"LRLRLRLRLR\",d = 5) == 468\n assert candidate(nums = [-20, -15, -10, -5, 0, 5, 10, 15, 20],s = \"RLRLRLRLR\",d = 3) == 608\n assert candidate(nums = [0, 1, 2, 3, 4, 5],s = \"RRRRRR\",d = 10) == 35\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],s = \"RRRRRRRRRL\",d = 1) == 149\n assert candidate(nums = [100, 200, 300, 400, 500],s = \"LLLLL\",d = 50) == 2000\n assert candidate(nums = [100, 101, 102, 103, 104, 105],s = \"LLLLLR\",d = 5) == 85\n assert candidate(nums = [-9, -7, -5, -3, -1],s = \"RRRRR\",d = 6) == 40\n assert candidate(nums = [-50, -20, -10, 0, 10, 20, 50],s = \"LRRLLRR\",d = 10) == 900\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],s = \"RLRLRLRLRL\",d = 20) == 1110\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],s = \"RRRRRRRRRR\",d = 10) == 165\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],s = \"LRLRLRLRLRL\",d = 1) == 230\n assert candidate(nums = [-50, -30, -10, 10, 30, 50],s = \"LLRRLL\",d = 15) == 720\n assert candidate(nums = [-10, -8, -6, -4, -2, 2, 4, 6, 8, 10],s = \"LLLLLLLLLL\",d = 3) == 380\n assert candidate(nums = [-20, -15, -10, -5, 0, 5, 10, 15, 20],s = \"RRRRLLLLL\",d = 3) == 482\n assert candidate(nums = [-100, -200, -300, -400, -500],s = \"LLLLL\",d = 100) == 2000\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4],s = \"RLRLRLRL\",d = 1) == 68\n assert candidate(nums = [1, 3, 5, 7, 9],s = \"LLLLL\",d = 2) == 40\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],s = \"RLRLRLRLRL\",d = 4) == 390\n assert candidate(nums = [-300, -200, -100, 0, 100, 200, 300],s = \"LRRLLRR\",d = 100) == 6600\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],s = \"RRRRRRRRRR\",d = 2) == 165\n assert candidate(nums = [-1000000000, 1000000000],s = \"RL\",d = 1000000000) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],s = \"LLLLL\",d = 5) == 200\n assert candidate(nums = [-10, -5, 0, 5, 10],s = \"RRLRR\",d = 7) == 126\n assert candidate(nums = [-1000, -500, 0, 500, 1000],s = \"RLLRL\",d = 1000) == 14000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],s = \"LLLLLLLLLL\",d = 1) == 330\n assert candidate(nums = [5, 3, 8, 1, 6],s = \"RRLLR\",d = 7) == 98\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],s = \"RRRRRRRRRR\",d = 2) == 165\n assert candidate(nums = [-9, -6, -3, 0, 3, 6, 9],s = \"RLRLRLR\",d = 6) == 234\n assert candidate(nums = [-5, -3, 1, 4, 7],s = \"LRRRL\",d = 2) == 64\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],s = \"RRRRRRRRRRRR\",d = 3) == 286\n assert candidate(nums = [-10, -5, 0, 5, 10, 15, 20],s = \"RRRLLLL\",d = 7) == 146\n assert candidate(nums = [-19, -17, -15, -13, -11, -9, -7, -5, -3, -1],s = \"RRRRRRRRRR\",d = 2) == 330\n assert candidate(nums = [-500000000, -250000000, 0, 250000000, 500000000],s = \"RLLLR\",d = 500000000) == 999999951\n assert candidate(nums = [0, 10, 20, 30, 40],s = \"LLLLL\",d = 5) == 200\n assert candidate(nums = [-500, -300, -100, 100, 300, 500],s = \"RLLRLR\",d = 200) == 8200\n assert candidate(nums = [-1000000000, 1000000000],s = \"LR\",d = 500000000) == 999999986\n assert candidate(nums = [-500, -400, -300, -200, -100],s = \"RRRRR\",d = 100) == 2000\n assert candidate(nums = [5, 10, 15, 20],s = \"RRRR\",d = 5) == 50\n assert candidate(nums = [-100, -50, 0, 50, 100, 150, 200],s = \"RLLRLLR\",d = 150) == 4900\n assert candidate(nums = [-9, -7, -5, -3, -1, 1, 3, 5, 7, 9],s = \"LRLRLRLRLR\",d = 10) == 710\n assert candidate(nums = [-1, 1, -2, 2, -3, 3],s = \"RLRLRL\",d = 5) == 62\n assert candidate(nums = [100, 200, 300, 400, 500],s = \"LLLLL\",d = 10) == 2000\n assert candidate(nums = [-1000000000, 1000000000],s = \"LR\",d = 1000000000) == 999999979\n assert candidate(nums = [-20, -15, -10, -5, 0, 5, 10, 15, 20],s = \"LRRRLRRRL\",d = 7) == 652\n assert candidate(nums = [5, 15, 25, 35, 45],s = \"LRRLL\",d = 10) == 180\n assert candidate(nums = [-50, -20, -10, 0, 10, 20, 50],s = \"LRLRLRL\",d = 30) == 1140\n assert candidate(nums = [-20, -10, 0, 10, 20],s = \"LRLLR\",d = 3) == 212\n assert candidate(nums = [-10, -5, 0, 5, 10, 15],s = \"RLRLRL\",d = 1) == 169\n assert candidate(nums = [100, 200, 300, 400, 500],s = \"RRRRR\",d = 50) == 2000\n assert candidate(nums = [100, 200, 300, 400, 500, 600],s = \"LLLLLR\",d = 150) == 5000\n assert candidate(nums = [-500, -400, -300, -200, -100],s = \"RRRRR\",d = 15) == 2000\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3],s = \"LLRLRLR\",d = 1) == 72\n assert candidate(nums = [-1000000000, 0, 1000000000],s = \"RLR\",d = 1000000000) == 999999965\n assert candidate(nums = [-1000000, 0, 1000000],s = \"RLR\",d = 1000000) == 6000000\n assert candidate(nums = [250, 500, 750, 1000, 1250],s = \"LLLLL\",d = 250) == 5000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],s = \"LLLLLLLLLL\",d = 500) == 16500\n assert candidate(nums = [-25, -15, -5, 5, 15, 25],s = \"RLRRRL\",d = 10) == 350\n", "comparison": "exact"}, "public_tests": ["[-2,0,2]\n\"RLL\"\n3", "[1,0]\n\"RL\"\n2"], "hints": ["Observe that if you ignore collisions, the resultant positions of robots after d seconds would be the same.", "After d seconds, sort the ending positions and use prefix sum to calculate the distance sum."], "metadata": {"canonical_parameter_names": ["nums", "s", "d"], "leetcode_dataset_entry_point": "Solution().sumDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:29+00:00", "tests_total": 110, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "brainteaser", "sorting", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def sum_distance(nums, s, d)", "container": null, "callable": "sum_distance", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "s", "type": "String"}, {"name": "d", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2732, "task_id": "find-a-good-subset-of-the-matrix", "difficulty": "Hard", "problem_description": "You are given a 0-indexed m x n binary matrix grid.\n\nLet us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset.\n\nMore formally, if the length of the chosen subset of rows is k, then the sum of each column should be at most floor(k / 2).\n\nReturn an integer array that contains row indices of a good subset sorted in ascending order.\n\nIf there are multiple good subsets, you can return any of them. If there are no good subsets, return an empty array.\n\nA subset of rows of the matrix grid is any matrix that can be obtained by deleting some (possibly none or all) rows from grid.\n\nExample 1:\n\nInput: grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]]\nOutput: [0,1]\nExplanation: We can choose the 0^th and 1^st rows to create a good subset of rows.\nThe length of the chosen subset is 2.\n- The sum of the 0^th column is 0 + 0 = 0, which is at most half of the length of the subset.\n- The sum of the 1^st column is 1 + 0 = 1, which is at most half of the length of the subset.\n- The sum of the 2^nd column is 1 + 0 = 1, which is at most half of the length of the subset.\n- The sum of the 3^rd column is 0 + 1 = 1, which is at most half of the length of the subset.\n\nExample 2:\n\nInput: grid = [[0]]\nOutput: [0]\nExplanation: We can choose the 0^th row to create a good subset of rows.\nThe length of the chosen subset is 1.\n- The sum of the 0^th column is 0, which is at most half of the length of the subset.\n\nExample 3:\n\nInput: grid = [[1,1,1],[1,1,1]]\nOutput: []\nExplanation: It is impossible to choose any subset of rows to create a good subset.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m <= 10^4\n- 1 <= n <= 5\n- grid[i][j] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]]) == [2, 3]\n assert candidate(grid = [[0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]]) == [0]\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [1, 0, 0]]) == [0]\n assert candidate(grid = [[0, 1, 1, 0], [0, 0, 0, 1], [1, 1, 1, 1]]) == [0, 1]\n assert candidate(grid = [[1, 1, 0], [0, 0, 1], [1, 0, 0]]) == [0, 1]\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 0]]) == [0, 1]\n assert candidate(grid = [[0]]) == [0]\n assert candidate(grid = [[1, 1, 1], [1, 1, 1]]) == []\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == [0]\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == [0, 1]\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == [1, 2]\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]]) == [3, 4]\n assert candidate(grid = [[1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1]]) == [3]\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == [1]\n assert candidate(grid = [[1, 1, 1, 0, 0], [0, 0, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == [0, 1]\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1]]) == [1]\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == [0]\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]]) == [0]\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) == [0, 1]\n assert candidate(grid = [[0, 0, 1, 1, 1], [0, 1, 0, 1, 1], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [1, 1, 1, 1, 1]]) == [2, 3]\n assert candidate(grid = [[0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 0, 1], [1, 1, 0, 0], [1, 0, 1, 0]]) == [0, 3]\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == [0, 4]\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]]) == []\n assert candidate(grid = [[0, 0, 1, 1, 1], [1, 0, 0, 1, 0], [1, 1, 0, 0, 0], [0, 0, 0, 0, 1], [0, 1, 1, 0, 0]]) == [0, 2]\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == [0]\n assert candidate(grid = [[1, 1, 1, 1, 0], [1, 1, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 1], [0, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == []\n assert candidate(grid = [[0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0]]) == [2]\n assert candidate(grid = [[0, 1, 1, 0, 0], [1, 0, 0, 1, 1], [0, 1, 1, 0, 0], [1, 0, 0, 1, 1], [0, 1, 1, 0, 0]]) == [3, 4]\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == [0]\n assert candidate(grid = [[0, 0, 1, 1, 0], [1, 0, 0, 1, 1], [0, 1, 1, 0, 0], [1, 1, 0, 0, 1]]) == [0, 3]\n assert candidate(grid = [[1, 1, 0, 1, 0], [1, 1, 0, 1, 0], [1, 1, 0, 1, 0], [1, 1, 0, 1, 0], [1, 1, 0, 1, 0]]) == []\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0]]) == [1, 2]\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 0, 0, 0], [0, 0, 0, 1, 1]]) == [1, 2]\n assert candidate(grid = [[0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0]]) == [3]\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1]]) == [0, 1]\n assert candidate(grid = [[0, 1, 1, 1, 0], [1, 0, 0, 0, 1], [0, 0, 1, 0, 0], [1, 1, 0, 1, 1]]) == [0, 1]\n assert candidate(grid = [[0, 0, 1, 1, 1], [0, 1, 0, 1, 1], [1, 0, 0, 1, 1], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0]]) == [4]\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]\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == [3]\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == [2, 3]\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]\n assert candidate(grid = [[0, 0, 1, 1, 0], [1, 0, 0, 0, 1], [0, 1, 1, 0, 0], [1, 1, 0, 1, 1]]) == [0, 1]\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) == [0]\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]]) == [4, 5]\n assert candidate(grid = [[1, 1, 1, 1, 0], [0, 0, 0, 0, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 1]]) == [0, 1]\n assert candidate(grid = [[0, 0, 0, 1, 1], [0, 1, 1, 0, 0], [1, 0, 1, 0, 1], [1, 1, 0, 1, 0], [0, 0, 0, 0, 0]]) == [4]\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == [0, 1]\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 1]]) == [4, 5]\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 1]]) == [0, 1]\n assert candidate(grid = [[1, 0, 1, 0, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0]]) == [2]\n assert candidate(grid = [[1, 1, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1], [1, 1, 1, 1, 1]]) == [1, 3]\n assert candidate(grid = [[0, 1, 1, 1, 0], [1, 0, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 0, 1], [1, 1, 1, 1, 0]]) == []\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]) == []\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]\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == [2]\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == []\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == [2, 3]\n assert candidate(grid = [[0, 0, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1]]) == [1, 2]\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 0], [1, 0, 0, 1, 1], [0, 1, 1, 0, 1], [1, 0, 1, 1, 0]]) == [0, 1]\n", "comparison": "exact"}, "public_tests": ["[[0,1,1,0],[0,0,0,1],[1,1,1,1]]", "[[0]]", "[[1,1,1],[1,1,1]]"], "hints": ["It can be proven, that if there exists a good subset of rows then there exists a good subset of rows with the size of either 1 or 2.", "To check if there exists a good subset of rows of size 1, we check if there exists a row containing only zeros, if it does, we return its index as a good subset.", "To check if there exists a good subset of rows of size 2, we iterate over two bit-masks, check if both are presented in the array and if they form a good subset, if they do, return their indices as a good subset."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().goodSubsetofBinaryMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:32+00:00", "tests_total": 86, "tests_dropped": 27, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "bit-manipulation", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def good_subsetof_binary_matrix(grid)", "container": null, "callable": "good_subsetof_binary_matrix", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2733, "task_id": "neither-minimum-nor-maximum", "difficulty": "Easy", "problem_description": "Given an integer array nums containing distinct positive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number.\n\nReturn the selected integer.\n\nExample 1:\n\nInput: nums = [3,2,1,4]\nOutput: 2\nExplanation: In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.\n\nExample 2:\n\nInput: nums = [1,2]\nOutput: -1\nExplanation: Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer.\n\nExample 3:\n\nInput: nums = [2,1,3]\nOutput: 2\nExplanation: Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n- All values in nums are distinct\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == -1\n assert candidate(nums = [1, 3, 2]) == 2\n assert candidate(nums = [9, 5, 6]) == 6\n assert candidate(nums = [9, 11, 10]) == 10\n assert candidate(nums = [1, 2]) == -1\n assert candidate(nums = [7, 8, 9]) == 8\n assert candidate(nums = [100, 1, 50]) == 50\n assert candidate(nums = [5, 3, 4, 1, 2]) == 3\n assert candidate(nums = [2, 1, 3]) == 2\n assert candidate(nums = [5, 10, 3, 8, 1]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50]) == 20\n assert candidate(nums = [7]) == -1\n assert candidate(nums = [5, 1, 4, 3, 2]) == 4\n assert candidate(nums = [3, 2, 1, 4]) == 3\n assert candidate(nums = [7, 8, 9]) == 8\n assert candidate(nums = [42, 24, 36, 12, 60, 72, 48]) == 42\n assert candidate(nums = [2, 1, 3, 5, 4, 6]) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35]) == 10\n assert candidate(nums = [30, 1, 29, 2, 28, 3, 27, 4, 26, 5]) == 29\n assert candidate(nums = [42, 35, 28, 21, 14, 7]) == 35\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94]) == 99\n assert candidate(nums = [60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50]) == 59\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 5\n assert candidate(nums = [1, 100, 50, 75, 25]) == 50\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 8\n assert candidate(nums = [6, 4, 2, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) == 6\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == 3\n assert candidate(nums = [60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == 59\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) == 22\n assert candidate(nums = [5, 10, 15, 20, 25]) == 10\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93]) == 2\n assert candidate(nums = [100, 1, 50, 25, 75, 33, 67, 88, 99, 2]) == 50\n assert candidate(nums = [7, 3, 9, 11, 5]) == 7\n assert candidate(nums = [42]) == -1\n assert candidate(nums = [45, 23, 67, 89, 12, 34, 56, 78, 90, 10, 20]) == 45\n assert candidate(nums = [100]) == -1\n assert candidate(nums = [42, 3, 7, 18, 29, 1]) == 3\n assert candidate(nums = [8, 6, 4, 2, 1, 3, 5, 7, 9, 10]) == 8\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 22\n assert candidate(nums = [100, 1, 50, 25, 75]) == 50\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88]) == 16\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 98\n assert candidate(nums = [4, 1, 3, 2, 5, 7, 6, 8]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 20\n assert candidate(nums = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 12\n assert candidate(nums = [88, 99, 77, 66, 55, 44]) == 88\n assert candidate(nums = [45, 30, 15, 60, 75, 90]) == 45\n assert candidate(nums = [31, 1, 41, 59, 26, 53, 58, 97, 93, 23]) == 31\n assert candidate(nums = [5, 1, 9, 3, 7]) == 5\n assert candidate(nums = [5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [55, 45, 35, 25, 15, 5, 10, 20, 30, 40]) == 45\n assert candidate(nums = [7, 3, 5, 1, 9, 11]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50]) == 20\n assert candidate(nums = [45, 30, 60, 20, 70]) == 45\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 4\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 3\n assert candidate(nums = [5, 3, 7, 1, 9, 11, 13, 15, 17, 19, 21]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 2\n assert candidate(nums = [100, 1, 50, 2, 99]) == 50\n assert candidate(nums = [33, 22, 11, 44, 55, 66, 77, 88, 99]) == 33\n assert candidate(nums = [7, 1, 5, 3, 6, 4]) == 5\n assert candidate(nums = [10, 5, 15, 20, 25]) == 10\n assert candidate(nums = [42, 27, 58, 19, 33, 49, 21]) == 42\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70]) == 20\n assert candidate(nums = [99, 100]) == -1\n assert candidate(nums = [25, 20, 15, 10, 5]) == 20\n assert candidate(nums = [7, 14, 21, 28, 35, 42]) == 14\n assert candidate(nums = [100, 1, 2, 3, 99, 50]) == 2\n assert candidate(nums = [66, 33, 99, 22, 44, 77, 55, 11, 88]) == 66\n assert candidate(nums = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53]) == 34\n assert candidate(nums = [5, 3, 8, 1, 4]) == 5\n assert candidate(nums = [100, 1, 50, 99, 2, 98]) == 50\n assert candidate(nums = [8, 15, 3, 12, 7, 18]) == 8\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 29\n assert candidate(nums = [7, 14, 9, 11, 6, 12]) == 7\n assert candidate(nums = [5, 1, 100, 10, 50, 20, 60, 30, 40, 70, 80, 90]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 10\n assert candidate(nums = [3, 1, 2, 4, 5]) == 3\n assert candidate(nums = [50, 40]) == -1\n assert candidate(nums = [10, 5, 3, 8, 2]) == 5\n assert candidate(nums = [97, 98, 95, 96, 99]) == 97\n assert candidate(nums = [100, 1, 50, 99, 2]) == 50\n assert candidate(nums = [47, 29, 83, 61, 95, 17, 53]) == 47\n", "comparison": "exact"}, "public_tests": ["[3,2,1,4]", "[1,2]", "[2,1,3]"], "hints": ["Find any value in the array that is not the minimum or the maximum value."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findNonMinOrMax", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:34+00:00", "tests_total": 94, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def find_non_min_or_max(nums)", "container": null, "callable": "find_non_min_or_max", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2734, "task_id": "lexicographically-smallest-string-after-substring-operation", "difficulty": "Medium", "problem_description": "Given a string s consisting of lowercase English letters. Perform the following operation:\n\n- Select any non-empty substring then replace every letter of the substring with the preceding letter of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.\n\nReturn the lexicographically smallest string after performing the operation.\n\nExample 1:\n\nInput: s = \"cbabc\"\nOutput: \"baabc\"\nExplanation:\nPerform the operation on the substring starting at index 0, and ending at index 1 inclusive.\n\nExample 2:\n\nInput: s = \"aa\"\nOutput: \"az\"\nExplanation:\nPerform the operation on the last letter.\n\nExample 3:\n\nInput: s = \"acbbc\"\nOutput: \"abaab\"\nExplanation:\nPerform the operation on the substring starting at index 1, and ending at index 4 inclusive.\n\nExample 4:\n\nInput: s = \"leetcode\"\nOutput: \"kddsbncd\"\nExplanation:\nPerform the operation on the entire string.\n\nConstraints:\n\n- 1 <= s.length <= 3 * 10^5\n- s consists of lowercase English letters\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abz\") == \"aay\"\n assert candidate(s = \"azazaz\") == \"ayazaz\"\n assert candidate(s = \"zzzz\") == \"yyyy\"\n assert candidate(s = \"azaza\") == \"ayaza\"\n assert candidate(s = \"acbbc\") == \"abaab\"\n assert candidate(s = \"cbabc\") == \"baabc\"\n assert candidate(s = \"azaz\") == \"ayaz\"\n assert candidate(s = \"z\") == \"y\"\n assert candidate(s = \"aaa\") == \"aaz\"\n assert candidate(s = \"aa\") == \"az\"\n assert candidate(s = \"abcdzxyz\") == \"aabcywxy\"\n assert candidate(s = \"abcd\") == \"aabc\"\n assert candidate(s = \"zzz\") == \"yyy\"\n assert candidate(s = \"leetcode\") == \"kddsbncd\"\n assert candidate(s = \"xyz\") == \"wxy\"\n assert candidate(s = \"mnopqrstuvsxyz\") == \"lmnopqrsturwxy\"\n assert candidate(s = \"zzabcd\") == \"yyabcd\"\n assert candidate(s = \"zazbzczdz\") == \"yazbzczdz\"\n assert candidate(s = \"aaaaaabbbbb\") == \"aaaaaaaaaaa\"\n assert candidate(s = \"abczzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"aabyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\"\n assert candidate(s = \"abxyzmnopqrstu\") == \"aawxylmnopqrst\"\n assert candidate(s = \"aczzzzza\") == \"abyyyyya\"\n assert candidate(s = \"aabbaabbaabb\") == \"aaaaaabbaabb\"\n assert candidate(s = \"aabbaabb\") == \"aaaaaabb\"\n assert candidate(s = \"abcabcabc\") == \"aababcabc\"\n assert candidate(s = \"abracadabra\") == \"aaqacadabra\"\n assert candidate(s = \"aaaaazzzzz\") == \"aaaaayyyyy\"\n assert candidate(s = \"aaaaz\") == \"aaaay\"\n assert candidate(s = \"zaz\") == \"yaz\"\n assert candidate(s = \"cbabczzzz\") == \"baabczzzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\"\n assert candidate(s = \"aaabaaab\") == \"aaaaaaab\"\n assert candidate(s = \"aaaabbbbcccc\") == \"aaaaaaaabbbb\"\n assert candidate(s = \"zzzzzzzzzz\") == \"yyyyyyyyyy\"\n assert candidate(s = \"abcdabcdabcd\") == \"aabcabcdabcd\"\n assert candidate(s = \"zzzzzaa\") == \"yyyyyaa\"\n assert candidate(s = \"zzzzz\") == \"yyyyy\"\n assert candidate(s = \"aaabaaaabaaa\") == \"aaaaaaaabaaa\"\n assert candidate(s = \"zzyyzzyyzzyy\") == \"yyxxyyxxyyxx\"\n assert candidate(s = \"aaaabaaa\") == \"aaaaaaaa\"\n assert candidate(s = \"xyzyxzyzyxzyz\") == \"wxyxwyxyxwyxy\"\n assert candidate(s = \"leetcodeisfun\") == \"kddsbncdhretm\"\n assert candidate(s = \"aaaaaaaabczzzzzzzz\") == \"aaaaaaaaabyyyyyyyy\"\n assert candidate(s = \"babababababababab\") == \"aabababababababab\"\n assert candidate(s = \"zaa\") == \"yaa\"\n assert candidate(s = \"mnopqrstu\") == \"lmnopqrst\"\n assert candidate(s = \"aaaaaz\") == \"aaaaay\"\n assert candidate(s = \"abacabad\") == \"aaacabad\"\n assert candidate(s = \"leetcodez\") == \"kddsbncdy\"\n assert candidate(s = \"zabz\") == \"yabz\"\n assert candidate(s = \"abzab\") == \"aayab\"\n assert candidate(s = \"aaaaaaaaaaaaaaaaaa\") == \"aaaaaaaaaaaaaaaaaz\"\n assert candidate(s = \"azz\") == \"ayy\"\n assert candidate(s = \"qwertypoiuytrewq\") == \"pvdqsxonhtxsqdvp\"\n assert candidate(s = \"aabbccdd\") == \"aaaabbcc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabc\") == \"aabcdefghijklmnopqrstuvwxyabc\"\n assert candidate(s = \"zzabc\") == \"yyabc\"\n assert candidate(s = \"zzzzza\") == \"yyyyya\"\n assert candidate(s = \"abczzzzabc\") == \"aabyyyyabc\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzz\") == \"yyyyyyyyyyyyyyyyyyyyyyyy\"\n assert candidate(s = \"abzabzabz\") == \"aayabzabz\"\n assert candidate(s = \"azzzzzz\") == \"ayyyyyy\"\n assert candidate(s = \"hellozworld\") == \"gdkknyvnqkc\"\n assert candidate(s = \"abacabadabacaba\") == \"aaacabadabacaba\"\n assert candidate(s = \"abcxyzzyxabc\") == \"aabwxyyxwabc\"\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxyz\") == \"yabcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == \"yyyyyyyyyyyyyyyyyyyy\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\"\n assert candidate(s = \"aaaabczzzz\") == \"aaaaabyyyy\"\n assert candidate(s = \"abcdz\") == \"aabcy\"\n assert candidate(s = \"aabbccddeeffgg\") == \"aaaabbccddeeff\"\n assert candidate(s = \"bbbb\") == \"aaaa\"\n assert candidate(s = \"abcdefghij\") == \"aabcdefghi\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aaaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy\"\n assert candidate(s = \"aaaazzzz\") == \"aaaayyyy\"\n assert candidate(s = \"bababababab\") == \"aababababab\"\n assert candidate(s = \"abcxyzabc\") == \"aabwxyabc\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == \"yxwvutsrqponmlkjihgfedcbaa\"\n assert candidate(s = \"abcdefg\") == \"aabcdef\"\n assert candidate(s = \"baaaaaaaaaa\") == \"aaaaaaaaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"aabcdefghijklmnopqrstuvwxy\"\n assert candidate(s = \"xyzabcdefghijklmnopqrstu\") == \"wxyabcdefghijklmnopqrstu\"\n assert candidate(s = \"abzzz\") == \"aayyy\"\n assert candidate(s = \"abcxyz\") == \"aabwxy\"\n assert candidate(s = \"abczyx\") == \"aabyxw\"\n assert candidate(s = \"zabxyzmnopqrstu\") == \"yabxyzmnopqrstu\"\n assert candidate(s = \"aaaab\") == \"aaaaa\"\n assert candidate(s = \"zzzzzyyyy\") == \"yyyyyxxxx\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == \"aabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"abcz\") == \"aaby\"\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaa\") == \"aaaaaaaaaaaaaaaaaaaaaaaaz\"\n assert candidate(s = \"zzzabzzz\") == \"yyyabzzz\"\n assert candidate(s = \"xyzaabbcc\") == \"wxyaabbcc\"\n assert candidate(s = \"mississippi\") == \"lhrrhrrhooh\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == \"yxwvutsrqponmlkjihgfedcbaazyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"abcabcabcabcabc\") == \"aababcabcabcabc\"\n assert candidate(s = \"baaaa\") == \"aaaaa\"\n assert candidate(s = \"zzzzzzzz\") == \"yyyyyyyy\"\n assert candidate(s = \"aaaazzzzzzzzzz\") == \"aaaayyyyyyyyyy\"\n assert candidate(s = \"zyxzyxzyxzyx\") == \"yxwyxwyxwyxw\"\n", "comparison": "exact"}, "public_tests": ["\"cbabc\"", "\"aa\"", "\"acbbc\"", "\"leetcode\""], "hints": ["When a character is replaced by the one that comes before it on the alphabet, it makes the string lexicographically smaller, except for ‘a'.", "Find the leftmost substring that doesn’t contain the character 'a' and change all characters in it."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().smallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:36+00:00", "tests_total": 102, "tests_dropped": 1, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def smallest_string(s)", "container": null, "callable": "smallest_string", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2735, "task_id": "collecting-chocolates", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i is nums[i]. Each chocolate is of a different type, and initially, the chocolate at the index i is of i^th type.\n\nIn one operation, you can do the following with an incurred cost of x:\n\n- Simultaneously change the chocolate of i^th type to ((i + 1) mod n)^th type for all chocolates.\n\nReturn the minimum cost to collect chocolates of all types, given that you can perform as many operations as you would like.\n\nExample 1:\n\nInput: nums = [20,1,15], x = 5\nOutput: 13\nExplanation: Initially, the chocolate types are [0,1,2]. We will buy the 1^st type of chocolate at a cost of 1.\nNow, we will perform the operation at a cost of 5, and the types of chocolates will become [1,2,0]. We will buy the 2^ndtype of chocolate at a cost of 1.\nNow, we will again perform the operation at a cost of 5, and the chocolate types will become [2,0,1]. We will buy the 0^thtype of chocolate at a cost of 1.\nThus, the total cost will become (1 + 5 + 1 + 5 + 1) = 13. We can prove that this is optimal.\n\nExample 2:\n\nInput: nums = [1,2,3], x = 4\nOutput: 6\nExplanation: We will collect all three types of chocolates at their own price without performing any operations. Therefore, the total cost is 1 + 2 + 3 = 6.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^9\n- 1 <= x <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],x = 10) == 90\n assert candidate(nums = [10, 20, 30, 40],x = 10) == 70\n assert candidate(nums = [1, 1, 1, 1, 1],x = 1) == 5\n assert candidate(nums = [7, 7, 7, 7, 7, 7],x = 2) == 42\n assert candidate(nums = [10, 20, 30, 40, 50],x = 1) == 54\n assert candidate(nums = [3, 1, 2],x = 3) == 6\n assert candidate(nums = [100, 200, 300],x = 50) == 400\n assert candidate(nums = [1, 2, 3],x = 4) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 1) == 10\n assert candidate(nums = [1000000000, 1000000000, 1000000000],x = 1000000000) == 3000000000\n assert candidate(nums = [1],x = 100) == 1\n assert candidate(nums = [5, 5, 5, 5],x = 10) == 20\n assert candidate(nums = [1, 3, 5, 7, 9],x = 2) == 13\n assert candidate(nums = [20, 1, 15],x = 5) == 13\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 10) == 45\n assert candidate(nums = [5, 5, 5, 5],x = 1) == 20\n assert candidate(nums = [10, 20, 30, 40],x = 5) == 55\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],x = 1) == 21\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],x = 30) == 540\n assert candidate(nums = [100, 200, 300, 400, 500],x = 500) == 1500\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 10) == 190\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 3) == 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],x = 1) == 39\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 100) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 2) == 27\n assert candidate(nums = [5, 8, 6, 3, 4, 7, 2, 9, 1],x = 3) == 26\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31],x = 10) == 100\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 100) == 10\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 8, 9, 10],x = 10) == 55\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3],x = 7) == 52\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],x = 2) == 70\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 5) == 75\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],x = 20) == 200\n assert candidate(nums = [1000000000, 1000000000, 1000000000],x = 1000000000) == 3000000000\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6],x = 15) == 55\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 2) == 28\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 100) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],x = 3) == 62\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5) == 45\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 1) == 10\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1],x = 500000000) == 500000005\n assert candidate(nums = [10, 20, 30, 40, 50],x = 15) == 105\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000],x = 500000000) == 1000000005\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 5) == 105\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],x = 5) == 96\n assert candidate(nums = [7, 8, 9, 10, 11, 7, 8, 9, 10, 11],x = 2) == 78\n assert candidate(nums = [100, 200, 150, 100, 50],x = 75) == 500\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 7) == 92\n assert candidate(nums = [3, 1, 2, 1, 3, 1, 2, 1, 3, 1],x = 1) == 11\n assert candidate(nums = [1, 10, 100, 1000, 10000],x = 1000) == 2112\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 3) == 34\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],x = 100000000) == 100000010\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 1) == 17\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],x = 2) == 24\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],x = 25) == 525\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 16, 17, 18, 19, 20],x = 10) == 165\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],x = 1) == 10000\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8],x = 2) == 23\n assert candidate(nums = [5, 9, 3, 8, 2, 7, 4, 6, 1],x = 10) == 35\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],x = 7) == 34\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 25) == 305\n assert candidate(nums = [29, 10, 6, 3, 5, 30, 50, 100, 3, 8, 9, 12, 15, 16, 20, 23, 25, 28, 30, 32],x = 15) == 220\n assert candidate(nums = [1, 3, 2, 4, 5],x = 10) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 1) == 20\n assert candidate(nums = [7, 8, 9, 1, 2, 3, 4, 5, 6],x = 3) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 10) == 190\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 1) == 17\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],x = 500000000) == 4000000000\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7],x = 8) == 56\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 500) == 4500\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 15) == 55\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],x = 7) == 248\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 5) == 145\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],x = 7) == 34\n assert candidate(nums = [10, 20, 30, 40, 50],x = 7) == 78\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 5) == 145\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 5) == 51\n assert candidate(nums = [5, 4, 3, 2, 1],x = 1) == 9\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],x = 1000000000) == 4000000000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],x = 10) == 135\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 10) == 80\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],x = 100000000) == 100000010\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],x = 3) == 140\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 10) == 45\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 50) == 1450\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 2) == 27\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 100) == 100\n assert candidate(nums = [3, 2, 1, 4, 5],x = 2) == 12\n assert candidate(nums = [10, 1, 10, 1, 10],x = 5) == 15\n assert candidate(nums = [10, 10, 1, 10, 10],x = 2) == 13\n assert candidate(nums = [50, 40, 30, 20, 10, 100, 90, 80, 70, 60],x = 15) == 230\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],x = 20) == 231\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000],x = 50000) == 61112\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 100) == 1900\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10],x = 1) == 19\n assert candidate(nums = [1000000000, 1000000000, 1000000000],x = 500000000) == 3000000000\n assert candidate(nums = [10, 20, 30, 40, 50],x = 5) == 70\n", "comparison": "exact"}, "public_tests": ["[20,1,15]\n5", "[1,2,3]\n4"], "hints": ["How many maximum rotations will be needed?", "The array will be rotated for a max of N times, so try all possibilities as N = 1000."], "metadata": {"canonical_parameter_names": ["nums", "x"], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:39+00:00", "tests_total": 100, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def min_cost(nums, x)", "container": null, "callable": "min_cost", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2736, "task_id": "maximum-sum-queries", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [x_i, y_i].\n\nFor the i^th query, find the maximum value of nums1[j] + nums2[j] among all indices j (0 <= j < n), where nums1[j] >= x_i and nums2[j] >= y_i, or -1 if there is no j satisfying the constraints.\n\nReturn an array answer where answer[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]]\nOutput: [6,10,7]\nExplanation:\nFor the 1st query x_i = 4 and y_i = 1, we can select index j = 0 since nums1[j] >= 4 and nums2[j] >= 1. The sum nums1[j] + nums2[j] is 6, and we can show that 6 is the maximum we can obtain.\n\nFor the 2nd query x_i = 1 and y_i = 3, we can select index j = 2 since nums1[j] >= 1 and nums2[j] >= 3. The sum nums1[j] + nums2[j] is 10, and we can show that 10 is the maximum we can obtain.\n\nFor the 3rd query x_i = 2 and y_i = 5, we can select index j = 3 since nums1[j] >= 2 and nums2[j] >= 5. The sum nums1[j] + nums2[j] is 7, and we can show that 7 is the maximum we can obtain.\n\nTherefore, we return [6,10,7].\n\nExample 2:\n\nInput: nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]]\nOutput: [9,9,9]\nExplanation: For this example, we can use index j = 2 for all the queries since it satisfies the constraints for each query.\n\nExample 3:\n\nInput: nums1 = [2,1], nums2 = [2,3], queries = [[3,3]]\nOutput: [-1]\nExplanation: There is one query in this example with x_i = 3 and y_i = 3. For every index, j, either nums1[j] < x_i or nums2[j] < y_i. Hence, there is no solution.\n\nConstraints:\n\n- nums1.length == nums2.length\n- n == nums1.length\n- 1 <= n <= 10^5\n- 1 <= nums1[i], nums2[i] <= 10^9\n- 1 <= queries.length <= 10^5\n- queries[i].length == 2\n- x_i == queries[i][1]\n- y_i == queries[i][2]\n- 1 <= x_i, y_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [4, 3, 1, 2],nums2 = [2, 4, 9, 5],queries = [[4, 1], [1, 3], [2, 5]]) == [6, 10, 7]\n assert candidate(nums1 = [2, 1],nums2 = [2, 3],queries = [[3, 3]]) == [-1]\n assert candidate(nums1 = [3, 2, 5],nums2 = [2, 3, 4],queries = [[4, 4], [3, 2], [1, 1]]) == [9, 9, 9]\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000],nums2 = [1000000000, 1000000000, 1000000000],queries = [[1000000000, 1000000000], [999999999, 999999999]]) == [2000000000, 2000000000]\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [2, -1, -1, -1, -1]\n assert candidate(nums1 = [9, 18, 27, 36, 45],nums2 = [45, 36, 27, 18, 9],queries = [[15, 30], [18, 18], [21, 24], [24, 21], [30, 15]]) == [54, 54, 54, 54, 54]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [10, 20, 30, 40, 50],queries = [[150, 15], [250, 25], [350, 35], [450, 45], [550, 55]]) == [550, 550, 550, 550, -1]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [10, 20, 30, 40, 50],queries = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55]]) == [100, 100, 100, 100, 100, 100, 100, 100, 100, -1]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[15, 85], [25, 75], [35, 65], [45, 55], [55, 45], [65, 35], [75, 25], [85, 15]]) == [110, 110, 110, 110, 110, 110, 110, 110]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[15, 35], [25, 25], [35, 15], [45, 5], [55, 55]]) == [60, 60, 60, 60, -1]\n assert candidate(nums1 = [500, 400, 300, 200, 100],nums2 = [100, 200, 300, 400, 500],queries = [[150, 350], [250, 250], [350, 150], [450, 50], [550, 500]]) == [600, 600, 600, 600, -1]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 15], [2, 14], [3, 13], [4, 12], [5, 11], [6, 10], [7, 9], [8, 8], [9, 7], [10, 6], [11, 5], [12, 4], [13, 3], [14, 2], [15, 1]]) == [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]\n assert candidate(nums1 = [1000000000, 999999999, 999999998, 999999997, 999999996],nums2 = [1, 2, 3, 4, 5],queries = [[999999999, 1], [999999998, 2], [999999997, 3], [999999996, 4], [999999995, 5]]) == [1000000001, 1000000001, 1000000001, 1000000001, 1000000001]\n assert candidate(nums1 = [5, 8, 12, 16, 20],nums2 = [20, 16, 12, 8, 5],queries = [[10, 10], [15, 5], [5, 20], [8, 12]]) == [24, 25, 25, 24]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],queries = [[2, 18], [18, 2], [10, 10], [5, 15], [15, 5]]) == [-1, -1, -1, 20, 20]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],queries = [[5, 5], [6, 5], [5, 6], [4, 4]]) == [10, -1, -1, 10]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(nums1 = [1, 10, 100, 1000, 10000],nums2 = [10000, 1000, 100, 10, 1],queries = [[1, 10000], [10, 1000], [100, 100], [1000, 10], [10000, 1]]) == [10001, 1010, 200, 1010, 10001]\n assert candidate(nums1 = [500000, 400000, 300000, 200000, 100000],nums2 = [1, 2, 3, 4, 5],queries = [[400000, 2], [500000, 5], [300000, 3], [100000, 1]]) == [400002, -1, 300003, 500001]\n assert candidate(nums1 = [10, 10, 10, 10, 10],nums2 = [10, 10, 10, 10, 10],queries = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25]]) == [20, 20, -1, -1, -1]\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000],nums2 = [1000000000, 1000000000, 1000000000],queries = [[1000000000, 1000000000], [500000000, 500000000], [1000000000, 999999999]]) == [2000000000, 2000000000, 2000000000]\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000, 1000000000],nums2 = [1000000000, 1000000000, 1000000000, 1000000000],queries = [[1000000000, 1000000000], [1, 1]]) == [2000000000, 2000000000]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2],queries = [[1, 20], [3, 18], [5, 16], [7, 14], [9, 12], [11, 10], [13, 8], [15, 6], [17, 4], [19, 2]]) == [21, 21, 21, 21, 21, 21, 21, 21, 21, 21]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],queries = [[5, 5], [5, 4], [4, 5], [4, 4], [3, 3]]) == [10, 10, 10, 10, 10]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[15, 35], [25, 25], [35, 15], [5, 45], [45, 5], [10, 50], [50, 10]]) == [60, 60, 60, 60, 60, 60, 60]\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums1 = [1000000000, 500000000, 250000000],nums2 = [250000000, 500000000, 1000000000],queries = [[500000000, 250000000], [250000000, 500000000], [750000000, 750000000]]) == [1250000000, 1250000000, -1]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[10, 50], [30, 30], [25, 25], [45, 5], [55, 55]]) == [60, 60, 60, 60, -1]\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],queries = [[500, 500], [150, 850], [950, 50], [200, 700], [400, 600]]) == [1100, 1100, 1100, 1100, 1100]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],queries = [[5, 5], [5, 6], [6, 5], [4, 4], [6, 6]]) == [10, -1, -1, 10, -1]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 10], [10, 1], [5, 5], [3, 7], [7, 3]]) == [11, 11, 11, 11, 11]\n assert candidate(nums1 = [1000000000, 999999999, 1, 2, 3],nums2 = [3, 4, 1000000000, 5, 6],queries = [[999999999, 2], [1, 3], [5, 4], [1000000000, 1000000000]]) == [1000000003, 1000000003, 1000000003, -1]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],queries = [[10, 5], [25, 15], [30, 25], [45, 35], [55, 50]]) == [95, 95, 95, 95, -1]\n assert candidate(nums1 = [1000000000, 999999999, 999999998, 999999997, 999999996],nums2 = [999999996, 999999997, 999999998, 999999999, 1000000000],queries = [[999999997, 999999998], [999999998, 999999999], [1000000000, 1000000000], [999999995, 999999995], [999999996, 999999997]]) == [1999999996, -1, -1, 1999999996, 1999999996]\n assert candidate(nums1 = [1, 5, 7, 9, 11, 13],nums2 = [15, 13, 11, 9, 7, 5],queries = [[1, 15], [7, 9], [10, 10], [12, 12], [14, 14], [16, 16]]) == [16, 18, -1, -1, -1, -1]\n assert candidate(nums1 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[100, 1], [90, 2], [80, 3], [70, 4], [60, 5], [50, 6], [40, 7], [30, 8], [20, 9], [10, 10]]) == [101, 92, 83, 74, 65, 56, 47, 38, 29, 20]\n assert candidate(nums1 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],nums2 = [30, 27, 24, 21, 18, 15, 12, 9, 6, 3],queries = [[3, 30], [6, 27], [9, 24], [12, 21], [15, 18], [18, 15], [21, 12], [24, 9], [27, 6], [30, 3]]) == [33, 33, 33, 33, 33, 33, 33, 33, 33, 33]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[15, 35], [25, 25], [35, 15], [45, 5]]) == [60, 60, 60, 60]\n assert candidate(nums1 = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[500, 1], [500, 2], [500, 3], [500, 4], [500, 5], [500, 6], [500, 7], [500, 8], [500, 9], [500, 10]]) == [510, 510, 510, 510, 510, 510, 510, 510, 510, 510]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[15, 45], [25, 25], [35, 15], [5, 50]]) == [-1, 60, 60, 60]\n assert candidate(nums1 = [5, 15, 25, 35, 45],nums2 = [45, 35, 25, 15, 5],queries = [[5, 45], [15, 35], [25, 25], [35, 15], [45, 5]]) == [50, 50, 50, 50, 50]\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [1, 10]]) == [11, 11, 11, 11, 11, 11, 11]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[5, 6], [6, 5], [4, 7], [7, 4], [3, 8], [8, 3], [2, 9], [9, 2], [1, 10], [10, 1]]) == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(nums1 = [500, 400, 300, 200, 100],nums2 = [100, 200, 300, 400, 500],queries = [[300, 200], [200, 300], [400, 100], [100, 400], [250, 250]]) == [600, 600, 600, 600, 600]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[5, 6], [6, 5], [7, 4], [4, 7], [8, 3], [3, 8], [9, 2], [2, 9], [10, 1], [1, 10]]) == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],queries = [[100, 1000], [200, 900], [300, 800], [400, 700], [500, 600], [600, 500], [700, 400], [800, 300], [900, 200], [1000, 100]]) == [1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100]\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [5000, 4000, 3000, 2000, 1000],queries = [[1500, 4500], [2500, 3500], [3500, 2500], [4500, 1500]]) == [-1, -1, -1, -1]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[10, 100], [20, 90], [30, 80], [40, 70], [50, 60], [60, 50], [70, 40], [80, 30], [90, 20], [100, 10]]) == [110, 110, 110, 110, 110, 110, 110, 110, 110, 110]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[5, 6], [6, 5], [1, 10], [10, 1], [3, 8], [8, 3], [2, 9], [9, 2]]) == [11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(nums1 = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10],nums2 = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [17, 17, 17, 17, 17, 17, 17, 17, -1, -1]\n assert candidate(nums1 = [5, 8, 3, 9, 2],nums2 = [6, 4, 10, 1, 7],queries = [[3, 4], [6, 6], [2, 8], [9, 1], [7, 7], [5, 5]]) == [13, -1, 13, 10, -1, 11]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[15, 45], [25, 25], [35, 15], [45, 5], [55, 55]]) == [-1, 60, 60, 60, -1]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100],queries = [[150, 450], [250, 350], [350, 250], [450, 150], [550, 50]]) == [-1, -1, -1, -1, -1]\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6],queries = [[1, 11], [1, 10], [1, 9], [1, 8], [1, 7]]) == [-1, 11, 11, 11, 11]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10],queries = [[55, 5], [5, 55], [25, 25], [35, 15], [15, 35]]) == [-1, -1, 60, 60, 60]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],queries = [[5, 5], [6, 5], [5, 6], [4, 4], [6, 6]]) == [10, -1, -1, 10, -1]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [2, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],queries = [[10, 10], [20, 20], [1, 1], [19, 1], [1, 19]]) == [-1, -1, 20, 20, 20]\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [2, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums1 = [1, 10, 100, 1000, 10000],nums2 = [10000, 1000, 100, 10, 1],queries = [[5000, 5000], [500, 500], [50, 50], [5, 5], [1, 1]]) == [-1, -1, 200, 1010, 10001]\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[5, 5], [1, 10], [10, 1], [6, 4], [4, 6]]) == [11, 11, 11, 11, 11]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]]) == [110, 110, 110, 110, 110, 110, 110, 110, 110, 110]\n", "comparison": "exact"}, "public_tests": ["[4,3,1,2]\n[2,4,9,5]\n[[4,1],[1,3],[2,5]]", "[3,2,5]\n[2,3,4]\n[[4,4],[3,2],[1,1]]", "[2,1]\n[2,3]\n[[3,3]]"], "hints": ["Sort (x, y) tuples and queries by x-coordinate descending. Don’t forget to index queries before sorting so that you can answer them in the correct order.", "Before answering a query (min_x, min_y), add all (x, y) pairs with x >= min_x to some data structure.", "Use a monotone descending map to store (y, x + y) pairs. A monotone map has ascending keys and descending values. When inserting a pair (y, x + y), remove all pairs (y', x' + y') with y' < y and x' + y' <= x + y.", "To find the insertion position use binary search (built-in in many languages).", "When querying for max (x + y) over y >= y', use binary search to find the first pair (y, x + y) with y >= y'. It will have the maximum value of x + y because the map has monotone descending values."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "queries"], "leetcode_dataset_entry_point": "Solution().maximumSumQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:41+00:00", "tests_total": 78, "tests_dropped": 14, "flags": [], "topic_tags": ["array", "binary-search", "stack", "binary-indexed-tree", "segment-tree", "sorting", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_sum_queries(nums1, nums2, queries)", "container": null, "callable": "maximum_sum_queries", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2739, "task_id": "total-distance-traveled", "difficulty": "Easy", "problem_description": "A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters.\n\nThe truck has a mileage of 10 km per liter. Whenever 5 liters of fuel get used up in the main tank, if the additional tank has at least 1 liters of fuel, 1 liters of fuel will be transferred from the additional tank to the main tank.\n\nReturn the maximum distance which can be traveled.\n\nNote: Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.\n\nExample 1:\n\nInput: mainTank = 5, additionalTank = 10\nOutput: 60\nExplanation:\nAfter spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.\nAfter spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.\nTotal distance traveled is 60km.\n\nExample 2:\n\nInput: mainTank = 1, additionalTank = 2\nOutput: 10\nExplanation:\nAfter spending 1 litre of fuel, the main tank becomes empty.\nTotal distance traveled is 10km.\n\nConstraints:\n\n- 1 <= mainTank, additionalTank <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mainTank = 100,additionalTank = 100) == 1240\n assert candidate(mainTank = 5,additionalTank = 10) == 60\n assert candidate(mainTank = 7,additionalTank = 3) == 80\n assert candidate(mainTank = 1,additionalTank = 2) == 10\n assert candidate(mainTank = 10,additionalTank = 5) == 120\n assert candidate(mainTank = 20,additionalTank = 20) == 240\n assert candidate(mainTank = 45,additionalTank = 5) == 500\n assert candidate(mainTank = 80,additionalTank = 10) == 900\n assert candidate(mainTank = 15,additionalTank = 1) == 160\n assert candidate(mainTank = 1,additionalTank = 50) == 10\n assert candidate(mainTank = 3,additionalTank = 20) == 30\n assert candidate(mainTank = 50,additionalTank = 50) == 620\n assert candidate(mainTank = 25,additionalTank = 30) == 310\n assert candidate(mainTank = 25,additionalTank = 10) == 310\n assert candidate(mainTank = 5,additionalTank = 25) == 60\n assert candidate(mainTank = 80,additionalTank = 20) == 990\n assert candidate(mainTank = 30,additionalTank = 3) == 330\n assert candidate(mainTank = 50,additionalTank = 15) == 620\n assert candidate(mainTank = 49,additionalTank = 5) == 540\n assert candidate(mainTank = 45,additionalTank = 50) == 560\n assert candidate(mainTank = 3,additionalTank = 4) == 30\n assert candidate(mainTank = 30,additionalTank = 30) == 370\n assert candidate(mainTank = 7,additionalTank = 1) == 80\n assert candidate(mainTank = 99,additionalTank = 99) == 1230\n assert candidate(mainTank = 75,additionalTank = 15) == 900\n assert candidate(mainTank = 9,additionalTank = 3) == 110\n assert candidate(mainTank = 60,additionalTank = 30) == 740\n assert candidate(mainTank = 9,additionalTank = 2) == 110\n assert candidate(mainTank = 15,additionalTank = 2) == 170\n assert candidate(mainTank = 50,additionalTank = 10) == 600\n assert candidate(mainTank = 75,additionalTank = 20) == 930\n assert candidate(mainTank = 5,additionalTank = 50) == 60\n assert candidate(mainTank = 8,additionalTank = 1) == 90\n assert candidate(mainTank = 99,additionalTank = 1) == 1000\n assert candidate(mainTank = 30,additionalTank = 8) == 370\n assert candidate(mainTank = 40,additionalTank = 30) == 490\n assert candidate(mainTank = 10,additionalTank = 99) == 120\n assert candidate(mainTank = 80,additionalTank = 3) == 830\n assert candidate(mainTank = 3,additionalTank = 7) == 30\n assert candidate(mainTank = 9,additionalTank = 10) == 110\n assert candidate(mainTank = 75,additionalTank = 25) == 930\n assert candidate(mainTank = 49,additionalTank = 10) == 590\n assert candidate(mainTank = 75,additionalTank = 30) == 930\n assert candidate(mainTank = 24,additionalTank = 6) == 290\n assert candidate(mainTank = 45,additionalTank = 30) == 560\n assert candidate(mainTank = 99,additionalTank = 100) == 1230\n assert candidate(mainTank = 25,additionalTank = 5) == 300\n assert candidate(mainTank = 45,additionalTank = 10) == 550\n assert candidate(mainTank = 80,additionalTank = 8) == 880\n assert candidate(mainTank = 49,additionalTank = 2) == 510\n assert candidate(mainTank = 50,additionalTank = 25) == 620\n assert candidate(mainTank = 30,additionalTank = 15) == 370\n assert candidate(mainTank = 100,additionalTank = 1) == 1010\n assert candidate(mainTank = 25,additionalTank = 25) == 310\n assert candidate(mainTank = 25,additionalTank = 15) == 310\n assert candidate(mainTank = 60,additionalTank = 25) == 740\n assert candidate(mainTank = 8,additionalTank = 7) == 90\n assert candidate(mainTank = 5,additionalTank = 20) == 60\n assert candidate(mainTank = 2,additionalTank = 10) == 20\n assert candidate(mainTank = 5,additionalTank = 5) == 60\n assert candidate(mainTank = 30,additionalTank = 10) == 370\n assert candidate(mainTank = 8,additionalTank = 3) == 90\n assert candidate(mainTank = 60,additionalTank = 15) == 740\n assert candidate(mainTank = 10,additionalTank = 9) == 120\n assert candidate(mainTank = 5,additionalTank = 4) == 60\n assert candidate(mainTank = 4,additionalTank = 5) == 40\n", "comparison": "exact"}, "public_tests": ["5\n10", "1\n2"], "hints": ["Avoid calculations in decimal to prevent precision errors."], "metadata": {"canonical_parameter_names": ["mainTank", "additionalTank"], "leetcode_dataset_entry_point": "Solution().distanceTraveled", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:46+00:00", "tests_total": 79, "tests_dropped": 13, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def distance_traveled(main_tank, additional_tank)", "container": null, "callable": "distance_traveled", "parameters": [{"name": "main_tank", "type": "Integer"}, {"name": "additional_tank", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2740, "task_id": "find-the-value-of-the-partition", "difficulty": "Medium", "problem_description": "You are given a positive integer array nums.\n\nPartition nums into two arrays, nums1 and nums2, such that:\n\n- Each element of the array nums belongs to either the array nums1 or the array nums2.\n- Both arrays are non-empty.\n- The value of the partition is minimized.\n\nThe value of the partition is |max(nums1) - min(nums2)|.\n\nHere, max(nums1) denotes the maximum element of the array nums1, and min(nums2) denotes the minimum element of the array nums2.\n\nReturn the integer denoting the value of such partition.\n\nExample 1:\n\nInput: nums = [1,3,2,4]\nOutput: 1\nExplanation: We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].\n- The maximum element of the array nums1 is equal to 2.\n- The minimum element of the array nums2 is equal to 3.\nThe value of the partition is |2 - 3| = 1.\nIt can be proven that 1 is the minimum value out of all partitions.\n\nExample 2:\n\nInput: nums = [100,1,10]\nOutput: 9\nExplanation: We can partition the array nums into nums1 = [10] and nums2 = [100,1].\n- The maximum element of the array nums1 is equal to 10.\n- The minimum element of the array nums2 is equal to 1.\nThe value of the partition is |10 - 1| = 9.\nIt can be proven that 9 is the minimum value out of all partitions.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 999999999\n assert candidate(nums = [5, 1, 3, 2, 4]) == 1\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [5, 1, 3, 19, 18]) == 1\n assert candidate(nums = [5, 6, 1, 4, 2]) == 1\n assert candidate(nums = [4, 2, 1, 3]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50]) == 10\n assert candidate(nums = [5, 2, 3, 1, 4]) == 1\n assert candidate(nums = [2, 3, 1, 2]) == 0\n assert candidate(nums = [2, 2, 2, 2]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [100, 1, 10]) == 9\n assert candidate(nums = [1, 3, 2, 4]) == 1\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]) == 1\n assert candidate(nums = [500000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1000000000]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 5\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 100\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [50, 20, 30, 10, 40, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 10\n assert candidate(nums = [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 = [50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [99, 100, 98, 97, 96, 95]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 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]) == 1\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 999999999, 99999999, 9999999, 999999, 99999, 9999, 999, 99, 9, 8]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 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]) == 1\n assert candidate(nums = [5, 3, 1, 9, 7, 2, 8, 6, 4, 10, 12, 11, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(nums = [1000000000, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993, 9, 999999992]) == 1\n assert candidate(nums = [7, 12, 1, 5, 3, 8, 6, 10, 2, 4, 9, 11]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 2\n assert candidate(nums = [999999999, 1000000000, 1, 2, 3, 4, 5, 6, 7, 8]) == 1\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]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 1\n assert candidate(nums = [500000000, 400000000, 300000000, 200000000, 100000000, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4]) == 0\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1]) == 9\n assert candidate(nums = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 10\n assert candidate(nums = [1000000000, 1, 999999999, 2, 999999998, 3, 999999997, 4, 999999996, 5]) == 1\n assert candidate(nums = [1, 500000000, 2, 400000000, 3, 300000000, 4, 200000000, 5, 100000000]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\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\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\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]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [7, 3, 10, 1, 5, 8, 6, 9, 2, 4]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 2\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 9\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 0\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]) == 10000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1000000000]) == 1\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]) == 0\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 1\n assert candidate(nums = [9, 7, 5, 3, 1, 10, 8, 6, 4, 2]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5]) == 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]) == 1\n assert candidate(nums = [1, 2, 3, 1000000000]) == 1\n assert candidate(nums = [100, 50, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600]) == 50\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\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1]) == 0\n assert candidate(nums = [1000000000, 1, 999999999, 2, 999999998, 3, 999999997]) == 1\n assert candidate(nums = [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]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 1\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == 1\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]) == 1\n assert candidate(nums = [500000000, 500000001, 500000002, 500000003, 500000004, 500000005, 500000006, 500000007, 500000008, 500000009]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 2\n assert candidate(nums = [7, 15, 2, 8, 9, 10, 11, 12, 3, 6, 4, 5]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 51, 60, 70, 80, 90]) == 1\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [1000000000, 1, 2, 3, 999999999]) == 1\n assert candidate(nums = [7, 10, 3, 15, 8, 12]) == 1\n assert candidate(nums = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30]) == 0\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, 1000000000]) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 10\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,3,2,4]", "[100,1,10]"], "hints": ["Sort the array.", "The answer is min(nums[i+1] - nums[i]) for all i in the range [0, n-2]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findValueOfPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:48+00:00", "tests_total": 106, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def find_value_of_partition(nums)", "container": null, "callable": "find_value_of_partition", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2741, "task_id": "special-permutations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums containing n distinct positive integers. A permutation of nums is called special if:\n\n- For all indexes 0 <= i < n - 1, either nums[i] % nums[i+1] == 0 or nums[i+1] % nums[i] == 0.\n\nReturn the total number of special permutations. As the answer could be large, return it modulo 10^9+ 7.\n\nExample 1:\n\nInput: nums = [2,3,6]\nOutput: 2\nExplanation: [3,6,2] and [2,6,3] are the two special permutations of nums.\n\nExample 2:\n\nInput: nums = [1,4,3]\nOutput: 2\nExplanation: [3,1,4] and [4,1,3] are the two special permutations of nums.\n\nConstraints:\n\n- 2 <= nums.length <= 14\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [31, 62, 93, 124, 155]) == 0\n assert candidate(nums = [2, 3, 6]) == 2\n assert candidate(nums = [17, 34, 51, 68, 85]) == 0\n assert candidate(nums = [7, 14, 28, 56, 112]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 0\n assert candidate(nums = [5, 10, 20, 40]) == 24\n assert candidate(nums = [11, 22, 33, 44]) == 4\n assert candidate(nums = [1, 4, 3]) == 2\n assert candidate(nums = [2, 4, 8, 16]) == 24\n assert candidate(nums = [19, 38, 57, 76, 95]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 0\n assert candidate(nums = [3, 5, 15, 7]) == 0\n assert candidate(nums = [4, 2, 6, 3]) == 2\n assert candidate(nums = [7, 14, 28, 56, 112, 224]) == 720\n assert candidate(nums = [2, 4, 8, 16, 32]) == 120\n assert candidate(nums = [7, 14, 28, 21]) == 4\n assert candidate(nums = [13, 26, 39, 52, 65]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25]) == 0\n assert candidate(nums = [29, 58, 87, 116, 145]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55]) == 0\n assert candidate(nums = [23, 46, 69, 92, 115]) == 0\n assert candidate(nums = [3, 9, 27, 81]) == 24\n assert candidate(nums = [3, 5, 15, 75]) == 12\n assert candidate(nums = [4, 6, 12, 24]) == 12\n assert candidate(nums = [2, 4, 6, 8]) == 4\n assert candidate(nums = [2, 3, 6, 12, 18, 36]) == 336\n assert candidate(nums = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480]) == 227020758\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182]) == 0\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238]) == 0\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112]) == 0\n assert candidate(nums = [2, 3, 5, 6, 10, 15, 30]) == 120\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == 0\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56]) == 0\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238]) == 0\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969]) == 178290591\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154]) == 0\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]) == 0\n assert candidate(nums = [5, 10, 20, 25, 50, 100, 125, 200, 250, 500]) == 136208\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70]) == 0\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == 0\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969]) == 178290591\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35]) == 0\n assert candidate(nums = [12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304]) == 178290591\n assert candidate(nums = [2, 3, 6, 9, 12, 18, 24]) == 280\n assert candidate(nums = [1, 3, 9, 27, 81, 243]) == 720\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 0\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350]) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 178290591\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 178290591\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == 3628800\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182]) == 0\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323]) == 178290591\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == 0\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512]) == 40320\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125]) == 362880\n assert candidate(nums = [2, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78]) == 0\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230, 253, 276, 299, 322]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42]) == 4\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]) == 0\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024]) == 40320\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210, 231, 252, 273, 294]) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 3628800\n assert candidate(nums = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]) == 39916800\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135]) == 0\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 178290591\n assert candidate(nums = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480, 40960]) == 178290591\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230, 253, 276, 299, 322]) == 0\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584, 7168, 14336, 28672, 57344]) == 178290591\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == 0\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536]) == 3628800\n assert candidate(nums = [2, 3, 5, 6, 10, 15, 30, 60, 120, 240, 480, 720, 1440, 2880]) == 180479895\n assert candidate(nums = [5, 10, 20, 25, 50]) == 20\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154]) == 0\n assert candidate(nums = [2, 6, 18, 54, 162, 486, 1458, 4374, 13122, 39366, 118098, 354294, 1062882, 3188646]) == 178290591\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 178290591\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156]) == 0\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84]) == 0\n assert candidate(nums = [29, 58, 87, 116, 145, 174, 203, 232, 261, 290, 319, 348, 377, 406]) == 0\n", "comparison": "exact"}, "public_tests": ["[2,3,6]", "[1,4,3]"], "hints": ["Can we solve this problem using DP with bit masking?", "You just need two states in DP which are last_ind in the permutation and the mask of numbers already used."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().specialPerm", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:51+00:00", "tests_total": 99, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "bitmask"]}, "language": "ruby", "interface": {"raw_signature": "def special_perm(nums)", "container": null, "callable": "special_perm", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2742, "task_id": "painting-the-walls", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:\n\n- A paid painter that paints the i^th wall in time[i] units of time and takes cost[i] units of money.\n- A free painter that paints any wall in 1 unit of time at a cost of 0. But the free painter can only be used if the paid painter is already occupied.\n\nReturn the minimum amount of money required to paint the n walls.\n\nExample 1:\n\nInput: cost = [1,2,3,2], time = [1,2,3,2]\nOutput: 3\nExplanation: The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.\n\nExample 2:\n\nInput: cost = [2,3,4,2], time = [1,1,1,1]\nOutput: 4\nExplanation: The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.\n\nConstraints:\n\n- 1 <= cost.length <= 500\n- cost.length == time.length\n- 1 <= cost[i] <= 10^6\n- 1 <= time[i] <= 500\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(cost = [4, 4, 4, 4],time = [4, 4, 4, 4]) == 4\n assert candidate(cost = [5, 8, 4, 3],time = [2, 3, 1, 2]) == 7\n assert candidate(cost = [10, 20, 30, 40],time = [5, 4, 3, 2]) == 10\n assert candidate(cost = [10, 20, 30, 40, 50],time = [5, 4, 3, 2, 1]) == 10\n assert candidate(cost = [5, 1, 4, 9],time = [2, 1, 3, 4]) == 4\n assert candidate(cost = [100, 200, 300],time = [1, 2, 3]) == 200\n assert candidate(cost = [1000000, 500000, 750000],time = [500, 250, 375]) == 500000\n assert candidate(cost = [10, 15, 10],time = [3, 4, 2]) == 10\n assert candidate(cost = [2, 3, 4, 2],time = [1, 1, 1, 1]) == 4\n assert candidate(cost = [3, 2, 1],time = [1, 2, 3]) == 1\n assert candidate(cost = [1, 2, 3, 2],time = [1, 2, 3, 2]) == 3\n assert candidate(cost = [10, 15, 10],time = [2, 3, 2]) == 10\n assert candidate(cost = [1000, 2000, 3000],time = [10, 20, 30]) == 1000\n assert candidate(cost = [1, 3, 5, 7, 9],time = [9, 7, 5, 3, 1]) == 1\n assert candidate(cost = [1, 1, 1, 1, 1],time = [1, 1, 1, 1, 1]) == 3\n assert candidate(cost = [5, 10, 15],time = [2, 3, 4]) == 5\n assert candidate(cost = [3, 1, 7, 8, 5],time = [2, 1, 4, 5, 3]) == 4\n assert candidate(cost = [250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250],time = [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]) == 750\n assert candidate(cost = [500000, 400000, 300000, 200000, 100000],time = [100, 200, 300, 400, 500]) == 100000\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600],time = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 50\n assert candidate(cost = [12, 18, 15, 25, 30, 20],time = [2, 3, 4, 5, 6, 7]) == 20\n assert candidate(cost = [1000000, 999999, 888888, 777777, 666666],time = [1, 2, 3, 4, 5]) == 666666\n assert candidate(cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1500\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(cost = [999999, 999998, 999997, 999996, 999995, 999994],time = [500, 499, 498, 497, 496, 495]) == 999994\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],time = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [10, 20, 30, 20, 10, 30],time = [2, 1, 3, 1, 2, 3]) == 20\n assert candidate(cost = [5, 15, 10, 20, 25],time = [1, 3, 2, 4, 5]) == 15\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 110\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],time = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(cost = [500, 250, 125, 63, 32, 16, 8, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 200, 300, 400, 500, 1, 2, 3, 4, 5]) == 1\n assert candidate(cost = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 25\n assert candidate(cost = [5000, 4000, 3000, 2000, 1000, 500, 400, 300, 200, 100],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 100\n assert candidate(cost = [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],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 20\n assert candidate(cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],time = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 110\n assert candidate(cost = [100, 200, 150, 300, 250],time = [2, 3, 1, 4, 2]) == 250\n assert candidate(cost = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500],time = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 1000\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 150\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 70\n assert candidate(cost = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],time = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(cost = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 100\n assert candidate(cost = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 999990\n assert candidate(cost = [10000, 20000, 30000, 40000, 50000],time = [1, 1, 1, 1, 1]) == 60000\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 11\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],time = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 300\n assert candidate(cost = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 75\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 1\n assert candidate(cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],time = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 300\n assert candidate(cost = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 70000\n assert candidate(cost = [5, 10, 15, 20, 25, 30],time = [2, 3, 4, 5, 6, 7]) == 15\n assert candidate(cost = [1000000, 500000, 250000, 125000],time = [10, 20, 30, 40]) == 125000\n assert candidate(cost = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],time = [29, 23, 19, 17, 13, 11, 7, 5, 3, 2, 3, 5, 7, 11, 13]) == 2\n assert candidate(cost = [10000, 20000, 30000, 40000, 50000],time = [1, 2, 3, 4, 5]) == 30000\n assert candidate(cost = [999999, 1, 999998, 2, 999997, 3, 999996, 4, 999995, 5],time = [5, 4, 3, 2, 1, 500, 400, 300, 200, 100]) == 3\n assert candidate(cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 700\n assert candidate(cost = [500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000],time = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 500000\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(cost = [300, 200, 100, 400, 500, 150, 250],time = [3, 2, 1, 4, 5, 2, 3]) == 400\n assert candidate(cost = [3, 7, 8, 6, 5, 4, 2, 1, 9],time = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(cost = [999999, 1000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 66\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(cost = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1000\n assert candidate(cost = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 75\n assert candidate(cost = [100000, 200000, 300000, 400000, 500000],time = [10, 20, 30, 40, 50]) == 100000\n assert candidate(cost = [500, 100, 200, 300, 400, 600],time = [1, 2, 3, 4, 5, 6]) == 300\n assert candidate(cost = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70],time = [15, 10, 5, 15, 10, 5, 15, 10, 5, 15, 10, 5, 15, 10, 5]) == 1\n assert candidate(cost = [1, 5, 8, 10, 3, 7],time = [2, 4, 3, 1, 2, 5]) == 4\n assert candidate(cost = [300, 200, 100, 400, 300],time = [5, 4, 3, 2, 1]) == 200\n assert candidate(cost = [100, 200, 300, 400, 500, 600],time = [1, 2, 3, 4, 5, 6]) == 400\n assert candidate(cost = [5, 8, 3, 12, 7, 10, 6, 9, 2, 4],time = [4, 3, 5, 2, 3, 1, 4, 5, 6, 2]) == 5\n assert candidate(cost = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 10\n assert candidate(cost = [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],time = [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]) == 240\n assert candidate(cost = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100000\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],time = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(cost = [9, 8, 7, 6, 5, 4, 3, 2, 1],time = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = [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]) == 1\n assert candidate(cost = [1, 10, 100, 1000, 10000, 100000, 1000000, 500000, 500000, 500000],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1011\n assert candidate(cost = [120, 110, 100, 90, 80, 70, 60, 50],time = [3, 2, 1, 4, 3, 2, 1, 4]) == 120\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],time = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(cost = [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],time = [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]) == 1\n assert candidate(cost = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10, 12, 11, 13, 15, 14, 16, 18, 17, 19, 20, 22, 21, 23, 25, 24, 26, 28, 27, 29, 30],time = [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]) == 1\n assert candidate(cost = [20, 30, 25, 40, 15, 35, 45, 10, 50, 5],time = [5, 4, 3, 2, 1, 3, 4, 5, 2, 1]) == 30\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 150\n assert candidate(cost = [999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1999998\n assert candidate(cost = [50, 60, 70, 80, 90, 100, 110],time = [1, 1, 1, 1, 1, 1, 1]) == 260\n", "comparison": "exact"}, "public_tests": ["[1,2,3,2]\n[1,2,3,2]", "[2,3,4,2]\n[1,1,1,1]"], "hints": ["Can we break the problem down into smaller subproblems and use DP?", "If you pay for wall i, it contributes cost[i] and effectively covers time[i] + 1 walls: the paid wall itself plus up to time[i] walls that the free painter can paint while the paid painter works.", "Use DP over the number of walls covered, capped at n."], "metadata": {"canonical_parameter_names": ["cost", "time"], "leetcode_dataset_entry_point": "Solution().paintWalls", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:53+00:00", "tests_total": 93, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def paint_walls(cost, time)", "container": null, "callable": "paint_walls", "parameters": [{"name": "cost", "type": "Integer[]"}, {"name": "time", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2744, "task_id": "find-maximum-number-of-string-pairs", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array words consisting of distinct strings.\n\nThe string words[i] can be paired with the string words[j] if:\n\n- The string words[i] is equal to the reversed string of words[j].\n- 0 <= i < j < words.length.\n\nReturn the maximum number of pairs that can be formed from the array words.\n\nNote that each string can belong in at most one pair.\n\nExample 1:\n\nInput: words = [\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]\nOutput: 2\nExplanation: In this example, we can form 2 pair of strings in the following way:\n- We pair the 0^th string with the 2^nd string, as the reversed string of word[0] is \"dc\" and is equal to words[2].\n- We pair the 1^st string with the 3^rd string, as the reversed string of word[1] is \"ca\" and is equal to words[3].\nIt can be proven that 2 is the maximum number of pairs that can be formed.\n\nExample 2:\n\nInput: words = [\"ab\",\"ba\",\"cc\"]\nOutput: 1\nExplanation: In this example, we can form 1 pair of strings in the following way:\n- We pair the 0^th string with the 1^st string, as the reversed string of words[1] is \"ab\" and is equal to words[0].\nIt can be proven that 1 is the maximum number of pairs that can be formed.\n\nExample 3:\n\nInput: words = [\"aa\",\"ab\"]\nOutput: 0\nExplanation: In this example, we are unable to form any pair of strings.\n\nConstraints:\n\n- 1 <= words.length <= 50\n- words[i].length == 2\n- words consists of distinct strings.\n- words[i] contains only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji']) == 5\n assert candidate(words = ['mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts']) == 4\n assert candidate(words = ['uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba']) == 4\n assert candidate(words = ['xy', 'yx', 'zw', 'wz', 'mn']) == 2\n assert candidate(words = ['xy', 'yx', 'za', 'az', 'bw', 'wb', 'cc']) == 3\n assert candidate(words = ['lm', 'ml', 'no', 'on', 'pq', 'qp', 'rs', 'sr']) == 4\n assert candidate(words = ['ef', 'fe', 'gh', 'hg', 'ij', 'ji']) == 3\n assert candidate(words = ['st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy']) == 4\n assert candidate(words = ['xy', 'yx', 'zz', 'zx', 'yx', 'xy']) == 4\n assert candidate(words = ['xy', 'yx', 'za', 'az', 'bw', 'wb']) == 3\n assert candidate(words = ['tu', 'ut', 'vw', 'wv', 'xy', 'yx', 'za', 'az']) == 4\n assert candidate(words = ['kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq']) == 4\n assert candidate(words = ['cd', 'ac', 'dc', 'ca', 'zz']) == 2\n assert candidate(words = ['de', 'ed', 'fg', 'gf', 'hi', 'ih', 'jk', 'kj']) == 4\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj']) == 0\n assert candidate(words = ['aa', 'ab']) == 0\n assert candidate(words = ['mn', 'nm', 'op', 'po', 'qr', 'rq']) == 3\n assert candidate(words = ['xy', 'yx', 'za', 'az', 'bw', 'wb', 'cd', 'dc']) == 4\n assert candidate(words = ['ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk']) == 4\n assert candidate(words = ['qq', 'rr', 'ss', 'tt', 'uu']) == 0\n assert candidate(words = ['ab', 'ba', 'cc']) == 1\n assert candidate(words = ['qp', 'pq', 'rs', 'sr', 'tu', 'ut']) == 3\n assert candidate(words = ['ab', 'cd', 'ef', 'gh', 'ij', 'kl', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']) == 0\n assert candidate(words = ['xy', 'yx', 'zz', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 2\n assert candidate(words = ['xy', 'yx', 'pq', 'qp', 'rs', 'sr', 'tu', 'ut', 'vw', 'wv', 'xy', 'yx', 'zz', 'aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 9\n assert candidate(words = ['xy', 'yx', 'zz', 'aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 2\n assert candidate(words = ['xy', 'yx', 'zw', 'wz', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk']) == 15\n assert candidate(words = ['xy', 'yx', 'zz', 'wz', 'zw', 'uv', 'vu', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'ab', 'ba', 'ef', 'fe']) == 16\n assert candidate(words = ['st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq']) == 13\n assert candidate(words = ['bc', 'cb', 'de', 'ed', 'fg', 'gf', 'hi', 'ih', 'jk', 'kj', 'lm', 'ml', 'no', 'on', 'pq', 'qp', 'rs', 'sr', 'tu', 'ut']) == 10\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm']) == 7\n assert candidate(words = ['xy', 'yx', 'zx', 'xz', 'ay', 'ya', 'by', 'yb']) == 4\n assert candidate(words = ['ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba', 'cd', 'dc']) == 13\n assert candidate(words = ['ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm']) == 5\n assert candidate(words = ['xy', 'yx', 'zv', 'vz', 'ws', 'sw', 'tr', 'rt', 'qu', 'uq', 'kp', 'pk', 'jo', 'oj', 'in', 'ni', 'mh', 'hm', 'lg', 'gl', 'kf', 'fk', 'je', 'ej', 'id', 'di', 'hc', 'ch', 'gb', 'bg', 'fa', 'af']) == 16\n assert candidate(words = ['ba', 'ab', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'zz', 'za', 'az', 'bz', 'zb', 'cz', 'zc', 'dz', 'zd']) == 17\n assert candidate(words = ['st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy']) == 25\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ac', 'ca', 'bd', 'db']) == 15\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'ae', 'ea', 'af', 'fa', 'ag', 'ga', 'ah', 'ha', 'ai', 'ia', 'aj', 'ja', 'ak', 'ka', 'al', 'la', 'am', 'ma', 'an', 'na', 'ao', 'oa', 'ap', 'pa', 'aq', 'qa', 'ar', 'ra', 'as', 'sa', 'at', 'ta', 'au', 'ua', 'av', 'va', 'aw', 'wa', 'ax', 'xa', 'ay', 'ya', 'az', 'za']) == 25\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz', 'xy', 'yx', 'zw', 'wz', 'mn', 'nm']) == 3\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy']) == 13\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 0\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy']) == 13\n assert candidate(words = ['pq', 'qp', 'rs', 'sr', 'tu', 'ut', 'vw', 'wv', 'xy', 'yx', 'za', 'az']) == 6\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'ae', 'ea', 'af', 'fa', 'ag', 'ga', 'ah', 'ha', 'ai', 'ia']) == 8\n", "comparison": "exact"}, "public_tests": ["[\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]", "[\"ab\",\"ba\",\"cc\"]", "[\"aa\",\"ab\"]"], "hints": ["Notice that array words consist of distinct strings.", "Iterate over all indices (i, j) and check if they can be paired."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().maximumNumberOfStringPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:01:57+00:00", "tests_total": 65, "tests_dropped": 20, "flags": [], "topic_tags": ["array", "hash-table", "string", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_number_of_string_pairs(words)", "container": null, "callable": "maximum_number_of_string_pairs", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2745, "task_id": "construct-the-longest-new-string", "difficulty": "Medium", "problem_description": "You are given three integers x, y, and z.\n\nYou have x strings equal to \"AA\", y strings equal to \"BB\", and z strings equal to \"AB\". You want to choose some (possibly all or none) of these strings and concatenate them in some order to form a new string. This new string must not contain \"AAA\" or \"BBB\" as a substring.\n\nReturn the maximum possible length of the new string.\n\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: x = 2, y = 5, z = 1\nOutput: 12\nExplanation: We can concatenate the strings \"BB\", \"AA\", \"BB\", \"AA\", \"BB\", and \"AB\" in that order. Then, our new string is \"BBAABBAABBAB\".\nThat string has length 12, and we can show that it is impossible to construct a string of longer length.\n\nExample 2:\n\nInput: x = 3, y = 2, z = 2\nOutput: 14\nExplanation: We can concatenate the strings \"AB\", \"AB\", \"AA\", \"BB\", \"AA\", \"BB\", and \"AA\" in that order. Then, our new string is \"ABABAABBAABBAA\".\nThat string has length 14, and we can show that it is impossible to construct a string of longer length.\n\nConstraints:\n\n- 1 <= x, y, z <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(x = 1,y = 10,z = 10) == 26\n assert candidate(x = 50,y = 50,z = 50) == 300\n assert candidate(x = 10,y = 1,z = 10) == 26\n assert candidate(x = 20,y = 10,z = 5) == 52\n assert candidate(x = 10,y = 10,z = 1) == 42\n assert candidate(x = 2,y = 5,z = 1) == 12\n assert candidate(x = 1,y = 1,z = 1) == 6\n assert candidate(x = 3,y = 2,z = 2) == 14\n assert candidate(x = 49,y = 50,z = 1) == 200\n assert candidate(x = 40,y = 1,z = 2) == 10\n assert candidate(x = 40,y = 40,z = 30) == 220\n assert candidate(x = 50,y = 49,z = 49) == 296\n assert candidate(x = 5,y = 1,z = 5) == 16\n assert candidate(x = 50,y = 1,z = 1) == 8\n assert candidate(x = 2,y = 1,z = 10) == 26\n assert candidate(x = 10,y = 10,z = 30) == 100\n assert candidate(x = 25,y = 25,z = 10) == 120\n assert candidate(x = 10,y = 15,z = 8) == 58\n assert candidate(x = 35,y = 15,z = 5) == 72\n assert candidate(x = 25,y = 1,z = 25) == 56\n assert candidate(x = 2,y = 50,z = 25) == 60\n assert candidate(x = 7,y = 7,z = 14) == 56\n assert candidate(x = 30,y = 30,z = 25) == 170\n assert candidate(x = 25,y = 20,z = 10) == 102\n assert candidate(x = 5,y = 5,z = 45) == 110\n assert candidate(x = 5,y = 5,z = 10) == 40\n assert candidate(x = 30,y = 20,z = 10) == 102\n assert candidate(x = 33,y = 33,z = 34) == 200\n assert candidate(x = 30,y = 15,z = 25) == 112\n assert candidate(x = 40,y = 10,z = 30) == 102\n assert candidate(x = 15,y = 15,z = 25) == 110\n assert candidate(x = 30,y = 25,z = 30) == 162\n assert candidate(x = 1,y = 30,z = 5) == 16\n assert candidate(x = 10,y = 5,z = 15) == 52\n assert candidate(x = 15,y = 15,z = 5) == 70\n assert candidate(x = 20,y = 20,z = 1) == 82\n assert candidate(x = 50,y = 10,z = 1) == 44\n assert candidate(x = 20,y = 1,z = 30) == 66\n assert candidate(x = 20,y = 15,z = 20) == 102\n assert candidate(x = 40,y = 30,z = 20) == 162\n assert candidate(x = 10,y = 15,z = 20) == 82\n assert candidate(x = 20,y = 30,z = 40) == 162\n assert candidate(x = 5,y = 5,z = 50) == 120\n assert candidate(x = 10,y = 10,z = 10) == 60\n assert candidate(x = 40,y = 10,z = 1) == 44\n assert candidate(x = 10,y = 35,z = 5) == 52\n assert candidate(x = 1,y = 1,z = 50) == 104\n assert candidate(x = 30,y = 20,z = 30) == 142\n assert candidate(x = 15,y = 25,z = 30) == 122\n assert candidate(x = 5,y = 5,z = 40) == 100\n assert candidate(x = 2,y = 2,z = 4) == 16\n assert candidate(x = 10,y = 1,z = 50) == 106\n assert candidate(x = 45,y = 40,z = 45) == 252\n assert candidate(x = 45,y = 5,z = 5) == 32\n assert candidate(x = 45,y = 30,z = 25) == 172\n assert candidate(x = 5,y = 10,z = 40) == 102\n assert candidate(x = 10,y = 10,z = 15) == 70\n assert candidate(x = 10,y = 10,z = 40) == 120\n assert candidate(x = 2,y = 2,z = 3) == 14\n assert candidate(x = 20,y = 20,z = 30) == 140\n assert candidate(x = 40,y = 10,z = 10) == 62\n assert candidate(x = 25,y = 25,z = 1) == 102\n assert candidate(x = 49,y = 50,z = 49) == 296\n assert candidate(x = 15,y = 15,z = 30) == 120\n assert candidate(x = 4,y = 3,z = 6) == 26\n assert candidate(x = 10,y = 10,z = 5) == 50\n assert candidate(x = 10,y = 40,z = 20) == 82\n assert candidate(x = 1,y = 50,z = 1) == 8\n assert candidate(x = 20,y = 15,z = 25) == 112\n assert candidate(x = 1,y = 50,z = 49) == 104\n assert candidate(x = 25,y = 25,z = 25) == 150\n assert candidate(x = 20,y = 20,z = 20) == 120\n assert candidate(x = 20,y = 20,z = 10) == 100\n assert candidate(x = 25,y = 20,z = 30) == 142\n assert candidate(x = 1,y = 50,z = 50) == 106\n assert candidate(x = 30,y = 40,z = 35) == 192\n assert candidate(x = 30,y = 30,z = 1) == 122\n assert candidate(x = 10,y = 30,z = 10) == 62\n assert candidate(x = 30,y = 10,z = 20) == 82\n assert candidate(x = 20,y = 25,z = 30) == 142\n assert candidate(x = 15,y = 15,z = 1) == 62\n assert candidate(x = 35,y = 5,z = 10) == 42\n assert candidate(x = 40,y = 10,z = 20) == 82\n assert candidate(x = 50,y = 1,z = 50) == 106\n assert candidate(x = 10,y = 20,z = 15) == 72\n", "comparison": "exact"}, "public_tests": ["2\n5\n1", "3\n2\n2"], "hints": ["It can be proved that ALL “AB”s can be used in the optimal solution. (1) If the final string starts with 'A', we can put all unused “AB”s at the very beginning. (2) If the final string starts with 'B' (meaning) it starts with “BB”, we can put all unused “AB”s after the 2nd 'B'.", "Using “AB” doesn’t increase the number of “AA”s or “BB”s we can use. If we put an “AB” after “BB”, then we still need to append “AA” as before, so it doesn’t change the state.", "We only need to consider strings “AA” and “BB”; we can either use the pattern “AABBAABB…” or the pattern “BBAABBAA…”, depending on which one of x and y is larger."], "metadata": {"canonical_parameter_names": ["x", "y", "z"], "leetcode_dataset_entry_point": "Solution().longestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:00+00:00", "tests_total": 88, "tests_dropped": 3, "flags": [], "topic_tags": ["math", "dynamic-programming", "greedy", "brainteaser"]}, "language": "ruby", "interface": {"raw_signature": "def longest_string(x, y, z)", "container": null, "callable": "longest_string", "parameters": [{"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}, {"name": "z", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2746, "task_id": "decremental-string-concatenation", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array words containing n strings.\n\nLet's define a join operation join(x, y) between two strings x and y as concatenating them into xy. However, if the last character of x is equal to the first character of y, one of them is deleted.\n\nFor example join(\"ab\", \"ba\") = \"aba\" and join(\"ab\", \"cde\") = \"abcde\".\n\nYou are to perform n - 1 join operations. Let str_0 = words[0]. Starting from i = 1 up to i = n - 1, for the i^th operation, you can do one of the following:\n\n- Make str_i = join(str_{i - 1}, words[i])\n- Make str_i = join(words[i], str_{i - 1})\n\nYour task is to minimize the length of str_{n - 1}.\n\nReturn an integer denoting the minimum possible length of str_{n - 1}.\n\nExample 1:\n\nInput: words = [\"aa\",\"ab\",\"bc\"]\nOutput: 4\nExplanation: In this example, we can perform join operations in the following order to minimize the length of str_2:\nstr_0 = \"aa\"\nstr_1 = join(str_0, \"ab\") = \"aab\"\nstr_2 = join(str_1, \"bc\") = \"aabc\"\nIt can be shown that the minimum possible length of str_2 is 4.\n\nExample 2:\n\nInput: words = [\"ab\",\"b\"]\nOutput: 2\nExplanation: In this example, str_0 = \"ab\", there are two ways to get str_1:\njoin(str_0, \"b\") = \"ab\" or join(\"b\", str_0) = \"bab\".\nThe first string, \"ab\", has the minimum length. Hence, the answer is 2.\n\nExample 3:\n\nInput: words = [\"aaa\",\"c\",\"aba\"]\nOutput: 6\nExplanation: In this example, we can perform join operations in the following order to minimize the length of str_2:\nstr_0 = \"aaa\"\nstr_1 = join(str_0, \"c\") = \"aaac\"\nstr_2 = join(\"aba\", str_1) = \"abaaac\"\nIt can be shown that the minimum possible length of str_2 is 6.\n\nConstraints:\n\n- 1 <= words.length <= 1000\n- 1 <= words[i].length <= 50\n- Each character in words[i] is an English lowercase letter\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abcd', 'de', 'efg', 'gh']) == 8\n assert candidate(words = ['abcd', 'dcba', 'abdc', 'cdab']) == 13\n assert candidate(words = ['x', 'y', 'z', 'x', 'y', 'z']) == 4\n assert candidate(words = ['ab', 'bc', 'cd', 'da']) == 5\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd']) == 16\n assert candidate(words = ['abc', 'cba', 'bca', 'acb']) == 9\n assert candidate(words = ['abc', 'cba', 'bac', 'bca']) == 10\n assert candidate(words = ['a', 'b', 'c', 'd', 'e']) == 5\n assert candidate(words = ['ab', 'b']) == 2\n assert candidate(words = ['aabb', 'bbaa', 'abab', 'baba']) == 13\n assert candidate(words = ['zz', 'za', 'az', 'zzz']) == 6\n assert candidate(words = ['xyz', 'zyx', 'xyz']) == 7\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']) == 35\n assert candidate(words = ['a', 'a', 'a', 'a']) == 1\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']) == 14\n assert candidate(words = ['same', 'emag', 'game', 'emerge', 'merge']) == 20\n assert candidate(words = ['hello', 'ollie', 'elephant']) == 16\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 10\n assert candidate(words = ['abc', 'abc', 'abc', 'abc']) == 12\n assert candidate(words = ['abc', 'bcd', 'cde']) == 8\n assert candidate(words = ['xyz', 'zyx', 'abc']) == 8\n assert candidate(words = ['aa', 'ab', 'bc']) == 4\n assert candidate(words = ['abc', 'cba', 'bac', 'bca', 'cab', 'acb']) == 14\n assert candidate(words = ['zzzz', 'zzz', 'zz', 'z']) == 7\n assert candidate(words = ['hello', 'ocean', 'nest']) == 12\n assert candidate(words = ['aaa', 'c', 'aba']) == 6\n assert candidate(words = ['abc', 'cab', 'bca', 'acb', 'bac', 'cba', 'abc', 'cab', 'bca', 'acb', 'bac', 'cba', 'abc', 'cab', 'bca', 'acb', 'bac', 'cba', 'abc', 'cab', 'bca', 'acb', 'bac', 'cba']) == 49\n assert candidate(words = ['abc', 'cab', 'bac', 'acb', 'bca', 'cba', 'abc', 'cab', 'bac', 'acb', 'bca', 'cba', 'abc', 'cab', 'bac', 'acb', 'bca', 'cba', 'abc', 'cab', 'bac', 'acb', 'bca', 'cba', 'abc', 'cab', 'bac', 'acb', 'bca', 'cba']) == 62\n assert candidate(words = ['abcde', 'edcba', 'bcdea', 'aebcd', 'defab', 'baced', 'cdefa', 'abced', 'decba', 'edabc']) == 43\n assert candidate(words = ['zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz']) == 16\n assert candidate(words = ['zzz', 'zyz', 'yzy', 'xyx', 'wxw', 'vuw', 'utv', 'tsu', 'rtr', 'qsp', 'pon', 'omn', 'nml', 'lmk', 'kjl', 'jik', 'ihg', 'hgf', 'ged', 'fcd', 'ebc', 'dad', 'cac', 'bcb', 'aba', 'aaa']) == 67\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa', 'abab', 'baba', 'bbaa', 'bbba', 'bbbb', 'baaa']) == 34\n assert candidate(words = ['abc', 'cba', 'bca', 'acb', 'cab', 'bac', 'aab', 'abb', 'bab', 'bba', 'aba', 'baa']) == 26\n assert candidate(words = ['aaaaabbbbbcccccdddddeeeee', 'eeeeedddddccccbbbbbaaaaa', 'ffffffffgggggghhhhhiiiii', 'iiiiihihhhhgggggffffffff']) == 95\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'ae', 'ea', 'af', 'fa', 'ag', 'ga', 'ah', 'ha', 'ai', 'ia', 'aj', 'ja', 'ak', 'ka']) == 21\n assert candidate(words = ['aaaaa', 'aaabb', 'aabbb', 'abbbb', 'bbbbb', 'bbbb', 'bbb', 'bb', 'b', 'a', 'aaaab', 'aaabb', 'aabbb', 'abbbb', 'bbbbb']) == 53\n assert candidate(words = ['abcdef', 'fedcba', 'ghijkl', 'lkjihg', 'mnopqr', 'rqponm', 'stuvwx', 'xwvuts', 'yzabcd', 'dcba']) == 53\n assert candidate(words = ['aabbcc', 'ccbbcc', 'ddccbb', 'bbaadd', 'aaddcc', 'ccddaabb', 'bbccddaa', 'aaddbbcc', 'ccddaabb', 'bbaadddc', 'ccbbccaa', 'aaddbbcc', 'ccbbccdd', 'ddeebbaa', 'aabbccdd', 'bbccddeea', 'aaddccdde', 'bbccddeea', 'aadddccb', 'bbccddeea', 'ccdddeebb', 'ddeebbaac', 'aaddccdde', 'bbccddeea', 'ccdddeebb', 'ddeebbaac', 'aaddccdde', 'bbccddeea', 'ccdddeebb', 'ddeebbaac']) == 220\n assert candidate(words = ['abcde', 'edcba', 'abc', 'cba', 'a', 'b', 'c', 'd', 'e']) == 17\n assert candidate(words = ['xyzz', 'zzyx', 'yxzz', 'zzzy', 'xyyx', 'yxyx', 'xzyx', 'zyxy', 'zzxx', 'xxzz', 'xyxy', 'yxyy', 'yyxy', 'xyxy', 'zyyx', 'xzyz', 'zzyz', 'yzyz', 'zyzy', 'xyzx', 'yxzx', 'xzyy', 'yzyx', 'xyyz', 'zyzy']) == 82\n assert candidate(words = ['repeat', 'eatrep', 'peatre', 'eatrep', 'peatre', 'eatrep', 'peatre', 'eatrep', 'peatre', 'eatrep', 'peatre']) == 57\n assert candidate(words = ['aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa', 'aaaaa']) == 289\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff', 'gggg', 'hhhh', 'iiii', 'jjjj', 'kkkk', 'llll', 'mmmm', 'nnnn', 'oooo', 'pppp', 'qqqq', 'rrrr', 'ssss', 'tttt', 'uuuu', 'vvvv', 'wwww', 'xxxx', 'yyyy', 'zzzz', 'aaab', 'bbac', 'ccad', 'ddae', 'eeaf', 'ffag', 'ggbh', 'hhih', 'iiji', 'jjik', 'kkil', 'llim', 'mmim', 'njin', 'okin', 'plin', 'qlin', 'rlin', 'slin', 'tlia', 'ulia', 'vlia', 'wlia', 'xlia', 'ylia', 'zlkb', 'alib', 'blib', 'clib', 'dlib', 'elib', 'flib', 'glib', 'hlid', 'ilid', 'jlid', 'klid', 'llie', 'mlie', 'nlie', 'olie', 'plie', 'qlie', 'rlie', 'slie', 'tlif', 'ulif', 'vlif', 'wlif', 'xlif', 'ylif', 'zlif', 'almg', 'blmg', 'clmg', 'dlog', 'elog', 'flmg', 'glog', 'hlmg', 'ilmg', 'jlog', 'klmg', 'llmg', 'mlmh', 'nlmh', 'olmh', 'plmh', 'qlmh', 'rlmh', 'slmh', 'tlmh', 'ulmh', 'vlim', 'wlim', 'xlmn', 'ylmn', 'zlmn', 'amno', 'bmno', 'cmno', 'dmno', 'emno', 'fmno', 'gmno', 'hmno', 'imno', 'jmno', 'kmno', 'lmno', 'mmnp', 'nmnp', 'omnp', 'pmnp', 'qmnp', 'rmnp', 'smnp', 'tmnp', 'umnp', 'vmno', 'wmno', 'xmno', 'ymno', 'zmno', 'anop', 'bnop', 'cnop', 'dnop', 'enop', 'fnop', 'gnop', 'hnop', 'inop', 'jnop', 'knop', 'lnop', 'mnop', 'mnoq', 'nnoq', 'onno', 'pnno', 'qnno', 'rnno', 'snno', 'tnno', 'unno', 'vnno', 'wnno', 'xnno', 'ynno', 'znno', 'aonr', 'bonr', 'conr', 'donr', 'eonr', 'fonr', 'gonr', 'honr', 'ionr', 'jonr', 'konr', 'lonr', 'monr', 'nonr', 'onrs', 'pnrs', 'qnrs', 'rnrs', 'snrs', 'tnrs', 'unrs', 'vnrs', 'wnrs', 'xnrs', 'ynrs', 'znrs', 'aors', 'bors', 'cors', 'dors', 'eors', 'fors', 'gors', 'hors', 'iors', 'jors', 'kors', 'lors', 'mors', 'nors', 'orsp', 'nosp', 'ospp', 'pspq', 'qspq', 'rspq', 'sspq', 'tspq', 'uspq', 'vspq', 'wspq', 'xspq', 'yspq', 'zspq', 'atpq', 'btpq', 'ctpq', 'dtpq', 'etpq', 'ftpq', 'gtpq', 'htpq', 'itpq', 'jtpq', 'ktpq', 'ltpq', 'mtpq', 'nspq', 'ntpq', 'optq', 'ptpr', 'qtpr', 'rtpr', 'stpr', 'ttpr', 'utpr', 'vtpr', 'wtpr', 'xtpr', 'ytpr', 'ztpr', 'aotr', 'botr', 'cotr', 'dotr', 'eotr', 'fotr', 'gotr', 'hotr', 'iotr', 'jotr', 'kotr', 'lotr', 'motr', 'notr', 'ootr', 'potr', 'qotr', 'rotr', 'sotr', 'totr', 'uotr', 'votr', 'wotr', 'xotr', 'yotr', 'zotr', 'aupt', 'bupt', 'aupt', 'cutr', 'dutr', 'eutr', 'futr', 'gutr', 'hutr', 'iutr', 'jutr', 'kutr', 'lutr', 'mutr', 'nctr', 'nutr', 'outr', 'pout', 'qout', 'rout', 'sout', 'tout', 'uout', 'vout', 'wout', 'xout', 'yout', 'zout']) == 1130\n assert candidate(words = ['zzzz', 'zzz', 'zz', 'z', 'z', 'zz', 'zzz', 'zzzz']) == 13\n assert candidate(words = ['aaaaaab', 'baaaaaa', 'aaabaaa', 'aaaabaa', 'aaaaaba', 'aaaaaab', 'baaaaaa', 'aaabaaa', 'aaaabaa', 'aaaaaba']) == 61\n assert candidate(words = ['abcde', 'edcba', 'fghij', 'jihgf', 'klmno', 'onmlk', 'pqrst', 'tsrqp', 'uvwxy', 'yxwvu', 'zyxwv', 'vwxyz', 'utsrq', 'qponm', 'lkjih', 'ihgfe', 'edcba']) == 76\n assert candidate(words = ['pqr', 'rst', 'tuv', 'vwx', 'xyz', 'zyx', 'wxy', 'uvw', 'tsr', 'qrp', 'pqr', 'rst', 'tuv', 'vwx', 'xyz']) == 34\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxyza', 'zyxwvutsrqponmlkjihgfedcbaz', 'abcdefghijklmnopqrstuvwxy', 'zyxwvutsrqponmlkjihgfedcba']) == 154\n assert candidate(words = ['aaaabbbb', 'bbbbcccc', 'ccccdddd', 'ddddaaaa']) == 29\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'xyz', 'zyx', 'xyz', 'zyx', 'xyz', 'zyx', 'xyz']) == 21\n assert candidate(words = ['abcdefg', 'ghijklm', 'mnopqr', 'rstuvw', 'wxyzabc', 'defghij', 'klmnopq', 'rstuvwx', 'yzabcd', 'efghijk', 'lmnopqr']) == 69\n assert candidate(words = ['aabb', 'bbaa', 'abab', 'baba', 'aabb', 'bbaa', 'abab', 'baba', 'aabb', 'bbaa', 'abab', 'baba', 'aabb', 'bbaa', 'abab', 'baba', 'aabb', 'bbaa', 'abab', 'baba']) == 61\n assert candidate(words = ['abcde', 'edcba', 'bcdef', 'fedcb', 'cdefg', 'gfedc', 'defgh', 'hgfed', 'efghi', 'ihgfe']) == 44\n assert candidate(words = ['abc', 'cba', 'bac', 'cab', 'acb', 'bca', 'xyz', 'zyx', 'yxz', 'zxy', 'yzx', 'xzy', 'uvw', 'vwu', 'wuv', 'uwv']) == 37\n assert candidate(words = ['ab', 'bc', 'cd', 'de', 'ef', 'fg', 'gh', 'hi', 'ij', 'jk', 'kl', 'lm', 'mn', 'no', 'op', 'pq', 'qr', 'rs', 'st', 'tu', 'uv', 'vw', 'wx', 'xy', 'yz', 'za']) == 27\n assert candidate(words = ['zzzz', 'zzz', 'zz', 'z', 'z']) == 7\n assert candidate(words = ['abcdefghij', 'jihgfedcba', 'mnopqrstuv', 'vutsrqponm', 'wxyzabcd', 'dcbaefgh', 'ijklmnop', 'ponmlkji', 'qrstuvwxyz', 'zyxwvutsrq']) == 87\n assert candidate(words = ['aabb', 'bbcc', 'ccdd', 'ddee', 'eemm', 'mmnn', 'nnoo', 'oopp', 'ppqq', 'qqrr', 'rrss', 'sstt', 'ttuu', 'uuvv', 'vvww', 'wwxx', 'xxyy', 'yyzz', 'zzaa', 'aabb']) == 61\n assert candidate(words = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'tttttttttttttttttttttttttttttttttttttttt', 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq']) == 198\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'ae', 'ea', 'af', 'fa']) == 11\n assert candidate(words = ['ababab', 'bababa', 'ababab', 'bababa', 'ababab', 'bababa', 'ababab', 'bababa', 'ababab', 'bababa']) == 51\n assert candidate(words = ['aabbcc', 'ccbbaa', 'aabbaa', 'bbaacc', 'ccabba', 'baacca', 'abbccc', 'ccabbb', 'bbbaac', 'acccbb']) == 52\n assert candidate(words = ['xyzz', 'zzxy', 'yzzx', 'zxyy', 'xyyx', 'yxzx', 'xzyz', 'zyzx', 'zyxz', 'yzzx', 'xyzz', 'zzxy']) == 39\n assert candidate(words = ['xy', 'yx', 'xz', 'zx', 'xw', 'wx', 'xv', 'vx', 'xu', 'ux', 'xt', 'tx', 'xs', 'sx', 'xr', 'rx', 'xq', 'qx', 'xp', 'px', 'xo', 'ox', 'xn', 'nx', 'xm', 'mx', 'xl', 'lx', 'xk', 'kx', 'xj', 'jx', 'xi', 'ix', 'xh', 'hx', 'xg', 'gx', 'xf', 'fx', 'xe', 'ex', 'xd', 'dx', 'xc', 'cx', 'xb', 'bx', 'xa', 'ax']) == 51\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa', 'baaa']) == 16\n assert candidate(words = ['abcabcabc', 'cbacbacba', 'bcabcbcab', 'abcbabcbc', 'cbacbacba', 'bcabcbcab', 'abcbabcbc', 'cbacbacba', 'bcabcbcab', 'abcbabcbc', 'cbacbacba', 'bcabcbcab', 'abcbabcbc', 'cbacbacba', 'bcabcbcab', 'abcbabcbc']) == 130\n assert candidate(words = ['abc', 'cba', 'bac', 'acb', 'cab', 'bca']) == 13\n assert candidate(words = ['abcdabcdabcd', 'dcbaabcdabcd', 'abcdabcdabcd', 'dcbaabcdabcd', 'abcdabcdabcd', 'dcbaabcdabcd', 'abcdabcdabcd', 'dcbaabcdabcd', 'abcdabcdabcd', 'dcbaabcdabcd', 'abcdabcdabcd', 'dcbaabcdabcd']) == 138\n assert candidate(words = ['abcabc', 'bcbcbc', 'cbacba', 'bababa', 'acbacb', 'bacbac', 'cabacb', 'bcbacb', 'cbacba', 'abcabc', 'bcbcbc']) == 58\n assert candidate(words = ['a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b']) == 2\n assert candidate(words = ['abcdefghijklmnopqrstuvwxy', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxy', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxy', 'zyxwvutsrqponmlkjihgfedcba']) == 150\n assert candidate(words = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', 'fffff', 'ggggg', 'hhhhh', 'iiiii', 'jjjjj']) == 50\n assert candidate(words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrst']) == 209\n assert candidate(words = ['zzzzz', 'zzzz', 'zzz', 'zz', 'z']) == 11\n assert candidate(words = ['abac', 'bcad', 'cada', 'dadb', 'babc', 'acab', 'baca', 'caba', 'abcd', 'dcba', 'fedc', 'dcfe', 'dcde', 'edcd', 'dede', 'eeee', 'ee', 'e', 'a']) == 54\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyzabcdefghijkl', 'pqonmlkjihgfedcbazyxwvutsr']) == 103\n assert candidate(words = ['aaaaab', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', 'fffff', 'ggggg', 'hhhhh', 'iiiii', 'jjjjj', 'kkkkk', 'lllll', 'mmmmm', 'nnnnn', 'ooooo', 'ppppp', 'qqqqq', 'rrrrr', 'sssss', 'ttttt']) == 100\n assert candidate(words = ['zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz']) == 31\n assert candidate(words = ['abcdabcdabcdabcdabcd', 'abcdeabcdeabcdeabcde', 'ababcababcababcab', 'abacabadabacabadaba', 'abacabadabacabadaba', 'abacabadabacabadaba', 'abacabadabacabadaba', 'abacabadabacabadaba']) == 147\n assert candidate(words = ['abcdef', 'fedcba', 'bcdefa', 'afedcb', 'cdefab', 'bafedc', 'defabc', 'cbafed', 'efabcd', 'dcbafe']) == 51\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']) == 26\n assert candidate(words = ['abc', 'cab', 'bac', 'bca', 'acb', 'cba', 'aba', 'bab', 'aab', 'abb', 'bba', 'baa', 'aba', 'abb', 'bab', 'aab', 'abb', 'bba', 'baa', 'aba', 'abb', 'bab', 'aab', 'abb', 'bba', 'baa', 'aba', 'abb', 'bab', 'aab', 'abb', 'bba', 'baa', 'aba', 'abb', 'bab', 'aab', 'abb', 'bba', 'baa', 'aba', 'abb', 'bab']) == 92\n assert candidate(words = ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == 61\n assert candidate(words = ['abc', 'cab', 'bac', 'acb', 'bca', 'cba']) == 14\n assert candidate(words = ['abcde', 'edcba', 'bcdea', 'aecdb', 'dbeca', 'cedba', 'bedca', 'aebcd', 'decba', 'cbade', 'bacde', 'acdeb']) == 53\n", "comparison": "exact"}, "public_tests": ["[\"aa\",\"ab\",\"bc\"]", "[\"ab\",\"b\"]", "[\"aaa\",\"c\",\"aba\"]"], "hints": ["Use dynamic programming with memoization.", "Notice that the first and last characters of a string are sufficient to determine the length of its concatenation with any other string.", "Define dp[i][first][last] as the shortest concatenation length of the first i words starting with a character first and ending with a character last. Convert characters to their ASCII codes if your programming language cannot implicitly convert them to array indices."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().minimizeConcatenatedLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:02+00:00", "tests_total": 85, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def minimize_concatenated_length(words)", "container": null, "callable": "minimize_concatenated_length", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2747, "task_id": "count-zero-request-servers", "difficulty": "Medium", "problem_description": "You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time.\n\nYou are also given an integer x and a 0-indexed integer array queries.\n\nReturn a 0-indexed integer array arr of length queries.length where arr[i] represents the number of servers that did not receive any requests during the time interval [queries[i] - x, queries[i]].\n\nNote that the time intervals are inclusive.\n\nExample 1:\n\nInput: n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]\nOutput: [1,2]\nExplanation:\nFor queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.\nFor queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.\n\nExample 2:\n\nInput: n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]\nOutput: [0,1]\nExplanation:\nFor queries[0]: All servers get at least one request in the duration of [1, 3].\nFor queries[1]: Only server with id 3 gets no request in the duration [2,4].\n\nConstraints:\n\n- 1 <= n <= 10^5\n- 1 <= logs.length <= 10^5\n- 1 <= queries.length <= 10^5\n- logs[i].length == 2\n- 1 <= logs[i][0] <= n\n- 1 <= logs[i][1] <= 10^6\n- 1 <= x <= 10^5\n- x < queries[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1,logs = [[1, 1]],x = 1,queries = [2]) == [0]\n assert candidate(n = 10,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],x = 10,queries = [20, 50, 80, 110]) == [8, 8, 8, 9]\n assert candidate(n = 4,logs = [[1, 10], [2, 15], [3, 20], [4, 25]],x = 10,queries = [15, 20, 25, 30]) == [2, 1, 1, 2]\n assert candidate(n = 3,logs = [[1, 3], [2, 6], [1, 5]],x = 5,queries = [10, 11]) == [1, 2]\n assert candidate(n = 3,logs = [[2, 4], [2, 1], [1, 2], [3, 1]],x = 2,queries = [3, 4]) == [0, 1]\n assert candidate(n = 5,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],x = 1,queries = [2, 3]) == [3, 3]\n assert candidate(n = 5,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],x = 1,queries = [2, 3, 4, 5, 6]) == [3, 3, 3, 3, 4]\n assert candidate(n = 2,logs = [[1, 1], [1, 2], [1, 3], [2, 4], [2, 5]],x = 2,queries = [3, 5, 7]) == [1, 0, 1]\n assert candidate(n = 2,logs = [[1, 1], [1, 2], [1, 3], [2, 4], [2, 5]],x = 2,queries = [3, 4, 5]) == [1, 0, 0]\n assert candidate(n = 2,logs = [[1, 1], [1, 2], [2, 3]],x = 2,queries = [4, 5]) == [0, 1]\n assert candidate(n = 4,logs = [[1, 1], [2, 2], [3, 3], [4, 4]],x = 4,queries = [5, 6, 7, 8]) == [0, 1, 2, 3]\n assert candidate(n = 5,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],x = 1,queries = [2, 3, 4, 5]) == [3, 3, 3, 3]\n assert candidate(n = 9,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [1, 19], [2, 20], [3, 21], [4, 22], [5, 23], [6, 24], [7, 25], [8, 26], [9, 27]],x = 15,queries = [20, 30, 40, 50]) == [0, 0, 6, 9]\n assert candidate(n = 10,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],x = 10,queries = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == [8, 8, 8, 8, 8, 8, 8, 8, 8, 9]\n assert candidate(n = 10,logs = [[1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [10, 55]],x = 10,queries = [15, 25, 35, 45, 55]) == [8, 7, 7, 7, 7]\n assert candidate(n = 8,logs = [[1, 10], [1, 20], [2, 15], [2, 25], [3, 12], [3, 18], [4, 16], [4, 22], [5, 14], [5, 24], [6, 11], [6, 21], [7, 13], [7, 23], [8, 17], [8, 27]],x = 10,queries = [15, 20, 25, 30]) == [2, 0, 0, 1]\n assert candidate(n = 5,logs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]],x = 5,queries = [7, 8, 9, 10, 11]) == [0, 0, 0, 0, 0]\n assert candidate(n = 10,logs = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [5, 1], [5, 2], [5, 3]],x = 2,queries = [3, 6, 9]) == [5, 10, 10]\n assert candidate(n = 10,logs = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]],x = 5,queries = [10, 15, 20]) == [4, 5, 10]\n assert candidate(n = 10,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],x = 10,queries = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(n = 10,logs = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],x = 5,queries = [10, 15, 20]) == [10, 10, 10]\n assert candidate(n = 5,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15]],x = 5,queries = [10, 15, 20, 25]) == [0, 0, 4, 5]\n assert candidate(n = 20,logs = [[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]],x = 10,queries = [11, 21, 31, 41]) == [9, 10, 20, 20]\n assert candidate(n = 5,logs = [[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]],x = 2,queries = [3, 4, 5]) == [2, 2, 2]\n assert candidate(n = 15,logs = [[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]],x = 5,queries = [6, 11, 16, 21, 26, 31]) == [9, 9, 10, 15, 15, 15]\n assert candidate(n = 5,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10]],x = 5,queries = [10, 15]) == [0, 4]\n assert candidate(n = 6,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12]],x = 5,queries = [12, 15, 20]) == [0, 3, 6]\n assert candidate(n = 10,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],x = 5,queries = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [4, 4, 4, 4, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 10,logs = [[1, 1], [2, 2], [1, 11], [2, 12], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],x = 10,queries = [15, 20, 25, 30]) == [2, 7, 10, 10]\n assert candidate(n = 7,logs = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [5, 1], [5, 2], [5, 3], [6, 1], [6, 2], [6, 3], [7, 1], [7, 2], [7, 3]],x = 2,queries = [3, 6, 9, 12]) == [0, 7, 7, 7]\n assert candidate(n = 5,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7]],x = 3,queries = [4, 7, 10, 13]) == [1, 0, 0, 5]\n assert candidate(n = 6,logs = [[1, 1], [1, 3], [2, 2], [2, 4], [3, 3], [3, 5], [4, 4], [4, 6], [5, 5], [5, 7], [6, 6], [6, 8]],x = 2,queries = [3, 6, 9, 12]) == [3, 1, 4, 6]\n assert candidate(n = 20,logs = [[1, 10], [2, 12], [3, 14], [4, 16], [5, 18], [6, 20], [7, 22], [8, 24], [9, 26], [10, 28], [11, 30], [12, 32], [13, 34], [14, 36], [15, 38], [16, 40], [17, 42], [18, 44], [19, 46], [20, 48]],x = 5,queries = [15, 25, 35, 45, 55]) == [17, 17, 17, 17, 20]\n assert candidate(n = 9,logs = [[1, 1], [1, 2], [1, 3], [2, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [4, 10], [4, 11], [4, 12], [5, 13], [5, 14], [5, 15]],x = 3,queries = [5, 10, 15, 20]) == [7, 7, 7, 9]\n assert candidate(n = 10,logs = [[1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [10, 55]],x = 10,queries = [12, 22, 32, 42, 52, 62]) == [9, 8, 8, 8, 8, 9]\n assert candidate(n = 12,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [1, 13], [2, 14], [3, 15], [4, 16], [5, 17], [6, 18], [7, 19], [8, 20], [9, 21], [10, 22], [11, 23], [12, 24]],x = 10,queries = [15, 25, 35, 45]) == [1, 2, 12, 12]\n assert candidate(n = 15,logs = [[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]],x = 5,queries = [6, 11, 16, 21]) == [9, 9, 10, 15]\n assert candidate(n = 8,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]],x = 1,queries = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [6, 6, 6, 6, 8, 8, 8, 8, 8, 8]\n assert candidate(n = 10,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],x = 3,queries = [5, 6, 7, 8, 9, 10, 11]) == [6, 6, 6, 6, 6, 6, 7]\n assert candidate(n = 10,logs = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]],x = 5,queries = [6, 7, 8, 9, 10]) == [7, 7, 7, 7, 7]\n assert candidate(n = 20,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100], [11, 110], [12, 120], [13, 130], [14, 140], [15, 150], [16, 160], [17, 170], [18, 180], [19, 190], [20, 200]],x = 50,queries = [150, 200, 250, 300]) == [14, 14, 19, 20]\n assert candidate(n = 12,logs = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20], [11, 22], [12, 24]],x = 10,queries = [12, 22, 32, 42]) == [6, 6, 10, 12]\n assert candidate(n = 10,logs = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],x = 20,queries = [50, 60, 70, 80, 90, 100]) == [7, 7, 7, 7, 7, 7]\n assert candidate(n = 15,logs = [[1, 10], [2, 12], [3, 14], [4, 16], [5, 18], [6, 20], [7, 22], [8, 24], [9, 26], [10, 28], [11, 30], [12, 32], [13, 34], [14, 36], [15, 38]],x = 10,queries = [15, 25, 35, 45]) == [12, 10, 10, 13]\n assert candidate(n = 12,logs = [[1, 1], [1, 2], [2, 2], [2, 3], [3, 3], [3, 4], [4, 4], [4, 5], [5, 5], [5, 6], [6, 6], [6, 7]],x = 3,queries = [4, 5, 6, 7, 8]) == [8, 7, 7, 8, 9]\n assert candidate(n = 6,logs = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2]],x = 2,queries = [3, 4, 5, 6]) == [0, 0, 6, 6]\n assert candidate(n = 10,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],x = 3,queries = [4, 7, 10, 13]) == [6, 6, 6, 9]\n assert candidate(n = 10,logs = [[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]],x = 10,queries = [15, 20, 25, 30]) == [0, 0, 4, 9]\n assert candidate(n = 15,logs = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 15], [7, 15], [8, 15], [9, 15], [10, 15], [11, 20], [12, 20], [13, 20], [14, 20], [15, 20]],x = 10,queries = [15, 20, 25]) == [5, 0, 5]\n assert candidate(n = 10,logs = [[1, 1], [2, 2], [1, 3], [2, 4], [1, 5], [2, 6], [1, 7], [2, 8], [1, 9], [2, 10], [3, 11], [4, 12], [5, 13], [6, 14], [7, 15], [8, 16], [9, 17], [10, 18], [3, 19], [4, 20]],x = 5,queries = [10, 15, 20, 25]) == [8, 4, 4, 9]\n assert candidate(n = 10,logs = [[1, 2], [2, 5], [3, 5], [4, 10], [5, 15], [6, 20], [7, 25], [8, 30], [9, 35], [10, 40]],x = 5,queries = [10, 15, 20, 25, 30, 35, 40]) == [7, 8, 8, 8, 8, 8, 8]\n assert candidate(n = 50,logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31], [32, 32], [33, 33], [34, 34], [35, 35], [36, 36], [37, 37], [38, 38], [39, 39], [40, 40], [41, 41], [42, 42], [43, 43], [44, 44], [45, 45], [46, 46], [47, 47], [48, 48], [49, 49], [50, 50]],x = 5,queries = [6, 11, 16, 21, 26, 31, 36, 41, 46, 51]) == [44, 44, 44, 44, 44, 44, 44, 44, 44, 45]\n assert candidate(n = 6,logs = [[1, 5], [1, 6], [1, 7], [2, 8], [2, 9], [3, 10], [3, 11], [4, 12], [4, 13], [5, 14], [5, 15], [6, 16], [6, 17]],x = 5,queries = [10, 15, 20, 25]) == [3, 3, 4, 6]\n assert candidate(n = 8,logs = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [1, 18], [2, 20]],x = 10,queries = [25, 30, 35]) == [5, 7, 8]\n assert candidate(n = 20,logs = [[1, 100], [2, 100], [3, 100], [4, 100], [5, 100], [6, 100], [7, 100], [8, 100], [9, 100], [10, 100], [11, 100], [12, 100], [13, 100], [14, 100], [15, 100], [16, 100], [17, 100], [18, 100], [19, 100], [20, 100]],x = 50,queries = [150, 200, 250]) == [0, 20, 20]\n assert candidate(n = 5,logs = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9]],x = 5,queries = [6, 10]) == [3, 0]\n assert candidate(n = 10,logs = [[1, 10], [1, 20], [1, 30], [2, 15], [2, 25], [3, 10], [3, 20], [4, 10], [4, 30], [5, 5], [5, 15], [5, 25], [5, 35]],x = 10,queries = [20, 25, 30, 35, 40]) == [5, 6, 5, 6, 7]\n assert candidate(n = 8,logs = [[1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45]],x = 5,queries = [15, 25, 35, 45]) == [6, 6, 6, 6]\n assert candidate(n = 10,logs = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],x = 1,queries = [2, 3]) == [0, 5]\n", "comparison": "exact"}, "public_tests": ["3\n[[1,3],[2,6],[1,5]]\n5\n[10,11]", "3\n[[2,4],[2,1],[1,2],[3,1]]\n2\n[3,4]"], "hints": ["Can we use sorting and two-pointer approach here?", "Sort the queries array and logs array based on time in increasing order.", "For every window of size x, use sliding window and two-pointer approach to find the answer to the queries."], "metadata": {"canonical_parameter_names": ["n", "logs", "x", "queries"], "leetcode_dataset_entry_point": "Solution().countServers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:05+00:00", "tests_total": 92, "tests_dropped": 33, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def count_servers(n, logs, x, queries)", "container": null, "callable": "count_servers", "parameters": [{"name": "n", "type": "Integer"}, {"name": "logs", "type": "Integer[][]"}, {"name": "x", "type": "Integer"}, {"name": "queries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2748, "task_id": "number-of-beautiful-pairs", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <= i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime.\n\nReturn the total number of beautiful pairs in nums.\n\nTwo integers x and y are coprime if there is no integer greater than 1 that divides both of them. In other words, x and y are coprime if gcd(x, y) == 1, where gcd(x, y) is the greatest common divisor of x and y.\n\nExample 1:\n\nInput: nums = [2,5,1,4]\nOutput: 5\nExplanation: There are 5 beautiful pairs in nums:\nWhen i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1.\nWhen i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1.\nWhen i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1.\nWhen i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1.\nWhen i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1.\nThus, we return 5.\n\nExample 2:\n\nInput: nums = [11,21,12]\nOutput: 2\nExplanation: There are 2 beautiful pairs:\nWhen i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1.\nWhen i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1.\nThus, we return 2.\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 9999\n- nums[i] % 10 != 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [34, 23, 12, 45, 56]) == 5\n assert candidate(nums = [33, 14, 25, 78]) == 5\n assert candidate(nums = [123, 456, 789, 101, 202]) == 9\n assert candidate(nums = [13, 31, 17, 71]) == 6\n assert candidate(nums = [111, 222, 333, 444]) == 5\n assert candidate(nums = [34, 23, 12, 45]) == 4\n assert candidate(nums = [12, 23, 34, 45, 56]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5]) == 9\n assert candidate(nums = [11, 21, 12]) == 2\n assert candidate(nums = [2, 5, 1, 4]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 27\n assert candidate(nums = [29, 97, 79, 92]) == 4\n assert candidate(nums = [123, 456, 789, 101]) == 6\n assert candidate(nums = [33, 14, 25, 77]) == 6\n assert candidate(nums = [987, 876, 765, 654, 543]) == 6\n assert candidate(nums = [98, 17, 31, 44]) == 6\n assert candidate(nums = [991, 992, 993, 994, 995, 996, 997, 998, 999]) == 21\n assert candidate(nums = [12, 21, 13, 31, 14, 41, 15, 51, 16, 61]) == 41\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91]) == 17\n assert candidate(nums = [111, 222, 333, 444, 555]) == 9\n assert candidate(nums = [31, 73, 17, 79, 97, 37, 71, 13, 39]) == 23\n assert candidate(nums = [2468, 1357, 8642, 7531, 9753]) == 9\n assert candidate(nums = [22, 44, 88, 16, 32, 64]) == 3\n assert candidate(nums = [135, 246, 357, 468, 579, 681, 792, 813, 924]) == 25\n assert candidate(nums = [9876, 8765, 7654, 6543, 5432, 4321]) == 11\n assert candidate(nums = [12, 23, 34, 45, 56, 67, 78, 89, 91]) == 27\n assert candidate(nums = [1234, 2345, 3456, 4567, 5678]) == 7\n assert candidate(nums = [9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9989, 9988, 9987, 9986]) == 40\n assert candidate(nums = [1234, 5678, 9101, 1112, 1314]) == 10\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == 27\n assert candidate(nums = [987, 654, 321, 111, 222]) == 9\n assert candidate(nums = [123, 456, 789, 101, 112, 131]) == 14\n assert candidate(nums = [6789, 5678, 4567, 3456, 2345, 1234]) == 8\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 27\n assert candidate(nums = [123, 456, 789, 101, 202]) == 9\n assert candidate(nums = [9876, 5432, 1234, 5678, 9012]) == 10\n assert candidate(nums = [8888, 7777, 6666, 5555]) == 5\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 27\n assert candidate(nums = [999, 888, 777, 666, 555, 444]) == 11\n assert candidate(nums = [2357, 1113, 1719, 2329, 3137]) == 10\n assert candidate(nums = [135, 246, 357, 468, 579]) == 8\n assert candidate(nums = [29, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79]) == 57\n assert candidate(nums = [19, 29, 39, 49, 59, 69, 79, 89, 97, 98, 96, 95, 94, 93, 92, 91]) == 85\n assert candidate(nums = [1234, 4321, 5678, 8765, 9012]) == 6\n assert candidate(nums = [1234, 4321, 5678, 8765, 9876]) == 6\n assert candidate(nums = [101, 203, 305, 407, 509]) == 9\n assert candidate(nums = [9876, 8765, 7654, 6543, 5432]) == 6\n assert candidate(nums = [13, 31, 37, 73, 79, 97]) == 9\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == 27\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 246, 642]) == 16\n assert candidate(nums = [1009, 2008, 3007, 4006, 5005]) == 8\n assert candidate(nums = [89, 97, 75, 53, 31, 19, 98, 87]) == 23\n assert candidate(nums = [113, 224, 335, 446, 557]) == 8\n assert candidate(nums = [101, 234, 357, 479, 591]) == 9\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 27\n assert candidate(nums = [1111, 2223, 3335, 4447]) == 6\n assert candidate(nums = [1234, 5678, 9101, 1121, 2132, 3143]) == 14\n assert candidate(nums = [911, 822, 733, 644, 555, 466]) == 10\n assert candidate(nums = [19, 28, 37, 46, 55, 64, 73, 82, 91]) == 27\n assert candidate(nums = [89, 97, 103, 107, 109]) == 8\n assert candidate(nums = [111, 222, 333, 444, 555, 666]) == 11\n assert candidate(nums = [99, 88, 77, 66, 55, 44, 33, 22, 11]) == 27\n assert candidate(nums = [101, 202, 303, 404, 505]) == 9\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909]) == 27\n assert candidate(nums = [987, 654, 321, 123, 456, 789]) == 6\n assert candidate(nums = [9998, 7775, 5552, 3337, 1111]) == 9\n", "comparison": "exact"}, "public_tests": ["[2,5,1,4]", "[11,21,12]"], "hints": ["Since nums.length is small, you can find all pairs of indices and check if each pair is beautiful.", "Use integer to string conversion to get the first and last digit of each number."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countBeautifulPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:07+00:00", "tests_total": 102, "tests_dropped": 36, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def count_beautiful_pairs(nums)", "container": null, "callable": "count_beautiful_pairs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2749, "task_id": "minimum-operations-to-make-the-integer-zero", "difficulty": "Medium", "problem_description": "You are given two integers num1 and num2.\n\nIn one operation, you can choose integer i in the range [0, 60] and subtract 2^i + num2 from num1.\n\nReturn the integer denoting the minimum number of operations needed to make num1 equal to 0.\n\nIf it is impossible to make num1 equal to 0, return -1.\n\nExample 1:\n\nInput: num1 = 3, num2 = -2\nOutput: 3\nExplanation: We can make 3 equal to 0 with the following operations:\n- We choose i = 2 and subtract 2^2 + (-2) from 3, 3 - (4 + (-2)) = 1.\n- We choose i = 2 and subtract 2^2 + (-2) from 1, 1 - (4 + (-2)) = -1.\n- We choose i = 0 and subtract 2^0 + (-2) from -1, (-1) - (1 + (-2)) = 0.\nIt can be proven, that 3 is the minimum number of operations that we need to perform.\n\nExample 2:\n\nInput: num1 = 5, num2 = 7\nOutput: -1\nExplanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation.\n\nConstraints:\n\n- 1 <= num1 <= 10^9\n- -10^9 <= num2 <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num1 = 8,num2 = 2) == 2\n assert candidate(num1 = 8,num2 = -1) == 2\n assert candidate(num1 = 7,num2 = -3) == 3\n assert candidate(num1 = 1,num2 = 0) == 1\n assert candidate(num1 = 15,num2 = -3) == 3\n assert candidate(num1 = 10,num2 = -3) == 2\n assert candidate(num1 = 1,num2 = 1) == -1\n assert candidate(num1 = 15,num2 = -5) == 4\n assert candidate(num1 = 31,num2 = -2) == 3\n assert candidate(num1 = 123456789,num2 = 987654321) == -1\n assert candidate(num1 = 100,num2 = -10) == 3\n assert candidate(num1 = 64,num2 = -1) == 2\n assert candidate(num1 = 1000000000,num2 = -1000000000) == 12\n assert candidate(num1 = 5,num2 = 7) == -1\n assert candidate(num1 = 3,num2 = -2) == 3\n assert candidate(num1 = 10,num2 = -1) == 2\n assert candidate(num1 = 8,num2 = -3) == 3\n assert candidate(num1 = 1048576,num2 = -512) == 2\n assert candidate(num1 = 1000000000,num2 = 1) == 19\n assert candidate(num1 = 1,num2 = 2) == -1\n assert candidate(num1 = 123456789,num2 = 10000000) == -1\n assert candidate(num1 = 1048576,num2 = -1024) == 2\n assert candidate(num1 = 1024,num2 = -255) == 8\n assert candidate(num1 = 127,num2 = -1) == 1\n assert candidate(num1 = 123456789,num2 = -987654321) == 16\n assert candidate(num1 = 1000000000,num2 = -500000000) == 11\n assert candidate(num1 = 511,num2 = -1) == 1\n assert candidate(num1 = 536870912,num2 = 268435456) == 1\n assert candidate(num1 = 999999999,num2 = -999999998) == 17\n assert candidate(num1 = 32767,num2 = -2) == 3\n assert candidate(num1 = 63,num2 = -1) == 1\n assert candidate(num1 = 262143,num2 = 1) == 15\n assert candidate(num1 = 1023,num2 = -10) == 5\n assert candidate(num1 = 1000000000,num2 = -999999999) == 19\n assert candidate(num1 = 999999999,num2 = 0) == 21\n assert candidate(num1 = 1023,num2 = 1) == 7\n assert candidate(num1 = 1048575,num2 = -1) == 1\n assert candidate(num1 = 2047,num2 = -2) == 3\n assert candidate(num1 = 513,num2 = 2) == 7\n assert candidate(num1 = 16383,num2 = 1) == 11\n assert candidate(num1 = 1000000000,num2 = 100000000) == -1\n assert candidate(num1 = 2,num2 = -2) == 1\n assert candidate(num1 = 682,num2 = -1) == 6\n assert candidate(num1 = 1023,num2 = -1) == 1\n assert candidate(num1 = 4095,num2 = 3) == 9\n assert candidate(num1 = 63,num2 = -31) == 5\n assert candidate(num1 = 1048576,num2 = -65536) == 2\n assert candidate(num1 = 98765,num2 = -49382) == 9\n assert candidate(num1 = 2048,num2 = -1024) == 2\n assert candidate(num1 = 511,num2 = -255) == 7\n assert candidate(num1 = 4095,num2 = -10) == 5\n assert candidate(num1 = 2048,num2 = 512) == 2\n assert candidate(num1 = 100,num2 = 50) == -1\n assert candidate(num1 = 1023,num2 = -3) == 3\n assert candidate(num1 = 1024,num2 = 0) == 1\n assert candidate(num1 = 15,num2 = 1) == 3\n assert candidate(num1 = 524287,num2 = -2) == 3\n assert candidate(num1 = 15,num2 = 3) == 2\n assert candidate(num1 = 131071,num2 = -1) == 1\n assert candidate(num1 = 1048575,num2 = 3) == 17\n assert candidate(num1 = 1024,num2 = -128) == 2\n assert candidate(num1 = 128,num2 = -32) == 2\n assert candidate(num1 = 2048,num2 = 1024) == 1\n assert candidate(num1 = 2048,num2 = -512) == 2\n assert candidate(num1 = 255,num2 = -1) == 1\n assert candidate(num1 = 1048576,num2 = 1048576) == -1\n assert candidate(num1 = 987654321,num2 = -98765432) == 12\n assert candidate(num1 = 65535,num2 = 3) == 13\n assert candidate(num1 = 999999999,num2 = 1) == 19\n assert candidate(num1 = 42,num2 = -21) == 5\n assert candidate(num1 = 1048576,num2 = 1048575) == 1\n assert candidate(num1 = 1024,num2 = -100) == 4\n assert candidate(num1 = 1000000000,num2 = -100000000) == 12\n assert candidate(num1 = 512,num2 = -512) == 1\n assert candidate(num1 = 127,num2 = -2) == 3\n assert candidate(num1 = 1000,num2 = 333) == -1\n assert candidate(num1 = 500000000,num2 = 250000000) == -1\n assert candidate(num1 = 1048576,num2 = -262144) == 2\n assert candidate(num1 = 1048576,num2 = -524288) == 2\n assert candidate(num1 = 31,num2 = -1) == 1\n assert candidate(num1 = 1048576,num2 = -1) == 2\n assert candidate(num1 = 2,num2 = 1) == 1\n assert candidate(num1 = 100000,num2 = 10000) == 6\n assert candidate(num1 = 15,num2 = -1) == 1\n assert candidate(num1 = 999999999,num2 = 1000000000) == -1\n assert candidate(num1 = 1048576,num2 = 1024) == 8\n assert candidate(num1 = 1023,num2 = -512) == 11\n assert candidate(num1 = 268435456,num2 = -33554432) == 2\n assert candidate(num1 = 999999999,num2 = -999999999) == 17\n assert candidate(num1 = 1048576,num2 = -1048576) == 1\n assert candidate(num1 = 1,num2 = -1000000000) == 13\n assert candidate(num1 = 512,num2 = -256) == 2\n assert candidate(num1 = 63,num2 = 1) == 5\n assert candidate(num1 = 1048576,num2 = 1) == 16\n assert candidate(num1 = 255,num2 = 3) == 5\n assert candidate(num1 = 1048576,num2 = -1000) == 8\n assert candidate(num1 = 1048576,num2 = 0) == 1\n assert candidate(num1 = 1024,num2 = 512) == 1\n assert candidate(num1 = 1000000000,num2 = 500000000) == -1\n assert candidate(num1 = 1,num2 = -1) == 1\n assert candidate(num1 = 1023,num2 = -511) == 7\n assert candidate(num1 = 123456789,num2 = 123456789) == -1\n assert candidate(num1 = 8191,num2 = -1) == 1\n assert candidate(num1 = 1048575,num2 = 1) == 18\n assert candidate(num1 = 134217727,num2 = -1) == 1\n assert candidate(num1 = 999999999,num2 = 100000000) == -1\n assert candidate(num1 = 500000000,num2 = 500000000) == -1\n assert candidate(num1 = 123456789,num2 = -98765432) == 12\n", "comparison": "exact"}, "public_tests": ["3\n-2", "5\n7"], "hints": ["If we want to make integer n equal to 0 by only subtracting powers of 2 from n, in how many operations can we achieve it?", "We need at least - the number of bits in the binary representation of n, and at most - n.", "Notice that, if it is possible to make num1 equal to 0, then we need at most 60 operations.", "Iterate on the number of operations."], "metadata": {"canonical_parameter_names": ["num1", "num2"], "leetcode_dataset_entry_point": "Solution().makeTheIntegerZero", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:09+00:00", "tests_total": 122, "tests_dropped": 14, "flags": [], "topic_tags": ["bit-manipulation", "brainteaser", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def make_the_integer_zero(num1, num2)", "container": null, "callable": "make_the_integer_zero", "parameters": [{"name": "num1", "type": "Integer"}, {"name": "num2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2750, "task_id": "ways-to-split-array-into-good-subarrays", "difficulty": "Medium", "problem_description": "You are given a binary array nums.\n\nA subarray of an array is good if it contains exactly one element with the value 1.\n\nReturn an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 10^9 + 7.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [0,1,0,0,1]\nOutput: 3\nExplanation: There are 3 ways to split nums into good subarrays:\n- [0,1] [0,0,1]\n- [0,1,0] [0,1]\n- [0,1,0,0] [1]\n\nExample 2:\n\nInput: nums = [0,1,0]\nOutput: 1\nExplanation: There is 1 way to split nums into good subarrays:\n- [0,1,0]\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 0, 1]) == 3\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 1]) == 8\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1]) == 9\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0]) == 1\n assert candidate(nums = [0, 1, 0]) == 1\n assert candidate(nums = [0, 0, 0, 1]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 63\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1]) == 60\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1]) == 63\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 38\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]) == 75\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]) == 96\n assert candidate(nums = [1, 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, 1]) == 31\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 59049\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) == 25\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1]) == 36\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]) == 900\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 16\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1]) == 423\n assert candidate(nums = [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 36\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 128\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0]) == 60\n assert candidate(nums = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]) == 41\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 17\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]) == 25\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 39\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 43\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 32\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 18\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 59049\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 128\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 16\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 100\n assert candidate(nums = [0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]) == 30\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 32\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 60\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 320\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 22\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 17\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 54\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]) == 4096\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 486\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 1]) == 8\n assert candidate(nums = [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, 1, 0, 1]) == 16384\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]) == 9\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 19683\n assert candidate(nums = [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1]) == 49\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 15\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 729\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 177147\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 147\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 19\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 17\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]) == 16\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]) == 288\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 729\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 47\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 20\n assert candidate(nums = [1, 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, 1]) == 29\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 32\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2048\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1]) == 288\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0]) == 20\n assert candidate(nums = [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, 1, 0, 1, 0]) == 16384\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 110\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]) == 18\n assert candidate(nums = [1, 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, 1]) == 30\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]) == 16\n assert candidate(nums = [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, 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, 1]) == 268435456\n", "comparison": "exact"}, "public_tests": ["[0,1,0,0,1]", "[0,1,0]"], "hints": ["If the array consists of only 0s answer is 0.", "In the final split, exactly one separation point exists between two consecutive 1s.", "In how many ways can separation points be put?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().numberOfGoodSubarraySplits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:12+00:00", "tests_total": 87, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_good_subarray_splits(nums)", "container": null, "callable": "number_of_good_subarray_splits", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2751, "task_id": "robot-collisions", "difficulty": "Hard", "problem_description": "There are n 1-indexed robots, each having a position on a line, health, and movement direction.\n\nYou are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique.\n\nAll robots start moving on the line simultaneously at the same speed in their given directions. If two robots ever share the same position while moving, they will collide.\n\nIf two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.\n\nYour task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final health of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.\n\nReturn an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.\n\nNote: The positions may be unsorted.\n\nExample 1:\n\nInput: positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = \"RRRRR\"\nOutput: [2,17,9,15,10]\nExplanation: No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].\n\nExample 2:\n\nInput: positions = [3,5,2,6], healths = [10,10,15,12], directions = \"RLRL\"\nOutput: [14]\nExplanation: There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].\n\nExample 3:\n\nInput: positions = [1,2,5,6], healths = [10,10,11,11], directions = \"RLRL\"\nOutput: []\nExplanation: Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].\n\nConstraints:\n\n- 1 <= positions.length == healths.length == directions.length == n <= 10^5\n- 1 <= positions[i], healths[i] <= 10^9\n- directions[i] == 'L' or directions[i] == 'R'\n- All values in positions are distinct\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(positions = [2, 4, 6, 8, 10],healths = [30, 25, 20, 15, 10],directions = \"LLRRR\") == [30, 25, 20, 15, 10]\n assert candidate(positions = [2, 4, 6, 8],healths = [1, 2, 3, 4],directions = \"LLLL\") == [1, 2, 3, 4]\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [2, 17, 9, 15, 10],directions = \"RRRRR\") == [2, 17, 9, 15, 10]\n assert candidate(positions = [1, 2, 3, 4],healths = [10, 20, 30, 40],directions = \"RLRL\") == [19, 39]\n assert candidate(positions = [100, 200, 300],healths = [10, 20, 30],directions = \"LRL\") == [10, 29]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [5, 5, 5, 5, 5],directions = \"RRRLR\") == [5, 5, 5]\n assert candidate(positions = [10, 20, 30],healths = [1, 2, 3],directions = \"RRR\") == [1, 2, 3]\n assert candidate(positions = [1, 2, 3, 4, 5, 6],healths = [1, 2, 3, 4, 5, 6],directions = \"RRLLRR\") == [1, 4, 5, 6]\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [5, 8, 2, 6, 4],directions = \"RRRLL\") == [5, 6]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [1, 2, 3, 4, 5],directions = \"RRRRR\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [10, 10, 10, 10, 10],directions = \"RLRLR\") == [10]\n assert candidate(positions = [10, 20, 30, 40],healths = [1, 1, 1, 1],directions = \"RRRR\") == [1, 1, 1, 1]\n assert candidate(positions = [1, 3, 5, 7],healths = [5, 5, 5, 5],directions = \"RLRL\") == []\n assert candidate(positions = [10, 20, 30],healths = [3, 2, 1],directions = \"LLL\") == [3, 2, 1]\n assert candidate(positions = [4, 2, 6, 8],healths = [5, 5, 5, 5],directions = \"LRLR\") == [5, 5]\n assert candidate(positions = [6, 5, 4, 3, 2, 1],healths = [6, 5, 4, 3, 2, 1],directions = \"LLRRLL\") == [6, 3, 2, 1]\n assert candidate(positions = [50, 40, 30, 20, 10],healths = [1, 2, 3, 4, 5],directions = \"LLLLL\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [10, 9, 8, 7, 6],directions = \"RRRLL\") == [10, 9, 6]\n assert candidate(positions = [50, 40, 30, 20, 10],healths = [1, 2, 3, 4, 5],directions = \"RRRRR\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [2, 3, 4, 5, 6],healths = [10, 9, 8, 7, 6],directions = \"LLLLL\") == [10, 9, 8, 7, 6]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [1, 2, 3, 4, 5],directions = \"RLRLR\") == [1, 3, 5]\n assert candidate(positions = [1, 10, 20, 30, 40],healths = [10, 9, 8, 7, 6],directions = \"RRRRR\") == [10, 9, 8, 7, 6]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [1, 2, 3, 4, 5],directions = \"LLRRL\") == [1, 2, 3]\n assert candidate(positions = [3, 5, 2, 6],healths = [10, 10, 15, 12],directions = \"RLRL\") == [14]\n assert candidate(positions = [1, 3, 5, 7],healths = [20, 15, 10, 5],directions = \"RRRR\") == [20, 15, 10, 5]\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [5, 10, 15, 20, 25],directions = \"RRRLL\") == [17, 25]\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [1, 3, 2, 4, 5],directions = \"RLRLR\") == [2, 3, 5]\n assert candidate(positions = [3, 5, 2, 6],healths = [10, 10, 15, 12],directions = \"RLRL\") == [14]\n assert candidate(positions = [2, 4, 6, 8, 10],healths = [5, 4, 3, 2, 1],directions = \"RRRRR\") == [5, 4, 3, 2, 1]\n assert candidate(positions = [1, 2, 5, 6],healths = [10, 10, 11, 11],directions = \"RLRL\") == []\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [2, 17, 9, 15, 10],directions = \"RRRRR\") == [2, 17, 9, 15, 10]\n assert candidate(positions = [1, 2, 5, 6],healths = [10, 10, 11, 11],directions = \"RLRL\") == []\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [5, 5, 5, 5, 5],directions = \"RLRLR\") == [5]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [1, 2, 3, 4, 5],directions = \"LLLLL\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [5, 10, 15, 20, 25],directions = \"RLLRR\") == [9, 15, 20, 25]\n assert candidate(positions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],healths = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],directions = \"LLRRLLRRLL\") == [10, 10]\n assert candidate(positions = [1, 10, 20, 30, 40, 50],healths = [10, 9, 8, 7, 6, 5],directions = \"RLRLRL\") == [9, 7, 5]\n assert candidate(positions = [10, 20, 30, 40, 50, 60],healths = [5, 4, 3, 2, 1, 6],directions = \"RLRLRL\") == []\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],directions = \"LRRLRLRLRL\") == [10, 11, 14, 16, 18]\n assert candidate(positions = [1, 10, 20, 30, 40],healths = [100, 50, 200, 150, 250],directions = \"RRRRL\") == [246]\n assert candidate(positions = [3, 6, 9, 12, 15, 18],healths = [100, 200, 300, 400, 500, 600],directions = \"RLRLRL\") == [199, 399, 599]\n assert candidate(positions = [100, 200, 300, 400, 500, 600, 700],healths = [1, 2, 3, 4, 5, 6, 7],directions = \"RLLRLRR\") == [1, 3, 4, 6, 7]\n assert candidate(positions = [5, 15, 25, 35, 45],healths = [10, 20, 30, 40, 50],directions = \"LRRRL\") == [10, 47]\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [1, 2, 3, 4, 5],directions = \"LLLLR\") == [1]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],directions = \"RRRRRRRRRL\") == [991]\n assert candidate(positions = [3, 7, 11, 15, 19],healths = [10, 15, 20, 25, 30],directions = \"RLRLR\") == [14, 24, 30]\n assert candidate(positions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"RRLLRRLLRR\") == [1, 2, 3, 6, 7, 10]\n assert candidate(positions = [20, 30, 40, 50, 60],healths = [100, 80, 90, 70, 60],directions = \"RRRRR\") == [100, 80, 90, 70, 60]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],directions = \"RRRRRLLLLL\") == []\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"LRRLLRRLLR\") == [1, 1]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [60, 70, 80, 90, 100],directions = \"LLLLL\") == [60, 70, 80, 90, 100]\n assert candidate(positions = [1, 3, 6, 8, 10],healths = [10, 15, 20, 25, 30],directions = \"RLRLR\") == [14, 24, 30]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"RRRRRRRRRR\") == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(positions = [5, 15, 25, 35, 45, 55],healths = [5, 10, 15, 20, 25, 30],directions = \"LRRRLR\") == [5, 22, 30]\n assert candidate(positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"RRRRRRRRRR\") == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(positions = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"LRRLLRLRLL\") == [10, 38, 50, 69, 89, 100]\n assert candidate(positions = [50, 40, 30, 20, 10],healths = [1, 2, 3, 4, 5],directions = \"RRRRR\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],healths = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],directions = \"RRLLLLRRLL\") == [10, 10]\n assert candidate(positions = [1, 5, 9, 13, 17],healths = [1, 2, 3, 4, 5],directions = \"RRRRR\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"RRRRRRRRRR\") == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(positions = [2, 5, 7, 10, 13, 16],healths = [10, 10, 10, 10, 10, 10],directions = \"LLRRLL\") == [10, 10]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5],directions = \"LRRRLLRLRL\") == [10, 47, 40, 29, 9]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [100, 90, 80, 70, 60],directions = \"RRRLL\") == [100, 90, 78]\n assert candidate(positions = [1, 3, 5, 7, 9, 11],healths = [100, 90, 80, 70, 60, 50],directions = \"RLRLRL\") == [99, 79, 59]\n assert candidate(positions = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"LRLRLRLRLR\") == [1, 2, 4, 6, 8, 10]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [5, 5, 5, 5, 5],directions = \"RLRLR\") == [5]\n assert candidate(positions = [2, 6, 10, 14, 18],healths = [5, 4, 3, 2, 1],directions = \"LLLLL\") == [5, 4, 3, 2, 1]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],directions = \"RLRLRLRLRL\") == [9, 7, 5, 3, 1]\n assert candidate(positions = [1, 6, 3, 8, 5, 10],healths = [1, 1, 1, 1, 1, 1],directions = \"RLRLRL\") == []\n assert candidate(positions = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"RRRRRRRRRR\") == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"RRLRLRLRLR\") == [1, 4, 6, 8, 10]\n assert candidate(positions = [1, 5, 10, 15, 20, 25, 30],healths = [30, 25, 20, 15, 10, 5, 1],directions = \"RRRRRLL\") == [30, 25, 20, 15, 8]\n assert candidate(positions = [3, 6, 9, 12, 15],healths = [15, 20, 25, 30, 35],directions = \"RRRLL\") == [27, 35]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],directions = \"RLRLRLRLRL\") == [99, 79, 59, 39, 19]\n assert candidate(positions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],healths = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],directions = \"LLLLLRRRRR\") == []\n assert candidate(positions = [5, 15, 25, 35, 45, 55],healths = [5, 10, 15, 20, 25, 30],directions = \"LRLRLR\") == [5, 14, 24, 30]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [5, 15, 25, 35, 45],directions = \"RLRLR\") == [14, 34, 45]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [100, 90, 80, 70, 60],directions = \"RLRLR\") == [99, 79, 60]\n assert candidate(positions = [50, 40, 30, 20, 10],healths = [1, 2, 3, 4, 5],directions = \"LLRRL\") == [1, 4, 5]\n assert candidate(positions = [100, 200, 300, 400, 500],healths = [1000, 900, 800, 700, 600],directions = \"RRRRR\") == [1000, 900, 800, 700, 600]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"RRRRRRRRRR\") == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"RRRRRRRRRL\") == [91]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"LRRRRRRRRR\") == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(positions = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],healths = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],directions = \"RRRRRRRRRR\") == [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]\n assert candidate(positions = [100, 90, 80, 70, 60],healths = [10, 20, 30, 40, 50],directions = \"LRRRL\") == [19, 30, 40, 50]\n assert candidate(positions = [5, 15, 25, 35, 45],healths = [10, 20, 30, 40, 50],directions = \"RLRLR\") == [19, 39, 50]\n assert candidate(positions = [100, 200, 300, 400, 500],healths = [50, 40, 30, 20, 10],directions = \"RLRLR\") == [49, 29, 10]\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [10, 9, 8, 7, 6],directions = \"RLRLR\") == [9, 7, 6]\n assert candidate(positions = [1, 2, 3, 4, 5],healths = [5, 5, 5, 5, 5],directions = \"LRRRL\") == [5, 5, 5]\n assert candidate(positions = [7, 6, 5, 4, 3, 2, 1],healths = [1, 1, 1, 1, 1, 1, 1],directions = \"RLRLRLR\") == [1]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"RLRRLLRLRR\") == [19, 48, 60, 79, 90, 100]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"RLRLRLRLRL\") == [19, 39, 59, 79, 99]\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [1, 2, 3, 4, 5],directions = \"LLLLL\") == [1, 2, 3, 4, 5]\n assert candidate(positions = [1, 5, 10, 15, 20, 25],healths = [1, 2, 3, 4, 5, 6],directions = \"RRLLLL\") == [1, 4, 5, 6]\n assert candidate(positions = [5, 10, 15, 20, 25, 30],healths = [5, 10, 15, 20, 25, 30],directions = \"RRRLLL\") == [17, 25, 30]\n assert candidate(positions = [1, 5, 9, 13, 17],healths = [2, 4, 6, 8, 10],directions = \"RRRLL\") == [5, 10]\n assert candidate(positions = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"RLRLRLRLRL\") == []\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [1, 10, 100, 1000, 10000],directions = \"LLLLL\") == [1, 10, 100, 1000, 10000]\n assert candidate(positions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"LRRLLRLRRL\") == [1, 2, 5, 6, 8]\n assert candidate(positions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"LLLLLLLLLL\") == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [100, 100, 100, 100, 100],directions = \"LLRLR\") == [100, 100, 100]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],directions = \"LLLLLLLLLL\") == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [1, 2, 3, 4, 5],directions = \"RRLLR\") == [1, 2, 3]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5],directions = \"RLRLRLRLRL\") == []\n assert candidate(positions = [8, 5, 2, 11, 14],healths = [10, 20, 30, 40, 50],directions = \"LRLLR\") == [30, 39, 50]\n assert candidate(positions = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10],healths = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],directions = \"RLRLRLRLRL\") == []\n assert candidate(positions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],healths = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],directions = \"LRRRRRRRRR\") == [9, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(positions = [1, 5, 3, 7, 9],healths = [9, 7, 5, 3, 1],directions = \"LRRLR\") == [9, 6, 5, 1]\n assert candidate(positions = [1, 10, 20, 30, 40],healths = [1, 2, 3, 4, 5],directions = \"RLLLL\") == [1, 3, 4, 5]\n assert candidate(positions = [5, 2, 9, 3, 8],healths = [10, 20, 15, 25, 30],directions = \"RLRLR\") == [10, 20, 15, 25, 30]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"LLLLLLLLLL\") == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [100, 200, 150, 50, 300],directions = \"RLRLR\") == [199, 149, 300]\n assert candidate(positions = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"LRRLRLRLRL\") == [1, 1]\n assert candidate(positions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],healths = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],directions = \"LRRRRRRRRR\") == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],directions = \"RLRLRLRLRL\") == [1, 3, 5, 7, 9]\n assert candidate(positions = [10, 5, 15, 20, 25],healths = [100, 50, 200, 300, 150],directions = \"RLRLL\") == [50, 298, 150]\n assert candidate(positions = [10, 20, 30, 40, 50],healths = [100, 90, 80, 70, 60],directions = \"RRRRR\") == [100, 90, 80, 70, 60]\n assert candidate(positions = [10, 20, 30, 40, 50, 60],healths = [1, 1, 1, 1, 1, 1],directions = \"RLRLRL\") == []\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"RLRLRLRLRL\") == []\n assert candidate(positions = [9, 7, 5, 3, 1],healths = [10, 20, 30, 40, 50],directions = \"LLLLL\") == [10, 20, 30, 40, 50]\n assert candidate(positions = [5, 4, 3, 2, 1],healths = [1, 2, 3, 4, 5],directions = \"RLRLR\") == [1, 2, 4]\n assert candidate(positions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],healths = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],directions = \"RLRLRLRLRL\") == []\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],directions = \"LLLLLLLLLL\") == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(positions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],healths = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],directions = \"RLLLLLLLLL\") == [91]\n assert candidate(positions = [1, 4, 6, 8, 10, 12],healths = [5, 12, 7, 10, 3, 8],directions = \"RLRLRR\") == [11, 9, 3, 8]\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],healths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],directions = \"RLRLRLRLRL\") == []\n assert candidate(positions = [100, 90, 80, 70, 60],healths = [5, 10, 15, 20, 25],directions = \"LLRRL\") == [13, 20, 25]\n assert candidate(positions = [1, 5, 9, 13, 17, 21, 25, 29],healths = [25, 25, 25, 25, 25, 25, 25, 25],directions = \"RLRLRLRL\") == []\n assert candidate(positions = [1, 2, 3, 4, 5, 6, 7, 8, 9],healths = [9, 8, 7, 6, 5, 4, 3, 2, 1],directions = \"LRRLLRLRL\") == [9, 8, 5, 3, 1]\n assert candidate(positions = [1, 2, 3, 4, 5, 6],healths = [6, 5, 4, 3, 2, 1],directions = \"RRLLLR\") == [6, 2, 1]\n assert candidate(positions = [1, 3, 5, 7, 9],healths = [2, 4, 6, 8, 10],directions = \"LRRLL\") == [2, 6, 10]\n assert candidate(positions = [1, 2, 3, 4, 5, 6],healths = [1, 2, 3, 4, 5, 6],directions = \"RRRRRR\") == [1, 2, 3, 4, 5, 6]\n assert candidate(positions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],healths = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],directions = \"RRRRRLLLLL\") == [7, 14, 16, 18, 20]\n assert candidate(positions = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],healths = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],directions = \"RLRLRLRLRL\") == [10, 29, 49, 69, 89, 100]\n assert candidate(positions = [5, 1, 9, 3, 7],healths = [10, 20, 30, 40, 50],directions = \"RLLRL\") == [20, 30, 48]\n", "comparison": "exact"}, "public_tests": ["[5,4,3,2,1]\n[2,17,9,15,10]\n\"RRRRR\"", "[3,5,2,6]\n[10,10,15,12]\n\"RLRL\"", "[1,2,5,6]\n[10,10,11,11]\n\"RLRL\""], "hints": ["Process the robots in the order of their positions to ensure that we process the collisions correctly.", "To optimize the solution, use a stack to keep track of the surviving robots as we iterate through the positions.", "Instead of simulating each collision, check the current robot against the top of the stack (if it exists) to determine if a collision occurs."], "metadata": {"canonical_parameter_names": ["positions", "healths", "directions"], "leetcode_dataset_entry_point": "Solution().survivedRobotsHealths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:14+00:00", "tests_total": 138, "tests_dropped": 3, "flags": ["has_images"], "topic_tags": ["array", "stack", "sorting", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def survived_robots_healths(positions, healths, directions)", "container": null, "callable": "survived_robots_healths", "parameters": [{"name": "positions", "type": "Integer[]"}, {"name": "healths", "type": "Integer[]"}, {"name": "directions", "type": "String"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2760, "task_id": "longest-even-odd-subarray-with-threshold", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums and an integer threshold.\n\nFind the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:\n\n- nums[l] % 2 == 0\n- For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2\n- For all indices i in the range [l, r], nums[i] <= threshold\n\nReturn an integer denoting the length of the longest such subarray.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [3,2,5,4], threshold = 5\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n\nExample 2:\n\nInput: nums = [1,2], threshold = 2\nOutput: 1\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].\nIt satisfies all the conditions and we can show that 1 is the maximum possible achievable length.\n\nExample 3:\n\nInput: nums = [2,3,4,5], threshold = 4\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].\nIt satisfies all the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n- 1 <= threshold <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 10) == 9\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 10\n assert candidate(nums = [2, 3, 4, 5],threshold = 4) == 3\n assert candidate(nums = [6, 1, 3, 8, 2, 9],threshold = 8) == 2\n assert candidate(nums = [50, 51, 50, 51, 50],threshold = 51) == 5\n assert candidate(nums = [1],threshold = 1) == 0\n assert candidate(nums = [3, 2, 5, 4],threshold = 5) == 3\n assert candidate(nums = [2, 4, 6, 8, 10],threshold = 10) == 1\n assert candidate(nums = [1, 2],threshold = 2) == 1\n assert candidate(nums = [2, 4, 6, 8, 10],threshold = 5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 5) == 4\n assert candidate(nums = [6, 5, 4, 3, 2, 1],threshold = 6) == 6\n assert candidate(nums = [100, 99, 98, 97, 96],threshold = 100) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 25) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],threshold = 10) == 0\n assert candidate(nums = [100, 99, 98, 97, 96, 95],threshold = 100) == 6\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],threshold = 15) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],threshold = 15) == 14\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],threshold = 3) == 28\n assert candidate(nums = [2, 3, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14],threshold = 14) == 9\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69],threshold = 55) == 6\n assert candidate(nums = [2, 5, 10, 15, 20, 25, 30],threshold = 20) == 5\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 8) == 7\n assert candidate(nums = [5, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],threshold = 15) == 12\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],threshold = 95) == 5\n assert candidate(nums = [3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2],threshold = 5) == 23\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],threshold = 10) == 10\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],threshold = 95) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],threshold = 5) == 1\n assert candidate(nums = [4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],threshold = 4) == 16\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],threshold = 3) == 10\n assert candidate(nums = [4, 5, 4, 5, 4, 5, 4, 5, 4, 5],threshold = 4) == 1\n assert candidate(nums = [4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],threshold = 6) == 9\n assert candidate(nums = [50, 49, 50, 49, 50, 49, 50, 49, 50, 49],threshold = 50) == 10\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],threshold = 15) == 6\n assert candidate(nums = [85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70],threshold = 85) == 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],threshold = 50) == 50\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 12\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16],threshold = 8) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],threshold = 10) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],threshold = 20) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],threshold = 25) == 24\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1],threshold = 15) == 14\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],threshold = 15) == 1\n assert candidate(nums = [99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100],threshold = 100) == 19\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],threshold = 15) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],threshold = 20) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],threshold = 2) == 1\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],threshold = 15) == 8\n assert candidate(nums = [50, 49, 50, 49, 50, 49, 50, 49, 50, 49],threshold = 50) == 10\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11],threshold = 10) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],threshold = 20) == 2\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],threshold = 15) == 12\n assert candidate(nums = [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],threshold = 28) == 25\n assert candidate(nums = [3, 6, 7, 8, 5, 4, 3, 2, 1],threshold = 7) == 4\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2],threshold = 3) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 8) == 7\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],threshold = 2) == 20\n assert candidate(nums = [97, 96, 95, 94, 93, 92, 91, 90, 89, 88],threshold = 95) == 7\n assert candidate(nums = [8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9],threshold = 9) == 20\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10],threshold = 15) == 5\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],threshold = 20) == 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],threshold = 16) == 15\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],threshold = 90) == 11\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],threshold = 20) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 10) == 10\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 10, 11],threshold = 11) == 8\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],threshold = 21) == 19\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],threshold = 95) == 5\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],threshold = 10) == 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],threshold = 20) == 19\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],threshold = 30) == 29\n assert candidate(nums = [6, 7, 8, 9, 10, 11, 12, 13, 14],threshold = 12) == 7\n assert candidate(nums = [8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9],threshold = 9) == 12\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 20\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31],threshold = 50) == 20\n assert candidate(nums = [100, 99, 100, 99, 100, 99, 100, 99, 100, 99],threshold = 100) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 5) == 4\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10],threshold = 10) == 9\n assert candidate(nums = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10, 5, 10],threshold = 10) == 45\n assert candidate(nums = [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],threshold = 2) == 39\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 10) == 9\n assert candidate(nums = [2, 1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10],threshold = 12) == 9\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 10) == 10\n assert candidate(nums = [42, 41, 42, 41, 42, 41, 42, 41, 42, 41, 42, 41, 42, 41, 42, 41],threshold = 42) == 16\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],threshold = 25) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],threshold = 1) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],threshold = 10) == 0\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],threshold = 8) == 7\n assert candidate(nums = [2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18],threshold = 18) == 15\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],threshold = 100) == 21\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2],threshold = 5) == 29\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],threshold = 25) == 24\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5],threshold = 6) == 14\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],threshold = 2) == 10\n assert candidate(nums = [60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46],threshold = 55) == 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],threshold = 10) == 9\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],threshold = 3) == 19\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],threshold = 3) == 14\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 10) == 13\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],threshold = 18) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],threshold = 20) == 19\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],threshold = 10) == 1\n assert candidate(nums = [2, 1, 3, 2, 1, 4, 5, 6, 7, 8],threshold = 5) == 4\n assert candidate(nums = [100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99],threshold = 100) == 20\n assert candidate(nums = [1, 3, 5, 7, 2, 8, 6, 4],threshold = 8) == 1\n assert candidate(nums = [8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30],threshold = 30) == 23\n assert candidate(nums = [2, 5, 4, 7, 6, 9, 8, 11, 10],threshold = 10) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],threshold = 15) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],threshold = 100) == 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, 21],threshold = 20) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 7) == 6\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],threshold = 2) == 1\n assert candidate(nums = [5, 8, 7, 6, 5, 4, 3, 2, 1, 100, 99, 98],threshold = 100) == 11\n assert candidate(nums = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52],threshold = 49) == 8\n assert candidate(nums = [42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43],threshold = 43) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 20],threshold = 20) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88],threshold = 95) == 7\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60],threshold = 58) == 9\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],threshold = 20) == 11\n", "comparison": "exact"}, "public_tests": ["[3,2,5,4]\n5", "[1,2]\n2", "[2,3,4,5]\n4"], "hints": ["Brute force all the possible subarrays and find the longest that satisfies the conditions."], "metadata": {"canonical_parameter_names": ["nums", "threshold"], "leetcode_dataset_entry_point": "Solution().longestAlternatingSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:17+00:00", "tests_total": 124, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def longest_alternating_subarray(nums, threshold)", "container": null, "callable": "longest_alternating_subarray", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "threshold", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2761, "task_id": "prime-pairs-with-target-sum", "difficulty": "Medium", "problem_description": "You are given an integer n. We say that two integers x and y form a prime number pair if:\n\n- 1 <= x <= y <= n\n- x + y == n\n- x and y are prime numbers\n\nReturn the 2D sorted list of prime number pairs [x_i, y_i]. The list should be sorted in increasing order of x_i. If there are no prime number pairs at all, return an empty array.\n\nNote: A prime number is a natural number greater than 1 with only two factors, itself and 1.\n\nExample 1:\n\nInput: n = 10\nOutput: [[3,7],[5,5]]\nExplanation: In this example, there are two prime pairs that satisfy the criteria.\nThese pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.\n\nExample 2:\n\nInput: n = 2\nOutput: []\nExplanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.\n\nConstraints:\n\n- 1 <= n <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 11) == []\n assert candidate(n = 20) == [[3, 17], [7, 13]]\n assert candidate(n = 2) == []\n assert candidate(n = 10) == [[3, 7], [5, 5]]\n assert candidate(n = 3) == []\n assert candidate(n = 29) == []\n assert candidate(n = 100) == [[3, 97], [11, 89], [17, 83], [29, 71], [41, 59], [47, 53]]\n assert candidate(n = 1000) == [[3, 997], [17, 983], [23, 977], [29, 971], [47, 953], [53, 947], [59, 941], [71, 929], [89, 911], [113, 887], [137, 863], [173, 827], [179, 821], [191, 809], [227, 773], [239, 761], [257, 743], [281, 719], [317, 683], [347, 653], [353, 647], [359, 641], [383, 617], [401, 599], [431, 569], [443, 557], [479, 521], [491, 509]]\n assert candidate(n = 50) == [[3, 47], [7, 43], [13, 37], [19, 31]]\n assert candidate(n = 56789) == []\n assert candidate(n = 300) == [[7, 293], [17, 283], [19, 281], [23, 277], [29, 271], [31, 269], [37, 263], [43, 257], [59, 241], [61, 239], [67, 233], [71, 229], [73, 227], [89, 211], [101, 199], [103, 197], [107, 193], [109, 191], [127, 173], [137, 163], [149, 151]]\n assert candidate(n = 5) == [[2, 3]]\n assert candidate(n = 333) == [[2, 331]]\n assert candidate(n = 60) == [[7, 53], [13, 47], [17, 43], [19, 41], [23, 37], [29, 31]]\n assert candidate(n = 28) == [[5, 23], [11, 17]]\n assert candidate(n = 1009) == []\n assert candidate(n = 30) == [[7, 23], [11, 19], [13, 17]]\n assert candidate(n = 40) == [[3, 37], [11, 29], [17, 23]]\n assert candidate(n = 4) == [[2, 2]]\n assert candidate(n = 37) == []\n assert candidate(n = 10000) == [[59, 9941], [71, 9929], [113, 9887], [149, 9851], [167, 9833], [197, 9803], [233, 9767], [251, 9749], [257, 9743], [281, 9719], [311, 9689], [449, 9551], [461, 9539], [467, 9533], [479, 9521], [503, 9497], [509, 9491], [521, 9479], [563, 9437], [569, 9431], [587, 9413], [659, 9341], [677, 9323], [719, 9281], [743, 9257], [761, 9239], [773, 9227], [797, 9203], [827, 9173], [839, 9161], [863, 9137], [941, 9059], [971, 9029], [1031, 8969], [1049, 8951], [1151, 8849], [1163, 8837], [1181, 8819], [1193, 8807], [1217, 8783], [1259, 8741], [1301, 8699], [1307, 8693], [1319, 8681], [1373, 8627], [1427, 8573], [1487, 8513], [1499, 8501], [1553, 8447], [1571, 8429], [1613, 8387], [1637, 8363], [1709, 8291], [1877, 8123], [1889, 8111], [1907, 8093], [1913, 8087], [1931, 8069], [2063, 7937], [2081, 7919], [2099, 7901], [2207, 7793], [2243, 7757], [2273, 7727], [2297, 7703], [2309, 7691], [2351, 7649], [2357, 7643], [2393, 7607], [2411, 7589], [2417, 7583], [2423, 7577], [2441, 7559], [2459, 7541], [2477, 7523], [2543, 7457], [2549, 7451], [2693, 7307], [2753, 7247], [2789, 7211], [2879, 7121], [2897, 7103], [2957, 7043], [2999, 7001], [3023, 6977], [3041, 6959], [3083, 6917], [3089, 6911], [3137, 6863], [3167, 6833], [3209, 6791], [3221, 6779], [3299, 6701], [3347, 6653], [3449, 6551], [3527, 6473], [3671, 6329], [3677, 6323], [3701, 6299], [3779, 6221], [3797, 6203], [3803, 6197], [3911, 6089], [3947, 6053], [3989, 6011], [4013, 5987], [4019, 5981], [4073, 5927], [4133, 5867], [4139, 5861], [4157, 5843], [4217, 5783], [4259, 5741], [4283, 5717], [4289, 5711], [4349, 5651], [4409, 5591], [4481, 5519], [4493, 5507], [4517, 5483], [4523, 5477], [4583, 5417], [4649, 5351], [4691, 5309], [4703, 5297], [4721, 5279], [4919, 5081]]\n assert candidate(n = 17) == []\n assert candidate(n = 1001) == []\n assert candidate(n = 200000) == [[67, 199933], [79, 199921], [127, 199873], [181, 199819], [193, 199807], [223, 199777], [271, 199729], [313, 199687], [331, 199669], [379, 199621], [397, 199603], [433, 199567], [499, 199501], [547, 199453], [571, 199429], [601, 199399], [643, 199357], [733, 199267], [739, 199261], [919, 199081], [967, 199033], [1033, 198967], [1063, 198937], [1171, 198829], [1231, 198769], [1327, 198673], [1429, 198571], [1447, 198553], [1471, 198529], [1531, 198469], [1609, 198391], [1663, 198337], [1699, 198301], [1723, 198277], [1741, 198259], [1759, 198241], [1777, 198223], [1861, 198139], [1873, 198127], [1987, 198013], [2029, 197971], [2053, 197947], [2113, 197887], [2221, 197779], [2287, 197713], [2311, 197689], [2521, 197479], [2617, 197383], [2659, 197341], [2689, 197311], [2707, 197293], [2731, 197269], [2767, 197233], [2797, 197203], [2917, 197083], [3121, 196879], [3163, 196837], [3169, 196831], [3229, 196771], [3301, 196699], [3313, 196687], [3319, 196681], [3343, 196657], [3457, 196543], [3499, 196501], [3541, 196459], [3547, 196453], [3571, 196429], [3613, 196387], [3697, 196303], [3709, 196291], [3823, 196177], [3889, 196111], [3919, 196081], [3967, 196033], [4003, 195997], [4027, 195973], [4093, 195907], [4219, 195781], [4261, 195739], [4507, 195493], [4657, 195343], [4723, 195277], [4729, 195271], [4759, 195241], [4951, 195049], [4957, 195043], [5011, 194989], [5023, 194977], [5101, 194899], [5233, 194767], [5347, 194653], [5419, 194581], [5431, 194569], [5479, 194521], [5521, 194479], [5557, 194443], [5569, 194431], [5623, 194377], [5647, 194353], [5737, 194263], [5821, 194179], [5851, 194149], [5881, 194119], [6007, 193993], [6043, 193957], [6211, 193789], [6229, 193771], [6277, 193723], [6337, 193663], [6397, 193603], [6427, 193573], [6451, 193549], [6553, 193447], [6577, 193423], [6607, 193393], [6619, 193381], [6673, 193327], [6907, 193093], [6949, 193051], [6991, 193009], [6997, 193003], [7039, 192961], [7069, 192931], [7219, 192781], [7243, 192757], [7333, 192667], [7369, 192631], [7417, 192583], [7537, 192463], [7681, 192319], [7741, 192259], [7867, 192133], [7879, 192121], [7963, 192037], [7993, 192007], [8089, 191911], [8101, 191899], [8167, 191833], [8209, 191791], [8293, 191707], [8311, 191689], [8329, 191671], [8467, 191533], [8527, 191473], [8539, 191461], [8647, 191353], [8719, 191281], [8839, 191161], [8863, 191137], [8929, 191071], [9091, 190909], [9109, 190891], [9157, 190843], [9241, 190759], [9283, 190717], [9343, 190657], [9421, 190579], [9463, 190537], [9613, 190387], [9631, 190369], [9643, 190357], [9661, 190339], [9679, 190321], [9739, 190261], [9871, 190129], [9907, 190093], [9949, 190051], [9973, 190027], [10039, 189961], [10099, 189901], [10141, 189859], [10177, 189823], [10243, 189757], [10267, 189733], [10303, 189697], [10357, 189643], [10453, 189547], [10477, 189523], [10567, 189433], [10639, 189361], [10651, 189349], [10663, 189337], [10729, 189271], [10771, 189229], [10831, 189169], [10861, 189139], [10939, 189061], [10957, 189043], [11047, 188953], [11059, 188941], [11131, 188869], [11173, 188827], [11299, 188701], [11437, 188563], [11467, 188533], [11527, 188473], [11593, 188407], [11677, 188323], [11689, 188311], [11701, 188299], [11719, 188281], [11821, 188179], [11863, 188137], [11971, 188029], [12037, 187963], [12049, 187951], [12073, 187927], [12157, 187843], [12289, 187711], [12301, 187699], [12487, 187513], [12577, 187423], [12583, 187417], [12613, 187387], [12697, 187303], [12763, 187237], [12781, 187219], [12823, 187177], [12829, 187171], [12889, 187111], [12919, 187081], [12973, 187027], [13159, 186841], [13267, 186733], [13291, 186709], [13381, 186619], [13399, 186601], [13417, 186583], [13729, 186271], [13789, 186211], [13903, 186097], [13963, 186037], [14029, 185971], [14083, 185917], [14107, 185893], [14251, 185749], [14293, 185707], [14323, 185677], [14401, 185599], [14407, 185593], [14431, 185569], [14449, 185551], [14461, 185539], [14533, 185467], [14629, 185371], [14767, 185233], [14779, 185221], [14851, 185149], [14869, 185131], [14923, 185077], [14929, 185071], [15031, 184969], [15121, 184879], [15289, 184711], [15307, 184693], [15313, 184687], [15331, 184669], [15349, 184651], [15373, 184627], [15391, 184609], [15511, 184489], [15559, 184441], [15583, 184417], [15649, 184351], [15667, 184333], [15679, 184321], [15727, 184273], [15889, 184111], [15913, 184087], [15919, 184081], [16057, 183943], [16339, 183661], [16363, 183637], [16477, 183523], [16561, 183439], [16603, 183397], [16651, 183349], [16657, 183343], [16693, 183307], [16699, 183301], [16741, 183259], [16963, 183037], [17047, 182953], [17107, 182893], [17299, 182701], [17341, 182659], [17359, 182641], [17383, 182617], [17401, 182599], [17491, 182509], [17497, 182503], [17569, 182431], [17659, 182341], [17761, 182239], [17791, 182209], [17911, 182089], [17959, 182041], [17971, 182029], [17989, 182011], [18043, 181957], [18097, 181903], [18127, 181873], [18211, 181789], [18223, 181777], [18289, 181711], [18307, 181693], [18397, 181603], [18451, 181549], [18541, 181459], [18757, 181243], [18787, 181213], [18859, 181141], [18913, 181087], [18919, 181081], [19051, 180949], [19207, 180793], [19249, 180751], [19333, 180667], [19489, 180511], [19609, 180391], [19753, 180247], [19759, 180241], [19819, 180181], [19927, 180073], [19993, 180007], [20011, 179989], [20047, 179953], [20101, 179899], [20173, 179827], [20341, 179659], [20407, 179593], [20521, 179479], [20563, 179437], [20593, 179407], [20719, 179281], [20731, 179269], [20857, 179143], [20959, 179041], [21013, 178987], [21061, 178939], [21067, 178933], [21169, 178831], [21187, 178813], [21193, 178807], [21247, 178753], [21319, 178681], [21379, 178621], [21391, 178609], [21397, 178603], [21433, 178567], [21487, 178513], [21499, 178501], [21559, 178441], [21649, 178351], [21673, 178327], [21739, 178261], [21751, 178249], [21817, 178183], [21859, 178141], [21961, 178039], [22051, 177949], [22093, 177907], [22111, 177889], [22159, 177841], [22189, 177811], [22447, 177553], [22567, 177433], [22573, 177427], [22621, 177379], [22699, 177301], [22717, 177283], [22777, 177223], [22783, 177217], [22993, 177007], [23011, 176989], [23017, 176983], [23143, 176857], [23203, 176797], [23209, 176791], [23371, 176629], [23497, 176503], [23539, 176461], [23581, 176419], [23599, 176401], [23671, 176329], [23773, 176227], [23911, 176089], [23977, 176023], [24007, 175993], [24061, 175939], [24091, 175909], [24103, 175897], [24109, 175891], [24247, 175753], [24337, 175663], [24379, 175621], [24481, 175519], [24547, 175453], [24691, 175309], [24697, 175303], [24709, 175291], [24733, 175267], [24859, 175141], [24919, 175081], [25057, 174943], [25171, 174829], [25237, 174763], [25321, 174679], [25633, 174367], [25741, 174259], [25759, 174241], [25933, 174067], [25939, 174061], [25951, 174049], [25981, 174019], [26083, 173917], [26161, 173839], [26227, 173773], [26293, 173707], [26317, 173683], [26371, 173629], [26641, 173359], [26737, 173263], [26863, 173137], [26947, 173053], [27031, 172969], [27067, 172933], [27241, 172759], [27259, 172741], [27283, 172717], [27337, 172663], [27367, 172633], [27397, 172603], [27427, 172573], [27481, 172519], [27847, 172153], [28111, 171889], [28123, 171877], [28201, 171799], [28429, 171571], [28447, 171553], [28573, 171427], [28597, 171403], [28729, 171271], [28837, 171163], [28909, 171091], [28921, 171079], [29101, 170899], [29173, 170827], [29191, 170809], [29251, 170749], [29311, 170689], [29443, 170557], [29527, 170473], [29587, 170413], [29611, 170389], [29629, 170371], [29761, 170239], [29803, 170197], [29833, 170167], [30013, 169987], [30091, 169909], [30109, 169891], [30169, 169831], [30211, 169789], [30223, 169777], [30307, 169693], [30319, 169681], [30367, 169633], [30469, 169531], [30517, 169483], [30529, 169471], [30631, 169369], [30661, 169339], [30757, 169243], [30781, 169219], [30841, 169159], [30871, 169129], [30931, 169069], [30937, 169063], [31063, 168937], [31219, 168781], [31231, 168769], [31327, 168673], [31357, 168643], [31477, 168523], [31543, 168457], [31567, 168433], [31723, 168277], [31849, 168151], [31873, 168127], [31891, 168109], [31957, 168043], [31963, 168037], [32029, 167971], [32083, 167917], [32089, 167911], [32191, 167809], [32323, 167677], [32359, 167641], [32377, 167623], [32479, 167521], [32563, 167437], [32587, 167413], [32779, 167221], [32803, 167197], [32887, 167113], [32983, 167017], [33013, 166987], [33091, 166909], [33151, 166849], [33331, 166669], [33343, 166657], [33391, 166609], [33403, 166597], [33529, 166471], [33601, 166399], [33637, 166363], [33703, 166297], [33811, 166189], [33937, 166063], [34039, 165961], [34123, 165877], [34171, 165829], [34183, 165817], [34297, 165703], [34327, 165673], [34537, 165463], [34543, 165457], [34603, 165397], [34651, 165349], [34687, 165313], [34819, 165181], [34897, 165103], [34963, 165037], [35089, 164911], [35107, 164893], [35257, 164743], [35317, 164683], [35323, 164677], [35401, 164599], [35419, 164581], [35569, 164431], [35809, 164191], [35851, 164149], [35911, 164089], [35977, 164023], [36007, 163993], [36013, 163987], [36073, 163927], [36229, 163771], [36373, 163627], [36433, 163567], [36457, 163543], [36523, 163477], [36583, 163417], [36607, 163393], [36637, 163363], [36691, 163309], [36871, 163129], [36973, 163027], [36979, 163021], [36997, 163003], [37003, 162997], [37171, 162829], [37273, 162727], [37309, 162691], [37423, 162577], [37447, 162553], [37483, 162517], [37501, 162499], [37507, 162493], [37549, 162451], [37561, 162439], [37657, 162343], [37993, 162007], [38053, 161947], [38119, 161881], [38239, 161761], [38317, 161683], [38431, 161569], [38593, 161407], [38677, 161323], [38737, 161263], [38767, 161233], [38833, 161167], [38851, 161149], [38953, 161047], [39019, 160981], [39097, 160903], [39139, 160861], [39313, 160687], [39373, 160627], [39397, 160603], [39409, 160591], [39769, 160231], [39799, 160201], [39841, 160159], [39883, 160117], [40063, 159937], [40129, 159871], [40189, 159811], [40213, 159787], [40231, 159769], [40237, 159763], [40429, 159571], [40459, 159541], [40531, 159469], [40543, 159457], [40597, 159403], [40639, 159361], [40801, 159199], [40903, 159097], [40927, 159073], [41077, 158923], [41269, 158731], [41389, 158611], [41593, 158407], [41641, 158359], [41659, 158341], [41887, 158113], [41953, 158047], [41983, 158017], [42169, 157831], [42187, 157813], [42331, 157669], [42373, 157627], [42457, 157543], [42487, 157513], [42571, 157429], [42589, 157411], [42649, 157351], [42697, 157303], [42709, 157291], [42727, 157273], [42793, 157207], [42859, 157141], [42943, 157057], [43159, 156841], [43177, 156823], [43201, 156799], [43321, 156679], [43399, 156601], [43411, 156589], [43579, 156421], [43759, 156241], [43783, 156217], [43891, 156109], [44179, 155821], [44203, 155797], [44269, 155731], [44281, 155719], [44293, 155707], [44491, 155509], [44587, 155413], [44617, 155383], [44623, 155377], [44683, 155317], [44701, 155299], [44797, 155203], [44809, 155191], [44839, 155161], [44917, 155083], [44953, 155047], [44983, 155017], [45127, 154873], [45247, 154753], [45319, 154681], [45427, 154573], [45541, 154459], [45613, 154387], [45631, 154369], [45667, 154333], [45697, 154303], [45757, 154243], [45817, 154183], [45841, 154159], [45943, 154057], [46051, 153949], [46183, 153817], [46237, 153763], [46261, 153739], [46351, 153649], [46411, 153589], [46471, 153529], [46477, 153523], [46489, 153511], [46573, 153427], [46591, 153409], [46663, 153337], [46681, 153319], [46687, 153313], [46723, 153277], [46867, 153133], [46933, 153067], [47041, 152959], [47059, 152941], [47143, 152857], [47149, 152851], [47161, 152839], [47581, 152419], [47623, 152377], [47713, 152287], [47797, 152203], [47917, 152083], [48091, 151909], [48187, 151813], [48271, 151729], [48313, 151687], [48397, 151603], [48463, 151537], [48523, 151477], [48571, 151429], [48619, 151381], [48661, 151339], [48757, 151243], [48787, 151213], [48799, 151201], [48847, 151153], [48859, 151141], [48973, 151027], [48991, 151009], [49009, 150991], [49033, 150967], [49081, 150919], [49117, 150883], [49279, 150721], [49393, 150607], [49411, 150589], [49417, 150583], [49429, 150571], [49477, 150523], [49627, 150373], [49783, 150217], [49789, 150211], [49807, 150193], [49831, 150169], [49939, 150061], [49999, 150001], [50047, 149953], [50101, 149899], [50287, 149713], [50311, 149689], [50377, 149623], [50497, 149503], [50503, 149497], [50581, 149419], [50839, 149161], [50857, 149143], [50923, 149077], [50989, 149011], [51043, 148957], [51109, 148891], [51133, 148867], [51217, 148783], [51307, 148693], [51361, 148639], [51421, 148579], [51427, 148573], [51487, 148513], [51517, 148483], [51613, 148387], [51721, 148279], [51829, 148171], [51853, 148147], [52051, 147949], [52081, 147919], [52147, 147853], [52189, 147811], [52201, 147799], [52291, 147709], [52387, 147613], [52453, 147547], [52543, 147457], [52609, 147391], [52711, 147289], [52747, 147253], [52837, 147163], [52861, 147139], [52903, 147097], [53017, 146983], [53047, 146953], [53233, 146767], [53281, 146719], [53299, 146701], [53323, 146677], [53353, 146647], [53419, 146581], [53437, 146563], [53479, 146521], [53551, 146449], [53593, 146407], [53611, 146389], [53617, 146383], [53653, 146347], [53923, 146077], [54013, 145987], [54037, 145963], [54121, 145879], [54139, 145861], [54181, 145819], [54193, 145807], [54277, 145723], [54319, 145681], [54367, 145633], [54469, 145531], [54499, 145501], [54541, 145459], [54559, 145441], [54577, 145423], [54583, 145417], [54601, 145399], [54787, 145213], [54979, 145021], [55117, 144883], [55171, 144829], [55243, 144757], [55249, 144751], [55291, 144709], [55333, 144667], [55411, 144589], [55621, 144379], [55711, 144289], [55837, 144163], [55897, 144103], [55927, 144073], [55987, 144013], [56053, 143947], [56167, 143833], [56179, 143821], [56209, 143791], [56383, 143617], [56431, 143569], [56473, 143527], [56533, 143467], [56599, 143401], [56671, 143329], [56713, 143287], [56737, 143263], [56893, 143107], [57037, 142963], [57097, 142903], [57163, 142837], [57241, 142759], [57301, 142699], [57427, 142573], [57457, 142543], [57901, 142099], [57943, 142057], [58129, 141871], [58147, 141853], [58171, 141829], [58189, 141811], [58207, 141793], [58231, 141769], [58321, 141679], [58363, 141637], [58603, 141397], [58693, 141307], [58699, 141301], [58921, 141079], [59011, 140989], [59023, 140977], [59107, 140893], [59221, 140779], [59239, 140761], [59341, 140659], [59407, 140593], [59443, 140557], [59467, 140533], [59473, 140527], [59557, 140443], [59581, 140419], [59779, 140221], [59809, 140191], [59833, 140167], [59929, 140071], [60013, 139987], [60139, 139861], [60169, 139831], [60271, 139729], [60337, 139663], [60373, 139627], [60607, 139393], [60631, 139369], [60661, 139339], [60703, 139297], [60727, 139273], [60733, 139267], [61261, 138739], [61339, 138661], [61363, 138637], [61441, 138559], [61483, 138517], [61507, 138493], [61627, 138373], [61651, 138349], [61681, 138319], [61717, 138283], [61819, 138181], [61837, 138163], [61843, 138157], [61861, 138139], [62017, 137983], [62053, 137947], [62131, 137869], [62347, 137653], [62563, 137437], [62617, 137383], [62659, 137341], [62761, 137239], [62791, 137209], [62869, 137131], [62971, 137029], [63103, 136897], [63247, 136753], [63397, 136603], [63463, 136537], [63499, 136501], [63601, 136399], [63607, 136393], [63649, 136351], [63667, 136333], [63691, 136309], [63697, 136303], [63727, 136273], [63793, 136207], [63823, 136177], [63901, 136099], [63907, 136093], [64063, 135937], [64171, 135829], [64279, 135721], [64303, 135697], [64399, 135601], [64489, 135511], [64567, 135433], [64591, 135409], [64609, 135391], [64633, 135367], [64717, 135283], [64849, 135151], [64951, 135049], [65011, 134989], [65053, 134947], [65269, 134731], [65293, 134707], [65323, 134677], [65407, 134593], [65413, 134587], [65419, 134581], [65497, 134503], [65557, 134443], [65563, 134437], [65599, 134401], [65629, 134371], [65647, 134353], [65707, 134293], [65713, 134287], [65731, 134269], [65809, 134191], [65839, 134161], [66037, 133963], [66169, 133831], [66343, 133657], [66403, 133597], [66457, 133543], [66553, 133447], [66697, 133303], [66721, 133279], [66739, 133261], [66883, 133117], [66931, 133069], [66949, 133051], [67033, 132967], [67141, 132859], [67261, 132739], [67339, 132661], [67369, 132631], [67411, 132589], [67453, 132547], [67477, 132523], [67489, 132511], [67531, 132469], [67579, 132421], [67759, 132241], [67801, 132199], [67843, 132157], [67891, 132109], [68041, 131959], [68053, 131947], [68059, 131941], [68161, 131839], [68329, 131671], [68389, 131611], [68521, 131479], [68683, 131317], [68749, 131251], [68899, 131101], [69019, 130981], [69031, 130969], [69073, 130927], [69127, 130873], [69193, 130807], [69313, 130687], [69379, 130621], [69697, 130303], [69739, 130261], [69829, 130171], [69931, 130069], [69997, 130003], [70099, 129901], [70207, 129793], [70237, 129763], [70393, 129607], [70501, 129499], [70621, 129379], [70639, 129361], [70687, 129313], [70879, 129121], [70951, 129049], [70999, 129001], [71059, 128941], [71143, 128857], [71167, 128833], [71233, 128767], [71317, 128683], [71341, 128659], [71437, 128563], [71479, 128521], [71527, 128473], [71551, 128449], [71563, 128437], [71569, 128431], [71713, 128287], [71761, 128239], [71881, 128119], [71887, 128113], [71947, 128053], [72253, 127747], [72337, 127663], [72421, 127579], [72493, 127507], [72547, 127453], [72577, 127423], [72679, 127321], [72739, 127261], [72949, 127051], [73039, 126961], [73141, 126859], [73243, 126757], [73309, 126691], [73369, 126631], [73387, 126613], [73417, 126583], [73453, 126547], [73459, 126541], [73483, 126517], [73651, 126349], [73693, 126307], [73771, 126229], [73849, 126151], [73999, 126001], [74071, 125929], [74101, 125899], [74197, 125803], [74209, 125791], [74257, 125743], [74293, 125707], [74317, 125683], [74383, 125617], [74449, 125551], [74713, 125287], [74731, 125269], [74779, 125221], [74869, 125131], [74887, 125113], [75013, 124987], [75181, 124819], [75217, 124783], [75223, 124777], [75307, 124693], [75367, 124633], [75511, 124489], [75541, 124459], [75553, 124447], [75571, 124429], [75703, 124297], [75709, 124291], [75787, 124213], [75853, 124147], [75913, 124087], [75979, 124021], [76003, 123997], [76147, 123853], [76213, 123787], [76243, 123757], [76333, 123667], [76369, 123631], [76507, 123493], [76543, 123457], [76561, 123439], [76603, 123397], [76771, 123229], [76831, 123169], [76873, 123127], [77029, 122971], [77047, 122953], [77167, 122833], [77239, 122761], [77347, 122653], [77491, 122509], [77551, 122449], [77557, 122443], [77611, 122389], [77797, 122203], [78007, 121993], [78049, 121951], [78079, 121921], [78157, 121843], [78367, 121633], [78553, 121447], [78643, 121357], [78649, 121351], [78691, 121309], [78877, 121123], [78919, 121081], [78979, 121021], [79063, 120937], [79111, 120889], [79153, 120847], [79279, 120721], [79309, 120691], [79393, 120607], [79423, 120577], [79609, 120391], [79669, 120331], [79777, 120223], [79801, 120199], [79843, 120157], [79903, 120097], [80071, 119929], [80077, 119923], [80149, 119851], [80173, 119827], [80191, 119809], [80263, 119737], [80329, 119671], [80341, 119659], [80347, 119653], [80449, 119551], [80611, 119389], [80701, 119299], [80809, 119191], [80911, 119089], [80917, 119083], [80953, 119047], [81097, 118903], [81157, 118843], [81181, 118819], [81199, 118801], [81283, 118717], [81331, 118669], [81457, 118543], [81547, 118453], [81703, 118297], [81727, 118273], [81853, 118147], [81919, 118081], [81943, 118057], [81967, 118033], [82009, 117991], [82021, 117979], [82189, 117811], [82237, 117763], [82279, 117721], [82471, 117529], [82483, 117517], [82759, 117241], [82837, 117163], [82891, 117109], [82963, 117037], [83047, 116953], [83071, 116929], [83077, 116923], [83089, 116911], [83203, 116797], [83269, 116731], [83311, 116689], [83407, 116593], [83557, 116443], [83563, 116437], [83641, 116359], [83761, 116239], [83833, 116167], [83869, 116131], [83911, 116089], [84067, 115933], [84121, 115879], [84127, 115873], [84163, 115837], [84223, 115777], [84229, 115771], [84307, 115693], [84673, 115327], [84691, 115309], [84697, 115303], [84751, 115249], [84979, 115021], [85027, 114973], [85087, 114913], [85201, 114799], [85243, 114757], [85429, 114571], [85447, 114553], [85453, 114547], [85513, 114487], [85549, 114451], [85843, 114157], [85933, 114067], [85999, 114001], [86011, 113989], [86017, 113983], [86239, 113761], [86269, 113731], [86353, 113647], [86461, 113539], [86533, 113467], [86629, 113371], [86767, 113233], [86851, 113149], [86857, 113143], [86869, 113131], [86959, 113041], [87049, 112951], [87313, 112687], [87337, 112663], [87427, 112573], [87541, 112459], [87697, 112303], [87721, 112279], [87739, 112261], [87751, 112249], [87793, 112207], [87931, 112069], [88003, 111997], [88129, 111871], [88423, 111577], [88513, 111487], [88591, 111409], [88663, 111337], [88729, 111271], [88747, 111253], [88771, 111229], [88789, 111211], [88813, 111187], [88873, 111127], [88897, 111103], [88951, 111049], [88969, 111031], [89083, 110917], [89101, 110899], [89119, 110881], [89137, 110863], [89269, 110731], [89371, 110629], [89413, 110587], [89431, 110569], [89443, 110557], [89521, 110479], [89563, 110437], [89689, 110311], [89767, 110233], [89779, 110221], [89839, 110161], [89917, 110083], [89977, 110023], [89983, 110017], [90127, 109873], [90379, 109621], [90403, 109597], [90481, 109519], [90529, 109471], [90547, 109453], [90679, 109321], [90697, 109303], [90703, 109297], [90841, 109159], [91009, 108991], [91033, 108967], [91249, 108751], [91291, 108709], [91369, 108631], [91459, 108541], [91621, 108379], [91711, 108289], [91753, 108247], [91807, 108193], [91813, 108187], [91873, 108127], [91921, 108079], [91939, 108061], [92077, 107923], [92119, 107881], [92143, 107857], [92173, 107827], [92227, 107773], [92353, 107647], [92401, 107599], [92419, 107581], [92551, 107449], [92623, 107377], [92791, 107209], [92863, 107137], [92899, 107101], [93097, 106903], [93133, 106867], [93139, 106861], [93199, 106801], [93241, 106759], [93253, 106747], [93307, 106693], [93319, 106681], [93337, 106663], [93463, 106537], [93559, 106441], [93637, 106363], [93703, 106297], [93739, 106261], [93787, 106213], [93811, 106189], [93871, 106129], [93913, 106087], [93967, 106033], [94033, 105967], [94057, 105943], [94117, 105883], [94273, 105727], [94309, 105691], [94327, 105673], [94351, 105649], [94399, 105601], [94483, 105517], [94603, 105397], [94621, 105379], [94723, 105277], [94747, 105253], [94771, 105229], [94789, 105211], [94903, 105097], [95083, 104917], [95089, 104911], [95131, 104869], [95239, 104761], [95257, 104743], [95317, 104683], [95527, 104473], [95617, 104383], [95713, 104287], [95881, 104119], [95911, 104089], [95947, 104053], [96097, 103903], [96157, 103843], [96199, 103801], [96331, 103669], [96451, 103549], [96517, 103483], [96601, 103399], [96643, 103357], [96667, 103333], [96763, 103237], [96769, 103231], [96823, 103177], [96907, 103093], [96931, 103069], [97159, 102841], [97171, 102829], [97231, 102769], [97327, 102673], [97441, 102559], [97453, 102547], [97501, 102499], [97549, 102451], [97771, 102229], [97861, 102139], [97879, 102121], [97987, 102013], [98251, 101749], [98299, 101701], [98347, 101653], [98389, 101611], [98419, 101581], [98467, 101533], [98473, 101527], [98533, 101467], [98641, 101359], [98713, 101287], [98779, 101221], [98887, 101113], [98893, 101107], [98911, 101089], [99013, 100987], [99259, 100741], [99391, 100609], [99409, 100591], [99607, 100393], [99643, 100357], [99667, 100333], [99709, 100291], [99721, 100279], [99733, 100267], [99787, 100213], [99793, 100207], [99817, 100183], [99871, 100129]]\n assert candidate(n = 23) == []\n assert candidate(n = 80) == [[7, 73], [13, 67], [19, 61], [37, 43]]\n assert candidate(n = 101) == []\n assert candidate(n = 8) == [[3, 5]]\n assert candidate(n = 250) == [[11, 239], [17, 233], [23, 227], [53, 197], [59, 191], [71, 179], [83, 167], [101, 149], [113, 137]]\n assert candidate(n = 100000) == [[11, 99989], [29, 99971], [71, 99929], [167, 99833], [191, 99809], [233, 99767], [239, 99761], [281, 99719], [293, 99707], [311, 99689], [389, 99611], [419, 99581], [449, 99551], [503, 99497], [569, 99431], [599, 99401], [653, 99347], [683, 99317], [743, 99257], [809, 99191], [827, 99173], [863, 99137], [881, 99119], [911, 99089], [947, 99053], [977, 99023], [983, 99017], [1019, 98981], [1061, 98939], [1091, 98909], [1103, 98897], [1151, 98849], [1163, 98837], [1193, 98807], [1283, 98717], [1289, 98711], [1361, 98639], [1373, 98627], [1427, 98573], [1439, 98561], [1481, 98519], [1493, 98507], [1571, 98429], [1613, 98387], [1787, 98213], [1871, 98129], [1877, 98123], [2027, 97973], [2039, 97961], [2069, 97931], [2081, 97919], [2129, 97871], [2141, 97859], [2153, 97847], [2213, 97787], [2351, 97649], [2393, 97607], [2417, 97583], [2423, 97577], [2447, 97553], [2477, 97523], [2621, 97379], [2633, 97367], [2699, 97301], [2741, 97259], [2843, 97157], [2897, 97103], [2927, 97073], [2999, 97001], [3011, 96989], [3041, 96959], [3089, 96911], [3203, 96797], [3221, 96779], [3251, 96749], [3329, 96671], [3413, 96587], [3539, 96461], [3557, 96443], [3581, 96419], [3623, 96377], [3671, 96329], [3677, 96323], [3719, 96281], [3767, 96233], [3779, 96221], [3821, 96179], [3833, 96167], [3851, 96149], [3863, 96137], [3947, 96053], [4013, 95987], [4127, 95873], [4211, 95789], [4217, 95783], [4253, 95747], [4283, 95717], [4349, 95651], [4397, 95603], [4451, 95549], [4493, 95507], [4517, 95483], [4673, 95327], [4721, 95279], [4733, 95267], [4787, 95213], [4889, 95111], [4937, 95063], [4973, 95027], [5039, 94961], [5051, 94949], [5153, 94847], [5189, 94811], [5273, 94727], [5351, 94649], [5387, 94613], [5417, 94583], [5441, 94559], [5471, 94529], [5573, 94427], [5651, 94349], [5657, 94343], [5669, 94331], [5693, 94307], [5849, 94151], [5879, 94121], [6029, 93971], [6089, 93911], [6113, 93887], [6173, 93827], [6299, 93701], [6317, 93683], [6521, 93479], [6581, 93419], [6719, 93281], [6737, 93263], [6761, 93239], [6869, 93131], [6911, 93089], [6917, 93083], [6947, 93053], [7013, 92987], [7043, 92957], [7079, 92921], [7151, 92849], [7211, 92789], [7247, 92753], [7283, 92717], [7307, 92693], [7331, 92669], [7433, 92567], [7541, 92459], [7643, 92357], [7703, 92297], [7757, 92243], [7823, 92177], [7949, 92051], [8039, 91961], [8219, 91781], [8243, 91757], [8297, 91703], [8369, 91631], [8423, 91577], [8429, 91571], [8501, 91499], [8537, 91463], [8543, 91457], [8627, 91373], [8669, 91331], [8747, 91253], [8807, 91193], [8837, 91163], [8849, 91151], [8861, 91139], [9011, 90989], [9029, 90971], [9137, 90863], [9323, 90677], [9341, 90659], [9467, 90533], [9473, 90527], [9629, 90371], [9719, 90281], [9803, 90197], [9851, 90149], [9929, 90071], [9941, 90059], [10037, 89963], [10061, 89939], [10091, 89909], [10103, 89897], [10133, 89867], [10151, 89849], [10181, 89819], [10247, 89753], [10331, 89669], [10343, 89657], [10433, 89567], [10487, 89513], [10499, 89501], [10601, 89399], [10607, 89393], [10613, 89387], [10739, 89261], [10847, 89153], [10949, 89051], [10979, 89021], [11003, 88997], [11117, 88883], [11279, 88721], [11393, 88607], [11411, 88589], [11621, 88379], [11699, 88301], [11777, 88223], [11789, 88211], [11831, 88169], [11981, 88019], [12041, 87959], [12113, 87887], [12119, 87881], [12197, 87803], [12203, 87797], [12281, 87719], [12329, 87671], [12377, 87623], [12413, 87587], [12491, 87509], [12527, 87473], [12641, 87359], [12743, 87257], [12821, 87179], [12893, 87107], [12917, 87083], [12959, 87041], [13007, 86993], [13049, 86951], [13163, 86837], [13187, 86813], [13217, 86783], [13229, 86771], [13421, 86579], [13469, 86531], [13499, 86501], [13523, 86477], [13577, 86423], [13619, 86381], [13649, 86351], [13709, 86291], [13751, 86249], [13757, 86243], [13799, 86201], [13829, 86171], [13883, 86117], [13931, 86069], [14009, 85991], [14153, 85847], [14207, 85793], [14249, 85751], [14423, 85577], [14549, 85451], [14561, 85439], [14639, 85361], [14669, 85331], [14741, 85259], [14753, 85247], [14771, 85229], [14867, 85133], [14879, 85121], [14891, 85109], [14897, 85103], [14939, 85061], [14951, 85049], [15053, 84947], [15131, 84869], [15173, 84827], [15263, 84737], [15269, 84731], [15287, 84713], [15299, 84701], [15467, 84533], [15497, 84503], [15551, 84449], [15569, 84431], [15683, 84317], [15737, 84263], [15761, 84239], [15809, 84191], [16061, 83939], [16067, 83933], [16097, 83903], [16127, 83873], [16187, 83813], [16223, 83777], [16361, 83639], [16421, 83579], [16529, 83471], [16661, 83339], [16823, 83177], [16883, 83117], [16937, 83063], [17117, 82883], [17189, 82811], [17207, 82793], [17387, 82613], [17471, 82529], [17579, 82421], [17627, 82373], [17783, 82217], [17807, 82193], [17837, 82163], [17987, 82013], [18047, 81953], [18131, 81869], [18251, 81749], [18311, 81689], [18329, 81671], [18353, 81647], [18371, 81629], [18701, 81299], [18719, 81281], [18797, 81203], [18803, 81197], [18869, 81131], [18899, 81101], [18917, 81083], [18959, 81041], [19037, 80963], [19181, 80819], [19211, 80789], [19319, 80681], [19373, 80627], [19379, 80621], [19433, 80567], [19463, 80537], [19553, 80447], [19571, 80429], [19727, 80273], [19793, 80207], [19853, 80147], [19889, 80111], [19949, 80051], [19961, 80039], [19979, 80021], [20021, 79979], [20177, 79823], [20183, 79817], [20231, 79769], [20369, 79631], [20399, 79601], [20411, 79589], [20441, 79559], [20507, 79493], [20549, 79451], [20663, 79337], [20681, 79319], [20717, 79283], [20759, 79241], [20771, 79229], [20807, 79193], [20849, 79151], [20897, 79103], [21011, 78989], [21023, 78977], [21059, 78941], [21107, 78893], [21143, 78857], [21191, 78809], [21221, 78779], [21347, 78653], [21377, 78623], [21407, 78593], [21491, 78509], [21503, 78497], [21521, 78479], [21563, 78437], [21599, 78401], [21683, 78317], [21767, 78233], [21821, 78179], [21863, 78137], [22031, 77969], [22067, 77933], [22133, 77867], [22277, 77723], [22409, 77591], [22511, 77489], [22709, 77291], [22721, 77279], [22739, 77261], [22751, 77249], [22787, 77213], [22859, 77141], [22907, 77093], [23039, 76961], [23057, 76943], [23081, 76919], [23087, 76913], [23117, 76883], [23321, 76679], [23327, 76673], [23333, 76667], [23369, 76631], [23459, 76541], [23537, 76463], [23633, 76367], [23741, 76259], [23747, 76253], [23909, 76091], [24179, 75821], [24203, 75797], [24317, 75683], [24359, 75641], [24371, 75629], [24443, 75557], [24473, 75527], [24593, 75407], [24611, 75389], [24623, 75377], [24671, 75329], [24677, 75323], [24851, 75149], [24917, 75083], [24971, 75029], [24989, 75011], [25097, 74903], [25127, 74873], [25169, 74831], [25229, 74771], [25253, 74747], [25301, 74699], [25391, 74609], [25439, 74561], [25469, 74531], [25589, 74411], [25643, 74357], [25703, 74297], [25799, 74201], [25841, 74159], [26141, 73859], [26153, 73847], [26177, 73823], [26249, 73751], [26321, 73679], [26357, 73643], [26387, 73613], [26393, 73607], [26417, 73583], [26669, 73331], [26723, 73277], [26879, 73121], [26921, 73079], [26981, 73019], [26987, 73013], [27077, 72923], [27107, 72893], [27281, 72719], [27299, 72701], [27329, 72671], [27449, 72551], [27539, 72461], [27617, 72383], [27647, 72353], [27749, 72251], [27773, 72227], [27779, 72221], [27827, 72173], [27947, 72053], [27953, 72047], [28001, 71999], [28151, 71849], [28163, 71837], [28211, 71789], [28289, 71711], [28307, 71693], [28403, 71597], [28463, 71537], [28517, 71483], [28547, 71453], [28571, 71429], [28661, 71339], [28751, 71249], [28871, 71129], [28961, 71039], [29009, 70991], [29021, 70979], [29063, 70937], [29123, 70877], [29147, 70853], [29207, 70793], [29231, 70769], [29333, 70667], [29411, 70589], [29429, 70571], [29759, 70241], [29819, 70181], [29837, 70163], [29879, 70121], [29921, 70079], [30059, 69941], [30071, 69929], [30089, 69911], [30323, 69677], [30347, 69653], [30509, 69491], [30803, 69197], [30809, 69191], [30851, 69149], [30881, 69119], [30971, 69029], [31091, 68909], [31121, 68879], [31181, 68819], [31223, 68777], [31271, 68729], [31469, 68531], [31511, 68489], [31517, 68483], [31601, 68399], [31649, 68351], [31721, 68279], [31793, 68207], [31859, 68141], [32057, 67943], [32069, 67931], [32099, 67901], [32117, 67883], [32237, 67763], [32321, 67679], [32369, 67631], [32381, 67619], [32411, 67589], [32423, 67577], [32441, 67559], [32507, 67493], [32573, 67427], [32579, 67421], [32609, 67391], [32693, 67307], [32783, 67217], [32789, 67211], [32831, 67169], [32843, 67157], [32939, 67061], [32957, 67043], [33023, 66977], [33053, 66947], [33149, 66851], [33179, 66821], [33191, 66809], [33203, 66797], [33287, 66713], [33317, 66683], [33347, 66653], [33413, 66587], [33533, 66467], [33569, 66431], [33587, 66413], [33617, 66383], [33623, 66377], [33641, 66359], [33809, 66191], [33827, 66173], [33863, 66137], [33893, 66107], [33911, 66089], [34019, 65981], [34157, 65843], [34211, 65789], [34283, 65717], [34301, 65699], [34313, 65687], [34367, 65633], [34421, 65579], [34457, 65543], [34607, 65393], [34673, 65327], [34871, 65129], [34877, 65123], [35081, 64919], [35099, 64901], [35129, 64871], [35291, 64709], [35339, 64661], [35423, 64577], [35447, 64553], [35597, 64403], [35729, 64271], [35933, 64067], [35963, 64037], [35993, 64007], [36137, 63863], [36161, 63839], [36191, 63809], [36263, 63737], [36341, 63659], [36353, 63647], [36383, 63617], [36389, 63611], [36467, 63533], [36473, 63527], [36479, 63521], [36527, 63473], [36653, 63347], [36683, 63317], [36821, 63179], [36887, 63113], [37013, 62987], [37019, 62981], [37061, 62939], [37097, 62903], [37139, 62861], [37181, 62819], [37199, 62801], [37277, 62723], [37313, 62687], [37361, 62639], [37397, 62603], [37409, 62591], [37493, 62507], [37517, 62483], [37649, 62351], [37781, 62219], [37799, 62201], [37811, 62189], [37871, 62129], [37997, 62003], [38039, 61961], [38219, 61781], [38327, 61673], [38333, 61667], [38447, 61553], [38453, 61547], [38669, 61331], [38747, 61253], [38993, 61007], [39047, 60953], [39113, 60887], [39227, 60773], [39239, 60761], [39341, 60659], [39383, 60617], [39461, 60539], [39503, 60497], [39551, 60449], [39749, 60251], [39791, 60209], [39839, 60161], [39971, 60029], [39983, 60017], [40253, 59747], [40277, 59723], [40433, 59567], [40487, 59513], [40529, 59471], [40559, 59441], [40583, 59417], [40841, 59159], [40949, 59051], [41057, 58943], [41213, 58787], [41243, 58757], [41387, 58613], [41399, 58601], [41519, 58481], [41549, 58451], [41597, 58403], [41609, 58391], [41621, 58379], [41687, 58313], [41729, 58271], [41771, 58229], [41801, 58199], [41849, 58151], [41927, 58073], [41957, 58043], [41969, 58031], [42023, 57977], [42083, 57917], [42101, 57899], [42197, 57803], [42209, 57791], [42227, 57773], [42281, 57719], [42359, 57641], [42407, 57593], [42443, 57557], [42473, 57527], [42533, 57467], [42611, 57389], [42797, 57203], [42821, 57179], [42923, 57077], [42953, 57047], [43037, 56963], [43049, 56951], [43103, 56897], [43313, 56687], [43319, 56681], [43403, 56597], [43457, 56543], [43481, 56519], [43499, 56501], [43607, 56393], [43793, 56207], [43913, 56087], [43961, 56039], [43991, 56009], [43997, 56003], [44111, 55889], [44129, 55871], [44171, 55829], [44201, 55799], [44207, 55793], [44267, 55733], [44279, 55721], [44381, 55619], [44453, 55547], [44531, 55469], [44543, 55457], [44657, 55343], [44687, 55313], [44741, 55259], [44771, 55229], [44927, 55073], [44939, 55061], [45083, 54917], [45119, 54881], [45131, 54869], [45233, 54767], [45377, 54623], [45497, 54503], [45503, 54497], [45557, 54443], [45587, 54413], [45599, 54401], [45677, 54323], [45707, 54293], [45833, 54167], [45989, 54011], [46049, 53951], [46061, 53939], [46073, 53927], [46103, 53897], [46181, 53819], [46187, 53813], [46301, 53699], [46307, 53693], [46451, 53549], [46559, 53441], [46589, 53411], [46619, 53381], [46691, 53309], [46769, 53231], [46811, 53189], [46829, 53171], [46853, 53147], [46997, 53003], [47111, 52889], [47279, 52721], [47303, 52697], [47309, 52691], [47417, 52583], [47459, 52541], [47543, 52457], [47609, 52391], [47639, 52361], [47699, 52301], [47711, 52289], [47741, 52259], [47777, 52223], [47819, 52181], [47837, 52163], [47933, 52067], [48023, 51977], [48029, 51971], [48131, 51869], [48197, 51803], [48281, 51719], [48341, 51659], [48353, 51647], [48407, 51593], [48437, 51563], [48449, 51551], [48479, 51521], [48497, 51503], [48527, 51473], [48539, 51461], [48563, 51437], [48593, 51407], [48761, 51239], [48869, 51131], [48953, 51047], [49031, 50969], [49043, 50957], [49109, 50891], [49211, 50789], [49223, 50777], [49277, 50723], [49409, 50591], [49451, 50549], [49559, 50441], [49613, 50387], [49667, 50333], [49727, 50273], [49739, 50261], [49823, 50177], [49853, 50147], [49871, 50129], [49877, 50123]]\n assert candidate(n = 22) == [[3, 19], [5, 17], [11, 11]]\n assert candidate(n = 89) == []\n assert candidate(n = 9973) == []\n assert candidate(n = 5000) == [[7, 4993], [13, 4987], [31, 4969], [43, 4957], [67, 4933], [97, 4903], [139, 4861], [199, 4801], [211, 4789], [241, 4759], [271, 4729], [277, 4723], [337, 4663], [349, 4651], [379, 4621], [397, 4603], [409, 4591], [433, 4567], [439, 4561], [487, 4513], [577, 4423], [643, 4357], [661, 4339], [673, 4327], [727, 4273], [739, 4261], [757, 4243], [769, 4231], [823, 4177], [907, 4093], [997, 4003], [1033, 3967], [1069, 3931], [1093, 3907], [1123, 3877], [1153, 3847], [1231, 3769], [1291, 3709], [1303, 3697], [1327, 3673], [1429, 3571], [1453, 3547], [1459, 3541], [1471, 3529], [1483, 3517], [1489, 3511], [1531, 3469], [1543, 3457], [1567, 3433], [1609, 3391], [1627, 3373], [1657, 3343], [1669, 3331], [1693, 3307], [1699, 3301], [1741, 3259], [1747, 3253], [1783, 3217], [1831, 3169], [1879, 3121], [1933, 3067], [1951, 3049], [1999, 3001], [2029, 2971], [2083, 2917], [2113, 2887], [2143, 2857], [2203, 2797], [2251, 2749], [2269, 2731], [2281, 2719], [2287, 2713], [2293, 2707], [2311, 2689], [2341, 2659], [2383, 2617]]\n assert candidate(n = 18) == [[5, 13], [7, 11]]\n assert candidate(n = 999983) == []\n assert candidate(n = 89765) == []\n assert candidate(n = 150) == [[11, 139], [13, 137], [19, 131], [23, 127], [37, 113], [41, 109], [43, 107], [47, 103], [53, 97], [61, 89], [67, 83], [71, 79]]\n assert candidate(n = 15) == [[2, 13]]\n assert candidate(n = 654321) == []\n assert candidate(n = 200) == [[3, 197], [7, 193], [19, 181], [37, 163], [43, 157], [61, 139], [73, 127], [97, 103]]\n assert candidate(n = 41) == []\n assert candidate(n = 26) == [[3, 23], [7, 19], [13, 13]]\n assert candidate(n = 31) == [[2, 29]]\n assert candidate(n = 750) == [[7, 743], [11, 739], [17, 733], [23, 727], [31, 719], [41, 709], [59, 691], [67, 683], [73, 677], [89, 661], [97, 653], [103, 647], [107, 643], [109, 641], [131, 619], [137, 613], [149, 601], [151, 599], [157, 593], [163, 587], [173, 577], [179, 571], [181, 569], [193, 557], [227, 523], [229, 521], [241, 509], [251, 499], [263, 487], [271, 479], [283, 467], [293, 457], [307, 443], [311, 439], [317, 433], [331, 419], [349, 401], [353, 397], [367, 383]]\n assert candidate(n = 301) == []\n assert candidate(n = 999999) == []\n assert candidate(n = 123456) == [[7, 123449], [17, 123439], [23, 123433], [29, 123427], [37, 123419], [59, 123397], [79, 123377], [83, 123373], [149, 123307], [167, 123289], [197, 123259], [227, 123229], [239, 123217], [313, 123143], [373, 123083], [379, 123077], [397, 123059], [439, 123017], [449, 123007], [499, 122957], [503, 122953], [569, 122887], [587, 122869], [607, 122849], [617, 122839], [857, 122599], [859, 122597], [877, 122579], [929, 122527], [947, 122509], [953, 122503], [967, 122489], [1013, 122443], [1063, 122393], [1069, 122387], [1093, 122363], [1109, 122347], [1129, 122327], [1193, 122263], [1237, 122219], [1249, 122207], [1283, 122173], [1289, 122167], [1307, 122149], [1423, 122033], [1427, 122029], [1429, 122027], [1459, 121997], [1489, 121967], [1493, 121963], [1567, 121889], [1613, 121843], [1667, 121789], [1669, 121787], [1693, 121763], [1759, 121697], [1823, 121633], [1847, 121609], [1877, 121579], [1879, 121577], [1933, 121523], [1949, 121507], [1987, 121469], [2003, 121453], [2017, 121439], [2053, 121403], [2087, 121369], [2089, 121367], [2099, 121357], [2113, 121343], [2129, 121327], [2143, 121313], [2267, 121189], [2287, 121169], [2333, 121123], [2389, 121067], [2393, 121063], [2417, 121039], [2437, 121019], [2459, 120997], [2539, 120917], [2549, 120907], [2557, 120899], [2579, 120877], [2593, 120863], [2609, 120847], [2633, 120823], [2677, 120779], [2689, 120767], [2693, 120763], [2707, 120749], [2719, 120737], [2767, 120689], [2833, 120623], [2837, 120619], [2879, 120577], [2887, 120569], [2917, 120539], [2953, 120503], [3137, 120319], [3163, 120293], [3209, 120247], [3257, 120199], [3299, 120157], [3359, 120097], [3389, 120067], [3407, 120049], [3463, 119993], [3527, 119929], [3533, 119923], [3607, 119849], [3617, 119839], [3643, 119813], [3659, 119797], [3673, 119783], [3697, 119759], [3709, 119747], [3719, 119737], [3733, 119723], [3767, 119689], [3769, 119687], [3779, 119677], [3797, 119659], [3803, 119653], [3823, 119633], [3907, 119549], [3923, 119533], [3943, 119513], [3967, 119489], [4027, 119429], [4093, 119363], [4157, 119299], [4159, 119297], [4219, 119237], [4229, 119227], [4273, 119183], [4283, 119173], [4297, 119159], [4327, 119129], [4349, 119107], [4357, 119099], [4373, 119083], [4409, 119047], [4423, 119033], [4483, 118973], [4549, 118907], [4583, 118873], [4637, 118819], [4657, 118799], [4783, 118673], [4787, 118669], [4993, 118463], [4999, 118457], [5003, 118453], [5087, 118369], [5113, 118343], [5179, 118277], [5197, 118259], [5209, 118247], [5237, 118219], [5309, 118147], [5399, 118057], [5413, 118043], [5419, 118037], [5477, 117979], [5479, 117977], [5483, 117973], [5519, 117937], [5557, 117899], [5573, 117883], [5623, 117833], [5647, 117809], [5659, 117797], [5669, 117787], [5683, 117773], [5693, 117763], [5783, 117673], [5813, 117643], [5839, 117617], [5879, 117577], [5927, 117529], [5939, 117517], [5953, 117503], [6029, 117427], [6043, 117413], [6067, 117389], [6197, 117259], [6217, 117239], [6247, 117209], [6263, 117193], [6323, 117133], [6329, 117127], [6337, 117119], [6529, 116927], [6553, 116903], [6607, 116849], [6637, 116819], [6653, 116803], [6659, 116797], [6709, 116747], [6737, 116719], [6793, 116663], [6863, 116593], [6907, 116549], [6917, 116539], [6949, 116507], [7013, 116443], [7019, 116437], [7069, 116387], [7127, 116329], [7177, 116279], [7187, 116269], [7213, 116243], [7297, 116159], [7349, 116107], [7477, 115979], [7523, 115933], [7573, 115883], [7577, 115879], [7583, 115873], [7603, 115853], [7607, 115849], [7649, 115807], [7673, 115783], [7687, 115769], [7699, 115757], [7723, 115733], [7793, 115663], [7853, 115603], [7867, 115589], [7933, 115523], [8093, 115363], [8147, 115309], [8219, 115237], [8233, 115223], [8273, 115183], [8293, 115163], [8329, 115127], [8377, 115079], [8389, 115067], [8443, 115013], [8543, 114913], [8573, 114883], [8597, 114859], [8609, 114847], [8623, 114833], [8629, 114827], [8647, 114809], [8699, 114757], [8707, 114749], [8713, 114743], [8807, 114649], [8839, 114617], [8863, 114593], [8963, 114493], [8969, 114487], [9049, 114407], [9127, 114329], [9137, 114319], [9157, 114299], [9187, 114269], [9227, 114229], [9239, 114217], [9257, 114199], [9343, 114113], [9413, 114043], [9467, 113989], [9473, 113983], [9547, 113909], [9613, 113843], [9619, 113837], [9677, 113779], [9679, 113777], [9697, 113759], [9733, 113723], [9739, 113717], [9833, 113623], [9967, 113489], [10039, 113417], [10093, 113363], [10099, 113357], [10169, 113287], [10177, 113279], [10223, 113233], [10243, 113213], [10247, 113209], [10267, 113189], [10289, 113167], [10303, 113153], [10313, 113143], [10333, 113123], [10429, 113027], [10433, 113023], [10459, 112997], [10477, 112979], [10529, 112927], [10597, 112859], [10613, 112843], [10657, 112799], [10799, 112657], [10853, 112603], [10867, 112589], [10883, 112573], [10949, 112507], [11027, 112429], [11059, 112397], [11093, 112363], [11117, 112339], [11119, 112337], [11159, 112297], [11177, 112279], [11243, 112213], [11257, 112199], [11317, 112139], [11353, 112103], [11369, 112087], [11437, 112019], [11483, 111973], [11497, 111959], [11503, 111953], [11587, 111869], [11593, 111863], [11657, 111799], [11677, 111779], [11689, 111767], [11789, 111667], [11833, 111623], [11863, 111593], [11923, 111533], [11959, 111497], [11969, 111487], [12109, 111347], [12119, 111337], [12203, 111253], [12227, 111229], [12239, 111217], [12269, 111187], [12329, 111127], [12347, 111109], [12413, 111043], [12479, 110977], [12487, 110969], [12517, 110939], [12539, 110917], [12547, 110909], [12577, 110879], [12637, 110819], [12703, 110753], [12809, 110647], [12853, 110603], [12889, 110567], [12893, 110563], [12899, 110557], [12923, 110533], [12953, 110503], [12979, 110477], [13037, 110419], [13183, 110273], [13187, 110269], [13219, 110237], [13327, 110129], [13337, 110119], [13397, 110059], [13417, 110039], [13469, 109987], [13513, 109943], [13537, 109919], [13553, 109903], [13597, 109859], [13613, 109843], [13627, 109829], [13649, 109807], [13859, 109597], [13873, 109583], [13877, 109579], [14033, 109423], [14143, 109313], [14153, 109303], [14159, 109297], [14177, 109279], [14323, 109133], [14407, 109049], [14419, 109037], [14489, 108967], [14533, 108923], [14549, 108907], [14563, 108893], [14593, 108863], [14629, 108827], [14653, 108803], [14657, 108799], [14717, 108739], [14747, 108709], [14779, 108677], [14813, 108643], [14869, 108587], [14923, 108533], [14939, 108517], [14957, 108499], [15017, 108439], [15077, 108379], [15193, 108263], [15233, 108223], [15263, 108193], [15269, 108187], [15277, 108179], [15329, 108127], [15349, 108107], [15377, 108079], [15443, 108013], [15559, 107897], [15583, 107873], [15619, 107837], [15629, 107827], [15679, 107777], [15683, 107773], [15737, 107719], [15739, 107717], [15809, 107647], [16007, 107449], [16183, 107273], [16187, 107269], [16229, 107227], [16273, 107183], [16319, 107137], [16333, 107123], [16477, 106979], [16493, 106963], [16519, 106937], [16553, 106903], [16603, 106853], [16633, 106823], [16673, 106783], [16703, 106753], [16729, 106727], [16763, 106693], [16787, 106669], [16829, 106627], [17029, 106427], [17093, 106363], [17099, 106357], [17107, 106349], [17137, 106319], [17159, 106297], [17183, 106273], [17239, 106217], [17293, 106163], [17327, 106129], [17333, 106123], [17443, 106013], [17489, 105967], [17573, 105883], [17627, 105829], [17729, 105727], [17783, 105673], [17789, 105667], [17807, 105649], [17837, 105619], [17923, 105533], [17929, 105527], [17939, 105517], [17957, 105499], [17989, 105467], [18049, 105407], [18059, 105397], [18077, 105379], [18089, 105367], [18097, 105359], [18119, 105337], [18133, 105323], [18217, 105239], [18229, 105227], [18257, 105199], [18289, 105167], [18313, 105143], [18433, 105023], [18457, 104999], [18503, 104953], [18523, 104933], [18539, 104917], [18587, 104869], [18713, 104743], [18749, 104707], [18773, 104683], [18797, 104659], [18859, 104597], [18913, 104543], [18919, 104537], [19073, 104383], [19087, 104369], [19213, 104243], [19249, 104207], [19273, 104183], [19309, 104147], [19333, 104123], [19403, 104053], [19423, 104033], [19447, 104009], [19463, 103993], [19477, 103979], [19489, 103967], [19543, 103913], [19553, 103903], [19687, 103769], [19753, 103703], [19813, 103643], [19843, 103613], [19889, 103567], [19927, 103529], [19973, 103483], [20047, 103409], [20063, 103393], [20107, 103349], [20123, 103333], [20149, 103307], [20219, 103237], [20333, 103123], [20357, 103099], [20369, 103087], [20389, 103067], [20407, 103049], [20543, 102913], [20627, 102829], [20663, 102793], [20693, 102763], [20789, 102667], [20809, 102647], [20849, 102607], [20897, 102559], [20959, 102497], [21019, 102437], [21023, 102433], [21059, 102397], [21089, 102367], [21139, 102317], [21157, 102299], [21163, 102293], [21227, 102229], [21317, 102139], [21377, 102079], [21379, 102077], [21397, 102059], [21433, 102023], [21493, 101963], [21499, 101957], [21517, 101939], [21577, 101879], [21587, 101869], [21617, 101839], [21649, 101807], [21737, 101719], [21803, 101653], [21929, 101527], [21943, 101513], [22027, 101429], [22037, 101419], [22073, 101383], [22079, 101377], [22093, 101363], [22109, 101347], [22123, 101333], [22133, 101323], [22189, 101267], [22247, 101209], [22259, 101197], [22273, 101183], [22283, 101173], [22307, 101149], [22343, 101113], [22349, 101107], [22367, 101089], [22447, 101009], [22469, 100987], [22543, 100913], [22549, 100907], [22669, 100787], [22709, 100747], [22783, 100673], [22787, 100669], [22807, 100649], [22907, 100549], [22937, 100519], [22963, 100493], [22973, 100483], [23039, 100417], [23053, 100403], [23063, 100393], [23099, 100357], [23143, 100313], [23159, 100297], [23189, 100267], [23327, 100129], [23399, 100057], [23549, 99907], [23623, 99833], [23627, 99829], [23633, 99823], [23663, 99793], [23669, 99787], [23689, 99767], [23743, 99713], [23747, 99709], [23767, 99689], [23789, 99667], [23813, 99643], [23833, 99623], [23879, 99577], [23893, 99563], [23929, 99527], [24107, 99349], [24109, 99347], [24179, 99277], [24197, 99259], [24223, 99233], [24317, 99139], [24337, 99119], [24373, 99083], [24439, 99017], [24443, 99013], [24509, 98947], [24517, 98939], [24527, 98929], [24547, 98909], [24677, 98779], [24683, 98773], [24767, 98689], [24793, 98663], [24859, 98597], [24923, 98533], [24977, 98479], [24989, 98467], [25013, 98443], [25037, 98419], [25087, 98369], [25229, 98227], [25243, 98213], [25409, 98047], [25439, 98017], [25447, 98009], [25469, 97987], [25537, 97919], [25577, 97879], [25609, 97847], [25643, 97813], [25667, 97789], [25679, 97777], [25847, 97609], [25849, 97607], [25873, 97583], [25903, 97553], [25933, 97523], [25997, 97459], [26003, 97453], [26083, 97373], [26153, 97303], [26297, 97159], [26339, 97117], [26417, 97039], [26449, 97007], [26459, 96997], [26497, 96959], [26633, 96823], [26669, 96787], [26687, 96769], [26693, 96763], [26699, 96757], [26717, 96739], [26759, 96697], [26813, 96643], [26903, 96553], [26959, 96497], [26987, 96469], [27103, 96353], [27127, 96329], [27197, 96259], [27277, 96179], [27299, 96157], [27397, 96059], [27509, 95947], [27527, 95929], [27539, 95917], [27583, 95873], [27653, 95803], [27673, 95783], [27733, 95723], [27739, 95717], [27743, 95713], [27749, 95707], [27823, 95633], [27827, 95629], [27917, 95539], [28027, 95429], [28087, 95369], [28183, 95273], [28279, 95177], [28349, 95107], [28393, 95063], [28429, 95027], [28447, 95009], [28463, 94993], [28549, 94907], [28607, 94849], [28619, 94837], [28663, 94793], [28729, 94727], [28807, 94649], [28843, 94613], [28859, 94597], [28909, 94547], [28927, 94529], [28979, 94477], [29009, 94447], [29017, 94439], [29023, 94433], [29059, 94397], [29077, 94379], [29129, 94327], [29147, 94309], [29287, 94169], [29303, 94153], [29339, 94117], [29347, 94109], [29399, 94057], [29423, 94033], [29473, 93983], [29567, 93889], [29569, 93887], [29629, 93827], [29669, 93787], [29717, 93739], [29753, 93703], [29819, 93637], [29927, 93529], [29959, 93497], [30029, 93427], [30119, 93337], [30133, 93323], [30137, 93319], [30169, 93287], [30203, 93253], [30269, 93187], [30323, 93133], [30367, 93089], [30403, 93053], [30469, 92987], [30497, 92959], [30529, 92927], [30557, 92899], [30593, 92863], [30677, 92779], [30689, 92767], [30703, 92753], [30757, 92699], [30763, 92693], [30773, 92683], [30809, 92647], [30817, 92639], [30829, 92627], [30949, 92507], [30977, 92479], [31069, 92387], [31079, 92377], [31123, 92333], [31139, 92317], [31159, 92297], [31219, 92237], [31223, 92233], [31237, 92219], [31253, 92203], [31267, 92189], [31277, 92179], [31337, 92119], [31379, 92077], [31489, 91967], [31513, 91943], [31517, 91939], [31547, 91909], [31583, 91873], [31643, 91813], [31649, 91807], [31699, 91757], [31723, 91733], [31817, 91639], [31873, 91583], [31883, 91573], [31957, 91499], [31963, 91493], [32003, 91453], [32059, 91397], [32063, 91393], [32069, 91387], [32083, 91373], [32089, 91367], [32159, 91297], [32173, 91283], [32203, 91253], [32213, 91243], [32257, 91199], [32297, 91159], [32303, 91153], [32327, 91129], [32359, 91097], [32377, 91079], [32423, 91033], [32467, 90989], [32479, 90977], [32569, 90887], [32609, 90847], [32633, 90823], [32653, 90803], [32707, 90749], [32779, 90677], [32797, 90659], [32839, 90617], [32909, 90547], [32933, 90523], [32957, 90499], [32983, 90473], [32987, 90469], [33049, 90407], [33053, 90403], [33083, 90373], [33329, 90127], [33349, 90107], [33403, 90053], [33479, 89977], [33493, 89963], [33533, 89923], [33547, 89909], [33589, 89867], [33617, 89839], [33623, 89833], [33637, 89819], [33647, 89809], [33703, 89753], [33767, 89689], [33797, 89659], [33829, 89627], [33857, 89599], [33889, 89567], [33893, 89563], [33923, 89533], [33937, 89519], [33997, 89459], [34039, 89417], [34057, 89399], [34127, 89329], [34183, 89273], [34253, 89203], [34267, 89189], [34303, 89153], [34319, 89137], [34337, 89119], [34369, 89087], [34439, 89017], [34487, 88969], [34519, 88937], [34537, 88919], [34583, 88873], [34589, 88867], [34603, 88853], [34613, 88843], [34649, 88807], [34667, 88789], [34847, 88609], [34849, 88607], [34963, 88493], [35059, 88397], [35117, 88339], [35129, 88327], [35279, 88177], [35327, 88129], [35339, 88117], [35363, 88093], [35419, 88037], [35437, 88019], [35449, 88007], [35569, 87887], [35603, 87853], [35759, 87697], [35869, 87587], [35897, 87559], [35899, 87557], [35933, 87523], [35983, 87473], [36013, 87443], [36073, 87383], [36097, 87359], [36269, 87187], [36277, 87179], [36307, 87149], [36353, 87103], [36373, 87083], [36497, 86959], [36527, 86929], [36529, 86927], [36587, 86869], [36599, 86857], [36643, 86813], [36713, 86743], [36767, 86689], [36779, 86677], [36857, 86599], [36877, 86579], [36923, 86533], [36947, 86509], [36979, 86477], [37003, 86453], [37057, 86399], [37087, 86369], [37159, 86297], [37199, 86257], [37217, 86239], [37273, 86183], [37277, 86179], [37313, 86143], [37339, 86117], [37379, 86077], [37547, 85909], [37567, 85889], [37619, 85837], [37663, 85793], [37813, 85643], [37879, 85577], [37907, 85549], [37987, 85469], [38153, 85303], [38197, 85259], [38219, 85237], [38447, 85009], [38543, 84913], [38629, 84827], [38669, 84787], [38737, 84719], [38783, 84673], [38803, 84653], [38867, 84589], [38923, 84533], [38933, 84523], [38953, 84503], [38993, 84463], [39019, 84437], [39079, 84377], [39107, 84349], [39139, 84317], [39157, 84299], [39209, 84247], [39217, 84239], [39227, 84229], [39233, 84223], [39293, 84163], [39313, 84143], [39367, 84089], [39397, 84059], [39409, 84047], [39439, 84017], [39623, 83833], [39679, 83777], [39719, 83737], [39839, 83617], [39847, 83609], [39877, 83579], [39979, 83477], [40013, 83443], [40039, 83417], [40099, 83357], [40189, 83267], [40213, 83243], [40237, 83219], [40253, 83203], [40433, 83023], [40459, 82997], [40493, 82963], [40543, 82913], [40609, 82847], [40693, 82763], [40697, 82759], [40699, 82757], [40823, 82633], [40847, 82609], [40897, 82559], [40927, 82529], [40949, 82507], [40973, 82483], [40993, 82463], [41117, 82339], [41149, 82307], [41177, 82279], [41189, 82267], [41233, 82223], [41263, 82193], [41389, 82067], [41443, 82013], [41453, 82003], [41513, 81943], [41519, 81937], [41603, 81853], [41609, 81847], [41617, 81839], [41687, 81769], [41719, 81737], [41729, 81727], [41809, 81647], [41887, 81569], [41893, 81563], [41897, 81559], [41903, 81553], [41947, 81509], [41999, 81457], [42017, 81439], [42083, 81373], [42157, 81299], [42223, 81233], [42257, 81199], [42283, 81173], [42293, 81163], [42299, 81157], [42337, 81119], [42359, 81097], [42373, 81083], [42379, 81077], [42407, 81049], [42409, 81047], [42433, 81023], [42437, 81019], [42443, 81013], [42467, 80989], [42533, 80923], [42667, 80789], [42677, 80779], [42709, 80747], [42719, 80737], [42743, 80713], [42773, 80683], [42787, 80669], [42829, 80627], [42853, 80603], [42899, 80557], [42929, 80527], [42943, 80513], [42967, 80489], [43049, 80407], [43093, 80363], [43177, 80279], [43223, 80233], [43283, 80173], [43457, 79999], [43517, 79939], [43609, 79847], [43613, 79843], [43627, 79829], [43633, 79823], [43759, 79697], [43787, 79669], [43867, 79589], [43963, 79493], [44029, 79427], [44059, 79397], [44089, 79367], [44119, 79337], [44123, 79333], [44263, 79193], [44269, 79187], [44417, 79039], [44537, 78919], [44563, 78893], [44579, 78877], [44617, 78839], [44633, 78823], [44647, 78809], [44879, 78577], [44887, 78569], [44917, 78539], [44939, 78517], [44959, 78497], [45139, 78317], [45179, 78277], [45197, 78259], [45263, 78193], [45289, 78167], [45293, 78163], [45317, 78139], [45319, 78137], [45377, 78079], [45439, 78017], [45523, 77933], [45557, 77899], [45589, 77867], [45659, 77797], [45673, 77783], [45737, 77719], [45757, 77699], [45767, 77689], [45869, 77587], [45887, 77569], [45893, 77563], [45943, 77513], [45979, 77477], [46073, 77383], [46133, 77323], [46187, 77269], [46219, 77237], [46439, 77017], [46507, 76949], [46549, 76907], [46573, 76883], [46619, 76837], [46679, 76777], [46703, 76753], [46723, 76733], [46807, 76649], [46853, 76603], [46877, 76579], [46919, 76537], [46993, 76463], [47087, 76369], [47123, 76333], [47207, 76249], [47293, 76163], [47297, 76159], [47309, 76147], [47353, 76103], [47417, 76039], [47459, 75997], [47543, 75913], [47623, 75833], [47659, 75797], [47713, 75743], [47777, 75679], [47797, 75659], [47837, 75619], [47903, 75553], [47917, 75539], [47977, 75479], [48049, 75407], [48079, 75377], [48109, 75347], [48119, 75337], [48179, 75277], [48187, 75269], [48239, 75217], [48247, 75209], [48497, 74959], [48523, 74933], [48527, 74929], [48533, 74923], [48677, 74779], [48757, 74699], [48847, 74609], [48859, 74597], [48869, 74587], [48883, 74573], [48889, 74567], [48947, 74509], [49003, 74453], [49037, 74419], [49043, 74413], [49103, 74353], [49139, 74317], [49169, 74287], [49177, 74279], [49199, 74257], [49253, 74203], [49279, 74177], [49297, 74159], [49307, 74149], [49363, 74093], [49409, 74047], [49429, 74027], [49549, 73907], [49559, 73897], [49597, 73859], [49633, 73823], [49747, 73709], [49757, 73699], [49783, 73673], [49843, 73613], [49927, 73529], [49939, 73517], [50023, 73433], [50069, 73387], [50077, 73379], [50087, 73369], [50093, 73363], [50129, 73327], [50147, 73309], [50153, 73303], [50329, 73127], [50377, 73079], [50417, 73039], [50459, 72997], [50497, 72959], [50503, 72953], [50549, 72907], [50587, 72869], [50723, 72733], [50767, 72689], [50777, 72679], [50833, 72623], [50839, 72617], [50909, 72547], [50923, 72533], [50989, 72467], [51169, 72287], [51203, 72253], [51229, 72227], [51283, 72173], [51287, 72169], [51347, 72109], [51383, 72073], [51413, 72043], [51437, 72019], [51473, 71983], [51539, 71917], [51577, 71879], [51607, 71849], [51613, 71843], [51647, 71809], [51679, 71777], [51749, 71707], [51859, 71597], [51893, 71563], [51907, 71549], [51929, 71527], [51973, 71483], [51977, 71479], [52027, 71429], [52057, 71399], [52067, 71389], [52069, 71387], [52103, 71353], [52127, 71329], [52163, 71293], [52223, 71233], [52289, 71167], [52313, 71143], [52387, 71069], [52433, 71023], [52457, 70999], [52543, 70913], [52579, 70877], [52673, 70783], [52727, 70729], [52747, 70709], [52769, 70687], [52817, 70639], [52837, 70619], [52883, 70573], [52919, 70537], [52967, 70489], [52999, 70457], [53017, 70439], [53077, 70379], [53129, 70327], [53147, 70309], [53233, 70223], [53279, 70177], [53299, 70157], [53377, 70079], [53437, 70019], [53453, 70003], [53527, 69929], [53597, 69859], [53609, 69847], [53623, 69833], [53629, 69827], [53693, 69763], [53717, 69739], [53719, 69737], [53759, 69697], [53899, 69557], [53917, 69539], [53959, 69497], [53993, 69463], [54139, 69317], [54193, 69263], [54217, 69239], [54293, 69163], [54347, 69109], [54437, 69019], [54493, 68963], [54539, 68917], [54547, 68909], [54559, 68897], [54577, 68879], [54679, 68777], [54713, 68743], [54727, 68729], [54773, 68683], [54787, 68669], [54917, 68539], [54949, 68507], [54973, 68483], [54979, 68477], [54983, 68473], [55009, 68447], [55057, 68399], [55127, 68329], [55217, 68239], [55229, 68227], [55243, 68213], [55249, 68207], [55343, 68113], [55469, 67987], [55529, 67927], [55589, 67867], [55603, 67853], [55667, 67789], [55673, 67783], [55697, 67759], [55733, 67723], [55837, 67619], [55849, 67607], [55889, 67567], [55897, 67559], [55933, 67523], [55967, 67489], [56003, 67453], [56009, 67447], [56087, 67369], [56113, 67343], [56149, 67307], [56167, 67289], [56209, 67247], [56237, 67219], [56239, 67217], [56267, 67189], [56269, 67187], [56299, 67157], [56377, 67079], [56383, 67073], [56453, 67003], [56479, 66977], [56509, 66947], [56533, 66923], [56659, 66797], [56773, 66683], [56813, 66643], [56827, 66629], [56923, 66533], [56957, 66499], [56989, 66467], [56993, 66463], [56999, 66457], [57073, 66383], [57097, 66359], [57119, 66337], [57163, 66293], [57283, 66173], [57287, 66169], [57347, 66109], [57349, 66107], [57367, 66089], [57373, 66083], [57389, 66067], [57427, 66029], [57493, 65963], [57527, 65929], [57529, 65927], [57557, 65899], [57667, 65789], [57679, 65777], [57727, 65729], [57737, 65719], [57809, 65647], [57839, 65617], [57847, 65609], [57899, 65557], [57917, 65539], [57977, 65479], [58043, 65413], [58049, 65407], [58099, 65357], [58129, 65327], [58147, 65309], [58169, 65287], [58189, 65267], [58199, 65257], [58217, 65239], [58243, 65213], [58309, 65147], [58337, 65119], [58367, 65089], [58393, 65063], [58403, 65053], [58427, 65029], [58453, 65003], [58537, 64919], [58579, 64877], [58603, 64853], [58693, 64763], [58763, 64693], [58789, 64667], [58889, 64567], [58943, 64513], [58967, 64489], [59023, 64433], [59053, 64403], [59083, 64373], [59123, 64333], [59219, 64237], [59233, 64223], [59239, 64217], [59333, 64123], [59393, 64063], [59419, 64037], [59443, 64013], [59617, 63839], [59663, 63793], [59729, 63727], [59747, 63709], [59753, 63703], [59797, 63659], [59809, 63647], [59879, 63577], [59929, 63527], [59957, 63499], [60013, 63443], [60017, 63439], [60037, 63419], [60089, 63367], [60103, 63353], [60139, 63317], [60209, 63247], [60257, 63199], [60259, 63197], [60343, 63113], [60353, 63103], [60383, 63073], [60397, 63059], [60427, 63029], [60527, 62929], [60637, 62819], [60703, 62753], [60733, 62723], [60773, 62683], [60859, 62597], [60917, 62539], [60923, 62533], [61129, 62327], [61153, 62303], [61223, 62233], [61357, 62099], [61403, 62053], [61409, 62047], [61417, 62039], [61469, 61987], [61507, 61949], [61547, 61909], [61613, 61843], [61637, 61819], [61643, 61813]]\n assert candidate(n = 500) == [[13, 487], [37, 463], [43, 457], [61, 439], [67, 433], [79, 421], [103, 397], [127, 373], [151, 349], [163, 337], [193, 307], [223, 277], [229, 271]]\n assert candidate(n = 54321) == [[2, 54319]]\n assert candidate(n = 13) == [[2, 11]]\n", "comparison": "exact"}, "public_tests": ["10", "2"], "hints": ["Pre-compute all the prime numbers in the range [1, n] using a sieve, and store them in a data structure where they can be accessed in O(1) time.", "For x in the range [2, n/2], we can use the pre-computed list of prime numbers to check if both x and n - x are primes. If they are, we add them to the result."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().findPrimePairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:19+00:00", "tests_total": 52, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "enumeration", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def find_prime_pairs(n)", "container": null, "callable": "find_prime_pairs", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2762, "task_id": "continuous-subarrays", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:\n\n- Let i, i + 1, ..., jbe the indices in the subarray. Then, for each pair of indices i <= i_1, i_2 <= j, 0 <= |nums[i_1] - nums[i_2]| <= 2.\n\nReturn the total number of continuous subarrays.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [5,4,2,4]\nOutput: 8\nExplanation:\nContinuous subarray of size 1: [5], [4], [2], [4].\nContinuous subarray of size 2: [5,4], [4,2], [2,4].\nContinuous subarray of size 3: [4,2,4].\nThere are no subarrys of size 4.\nTotal continuous subarrays = 4 + 3 + 1 = 8.\nIt can be shown that there are no more continuous subarrays.\n\nExample 2:\n\nInput: nums = [1,2,3]\nOutput: 6\nExplanation:\nContinuous subarray of size 1: [1], [2], [3].\nContinuous subarray of size 2: [1,2], [2,3].\nContinuous subarray of size 3: [1,2,3].\nTotal continuous subarrays = 3 + 2 + 1 = 6.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 2, 4]) == 8\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4]) == 27\n assert candidate(nums = [9, 7, 5, 3, 1]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 24\n assert candidate(nums = [1, 3, 5, 7, 9]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 27\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5]) == 15\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 210\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 6\n assert candidate(nums = [2, 2, 2, 1, 1, 3, 3, 3]) == 36\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 19\n assert candidate(nums = [10, 9, 8, 8, 7, 6, 5, 5, 4, 3, 2, 1]) == 39\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [1, 2, 2, 2, 3, 3]) == 21\n assert candidate(nums = [1, 2, 2, 2, 1]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1]) == 15\n assert candidate(nums = [1, 3, 1, 3, 1, 3]) == 21\n assert candidate(nums = [1, 2, 2, 2, 3]) == 15\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 27\n assert candidate(nums = [1, 3, 5, 4, 6, 7, 8, 2]) == 17\n assert candidate(nums = [1, 2, 3]) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 55\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 57\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 42\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 31\n assert candidate(nums = [100, 101, 102, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 60\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 210\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5]) == 63\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 57\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4]) == 69\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 97\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 210\n assert candidate(nums = [1, 5, 2, 3, 7, 4, 8, 6, 10, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 42\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]) == 90\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]) == 59\n assert candidate(nums = [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 508, 507, 506, 505, 504, 503, 502, 501, 500, 499, 498, 497, 496, 495, 494, 493, 492, 491, 490]) == 87\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 57\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2]) == 210\n assert candidate(nums = [4, 4, 5, 4, 4, 6, 5, 4, 4, 3]) == 49\n assert candidate(nums = [1, 5, 4, 2, 4, 1, 3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 37\n assert candidate(nums = [1, 4, 2, 3, 2, 3, 4, 1, 2, 3, 2, 3, 4, 1]) == 43\n assert candidate(nums = [10, 10, 9, 11, 12, 8, 7, 6, 10, 10, 9, 11, 12, 8, 7, 6]) == 36\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]) == 72\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 210\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 10\n assert candidate(nums = [3, 3, 2, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 120\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, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 162\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 33\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 210\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 210\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 98\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 325\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 210\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 1081\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4]) == 69\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]) == 57\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 45\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 27\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]) == 72\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 210\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]) == 72\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 39\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]) == 465\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 54\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4]) == 60\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5]) == 69\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 38\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 2, 1, 1, 1, 2, 3, 3, 2, 1]) == 120\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3]) == 117\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(nums = [5, 1, 5, 3, 3, 5, 2, 4, 4, 2, 3, 5, 6, 8, 7, 9, 10, 8, 6, 4, 2, 1]) == 52\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 19\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 55\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, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 820\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 78\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]) == 990\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 55\n assert candidate(nums = [10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11]) == 210\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 39\n assert candidate(nums = [5, 4, 4, 4, 4, 5, 6, 7, 8, 7, 6, 5, 4, 4, 4, 4, 5]) == 71\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 210\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2]) == 54\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 210\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 496\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10]) == 267\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]) == 87\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 55\n assert candidate(nums = [1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 472\n assert candidate(nums = [100, 99, 100, 98, 99, 100, 97, 98, 99, 100]) == 30\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 63\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]) == 69\n assert candidate(nums = [5, 6, 6, 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]) == 141\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1]) == 55\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 57\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 55\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 39\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 54\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 20\n assert candidate(nums = [1, 3, 5, 3, 1, 3, 5, 3, 1, 3]) == 23\n assert candidate(nums = [5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3, 5, 2, 5, 3]) == 80\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 81\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 55\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]) == 60\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 210\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, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 147\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 65\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 210\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 55\n assert candidate(nums = [20, 18, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 2, 4, 6, 8, 10, 12, 14, 16]) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 48\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 210\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 6, 7, 4, 8, 3, 9, 2, 10, 1]) == 35\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]) == 72\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]) == 84\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 210\n assert candidate(nums = [10, 11, 12, 10, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 58\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1]) == 66\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 55\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 27\n assert candidate(nums = [4, 2, 2, 2, 3, 4, 5]) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 57\n assert candidate(nums = [1, 4, 2, 3, 2, 5, 4, 3]) == 17\n assert candidate(nums = [1, 2, 3, 2, 1]) == 15\n assert candidate(nums = [1, 3, 2, 3, 1]) == 15\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 42\n assert candidate(nums = [3, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 55\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 1, 3, 2, 1]) == 55\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 48\n assert candidate(nums = [1, 2, 2, 1]) == 10\n assert candidate(nums = [3, 3, 2, 2, 1, 1, 4, 4, 5, 5]) == 31\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 6\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4]) == 45\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 55\n assert candidate(nums = [2, 2, 2, 1, 3]) == 15\n assert candidate(nums = [100, 101, 102, 99, 98, 97, 96]) == 15\n assert candidate(nums = [10, 9, 8, 7, 6]) == 12\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 30\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 42\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, 9, 10, 10, 10]) == 102\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 10\n assert candidate(nums = [1, 2, 2, 3, 2, 1, 2, 2, 3, 2]) == 55\n assert candidate(nums = [10, 20, 30, 40, 50]) == 5\n assert candidate(nums = [1, 2, 2, 3, 4]) == 14\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 3, 3, 3, 4, 4, 4]) == 60\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 3, 3, 3, 2, 2, 2]) == 78\n assert candidate(nums = [1, 3, 2, 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, 1, 2, 3]) == 2850\n assert candidate(nums = [5, 4, 3, 4, 5]) == 15\n assert candidate(nums = [1, 1000000000]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [1, 3, 5, 7, 9]) == 9\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == 5\n assert candidate(nums = [5, 2, 2, 4, 5, 3]) == 12\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 55\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == 37\n assert candidate(nums = [1, 1, 1, 1]) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 57\n assert candidate(nums = [1, 2, 3, 4, 5]) == 12\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 45\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1]) == 120\n assert candidate(nums = [1, 3, 5, 3, 1, 3, 5, 3, 1]) == 20\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]) == 3321\n assert candidate(nums = [10, 10, 10, 10, 10]) == 15\n assert candidate(nums = [10, 10, 10, 10, 10, 10]) == 21\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 4, 3, 2, 1]) == 36\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 55\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4]) == 45\n assert candidate(nums = [2, 2, 2, 1, 3, 1, 3, 2, 2, 1]) == 55\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 19\n assert candidate(nums = [1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 2, 2, 1]) == 10\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 55\n assert candidate(nums = [1, 2, 2, 2, 2, 2]) == 21\n assert candidate(nums = [1, 3, 2, 2, 1, 3, 2, 2, 1]) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 33\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 55\n assert candidate(nums = [3, 1]) == 3\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1]) == 45\n assert candidate(nums = [1, 3]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 21\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 5]) == 23\n assert candidate(nums = [5, 7, 7, 8, 8, 10]) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 29\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 28\n assert candidate(nums = [5, 6, 7, 8, 9, 5, 6, 7, 8, 9]) == 24\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == 15\n assert candidate(nums = [1, 2, 3]) == 6\n assert candidate(nums = [1, 3, 2, 3, 1, 4, 2, 3, 1]) == 24\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 27\n assert candidate(nums = [10, 10, 10, 10]) == 10\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3]) == 120\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 33\n assert candidate(nums = [1, 4, 2, 3, 5, 6, 7, 8, 9]) == 20\n assert candidate(nums = [1000000000]) == 1\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10]) == 21\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 51\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1]) == 36\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1]) == 18\n assert candidate(nums = [1, 4, 7, 10, 13]) == 5\n assert candidate(nums = [10, 9, 10, 11, 10, 9, 10, 11, 10, 9]) == 55\n assert candidate(nums = [5, 4, 2, 4]) == 8\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 55\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 57\n assert candidate(nums = [3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6]) == 57\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 64\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 27\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 45\n", "comparison": "exact"}, "public_tests": ["[5,4,2,4]", "[1,2,3]"], "hints": ["Try using the sliding window technique.", "Use a set or map to keep track of the maximum and minimum of subarrays."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().continuousSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:22+00:00", "tests_total": 234, "tests_dropped": 13, "flags": [], "topic_tags": ["array", "queue", "sliding-window", "heap-priority-queue", "ordered-set", "monotonic-queue"]}, "language": "ruby", "interface": {"raw_signature": "def continuous_subarrays(nums)", "container": null, "callable": "continuous_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2763, "task_id": "sum-of-imbalance-numbers-of-all-subarrays", "difficulty": "Hard", "problem_description": "The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:\n\n- 0 <= i < n - 1, and\n- sarr[i+1] - sarr[i] > 1\n\nHere, sorted(arr) is the function that returns the sorted version of arr.\n\nGiven a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,1,4]\nOutput: 3\nExplanation: There are 3 subarrays with non-zero imbalance numbers:\n- Subarray [3, 1] with an imbalance number of 1.\n- Subarray [3, 1, 4] with an imbalance number of 1.\n- Subarray [1, 4] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.\n\nExample 2:\n\nInput: nums = [1,3,3,3,5]\nOutput: 8\nExplanation: There are 7 subarrays with non-zero imbalance numbers:\n- Subarray [1, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.\n- Subarray [3, 3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 5] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 3, 1, 4]) == 3\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 3, 3, 3, 5]) == 8\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 36\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 105\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10]) == 73\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 11, 12, 13, 14, 15]) == 166\n assert candidate(nums = [3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 5, 5, 5, 5]) == 64\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == 46\n assert candidate(nums = [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, 5, 2, 6, 3, 7, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 84\n assert candidate(nums = [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, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10, 15, 11, 14, 12, 13]) == 204\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9, 10]) == 69\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 262\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]) == 72\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 262\n assert candidate(nums = [3, 1, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 6\n assert candidate(nums = [5, 3, 2, 4, 1, 6, 7, 8, 9, 10, 11, 12]) == 47\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, 1, 3, 2, 4, 6, 7, 8, 9, 10]) == 31\n assert candidate(nums = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5, 15, 11, 14, 12, 13]) == 118\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]) == 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, 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 = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15]) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 30\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]) == 171\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 8\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9]) == 54\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15]) == 68\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, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5]) == 80\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\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, 23, 22, 25, 24]) == 265\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 = [7, 3, 5, 9, 1, 4, 6, 8, 2, 10]) == 91\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 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]) == 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]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13, 18, 17, 16, 21, 20, 19, 24, 23, 22, 27, 26, 25, 29, 28]) == 461\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, 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]) == 72\n assert candidate(nums = [2, 1, 3, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 85\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, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 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]) == 36\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 9\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == 154\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 846\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 36\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 7, 8, 10, 9]) == 39\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 36\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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]) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [5, 1, 4, 2, 8, 6, 3, 7, 9]) == 49\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 7\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 134\n assert candidate(nums = [2, 3, 1, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28]) == 391\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]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 3, 3, 3, 3, 3]) == 250\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 3, 2]) == 1\n assert candidate(nums = [1, 3, 3, 3, 5]) == 8\n assert candidate(nums = [1, 5, 3, 4, 2]) == 6\n assert candidate(nums = [1, 2, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 0\n assert candidate(nums = [3, 1, 2]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [3, 2, 1]) == 0\n assert candidate(nums = [3, 1, 2, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == 35\n assert candidate(nums = [7, 9, 5, 8, 2, 6, 3, 4, 1]) == 46\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4]) == 0\n assert candidate(nums = [1, 2, 3, 4]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 0\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 14\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4]) == 0\n assert candidate(nums = [10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == 35\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 1]) == 0\n assert candidate(nums = [3, 2, 1, 2, 3]) == 0\n assert candidate(nums = [2, 3, 1, 4]) == 3\n assert candidate(nums = [3, 1, 2, 4, 3]) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5]) == 0\n assert candidate(nums = [2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1]) == 0\n assert candidate(nums = [3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [3, 2, 1, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == 0\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 4, 2, 3]) == 3\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [2, 1, 3]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5]) == 0\n assert candidate(nums = [1, 2, 2, 1, 2]) == 0\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4]) == 0\n assert candidate(nums = [1, 5, 2, 4, 3]) == 6\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [7, 8, 9, 1, 2, 3, 4, 5, 6]) == 17\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [3, 3, 2, 2, 1, 1]) == 0\n assert candidate(nums = [3, 3, 2, 2, 1, 1]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 0\n", "comparison": "exact"}, "public_tests": ["[2,3,1,4]", "[1,3,3,3,5]"], "hints": ["Iterate over all subarrays in a nested fashion. Namely, for each left endpoint, start from nums[left] and add elements nums[left + 1], nums[left + 2], etc.", "To keep track of the imbalance value, maintain a set of added elements.", "Increment the imbalance value whenever a new number is not adjacent (+/- 1) to other old numbers. For example, when you add 3 to [1, 5], or when you add 5 to [1, 3]. For a formal proof, consider three cases: new value is (i) largest, (ii) smallest, (iii) between two old numbers.", "Decrement the imbalance value whenever a new number is adjacent (+/- 1) to two old numbers. For example, when you add 3 to [2, 4]. The imbalance value does not change in the case of one adjacent old number."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumImbalanceNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:24+00:00", "tests_total": 181, "tests_dropped": 38, "flags": [], "topic_tags": ["array", "hash-table", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def sum_imbalance_numbers(nums)", "container": null, "callable": "sum_imbalance_numbers", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2765, "task_id": "longest-alternating-subarray", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:\n\n- m is greater than 1.\n- s_1 = s_0 + 1.\n- The 0-indexed subarray s looks like [s_0, s_1, s_0, s_1,...,s_{(m-1) % 2}]. In other words, s_1 - s_0 = 1, s_2 - s_1 = -1, s_3 - s_2 = 1, s_4 - s_3 = -1, and so on up to s[m - 1] - s[m - 2] = (-1)^m.\n\nReturn the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,4,3,4]\nOutput: 4\nExplanation:\nThe alternating subarrays are [2, 3], [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.\n\nExample 2:\n\nInput: nums = [4,5,6]\nOutput: 2\nExplanation:\n[4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 9, 8, 9, 8, 9, 10]) == 4\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 3, 2, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == -1\n assert candidate(nums = [2, 2, 2, 3, 4, 3, 2, 3, 4]) == 3\n assert candidate(nums = [2, 3, 4, 3, 4]) == 4\n assert candidate(nums = [5, 4, 5, 4, 5]) == 4\n assert candidate(nums = [2, 1, 2, 1, 2]) == 4\n assert candidate(nums = [10, 9, 10, 9, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [10, 9, 10, 9, 10, 9]) == 5\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4]) == 9\n assert candidate(nums = [5, 6, 7, 8, 7, 6, 7, 8]) == 3\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 9, 8, 7, 6]) == 3\n assert candidate(nums = [1, 3, 2, 3, 2, 3]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5]) == -1\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 2]) == 5\n assert candidate(nums = [3, 2, 3, 2, 3, 2, 3]) == 6\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 4, 3, 2]) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 2\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2]) == 8\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1]) == 7\n assert candidate(nums = [10, 9, 10, 9, 10, 9, 10]) == 6\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3]) == 4\n assert candidate(nums = [3, 4, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 2\n assert candidate(nums = [4, 5, 6]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 4]) == 4\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [10, 11, 10, 11, 12, 13, 12, 11, 12, 11, 10]) == 4\n assert candidate(nums = [9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10]) == 18\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9]) == 4\n assert candidate(nums = [7, 8, 9, 10, 9, 8, 9, 10, 9, 8, 9, 10, 9, 8, 9]) == 3\n assert candidate(nums = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10]) == 18\n assert candidate(nums = [3, 4, 3, 4, 3, 4, 5, 4, 3, 4, 3, 4, 5, 4, 3]) == 6\n assert candidate(nums = [3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3]) == 3\n assert candidate(nums = [10, 11, 10, 11, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4]) == 4\n assert candidate(nums = [10, 11, 12, 11, 10, 11, 12, 13, 14, 15, 16, 17, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == 3\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2]) == 3\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 12, 11, 10, 11, 12]) == 6\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 19\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 3\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12]) == 14\n assert candidate(nums = [5, 6, 7, 6, 5, 6, 7, 6, 5, 6, 7, 6, 5, 6, 7, 6, 5]) == 3\n assert candidate(nums = [100, 101, 102, 103, 102, 103, 102, 103, 102, 103, 102, 103, 102]) == 11\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6]) == 26\n assert candidate(nums = [2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2]) == 5\n assert candidate(nums = [3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3]) == 33\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\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14]) == -1\n assert candidate(nums = [8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9]) == 20\n assert candidate(nums = [1, 3, 2, 3, 4, 3, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5]) == 3\n assert candidate(nums = [10, 11, 10, 11, 12, 11, 12, 13, 12, 13, 14]) == 4\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 23\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3]) == 3\n assert candidate(nums = [3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 5, 4, 5, 6, 7, 8, 7, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8]) == 35\n assert candidate(nums = [1, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 4\n assert candidate(nums = [2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4]) == 3\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5]) == 4\n assert candidate(nums = [1, 1, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3]) == 4\n assert candidate(nums = [10, 11, 12, 11, 10, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 7, 8, 9]) == 3\n assert candidate(nums = [7, 8, 7, 8, 7, 8, 9, 8, 9, 8, 7, 8, 7, 6, 7, 8, 7]) == 6\n assert candidate(nums = [5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9]) == 4\n assert candidate(nums = [4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6]) == 3\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [7, 8, 7, 8, 9, 8, 7, 8, 9, 10, 9, 8, 7, 8, 9, 10, 11, 10, 9, 8]) == 4\n assert candidate(nums = [3, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5]) == 4\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 7, 8, 7, 8, 9, 10, 9, 10, 9, 8, 7, 6, 5]) == 6\n assert candidate(nums = [15, 16, 17, 18, 19, 20, 21, 20, 19, 18, 17, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 16, 17]) == 3\n assert candidate(nums = [7, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9]) == 24\n assert candidate(nums = [7, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8]) == 19\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3]) == 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]) == 32\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5, 4, 5, 6]) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 18\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 18\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 12, 11, 12, 11]) == 6\n assert candidate(nums = [2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4]) == 3\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]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 3\n assert candidate(nums = [1, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3]) == -1\n assert candidate(nums = [2, 3, 2, 1, 2, 1, 2, 3, 4, 5, 4, 3, 4, 5, 6, 7, 8, 7]) == 4\n assert candidate(nums = [7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7]) == 21\n assert candidate(nums = [1, 3, 2, 3, 4, 3, 5, 6, 5, 7, 8, 7, 9, 10, 9, 11, 12, 11, 13]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 10]) == -1\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6]) == 30\n assert candidate(nums = [7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8]) == 30\n assert candidate(nums = [2, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 5, 4, 3, 4, 3, 4, 3, 4, 3, 4]) == 10\n assert candidate(nums = [2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]) == 3\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6]) == 20\n assert candidate(nums = [2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2]) == 3\n assert candidate(nums = [11, 12, 13, 14, 15, 14, 13, 14, 15, 14, 13, 14, 15, 14, 13, 14, 15, 14, 13, 14, 15, 14, 13, 14, 15, 14, 13, 14]) == 3\n assert candidate(nums = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9]) == 17\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7]) == 23\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 16\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7]) == 4\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 30\n assert candidate(nums = [10, 11, 12, 13, 14, 13, 14, 15, 14, 13, 14, 15, 14, 13, 14]) == 4\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8]) == 4\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2]) == 3\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 4, 5, 6, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 1, 2, 1]) == 6\n assert candidate(nums = [20, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22, 21, 22]) == 22\n assert candidate(nums = [5, 6, 5, 6, 7, 8, 7, 6, 7, 8, 9, 10, 9, 8]) == 4\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 19\n assert candidate(nums = [9, 10, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 5, 6, 7, 8, 7, 8]) == 4\n assert candidate(nums = [4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5]) == 34\n assert candidate(nums = [4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4]) == 20\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 20\n assert candidate(nums = [1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 20\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 3, 4, 5, 4, 5, 4, 5, 4]) == 7\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == -1\n assert candidate(nums = [6, 5, 4, 5, 6, 5, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4]) == 3\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8]) == 4\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]) == 26\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10]) == -1\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 3\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 5]) == 4\n assert candidate(nums = [5, 4, 3, 4, 5, 6, 7, 6, 7, 8, 7, 8, 9, 10, 9, 10, 9, 10, 9]) == 7\n assert candidate(nums = [5, 6, 7, 6, 7, 8, 7, 6, 7, 8, 9, 8, 7, 6]) == 4\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 12, 11, 10, 9, 10, 11, 10]) == 6\n assert candidate(nums = [9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9]) == 25\n assert candidate(nums = [6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7]) == 36\n assert candidate(nums = [2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [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]) == 3\n assert candidate(nums = [5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 3\n assert candidate(nums = [3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4]) == 3\n assert candidate(nums = [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]) == 27\n assert candidate(nums = [10, 11, 10, 9, 10, 9, 8, 7, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7]) == 3\n assert candidate(nums = [7, 8, 7, 8, 9, 10, 9, 10, 11, 12, 11, 12, 13, 14, 13, 12, 11]) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 20\n assert candidate(nums = [9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10]) == 20\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 2, 5, 4, 5, 4, 6, 5, 6, 5, 7, 6, 7, 6, 8, 7, 8, 7]) == 3\n assert candidate(nums = [7, 8, 9, 8, 7, 8, 9, 8, 7, 8, 9, 8, 7, 8, 9, 8, 7, 8, 9, 8, 7, 8, 9, 8, 7]) == 3\n assert candidate(nums = [5, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7, 8, 9]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [5, 6, 7, 8, 7, 8, 9, 10, 9, 10, 11, 12, 11, 12, 13]) == 4\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 10, 11, 12, 11, 10, 9, 10, 11, 12]) == 8\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 21\n assert candidate(nums = [8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7]) == 27\n assert candidate(nums = [7, 8, 9, 8, 9, 8, 9, 10, 9, 8, 7, 6, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [5, 6, 7, 8, 7, 6, 7, 8, 9, 8, 9, 10, 9, 10, 11, 10, 11, 12]) == 4\n", "comparison": "exact"}, "public_tests": ["[2,3,4,3,4]", "[4,5,6]"], "hints": ["As the constraints are low, you can check each subarray for the given condition."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().alternatingSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:29+00:00", "tests_total": 157, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def alternating_subarray(nums)", "container": null, "callable": "alternating_subarray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2766, "task_id": "relocate-marbles", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.\n\nThroughout moveFrom.length steps, you will change the positions of the marbles. On the i^th step, you will move all marbles at position moveFrom[i] to position moveTo[i].\n\nAfter completing all the steps, return the sorted list of occupied positions.\n\nNotes:\n\n- We call a position occupied if there is at least one marble in that position.\n- There may be multiple marbles in a single position.\n\nExample 1:\n\nInput: nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]\nOutput: [5,6,8,9]\nExplanation: Initially, the marbles are at positions 1,6,7,8.\nAt the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.\nAt the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.\nAt the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.\nAt the end, the final positions containing at least one marbles are [5,6,8,9].\n\nExample 2:\n\nInput: nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]\nOutput: [2]\nExplanation: Initially, the marbles are at positions [1,1,3,3].\nAt the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].\nAt the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].\nSince 2 is the only occupied position, we return [2].\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= moveFrom.length <= 10^5\n- moveFrom.length == moveTo.length\n- 1 <= nums[i], moveFrom[i], moveTo[i] <= 10^9\n- The test cases are generated such that there is at least a marble in moveFrom[i] at the moment we want to apply the i^th move.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3],moveTo = [5, 5, 5]) == [4, 5]\n assert candidate(nums = [1, 6, 7, 8],moveFrom = [1, 7, 2],moveTo = [2, 9, 5]) == [5, 6, 8, 9]\n assert candidate(nums = [5, 5, 5, 5],moveFrom = [5],moveTo = [10]) == [10]\n assert candidate(nums = [1, 1, 3, 3],moveFrom = [1, 3],moveTo = [2, 2]) == [2]\n assert candidate(nums = [5, 10, 15],moveFrom = [5, 10],moveTo = [10, 15]) == [15]\n assert candidate(nums = [10, 20, 30],moveFrom = [10, 20],moveTo = [30, 10]) == [10, 30]\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3],moveTo = [3, 4, 5]) == [4, 5]\n assert candidate(nums = [10, 20, 30],moveFrom = [10, 20],moveTo = [15, 25]) == [15, 25, 30]\n assert candidate(nums = [10, 20, 30, 40],moveFrom = [10, 20],moveTo = [15, 25]) == [15, 25, 30, 40]\n assert candidate(nums = [100, 200, 300],moveFrom = [100, 200],moveTo = [200, 300]) == [300]\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3],moveTo = [6, 7, 8]) == [4, 5, 6, 7, 8]\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 4, 3, 2, 1]) == [1, 2, 3]\n assert candidate(nums = [5, 10, 15],moveFrom = [5, 15],moveTo = [10, 20]) == [10, 20]\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],moveFrom = [1, 2, 3, 4, 5],moveTo = [6, 6, 6, 6, 6]) == [6]\n assert candidate(nums = [5, 5, 5, 5, 5],moveFrom = [5],moveTo = [10]) == [10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveFrom = [1, 3, 5, 7, 9],moveTo = [3, 5, 7, 9, 11]) == [11, 13, 15, 17, 19]\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 6],moveFrom = [2, 4, 6],moveTo = [3, 5, 7]) == [1, 3, 5, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [1, 4, 7, 10, 13],moveTo = [2, 5, 8, 11, 14]) == [2, 3, 5, 6, 8, 9, 11, 12, 14, 15]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [1, 3, 5, 7, 9, 11, 13],moveTo = [2, 4, 6, 8, 10, 12, 14]) == [2, 4, 6, 8, 10, 12, 14, 15]\n assert candidate(nums = [2, 4, 6, 8, 10],moveFrom = [2, 4, 6, 8],moveTo = [1, 3, 5, 7]) == [1, 3, 5, 7, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 3, 5, 7, 9],moveTo = [2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 3, 5, 7, 9],moveTo = [2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],moveFrom = [5, 15, 25, 35, 45],moveTo = [10, 20, 30, 40, 50]) == [10, 20, 30, 40, 50]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 20, 30, 40, 50],moveTo = [15, 25, 35, 45, 55]) == [15, 25, 35, 45, 55, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveTo = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == [1, 2, 3, 4]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 4, 3, 2, 1]) == [1, 2, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 6, 7, 8, 9]) == [6, 7, 8, 9, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveFrom = [1, 3, 5, 7, 9],moveTo = [2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10, 11, 13, 15, 17, 19]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 20, 30, 40, 50],moveTo = [50, 60, 70, 80, 90]) == [60, 70, 80, 90, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [1, 3, 5, 7, 9, 11, 13, 15],moveTo = [2, 4, 6, 8, 10, 12, 14, 16]) == [2, 4, 6, 8, 10, 12, 14, 16]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],moveFrom = [1, 5, 9, 13],moveTo = [2, 6, 10, 14]) == [2, 3, 6, 7, 10, 11, 14]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveTo = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50],moveFrom = [10, 20, 30, 40, 50],moveTo = [20, 30, 40, 50, 60]) == [60]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveFrom = [1, 5, 9, 13, 17],moveTo = [2, 6, 10, 14, 18]) == [2, 3, 6, 7, 10, 11, 14, 15, 18, 19]\n assert candidate(nums = [10, 20, 30, 40, 50],moveFrom = [10, 20, 30, 40],moveTo = [50, 40, 30, 20]) == [20, 30, 50]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],moveFrom = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],moveTo = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],moveFrom = [100, 300, 500, 700, 900],moveTo = [200, 400, 600, 800, 1000]) == [200, 400, 600, 800, 1000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 30, 50, 70, 90],moveTo = [15, 45, 65, 85, 105]) == [15, 20, 40, 45, 60, 65, 80, 85, 100, 105]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveFrom = [3, 5, 7, 9, 11],moveTo = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5, 13, 15, 17, 19]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],moveFrom = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveTo = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 30, 50, 70, 90],moveTo = [20, 40, 60, 80, 100]) == [20, 40, 60, 80, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 3, 5, 7, 9],moveTo = [9, 7, 5, 3, 1]) == [1, 2, 3, 4, 5, 6, 8, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [1, 3, 5, 7, 9, 11, 13, 15],moveTo = [2, 4, 6, 8, 10, 12, 14, 16]) == [2, 4, 6, 8, 10, 12, 14, 16]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],moveFrom = [5, 15, 25, 35, 45, 55, 65, 75],moveTo = [10, 20, 30, 40, 50, 60, 70, 80]) == [10, 20, 30, 40, 50, 60, 70, 80]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [6, 7, 8, 9, 10]) == [6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [2, 4, 6, 8, 10],moveTo = [1, 3, 5, 7, 9]) == [1, 3, 5, 7, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveFrom = [1, 3, 5, 7, 9],moveTo = [2, 4, 6, 8, 10]) == [2, 4, 6, 8, 10, 11, 13, 15, 17, 19]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 30, 50, 70, 90],moveTo = [20, 40, 60, 80, 100]) == [20, 40, 60, 80, 100]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],moveFrom = [10, 30, 50, 70, 90, 110, 130],moveTo = [15, 35, 55, 75, 95, 115, 135]) == [15, 20, 35, 40, 55, 60, 75, 80, 95, 100, 115, 120, 135, 140, 150]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],moveFrom = [5, 25, 45, 65, 85],moveTo = [10, 30, 50, 70, 90]) == [10, 15, 30, 35, 50, 55, 70, 75, 90, 95]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 3, 5, 7, 9],moveTo = [11, 12, 13, 14, 15]) == [2, 4, 6, 8, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],moveFrom = [100, 200, 300, 400, 500, 600, 700, 800, 900],moveTo = [101, 201, 301, 401, 501, 601, 701, 801, 901]) == [101, 201, 301, 401, 501, 601, 701, 801, 901, 1000]\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],moveFrom = [1, 2, 3, 4],moveTo = [5, 5, 5, 5]) == [5]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],moveFrom = [5, 15, 25, 35, 45],moveTo = [10, 20, 30, 40, 50]) == [10, 20, 30, 40, 50]\n assert candidate(nums = [1000000000, 1000000000, 1000000000],moveFrom = [1000000000],moveTo = [999999999]) == [999999999]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9],moveTo = [10, 9, 8, 7, 6, 5, 4, 3, 2]) == [2, 3, 4, 5, 10]\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5],moveFrom = [1, 2, 3, 4],moveTo = [6, 7, 8, 9]) == [5, 6, 7, 8, 9]\n assert candidate(nums = [10, 20, 30, 40, 50],moveFrom = [10, 30, 50],moveTo = [20, 40, 60]) == [20, 40, 60]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],moveFrom = [100, 200, 300, 400, 500],moveTo = [150, 250, 350, 450, 550]) == [150, 250, 350, 450, 550, 600, 700, 800, 900, 1000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 20, 30, 40, 50],moveTo = [11, 21, 31, 41, 51]) == [11, 21, 31, 41, 51, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],moveFrom = [1, 2, 3, 4],moveTo = [3, 4, 5, 6]) == [5, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9],moveTo = [10, 9, 8, 7, 6, 5, 4, 3, 2]) == [2, 3, 4, 5, 10]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],moveFrom = [100, 200, 300, 400, 500, 600, 700, 800, 900],moveTo = [900, 800, 700, 600, 500, 400, 300, 200, 100]) == [100, 200, 300, 400, 500, 1000]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [6, 6, 6, 6, 6]) == [6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5],moveTo = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 1, 1, 2, 2, 3],moveFrom = [1, 2, 3],moveTo = [4, 5, 6]) == [4, 5, 6]\n assert candidate(nums = [1, 2, 3, 4, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 4, 3, 2, 1]) == [1, 2, 3]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [6, 7, 8, 9, 10]) == [6, 7, 8, 9, 10]\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000],moveFrom = [1000000, 2000000, 3000000, 4000000, 5000000],moveTo = [5000000, 4000000, 3000000, 2000000, 1000000]) == [1000000, 2000000, 3000000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 20, 30, 40, 50],moveTo = [20, 30, 40, 50, 60]) == [60, 70, 80, 90, 100]\n assert candidate(nums = [5, 10, 15, 20, 25, 30],moveFrom = [5, 10, 15, 20, 25],moveTo = [10, 15, 20, 25, 30]) == [30]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveTo = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 4, 3, 2, 1]) == [1, 2, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveTo = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [5, 6, 7, 8, 9, 10],moveTo = [16, 17, 18, 19, 20, 21]) == [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9],moveFrom = [2, 5, 8],moveTo = [10, 11, 12]) == [1, 3, 4, 6, 7, 9, 10, 11, 12]\n assert candidate(nums = [1, 3, 5, 7, 9],moveFrom = [1, 3, 5],moveTo = [2, 4, 6]) == [2, 4, 6, 7, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],moveFrom = [1, 5, 9, 13],moveTo = [2, 6, 10, 14]) == [2, 3, 6, 7, 10, 11, 14, 15]\n assert candidate(nums = [1, 1, 2, 2, 3, 3],moveFrom = [1, 2, 3],moveTo = [4, 5, 6]) == [4, 5, 6]\n assert candidate(nums = [1, 3, 5, 7, 9],moveFrom = [1, 5, 9],moveTo = [2, 6, 10]) == [2, 3, 6, 7, 10]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],moveTo = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],moveFrom = [1, 3, 5, 7],moveTo = [2, 4, 6, 8]) == [2, 4, 6, 8, 9, 11, 13, 15]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],moveFrom = [5, 10, 15, 20, 25],moveTo = [10, 15, 20, 25, 30]) == [30, 35, 40, 45, 50]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],moveFrom = [100, 300, 500, 700, 900],moveTo = [200, 400, 600, 800, 1000]) == [200, 400, 600, 800, 1000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveTo = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],moveFrom = [1, 3, 5, 7, 9],moveTo = [9, 7, 5, 3, 1]) == [1, 2, 3, 4, 5, 6, 8]\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9],moveTo = [11, 12, 13, 14, 15, 16, 17, 18, 19]) == [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 6, 7, 8, 9]) == [6, 7, 8, 9, 10]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],moveFrom = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],moveTo = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [15]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],moveFrom = [1, 5, 9, 13, 17],moveTo = [2, 6, 10, 14, 18]) == [2, 3, 6, 7, 10, 11, 14, 15, 18, 19]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveTo = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [11]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5],moveTo = [5, 4, 3, 2, 1]) == [1, 2, 3, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],moveFrom = [10, 20, 30, 40, 50, 60, 70, 80, 90],moveTo = [5, 15, 25, 35, 45, 55, 65, 75, 85]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],moveFrom = [1, 2, 3, 4, 5],moveTo = [10, 9, 8, 7, 6]) == [6, 7, 8, 9, 10]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],moveFrom = [1, 10, 100, 1000, 10000],moveTo = [1000000000, 100000000, 10000000, 1000000, 100000]) == [100000, 1000000, 10000000, 100000000, 1000000000]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],moveFrom = [5, 10, 15, 20, 25],moveTo = [6, 11, 16, 21, 26]) == [6, 11, 16, 21, 26, 30, 35, 40, 45, 50]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000],moveFrom = [1, 10, 100, 1000, 10000],moveTo = [10, 100, 1000, 10000, 100000]) == [100000]\n", "comparison": "exact"}, "public_tests": ["[1,6,7,8]\n[1,7,2]\n[2,9,5]", "[1,1,3,3]\n[1,3]\n[2,2]"], "hints": ["Can we solve this problem using a set or map?", "Sequentially process pairs from moveFrom[i] and moveTo[i]. In each step, remove the occurrence of moveFrom[i] and add moveTo[i] into the set."], "metadata": {"canonical_parameter_names": ["nums", "moveFrom", "moveTo"], "leetcode_dataset_entry_point": "Solution().relocateMarbles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:31+00:00", "tests_total": 97, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def relocate_marbles(nums, move_from, move_to)", "container": null, "callable": "relocate_marbles", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "move_from", "type": "Integer[]"}, {"name": "move_to", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2767, "task_id": "partition-string-into-minimum-beautiful-substrings", "difficulty": "Medium", "problem_description": "Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.\n\nA string is beautiful if:\n\n- It doesn't contain leading zeros.\n- It's the binary representation of a number that is a power of 5.\n\nReturn the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings, return -1.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"1011\"\nOutput: 2\nExplanation: We can paritition the given string into [\"101\", \"1\"].\n- The string \"101\" does not contain leading zeros and is the binary representation of integer 5^1 = 5.\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 5^0 = 1.\nIt can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.\n\nExample 2:\n\nInput: s = \"111\"\nOutput: 3\nExplanation: We can paritition the given string into [\"1\", \"1\", \"1\"].\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 5^0 = 1.\nIt can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.\n\nExample 3:\n\nInput: s = \"0\"\nOutput: -1\nExplanation: We can not partition the given string into beautiful substrings.\n\nConstraints:\n\n- 1 <= s.length <= 15\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1100101\") == -1\n assert candidate(s = \"100000000000000\") == -1\n assert candidate(s = \"101010101010101\") == -1\n assert candidate(s = \"101010101\") == -1\n assert candidate(s = \"111\") == 3\n assert candidate(s = \"100000\") == -1\n assert candidate(s = \"111111111\") == 9\n assert candidate(s = \"0\") == -1\n assert candidate(s = \"1010101\") == -1\n assert candidate(s = \"1111111\") == 7\n assert candidate(s = \"111111111111111\") == 15\n assert candidate(s = \"1100001\") == -1\n assert candidate(s = \"1011\") == 2\n assert candidate(s = \"100111\") == -1\n assert candidate(s = \"100111011\") == -1\n assert candidate(s = \"1\") == 1\n assert candidate(s = \"110000\") == -1\n assert candidate(s = \"1000000\") == -1\n assert candidate(s = \"1110111\") == 5\n assert candidate(s = \"100000000\") == -1\n assert candidate(s = \"110011001\") == -1\n assert candidate(s = \"11001\") == 1\n assert candidate(s = \"10101010101\") == -1\n assert candidate(s = \"100010001000100\") == -1\n assert candidate(s = \"101010101010001\") == -1\n assert candidate(s = \"111011011001111\") == -1\n assert candidate(s = \"100000000000001\") == -1\n assert candidate(s = \"111000111000111\") == -1\n assert candidate(s = \"10000000000000\") == -1\n assert candidate(s = \"1001101\") == -1\n assert candidate(s = \"110101011010101\") == -1\n assert candidate(s = \"111101111\") == 7\n assert candidate(s = \"1010101010\") == -1\n assert candidate(s = \"1100011\") == -1\n assert candidate(s = \"11010101101\") == -1\n assert candidate(s = \"10100001001\") == -1\n assert candidate(s = \"1111100000001\") == -1\n assert candidate(s = \"111110111110111\") == 7\n assert candidate(s = \"010001\") == -1\n assert candidate(s = \"110011\") == 2\n assert candidate(s = \"10011101\") == -1\n assert candidate(s = \"100100100100100\") == -1\n assert candidate(s = \"1011101\") == 3\n assert candidate(s = \"111001110011100\") == -1\n assert candidate(s = \"110011001100110\") == -1\n assert candidate(s = \"11111100111\") == 7\n assert candidate(s = \"1111101111101\") == 5\n assert candidate(s = \"1010010101010\") == -1\n assert candidate(s = \"11010110111\") == -1\n assert candidate(s = \"11001101\") == 2\n assert candidate(s = \"101101001\") == -1\n assert candidate(s = \"100100010010001\") == -1\n assert candidate(s = \"111100001111\") == -1\n assert candidate(s = \"110010\") == -1\n assert candidate(s = \"1001001\") == -1\n assert candidate(s = \"100110010011001\") == -1\n assert candidate(s = \"1100100110001\") == -1\n assert candidate(s = \"1000000000000\") == -1\n assert candidate(s = \"1111100111\") == 6\n assert candidate(s = \"111111111111110\") == -1\n assert candidate(s = \"111011101110111\") == 9\n assert candidate(s = \"000000000000000\") == -1\n assert candidate(s = \"11010101010\") == -1\n assert candidate(s = \"1111111111111\") == 13\n assert candidate(s = \"111110111100001\") == -1\n assert candidate(s = \"10000100001\") == -1\n assert candidate(s = \"11101001101\") == -1\n assert candidate(s = \"0101010101\") == -1\n assert candidate(s = \"11001000110101\") == -1\n assert candidate(s = \"10110110110\") == -1\n assert candidate(s = \"11011011011\") == 5\n assert candidate(s = \"101010101010110\") == -1\n assert candidate(s = \"11111111101\") == 5\n assert candidate(s = \"1010101010101\") == -1\n assert candidate(s = \"1100010000100\") == -1\n assert candidate(s = \"1110011100111\") == 5\n assert candidate(s = \"1111100001\") == -1\n assert candidate(s = \"10011001\") == -1\n assert candidate(s = \"110010111011101\") == -1\n assert candidate(s = \"110011101100111\") == -1\n assert candidate(s = \"111101110111011\") == 9\n assert candidate(s = \"1001001001001\") == -1\n assert candidate(s = \"11111111111\") == 11\n assert candidate(s = \"100101010100101\") == -1\n assert candidate(s = \"101111111111111\") == 13\n assert candidate(s = \"111100001111000\") == -1\n assert candidate(s = \"111111000111111\") == -1\n assert candidate(s = \"1111101\") == 1\n assert candidate(s = \"000000\") == -1\n assert candidate(s = \"111111000000111\") == -1\n assert candidate(s = \"110110110110110\") == -1\n assert candidate(s = \"1000000000001\") == -1\n assert candidate(s = \"110010111\") == -1\n assert candidate(s = \"100000100000100\") == -1\n assert candidate(s = \"1001110001\") == 1\n", "comparison": "exact"}, "public_tests": ["\"1011\"", "\"111\"", "\"0\""], "hints": ["To check if number x is a power of 5 or not, we will divide x by 5 while x > 1 and x mod 5 == 0. After iteration if x == 1, then it was a power of 5.", "Since the constraint of s.length is small, we can use recursion to find all the partitions."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumBeautifulSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:33+00:00", "tests_total": 148, "tests_dropped": 53, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming", "backtracking"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_beautiful_substrings(s)", "container": null, "callable": "minimum_beautiful_substrings", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2768, "task_id": "number-of-black-blocks", "difficulty": "Medium", "problem_description": "You are given two integers m and n representing the dimensions of a 0-indexed m x n grid.\n\nYou are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.\n\nA block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].\n\nReturn a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i black cells.\n\nExample 1:\n\nInput: m = 3, n = 3, coordinates = [[0,0]]\nOutput: [3,1,0,0,0]\nExplanation: The grid looks like this:\n\nThere is only 1 block with one black cell, and it is the block starting with cell [0,0].\nThe other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.\nThus, we return [3,1,0,0,0].\n\nExample 2:\n\nInput: m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]\nOutput: [0,2,2,0,0]\nExplanation: The grid looks like this:\n\nThere are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).\nThe other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.\nTherefore, we return [0,2,2,0,0].\n\nConstraints:\n\n- 2 <= m <= 10^5\n- 2 <= n <= 10^5\n- 0 <= coordinates.length <= 10^4\n- coordinates[i].length == 2\n- 0 <= coordinates[i][0] < m\n- 0 <= coordinates[i][1] < n\n- It is guaranteed that coordinates contains pairwise distinct coordinates.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 5,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2]]) == [9, 3, 3, 0, 1]\n assert candidate(m = 5,n = 5,coordinates = [[2, 2], [3, 3], [1, 1]]) == [6, 8, 2, 0, 0]\n assert candidate(m = 3,n = 3,coordinates = [[0, 0], [1, 1], [0, 2]]) == [0, 2, 2, 0, 0]\n assert candidate(m = 5,n = 5,coordinates = [[1, 1], [1, 2], [2, 1], [2, 2]]) == [7, 4, 4, 0, 1]\n assert candidate(m = 10,n = 10,coordinates = [[5, 5], [4, 4], [6, 6]]) == [71, 8, 2, 0, 0]\n assert candidate(m = 3,n = 3,coordinates = [[0, 0]]) == [3, 1, 0, 0, 0]\n assert candidate(m = 4,n = 4,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3]]) == [2, 4, 3, 0, 0]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [3, 3]]) == [71, 5, 4, 0, 1]\n assert candidate(m = 10,n = 10,coordinates = [[3, 3], [4, 4], [5, 5]]) == [71, 8, 2, 0, 0]\n assert candidate(m = 4,n = 5,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1]]) == [8, 1, 2, 0, 1]\n assert candidate(m = 5,n = 5,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1]]) == [12, 1, 2, 0, 1]\n assert candidate(m = 4,n = 5,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3]]) == [4, 5, 3, 0, 0]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [9, 9], [4, 4]]) == [75, 6, 0, 0, 0]\n assert candidate(m = 4,n = 4,coordinates = [[0, 1], [1, 0], [1, 2], [2, 1]]) == [1, 4, 4, 0, 0]\n assert candidate(m = 5,n = 5,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3]]) == [6, 7, 3, 0, 0]\n assert candidate(m = 2,n = 2,coordinates = []) == [1, 0, 0, 0, 0]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == [68, 9, 4, 0, 0]\n assert candidate(m = 7,n = 8,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]) == [25, 9, 7, 0, 1]\n assert candidate(m = 100,n = 100,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19]]) == [9743, 39, 19, 0, 0]\n assert candidate(m = 8,n = 7,coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 0], [7, 6]]) == [25, 10, 7, 0, 0]\n assert candidate(m = 20,n = 10,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [4, 0], [4, 1], [4, 2], [5, 0], [5, 1], [5, 2], [6, 0], [6, 1], [6, 2]]) == [150, 1, 8, 0, 12]\n assert candidate(m = 10,n = 5,coordinates = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 4], [2, 0], [2, 4], [3, 0], [3, 4], [4, 0], [4, 4], [5, 0], [5, 4], [6, 0], [6, 4], [7, 0], [7, 4], [8, 0], [8, 4], [9, 0], [9, 4]]) == [16, 0, 18, 2, 0]\n assert candidate(m = 50,n = 50,coordinates = [[25, 25], [24, 24], [26, 26], [24, 25], [25, 24], [25, 26], [26, 25]]) == [2387, 6, 4, 2, 2]\n assert candidate(m = 9,n = 9,coordinates = [[0, 4], [1, 3], [1, 5], [2, 2], [2, 4], [2, 6], [3, 1], [3, 3], [3, 5], [3, 7], [4, 0], [4, 2], [4, 4], [4, 6], [4, 8], [5, 1], [5, 3], [5, 5], [5, 7], [6, 2], [6, 4], [6, 6], [7, 3], [7, 5], [8, 4]]) == [12, 12, 40, 0, 0]\n assert candidate(m = 8,n = 8,coordinates = [[0, 0], [0, 7], [7, 0], [7, 7], [1, 1], [1, 6], [6, 1], [6, 6], [2, 2], [2, 5], [5, 2], [5, 5], [3, 3], [3, 4], [4, 3], [4, 4]]) == [16, 16, 16, 0, 1]\n assert candidate(m = 7,n = 8,coordinates = [[0, 1], [1, 0], [2, 1], [3, 0], [4, 1], [5, 0], [6, 1]]) == [30, 6, 6, 0, 0]\n assert candidate(m = 6,n = 6,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [12, 6, 6, 0, 1]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [56, 14, 10, 0, 1]\n assert candidate(m = 7,n = 7,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5], [5, 3], [5, 4], [5, 5], [6, 6]]) == [12, 2, 14, 0, 8]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [3, 3]]) == [65, 1, 6, 0, 9]\n assert candidate(m = 100,n = 100,coordinates = [[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [3, 3], [50, 50], [50, 51], [50, 52], [50, 53], [51, 50], [51, 51], [51, 52], [51, 53], [52, 50], [52, 51], [52, 52], [52, 53], [53, 50], [53, 51], [53, 52], [53, 53]]) == [9760, 5, 18, 0, 18]\n assert candidate(m = 8,n = 8,coordinates = [[0, 1], [0, 2], [1, 0], [1, 3], [2, 1], [2, 2], [3, 0], [3, 3], [4, 1], [4, 2], [5, 0], [5, 3], [6, 1], [6, 2], [7, 0], [7, 3]]) == [21, 7, 21, 0, 0]\n assert candidate(m = 9,n = 9,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == [42, 10, 8, 0, 4]\n assert candidate(m = 10,n = 20,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [4, 0], [4, 1], [4, 2]]) == [156, 1, 6, 0, 8]\n assert candidate(m = 7,n = 6,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 0], [0, 5], [6, 5], [5, 0], [4, 1], [1, 4], [2, 3], [3, 2]]) == [7, 8, 14, 0, 1]\n assert candidate(m = 9,n = 9,coordinates = [[4, 4], [3, 3], [3, 5], [5, 3], [5, 5], [2, 2], [2, 6], [6, 2], [6, 6], [1, 1], [1, 7], [7, 1], [7, 7], [0, 0], [0, 8], [8, 0], [8, 8]]) == [24, 24, 16, 0, 0]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [56, 16, 9, 0, 0]\n assert candidate(m = 10,n = 5,coordinates = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [1, 4]]) == [28, 0, 4, 0, 4]\n assert candidate(m = 6,n = 6,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5]]) == [8, 2, 10, 0, 5]\n assert candidate(m = 8,n = 8,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == [30, 12, 7, 0, 0]\n assert candidate(m = 9,n = 9,coordinates = [[0, 0], [0, 8], [8, 0], [8, 8], [4, 4], [3, 3], [5, 5], [2, 2], [6, 6]]) == [44, 16, 4, 0, 0]\n assert candidate(m = 9,n = 9,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [0, 1], [1, 0], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6], [8, 7], [7, 8]]) == [36, 6, 15, 2, 5]\n assert candidate(m = 100,n = 100,coordinates = [[10, 10], [10, 11], [11, 10], [11, 11], [20, 20], [21, 20], [20, 21], [21, 21]]) == [9783, 8, 8, 0, 2]\n assert candidate(m = 9,n = 7,coordinates = [[0, 3], [1, 2], [2, 1], [3, 0], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1]]) == [24, 16, 8, 0, 0]\n assert candidate(m = 6,n = 6,coordinates = [[0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4]]) == [8, 3, 9, 1, 4]\n assert candidate(m = 6,n = 7,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [3, 3], [3, 4], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4]]) == [8, 3, 2, 3, 14]\n assert candidate(m = 7,n = 8,coordinates = [[0, 0], [0, 7], [6, 0], [6, 7], [3, 3], [3, 4], [4, 3], [4, 4], [2, 2], [2, 5], [5, 2], [5, 5]]) == [17, 16, 8, 0, 1]\n assert candidate(m = 8,n = 8,coordinates = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6], [6, 5], [6, 6]]) == [19, 7, 15, 1, 7]\n assert candidate(m = 8,n = 7,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5], [6, 6]]) == [21, 5, 11, 0, 5]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]) == [72, 1, 4, 0, 4]\n assert candidate(m = 5,n = 6,coordinates = [[0, 0], [0, 5], [1, 1], [1, 4], [2, 2], [2, 3], [3, 3], [3, 4], [4, 1], [4, 5]]) == [2, 9, 7, 2, 0]\n assert candidate(m = 7,n = 6,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [14, 7, 5, 2, 2]\n assert candidate(m = 8,n = 8,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [0, 7], [7, 0]]) == [28, 14, 7, 0, 0]\n assert candidate(m = 6,n = 6,coordinates = [[0, 0], [0, 5], [5, 0], [5, 5], [2, 2], [3, 3], [1, 1], [4, 4]]) == [10, 10, 5, 0, 0]\n assert candidate(m = 8,n = 6,coordinates = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5]]) == [14, 4, 12, 0, 5]\n assert candidate(m = 15,n = 20,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [238, 19, 9, 0, 0]\n assert candidate(m = 5,n = 10,coordinates = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == [27, 0, 9, 0, 0]\n assert candidate(m = 12,n = 11,coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [81, 19, 10, 0, 0]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3]]) == [69, 3, 7, 0, 2]\n assert candidate(m = 5,n = 4,coordinates = [[0, 1], [1, 2], [2, 0], [3, 1], [3, 2], [4, 0], [4, 1]]) == [0, 7, 3, 2, 0]\n assert candidate(m = 7,n = 8,coordinates = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5]]) == [23, 16, 3, 0, 0]\n assert candidate(m = 12,n = 10,coordinates = [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], [5, 5], [6, 5], [7, 5], [5, 6], [6, 6], [7, 6]]) == [78, 5, 10, 0, 6]\n assert candidate(m = 6,n = 5,coordinates = [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 0], [3, 2], [4, 0], [4, 1], [4, 2], [5, 0], [5, 1]]) == [5, 1, 4, 7, 3]\n assert candidate(m = 7,n = 8,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [3, 5], [4, 4], [4, 5], [4, 6], [5, 5], [5, 6], [5, 7]]) == [18, 5, 9, 4, 6]\n assert candidate(m = 6,n = 7,coordinates = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5]]) == [13, 3, 11, 0, 3]\n assert candidate(m = 7,n = 8,coordinates = [[0, 1], [0, 3], [1, 2], [1, 4], [2, 1], [2, 3], [2, 5], [3, 2], [3, 4], [3, 6], [4, 1], [4, 3], [4, 5], [5, 2], [5, 4], [6, 3]]) == [7, 12, 23, 0, 0]\n assert candidate(m = 10,n = 10,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [52, 10, 14, 0, 5]\n assert candidate(m = 5,n = 6,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4]]) == [6, 1, 8, 0, 5]\n assert candidate(m = 6,n = 7,coordinates = [[0, 0], [0, 6], [1, 1], [1, 5], [2, 2], [2, 4], [3, 3], [4, 2], [4, 4], [5, 1], [5, 5]]) == [6, 14, 10, 0, 0]\n assert candidate(m = 8,n = 8,coordinates = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 3], [4, 4]]) == [34, 5, 6, 0, 4]\n assert candidate(m = 9,n = 9,coordinates = [[0, 1], [0, 2], [1, 0], [1, 3], [2, 1], [2, 2], [3, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == [37, 13, 12, 2, 0]\n", "comparison": "exact"}, "public_tests": ["3\n3\n[[0,0]]", "3\n3\n[[0,0],[1,1],[0,2]]"], "hints": ["The number of blocks is too much but the number of black cells is less than that.", "It means the number of blocks with at least one black cell is O(|coordinates|). let’s just hold them.", "Iterate through the coordinates and update the block counts accordingly. For each coordinate, determine which block(s) it belongs to and increment the count of black cells for those block(s).", "After processing all the coordinates, count the number of blocks with different numbers of black cells. You can use another data structure to keep track of the counts of blocks with 0 black cells, 1 black cell, and so on."], "metadata": {"canonical_parameter_names": ["m", "n", "coordinates"], "leetcode_dataset_entry_point": "Solution().countBlackBlocks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:36+00:00", "tests_total": 72, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def count_black_blocks(m, n, coordinates)", "container": null, "callable": "count_black_blocks", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "coordinates", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2769, "task_id": "find-the-maximum-achievable-number", "difficulty": "Easy", "problem_description": "Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times:\n\n- Increase or decrease x by 1, and simultaneously increase or decrease num by 1.\n\nReturn the maximum possible value of x.\n\nExample 1:\n\nInput: num = 4, t = 1\nOutput: 6\nExplanation:\nApply the following operation once to make the maximum achievable number equal to num:\n- Decrease the maximum achievable number by 1, and increase num by 1.\n\nExample 2:\n\nInput: num = 3, t = 2\nOutput: 7\nExplanation:\nApply the following operation twice to make the maximum achievable number equal to num:\n- Decrease the maximum achievable number by 1, and increase num by 1.\n\nConstraints:\n\n- 1 <= num, t <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 1,t = 50) == 101\n assert candidate(num = 10,t = 5) == 20\n assert candidate(num = 50,t = 50) == 150\n assert candidate(num = 1,t = 1) == 3\n assert candidate(num = 25,t = 25) == 75\n assert candidate(num = 3,t = 2) == 7\n assert candidate(num = 4,t = 1) == 6\n assert candidate(num = 25,t = 10) == 45\n assert candidate(num = 2,t = 45) == 92\n assert candidate(num = 28,t = 12) == 52\n assert candidate(num = 42,t = 15) == 72\n assert candidate(num = 45,t = 4) == 53\n assert candidate(num = 35,t = 28) == 91\n assert candidate(num = 7,t = 20) == 47\n assert candidate(num = 40,t = 1) == 42\n assert candidate(num = 27,t = 15) == 57\n assert candidate(num = 30,t = 15) == 60\n assert candidate(num = 28,t = 28) == 84\n assert candidate(num = 18,t = 49) == 116\n assert candidate(num = 29,t = 17) == 63\n assert candidate(num = 30,t = 29) == 88\n assert candidate(num = 35,t = 10) == 55\n assert candidate(num = 8,t = 8) == 24\n assert candidate(num = 49,t = 50) == 149\n assert candidate(num = 30,t = 45) == 120\n assert candidate(num = 28,t = 30) == 88\n assert candidate(num = 20,t = 35) == 90\n assert candidate(num = 5,t = 50) == 105\n assert candidate(num = 10,t = 40) == 90\n assert candidate(num = 29,t = 15) == 59\n assert candidate(num = 33,t = 18) == 69\n assert candidate(num = 27,t = 30) == 87\n assert candidate(num = 40,t = 10) == 60\n assert candidate(num = 2,t = 25) == 52\n assert candidate(num = 45,t = 15) == 75\n assert candidate(num = 23,t = 48) == 119\n assert candidate(num = 49,t = 10) == 69\n assert candidate(num = 20,t = 45) == 110\n assert candidate(num = 15,t = 45) == 105\n assert candidate(num = 12,t = 10) == 32\n assert candidate(num = 2,t = 30) == 62\n assert candidate(num = 12,t = 40) == 92\n assert candidate(num = 37,t = 30) == 97\n assert candidate(num = 7,t = 7) == 21\n assert candidate(num = 1,t = 20) == 41\n assert candidate(num = 7,t = 43) == 93\n assert candidate(num = 20,t = 1) == 22\n assert candidate(num = 10,t = 1) == 12\n assert candidate(num = 42,t = 9) == 60\n assert candidate(num = 45,t = 20) == 85\n assert candidate(num = 45,t = 45) == 135\n assert candidate(num = 45,t = 10) == 65\n assert candidate(num = 1,t = 25) == 51\n assert candidate(num = 30,t = 25) == 80\n assert candidate(num = 5,t = 30) == 65\n assert candidate(num = 45,t = 1) == 47\n assert candidate(num = 12,t = 38) == 88\n assert candidate(num = 15,t = 20) == 55\n assert candidate(num = 20,t = 30) == 80\n assert candidate(num = 7,t = 35) == 77\n assert candidate(num = 50,t = 2) == 54\n assert candidate(num = 40,t = 5) == 50\n assert candidate(num = 35,t = 15) == 65\n assert candidate(num = 27,t = 27) == 81\n assert candidate(num = 22,t = 35) == 92\n assert candidate(num = 50,t = 25) == 100\n assert candidate(num = 49,t = 25) == 99\n assert candidate(num = 2,t = 40) == 82\n assert candidate(num = 15,t = 30) == 75\n assert candidate(num = 30,t = 30) == 90\n assert candidate(num = 33,t = 15) == 63\n assert candidate(num = 35,t = 18) == 71\n assert candidate(num = 15,t = 40) == 95\n assert candidate(num = 23,t = 3) == 29\n assert candidate(num = 40,t = 20) == 80\n assert candidate(num = 30,t = 20) == 70\n assert candidate(num = 33,t = 17) == 67\n assert candidate(num = 7,t = 25) == 57\n assert candidate(num = 47,t = 5) == 57\n assert candidate(num = 50,t = 1) == 52\n assert candidate(num = 29,t = 21) == 71\n assert candidate(num = 20,t = 25) == 70\n", "comparison": "exact"}, "public_tests": ["4\n1", "3\n2"], "hints": ["Let x be the answer, it’s always optimal to decrease x in each operation and increase nums."], "metadata": {"canonical_parameter_names": ["num", "t"], "leetcode_dataset_entry_point": "Solution().theMaximumAchievableX", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:38+00:00", "tests_total": 82, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def the_maximum_achievable_x(num, t)", "container": null, "callable": "the_maximum_achievable_x", "parameters": [{"name": "num", "type": "Integer"}, {"name": "t", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2770, "task_id": "maximum-number-of-jumps-to-reach-the-last-index", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums of n integers and an integer target.\n\nYou are initially positioned at index 0. In one step, you can jump from index i to any index j such that:\n\n- 0 <= i < j < n\n- -target <= nums[j] - nums[i] <= target\n\nReturn the maximum number of jumps you can make to reach index n - 1.\n\nIf there is no way to reach index n - 1, return -1.\n\nExample 1:\n\nInput: nums = [1,3,6,4,1,2], target = 2\nOutput: 3\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 3.\n- Jump from index 3 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.\n\nExample 2:\n\nInput: nums = [1,3,6,4,1,2], target = 3\nOutput: 5\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 2.\n- Jump from index 2 to index 3.\n- Jump from index 3 to index 4.\n- Jump from index 4 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.\n\nExample 3:\n\nInput: nums = [1,3,6,4,1,2], target = 0\nOutput: -1\nExplanation: It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.\n\nConstraints:\n\n- 2 <= nums.length == n <= 1000\n- -10^9 <= nums[i] <= 10^9\n- 0 <= target <= 2 * 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 6, 4, 1, 2],target = 3) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],target = 9) == 9\n assert candidate(nums = [1, 5, 10, 15, 20],target = 4) == -1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],target = 9) == 9\n assert candidate(nums = [10, 8, 6, 4, 2],target = 2) == 4\n assert candidate(nums = [0, 0, 0, 0, 0],target = 0) == 4\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],target = 500000000) == 4\n assert candidate(nums = [-1, 0, 1, 2, 3],target = 2) == 4\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000],target = 2000000000) == 3\n assert candidate(nums = [10, 8, 6, 4, 2],target = 1) == -1\n assert candidate(nums = [1, 3, 6, 4, 1, 2],target = 0) == -1\n assert candidate(nums = [1, 5, 9, 14, 20],target = 4) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 0) == 9\n assert candidate(nums = [10, 20, 30, 40, 50],target = 10) == 4\n assert candidate(nums = [1, 5, 10, 15, 20],target = 9) == 4\n assert candidate(nums = [1, 2, 3, 5, 6, 8, 9],target = 2) == 6\n assert candidate(nums = [10, 20, 30, 40, 50],target = 15) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 1) == 9\n assert candidate(nums = [1, 1, 1, 1, 1],target = 1) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 1) == 9\n assert candidate(nums = [1, 1, 1, 1, 1],target = 0) == 4\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],target = 10) == -1\n assert candidate(nums = [1, 3, 5, 7, 9],target = 2) == 4\n assert candidate(nums = [5, 4, 3, 2, 1],target = 1) == 4\n assert candidate(nums = [1, 3, 6, 4, 1, 2],target = 2) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],target = 1) == 4\n assert candidate(nums = [2, 4, 5, 7, 9, 11],target = 2) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 0) == 9\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],target = 4) == 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],target = 2) == 19\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],target = 2) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 0) == 9\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],target = 99) == 9\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],target = 1) == 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],target = 4) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50],target = 5) == -1\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10],target = 9) == 19\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 15) == 9\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 20) == 9\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 10) == 9\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],target = 2) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 0) == -1\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765],target = 20) == -1\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],target = 15) == 9\n assert candidate(nums = [1, 5, 3, 7, 9, 12, 10, 15, 20, 18],target = 5) == 9\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],target = 4) == 19\n assert candidate(nums = [1, 10, 21, 32, 43, 54, 65, 76, 87, 98],target = 9) == -1\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],target = 4) == 9\n assert candidate(nums = [-10, -5, 0, 5, 10, 15],target = 10) == 5\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],target = 9) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 1) == 19\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 0) == 9\n assert candidate(nums = [5, 15, 10, 20, 25, 30],target = 5) == -1\n assert candidate(nums = [9, 7, 5, 3, 1, 0, -2, -4, -6, -8, -10],target = 3) == 10\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 30],target = 5) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 1) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 1) == 14\n assert candidate(nums = [1, 3, 6, 4, 1, 2, 1, 3, 6, 4, 1, 2, 1, 3, 6, 4, 1, 2, 1, 3],target = 2) == 13\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 1) == 21\n assert candidate(nums = [1, 4, 3, 2, 5, 6, 7, 8, 9, 10],target = 3) == 9\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],target = 1) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 0) == -1\n assert candidate(nums = [1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4],target = 3) == 19\n assert candidate(nums = [1000000000, 999999998, 999999996, 999999994, 999999992],target = 2) == 4\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2],target = 1) == 19\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 1) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 10) == 19\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10, 12, 13, 15, 14, 16, 17, 19, 18, 20],target = 2) == 19\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],target = 6) == 19\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 1) == -1\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],target = 50) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 20) == 9\n assert candidate(nums = [5, 1, 4, 2, 8, 7, 3, 6],target = 3) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 15) == 9\n assert candidate(nums = [5, 15, 10, 20, 25, 30, 35],target = 10) == 6\n assert candidate(nums = [1, 3, 6, 4, 1, 2, 8, 5, 7, 10],target = 3) == 8\n assert candidate(nums = [-10, -20, -30, -40, -50],target = 10) == 4\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6],target = 1) == 5\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109],target = 10) == -1\n assert candidate(nums = [1, 5, 3, 7, 2, 6, 4, 8, 1, 9, 5, 10, 6, 11, 7],target = 4) == 10\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],target = 1) == 14\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946],target = 500) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],target = 2) == 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],target = 0) == 19\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],target = 20) == -1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],target = 1) == 19\n assert candidate(nums = [1, 4, 2, 7, 5, 9, 8, 11, 10],target = 3) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],target = 1) == 19\n assert candidate(nums = [1, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11],target = 3) == 14\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],target = 8) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 1) == 19\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 100) == 9\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 15) == 9\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],target = 9) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 1) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3],target = 2) == 14\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 3) == 9\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],target = 0) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],target = 1000000) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 10) == 9\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],target = 20) == -1\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14],target = 1) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 5) == 19\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],target = 30) == 9\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],target = 1) == 10\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],target = 15) == -1\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],target = 1) == 29\n assert candidate(nums = [1, 3, 6, 4, 1, 2, 5, 7, 8, 9],target = 2) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],target = 1) == 19\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],target = 15) == 9\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 30],target = 5) == 6\n assert candidate(nums = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5],target = 4) == 19\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 10) == 9\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4],target = 3) == 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],target = 0) == -1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],target = 1) == 4\n assert candidate(nums = [10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95],target = 10) == 19\n assert candidate(nums = [2, 3, 1, 1, 4, 2, 3, 1, 1, 4, 2, 3, 1, 1, 4, 2, 3, 1, 1, 4],target = 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],target = 1) == 19\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],target = 1) == 14\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 20) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 5) == 19\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 100) == -1\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10],target = 4) == 11\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8],target = 2) == 14\n assert candidate(nums = [1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 3],target = 2) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 9) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 1) == 9\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],target = 1) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 5) == 9\n assert candidate(nums = [1, 3, 6, 7, 10, 12, 15],target = 2) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 2) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 5) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0],target = 10) == 19\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000],target = 999999999) == 9\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],target = 999999999) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 2) == 9\n assert candidate(nums = [10, 5, 10, 15, 20, 25, 30, 35, 40, 45],target = 10) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 15) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 2) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 5) == 9\n", "comparison": "exact"}, "public_tests": ["[1,3,6,4,1,2]\n2", "[1,3,6,4,1,2]\n3", "[1,3,6,4,1,2]\n0"], "hints": ["Use a dynamic programming approach.", "Define a dynamic programming array dp of size n, where dp[i] represents the maximum number of jumps from index 0 to index i.", "For each j iterate over all i < j. Set dp[j] = max(dp[j], dp[i] + 1) if -target <= nums[j] - nums[i] <= target."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().maximumJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:40+00:00", "tests_total": 141, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_jumps(nums, target)", "container": null, "callable": "maximum_jumps", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2771, "task_id": "longest-non-decreasing-subarray-from-two-arrays", "difficulty": "Medium", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2 of length n.\n\nLet's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].\n\nYour task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.\n\nReturn an integer representing the length of the longest non-decreasing subarray in nums3.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums1 = [2,3,1], nums2 = [1,2,1]\nOutput: 2\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].\nThe subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.\nWe can show that 2 is the maximum achievable length.\n\nExample 2:\n\nInput: nums1 = [1,3,2,1], nums2 = [2,2,3,4]\nOutput: 4\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].\nThe entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.\n\nExample 3:\n\nInput: nums1 = [1,1], nums2 = [2,2]\nOutput: 2\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums1[1]] => [1,1].\nThe entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.\n\nConstraints:\n\n- 1 <= nums1.length == nums2.length == n <= 10^5\n- 1 <= nums1[i], nums2[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [2, 3, 1],nums2 = [1, 2, 1]) == 2\n assert candidate(nums1 = [8, 6, 4, 2],nums2 = [7, 5, 3, 1]) == 1\n assert candidate(nums1 = [1, 2, 2, 2, 3],nums2 = [2, 2, 3, 3, 4]) == 5\n assert candidate(nums1 = [1000000000, 1, 1000000000],nums2 = [1, 1000000000, 1]) == 3\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000],nums2 = [1000000000, 1000000000, 1000000000]) == 3\n assert candidate(nums1 = [1, 3, 5, 7],nums2 = [2, 4, 6, 8]) == 4\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1]) == 3\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 5\n assert candidate(nums1 = [3, 3, 3, 3],nums2 = [3, 3, 3, 3]) == 4\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums1 = [8, 4, 6, 2],nums2 = [7, 3, 5, 1]) == 2\n assert candidate(nums1 = [5, 3, 4, 5],nums2 = [1, 2, 3, 4]) == 4\n assert candidate(nums1 = [1],nums2 = [2]) == 1\n assert candidate(nums1 = [1, 1],nums2 = [2, 2]) == 2\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums1 = [1, 3, 2, 1],nums2 = [2, 2, 3, 4]) == 4\n assert candidate(nums1 = [1],nums2 = [1]) == 1\n assert candidate(nums1 = [10, 10, 10],nums2 = [10, 10, 10]) == 3\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7],nums2 = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8]) == 21\n assert candidate(nums1 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12],nums2 = [2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13]) == 20\n assert candidate(nums1 = [1, 5, 9, 13, 17, 21],nums2 = [2, 6, 10, 14, 18, 22]) == 6\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(nums1 = [1, 3, 2, 1, 2, 3, 2, 1, 2, 3],nums2 = [2, 4, 3, 2, 3, 4, 3, 2, 3, 4]) == 5\n assert candidate(nums1 = [7, 7, 7, 7, 7, 7, 7],nums2 = [7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 10\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums1 = [10, 9, 2, 5, 3, 7, 101, 18],nums2 = [9, 8, 3, 6, 5, 8, 102, 19]) == 5\n assert candidate(nums1 = [3, 3, 2, 2, 1, 1],nums2 = [2, 2, 1, 1, 3, 3]) == 6\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums1 = [5, 7, 9, 10, 6, 8],nums2 = [6, 7, 8, 9, 10, 5]) == 5\n assert candidate(nums1 = [1, 3, 5, 2, 4, 6, 3, 5, 7],nums2 = [2, 4, 6, 1, 3, 5, 4, 6, 8]) == 3\n assert candidate(nums1 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],nums2 = [2, 4, 3, 5, 4, 6, 5, 7, 6, 8]) == 10\n assert candidate(nums1 = [1, 2, 2, 3, 4, 4, 4, 5, 5, 5],nums2 = [2, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],nums2 = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 15\n assert candidate(nums1 = [3, 6, 9, 12, 15],nums2 = [1, 4, 7, 10, 13]) == 5\n assert candidate(nums1 = [3, 3, 3, 100, 3, 3, 3, 100, 3, 3],nums2 = [100, 3, 3, 3, 100, 3, 3, 3, 100, 3]) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 5\n assert candidate(nums1 = [10, 20, 15, 25, 30, 5, 10, 20, 25, 35],nums2 = [5, 15, 10, 20, 35, 1, 5, 15, 25, 40]) == 5\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums1 = [1, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14]) == 7\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == 8\n assert candidate(nums1 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10],nums2 = [2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 16\n assert candidate(nums1 = [1, 2, 3, 4, 5, 100, 6, 7, 8, 9],nums2 = [1, 2, 3, 4, 5, 5, 6, 7, 8, 9]) == 10\n assert candidate(nums1 = [10, 20, 30, 25, 20, 15, 10, 5],nums2 = [5, 10, 15, 20, 25, 30, 35, 40]) == 8\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 10\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],nums2 = [2, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 15\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [101, 201, 301, 401, 501, 601, 701, 801, 901, 1001]) == 10\n assert candidate(nums1 = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11]) == 10\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 15\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 10\n assert candidate(nums1 = [7, 7, 7, 7, 7],nums2 = [7, 7, 7, 7, 7]) == 5\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [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, 2, 2, 2, 2, 2, 2]) == 31\n assert candidate(nums1 = [5, 3, 5, 3, 5, 3, 5],nums2 = [3, 5, 3, 5, 3, 5, 3]) == 7\n assert candidate(nums1 = [3, 2, 4, 5, 1, 3, 4],nums2 = [4, 3, 5, 6, 2, 4, 5]) == 4\n assert candidate(nums1 = [1, 4, 7, 10, 13, 16, 19],nums2 = [2, 5, 8, 11, 14, 17, 20]) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums1 = [5, 10, 5, 15, 20],nums2 = [3, 8, 7, 12, 25]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == 17\n assert candidate(nums1 = [5, 3, 4, 5, 1, 6, 7, 8, 9, 10],nums2 = [4, 4, 5, 6, 1, 2, 3, 8, 8, 11]) == 6\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 20\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 15\n assert candidate(nums1 = [10, 11, 10, 11, 10, 11],nums2 = [11, 10, 11, 10, 11, 10]) == 6\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [5, 6, 7, 8, 9, 1, 2, 3, 4, 5],nums2 = [4, 5, 6, 7, 8, 9, 1, 2, 3, 4]) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 15\n assert candidate(nums1 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],nums2 = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 10\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [10, 8, 6, 4, 2]) == 1\n assert candidate(nums1 = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9],nums2 = [2, 6, 3, 7, 4, 8, 5, 9, 6, 10]) == 2\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10]) == 5\n assert candidate(nums1 = [1, 4, 5, 3, 2, 6, 7],nums2 = [2, 3, 4, 5, 6, 7, 8]) == 7\n assert candidate(nums1 = [1, 5, 2, 5, 3, 6],nums2 = [2, 3, 4, 5, 6, 7]) == 6\n assert candidate(nums1 = [1, 5, 7, 3, 9, 12],nums2 = [2, 4, 6, 8, 10, 11]) == 6\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2]) == 2\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 5\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums1 = [1, 2, 2, 3, 4, 5, 6],nums2 = [2, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(nums1 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],nums2 = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 10\n assert candidate(nums1 = [1000000000, 999999999, 999999998, 999999997, 999999996],nums2 = [999999999, 999999998, 999999997, 999999996, 999999995]) == 2\n assert candidate(nums1 = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],nums2 = [20, 10, 20, 10, 20, 10, 20, 10, 20, 10]) == 10\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [1, 3, 5, 7, 9, 11]) == 6\n assert candidate(nums1 = [1, 5, 3, 7, 9],nums2 = [2, 6, 4, 8, 10]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 5\n assert candidate(nums1 = [3, 5, 4, 3, 5, 6, 7],nums2 = [2, 1, 6, 5, 4, 8, 9]) == 6\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 10\n assert candidate(nums1 = [3, 4, 2, 5, 7, 8],nums2 = [2, 5, 5, 6, 5, 7]) == 6\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 10\n assert candidate(nums1 = [1, 2, 2, 2, 3, 3, 3, 4, 4, 4],nums2 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4]) == 10\n assert candidate(nums1 = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7],nums2 = [2, 1, 3, 2, 5, 4, 7, 6, 8, 7]) == 10\n assert candidate(nums1 = [1000000000, 1, 1000000000, 2, 1000000000, 3, 1000000000, 4, 1000000000, 5],nums2 = [1, 1000000000, 2, 1000000000, 3, 1000000000, 4, 1000000000, 5, 1000000000]) == 10\n assert candidate(nums1 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10],nums2 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 2\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],nums2 = [999999999, 999999999, 999999999, 999999999, 999999999]) == 5\n assert candidate(nums1 = [10, 10, 10, 10, 10],nums2 = [11, 9, 11, 9, 11]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4],nums2 = [4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 4\n assert candidate(nums1 = [1, 10, 3, 10, 5, 10, 7, 10, 9, 10],nums2 = [2, 9, 4, 9, 6, 9, 8, 9, 10, 9]) == 4\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [9, 7, 5, 3, 1]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 3, 2, 1],nums2 = [2, 3, 4, 5, 4, 3, 2]) == 5\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [11, 21, 31, 41, 51, 61, 71, 81, 91, 101]) == 10\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) == 13\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2]) == 5\n assert candidate(nums1 = [7, 8, 9, 10, 11, 5, 6, 7, 8, 9],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 5],nums2 = [2, 2, 3, 3, 4, 4, 5]) == 7\n", "comparison": "exact"}, "public_tests": ["[2,3,1]\n[1,2,1]", "[1,3,2,1]\n[2,2,3,4]", "[1,1]\n[2,2]"], "hints": ["Consider using dynamic programming.", "Let dp[i][0] (dp[i][1]) be the length of the longest non-decreasing ending with nums1[i] (nums2[i]).", "Initialize dp[i][0] to 1. If nums1[i] >= nums1[i - 1] then dp[i][0] may be dp[i - 1][0] + 1. If nums1[i] >= nums2[i - 1] then dp[i][0] may be dp[i - 1][1] + 1. Perform a similar calculation for nums2[i] and dp[i][1]."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().maxNonDecreasingLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:43+00:00", "tests_total": 125, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def max_non_decreasing_length(nums1, nums2)", "container": null, "callable": "max_non_decreasing_length", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2772, "task_id": "apply-operations-to-make-all-array-elements-equal-to-zero", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and a positive integer k.\n\nYou can apply the following operation on the array any number of times:\n\n- Choose any subarray of size k from the array and decrease all its elements by 1.\n\nReturn true if you can make all the array elements equal to 0, or false otherwise.\n\nA subarray is a contiguous non-empty part of an array.\n\nExample 1:\n\nInput: nums = [2,2,3,1,1,0], k = 3\nOutput: true\nExplanation: We can do the following operations:\n- Choose the subarray [2,2,3]. The resulting array will be nums = [1,1,2,1,1,0].\n- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,1,0,0,0].\n- Choose the subarray [1,1,1]. The resulting array will be nums = [0,0,0,0,0,0].\n\nExample 2:\n\nInput: nums = [1,3,1,1], k = 2\nOutput: false\nExplanation: It is not possible to make all the array elements equal to 0.\n\nConstraints:\n\n- 1 <= k <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 3, 1, 1, 0],k = 3) == True\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == True\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == False\n assert candidate(nums = [1000000, 1000000, 1000000],k = 3) == True\n assert candidate(nums = [0, 0, 0, 0],k = 2) == True\n assert candidate(nums = [1, 3, 1, 1],k = 2) == False\n assert candidate(nums = [0, 0, 0, 0, 0],k = 5) == True\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == False\n assert candidate(nums = [1, 0, 1, 0, 1],k = 2) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == False\n assert candidate(nums = [5, 5, 5, 5, 5],k = 1) == True\n assert candidate(nums = [10, 9, 8, 7, 6],k = 3) == False\n assert candidate(nums = [1, 1, 1, 1],k = 1) == True\n assert candidate(nums = [0, 0, 0, 0, 0],k = 1) == True\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 7) == False\n assert candidate(nums = [3, 2, 1, 1, 2, 3, 3, 2, 1, 1, 2, 3, 3, 2, 1, 1, 2, 3, 3, 2, 1],k = 3) == False\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 = 20) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 3, 2, 1, 0],k = 5) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0],k = 5) == False\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 7) == False\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 = 1) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == False\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5],k = 4) == True\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 10) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == False\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],k = 5) == False\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 3) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 11) == False\n assert candidate(nums = [3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2],k = 5) == False\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 5) == True\n assert candidate(nums = [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, 4],k = 10) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == False\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) == True\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6],k = 7) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 3, 2, 1, 0],k = 3) == False\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],k = 1) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == False\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],k = 7) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == False\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4],k = 6) == True\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],k = 3) == True\n assert candidate(nums = [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 = 10) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == False\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1, 1, 1, 1],k = 3) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 7) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == False\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 3) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1],k = 3) == False\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == False\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 0, 0, 0],k = 4) == True\n assert candidate(nums = [3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3],k = 3) == False\n assert candidate(nums = [3, 4, 5, 4, 3, 2, 1, 0],k = 3) == False\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2],k = 3) == False\n assert candidate(nums = [1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0],k = 3) == True\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 7) == True\n assert candidate(nums = [3, 4, 5, 4, 3, 4, 5, 4, 3],k = 3) == False\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 3) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 15) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0],k = 5) == False\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],k = 50) == False\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4],k = 4) == False\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 2) == False\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 2) == False\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000],k = 5) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == False\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == True\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],k = 3) == False\n assert candidate(nums = [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, 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, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 15) == False\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],k = 25) == True\n assert candidate(nums = [4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 0, 0, 0],k = 4) == False\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 1) == True\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],k = 10) == False\n assert candidate(nums = [5, 4, 3, 2, 1, 0],k = 3) == False\n assert candidate(nums = [4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0],k = 5) == False\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == True\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1],k = 5) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == False\n assert candidate(nums = [6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],k = 6) == False\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],k = 2) == False\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 7) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == False\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1],k = 3) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == False\n assert candidate(nums = [2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2],k = 3) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == False\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 2) == False\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 10) == True\n assert candidate(nums = [0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0],k = 5) == False\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],k = 3) == False\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 4) == False\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],k = 4) == True\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == False\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1],k = 2) == False\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 2) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == False\n", "comparison": "exact"}, "public_tests": ["[2,2,3,1,1,0]\n3", "[1,3,1,1]\n2"], "hints": ["In case it is possible, then how can you do the operations? which subarrays do you choose and in what order?", "The order of the chosen subarrays should be from the left to the right of the array"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().checkArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:46+00:00", "tests_total": 101, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def check_array(nums, k)", "container": null, "callable": "check_array", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2778, "task_id": "sum-of-squares-of-special-elements", "difficulty": "Easy", "problem_description": "You are given a 1-indexed integer array nums of length n.\n\nAn element nums[i] of nums is called special if i divides n, i.e. n % i == 0.\n\nReturn the sum of the squares of all special elements of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 21\nExplanation: There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.\nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.\n\nExample 2:\n\nInput: nums = [2,7,1,19,18,3]\nOutput: 63\nExplanation: There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.\nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.\n\nConstraints:\n\n- 1 <= nums.length == n <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25]) == 650\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4]) == 21\n assert candidate(nums = [49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49]) == 14406\n assert candidate(nums = [49, 25, 9, 4, 1]) == 2402\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 3250\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [10, 20, 30, 40, 50]) == 2600\n assert candidate(nums = [5, 5, 5, 5, 5]) == 50\n assert candidate(nums = [30, 20, 10]) == 1000\n assert candidate(nums = [49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 4083\n assert candidate(nums = [2, 7, 1, 19, 18, 3]) == 63\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]) == 2358\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1428\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 1040\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 50]) == 2630\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 675\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 2359\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 50, 49, 48, 47, 46]) == 3140\n assert candidate(nums = [50, 25, 12, 6, 4, 3, 2, 1]) == 3162\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 50]) == 2630\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]) == 75\n assert candidate(nums = [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]) == 2604\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36]) == 8216\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 2359\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1, 6, 12, 18, 24, 30, 36, 42, 48, 50]) == 9175\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]) == 2483\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 50]) == 2509\n assert candidate(nums = [42, 35, 28, 21, 14, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 3838\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]) == 1300\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]) == 651\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == 11868\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 546\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 1170\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]) == 3255\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 131\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 172\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]) == 27\n assert candidate(nums = [16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 32]) == 2720\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[2,7,1,19,18,3]"], "hints": ["Iterate over all the elements of the array. For each index i, check if it is special using the modulo operator.", "if n%i == 0, index i is special and you should add nums[i] to the answer."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumOfSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:50+00:00", "tests_total": 105, "tests_dropped": 65, "flags": [], "topic_tags": ["array", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_squares(nums)", "container": null, "callable": "sum_of_squares", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2779, "task_id": "maximum-beauty-of-an-array-after-applying-operation", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums and a non-negative integer k.\n\nIn one operation, you can do the following:\n\n- Choose an index i that hasn't been chosen before from the range [0, nums.length - 1].\n- Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].\n\nThe beauty of the array is the length of the longest subsequence consisting of equal elements.\n\nReturn the maximum possible beauty of the array nums after applying the operation any number of times.\n\nNote that you can apply the operation to each index only once.\n\nA subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [4,6,1,2], k = 2\nOutput: 3\nExplanation: In this example, we apply the following operations:\n- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].\n- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].\nAfter the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).\nIt can be proven that 3 is the maximum possible length we can achieve.\n\nExample 2:\n\nInput: nums = [1,1,1,1], k = 10\nOutput: 4\nExplanation: In this example we don't have to apply any operations.\nThe beauty of the array nums is 4 (whole array).\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i], k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],k = 15) == 4\n assert candidate(nums = [5, 15, 25, 35],k = 5) == 2\n assert candidate(nums = [100, 100, 100],k = 5) == 3\n assert candidate(nums = [100, 200, 300, 400, 500],k = 0) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [3, 3, 3, 3, 3],k = 1) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 5\n assert candidate(nums = [100000, 0, 50000, 25000, 75000],k = 50000) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 2\n assert candidate(nums = [8, 8, 8, 8, 8, 8],k = 0) == 6\n assert candidate(nums = [1, 3, 5, 7, 9],k = 1) == 2\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == 9\n assert candidate(nums = [5, 3, 9, 8, 7],k = 1) == 3\n assert candidate(nums = [2, 4, 6, 8, 10],k = 2) == 3\n assert candidate(nums = [3, 3, 3, 3, 3],k = 5) == 5\n assert candidate(nums = [4, 6, 1, 2],k = 2) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],k = 0) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],k = 0) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 0) == 1\n assert candidate(nums = [1, 100000],k = 50000) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 9\n assert candidate(nums = [5, 3, 15, 8, 10],k = 5) == 4\n assert candidate(nums = [100000, 100000, 100000],k = 0) == 3\n assert candidate(nums = [5, 3, 15, 8, 1],k = 3) == 3\n assert candidate(nums = [1, 1, 1, 1],k = 10) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 3\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],k = 50) == 10\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 5) == 10\n assert candidate(nums = [1, 1, 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],k = 1) == 18\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 3) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 1) == 12\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 0) == 5\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57],k = 4) == 3\n assert candidate(nums = [2, 5, 9, 14, 20, 27, 35, 44, 54, 65],k = 10) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],k = 1) == 9\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 1) == 9\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],k = 4) == 3\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 3\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996],k = 50000) == 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],k = 1) == 6\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],k = 50) == 11\n assert candidate(nums = [100, 100, 200, 200, 300, 300, 400, 400],k = 50) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 4\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 10000) == 10\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40],k = 10) == 9\n assert candidate(nums = [5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 3) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15],k = 3) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],k = 10) == 3\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 20) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 3\n assert candidate(nums = [5, 8, 12, 15, 17, 20, 23, 25, 28, 30],k = 5) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4],k = 1) == 15\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) == 7\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11],k = 2) == 5\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 3\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981],k = 50000) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1) == 3\n assert candidate(nums = [5, 8, 11, 14, 17, 20, 23, 26, 29, 32],k = 5) == 4\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 = 0) == 20\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10],k = 1) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 15\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],k = 100000) == 32\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) == 11\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 150) == 4\n assert candidate(nums = [5, 8, 8, 10, 12, 15, 15, 20, 22, 25],k = 3) == 4\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 = 100000) == 20\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 2\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],k = 50) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 10\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 = 9) == 19\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500],k = 50) == 3\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 = 9) == 19\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 1) == 6\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700],k = 100) == 3\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],k = 3) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10000) == 15\n assert candidate(nums = [100000, 1, 2, 3, 100000, 100000, 4, 5, 6, 7, 8, 9],k = 100000) == 12\n assert candidate(nums = [90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 25000) == 6\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40],k = 7) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 3\n assert candidate(nums = [2, 4, 4, 4, 6, 8, 8, 8, 10, 12, 12, 14, 16, 18],k = 2) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 15) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 5\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 45) == 10\n assert candidate(nums = [90, 80, 70, 60, 50, 40, 30, 20, 10, 0],k = 10) == 3\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 10) == 5\n assert candidate(nums = [100, 110, 120, 130, 140, 150, 160, 170, 180, 190],k = 15) == 4\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000],k = 15000) == 4\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],k = 5) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 1) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 0) == 2\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 1) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 2) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 8) == 9\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 = 100000) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 2) == 15\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6],k = 1) == 14\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 2) == 3\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20],k = 3) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 8) == 9\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145],k = 25) == 6\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],k = 20) == 11\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000],k = 25000) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 4\n assert candidate(nums = [100, 100, 100, 200, 200, 200, 300, 300, 300, 400, 400, 400, 500, 500, 500],k = 100) == 9\n assert candidate(nums = [5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 3) == 4\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],k = 45) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\n assert candidate(nums = [5, 15, 25, 35, 45, 55],k = 10) == 3\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],k = 1) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 10\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],k = 12) == 25\n", "comparison": "exact"}, "public_tests": ["[4,6,1,2]\n2", "[1,1,1,1]\n10"], "hints": ["Sort the array.", "The problem becomes the following: find maximum subarray A[i … j] such that A[j] - A[i] ≤ 2 * k."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:53+00:00", "tests_total": 119, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "sliding-window", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_beauty(nums, k)", "container": null, "callable": "maximum_beauty", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2780, "task_id": "minimum-index-of-a-valid-split", "difficulty": "Medium", "problem_description": "An element x of an integer array arr of length m is dominant if more than half the elements of arr have a value of x.\n\nYou are given a 0-indexed integer array nums of length n with one dominant element.\n\nYou can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only valid if:\n\n- 0 <= i < n - 1\n- nums[0, ..., i], and nums[i + 1, ..., n - 1] have the same dominant element.\n\nHere, nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j, both ends being inclusive. Particularly, if j < i then nums[i, ..., j] denotes an empty subarray.\n\nReturn the minimum index of a valid split. If no valid split exists, return -1.\n\nExample 1:\n\nInput: nums = [1,2,2,2]\nOutput: 2\nExplanation: We can split the array at index 2 to obtain arrays [1,2,2] and [2].\nIn array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.\nIn array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.\nBoth [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 2 is the minimum index of a valid split.\n\nExample 2:\n\nInput: nums = [2,1,3,1,1,1,7,1,2,1]\nOutput: 4\nExplanation: We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].\nIn array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nIn array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nBoth [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 4 is the minimum index of a valid split.\n\nExample 3:\n\nInput: nums = [3,3,3,3,7,2,2]\nOutput: -1\nExplanation: It can be shown that there is no valid split.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- nums has exactly one dominant element.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 1]) == 0\n assert candidate(nums = [3, 3, 3, 3, 7, 2, 2]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 1]) == 0\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]) == 0\n assert candidate(nums = [1, 2, 2, 2]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 1, 3, 1, 1, 1, 7, 1, 2, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 1, 1, 1, 1, 1]) == -1\n", "comparison": "exact"}, "public_tests": ["[1,2,2,2]", "[2,1,3,1,1,1,7,1,2,1]", "[3,3,3,3,7,2,2]"], "hints": ["Find the dominant element of nums by using a hashmap to maintain element frequency, we denote the dominant element as x and its frequency as f.", "For each index in [0, n - 2], calculate f1, x’s frequency in the subarray [0, i] when looping the index. And f2, x’s frequency in the subarray [i + 1, n - 1] which is equal to f - f1. Then we can check whether x is dominant in both subarrays."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:55+00:00", "tests_total": 12, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_index(nums)", "container": null, "callable": "minimum_index", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2781, "task_id": "length-of-the-longest-valid-substring", "difficulty": "Hard", "problem_description": "You are given a string word and an array of strings forbidden.\n\nA string is called valid if none of its substrings are present in forbidden.\n\nReturn the length of the longest valid substring of the string word.\n\nA substring is a contiguous sequence of characters in a string, possibly empty.\n\nExample 1:\n\nInput: word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" and \"aabc\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"aaa\" or \"cb\" as a substring.\n\nExample 2:\n\nInput: word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"l\", \"t\", \"c\", \"o\", \"d\", \"tc\", \"co\", \"od\", \"tco\", \"cod\", and \"tcod\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"de\", \"le\", or \"e\" as a substring.\n\nConstraints:\n\n- 1 <= word.length <= 10^5\n- word consists only of lowercase English letters.\n- 1 <= forbidden.length <= 10^5\n- 1 <= forbidden[i].length <= 10\n- forbidden[i] consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"zzzzzzzzzz\",forbidden = ['zz']) == 1\n assert candidate(word = \"abacab\",forbidden = ['ba', 'ca']) == 2\n assert candidate(word = \"leetcode\",forbidden = ['de', 'le', 'e']) == 4\n assert candidate(word = \"abcde\",forbidden = ['fgh']) == 5\n assert candidate(word = \"aaaaaaa\",forbidden = ['aa']) == 1\n assert candidate(word = \"aaaabaaa\",forbidden = ['aa']) == 3\n assert candidate(word = \"abcde\",forbidden = ['fgh', 'ijk']) == 5\n assert candidate(word = \"xyz\",forbidden = ['xy', 'yz']) == 1\n assert candidate(word = \"cbaaaabc\",forbidden = ['aaa', 'cb']) == 4\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",forbidden = ['abc', 'xyz']) == 24\n assert candidate(word = \"abcd\",forbidden = ['a', 'b', 'c', 'd']) == 0\n assert candidate(word = \"abacaba\",forbidden = ['ba', 'ca']) == 2\n assert candidate(word = \"abcde\",forbidden = ['ab', 'bc', 'cd', 'de']) == 1\n assert candidate(word = \"aaabbbcccddd\",forbidden = ['aaa', 'bbb', 'ccc', 'ddd', 'abc']) == 4\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",forbidden = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']) == 4\n assert candidate(word = \"pppppppppppppppppppppppppppppppppp\",forbidden = ['pp', 'p']) == 0\n assert candidate(word = \"abcdefghijabcdefghij\",forbidden = ['abc', 'def', 'ghi', 'jij', 'fed', 'cba']) == 5\n assert candidate(word = \"abcdefghijabcdefghij\",forbidden = ['abcdefghij', 'abc', 'def', 'ghi', 'jih', 'ihg', 'fed', 'cba']) == 5\n assert candidate(word = \"xyxzyzyxzyzyzxzyzx\",forbidden = ['xyz', 'zyx', 'xzy']) == 7\n assert candidate(word = \"hellothere\",forbidden = ['he', 'lo', 'th', 'er', 'ere']) == 3\n assert candidate(word = \"xyzxyzxyzxyz\",forbidden = ['xy', 'yz', 'zx', 'xyz']) == 1\n assert candidate(word = \"abcdefghij\",forbidden = ['abc', 'def', 'ghi', 'j']) == 4\n assert candidate(word = \"abcdeabcdeabcde\",forbidden = ['abc', 'cde', 'dea', 'bcd']) == 3\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",forbidden = ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == 2\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\",forbidden = ['qwe', 'ert', 'rty', 'tyu', 'yui', 'uio', 'iop', 'asd', 'sdf', 'dfg', 'fgh', 'ghj', 'hjk', 'jkl', 'klz', 'lzx', 'zxc', 'xcv', 'cvb', 'vbn', 'bnm']) == 4\n assert candidate(word = \"mississippi\",forbidden = ['iss', 'sip', 'issi', 'ippi']) == 4\n assert candidate(word = \"abcabcabcabc\",forbidden = ['abcabc', 'bcab', 'cababc']) == 5\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbb\",forbidden = ['aaa', 'bbb', 'ab', 'ba', 'aab', 'bba']) == 2\n assert candidate(word = \"banana\",forbidden = ['na', 'an', 'ba', 'baa', 'nan', 'ban', 'anan']) == 1\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",forbidden = ['xyz', 'uvw', 'rst', 'qpo', 'lmn', 'fed', 'cba']) == 13\n assert candidate(word = \"banana\",forbidden = ['ana', 'nan', 'ba', 'na', 'an']) == 1\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\",forbidden = ['qwe', 'rty', 'uiop', 'asdf', 'ghjk', 'lzx', 'cvb', 'nm']) == 6\n assert candidate(word = \"xyzxyzxyzxyz\",forbidden = ['xy', 'yz', 'zx']) == 1\n assert candidate(word = \"aaaaabbbbbcccccc\",forbidden = ['aaaa', 'bbbb', 'cccc', 'ab', 'bc', 'ca']) == 3\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",forbidden = ['aabb', 'bbcc', 'ccdd', 'ddee', 'eefg', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno', 'mnop', 'nopq', 'opqr', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'zyz']) == 45\n assert candidate(word = \"abcabcabcabc\",forbidden = ['abc', 'cab', 'bca']) == 2\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",forbidden = ['abc', 'xyz', 'mnop', 'qrst']) == 14\n assert candidate(word = \"ababababab\",forbidden = ['aba', 'bab', 'aaa']) == 2\n assert candidate(word = \"mississippi\",forbidden = ['issi', 'iss', 'ss', 'ssip', 'ippi']) == 4\n assert candidate(word = \"xyzxyzxyz\",forbidden = ['xyz', 'xy', 'yz']) == 2\n assert candidate(word = \"abcabcabcabcabc\",forbidden = ['abc', 'bca', 'cab']) == 2\n assert candidate(word = \"abababababababab\",forbidden = ['aba', 'bab', 'abb']) == 2\n assert candidate(word = \"hellohellohellohello\",forbidden = ['he', 'el', 'll', 'lo', 'oh']) == 1\n assert candidate(word = \"xyxyxyxyxyxyxyxy\",forbidden = ['xyx', 'yxy', 'xyxy']) == 2\n assert candidate(word = \"abacabadabacaba\",forbidden = ['aba', 'abc', 'bac']) == 5\n assert candidate(word = \"mississippi\",forbidden = ['issi', 'iss', 'is', 'mp', 'ss', 'pp']) == 3\n assert candidate(word = \"abcdefghij\",forbidden = ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl']) == 2\n assert candidate(word = \"mississippi\",forbidden = ['iss', 'issi', 'ippi', 'issipp', 'missi', 'sissi', 'ssippi']) == 5\n assert candidate(word = \"nolongerforbidden\",forbidden = ['for', 'bidden', 'no', 'longer']) == 7\n assert candidate(word = \"qwertypoiuytrewq\",forbidden = ['qw', 'we', 'er', 'rt', 'ty', 'yu', 'ui', 'io', 'op']) == 11\n assert candidate(word = \"banana\",forbidden = ['na', 'ba', 'an']) == 1\n assert candidate(word = \"thisthisthisthisthis\",forbidden = ['thi', 'hist', 'isth', 'histh', 'thist']) == 3\n assert candidate(word = \"mississippi\",forbidden = ['iss', 'issi', 'ippi']) == 5\n assert candidate(word = \"abababababababab\",forbidden = ['aba', 'bab', 'aab', 'bba']) == 2\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\",forbidden = ['qw', 'er', 'ty', 'ui', 'op', 'as', 'df', 'gh', 'jk', 'kl', 'zx', 'cv', 'vb', 'bn', 'nm']) == 2\n assert candidate(word = \"abcdabcdabcdabcdabcdabcd\",forbidden = ['abcd', 'bcda', 'cdab', 'dabc']) == 3\n assert candidate(word = \"abacaxabcd\",forbidden = ['ab', 'ca', 'bc', 'd']) == 3\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",forbidden = ['aa', 'bb', 'cc', 'zz', 'yy']) == 44\n assert candidate(word = \"banana\",forbidden = ['ana', 'nan', 'ban', 'ana', 'naa']) == 2\n assert candidate(word = \"mississippi\",forbidden = ['issi', 'iss', 'is', 'i', 's', 'p', 'mp']) == 1\n assert candidate(word = \"abracadabra\",forbidden = ['abr', 'rac', 'ada', 'bra', 'cab', 'cad']) == 3\n assert candidate(word = \"abcdefghij\",forbidden = ['abcdefghij', 'abcdefghi', 'bcdefgh', 'cdefgh', 'defgh', 'efgh', 'fgh', 'gh', 'h', 'ij']) == 7\n assert candidate(word = \"abacabadabacaba\",forbidden = ['aba', 'bad', 'cab', 'abc']) == 4\n assert candidate(word = \"aaaaaaaaaa\",forbidden = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa']) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",forbidden = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 2\n assert candidate(word = \"mnopqrstuvwxyzabcdefghijkl\",forbidden = ['mnop', 'qrst', 'uvwx', 'yzab', 'cdef', 'ghij', 'klmn', 'opqr', 'stuv', 'wxyz']) == 6\n assert candidate(word = \"aabbccddeeff\",forbidden = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff']) == 2\n assert candidate(word = \"abcabcabcabcabcabcabc\",forbidden = ['abcabc', 'bcabc', 'cabc', 'abca', 'bca', 'cab', 'abc']) == 2\n assert candidate(word = \"abacabadabacaba\",forbidden = ['aba', 'aca', 'bad']) == 4\n assert candidate(word = \"thisisaverylongwordthatneedstobecut\",forbidden = ['this', 'is', 'very', 'long', 'word', 'that', 'needs', 'to', 'be', 'cut']) == 7\n assert candidate(word = \"abacabacabacaba\",forbidden = ['aba', 'aca', 'bab']) == 3\n assert candidate(word = \"abacabadabacaba\",forbidden = ['aba', 'abc', 'bac']) == 5\n assert candidate(word = \"thisisateststring\",forbidden = ['test', 'string', 'is', 'a', 'this']) == 8\n assert candidate(word = \"mississippi\",forbidden = ['issi', 'sip', 'iss', 'ippi', 'ppi']) == 4\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",forbidden = ['abc', 'xyz', 'mnop']) == 14\n", "comparison": "exact"}, "public_tests": ["\"cbaaaabc\"\n[\"aaa\",\"cb\"]", "\"leetcode\"\n[\"de\",\"le\",\"e\"]"], "hints": [], "metadata": {"canonical_parameter_names": ["word", "forbidden"], "leetcode_dataset_entry_point": "Solution().longestValidSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:02:59+00:00", "tests_total": 76, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "string", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def longest_valid_substring(word, forbidden)", "container": null, "callable": "longest_valid_substring", "parameters": [{"name": "word", "type": "String"}, {"name": "forbidden", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2784, "task_id": "check-if-array-is-good", "difficulty": "Easy", "problem_description": "You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\n\nbase[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].\n\nReturn true if the given array is good, otherwise return false.\n\nNote: A permutation of integers represents an arrangement of these numbers.\n\nExample 1:\n\nInput: nums = [2, 1, 3]\nOutput: false\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.\n\nExample 2:\n\nInput: nums = [1, 3, 3, 2]\nOutput: true\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.\n\nExample 3:\n\nInput: nums = [1, 1]\nOutput: true\nExplanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.\n\nExample 4:\n\nInput: nums = [3, 4, 4, 1, 2, 1]\nOutput: false\nExplanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= num[i] <= 200\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 2]) == True\n assert candidate(nums = [2, 1, 1]) == False\n assert candidate(nums = [2, 1, 2]) == True\n assert candidate(nums = [1, 2, 3, 3, 5, 4]) == False\n assert candidate(nums = [2, 2]) == False\n assert candidate(nums = [1, 2, 3, 3, 4, 4]) == False\n assert candidate(nums = [1, 2, 2]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1]) == False\n assert candidate(nums = [2, 1, 3]) == False\n assert candidate(nums = [1, 1]) == True\n assert candidate(nums = [2, 2, 1, 3]) == False\n assert candidate(nums = [1, 2, 3, 3]) == True\n assert candidate(nums = [2, 2, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 4]) == True\n assert candidate(nums = [3, 4, 4, 1, 2, 1]) == False\n assert candidate(nums = [4, 3, 4, 2, 1]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 4]) == False\n assert candidate(nums = [5, 5, 1, 2, 3, 4]) == True\n assert candidate(nums = [5, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [4, 1, 2, 3, 4]) == True\n assert candidate(nums = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12]) == False\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [8, 1, 2, 3, 4, 5, 6, 7, 8]) == True\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]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11]) == True\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [3, 2, 1, 4, 4]) == True\n assert candidate(nums = [1, 2, 3, 4, 4, 4]) == False\n assert candidate(nums = [20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 1, 7]) == False\n assert candidate(nums = [11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == True\n assert candidate(nums = [19, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19]) == False\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, 24]) == True\n assert candidate(nums = [5, 1, 2, 3, 4, 4, 5]) == False\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 10]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11]) == False\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == False\n assert candidate(nums = [7, 1, 2, 3, 4, 5, 6, 7]) == True\n assert candidate(nums = [3, 1, 2, 3]) == True\n assert candidate(nums = [6, 1, 2, 3, 4, 5, 6]) == True\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, 28]) == True\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 10]) == False\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [2, 1, 4, 3, 5, 6, 6]) == True\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, 27]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == False\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, 30]) == True\n assert candidate(nums = [6, 6, 1, 2, 3, 4, 5]) == True\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, 26]) == True\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 7]) == True\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == False\n assert candidate(nums = [2, 3, 1, 1, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 6, 7]) == False\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 6]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 20, 20]) == False\n assert candidate(nums = [6, 1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9]) == False\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 6]) == True\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, 22]) == True\n assert candidate(nums = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 19]) == True\n assert candidate(nums = [6, 2, 1, 3, 4, 5, 6]) == True\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20]) == True\n assert candidate(nums = [6, 1, 2, 3, 4, 5, 6, 6, 7]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20]) == True\n assert candidate(nums = [2, 2, 1, 3, 4]) == False\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == False\n assert candidate(nums = [18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]) == True\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, 50, 1]) == False\n assert candidate(nums = [19, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19]) == False\n assert candidate(nums = [6, 3, 2, 1, 4, 5, 6]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 10, 20]) == False\n assert candidate(nums = [13, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(nums = [5, 2, 3, 4, 4, 1, 5]) == False\n assert candidate(nums = [17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 17]) == False\n assert candidate(nums = [7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 7]) == False\n assert candidate(nums = [18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18]) == False\n assert candidate(nums = [5, 5, 1, 2, 3, 4, 5]) == False\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]) == False\n assert candidate(nums = [7, 1, 2, 3, 4, 5, 6, 6]) == False\n assert candidate(nums = [11, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]) == False\n assert candidate(nums = [1, 3, 2, 5, 4, 5]) == True\n assert candidate(nums = [5, 3, 4, 5, 1, 2]) == True\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, 25]) == True\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, 1, 50]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 21]) == False\n assert candidate(nums = [7, 1, 2, 3, 4, 5, 6, 6, 8]) == False\n assert candidate(nums = [15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 2, 3, 4, 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]) == False\n assert candidate(nums = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(nums = [18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 18]) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1]) == False\n assert candidate(nums = [16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16]) == False\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9]) == False\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 11]) == True\n assert candidate(nums = [15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15]) == False\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11]) == False\n assert candidate(nums = [19, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == True\n assert candidate(nums = [8, 1, 2, 3, 4, 5, 6, 7, 7, 9]) == False\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 20]) == False\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, 29]) == True\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 8]) == False\n assert candidate(nums = [8, 1, 2, 3, 4, 5, 6, 7, 7, 8, 8]) == False\n assert candidate(nums = [2, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == False\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, 50, 50]) == False\n", "comparison": "exact"}, "public_tests": ["[2, 1, 3]", "[1, 3, 3, 2]", "[1, 1]", "[3, 4, 4, 1, 2, 1]"], "hints": ["Find the maximum element of the array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().isGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:03+00:00", "tests_total": 120, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "hash-table", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def is_good(nums)", "container": null, "callable": "is_good", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2785, "task_id": "sort-vowels-in-a-string", "difficulty": "Medium", "problem_description": "Given a 0-indexed string s, permute s to get a new string t such that:\n\n- All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].\n- The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].\n\nReturn the resulting string.\n\nThe vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.\n\nExample 1:\n\nInput: s = \"lEetcOde\"\nOutput: \"lEOtcede\"\nExplanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.\n\nExample 2:\n\nInput: s = \"lYmpH\"\nOutput: \"lYmpH\"\nExplanation: There are no vowels in s (all characters in s are consonants), so we return \"lYmpH\".\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists only of letters of the English alphabet in uppercase and lowercase.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == \"b\"\n assert candidate(s = \"bCdEfGhIjK\") == \"bCdEfGhIjK\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"AEIOUaeiou\") == \"AEIOUaeiou\"\n assert candidate(s = \"uoiea\") == \"aeiou\"\n assert candidate(s = \"AbEcIdOfUg\") == \"AbEcIdOfUg\"\n assert candidate(s = \"aAeEiIoOuU\") == \"AEIOUaeiou\"\n assert candidate(s = \"ThIsIsAtEsTcAsE\") == \"ThAsAsEtEsTcIsI\"\n assert candidate(s = \"SortingVowels\") == \"SertingVowols\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\") == \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\"\n assert candidate(s = \"aeiouAEIOU\") == \"AEIOUaeiou\"\n assert candidate(s = \"aAbBcCdDeEfFgGiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"AEbBcCdDIOfFgGUajJkKlLmMnNeipPqQrRsStTouvVwWxXyYzZ\"\n assert candidate(s = \"lEetcOde\") == \"lEOtcede\"\n assert candidate(s = \"ZyXwVutSrQpOnMlKjIhGfEdCbA\") == \"ZyXwVAtSrQpEnMlKjIhGfOdCbu\"\n assert candidate(s = \"ZYXWVUTSRQPONMLKJIHGFEDCBA\") == \"ZYXWVATSRQPENMLKJIHGFODCBU\"\n assert candidate(s = \"lYmpH\") == \"lYmpH\"\n assert candidate(s = \"Consonants\") == \"Cansononts\"\n assert candidate(s = \"aEIoU\") == \"EIUao\"\n assert candidate(s = \"AEIOU\") == \"AEIOU\"\n assert candidate(s = \"uUuUuUuUuUuUuUuUuUuUuUuUuUuU\") == \"UUUUUUUUUUUUUUuuuuuuuuuuuuuu\"\n assert candidate(s = \"mIxEdcAsEvOwElScOnSoNnTs\") == \"mAxEdcEsEvIwOlScOnSoNnTs\"\n assert candidate(s = \"rEvErsE\") == \"rEvErsE\"\n assert candidate(s = \"mIxEdCaSeVoWels\") == \"mExIdCaSeVeWols\"\n assert candidate(s = \"ThIsIsAVeRyLoNgStRiNgWhItHaMuLtIpLeVoWels\") == \"ThAsIsIVIRyLINgStRaNgWhetHeMeLtipLoVoWuls\"\n assert candidate(s = \"aBbAcCcAdDeE\") == \"ABbAcCcEdDae\"\n assert candidate(s = \"AeIoUeIoUaEiOuaEiOueIoU\") == \"AEEIIIOOUUUaaeeeiiooouu\"\n assert candidate(s = \"sAd\") == \"sAd\"\n assert candidate(s = \"bYpHtRfjK\") == \"bYpHtRfjK\"\n assert candidate(s = \"UnIvErSiTy\") == \"EnIvUrSiTy\"\n assert candidate(s = \"aEiOuAeIoUaEiOuAeIoUaEiOu\") == \"AAEEEIIOOOUUaaaeeiiioouuu\"\n assert candidate(s = \"UPPERCASE\") == \"APPERCESU\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == \"AbcdEfghIjklmnOpqrstUvwxyzaBCDeFGHiJKLMNoPQRSTuVWXYZ\"\n assert candidate(s = \"pYtHoNpRoGrAmMiNg\") == \"pYtHANpRiGromMoNg\"\n assert candidate(s = \"bBcCdDfFgGhHjJkKlLmMpPqQrRsStTvVwWxXyYzZ\") == \"bBcCdDfFgGhHjJkKlLmMpPqQrRsStTvVwWxXyYzZ\"\n assert candidate(s = \"bCdfGhjklmnpqrstvwxyz\") == \"bCdfGhjklmnpqrstvwxyz\"\n assert candidate(s = \"ThiSisAnExAmPlE\") == \"ThASAsEnEximPli\"\n assert candidate(s = \"HELLOworld\") == \"HELLOworld\"\n assert candidate(s = \"VowelsVowelsVowels\") == \"VewelsVewolsVowols\"\n assert candidate(s = \"fEaIoUeIaO\") == \"fEIIOUaaeo\"\n assert candidate(s = \"vOwElsInThEmIdDlE\") == \"vEwElsEnThImIdDlO\"\n assert candidate(s = \"uUoOiIeEaAA\") == \"AAEIOUaeiou\"\n assert candidate(s = \"ThiSisAEeIoU\") == \"ThASEsIUeiio\"\n assert candidate(s = \"sTrInGwItHvErYsMaLlVoWels\") == \"sTrEnGwItHvIrYsMaLlVeWols\"\n assert candidate(s = \"ThIsIsAVeRyLoNgStRiNgThAtCoNTaInSaLlThEvOwElScInDiFfErEnTcAsEs\") == \"ThAsAsAVERyLENgStRENgThEtCENTIInSILlThIvOwalScanDeFfirinTcosos\"\n assert candidate(s = \"uoieaUOIEA\") == \"AEIOUaeiou\"\n assert candidate(s = \"pythonProgramming\") == \"pythanPrigrommong\"\n assert candidate(s = \"vowelVowelVowel\") == \"vewelVewolVowol\"\n assert candidate(s = \"Vowels\") == \"Vewols\"\n assert candidate(s = \"aAaAaAaAaAaA\") == \"AAAAAAaaaaaa\"\n assert candidate(s = \"MixedCASEaeiou\") == \"MAxEdCaSeeiiou\"\n assert candidate(s = \"vOwElsShOuLdBeSoRtEd\") == \"vEwElsShOOLdBeSoRtud\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"AAAAAAAAAAAAAaaaaaaaaaaaaa\"\n assert candidate(s = \"VoWaElScOlE\") == \"VEWEOlScalo\"\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzAEIOU\") == \"bcdfghjklmnpqrstvwxyzAEIOU\"\n assert candidate(s = \"eEeEoOiIuUaAA\") == \"AAEEIOUaeeiou\"\n assert candidate(s = \"mEaTbAlL\") == \"mAETbalL\"\n assert candidate(s = \"uUoOiIaAeE\") == \"AEIOUaeiou\"\n assert candidate(s = \"UPPERCASEAEIOU\") == \"APPARCESEEIOUU\"\n assert candidate(s = \"ZyXwVuTsRqPoNmLkJiHgFeDcBa\") == \"ZyXwVaTsRqPeNmLkJiHgFoDcBu\"\n assert candidate(s = \"QwErTyUiOpAsDfGhJkLzXcVbNm\") == \"QwArTyEOUpisDfGhJkLzXcVbNm\"\n assert candidate(s = \"bAnAnA\") == \"bAnAnA\"\n assert candidate(s = \"vOwElScOnSoNnTsWiThMiXeDcAsE\") == \"vAwElScEnSONnTsWOThMeXiDciso\"\n assert candidate(s = \"ThEQUICKBRoWNfOxJUmpEDoVERtHElAZYdOG\") == \"ThAQEECKBREWNfExJImpODOVURtHUloZYdoG\"\n assert candidate(s = \"AEIOUaeiouAEIOUaeiou\") == \"AAEEIIOOUUaaeeiioouu\"\n assert candidate(s = \"CoMpLeXsTrInGwItHoUtvOwElS\") == \"CEMpLIXsTrInGwOtHUetvowolS\"\n assert candidate(s = \"aeiouAEIOUbcdfghjklmnpqrstvwxyz\") == \"AEIOUaeioubcdfghjklmnpqrstvwxyz\"\n assert candidate(s = \"Mississippi\") == \"Mississippi\"\n assert candidate(s = \"qwertyUIOP\") == \"qwIrtyOUeP\"\n assert candidate(s = \"MixedWithVowelsAndConsonants\") == \"MAxadWethVewilsindConsononts\"\n assert candidate(s = \"hApPy\") == \"hApPy\"\n assert candidate(s = \"bBbBbBbBbBbB\") == \"bBbBbBbBbBbB\"\n assert candidate(s = \"UoIeA\") == \"AIUeo\"\n assert candidate(s = \"fLkDjGhtY\") == \"fLkDjGhtY\"\n assert candidate(s = \"mIxEdVoWElScAsE\") == \"mAxEdVEWElScIso\"\n assert candidate(s = \"iIiIiIiIiIiIiIiIiIiIiIiIiIiI\") == \"IIIIIIIIIIIIIIiiiiiiiiiiiiii\"\n assert candidate(s = \"aAAAAAeiouuuuuuuuuuuuu\") == \"AAAAAaeiouuuuuuuuuuuuu\"\n assert candidate(s = \"vowelsAndConsonants\") == \"vAwalsendConsononts\"\n assert candidate(s = \"AeIoUxyZ\") == \"AIUeoxyZ\"\n assert candidate(s = \"mIxEdCaSe\") == \"mExIdCaSe\"\n assert candidate(s = \"Lowercaseaeiou\") == \"Lawarceseeioou\"\n assert candidate(s = \"Alphabetical\") == \"Alphabatecil\"\n assert candidate(s = \"tHeQuIcKBrOwNBrownFoxJumpsOverLaZyDog\") == \"tHIQOOcKBrawNBrewnFexJompsovorLuZyDug\"\n assert candidate(s = \"ThIsIsAVeRyLoNgStRiNgWitHaLoTofVoWels\") == \"ThAsIsIVaRyLeNgStReNgWitHiLoTofVoWols\"\n assert candidate(s = \"vowel\") == \"vewol\"\n assert candidate(s = \"aAeE\") == \"AEae\"\n assert candidate(s = \"AeIoUaEiOuAEIOUaeiouAEIOU\") == \"AAAEEEIIIOOOUUUaaeeiioouu\"\n assert candidate(s = \"tRiUmPh\") == \"tRUimPh\"\n assert candidate(s = \"sTrInGwItHmUlTiPlEvOwEl\") == \"sTrEnGwEtHmIlTIPlOvUwil\"\n assert candidate(s = \"dFdFdFdFdFdFdFdFdfDFDF\") == \"dFdFdFdFdFdFdFdFdfDFDF\"\n assert candidate(s = \"VowElScOdInG\") == \"VEwIlScOdonG\"\n assert candidate(s = \"aAeEiIoOuUaAeEiIoOuU\") == \"AAEEIIOOUUaaeeiioouu\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"aBcDaFgHeJkLmNePqRsTiVwXyZiBcDoFgHoJkLmNuPqRsTuVwXyZ\"\n assert candidate(s = \"auDiEnCe\") == \"EaDeinCu\"\n assert candidate(s = \"bcdfghjklmnpqrstvwxyz\") == \"bcdfghjklmnpqrstvwxyz\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaA\") == \"AAAAAAAAAAAAaaaaaaaaaaaa\"\n assert candidate(s = \"ProgrammingIsFun\") == \"PrIgrammingosFun\"\n assert candidate(s = \"MultipleVowels\") == \"MeltepliVowuls\"\n assert candidate(s = \"aAAAAAAAAAAAAAAAAAAAAAAAAAAAAa\") == \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAaa\"\n assert candidate(s = \"aEiOuAeIoU\") == \"AEIOUaeiou\"\n assert candidate(s = \"ThIsIsAComPlExStRiNgWitHvArIoUsVoWElS\") == \"ThAsAsECEmPlIxStRINgWItHvUriiosVoWolS\"\n assert candidate(s = \"sOrTiNg\") == \"sOrTiNg\"\n assert candidate(s = \"aEiOuBCDFG\") == \"EOaiuBCDFG\"\n assert candidate(s = \"oOoOoOoOoOoOoOoOoOoOoOoOoOoO\") == \"OOOOOOOOOOOOOOoooooooooooooo\"\n assert candidate(s = \"lowercase\") == \"lawerceso\"\n assert candidate(s = \"consonantsConsonantsVowelsVowels\") == \"cansanentsCensonontsVowolsVowols\"\n assert candidate(s = \"aEiOuAeIouAeIouAeIouAeIou\") == \"AAAAEIIIIOaeeeeioooouuuuu\"\n assert candidate(s = \"bbbbbbbbbbbbbbbbbAEIOU\") == \"bbbbbbbbbbbbbbbbbAEIOU\"\n assert candidate(s = \"abcdefgABCDEFGhijklmHIJKLmnopqrNOPQRSTuvwxyzUVWXYS\") == \"AbcdEfgIBCDOFGhUjklmHaJKLmnepqrNiPQRSTovwxyzuVWXYS\"\n assert candidate(s = \"vErYlArGeInPuTStRiNgWiThMaNyVoWels\") == \"vArYlErGIanPeTStReNgWiThMiNyVoWuls\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvatsrqpenmlkjihgfodcbu\"\n assert candidate(s = \"vowelVOWELvowelVOWEL\") == \"vEwElVOWOLvewelVoWoL\"\n assert candidate(s = \"bCdfGhJklMnpQrStVwXz\") == \"bCdfGhJklMnpQrStVwXz\"\n assert candidate(s = \"cOdInGqUeStIoN\") == \"cIdInGqOUSteoN\"\n assert candidate(s = \"ThIsIsAtEsT\") == \"ThAsEsItIsT\"\n assert candidate(s = \"pRoGrAmMiNg\") == \"pRAGrimMoNg\"\n assert candidate(s = \"AaEeIiOoUuAaEeIiOoUu\") == \"AAEEIIOOUUaaeeiioouu\"\n assert candidate(s = \"mIxEdVoWelsInThEString\") == \"mExEdVIWIlsenThiStrong\"\n assert candidate(s = \"aBCdEFGhIJKLmNoPQrSTuVwXyZ\") == \"EBCdIFGhaJKLmNoPQrSTuVwXyZ\"\n assert candidate(s = \"aAAAAA\") == \"AAAAAa\"\n assert candidate(s = \"VowelsAndConsonants\") == \"VAwalsendConsononts\"\n assert candidate(s = \"UniqueVowels\") == \"UneqeiVowuls\"\n assert candidate(s = \"joyFul\") == \"joyFul\"\n assert candidate(s = \"vOwElMvOwElMvOwElMvOwElM\") == \"vEwElMvEwElMvOwOlMvOwOlM\"\n assert candidate(s = \"VowelsMixed\") == \"VewelsMixod\"\n assert candidate(s = \"UeOiAaUeOiAaUeOiAaUeOiAa\") == \"AAAAOOOOUUUUaaaaeeeeiiii\"\n assert candidate(s = \"cOdInG\") == \"cIdOnG\"\n assert candidate(s = \"eEeEeEeEeEeEeEeEeEeEeEeEeE\") == \"EEEEEEEEEEEEEeeeeeeeeeeeee\"\n assert candidate(s = \"bBbBbBbBbBbBbBbBbBbBbBbB\") == \"bBbBbBbBbBbBbBbBbBbBbBbB\"\n assert candidate(s = \"fghijklmno\") == \"fghijklmno\"\n assert candidate(s = \"AEIOUzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"AEIOUzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"VoWeLiInInG\") == \"VIWILeinonG\"\n assert candidate(s = \"MiXeDcAsEaeiouAEIOU\") == \"MAXADcEsEIOUaeeiiou\"\n assert candidate(s = \"QWERTYUIOPASDFGHJKLZXCVBNM\") == \"QWARTYEIOPUSDFGHJKLZXCVBNM\"\n assert candidate(s = \"zXcVbNMA\") == \"zXcVbNMA\"\n assert candidate(s = \"ConsonantsWithVowels\") == \"CansenintsWothVowols\"\n assert candidate(s = \"aAeEiIoOuUaAeEiIoOuUaAeEiIoOuU\") == \"AAAEEEIIIOOOUUUaaaeeeiiiooouuu\"\n assert candidate(s = \"aAbBcCdDeEfFgGiImMoOnNpPrRsStTuUvVwWxXyYzZ\") == \"AEbBcCdDIOfFgGUamMeinNpPrRsStTouvVwWxXyYzZ\"\n assert candidate(s = \"uUUUUU\") == \"UUUUUu\"\n assert candidate(s = \"aEiOuaEiOuaEiOuaEiOu\") == \"EEEEOOOOaaaaiiiiuuuu\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == \"AbCdEfGhIjKlMnOpQrStUvWxYz\"\n assert candidate(s = \"sOrtThEvOwElS\") == \"sErtThEvOwOlS\"\n", "comparison": "exact"}, "public_tests": ["\"lEetcOde\"", "\"lYmpH\""], "hints": ["Add all the vowels in an array and sort the array.", "Replace characters in string s if it's a vowel from the new array."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().sortVowels", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:06+00:00", "tests_total": 150, "tests_dropped": 7, "flags": [], "topic_tags": ["string", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def sort_vowels(s)", "container": null, "callable": "sort_vowels", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2786, "task_id": "visit-array-positions-to-maximize-score", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and a positive integer x.\n\nYou are initially at position 0 in the array and you can visit other positions according to the following rules:\n\n- If you are currently in position i, then you can move to any position j such that i < j.\n- For each position i that you visit, you get a score of nums[i].\n- If you move from a position i to a position j and the parities of nums[i] and nums[j] differ, then you lose a score of x.\n\nReturn the maximum total score you can get.\n\nNote that initially you have nums[0] points.\n\nExample 1:\n\nInput: nums = [2,3,6,1,9,2], x = 5\nOutput: 13\nExplanation: We can visit the following positions in the array: 0 -> 2 -> 3 -> 4.\nThe corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5.\nThe total score will be: 2 + 6 + 1 + 9 - 5 = 13.\n\nExample 2:\n\nInput: nums = [2,4,6,8], x = 3\nOutput: 20\nExplanation: All the integers in the array have the same parities, so we can visit all of them without losing any score.\nThe total score is: 2 + 4 + 6 + 8 = 20.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i], x <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],x = 1) == 11\n assert candidate(nums = [10, 13, 15, 17, 19],x = 10) == 64\n assert candidate(nums = [1, 2, 3, 4, 5, 6],x = 2) == 13\n assert candidate(nums = [10, 13, 14, 15, 19],x = 10) == 48\n assert candidate(nums = [5, 3, 2, 4, 6, 7, 8, 9],x = 4) == 29\n assert candidate(nums = [5, 5, 5, 5, 5, 5],x = 1) == 30\n assert candidate(nums = [10, 15, 20, 25, 30],x = 10) == 65\n assert candidate(nums = [1, 2, 3, 4, 5],x = 2) == 9\n assert candidate(nums = [7, 8, 9, 10, 11, 12],x = 7) == 32\n assert candidate(nums = [10, 15, 20, 25, 30],x = 7) == 72\n assert candidate(nums = [2, 3, 6, 1, 9, 2],x = 5) == 13\n assert candidate(nums = [7, 11, 13, 14, 15],x = 3) == 54\n assert candidate(nums = [1, 1, 1, 1, 1],x = 10) == 5\n assert candidate(nums = [5, 3, 8, 9, 2, 4],x = 6) == 17\n assert candidate(nums = [2, 4, 6, 8],x = 3) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],x = 2) == 420\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],x = 3) == 420\n assert candidate(nums = [100000, 100001, 100002, 100003, 100004, 100005, 100006, 100007, 100008, 100009],x = 50000) == 550045\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 150) == 5500\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],x = 3) == 240\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9],x = 3) == 73\n assert candidate(nums = [1, 3, 2, 8, 7, 4, 6, 9, 5, 10],x = 6) == 30\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2],x = 5) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 7) == 119\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],x = 10) == 520\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],x = 30) == 239\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 1) == 191\n assert candidate(nums = [12, 17, 18, 13, 20, 21, 16, 19, 14, 15],x = 8) == 98\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],x = 10) == 420\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],x = 2) == 409\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],x = 7) == 632\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],x = 15) == 240\n assert candidate(nums = [10, 30, 20, 40, 50, 70, 60, 90, 80, 100, 120, 110, 140, 130, 160, 150, 180, 170, 200, 190],x = 20) == 2100\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],x = 5) == 124\n assert candidate(nums = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11],x = 2) == 54\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994],x = 100000) == 6399979\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],x = 20) == 109\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 2) == 39\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],x = 10) == 400\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995],x = 1000) == 5994985\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],x = 2) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 2) == 100\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],x = 500000) == 5499975\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 1) == 46\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],x = 15) == 2100\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 100) == 11\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],x = 10) == 40\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 1) == 10\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],x = 500000) == 5499969\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],x = 2) == 256\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 100) == 5500\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],x = 100000) == 1980468\n assert candidate(nums = [500000, 499999, 499998, 499997, 499996, 499995, 499994, 499993, 499992, 499991, 499990, 499989, 499988, 499987, 499986, 499985, 499984, 499983, 499982, 499981],x = 100000) == 8099810\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],x = 100000) == 9099945\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 3) == 159\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],x = 20) == 308\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],x = 5) == 240\n assert candidate(nums = [5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62],x = 7) == 543\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],x = 2) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 2) == 39\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],x = 25) == 675\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],x = 500000) == 2999994\n assert candidate(nums = [2, 3, 6, 1, 9, 2, 4, 8, 5, 7, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],x = 5) == 424\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],x = 5) == 400\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 10) == 50\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],x = 5) == 225\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 1) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],x = 1) == 225\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],x = 1) == 30\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],x = 1) == 101\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 3) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],x = 15) == 660\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400],x = 50) == 2200\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],x = 1) == 101\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 15) == 30\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],x = 1) == 20\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],x = 1000000) == 10000000\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],x = 2) == 110\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10],x = 3) == 98\n assert candidate(nums = [1000000, 999999, 1000000, 999999, 1000000, 999999],x = 1000000) == 3000000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],x = 100) == 923\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],x = 1) == 132\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],x = 5) == 110\n assert candidate(nums = [4, 2, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],x = 5) == 240\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],x = 1000) == 9990955\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 10) == 25\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10) == 15\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],x = 1) == 150\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 10) == 100\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],x = 1000) == 9990945\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 2) == 31\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],x = 10) == 629\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995],x = 500000) == 3499991\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],x = 5) == 144\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],x = 3) == 625\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],x = 5) == 73\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],x = 500) == 12000\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 7, 9, 8, 10, 11, 13, 12, 14, 15, 17, 16, 18, 19, 20],x = 20) == 115\n assert candidate(nums = [31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],x = 15) == 158\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],x = 25) == 2100\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],x = 3) == 18\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987],x = 100000) == 12711020\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],x = 5) == 780\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],x = 10) == 225\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23],x = 10) == 90\n", "comparison": "exact"}, "public_tests": ["[2,3,6,1,9,2]\n5", "[2,4,6,8]\n3"], "hints": ["How can we use dynamic programming to solve the problem?", "Let dp[i] be the answer to the subarray nums[0…i]. What are the transitions of this dp?"], "metadata": {"canonical_parameter_names": ["nums", "x"], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:08+00:00", "tests_total": 109, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def max_score(nums, x)", "container": null, "callable": "max_score", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2787, "task_id": "ways-to-express-an-integer-as-sum-of-powers", "difficulty": "Medium", "problem_description": "Given two positive integers n and x.\n\nReturn the number of ways n can be expressed as the sum of the x^th power of unique positive integers, in other words, the number of sets of unique integers [n_1, n_2, ..., n_k] where n = n_1^x + n_2^x + ... + n_k^x.\n\nSince the result can be very large, return it modulo 10^9 + 7.\n\nFor example, if n = 160 and x = 3, one way to express n is n = 2^3 + 3^3 + 5^3.\n\nExample 1:\n\nInput: n = 10, x = 2\nOutput: 1\nExplanation: We can express n as the following: n = 3^2 + 1^2 = 10.\nIt can be shown that it is the only way to express 10 as the sum of the 2^nd power of unique integers.\n\nExample 2:\n\nInput: n = 4, x = 1\nOutput: 2\nExplanation: We can express n in the following ways:\n- n = 4^1 = 4.\n- n = 3^1 + 1^1 = 4.\n\nConstraints:\n\n- 1 <= n <= 300\n- 1 <= x <= 5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 100,x = 4) == 0\n assert candidate(n = 50,x = 2) == 3\n assert candidate(n = 200,x = 2) == 9\n assert candidate(n = 300,x = 5) == 0\n assert candidate(n = 160,x = 3) == 1\n assert candidate(n = 4,x = 1) == 2\n assert candidate(n = 10,x = 2) == 1\n assert candidate(n = 20,x = 2) == 1\n assert candidate(n = 200,x = 5) == 0\n assert candidate(n = 144,x = 2) == 2\n assert candidate(n = 225,x = 4) == 0\n assert candidate(n = 180,x = 5) == 0\n assert candidate(n = 125,x = 2) == 5\n assert candidate(n = 80,x = 3) == 0\n assert candidate(n = 190,x = 5) == 0\n assert candidate(n = 300,x = 3) == 0\n assert candidate(n = 199,x = 4) == 0\n assert candidate(n = 243,x = 5) == 1\n assert candidate(n = 210,x = 5) == 0\n assert candidate(n = 290,x = 5) == 0\n assert candidate(n = 200,x = 4) == 0\n assert candidate(n = 120,x = 2) == 4\n assert candidate(n = 260,x = 4) == 0\n assert candidate(n = 100,x = 2) == 3\n assert candidate(n = 128,x = 2) == 0\n assert candidate(n = 160,x = 2) == 4\n assert candidate(n = 150,x = 4) == 0\n assert candidate(n = 180,x = 4) == 0\n assert candidate(n = 150,x = 2) == 9\n assert candidate(n = 299,x = 5) == 0\n assert candidate(n = 175,x = 3) == 0\n assert candidate(n = 180,x = 2) == 6\n assert candidate(n = 210,x = 2) == 18\n assert candidate(n = 220,x = 3) == 0\n assert candidate(n = 280,x = 3) == 1\n assert candidate(n = 275,x = 5) == 1\n assert candidate(n = 275,x = 4) == 0\n assert candidate(n = 300,x = 1) == 872471266\n assert candidate(n = 190,x = 2) == 14\n assert candidate(n = 140,x = 5) == 0\n assert candidate(n = 170,x = 3) == 0\n assert candidate(n = 299,x = 3) == 0\n assert candidate(n = 195,x = 2) == 16\n assert candidate(n = 275,x = 3) == 0\n assert candidate(n = 280,x = 4) == 0\n assert candidate(n = 140,x = 4) == 0\n assert candidate(n = 260,x = 5) == 0\n assert candidate(n = 196,x = 4) == 0\n assert candidate(n = 250,x = 3) == 0\n assert candidate(n = 289,x = 3) == 1\n assert candidate(n = 150,x = 3) == 0\n assert candidate(n = 200,x = 1) == 487067746\n assert candidate(n = 120,x = 3) == 0\n assert candidate(n = 100,x = 1) == 444793\n assert candidate(n = 175,x = 4) == 0\n assert candidate(n = 260,x = 2) == 19\n assert candidate(n = 180,x = 3) == 0\n assert candidate(n = 170,x = 5) == 0\n assert candidate(n = 290,x = 2) == 31\n assert candidate(n = 299,x = 2) == 33\n assert candidate(n = 256,x = 4) == 1\n assert candidate(n = 270,x = 3) == 0\n assert candidate(n = 90,x = 3) == 0\n assert candidate(n = 250,x = 4) == 0\n assert candidate(n = 17,x = 2) == 1\n assert candidate(n = 1,x = 5) == 1\n assert candidate(n = 3,x = 1) == 2\n assert candidate(n = 125,x = 3) == 1\n assert candidate(n = 2,x = 2) == 0\n assert candidate(n = 50,x = 3) == 0\n assert candidate(n = 81,x = 4) == 1\n assert candidate(n = 20,x = 4) == 0\n assert candidate(n = 17,x = 4) == 1\n assert candidate(n = 5,x = 1) == 3\n assert candidate(n = 15,x = 2) == 0\n assert candidate(n = 120,x = 4) == 0\n assert candidate(n = 100,x = 3) == 1\n assert candidate(n = 27,x = 3) == 1\n assert candidate(n = 64,x = 2) == 1\n assert candidate(n = 8,x = 3) == 1\n assert candidate(n = 31,x = 1) == 340\n assert candidate(n = 1,x = 1) == 1\n assert candidate(n = 256,x = 5) == 0\n assert candidate(n = 64,x = 3) == 1\n assert candidate(n = 25,x = 2) == 2\n assert candidate(n = 28,x = 2) == 0\n assert candidate(n = 9,x = 2) == 1\n assert candidate(n = 12,x = 2) == 0\n assert candidate(n = 250,x = 5) == 0\n assert candidate(n = 81,x = 2) == 3\n assert candidate(n = 70,x = 1) == 29927\n assert candidate(n = 50,x = 5) == 0\n assert candidate(n = 9,x = 4) == 0\n assert candidate(n = 15,x = 1) == 27\n assert candidate(n = 250,x = 2) == 21\n assert candidate(n = 30,x = 1) == 296\n", "comparison": "exact"}, "public_tests": ["10\n2", "4\n1"], "hints": ["You can use dynamic programming, where dp[k][j] represents the number of ways to express k as the sum of the x-th power of unique positive integers such that the biggest possible number we use is j.", "To calculate dp[k][j], you can iterate over the numbers smaller than j and try to use each one as a power of x to make our sum k."], "metadata": {"canonical_parameter_names": ["n", "x"], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:10+00:00", "tests_total": 96, "tests_dropped": 0, "flags": [], "topic_tags": ["dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_ways(n, x)", "container": null, "callable": "number_of_ways", "parameters": [{"name": "n", "type": "Integer"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2788, "task_id": "split-strings-by-separator", "difficulty": "Easy", "problem_description": "Given an array of strings words and a character separator, split each string in words by separator.\n\nReturn an array of strings containing the new strings formed after the splits, excluding empty strings.\n\nNotes\n\n- separator is used to determine where the split should occur, but it is not included as part of the resulting strings.\n- A split may result in more than two strings.\n- The resulting strings must maintain the same order as they were initially given.\n\nExample 1:\n\nInput: words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\"\nOutput: [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\nExplanation: In this example we split as follows:\n\n\"one.two.three\" splits into \"one\", \"two\", \"three\"\n\"four.five\" splits into \"four\", \"five\"\n\"six\" splits into \"six\"\n\nHence, the resulting array is [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"].\n\nExample 2:\n\nInput: words = [\"$easy$\",\"$problem$\"], separator = \"$\"\nOutput: [\"easy\",\"problem\"]\nExplanation: In this example we split as follows:\n\n\"$easy$\" splits into \"easy\" (excluding empty strings)\n\"$problem$\" splits into \"problem\" (excluding empty strings)\n\nHence, the resulting array is [\"easy\",\"problem\"].\n\nExample 3:\n\nInput: words = [\"|||\"], separator = \"|\"\nOutput: []\nExplanation: In this example the resulting split of \"|||\" will contain only empty strings, so we return an empty array [].\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 20\n- characters in words[i] are either lowercase English letters or characters from the string \".,|$#@\" (excluding the quotes)\n- separator is a character from the string \".,|$#@\" (excluding the quotes)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['no-separator'],separator = \",\") == ['no-separator']\n assert candidate(words = ['hello.world', 'foo.bar.baz'],separator = \".\") == ['hello', 'world', 'foo', 'bar', 'baz']\n assert candidate(words = ['test|test|test'],separator = \"|\") == ['test', 'test', 'test']\n assert candidate(words = ['#a#b#', 'c#d', 'e#f#g'],separator = \"#\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n assert candidate(words = ['a,b,c', 'd,e', 'f,g,h'],separator = \",\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n assert candidate(words = ['...'],separator = \".\") == []\n assert candidate(words = ['multiple,,,commas'],separator = \",\") == ['multiple', 'commas']\n assert candidate(words = ['@a@', 'b@c@d', 'e@f@g@h'],separator = \"@\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n assert candidate(words = ['no-separator-here'],separator = \"-\") == ['no', 'separator', 'here']\n assert candidate(words = ['|a|b|c|', 'd|e|f', 'g|h|i|j'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n assert candidate(words = ['|a|b|c|d|'],separator = \"|\") == ['a', 'b', 'c', 'd']\n assert candidate(words = ['abc', 'def', 'ghi'],separator = \".\") == ['abc', 'def', 'ghi']\n assert candidate(words = ['hello.world', 'how.are.you'],separator = \".\") == ['hello', 'world', 'how', 'are', 'you']\n assert candidate(words = ['1.2.3', '4.5.6.7'],separator = \".\") == ['1', '2', '3', '4', '5', '6', '7']\n assert candidate(words = ['test|string|data'],separator = \"|\") == ['test', 'string', 'data']\n assert candidate(words = [',,', ',,'],separator = \",\") == []\n assert candidate(words = ['hello.world', 'example.test'],separator = \".\") == ['hello', 'world', 'example', 'test']\n assert candidate(words = ['#abc#', '#def#', '#ghi#'],separator = \"#\") == ['abc', 'def', 'ghi']\n assert candidate(words = ['hello.world', 'python.is.awesome'],separator = \".\") == ['hello', 'world', 'python', 'is', 'awesome']\n assert candidate(words = ['###', '@#@', '$#$'],separator = \"#\") == ['@', '@', '$', '$']\n assert candidate(words = ['hello.world', 'python.code'],separator = \".\") == ['hello', 'world', 'python', 'code']\n assert candidate(words = ['@hello@world', '@foo@bar@baz'],separator = \"@\") == ['hello', 'world', 'foo', 'bar', 'baz']\n assert candidate(words = ['$easy$', '$problem$'],separator = \"$\") == ['easy', 'problem']\n assert candidate(words = ['|||'],separator = \"|\") == []\n assert candidate(words = ['a,b,c', 'd,e,f', 'g,h'],separator = \",\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n assert candidate(words = ['abc', 'def', 'ghi'],separator = \",\") == ['abc', 'def', 'ghi']\n assert candidate(words = ['#a#b#c#'],separator = \"#\") == ['a', 'b', 'c']\n assert candidate(words = ['one.two.three', 'four.five', 'six'],separator = \".\") == ['one', 'two', 'three', 'four', 'five', 'six']\n assert candidate(words = ['a.b.c.d.e'],separator = \".\") == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['a.b.c', 'd.e', 'f'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f']\n assert candidate(words = ['same|same|same', 'different|path|here'],separator = \"|\") == ['same', 'same', 'same', 'different', 'path', 'here']\n assert candidate(words = ['.,.', '.a.b.', '.c.d.e.'],separator = \".\") == [',', 'a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['hello|world|foo|bar', 'baz|qux|quux', 'corge|grault|garply'],separator = \"|\") == ['hello', 'world', 'foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply']\n assert candidate(words = ['this$that', 'and', 'the$other', 'thing'],separator = \"$\") == ['this', 'that', 'and', 'the', 'other', 'thing']\n assert candidate(words = ['.a.b.c.', '.d.e.', '.f.g.h.'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n assert candidate(words = ['a.b.c.d.e', 'f.g', 'h', 'i..j', 'k..l..m'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']\n assert candidate(words = ['a.b.c.d', 'e.f.g', 'h.i'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']\n assert candidate(words = ['##word1##', '##word2##word3##', 'word4##word5##'],separator = \"#\") == ['word1', 'word2', 'word3', 'word4', 'word5']\n assert candidate(words = ['1,2,3', '4,,5', ',6,'],separator = \",\") == ['1', '2', '3', '4', '5', '6']\n assert candidate(words = ['start|end', 'middle|middle|middle', 'no|change'],separator = \"|\") == ['start', 'end', 'middle', 'middle', 'middle', 'no', 'change']\n assert candidate(words = ['noSeparatorHere', 'neitherHere', 'orHere'],separator = \"|\") == ['noSeparatorHere', 'neitherHere', 'orHere']\n assert candidate(words = ['|||', '||||', '|||||'],separator = \"|\") == []\n assert candidate(words = ['|a||b||c|', '|d||e|', 'f|||g'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n assert candidate(words = ['a|b|c', 'd.e.f', 'g#h#i'],separator = \"|\") == ['a', 'b', 'c', 'd.e.f', 'g#h#i']\n assert candidate(words = ['abc#def#ghi#jkl', 'mno#pqr', 'stu#vw'],separator = \"#\") == ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vw']\n assert candidate(words = ['a|b|c|d|e', 'f|g|h|i', 'j|k|l|m|n|o'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']\n assert candidate(words = ['@start@middle@end', '@multiple@parts@here', '@only@one'],separator = \"@\") == ['start', 'middle', 'end', 'multiple', 'parts', 'here', 'only', 'one']\n assert candidate(words = ['abc...def...ghi', 'jkl...mno', 'pqr...stu...vwx...yz'],separator = \"...\") == ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']\n assert candidate(words = ['one..two...three', 'four....five', 'six......'],separator = \".\") == ['one', 'two', 'three', 'four', 'five', 'six']\n assert candidate(words = ['abc.def.ghi', 'jklmno.pqr.stu', 'vwxyz.123.456'],separator = \".\") == ['abc', 'def', 'ghi', 'jklmno', 'pqr', 'stu', 'vwxyz', '123', '456']\n assert candidate(words = ['a.b.c.d.e.f.g'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n assert candidate(words = ['hello###world', '###foo###bar', 'baz###'],separator = \"###\") == ['hello', 'world', 'foo', 'bar', 'baz']\n assert candidate(words = ['###abc###', 'def###ghi', '###jkl###'],separator = \"#\") == ['abc', 'def', 'ghi', 'jkl']\n assert candidate(words = ['|a||b|c|', '|d|e||f|', 'g|h|i||j'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n assert candidate(words = ['no|separator', 'only|one|separator', 'two|separators|here'],separator = \"|\") == ['no', 'separator', 'only', 'one', 'separator', 'two', 'separators', 'here']\n assert candidate(words = ['test$test$test', '$test$test', 'test$$test'],separator = \"$\") == ['test', 'test', 'test', 'test', 'test', 'test', 'test']\n assert candidate(words = ['noSeparatorHere', 'norHere', 'stillNotHere'],separator = \".\") == ['noSeparatorHere', 'norHere', 'stillNotHere']\n assert candidate(words = ['||||', '...', '####'],separator = \"|\") == ['...', '####']\n assert candidate(words = ['one$two$three', 'four$five', '$six$'],separator = \"$\") == ['one', 'two', 'three', 'four', 'five', 'six']\n assert candidate(words = ['abc@def@ghi', 'jkl@@mno@pqr', 'stu@vwx@@yz'],separator = \"@\") == ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']\n assert candidate(words = ['word1@word2', 'word3', 'word4@word5@word6'],separator = \"@\") == ['word1', 'word2', 'word3', 'word4', 'word5', 'word6']\n assert candidate(words = ['example.com', 'user@example.co.uk'],separator = \".\") == ['example', 'com', 'user@example', 'co', 'uk']\n assert candidate(words = ['abc', 'def', 'ghi'],separator = \"z\") == ['abc', 'def', 'ghi']\n assert candidate(words = ['@@@@', '####', '&&&&'],separator = \"@\") == ['####', '&&&&']\n assert candidate(words = ['a.b.c.d.e', 'f.g', 'h'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n assert candidate(words = ['@#$|%|^&*', '!@#$%^&*()', '|{}[]<>:'],separator = \"$\") == ['@#', '|%|^&*', '!@#', '%^&*()', '|{}[]<>:']\n assert candidate(words = ['hello###world', 'foo###bar', 'baz###qux'],separator = \"###\") == ['hello', 'world', 'foo', 'bar', 'baz', 'qux']\n assert candidate(words = ['a,b,c,d,e', 'f,g,h,i,j', 'k,l,m,n,o'],separator = \",\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']\n assert candidate(words = ['||a||b||c||', '|||', 'd|||e'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['hello||world', 'foo|bar|baz', 'qux|||quux'],separator = \"|\") == ['hello', 'world', 'foo', 'bar', 'baz', 'qux', 'quux']\n assert candidate(words = ['word1#word2#word3', 'word4#word5', 'word6'],separator = \"#\") == ['word1', 'word2', 'word3', 'word4', 'word5', 'word6']\n assert candidate(words = ['x|y|z|w|v|u|t', 's|r|q', 'p|o|n|m'],separator = \"|\") == ['x', 'y', 'z', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm']\n assert candidate(words = ['a.b.c.d.e', 'f.g', 'h.i.j'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n assert candidate(words = ['|||', '|a|b|c|', 'd|e|f|'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e', 'f']\n assert candidate(words = ['###', '@#@'],separator = \"#\") == ['@', '@']\n assert candidate(words = ['start.with.dot.', '.end.with.dot', '.both.ends.'],separator = \".\") == ['start', 'with', 'dot', 'end', 'with', 'dot', 'both', 'ends']\n assert candidate(words = ['..', '$.$', '#@#@'],separator = \".\") == ['$', '$', '#@#@']\n assert candidate(words = [',,a,,b,,c,,', ',,,', 'd,,,e'],separator = \",\") == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['a.b.c.d.e', 'f.g.h', 'i.j'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n assert candidate(words = ['#start#middle#end', '##double##triple###', '###quadruple####'],separator = \"#\") == ['start', 'middle', 'end', 'double', 'triple', 'quadruple']\n assert candidate(words = ['###abc###', '###def###ghi###', '###'],separator = \"#\") == ['abc', 'def', 'ghi']\n assert candidate(words = ['noSeparator', 'alsoNoSeparatorHere'],separator = \"$\") == ['noSeparator', 'alsoNoSeparatorHere']\n assert candidate(words = ['abc#def#ghi', 'jkl|mno|pqr', 'stu,vwx,yz'],separator = \"#\") == ['abc', 'def', 'ghi', 'jkl|mno|pqr', 'stu,vwx,yz']\n assert candidate(words = [',,comma,,', 'separated,,values', ',,'],separator = \",\") == ['comma', 'separated', 'values']\n assert candidate(words = ['leading|trailing|', '|trailing|only', 'only|leading|'],separator = \"|\") == ['leading', 'trailing', 'trailing', 'only', 'only', 'leading']\n assert candidate(words = ['no|separators', 'here', 'either'],separator = \"|\") == ['no', 'separators', 'here', 'either']\n assert candidate(words = ['a@b@c@d', 'e@f@g', 'h@i@j@k@l'],separator = \"@\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']\n assert candidate(words = ['###', '@@@', '$$$'],separator = \"#\") == ['@@@', '$$$']\n assert candidate(words = ['|a||b||c|', 'd||e|f||', '|g|h|i|'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']\n assert candidate(words = ['....', '|||', '@@@'],separator = \".\") == ['|||', '@@@']\n assert candidate(words = ['a.b.c.d.e', 'f.g', 'h'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n assert candidate(words = ['@start', 'end@', '@both@'],separator = \"@\") == ['start', 'end', 'both']\n assert candidate(words = ['###', '#foo#bar#', '###baz##'],separator = \"#\") == ['foo', 'bar', 'baz']\n assert candidate(words = ['repeated..dots', 'triple|||pipes', 'quadruple@@@@at'],separator = \".\") == ['repeated', 'dots', 'triple|||pipes', 'quadruple@@@@at']\n assert candidate(words = ['a@b@c@d', 'e@f', 'g@h@i@j@k'],separator = \"@\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']\n assert candidate(words = ['a.b.c.d', 'e.f', 'g.h.i.j.k'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']\n assert candidate(words = ['end.with.dot.', '.start.with.dot', '.middle.dot.'],separator = \".\") == ['end', 'with', 'dot', 'start', 'with', 'dot', 'middle', 'dot']\n assert candidate(words = ['x##y##z', '##', 'w####v'],separator = \"#\") == ['x', 'y', 'z', 'w', 'v']\n assert candidate(words = ['|||abc|||', 'def|||ghi|||', '|||jkl|||mno|||'],separator = \"|\") == ['abc', 'def', 'ghi', 'jkl', 'mno']\n assert candidate(words = ['word', 'anotherword', 'yetanotherword'],separator = \"x\") == ['word', 'anotherword', 'yetanotherword']\n assert candidate(words = ['........', '...', '.'],separator = \".\") == []\n assert candidate(words = ['#example#test#case', '##', 'no#separator'],separator = \"#\") == ['example', 'test', 'case', 'no', 'separator']\n assert candidate(words = ['........'],separator = \".\") == []\n assert candidate(words = ['apple,banana,cherry', 'date,elderberry', 'fig,grape'],separator = \",\") == ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape']\n assert candidate(words = ['..', '...', '....'],separator = \".\") == []\n assert candidate(words = ['|||||||'],separator = \"|\") == []\n assert candidate(words = ['abc.def.ghi', 'jkl..mno', 'pqr'],separator = \".\") == ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr']\n assert candidate(words = ['multiple...dots', 'here||||are', 'pipes', 'and###hashes'],separator = \".\") == ['multiple', 'dots', 'here||||are', 'pipes', 'and###hashes']\n assert candidate(words = ['a|b||c|||d||||e'],separator = \"|\") == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = [',,apple,,,banana,,,', 'cherry,,,', 'date,'],separator = \",\") == ['apple', 'banana', 'cherry', 'date']\n assert candidate(words = ['@start@', 'middle@', '@end'],separator = \"@\") == ['start', 'middle', 'end']\n assert candidate(words = ['#a#b#c#d', '#e##f#', 'g#h#i#'],separator = \"#\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']\n assert candidate(words = ['a.b.c.d.e', 'f.g.h', 'i.j.k.l'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']\n assert candidate(words = ['a.b.c.d.e', 'f.g.h', 'i.j.k.l.m'],separator = \".\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']\n assert candidate(words = ['foo$bar$baz', 'qux$quux', 'corge$grault$garply'],separator = \"$\") == ['foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply']\n", "comparison": "exact"}, "public_tests": ["[\"one.two.three\",\"four.five\",\"six\"]\n\".\"", "[\"$easy$\",\"$problem$\"]\n\"$\"", "[\"|||\"]\n\"|\""], "hints": ["Iterate over each string in the given array using a loop and perform string splitting based on the provided separator character.", "Be sure not to return empty strings."], "metadata": {"canonical_parameter_names": ["words", "separator"], "leetcode_dataset_entry_point": "Solution().splitWordsBySeparator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:13+00:00", "tests_total": 138, "tests_dropped": 23, "flags": [], "topic_tags": ["array", "string"]}, "language": "ruby", "interface": {"raw_signature": "def split_words_by_separator(words, separator)", "container": null, "callable": "split_words_by_separator", "parameters": [{"name": "words", "type": "String[]"}, {"name": "separator", "type": "Character"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2789, "task_id": "largest-element-in-an-array-after-merge-operations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums consisting of positive integers.\n\nYou can do the following operation on the array any number of times:\n\n- Choose an index i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.\n\nReturn the value of the largest element that you can possibly obtain in the final array.\n\nExample 1:\n\nInput: nums = [2,3,7,9,3]\nOutput: 21\nExplanation: We can apply the following operations on the array:\n- Choose i = 0. The resulting array will be nums = [5,7,9,3].\n- Choose i = 1. The resulting array will be nums = [5,16,3].\n- Choose i = 0. The resulting array will be nums = [21,3].\nThe largest element in the final array is 21. It can be shown that we cannot obtain a larger element.\n\nExample 2:\n\nInput: nums = [5,3,3]\nOutput: 11\nExplanation: We can do the following operations on the array:\n- Choose i = 1. The resulting array will be nums = [5,6].\n- Choose i = 0. The resulting array will be nums = [11].\nThere is only one element in the final array, which is 11.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) == 1111111\n assert candidate(nums = [10, 5, 2, 1]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [2, 3, 7, 9, 3]) == 21\n assert candidate(nums = [10, 5, 2]) == 10\n assert candidate(nums = [5, 3, 3]) == 11\n assert candidate(nums = [1, 10, 1, 10, 1]) == 22\n assert candidate(nums = [1, 1000000, 1]) == 1000001\n assert candidate(nums = [5]) == 5\n assert candidate(nums = [1000000]) == 1000000\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [10, 9, 8, 7, 6]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 256\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 9, 8, 10, 12, 11, 13, 15, 14, 16, 18, 17, 19, 20]) == 210\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]) == 2500\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 1000000\n assert candidate(nums = [1000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000000\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 10000000\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1000\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256]) == 511\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 100\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 75\n assert candidate(nums = [2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2]) == 20\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\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, 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]) == 99\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4]) == 58\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 1, 1, 1]) == 200\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2046\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 60\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 111\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 65\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 206\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 45\n assert candidate(nums = [2, 2, 2, 2, 1, 1, 1, 1, 1, 1]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) == 1111111\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == 11111\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 165\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 3, 3, 3, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 188\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 275\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 110\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 100\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 30\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 90\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 639\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 10000000\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 300\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]) == 325\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 100\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 21\n assert candidate(nums = [5, 5, 5, 5, 10, 10, 10, 10, 15, 15]) == 90\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350, 500, 450, 600]) == 3300\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 42\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 175\n assert candidate(nums = [10, 5, 5, 10, 10, 5, 5, 10]) == 60\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]) == 66\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]) == 465\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999]) == 9999990\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64, 128, 128, 128, 256, 256, 256, 512, 512, 512, 1024, 1024, 1024]) == 6141\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 4000000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 70\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 40\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16]) == 62\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000]) == 5000000\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == 100000\n assert candidate(nums = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 56\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4]) == 22\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 45\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 220\n assert candidate(nums = [10, 20, 15, 25, 30, 20, 10, 5, 1, 2]) == 100\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 110\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 1000000, 1000000, 1000000]) == 4111111\n assert candidate(nums = [71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == 71\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [1, 3, 2, 4, 2, 3, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 9]) == 95\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 35\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]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 39\n assert candidate(nums = [10, 5, 5, 10, 20, 5]) == 50\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 100\n assert candidate(nums = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10]) == 75\n assert candidate(nums = [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, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 124\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 110\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 55\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]) == 53\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 504\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 15\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]) == 265\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 110\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 2100\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 1000000\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000]) == 111111\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1]) == 1000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 110\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]) == 220\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 200\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1]) == 5000004\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 39\n assert candidate(nums = [5, 15, 5, 15, 5, 15, 5, 15, 5, 15]) == 100\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 90\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1210\n assert candidate(nums = [1, 3, 3, 2, 2, 4, 4, 1, 1, 5, 5, 1, 1, 6, 6]) == 45\n", "comparison": "exact"}, "public_tests": ["[2,3,7,9,3]", "[5,3,3]"], "hints": ["Start from the end of the array and keep merging elements together until it is no longer possible.", "The answer will be the resulting element from the last merge operation."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxArrayValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:15+00:00", "tests_total": 124, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def max_array_value(nums)", "container": null, "callable": "max_array_value", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2790, "task_id": "maximum-number-of-groups-with-increasing-length", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array usageLimits of length n.\n\nYour task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:\n\n- Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.\n- Each group (except the first one) must have a length strictly greater than the previous group.\n\nReturn an integer denoting the maximum number of groups you can create while satisfying these conditions.\n\nExample 1:\n\nInput: usageLimits = [1,2,5]\nOutput: 3\nExplanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [2].\nGroup 2 contains the numbers [1,2].\nGroup 3 contains the numbers [0,1,2].\nIt can be shown that the maximum number of groups is 3.\nSo, the output is 3.\n\nExample 2:\n\nInput: usageLimits = [2,1,2]\nOutput: 2\nExplanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nGroup 2 contains the numbers [1,2].\nIt can be shown that the maximum number of groups is 2.\nSo, the output is 2.\n\nExample 3:\n\nInput: usageLimits = [1,1]\nOutput: 1\nExplanation: In this example, we can use both 0 and 1 at most once.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nIt can be shown that the maximum number of groups is 1.\nSo, the output is 1.\n\nConstraints:\n\n- 1 <= usageLimits.length <= 10^5\n- 1 <= usageLimits[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(usageLimits = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000]) == 3\n assert candidate(usageLimits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(usageLimits = [1, 2, 5]) == 3\n assert candidate(usageLimits = [1, 2, 3, 4, 5]) == 5\n assert candidate(usageLimits = [3, 3, 3]) == 3\n assert candidate(usageLimits = [1, 1]) == 1\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(usageLimits = [1]) == 1\n assert candidate(usageLimits = [1, 1000000000, 1, 1000000000, 1]) == 4\n assert candidate(usageLimits = [3, 3, 3, 3]) == 4\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5\n assert candidate(usageLimits = [2, 1, 2]) == 2\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 5\n assert candidate(usageLimits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 11\n assert candidate(usageLimits = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 19\n assert candidate(usageLimits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(usageLimits = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 14\n assert candidate(usageLimits = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(usageLimits = [20, 1, 20, 2, 20, 3, 20, 4, 20, 5, 20, 6, 20, 7, 20, 8, 20, 9, 20, 10]) == 20\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(usageLimits = [1, 3, 6, 10, 15]) == 5\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 20\n assert candidate(usageLimits = [5, 3, 2, 1]) == 4\n assert candidate(usageLimits = [15, 10, 6, 3, 1]) == 5\n assert candidate(usageLimits = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 10\n assert candidate(usageLimits = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(usageLimits = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(usageLimits = [30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == 15\n assert candidate(usageLimits = [10, 10, 10, 10, 10]) == 5\n assert candidate(usageLimits = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(usageLimits = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == 10\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(usageLimits = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(usageLimits = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20]) == 6\n assert candidate(usageLimits = [100, 50, 25, 12, 6, 3, 1]) == 7\n assert candidate(usageLimits = [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]) == 20\n assert candidate(usageLimits = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 7\n assert candidate(usageLimits = [5, 4, 3, 2, 1]) == 5\n assert candidate(usageLimits = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 14\n assert candidate(usageLimits = [1000000000, 1, 1000000000, 1, 1000000000, 1]) == 5\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(usageLimits = [1, 2, 2, 3, 3, 3]) == 4\n assert candidate(usageLimits = [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]) == 16\n assert candidate(usageLimits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(usageLimits = [1000000000, 1000000000, 1000000000, 1000000000]) == 4\n assert candidate(usageLimits = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 4\n assert candidate(usageLimits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(usageLimits = [5, 2, 4, 1, 3]) == 5\n assert candidate(usageLimits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(usageLimits = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 10\n assert candidate(usageLimits = [5, 4, 3, 2, 1]) == 5\n assert candidate(usageLimits = [100, 50, 25, 10, 5, 1]) == 6\n assert candidate(usageLimits = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 5\n assert candidate(usageLimits = [1, 2, 3, 4, 5]) == 5\n assert candidate(usageLimits = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 10\n assert candidate(usageLimits = [20, 10, 30, 5, 15, 25, 5, 35, 40, 10, 5, 15, 20, 5, 25, 30, 5, 40, 5, 10]) == 20\n assert candidate(usageLimits = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 7\n assert candidate(usageLimits = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(usageLimits = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 14\n assert candidate(usageLimits = [10, 10, 10, 10, 10, 10, 10, 10, 10, 1]) == 10\n assert candidate(usageLimits = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 7\n assert candidate(usageLimits = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 11\n assert candidate(usageLimits = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(usageLimits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(usageLimits = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 6\n assert candidate(usageLimits = [10, 10, 10, 10, 10, 10]) == 6\n assert candidate(usageLimits = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 15\n", "comparison": "exact"}, "public_tests": ["[1,2,5]", "[2,1,2]", "[1,1]"], "hints": ["Can we solve this problem using sorting and binary search?", "Sort the array in increasing order and run a binary search on the number of groups, x.", "To determine if a value x is feasible, greedily distribute the numbers such that each group receives 1, 2, 3, ..., x numbers."], "metadata": {"canonical_parameter_names": ["usageLimits"], "leetcode_dataset_entry_point": "Solution().maxIncreasingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:18+00:00", "tests_total": 70, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "binary-search", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_increasing_groups(usage_limits)", "container": null, "callable": "max_increasing_groups", "parameters": [{"name": "usage_limits", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2798, "task_id": "number-of-employees-who-met-the-target", "difficulty": "Easy", "problem_description": "There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.\n\nThe company requires each employee to work for at least target hours.\n\nYou are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.\n\nReturn the integer denoting the number of employees who worked at least target hours.\n\nExample 1:\n\nInput: hours = [0,1,2,3,4], target = 2\nOutput: 3\nExplanation: The company wants each employee to work for at least 2 hours.\n- Employee 0 worked for 0 hours and didn't meet the target.\n- Employee 1 worked for 1 hours and didn't meet the target.\n- Employee 2 worked for 2 hours and met the target.\n- Employee 3 worked for 3 hours and met the target.\n- Employee 4 worked for 4 hours and met the target.\nThere are 3 employees who met the target.\n\nExample 2:\n\nInput: hours = [5,1,4,2,2], target = 6\nOutput: 0\nExplanation: The company wants each employee to work for at least 6 hours.\nThere are 0 employees who met the target.\n\nConstraints:\n\n- 1 <= n == hours.length <= 50\n- 0 <= hours[i], target <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(hours = [5, 5, 5, 5, 5],target = 5) == 5\n assert candidate(hours = [3, 4, 5, 6, 7],target = 4) == 4\n assert candidate(hours = [1, 5, 7, 9],target = 8) == 1\n assert candidate(hours = [10, 10, 10],target = 10) == 3\n assert candidate(hours = [0, 1, 2, 3, 4],target = 2) == 3\n assert candidate(hours = [10, 20, 30, 40, 50],target = 25) == 3\n assert candidate(hours = [50, 50, 50, 50, 50],target = 50) == 5\n assert candidate(hours = [1],target = 1) == 1\n assert candidate(hours = [3, 5, 7, 9, 11],target = 10) == 1\n assert candidate(hours = [1, 2, 3, 4, 5],target = 0) == 5\n assert candidate(hours = [100, 200, 300],target = 150) == 2\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 5) == 6\n assert candidate(hours = [1, 1, 1, 1, 1],target = 1) == 5\n assert candidate(hours = [3, 3, 3, 3, 3],target = 3) == 5\n assert candidate(hours = [0, 0, 0, 0, 0],target = 1) == 0\n assert candidate(hours = [5, 1, 4, 2, 2],target = 6) == 0\n assert candidate(hours = [100, 200, 300, 400, 500],target = 150) == 4\n assert candidate(hours = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],target = 55000) == 5\n assert candidate(hours = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25],target = 25) == 10\n assert candidate(hours = [10000, 20000, 30000, 40000, 50000],target = 30000) == 3\n assert candidate(hours = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],target = 1) == 0\n assert candidate(hours = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],target = 45) == 6\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],target = 150) == 6\n assert candidate(hours = [33, 66, 99, 132, 165, 198, 231, 264, 297, 330],target = 198) == 5\n assert candidate(hours = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 5) == 10\n assert candidate(hours = [55, 55, 55, 55, 55, 55, 55, 55, 55, 55],target = 54) == 10\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 101) == 0\n assert candidate(hours = [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],target = 25) == 13\n assert candidate(hours = [100000, 50000, 75000, 25000, 0],target = 50000) == 3\n assert candidate(hours = [0, 100000, 50000, 75000, 25000],target = 50000) == 3\n assert candidate(hours = [15, 25, 35, 45, 55],target = 35) == 3\n assert candidate(hours = [100, 200, 300, 400, 500],target = 500) == 1\n assert candidate(hours = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],target = 95) == 5\n assert candidate(hours = [50, 50, 50, 50, 50],target = 50) == 5\n assert candidate(hours = [99995, 99996, 99997, 99998, 99999, 100000],target = 99995) == 6\n assert candidate(hours = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],target = 50) == 11\n assert candidate(hours = [1, 10, 100, 1000, 10000, 100000, 0, 0, 0, 0],target = 100) == 4\n assert candidate(hours = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 5) == 6\n assert candidate(hours = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],target = 25) == 8\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 0) == 10\n assert candidate(hours = [50, 40, 30, 20, 10, 0, 10, 20, 30, 40],target = 25) == 5\n assert candidate(hours = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250],target = 100) == 7\n assert candidate(hours = [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],target = 9) == 30\n assert candidate(hours = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],target = 5) == 5\n assert candidate(hours = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],target = 100000) == 10\n assert candidate(hours = [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],target = 15) == 16\n assert candidate(hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 2) == 9\n assert candidate(hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 10) == 5\n assert candidate(hours = [50, 40, 30, 20, 10, 0],target = 25) == 3\n assert candidate(hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],target = 39) == 1\n assert candidate(hours = [10, 20, 30, 40, 50],target = 25) == 3\n assert candidate(hours = [1, 10, 100, 1000, 10000],target = 50) == 3\n assert candidate(hours = [10, 20, 30, 40, 50],target = 100) == 0\n assert candidate(hours = [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],target = 10) == 26\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 10) == 10\n assert candidate(hours = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],target = 10) == 5\n assert candidate(hours = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],target = 60) == 5\n assert candidate(hours = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],target = 25) == 20\n assert candidate(hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],target = 20) == 10\n assert candidate(hours = [5, 15, 25, 35, 45],target = 25) == 3\n assert candidate(hours = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],target = 99995) == 5\n assert candidate(hours = [9, 9, 9, 9, 9],target = 9) == 5\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 50) == 6\n assert candidate(hours = [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],target = 30) == 15\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 10) == 1\n assert candidate(hours = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 1000) == 1\n assert candidate(hours = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14, 16, 15, 17],target = 8) == 18\n assert candidate(hours = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],target = 5) == 6\n assert candidate(hours = [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, 50],target = 25) == 14\n assert candidate(hours = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],target = 50000) == 6\n assert candidate(hours = [50, 40, 30, 20, 10, 0, 10, 20, 30, 40],target = 10) == 9\n assert candidate(hours = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60],target = 25) == 8\n assert candidate(hours = [50, 40, 30, 20, 10],target = 25) == 3\n assert candidate(hours = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],target = 40) == 6\n assert candidate(hours = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250],target = 125) == 6\n assert candidate(hours = [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],target = 25) == 26\n assert candidate(hours = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 25) == 6\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 5) == 6\n assert candidate(hours = [100000, 99999, 99998, 99997, 99996],target = 100000) == 1\n assert candidate(hours = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 500) == 6\n assert candidate(hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],target = 9) == 1\n assert candidate(hours = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],target = 5) == 6\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 99) == 1\n assert candidate(hours = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 3) == 6\n assert candidate(hours = [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],target = 2) == 16\n assert candidate(hours = [100000, 99999, 100000, 100000, 99999],target = 100000) == 3\n assert candidate(hours = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],target = 3) == 10\n assert candidate(hours = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 1) == 10\n assert candidate(hours = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 10) == 1\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 10) == 11\n assert candidate(hours = [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],target = 20) == 15\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 105) == 0\n assert candidate(hours = [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],target = 5) == 39\n assert candidate(hours = [0, 0, 0, 0, 0],target = 1) == 0\n assert candidate(hours = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 11) == 5\n assert candidate(hours = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000],target = 50000) == 30\n assert candidate(hours = [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],target = 1) == 0\n assert candidate(hours = [12, 34, 56, 78, 90],target = 50) == 3\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 55) == 5\n assert candidate(hours = [30, 25, 20, 15, 10],target = 20) == 3\n", "comparison": "exact"}, "public_tests": ["[0,1,2,3,4]\n2", "[5,1,4,2,2]\n6"], "hints": ["Iterate over the elements of array hours and check if the value is greater than or equal to target."], "metadata": {"canonical_parameter_names": ["hours", "target"], "leetcode_dataset_entry_point": "Solution().numberOfEmployeesWhoMetTarget", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:26+00:00", "tests_total": 103, "tests_dropped": 3, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_employees_who_met_target(hours, target)", "container": null, "callable": "number_of_employees_who_met_target", "parameters": [{"name": "hours", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2799, "task_id": "count-complete-subarrays-in-an-array", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of positive integers.\n\nWe call a subarray of an array complete if the following condition is satisfied:\n\n- The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.\n\nReturn the number of complete subarrays.\n\nA subarray is a contiguous non-empty part of an array.\n\nExample 1:\n\nInput: nums = [1,3,1,2,2]\nOutput: 4\nExplanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].\n\nExample 2:\n\nInput: nums = [5,5,5,5]\nOutput: 10\nExplanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 2000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 28\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 4\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996]) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3]) == 10\n assert candidate(nums = [7, 7, 7, 1, 7, 7, 7]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1]) == 15\n assert candidate(nums = [1, 2, 1, 3, 2, 1]) == 9\n assert candidate(nums = [1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50]) == 1\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 4, 4, 5, 5]) == 6\n assert candidate(nums = [2000, 1, 2000, 2, 2000, 3]) == 2\n assert candidate(nums = [1, 3, 1, 2, 2]) == 4\n assert candidate(nums = [5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\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]) == 190\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 11\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1]) == 144\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 84\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 1, 2, 3, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9]) == 25\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]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 21\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 6, 5, 4, 3, 2, 1]) == 26\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 210\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 55\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, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 2211\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]) == 231\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 21\n assert candidate(nums = [2, 3, 1, 3, 5, 7, 5, 1, 3, 2, 4, 1, 5, 3, 7, 2, 5, 1, 3, 5, 7, 9, 1, 2, 3, 4, 5]) == 85\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]) == 136\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 115\n assert candidate(nums = [7, 7, 1, 3, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 4\n assert candidate(nums = [1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3]) == 162\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]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 1\n assert candidate(nums = [1000, 1000, 999, 999, 998, 998, 997, 997, 996, 996, 995, 995, 994, 994]) == 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]) == 171\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]) == 1\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]) == 4\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 66\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 2000, 1999, 1998, 1997, 1996]) == 21\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 210\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]) == 190\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 6\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]) == 351\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]) == 496\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 91\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4\n assert candidate(nums = [7, 3, 7, 3, 1, 3, 7, 1, 7, 3, 7, 3, 1]) == 58\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 4\n assert candidate(nums = [1, 2, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 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]) == 25\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]) == 2\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]) == 253\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 3, 4, 5]) == 43\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 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]) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1]) == 20\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]) == 66\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10]) == 91\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 210\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9]) == 91\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 133\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 91\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 66\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500]) == 66\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 66\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981]) == 1\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]) == 231\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 10]) == 7\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 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, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 66\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 10, 6, 7, 8, 9, 10]) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\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]) == 325\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == 6\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 231\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]) == 25\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 190\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 136\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 231\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 171\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]) == 231\n assert candidate(nums = [10, 20, 10, 30, 20, 10, 40, 50, 30, 20]) == 15\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 120\n", "comparison": "exact"}, "public_tests": ["[1,3,1,2,2]", "[5,5,5,5]"], "hints": ["Let’s say k is the number of distinct elements in the array. Our goal is to find the number of subarrays with k distinct elements.", "Since the constraints are small, you can check every subarray."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countCompleteSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:28+00:00", "tests_total": 99, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def count_complete_subarrays(nums)", "container": null, "callable": "count_complete_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2800, "task_id": "shortest-string-that-contains-three-strings", "difficulty": "Medium", "problem_description": "Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.\n\nIf there are multiple such strings, return the lexicographically smallest one.\n\nReturn a string denoting the answer to the problem.\n\nNotes\n\n- A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n- A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: a = \"abc\", b = \"bca\", c = \"aaa\"\nOutput: \"aaabca\"\nExplanation: We show that \"aaabca\" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and \"aaabca\" is the lexicographically smallest one.\n\nExample 2:\n\nInput: a = \"ab\", b = \"ba\", c = \"aba\"\nOutput: \"aba\"\nExplanation: We show that the string \"aba\" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that \"aba\" is the lexicographically smallest one.\n\nConstraints:\n\n- 1 <= a.length, b.length, c.length <= 100\n- a, b, c consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(a = \"aaaa\",b = \"bbbb\",c = \"cccc\") == \"aaaabbbbcccc\"\n assert candidate(a = \"aaa\",b = \"aa\",c = \"a\") == \"aaa\"\n assert candidate(a = \"ab\",b = \"ba\",c = \"aba\") == \"aba\"\n assert candidate(a = \"hello\",b = \"world\",c = \"hold\") == \"helloholdworld\"\n assert candidate(a = \"a\",b = \"b\",c = \"c\") == \"abc\"\n assert candidate(a = \"abcabc\",b = \"bcabc\",c = \"cabc\") == \"abcabc\"\n assert candidate(a = \"same\",b = \"same\",c = \"same\") == \"same\"\n assert candidate(a = \"a\",b = \"ab\",c = \"abc\") == \"abc\"\n assert candidate(a = \"xyz\",b = \"yzx\",c = \"zxy\") == \"xyzxy\"\n assert candidate(a = \"aaa\",b = \"bbb\",c = \"ccc\") == \"aaabbbccc\"\n assert candidate(a = \"abcde\",b = \"cdefg\",c = \"efghi\") == \"abcdefghi\"\n assert candidate(a = \"xyz\",b = \"zyx\",c = \"yzx\") == \"zyxyzx\"\n assert candidate(a = \"abc\",b = \"bca\",c = \"aaa\") == \"aaabca\"\n assert candidate(a = \"zzz\",b = \"zz\",c = \"z\") == \"zzz\"\n assert candidate(a = \"abcd\",b = \"bcd\",c = \"cde\") == \"abcde\"\n assert candidate(a = \"dog\",b = \"god\",c = \"dog\") == \"dogod\"\n assert candidate(a = \"start\",b = \"middle\",c = \"end\") == \"middlendstart\"\n assert candidate(a = \"abc\",b = \"abc\",c = \"abc\") == \"abc\"\n assert candidate(a = \"abc\",b = \"def\",c = \"ghi\") == \"abcdefghi\"\n assert candidate(a = \"short\",b = \"longerstring\",c = \"tiny\") == \"longerstringshortiny\"\n assert candidate(a = \"one\",b = \"two\",c = \"three\") == \"threetwone\"\n assert candidate(a = \"alphabet\",b = \"bet\",c = \"phabet\") == \"alphabet\"\n assert candidate(a = \"abacabad\",b = \"acabadab\",c = \"adabacab\") == \"adabacabadab\"\n assert candidate(a = \"unique\",b = \"queue\",c = \"ueuniq\") == \"ueuniqueue\"\n assert candidate(a = \"short\",b = \"longer\",c = \"longest\") == \"longerlongestshort\"\n assert candidate(a = \"abcabcabc\",b = \"bcabcabca\",c = \"cabcabcab\") == \"abcabcabcab\"\n assert candidate(a = \"abcd\",b = \"bcd\",c = \"cd\") == \"abcd\"\n assert candidate(a = \"abcxyz\",b = \"xyzabc\",c = \"bcxyza\") == \"abcxyzabc\"\n assert candidate(a = \"intersection\",b = \"section\",c = \"inter\") == \"intersection\"\n assert candidate(a = \"abcdefg\",b = \"efghijk\",c = \"ghijklm\") == \"abcdefghijklm\"\n assert candidate(a = \"abc\",b = \"bcd\",c = \"cde\") == \"abcde\"\n assert candidate(a = \"abcd\",b = \"bcde\",c = \"cdef\") == \"abcdef\"\n assert candidate(a = \"supercalifragilisticexpialidocious\",b = \"califragilistic\",c = \"fragilisticexpialidocious\") == \"supercalifragilisticexpialidocious\"\n assert candidate(a = \"abacaba\",b = \"acababc\",c = \"bacab\") == \"abacababc\"\n assert candidate(a = \"hello\",b = \"world\",c = \"helloworld\") == \"helloworld\"\n assert candidate(a = \"abcd\",b = \"dcba\",c = \"bacd\") == \"abcdcbacd\"\n assert candidate(a = \"mnop\",b = \"nopq\",c = \"opqr\") == \"mnopqr\"\n assert candidate(a = \"sequence\",b = \"sequenceabc\",c = \"absequence\") == \"absequenceabc\"\n assert candidate(a = \"prefix\",b = \"suffix\",c = \"fix\") == \"prefixsuffix\"\n assert candidate(a = \"aaa\",b = \"aab\",c = \"aba\") == \"aaaba\"\n assert candidate(a = \"aabbcc\",b = \"bbccdd\",c = \"ccddeeff\") == \"aabbccddeeff\"\n assert candidate(a = \"xyzz\",b = \"zzxy\",c = \"xyxy\") == \"xyxyzzxy\"\n assert candidate(a = \"abcde\",b = \"edcba\",c = \"cabde\") == \"cabdedcbabcde\"\n assert candidate(a = \"abcdef\",b = \"defghi\",c = \"ghijkl\") == \"abcdefghijkl\"\n assert candidate(a = \"abcdefg\",b = \"efghijk\",c = \"ghijkl\") == \"abcdefghijkl\"\n assert candidate(a = \"pqrs\",b = \"rstu\",c = \"stuv\") == \"pqrstuv\"\n assert candidate(a = \"abcdxyz\",b = \"xyzabc\",c = \"bcde\") == \"abcdxyzabcde\"\n assert candidate(a = \"abcdabcd\",b = \"bcdbcd\",c = \"dcbcdabc\") == \"dcbcdabcdabcdbcd\"\n assert candidate(a = \"algorithm\",b = \"rhythm\",c = \"thmology\") == \"algorithmologyrhythm\"\n assert candidate(a = \"banana\",b = \"nab\",c = \"ana\") == \"bananab\"\n assert candidate(a = \"intersect\",b = \"section\",c = \"inter\") == \"intersection\"\n assert candidate(a = \"apple\",b = \"peach\",c = \"cherry\") == \"applepeacherry\"\n assert candidate(a = \"abcabc\",b = \"bcabca\",c = \"cababc\") == \"cababcabca\"\n assert candidate(a = \"hello\",b = \"lohe\",c = \"hello\") == \"hellohe\"\n assert candidate(a = \"xyzabc\",b = \"bcdef\",c = \"defg\") == \"xyzabcdefg\"\n assert candidate(a = \"overlap\",b = \"lapover\",c = \"over\") == \"lapoverlap\"\n assert candidate(a = \"longstring\",b = \"stringlong\",c = \"nstringl\") == \"nstringlongstring\"\n assert candidate(a = \"abcdef\",b = \"defabc\",c = \"efabcd\") == \"defabcdef\"\n assert candidate(a = \"xy\",b = \"yx\",c = \"xyz\") == \"yxyz\"\n assert candidate(a = \"abc\",b = \"cab\",c = \"bac\") == \"bacabc\"\n assert candidate(a = \"apple\",b = \"plea\",c = \"eat\") == \"appleat\"\n assert candidate(a = \"abcabcabc\",b = \"bcabcbc\",c = \"cabcbcb\") == \"abcabcabcbcb\"\n assert candidate(a = \"pqr\",b = \"qrp\",c = \"rpq\") == \"pqrpq\"\n assert candidate(a = \"hello\",b = \"world\",c = \"hello\") == \"helloworld\"\n assert candidate(a = \"abcdefg\",b = \"efgabcd\",c = \"fgabcde\") == \"efgabcdefg\"\n assert candidate(a = \"aaabbb\",b = \"bbbaaa\",c = \"aaabbb\") == \"aaabbbaaa\"\n assert candidate(a = \"xyz\",b = \"zyx\",c = \"xyx\") == \"xyxyzyx\"\n assert candidate(a = \"abcdefgh\",b = \"efghijkl\",c = \"ghijklmn\") == \"abcdefghijklmn\"\n assert candidate(a = \"aaabbb\",b = \"bbbaaa\",c = \"aabbaa\") == \"aaabbbaaabbaa\"\n assert candidate(a = \"abcdabcd\",b = \"cdabcdabcd\",c = \"bcdabcdabcd\") == \"bcdabcdabcd\"\n assert candidate(a = \"xyz\",b = \"wxyz\",c = \"vwxyz\") == \"vwxyz\"\n assert candidate(a = \"programming\",b = \"coding\",c = \"ingenuity\") == \"codingenuityprogramming\"\n assert candidate(a = \"zebra\",b = \"bra\",c = \"ebra\") == \"zebra\"\n assert candidate(a = \"zzz\",b = \"zzzz\",c = \"zzzzz\") == \"zzzzz\"\n assert candidate(a = \"longstring\",b = \"stringlong\",c = \"ngstringlo\") == \"longstringlong\"\n assert candidate(a = \"antidisestablishmentarianism\",b = \"disestablishmentarianism\",c = \"establishmentarianism\") == \"antidisestablishmentarianism\"\n assert candidate(a = \"xyzabc\",b = \"bcdef\",c = \"defgh\") == \"xyzabcdefgh\"\n assert candidate(a = \"banana\",b = \"ananas\",c = \"nana\") == \"bananas\"\n assert candidate(a = \"abcde\",b = \"edcba\",c = \"bcde\") == \"abcdedcba\"\n assert candidate(a = \"aaaaaa\",b = \"aaaaaab\",c = \"baaaaaa\") == \"baaaaaab\"\n assert candidate(a = \"aabbcc\",b = \"bbccaa\",c = \"ccaabb\") == \"aabbccaabb\"\n assert candidate(a = \"zzzz\",b = \"zzzz\",c = \"zzzz\") == \"zzzz\"\n assert candidate(a = \"unique\",b = \"queue\",c = \"uniq\") == \"uniqueue\"\n assert candidate(a = \"banana\",b = \"nab\",c = \"ananab\") == \"bananab\"\n assert candidate(a = \"longword\",b = \"wordlong\",c = \"long\") == \"longwordlong\"\n assert candidate(a = \"aaaa\",b = \"aaab\",c = \"aabb\") == \"aaaabb\"\n assert candidate(a = \"banana\",b = \"nabana\",c = \"anaban\") == \"anabanana\"\n assert candidate(a = \"banana\",b = \"anana\",c = \"nana\") == \"banana\"\n assert candidate(a = \"hello\",b = \"lohe\",c = \"world\") == \"helloheworld\"\n assert candidate(a = \"pneumonoultramicroscopicsilicovolcanoconiosis\",b = \"microscopicsilicovolcanoconiosis\",c = \"silicovolcanoconiosis\") == \"pneumonoultramicroscopicsilicovolcanoconiosis\"\n assert candidate(a = \"xylophone\",b = \"lophon\",c = \"phone\") == \"xylophone\"\n assert candidate(a = \"abac\",b = \"bacd\",c = \"acde\") == \"abacde\"\n assert candidate(a = \"mississippi\",b = \"issi\",c = \"sip\") == \"mississippi\"\n assert candidate(a = \"abcdefg\",b = \"defgabc\",c = \"fgabcde\") == \"defgabcdefg\"\n assert candidate(a = \"abc\",b = \"cbad\",c = \"dabc\") == \"cbadabc\"\n assert candidate(a = \"aab\",b = \"abb\",c = \"bba\") == \"aabba\"\n assert candidate(a = \"aaaab\",b = \"bbbaa\",c = \"aabba\") == \"bbbaaaabba\"\n assert candidate(a = \"abcd\",b = \"cdab\",c = \"abcd\") == \"abcdab\"\n assert candidate(a = \"abcdefg\",b = \"ghijklm\",c = \"jklmnop\") == \"abcdefghijklmnop\"\n assert candidate(a = \"banana\",b = \"nab\",c = \"nan\") == \"bananab\"\n assert candidate(a = \"abcdabcd\",b = \"bcdbcdb\",c = \"cdcdcdc\") == \"abcdabcdbcdbcdcdcdc\"\n assert candidate(a = \"mnopqr\",b = \"pqrs\",c = \"rstuv\") == \"mnopqrstuv\"\n assert candidate(a = \"overlap\",b = \"lapover\",c = \"verlapo\") == \"lapoverlapo\"\n assert candidate(a = \"abcd\",b = \"cdab\",c = \"bcda\") == \"abcdab\"\n assert candidate(a = \"abacaba\",b = \"cabacab\",c = \"bacabac\") == \"cabacabac\"\n assert candidate(a = \"overlap\",b = \"laplap\",c = \"lapping\") == \"overlaplapping\"\n assert candidate(a = \"hello\",b = \"world\",c = \"helowrld\") == \"hellohelowrldworld\"\n assert candidate(a = \"abcdefghij\",b = \"ghijklmnop\",c = \"mnopqrstuv\") == \"abcdefghijklmnopqrstuv\"\n assert candidate(a = \"aaaab\",b = \"bbbbb\",c = \"ccccd\") == \"aaaabbbbbccccd\"\n assert candidate(a = \"hello\",b = \"world\",c = \"owor\") == \"helloworld\"\n assert candidate(a = \"ab\",b = \"bc\",c = \"ca\") == \"abca\"\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n\"bca\"\n\"aaa\"", "\"ab\"\n\"ba\"\n\"aba\""], "hints": ["Think about how you can generate all possible strings that contain all three input strings as substrings. Can you come up with an efficient algorithm to do this?", "Check all permutations of the words a, b, and c. For each permutation, begin by appending some letters to the end of the first word to form the second word. Then, proceed to add more letters to generate the third word."], "metadata": {"canonical_parameter_names": ["a", "b", "c"], "leetcode_dataset_entry_point": "Solution().minimumString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:30+00:00", "tests_total": 111, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_string(a, b, c)", "container": null, "callable": "minimum_string", "parameters": [{"name": "a", "type": "String"}, {"name": "b", "type": "String"}, {"name": "c", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2801, "task_id": "count-stepping-numbers-in-range", "difficulty": "Hard", "problem_description": "Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].\n\nA stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.\n\nReturn an integer denoting the count of stepping numbers in the inclusive range [low, high].\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nNote: A stepping number should not have a leading zero.\n\nExample 1:\n\nInput: low = \"1\", high = \"11\"\nOutput: 10\nExplanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.\n\nExample 2:\n\nInput: low = \"90\", high = \"101\"\nOutput: 2\nExplanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.\n\nConstraints:\n\n- 1 <= int(low) <= int(high) < 10^100\n- 1 <= low.length, high.length <= 100\n- low and high consist of only digits.\n- low and high don't have any leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(low = \"123\",high = \"456\") == 13\n assert candidate(low = \"5555555555\",high = \"6666666666\") == 436\n assert candidate(low = \"1111111111\",high = \"2222222222\") == 307\n assert candidate(low = \"1000000000\",high = \"1000000001\") == 0\n assert candidate(low = \"10\",high = \"100\") == 17\n assert candidate(low = \"9999999999\",high = \"9999999999\") == 0\n assert candidate(low = \"1\",high = \"9876543210\") == 6111\n assert candidate(low = \"1\",high = \"11\") == 10\n assert candidate(low = \"9876543210\",high = \"9876543210\") == 1\n assert candidate(low = \"90\",high = \"101\") == 2\n assert candidate(low = \"10000000000000000000\",high = \"10000000000000000010\") == 0\n assert candidate(low = \"12345678901234567890\",high = \"98765432109876543210\") == 1768804\n assert candidate(low = \"12345678901234567890\",high = \"12345678901234567891\") == 0\n assert candidate(low = \"999999999999999999\",high = \"1000000000000000000\") == 0\n assert candidate(low = \"321098765432109876543210987\",high = \"432109876543210987654321098\") == 25767582\n assert candidate(low = \"8888888888\",high = \"8888888899\") == 0\n assert candidate(low = \"9999999999999999999\",high = \"10000000000000000000\") == 0\n assert candidate(low = \"3333333333\",high = \"4444444444\") == 436\n assert candidate(low = \"989898989898989898\",high = \"999999999999999999\") == 1\n assert candidate(low = \"9\",high = \"9\") == 1\n assert candidate(low = \"1234567890\",high = \"2345678901\") == 333\n assert candidate(low = \"1\",high = \"2147483647\") == 3627\n assert candidate(low = \"1010101010\",high = \"2020202020\") == 251\n assert candidate(low = \"8888888888\",high = \"9999999999\") == 196\n assert candidate(low = \"1\",high = \"12345678901234567890\") == 2358711\n assert candidate(low = \"54321098765432109876543210\",high = \"65432109876543210987654321\") == 14851321\n assert candidate(low = \"5\",high = \"5555555555\") == 4904\n assert candidate(low = \"987654321\",high = \"9876543211\") == 2931\n assert candidate(low = \"54321098765432109876\",high = \"65432109876543210987\") == 297140\n assert candidate(low = \"5000000000\",high = \"5000000010\") == 0\n assert candidate(low = \"500\",high = \"600\") == 4\n assert candidate(low = \"5\",high = \"5\") == 1\n assert candidate(low = \"12345678912345678912\",high = \"23456789123456789123\") == 226942\n assert candidate(low = \"8888888888\",high = \"8989898989\") == 70\n assert candidate(low = \"9876543210\",high = \"9876543219\") == 2\n assert candidate(low = \"888888888\",high = \"999999999\") == 105\n assert candidate(low = \"1000000000\",high = \"9999999999\") == 2986\n assert candidate(low = \"8989898989\",high = \"9898989898\") == 127\n assert candidate(low = \"1212121212\",high = \"2121212121\") == 202\n assert candidate(low = \"987654321\",high = \"987654322\") == 1\n assert candidate(low = \"10000000000000000000\",high = \"10000000000000000001\") == 0\n assert candidate(low = \"54321\",high = \"65432\") == 17\n assert candidate(low = \"8999999999999999999\",high = \"9000000000000000001\") == 0\n assert candidate(low = \"1010101010\",high = \"1121212121\") == 70\n assert candidate(low = \"1010101010\",high = \"9090909090\") == 2860\n assert candidate(low = \"9999999999\",high = \"10000000000\") == 0\n assert candidate(low = \"9999999990\",high = \"9999999999\") == 0\n assert candidate(low = \"9876543210987654321\",high = \"9876543210987654322\") == 0\n assert candidate(low = \"1\",high = \"9999999999\") == 6236\n assert candidate(low = \"98765432109876543210\",high = \"98765432109876543211\") == 0\n assert candidate(low = \"1234567890\",high = \"1234567899\") == 1\n assert candidate(low = \"123\",high = \"45678901234567890123\") == 3157659\n assert candidate(low = \"7777777777\",high = \"8888888888\") == 307\n assert candidate(low = \"12121212121212121212\",high = \"13131313131313131313\") == 102885\n assert candidate(low = \"321\",high = \"654\") == 13\n assert candidate(low = \"9876543210123456789\",high = \"9876543210123456790\") == 1\n assert candidate(low = \"1010101010\",high = \"1111111111\") == 70\n assert candidate(low = \"98765432101234567890\",high = \"98765432101234567899\") == 1\n assert candidate(low = \"4444444444\",high = \"5555555555\") == 456\n assert candidate(low = \"200\",high = \"210\") == 1\n assert candidate(low = \"1\",high = \"1234567890\") == 3500\n assert candidate(low = \"987654321\",high = \"9876543210\") == 2931\n assert candidate(low = \"9876543210\",high = \"10123456789\") == 252\n assert candidate(low = \"99999999999999999999\",high = \"100000000000000000000\") == 0\n assert candidate(low = \"1111111111111111111\",high = \"1212121212121212121\") == 8551\n assert candidate(low = \"1111111111\",high = \"1111111111\") == 0\n assert candidate(low = \"8989898989\",high = \"9090909090\") == 1\n assert candidate(low = \"98765432101234567890\",high = \"98765432101234567891\") == 0\n assert candidate(low = \"5432109876\",high = \"5432109877\") == 0\n assert candidate(low = \"50505050505050505050\",high = \"60606060606060606060\") == 298777\n assert candidate(low = \"11111111111111111111\",high = \"22222222222222222222\") == 204289\n assert candidate(low = \"98765432101234567890\",high = \"98765432109876543210\") == 1\n assert candidate(low = \"10000000000\",high = \"20000000000\") == 460\n assert candidate(low = \"123\",high = \"135\") == 1\n assert candidate(low = \"1000000000\",high = \"2000000000\") == 251\n assert candidate(low = \"123456789\",high = \"987654321\") == 1362\n assert candidate(low = \"98765432109876543210987654321\",high = \"98765432109876543210987654322\") == 0\n assert candidate(low = \"98765\",high = \"98766\") == 1\n assert candidate(low = \"123456789\",high = \"1234567891\") == 1681\n assert candidate(low = \"987654321\",high = \"9876543219\") == 2932\n assert candidate(low = \"987654321\",high = \"987654329\") == 2\n assert candidate(low = \"543210\",high = \"6543210\") == 380\n assert candidate(low = \"1234567890\",high = \"1234567891\") == 0\n assert candidate(low = \"123\",high = \"321\") == 6\n assert candidate(low = \"1010101010101010101\",high = \"1111111111111111111\") == 22950\n assert candidate(low = \"8999999999\",high = \"9000000000\") == 0\n assert candidate(low = \"555555555\",high = \"666666666\") == 228\n assert candidate(low = \"10101010101010101010\",high = \"21212121212121212121\") == 195908\n assert candidate(low = \"1\",high = \"10000000000000000000\") == 2194764\n assert candidate(low = \"12345\",high = \"123456789012345\") == 90485\n assert candidate(low = \"2222222222\",high = \"3333333333\") == 389\n assert candidate(low = \"1\",high = \"99999999999999999999999999999999999999999999999999\") == 254219541\n assert candidate(low = \"123454321\",high = \"123456789\") == 16\n assert candidate(low = \"1010101010\",high = \"1010101011\") == 1\n assert candidate(low = \"112233445566778899\",high = \"122334455667788990\") == 12190\n assert candidate(low = \"100000000000000000000000000000000000000000000000000\",high = \"200000000000000000000000000000000000000000000000000\") == 251590529\n assert candidate(low = \"1111111111\",high = \"9999999999\") == 2916\n assert candidate(low = \"10101010101010101010\",high = \"20202020202020202020\") == 164407\n assert candidate(low = \"123\",high = \"133\") == 1\n assert candidate(low = \"10\",high = \"1111111111\") == 3311\n", "comparison": "exact"}, "public_tests": ["\"1\"\n\"11\"", "\"90\"\n\"101\""], "hints": ["Calculate the number of stepping numbers in the range [1, high] and subtract the number of stepping numbers in the range [1, low - 1].", "The main problem is calculating the number of stepping numbers in the range [1, x].", "First, calculate the number of stepping numbers shorter than x in length, which can be done using dynamic programming. (dp[i][j] is the number of i-digit stepping numbers ending with digit j).", "Finally, calculate the number of stepping numbers that have the same length as x similarly. However, this time we need to maintain whether the prefix (in string) is smaller than or equal to x in the DP state."], "metadata": {"canonical_parameter_names": ["low", "high"], "leetcode_dataset_entry_point": "Solution().countSteppingNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:32+00:00", "tests_total": 101, "tests_dropped": 1, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def count_stepping_numbers(low, high)", "container": null, "callable": "count_stepping_numbers", "parameters": [{"name": "low", "type": "String"}, {"name": "high", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2806, "task_id": "account-balance-after-rounded-purchase", "difficulty": "Easy", "problem_description": "Initially, you have a bank account balance of 100 dollars.\n\nYou are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars, in other words, its price.\n\nWhen making the purchase, first the purchaseAmount is rounded to the nearest multiple of 10. Let us call this value roundedAmount. Then, roundedAmount dollars are removed from your bank account.\n\nReturn an integer denoting your final bank account balance after this purchase.\n\nNotes:\n\n- 0 is considered to be a multiple of 10 in this problem.\n- When rounding, 5 is rounded upward (5 is rounded to 10, 15 is rounded to 20, 25 to 30, and so on).\n\nExample 1:\n\nInput: purchaseAmount = 9\nOutput: 90\nExplanation:\nThe nearest multiple of 10 to 9 is 10. So your account balance becomes 100 - 10 = 90.\n\nExample 2:\n\nInput: purchaseAmount = 15\nOutput: 80\nExplanation:\nThe nearest multiple of 10 to 15 is 20. So your account balance becomes 100 - 20 = 80.\n\nExample 3:\n\nInput: purchaseAmount = 10\nOutput: 90\nExplanation:\n10 is a multiple of 10 itself. So your account balance becomes 100 - 10 = 90.\n\nConstraints:\n\n- 0 <= purchaseAmount <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(purchaseAmount = 100) == 0\n assert candidate(purchaseAmount = 85) == 10\n assert candidate(purchaseAmount = 15) == 80\n assert candidate(purchaseAmount = 10) == 90\n assert candidate(purchaseAmount = 45) == 50\n assert candidate(purchaseAmount = 51) == 50\n assert candidate(purchaseAmount = 34) == 70\n assert candidate(purchaseAmount = 0) == 100\n assert candidate(purchaseAmount = 60) == 40\n assert candidate(purchaseAmount = 25) == 70\n assert candidate(purchaseAmount = 9) == 90\n assert candidate(purchaseAmount = 75) == 20\n assert candidate(purchaseAmount = 50) == 50\n assert candidate(purchaseAmount = 55) == 40\n assert candidate(purchaseAmount = 99) == 0\n assert candidate(purchaseAmount = 31) == 70\n assert candidate(purchaseAmount = 27) == 70\n assert candidate(purchaseAmount = 22) == 80\n assert candidate(purchaseAmount = 35) == 60\n assert candidate(purchaseAmount = 1) == 100\n assert candidate(purchaseAmount = 7) == 90\n assert candidate(purchaseAmount = 49) == 50\n assert candidate(purchaseAmount = 28) == 70\n assert candidate(purchaseAmount = 11) == 90\n assert candidate(purchaseAmount = 26) == 70\n assert candidate(purchaseAmount = 65) == 30\n assert candidate(purchaseAmount = 90) == 10\n assert candidate(purchaseAmount = 69) == 30\n assert candidate(purchaseAmount = 84) == 20\n assert candidate(purchaseAmount = 91) == 10\n assert candidate(purchaseAmount = 29) == 70\n assert candidate(purchaseAmount = 67) == 30\n assert candidate(purchaseAmount = 23) == 80\n assert candidate(purchaseAmount = 59) == 40\n assert candidate(purchaseAmount = 63) == 40\n assert candidate(purchaseAmount = 4) == 100\n assert candidate(purchaseAmount = 38) == 60\n assert candidate(purchaseAmount = 6) == 90\n assert candidate(purchaseAmount = 5) == 90\n assert candidate(purchaseAmount = 79) == 20\n assert candidate(purchaseAmount = 74) == 30\n assert candidate(purchaseAmount = 47) == 50\n assert candidate(purchaseAmount = 77) == 20\n assert candidate(purchaseAmount = 39) == 60\n assert candidate(purchaseAmount = 2) == 100\n assert candidate(purchaseAmount = 8) == 90\n assert candidate(purchaseAmount = 95) == 0\n assert candidate(purchaseAmount = 14) == 90\n assert candidate(purchaseAmount = 94) == 10\n assert candidate(purchaseAmount = 30) == 70\n assert candidate(purchaseAmount = 89) == 10\n assert candidate(purchaseAmount = 3) == 100\n assert candidate(purchaseAmount = 19) == 80\n assert candidate(purchaseAmount = 82) == 20\n", "comparison": "exact"}, "public_tests": ["9", "15", "10"], "hints": ["To determine the nearest multiple of 10, we can brute force the rounded amount since there are at most 100 options. In case of multiple nearest multiples, choose the largest.", "Another solution is observing that the rounded amount is floor((purchaseAmount + 5) / 10) * 10. Using this formula, we can calculate the account balance without having to brute force the rounded amount."], "metadata": {"canonical_parameter_names": ["purchaseAmount"], "leetcode_dataset_entry_point": "Solution().accountBalanceAfterPurchase", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:37+00:00", "tests_total": 54, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def account_balance_after_purchase(purchase_amount)", "container": null, "callable": "account_balance_after_purchase", "parameters": [{"name": "purchase_amount", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2808, "task_id": "minimum-seconds-to-equalize-a-circular-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums containing n integers.\n\nAt each second, you perform the following operation on the array:\n\n- For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].\n\nNote that all the elements get replaced simultaneously.\n\nReturn the minimum number of seconds needed to make all elements in the array nums equal.\n\nExample 1:\n\nInput: nums = [1,2,1,2]\nOutput: 1\nExplanation: We can equalize the array in 1 second in the following way:\n- At 1^st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].\nIt can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.\n\nExample 2:\n\nInput: nums = [2,1,3,3,2]\nOutput: 2\nExplanation: We can equalize the array in 2 seconds in the following way:\n- At 1^st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].\n- At 2^nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].\nIt can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.\n\nExample 3:\n\nInput: nums = [5,5,5,5]\nOutput: 0\nExplanation: We don't need to perform any operations as all elements in the initial array are the same.\n\nConstraints:\n\n- 1 <= n == nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 10, 20, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 1]) == 2\n assert candidate(nums = [10, 10, 1, 10, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50]) == 2\n assert candidate(nums = [5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [1, 1, 2, 2, 1, 1]) == 1\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 1]) == 1\n assert candidate(nums = [10, 1, 10, 1, 10]) == 1\n assert candidate(nums = [10, 10, 10, 20, 20, 10, 10, 10]) == 1\n assert candidate(nums = [3, 3, 3, 4, 4, 4, 3]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1]) == 2\n assert candidate(nums = [1, 2, 1, 2]) == 1\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 3\n assert candidate(nums = [2, 1, 3, 3, 2]) == 2\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1, 1, 2, 2]) == 8\n assert candidate(nums = [3, 2, 1, 4, 3, 2, 1, 5, 3, 2, 1, 6, 3, 2, 1, 7, 3, 2, 1, 8]) == 2\n assert candidate(nums = [5, 6, 5, 7, 5, 8, 5, 9, 5, 10]) == 1\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1]) == 3\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1, 1]) == 8\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 15\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 1\n assert candidate(nums = [100, 99, 100, 98, 100, 97, 100, 96, 100, 95, 100, 94, 100, 93, 100]) == 1\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1]) == 2\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10, 7, 7]) == 3\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 1, 1, 1]) == 8\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2]) == 3\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 1, 2, 2, 1, 4, 4, 4, 4, 1, 2, 2, 1]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 5\n assert candidate(nums = [8, 9, 8, 10, 8, 11, 8, 12, 8, 13, 8, 14, 8, 15, 8, 16, 8, 17, 8, 18]) == 1\n assert candidate(nums = [6, 6, 6, 6, 5, 5, 5, 5, 6, 6, 6, 6, 5, 5, 5, 5, 6, 6, 6, 6]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 2\n assert candidate(nums = [9, 1, 9, 2, 9, 3, 9, 4, 9, 5, 9, 6, 9, 7, 9, 8]) == 1\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\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 1]) == 5\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 9\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 4\n assert candidate(nums = [6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6]) == 1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3]) == 3\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7]) == 1\n assert candidate(nums = [7, 7, 1, 7, 7, 7, 7, 1, 7]) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1, 1, 2]) == 8\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5]) == 1\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1]) == 2\n assert candidate(nums = [8, 8, 8, 7, 8, 8, 8, 7, 8, 8, 8, 7, 8, 8, 8]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\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]) == 10\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300, 100, 200, 300]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000]) == 1\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5]) == 1\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]) == 12\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]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 7\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]) == 5\n assert candidate(nums = [7, 5, 3, 5, 7, 5, 3, 5]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 3\n assert candidate(nums = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\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, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 5\n assert candidate(nums = [5, 1, 4, 1, 5, 1, 4, 5, 4, 5]) == 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]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 4\n assert candidate(nums = [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]) == 4\n assert candidate(nums = [1000000000, 999999999, 1000000000, 999999999, 1000000000]) == 1\n assert candidate(nums = [10, 20, 10, 30, 20, 10, 30, 20, 10]) == 1\n assert candidate(nums = [10, 1, 10, 2, 10, 3, 10, 4, 10, 5]) == 1\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 10, 10]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 5\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 8\n assert candidate(nums = [5, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7, 8, 9]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5]) == 7\n assert candidate(nums = [7, 2, 2, 7, 3, 7, 3, 3]) == 1\n assert candidate(nums = [7, 1, 5, 3, 6, 1, 5, 3, 6, 1, 5, 3, 6]) == 2\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9]) == 1\n assert candidate(nums = [9, 9, 1, 9, 9, 1, 9, 9, 1, 9, 9]) == 1\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 2\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,2,1,2]", "[2,1,3,3,2]", "[5,5,5,5]"], "hints": ["For every possible x - the final value of the array, calculate the number of seconds needed to make all elements equal to x.", "Notice that if you take two consecutive occurrences (i, j) of x, then the number of operations to make segment [i + 1, j - 1] equal to x is floor((j - i) / 2)"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumSeconds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:42+00:00", "tests_total": 116, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_seconds(nums)", "container": null, "callable": "minimum_seconds", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2809, "task_id": "minimum-time-to-make-array-sum-at-most-x", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:\n\n- Choose an index 0 <= i < nums1.length and make nums1[i] = 0.\n\nYou are also given an integer x.\n\nReturn the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.\n\nExample 1:\n\nInput: nums1 = [1,2,3], nums2 = [1,2,3], x = 4\nOutput: 3\nExplanation:\nFor the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6].\nFor the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9].\nFor the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0].\nNow sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.\n\nExample 2:\n\nInput: nums1 = [1,2,3], nums2 = [3,3,3], x = 4\nOutput: -1\nExplanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.\n\nConstraints:\n\n- 1 <= nums1.length <= 10^3\n- 1 <= nums1[i] <= 10^3\n- 0 <= nums2[i] <= 10^3\n- nums1.length == nums2.length\n- 0 <= x <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3],nums2 = [1, 2, 3],x = 4) == 3\n assert candidate(nums1 = [5, 3, 8],nums2 = [2, 1, 4],x = 15) == 1\n assert candidate(nums1 = [5, 5, 5],nums2 = [1, 1, 1],x = 15) == 0\n assert candidate(nums1 = [10, 10, 10],nums2 = [0, 0, 0],x = 30) == 0\n assert candidate(nums1 = [1, 1, 1],nums2 = [0, 0, 0],x = 0) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],x = 25) == 0\n assert candidate(nums1 = [100, 200, 300],nums2 = [10, 20, 30],x = 1000) == 0\n assert candidate(nums1 = [3, 3, 3],nums2 = [1, 2, 3],x = 10) == 0\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 3, 3],x = 4) == -1\n assert candidate(nums1 = [10, 20, 30],nums2 = [0, 0, 0],x = 15) == 2\n assert candidate(nums1 = [100, 200],nums2 = [50, 100],x = 1000) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [0, 0, 0],x = 10) == 2\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],x = 10) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2],x = 10) == 0\n assert candidate(nums1 = [2, 4, 6],nums2 = [1, 1, 1],x = 12) == 0\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [1, 2, 3, 4],x = 100) == 0\n assert candidate(nums1 = [5, 3, 1],nums2 = [2, 1, 3],x = 10) == 0\n assert candidate(nums1 = [7, 5, 3],nums2 = [2, 4, 6],x = 20) == 0\n assert candidate(nums1 = [1, 2],nums2 = [3, 4],x = 5) == 0\n assert candidate(nums1 = [3, 2, 1],nums2 = [1, 1, 1],x = 5) == 1\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],x = 25) == 0\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],x = 4) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],x = 150) == 0\n assert candidate(nums1 = [1, 1, 1],nums2 = [1, 1, 1],x = 1) == -1\n assert candidate(nums1 = [3, 3, 3],nums2 = [1, 1, 1],x = 5) == 3\n assert candidate(nums1 = [999, 998, 997, 996, 995],nums2 = [1, 2, 3, 4, 5],x = 4500) == 1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [5, 5, 5, 5, 5],x = 5) == 0\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [0, 0, 0, 0],x = 1000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 5) == -1\n assert candidate(nums1 = [10, 20, 30],nums2 = [1, 2, 3],x = 50) == 1\n assert candidate(nums1 = [10, 20, 30],nums2 = [0, 0, 0],x = 15) == 2\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 5000) == 1\n assert candidate(nums1 = [10, 20, 30],nums2 = [1, 2, 3],x = 60) == 0\n assert candidate(nums1 = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 50) == 10\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],x = 4) == 0\n assert candidate(nums1 = [1, 10, 100, 1000],nums2 = [1000, 100, 10, 1],x = 2000) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [9, 7, 5, 3, 1],x = 20) == -1\n assert candidate(nums1 = [50, 100, 150, 200],nums2 = [1, 2, 3, 4],x = 300) == 2\n assert candidate(nums1 = [1000, 1000, 1000],nums2 = [1, 1, 1],x = 2500) == 1\n assert candidate(nums1 = [10, 10, 10, 10, 10],nums2 = [5, 5, 5, 5, 5],x = 25) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 550) == 0\n assert candidate(nums1 = [10, 10, 10, 10],nums2 = [1, 2, 3, 4],x = 30) == 2\n assert candidate(nums1 = [5, 10, 15, 20],nums2 = [1, 1, 1, 1],x = 15) == 3\n assert candidate(nums1 = [5, 15, 25, 35, 45],nums2 = [1, 1, 1, 1, 1],x = 50) == 3\n assert candidate(nums1 = [999, 998, 997, 996, 995],nums2 = [1, 2, 3, 4, 5],x = 5000) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [10, 20, 30, 40, 50],x = 100) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 100) == 0\n assert candidate(nums1 = [100, 200, 300],nums2 = [10, 20, 30],x = 1500) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],x = 5) == 0\n assert candidate(nums1 = [500, 500, 500],nums2 = [1, 1, 1],x = 1000) == 2\n assert candidate(nums1 = [1000, 1000, 1000, 1000, 1000],nums2 = [1000, 1000, 1000, 1000, 1000],x = 5000) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 1, 1, 1, 1],x = 5) == -1\n assert candidate(nums1 = [3, 6, 9],nums2 = [2, 4, 6],x = 20) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [9, 8, 7, 6, 5],x = 10) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 100) == -1\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],x = 0) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 55) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 50) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],x = 200) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [5, 4, 3, 2, 1],x = 5) == 0\n assert candidate(nums1 = [1000, 500, 250, 125, 62, 31],nums2 = [62, 31, 15, 7, 3, 1],x = 2000) == 0\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [1, 2, 3, 4, 5],x = 100) == 0\n assert candidate(nums1 = [100, 200, 300],nums2 = [10, 20, 30],x = 1000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10) == 0\n assert candidate(nums1 = [5, 10, 15, 20],nums2 = [2, 4, 6, 8],x = 50) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [0, 0, 0, 0, 0],x = 15) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 5000) == 0\n assert candidate(nums1 = [100, 100, 100],nums2 = [50, 50, 50],x = 300) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],x = 550) == 0\n assert candidate(nums1 = [100, 200, 300],nums2 = [0, 0, 0],x = 150) == 2\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [0, 0, 0, 0, 0],x = 50) == 3\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [5, 4, 3, 2, 1],x = 50) == 3\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [1, 2, 3, 4],x = 500) == 2\n assert candidate(nums1 = [9, 9, 9, 9],nums2 = [1, 2, 3, 4],x = 50) == 0\n assert candidate(nums1 = [1000, 1000, 1000],nums2 = [1000, 1000, 1000],x = 3000) == 0\n assert candidate(nums1 = [100, 150, 200, 250, 300],nums2 = [5, 10, 15, 20, 25],x = 2000) == 0\n assert candidate(nums1 = [999, 999, 999],nums2 = [1000, 1000, 1000],x = 2997) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 55) == 0\n assert candidate(nums1 = [9, 8, 7, 6, 5],nums2 = [0, 1, 2, 3, 4],x = 30) == 3\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],x = 50) == 3\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5],x = 15) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 600) == 0\n assert candidate(nums1 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5500) == 0\n assert candidate(nums1 = [50, 50, 50, 50],nums2 = [0, 0, 0, 0],x = 150) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],x = 20) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 4, 3, 2, 1],x = 100) == 2\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 0, 0],x = 30) == 2\n assert candidate(nums1 = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],x = 10000) == 0\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [1, 2, 3, 4],x = 100) == 0\n assert candidate(nums1 = [10, 10, 10, 10, 10],nums2 = [0, 0, 0, 0, 0],x = 10) == 4\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 2, 3, 4, 5],x = 1500) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 4, 3, 2, 1],x = 150) == 0\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [1, 3, 5, 7, 9],x = 50) == 0\n assert candidate(nums1 = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5000) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [0, 0, 0, 0, 0],x = 150) == 0\n assert candidate(nums1 = [500, 500, 500, 500, 500],nums2 = [0, 1, 2, 3, 4],x = 2000) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],x = 50) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [0, 0, 0, 0, 1000],x = 1500) == 0\n assert candidate(nums1 = [50, 40, 30, 20, 10],nums2 = [1, 2, 3, 4, 5],x = 150) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 5, 5, 5, 5],x = 200) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 100) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 55) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [100, 100, 100, 100, 100],x = 500) == 0\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [1, 1, 1, 1, 1],x = 50) == 2\n assert candidate(nums1 = [100, 200, 300],nums2 = [5, 10, 15],x = 600) == 0\n assert candidate(nums1 = [999, 999, 999],nums2 = [1, 1, 1],x = 2995) == 1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 500) == 1\n assert candidate(nums1 = [100, 200, 300],nums2 = [5, 10, 15],x = 500) == 1\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9],x = 45) == 0\n assert candidate(nums1 = [7, 14, 21, 28],nums2 = [1, 1, 1, 1],x = 50) == 1\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 1, 1, 1, 1],x = 1500) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n[1,2,3]\n4", "[1,2,3]\n[3,3,3]\n4"], "hints": ["It can be proven that in the optimal solution, for each index i, we only need to set nums1[i] to 0 at most once. (If we have to set it twice, we can simply remove the earlier set and all the operations “shift left” by 1.)", "It can also be proven that if we select several indexes i_1, i_2, ..., i_k and set nums1[i_1], nums1[i_2], ..., nums1[i_k] to 0, it’s always optimal to set them in the order of nums2[i_1] <= nums2[i_2] <= ... <= nums2[i_k] (the larger the increase is, the later we should set it to 0).", "Let’s sort all the values by nums2 (in non-decreasing order). Let dp[i][j] represent the maximum total value that can be reduced if we do j operations on the first i elements. Then we have dp[i][0] = 0 (for all i = 0, 1, ..., n) and dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1] + nums2[i - 1] * j + nums1[i - 1]) (for 1 <= i <= n and 1 <= j <= i).", "The answer is the minimum value of t, such that 0 <= t <= n and sum(nums1) + sum(nums2) * t - dp[n][t] <= x, or -1 if it doesn’t exist."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "x"], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:45+00:00", "tests_total": 111, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_time(nums1, nums2, x)", "container": null, "callable": "minimum_time", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2810, "task_id": "faulty-keyboard", "difficulty": "Easy", "problem_description": "Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.\n\nYou are given a 0-indexed string s, and you type each character of s using your faulty keyboard.\n\nReturn the final string that will be present on your laptop screen.\n\nExample 1:\n\nInput: s = \"string\"\nOutput: \"rtsng\"\nExplanation:\nAfter typing first character, the text on the screen is \"s\".\nAfter the second character, the text is \"st\".\nAfter the third character, the text is \"str\".\nSince the fourth character is an 'i', the text gets reversed and becomes \"rts\".\nAfter the fifth character, the text is \"rtsn\".\nAfter the sixth character, the text is \"rtsng\".\nTherefore, we return \"rtsng\".\n\nExample 2:\n\nInput: s = \"poiinter\"\nOutput: \"ponter\"\nExplanation:\nAfter the first character, the text on the screen is \"p\".\nAfter the second character, the text is \"po\".\nSince the third character you type is an 'i', the text gets reversed and becomes \"op\".\nSince the fourth character you type is an 'i', the text gets reversed and becomes \"po\".\nAfter the fifth character, the text is \"pon\".\nAfter the sixth character, the text is \"pont\".\nAfter the seventh character, the text is \"ponte\".\nAfter the eighth character, the text is \"ponter\".\nTherefore, we return \"ponter\".\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists of lowercase English letters.\n- s[0] != 'i'\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"string\") == \"rtsng\"\n assert candidate(s = \"aibcdie\") == \"dcbae\"\n assert candidate(s = \"noicanoati\") == \"taonacno\"\n assert candidate(s = \"abcide\") == \"cbade\"\n assert candidate(s = \"poiinter\") == \"ponter\"\n assert candidate(s = \"abcidifgh\") == \"dabcfgh\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"abcdefghi\") == \"hgfedcba\"\n assert candidate(s = \"lowihello\") == \"wolhello\"\n assert candidate(s = \"abci\") == \"cba\"\n assert candidate(s = \"aibiciici\") == \"ccab\"\n assert candidate(s = \"abcidiefgh\") == \"dabcefgh\"\n assert candidate(s = \"exampleistring\") == \"rtsexampleng\"\n assert candidate(s = \"abc\") == \"abc\"\n assert candidate(s = \"abcdefgh\") == \"abcdefgh\"\n assert candidate(s = \"aibici\") == \"cab\"\n assert candidate(s = \"abcidefghi\") == \"hgfedabc\"\n assert candidate(s = \"noiidea\") == \"nodea\"\n assert candidate(s = \"abcdefghij\") == \"hgfedcbaj\"\n assert candidate(s = \"abcdei\") == \"edcba\"\n assert candidate(s = \"thisisateststringwithmanyireversals\") == \"ynamhtrtstsetashtsngwreversals\"\n assert candidate(s = \"abcdefghiihgfedcbaabcdeffedcba\") == \"abcdefghhgfedcbaabcdeffedcba\"\n assert candidate(s = \"complexityiincreasesiiwithiiireversals\") == \"htxelpmoctyncreaseswreversals\"\n assert candidate(s = \"floccinaucinihilipilification\") == \"tacllnccolfnauchpfon\"\n assert candidate(s = \"startwithiinthemiddle\") == \"mehtnhtstartwddle\"\n assert candidate(s = \"softwaredevelopmentiitheory\") == \"softwaredevelopmenttheory\"\n assert candidate(s = \"palindromelevel\") == \"lapndromelevel\"\n assert candidate(s = \"endwithiiiiiiiiiiiiiiiiii\") == \"wdneth\"\n assert candidate(s = \"nestedireversalsiiii\") == \"detsenreversals\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydogi\") == \"godyzalehtrevospmujxofnworbkcaqu\"\n assert candidate(s = \"abracadabra\") == \"abracadabra\"\n assert candidate(s = \"pythonprogramming\") == \"mmargorpnohtypng\"\n assert candidate(s = \"programmingiisfun\") == \"mmargorpngsfun\"\n assert candidate(s = \"xylophoneix\") == \"enohpolyxx\"\n assert candidate(s = \"longstringwithseveralireversalsandmorecharacters\") == \"lareveshtrtsgnolngwreversalsandmorecharacters\"\n assert candidate(s = \"trickytongueiishere\") == \"rtckytongueshere\"\n assert candidate(s = \"randomcharacterswithiabcdefghijklmnopqrstuvwxyz\") == \"hgfedcbawsretcarahcmodnarthjklmnopqrstuvwxyz\"\n assert candidate(s = \"longstringwithnointerference\") == \"onhtrtsgnolngwnterference\"\n assert candidate(s = \"singleireversal\") == \"elgnsreversal\"\n assert candidate(s = \"datastructuresiiialgorithms\") == \"rogladatastructuresthms\"\n assert candidate(s = \"thisisaverylongstringthatneedstobechecked\") == \"rtsgnolyrevashtsngthatneedstobechecked\"\n assert candidate(s = \"algorithmisawesome\") == \"mhtalgorsawesome\"\n assert candidate(s = \"almostdone\") == \"almostdone\"\n assert candidate(s = \"racecariispeedoomeokarttercecar\") == \"racecarspeedoomeokarttercecar\"\n assert candidate(s = \"reverseiiiandthencontinue\") == \"tnocnehtdnareversenue\"\n assert candidate(s = \"abcdefghijiiiiiiiiiiiiiijklmnopqrstuvwxyz\") == \"hgfedcbajjklmnopqrstuvwxyz\"\n assert candidate(s = \"algorithmiiengineering\") == \"reenroglathmengng\"\n assert candidate(s = \"xylophoneiikeyboard\") == \"xylophonekeyboard\"\n assert candidate(s = \"almostmiintrandomiisequence\") == \"almostmntrandomsequence\"\n assert candidate(s = \"aaaaaaaaaaibbbbbbbbbaaaaaaaaaa\") == \"aaaaaaaaaabbbbbbbbbaaaaaaaaaa\"\n assert candidate(s = \"algorithm\") == \"roglathm\"\n assert candidate(s = \"simpletestcase\") == \"smpletestcase\"\n assert candidate(s = \"aaaaabbbbccccdddd\") == \"aaaaabbbbccccdddd\"\n assert candidate(s = \"redder\") == \"redder\"\n assert candidate(s = \"reverseeveryithirdcharacter\") == \"htreverseeveryrdcharacter\"\n assert candidate(s = \"supercalifragilisticexpialidocious\") == \"codpxecllacrepusfragstalous\"\n assert candidate(s = \"abcdefghiijklmnopqrstuvwxyz\") == \"abcdefghjklmnopqrstuvwxyz\"\n assert candidate(s = \"nestedreversalsiiinesting\") == \"tsennestedreversalsng\"\n assert candidate(s = \"onetwothreefourfiveisixseveneightnine\") == \"nthgsfruofeerhtowtenovexsevenene\"\n assert candidate(s = \"withmultipleis\") == \"elpwthmults\"\n assert candidate(s = \"nestedintegers\") == \"detsenntegers\"\n assert candidate(s = \"reversal\") == \"reversal\"\n assert candidate(s = \"reversingireversibility\") == \"lsreversreverngbty\"\n assert candidate(s = \"abcdefghiiiiiiiiiijklmnopqrstuvwxyz\") == \"abcdefghjklmnopqrstuvwxyz\"\n assert candidate(s = \"sequenceofireversalsii\") == \"foecneuqesreversals\"\n assert candidate(s = \"abcdefghijiklmnopqrstuvwxyziiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiijklmnopqrstuvwxyz\") == \"jabcdefghklmnopqrstuvwxyzjklmnopqrstuvwxyz\"\n assert candidate(s = \"thisstringhasiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiinside\") == \"snsahgnhtsstrde\"\n assert candidate(s = \"abcdefghijiklmnopqrstuvwxyz\") == \"jabcdefghklmnopqrstuvwxyz\"\n assert candidate(s = \"twofour\") == \"twofour\"\n assert candidate(s = \"aiaiaiaiaiaiaiai\") == \"aaaaaaaa\"\n assert candidate(s = \"reverseeveryiinthisstring\") == \"rtssreverseeverynthng\"\n assert candidate(s = \"complexityincreaseswithmoreireversals\") == \"eromhtytcomplexncreaseswreversals\"\n assert candidate(s = \"thisisnotsoeasyasitis\") == \"tsthsnotsoeasyass\"\n assert candidate(s = \"nnnnmmmmlllkkkjjjiiihgfedcbaiiijjkkllmmnn\") == \"abcdefghnnnnmmmmlllkkkjjjjjkkllmmnn\"\n assert candidate(s = \"faultykeyboardstests\") == \"faultykeyboardstests\"\n assert candidate(s = \"onlyonei\") == \"enoylno\"\n assert candidate(s = \"specialcharactersarefun\") == \"cepsalcharactersarefun\"\n assert candidate(s = \"mississippiii\") == \"ppssmss\"\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == \"hhhgggfffeeedddcccbbbaaajjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\"\n assert candidate(s = \"thisisaverylongstringthatwilltestthealgorithm\") == \"roglaehttsetllrtsgnolyrevashtsngthatwthm\"\n assert candidate(s = \"singleiiiiiiiiiii\") == \"elgns\"\n assert candidate(s = \"aibohphobia\") == \"bohphobaa\"\n assert candidate(s = \"aaaaaaaaiiiiiii\") == \"aaaaaaaa\"\n assert candidate(s = \"debuggingiiibugs\") == \"gndebuggbugs\"\n assert candidate(s = \"complexstringwithmultipleiiiiinversions\") == \"srevntlumhtrtsxelpmocngwpleons\"\n assert candidate(s = \"level\") == \"level\"\n assert candidate(s = \"thisisaverylongstringwithmultipleireversals\") == \"elpwgnsthsaverylongstrthmultreversals\"\n assert candidate(s = \"backtothebeginning\") == \"nnbacktothebegng\"\n assert candidate(s = \"mixedwithiandothercharacters\") == \"htmxedwandothercharacters\"\n assert candidate(s = \"aibohphobiai\") == \"aabohphob\"\n assert candidate(s = \"complexityiiis\") == \"ytcomplexs\"\n assert candidate(s = \"almostdoneii\") == \"almostdone\"\n assert candidate(s = \"mississippiiiiii\") == \"ssmsspp\"\n assert candidate(s = \"aaaaabbbbccccddddiiii\") == \"aaaaabbbbccccdddd\"\n assert candidate(s = \"abcdefghiihgfedcbaiiijjkkllmmnn\") == \"abcdefghhgfedcbajjkkllmmnn\"\n assert candidate(s = \"abcdefghiabcdefghi\") == \"hgfedcbaabcdefgh\"\n assert candidate(s = \"bananaananab\") == \"bananaananab\"\n assert candidate(s = \"congratulations\") == \"talutargnocons\"\n assert candidate(s = \"nointerruptshere\") == \"onnterruptshere\"\n assert candidate(s = \"endwithiiiiireversal\") == \"htendwreversal\"\n assert candidate(s = \"abcdefghijkilmnopqrstuvwtuvrqpomnlijkihgfedcba\") == \"kjkjabcdefghlmnopqrstuvwtuvrqpomnlhgfedcba\"\n assert candidate(s = \"complexstringwithiiiiiiiiiii\") == \"htrtsxelpmocngw\"\n assert candidate(s = \"mammaiamamma\") == \"ammamamamma\"\n assert candidate(s = \"reversethisplease\") == \"htesreversplease\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydogii\") == \"uqackbrownfoxjumpsoverthelazydog\"\n assert candidate(s = \"multipleiiireversalsinbetween\") == \"slasrevertlumplenbetween\"\n assert candidate(s = \"multipeiiiiiinsersions\") == \"sresnepmultons\"\n assert candidate(s = \"performanceiiioptimization\") == \"taztpoperformancemon\"\n assert candidate(s = \"endingwithi\") == \"htdnengw\"\n assert candidate(s = \"noireversals\") == \"onreversals\"\n assert candidate(s = \"reversalsarefun\") == \"reversalsarefun\"\n assert candidate(s = \"sequenceiiwithiiiiiiiiiinterspersediiiis\") == \"wecneuqesthntersperseds\"\n assert candidate(s = \"mixandmatchi\") == \"hctamdnaxm\"\n assert candidate(s = \"programmingii\") == \"mmargorpng\"\n assert candidate(s = \"multipleiiiiireversals\") == \"elpmultreversals\"\n assert candidate(s = \"thisisaverylongstringwithoutianyireversals\") == \"ynawgnsthsaverylongstrthoutreversals\"\n assert candidate(s = \"xyzzzyxzyzyzyzzyxzyzyzyz\") == \"xyzzzyxzyzyzyzzyxzyzyzyz\"\n assert candidate(s = \"verylongstringwithrandomcharactersandiiiiiiiiiintersions\") == \"sretndnasretcarahcmodnarhtrtsgnolyrevngwons\"\n assert candidate(s = \"thisisaverylongstringwithmanyireversals\") == \"ynamhtrtsgnolyrevashtsngwreversals\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aabbccddeeffgghhjjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"abcdefghiiihgfedcbaiiijjkkllmmnniiihgfedcba\") == \"nnmmllkkjjhgfedcbahgfedcbahgfedcba\"\n assert candidate(s = \"oneletter\") == \"oneletter\"\n assert candidate(s = \"nestedinversionexampleiiii\") == \"srevnnestedonexample\"\n assert candidate(s = \"deified\") == \"fdeed\"\n assert candidate(s = \"abcdefghiijiklmnopqrstuvwxyz\") == \"jhgfedcbaklmnopqrstuvwxyz\"\n assert candidate(s = \"thisisaverylongstringwithsomeireversalsintheend\") == \"slasreverwgnsthsaverylongstrthsomentheend\"\n assert candidate(s = \"programmingchallengesarefun\") == \"mmargorpngchallengesarefun\"\n assert candidate(s = \"nolemonnomelon\") == \"nolemonnomelon\"\n assert candidate(s = \"nestediinici\") == \"cnestedn\"\n assert candidate(s = \"continuousintegration\") == \"targetntnocnuouson\"\n assert candidate(s = \"racecar\") == \"racecar\"\n assert candidate(s = \"abracaicabracai\") == \"acarbacabraca\"\n assert candidate(s = \"quickbrownfoxjumpsovertheilazydog\") == \"ehtrevospmujxofnworbkcqulazydog\"\n assert candidate(s = \"abcdefghiihgfedcba\") == \"abcdefghhgfedcba\"\n assert candidate(s = \"abcdefghiihgfedcbaabcdefghiihgfedcba\") == \"abcdefghhgfedcbaabcdefghhgfedcba\"\n assert candidate(s = \"nestedinversionswithinstrings\") == \"rtsnwsnodetsennversthngs\"\n assert candidate(s = \"thisisatestoftheinputstring\") == \"rtstupnsthsatestoftheng\"\n assert candidate(s = \"mississippi\") == \"ppssmss\"\n assert candidate(s = \"shortiiilong\") == \"trohslong\"\n assert candidate(s = \"reversemeifoundyou\") == \"emesreverfoundyou\"\n assert candidate(s = \"reversethisstring\") == \"rtssreversethng\"\n", "comparison": "exact"}, "public_tests": ["\"string\"", "\"poiinter\""], "hints": ["Try to build a new string by traversing the given string and reversing whenever you get the character ‘i’."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().finalString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:47+00:00", "tests_total": 171, "tests_dropped": 30, "flags": [], "topic_tags": ["string", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def final_string(s)", "container": null, "callable": "final_string", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2811, "task_id": "check-if-it-is-possible-to-split-array", "difficulty": "Medium", "problem_description": "You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n arrays of size 1 by performing a series of steps.\n\nAn array is called good if:\n\n- The length of the array is one, or\n- The sum of the elements of the array is greater than or equal to m.\n\nIn each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two arrays, if both resulting arrays are good.\n\nReturn true if you can split the given array into n arrays, otherwise return false.\n\nExample 1:\n\nInput: nums = [2, 2, 1], m = 4\nOutput: true\nExplanation:\n- Split [2, 2, 1] to [2, 2] and [1]. The array [1] has a length of one, and the array [2, 2] has the sum of its elements equal to 4 >= m, so both are good arrays.\n- Split [2, 2] to [2] and [2]. both arrays have the length of one, so both are good arrays.\n\nExample 2:\n\nInput: nums = [2, 1, 3], m = 5\nOutput: false\nExplanation:\nThe first move has to be either of the following:\n- Split [2, 1, 3] to [2, 1] and [3]. The array [2, 1] has neither length of one nor sum of elements greater than or equal to m.\n- Split [2, 1, 3] to [2] and [1, 3]. The array [1, 3] has neither length of one nor sum of elements greater than or equal to m.\n\nSo as both moves are invalid (they do not divide the array into two good arrays), we are unable to split nums into n arrays of size 1.\n\nExample 3:\n\nInput: nums = [2, 3, 3, 2, 3], m = 6\nOutput: true\nExplanation:\n- Split [2, 3, 3, 2, 3] to [2] and [3, 3, 2, 3].\n- Split [3, 3, 2, 3] to [3, 3, 2] and [3].\n- Split [3, 3, 2] to [3, 3] and [2].\n- Split [3, 3] to [3] and [3].\n\nConstraints:\n\n- 1 <= n == nums.length <= 100\n- 1 <= nums[i] <= 100\n- 1 <= m <= 200\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40],m = 50) == True\n assert candidate(nums = [2, 3, 3, 2, 3],m = 6) == True\n assert candidate(nums = [50, 50],m = 100) == True\n assert candidate(nums = [1, 2, 3, 4, 5],m = 9) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1],m = 2) == True\n assert candidate(nums = [2, 1, 3],m = 5) == False\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],m = 20) == True\n assert candidate(nums = [1, 2, 3, 4, 5],m = 10) == False\n assert candidate(nums = [1, 1, 1, 1],m = 2) == True\n assert candidate(nums = [100, 100],m = 150) == True\n assert candidate(nums = [10, 20, 30, 40, 50],m = 60) == True\n assert candidate(nums = [1, 100, 1, 1, 1],m = 101) == True\n assert candidate(nums = [2, 2, 1],m = 4) == True\n assert candidate(nums = [50, 50, 50, 50],m = 100) == True\n assert candidate(nums = [100, 100, 100],m = 200) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 15) == True\n assert candidate(nums = [100],m = 100) == True\n assert candidate(nums = [5, 5, 5, 5, 5],m = 10) == True\n assert candidate(nums = [50, 50, 50],m = 100) == True\n assert candidate(nums = [1, 1, 1, 1, 1],m = 2) == True\n assert candidate(nums = [5, 5, 5, 5, 5],m = 15) == False\n assert candidate(nums = [10, 20, 30],m = 15) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 10) == True\n assert candidate(nums = [10, 20, 30, 40],m = 35) == True\n assert candidate(nums = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 102) == False\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],m = 10) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 35) == True\n assert candidate(nums = [90, 10, 10, 10, 10, 10, 10, 10, 10, 10],m = 20) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 2) == True\n assert candidate(nums = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 101) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],m = 25) == True\n assert candidate(nums = [33, 33, 34, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33],m = 66) == True\n assert candidate(nums = [50, 40, 30, 20, 10, 15, 25, 35, 45, 55],m = 75) == True\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],m = 10) == True\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],m = 30) == True\n assert candidate(nums = [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, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],m = 3) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 25) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],m = 5) == False\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],m = 5) == True\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],m = 2) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],m = 99) == True\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100],m = 101) == True\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],m = 180) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 180) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 10) == True\n assert candidate(nums = [99, 1, 99, 1, 99, 1, 99, 1, 99],m = 198) == False\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],m = 10) == True\n assert candidate(nums = [5, 15, 10, 20, 25, 30, 35, 40, 45, 50],m = 60) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 30) == True\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],m = 190) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 100) == True\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],m = 30) == True\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],m = 2) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 9) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],m = 100) == True\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],m = 99) == True\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],m = 50) == True\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, 3],m = 6) == True\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],m = 55) == True\n assert candidate(nums = [99, 1, 99, 1, 99, 1, 99, 1, 99, 1],m = 198) == False\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],m = 3) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 20) == True\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],m = 200) == True\n assert candidate(nums = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100],m = 140) == True\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5],m = 60) == True\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],m = 5) == True\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],m = 30) == True\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5],m = 100) == True\n assert candidate(nums = [99, 1, 99, 1, 99, 1, 99, 1, 99, 1],m = 100) == True\n assert candidate(nums = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 101) == True\n assert candidate(nums = [99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99],m = 100) == True\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],m = 3) == True\n assert candidate(nums = [50, 50, 1, 50, 50, 1, 50, 50, 1, 50, 50, 1, 50, 50, 1, 50, 50, 1, 50, 50],m = 99) == True\n assert candidate(nums = [10, 20, 10, 20, 10],m = 20) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],m = 4) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 18) == True\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],m = 10) == True\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30],m = 60) == True\n assert candidate(nums = [50, 25, 25, 50, 25, 25, 50],m = 75) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],m = 100) == True\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],m = 2) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 25) == True\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],m = 2) == True\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],m = 10) == True\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],m = 199) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],m = 10) == True\n assert candidate(nums = [99, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 99],m = 199) == False\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],m = 39) == True\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],m = 5) == True\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70],m = 50) == True\n assert candidate(nums = [20, 10, 10, 30, 20, 10, 10, 40, 30, 10],m = 35) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],m = 99) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],m = 100) == True\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],m = 20) == True\n assert candidate(nums = [100, 1, 1, 1, 100],m = 101) == True\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],m = 2) == True\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],m = 199) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 150) == True\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20],m = 30) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 20) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 200) == False\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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100],m = 150) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 190) == True\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],m = 9) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 15) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],m = 30) == True\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],m = 190) == True\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, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50],m = 115) == True\n", "comparison": "exact"}, "public_tests": ["[2, 2, 1]\n4", "[2, 1, 3]\n5", "[2, 3, 3, 2, 3]\n6"], "hints": ["It can be proven that if you can split more than one element as a subarray, then you can split exactly one element."], "metadata": {"canonical_parameter_names": ["nums", "m"], "leetcode_dataset_entry_point": "Solution().canSplitArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:49+00:00", "tests_total": 113, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def can_split_array(nums, m)", "container": null, "callable": "can_split_array", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "m", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2812, "task_id": "find-the-safest-path-in-a-grid", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:\n\n- A cell containing a thief if grid[r][c] = 1\n- An empty cell if grid[r][c] = 0\n\nYou are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.\n\nThe safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.\n\nReturn the maximum safeness factor of all paths leading to cell (n - 1, n - 1).\n\nAn adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.\n\nThe Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.\n\nExample 1:\n\nInput: grid = [[1,0,0],[0,0,0],[0,0,1]]\nOutput: 0\nExplanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).\n\nExample 2:\n\nInput: grid = [[0,0,1],[0,0,0],[0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.\n\nExample 3:\n\nInput: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.\n- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.\n\nConstraints:\n\n- 1 <= grid.length == n <= 400\n- grid[i].length == n\n- grid[i][j] is either 0 or 1.\n- There is at least one thief in the grid.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 0, 1], [0, 0, 0], [0, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 0], [0, 0, 0], [0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 1], [0, 0, 0], [1, 0, 1]]) == 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, 1, 0, 0, 0, 1, 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, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 11\n assert candidate(grid = [[0, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0]]) == 1\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, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0]]) == 7\n assert candidate(grid = [[0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 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, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 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]]) == 4\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1]]) == 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, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 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, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 15\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 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, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 2\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, 1, 0, 0, 0, 1, 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, 1, 0, 0, 0, 1, 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]]) == 3\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0]]) == 6\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], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 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, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1]]) == 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, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 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, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 1, 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], [1, 0, 0, 0, 0, 0, 0, 0, 1], [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, 1, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 1, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 1, 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, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 1], [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], [1, 0, 0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[0, 0, 0, 0, 1, 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], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 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, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 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, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\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], [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, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]]) == 4\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0]]) == 2\n", "comparison": "exact"}, "public_tests": ["[[1,0,0],[0,0,0],[0,0,1]]", "[[0,0,1],[0,0,0],[0,0,0]]", "[[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]"], "hints": ["Consider using both BFS and binary search together.", "Launch a BFS starting from all the cells containing thieves to calculate d[x][y] which is the smallest Manhattan distance from (x, y) to the nearest grid that contains thieves.", "To check if the bottom-right cell of the grid can be reached through a path of safeness factor v, eliminate all cells (x, y) such that grid[x][y] < v. if (0, 0) and (n - 1, n - 1) are still connected, there exists a path between (0, 0) and (n - 1, n - 1) of safeness factor v.", "Binary search over the final safeness factor v."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maximumSafenessFactor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:51+00:00", "tests_total": 66, "tests_dropped": 1, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "binary-search", "breadth-first-search", "union-find", "heap-priority-queue", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_safeness_factor(grid)", "container": null, "callable": "maximum_safeness_factor", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2813, "task_id": "maximum-elegance-of-a-k-length-subsequence", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array items of length n and an integer k.\n\nitems[i] = [profit_i, category_i], where profit_i and category_i denote the profit and category of the i^th item respectively.\n\nLet's define the elegance of a subsequence of items as total_profit + distinct_categories^2, where total_profit is the sum of all profits in the subsequence, and distinct_categories is the number of distinct categories from all the categories in the selected subsequence.\n\nYour task is to find the maximum elegance from all subsequences of size k in items.\n\nReturn an integer denoting the maximum elegance of a subsequence of items with size exactly k.\n\nNote: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.\n\nExample 1:\n\nInput: items = [[3,2],[5,1],[10,1]], k = 2\nOutput: 17\nExplanation: In this example, we have to select a subsequence of size 2.\nWe can select items[0] = [3,2] and items[2] = [10,1].\nThe total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].\nHence, the elegance is 13 + 2^2 = 17, and we can show that it is the maximum achievable elegance.\n\nExample 2:\n\nInput: items = [[3,1],[3,1],[2,2],[5,3]], k = 3\nOutput: 19\nExplanation: In this example, we have to select a subsequence of size 3.\nWe can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3].\nThe total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3].\nHence, the elegance is 10 + 3^2 = 19, and we can show that it is the maximum achievable elegance.\n\nExample 3:\n\nInput: items = [[1,1],[2,1],[3,1]], k = 3\nOutput: 7\nExplanation: In this example, we have to select a subsequence of size 3.\nWe should select all the items.\nThe total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1].\nHence, the maximum elegance is 6 + 1^2 = 7.\n\nConstraints:\n\n- 1 <= items.length == n <= 10^5\n- items[i].length == 2\n- items[i][0] == profit_i\n- items[i][1] == category_i\n- 1 <= profit_i <= 10^9\n- 1 <= category_i <= n\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(items = [[10, 1], [9, 1], [8, 1], [7, 1], [6, 1]],k = 2) == 20\n assert candidate(items = [[9, 1], [7, 2], [5, 3], [3, 4], [1, 5]],k = 4) == 40\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],k = 3) == 129\n assert candidate(items = [[5, 1], [6, 2], [7, 3], [8, 4]],k = 4) == 42\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],k = 5) == 175\n assert candidate(items = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],k = 5) == 1525\n assert candidate(items = [[5, 1], [7, 2], [3, 2], [8, 3], [6, 3]],k = 3) == 29\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],k = 3) == 12\n assert candidate(items = [[5, 1], [5, 1], [5, 1], [5, 2], [5, 2], [5, 3]],k = 4) == 29\n assert candidate(items = [[1000000000, 1], [1000000000, 2], [1000000000, 3], [1000000000, 4], [1000000000, 5]],k = 5) == 5000000025\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 3) == 33\n assert candidate(items = [[3, 2], [5, 1], [10, 1]],k = 2) == 17\n assert candidate(items = [[1, 1], [2, 1], [3, 1]],k = 3) == 7\n assert candidate(items = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],k = 4) == 1416\n assert candidate(items = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1]],k = 3) == 21\n assert candidate(items = [[10, 5], [10, 5], [10, 5], [10, 5], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9]],k = 5) == 75\n assert candidate(items = [[3, 1], [3, 1], [2, 2], [5, 3]],k = 3) == 19\n assert candidate(items = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3]],k = 3) == 12\n assert candidate(items = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9], [1000, 10]],k = 5) == 4025\n assert candidate(items = [[100, 1], [90, 1], [80, 2], [70, 2], [60, 3], [50, 3], [40, 3], [30, 4], [20, 4], [10, 4]],k = 3) == 274\n assert candidate(items = [[100, 1], [90, 1], [80, 1], [70, 1], [60, 1], [50, 2], [40, 2], [30, 2], [20, 2], [10, 2]],k = 5) == 401\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 5) == 65\n assert candidate(items = [[100, 10], [90, 9], [80, 8], [70, 7], [60, 6], [50, 5], [40, 4], [30, 3], [20, 2], [10, 1], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],k = 8) == 584\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15]],k = 5) == 30\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [10, 1], [20, 2], [30, 3], [40, 4]],k = 10) == 661\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],k = 10) == 650\n assert candidate(items = [[9, 1], [8, 1], [7, 1], [6, 1], [5, 1], [4, 2], [3, 2], [2, 2], [1, 2], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [8, 3], [9, 3], [10, 3], [10, 4]],k = 10) == 94\n assert candidate(items = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 15) == 160\n assert candidate(items = [[5, 3], [10, 2], [15, 1], [20, 3], [25, 2], [30, 1], [35, 4]],k = 4) == 126\n assert candidate(items = [[1000000000, 1], [1000000000, 2], [1000000000, 1], [1000000000, 2], [1000000000, 1], [1000000000, 2], [1000000000, 1], [1000000000, 2], [1000000000, 1], [1000000000, 2]],k = 5) == 5000000004\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 1], [2, 2], [3, 3], [4, 4]],k = 7) == 98\n assert candidate(items = [[100, 1], [200, 2], [300, 1], [400, 2], [500, 3], [600, 3], [700, 4], [800, 4], [900, 5]],k = 6) == 3916\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],k = 15) == 1074\n assert candidate(items = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]],k = 10) == 155\n assert candidate(items = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5]],k = 5) == 65\n assert candidate(items = [[1000000000, 1], [900000000, 1], [800000000, 2], [700000000, 2], [600000000, 3], [500000000, 3], [400000000, 3], [300000000, 4], [200000000, 4], [100000000, 4]],k = 3) == 2700000004\n assert candidate(items = [[10, 1], [9, 1], [8, 1], [7, 1], [6, 1], [5, 2], [4, 2], [3, 2], [2, 2], [1, 2]],k = 5) == 43\n assert candidate(items = [[5, 1], [5, 1], [5, 1], [5, 1], [5, 1], [5, 2], [5, 2], [5, 2], [5, 2], [5, 2], [5, 3], [5, 3], [5, 3], [5, 3], [5, 3]],k = 10) == 59\n assert candidate(items = [[50, 1], [40, 1], [30, 1], [20, 1], [10, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [50, 3], [40, 3], [30, 3], [20, 3], [10, 3]],k = 5) == 214\n assert candidate(items = [[10, 1], [10, 1], [10, 1], [10, 2], [10, 2], [10, 2], [10, 3], [10, 3], [10, 3], [10, 4]],k = 4) == 56\n assert candidate(items = [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 1], [3, 2], [2, 3], [1, 4], [9, 5]],k = 7) == 73\n assert candidate(items = [[1000000000, 1], [1000000000, 2], [1000000000, 3], [1000000000, 4], [1000000000, 5], [1000000000, 6], [1000000000, 7], [1000000000, 8], [1000000000, 9], [1000000000, 10]],k = 5) == 5000000025\n assert candidate(items = [[50, 1], [40, 2], [30, 3], [20, 4], [10, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]],k = 5) == 175\n assert candidate(items = [[5, 1], [7, 2], [9, 3], [10, 2], [12, 1], [15, 4], [18, 5], [20, 1]],k = 5) == 97\n assert candidate(items = [[5, 1], [5, 1], [5, 1], [5, 1], [5, 1], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [15, 3], [15, 3], [15, 3], [15, 3], [15, 3]],k = 5) == 76\n assert candidate(items = [[5, 1], [10, 1], [15, 1], [20, 1], [25, 1], [30, 1], [35, 1], [40, 1], [45, 1], [50, 1], [5, 2], [10, 2], [15, 2], [20, 2], [25, 2], [30, 2], [35, 2], [40, 2], [45, 2], [50, 2]],k = 10) == 404\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5]],k = 10) == 155\n assert candidate(items = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 1], [70, 1], [80, 1], [90, 1], [100, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],k = 15) == 594\n assert candidate(items = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 1], [700, 2], [800, 3], [900, 4], [1000, 5]],k = 7) == 4925\n assert candidate(items = [[100, 1], [90, 1], [80, 1], [70, 1], [60, 1], [50, 2], [40, 2], [30, 2], [20, 2], [10, 2], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3]],k = 6) == 454\n assert candidate(items = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]],k = 3) == 39\n assert candidate(items = [[100, 1], [90, 2], [80, 3], [70, 4], [60, 5], [50, 6], [40, 7], [30, 8], [20, 9], [10, 10]],k = 7) == 539\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 2], [5, 2], [6, 2], [7, 3], [8, 3], [9, 3], [10, 4], [11, 4], [12, 4], [13, 5], [14, 5], [15, 5]],k = 7) == 97\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 2], [5, 2], [6, 2], [7, 3], [8, 3], [9, 3], [10, 4], [11, 4], [12, 4], [13, 5], [14, 5], [15, 5], [16, 6], [17, 6], [18, 6], [19, 7], [20, 7], [21, 7]],k = 10) == 189\n assert candidate(items = [[10, 1], [20, 1], [30, 1], [40, 2], [50, 2], [60, 2], [70, 3], [80, 3], [90, 3], [100, 4]],k = 7) == 499\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 2], [5, 2], [6, 2], [7, 3], [8, 3], [9, 3], [10, 4]],k = 4) == 44\n assert candidate(items = [[5, 1], [4, 1], [3, 1], [2, 1], [1, 1], [10, 2], [9, 2], [8, 2], [7, 2], [6, 2]],k = 5) == 43\n assert candidate(items = [[1, 1], [1, 1], [2, 2], [2, 2], [3, 3], [3, 3], [4, 4], [4, 4], [5, 5], [5, 5]],k = 6) == 45\n assert candidate(items = [[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]],k = 15) == 345\n assert candidate(items = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10], [10, 1], [9, 2], [8, 3], [7, 4], [6, 5]],k = 8) == 116\n assert candidate(items = [[500, 1], [400, 1], [300, 1], [200, 1], [100, 1], [500, 2], [400, 2], [300, 2], [200, 2], [100, 2], [500, 3], [400, 3], [300, 3], [200, 3], [100, 3]],k = 8) == 3309\n assert candidate(items = [[1, 1], [1, 1], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2], [2, 2], [3, 3], [3, 3]],k = 3) == 15\n assert candidate(items = [[10, 1], [20, 1], [30, 2], [40, 2], [50, 3], [60, 3], [70, 4], [80, 4], [90, 5], [100, 5], [110, 6], [120, 6], [130, 7], [140, 7], [150, 8], [160, 8], [170, 9], [180, 9], [190, 10], [200, 10]],k = 15) == 2014\n assert candidate(items = [[100, 1], [90, 1], [80, 1], [70, 1], [60, 1], [50, 2], [40, 2], [30, 2], [20, 2], [10, 2]],k = 4) == 341\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 5) == 30\n assert candidate(items = [[5, 1], [5, 1], [5, 1], [5, 1], [5, 1], [5, 2], [5, 2], [5, 2], [5, 2], [5, 2]],k = 3) == 19\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 10) == 110\n assert candidate(items = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [11, 10], [12, 9], [13, 8], [14, 7], [15, 6], [16, 5], [17, 4], [18, 3], [19, 2], [20, 1]],k = 15) == 295\n assert candidate(items = [[3, 1], [5, 2], [7, 3], [9, 4], [11, 5], [13, 1], [15, 2], [17, 3], [19, 4], [21, 5]],k = 5) == 110\n assert candidate(items = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [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 = 10) == 11\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],k = 5) == 425\n assert candidate(items = [[100, 1], [90, 2], [80, 3], [70, 4], [60, 5], [50, 6], [40, 7], [30, 8], [20, 9], [10, 10]],k = 3) == 279\n assert candidate(items = [[100, 1], [90, 1], [80, 1], [70, 1], [60, 1], [50, 1], [40, 1], [30, 1], [20, 1], [10, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],k = 15) == 594\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 1], [50, 2], [60, 3], [70, 4], [80, 5], [90, 4], [100, 5], [110, 6], [120, 7], [130, 8], [140, 9], [150, 10]],k = 8) == 969\n assert candidate(items = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]],k = 3) == 7\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],k = 10) == 155\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]],k = 10) == 120\n assert candidate(items = [[1000000000, 1], [999999999, 2], [888888888, 3], [777777777, 4], [666666666, 5], [555555555, 6], [444444444, 7], [333333333, 8], [222222222, 9], [111111111, 10]],k = 5) == 4333333355\n assert candidate(items = [[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]],k = 10) == 205\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],k = 10) == 674\n assert candidate(items = [[10, 1], [9, 1], [8, 1], [7, 1], [6, 1], [5, 1], [4, 1], [3, 1], [2, 1], [1, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]],k = 8) == 58\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],k = 6) == 49\n assert candidate(items = [[90, 1], [80, 2], [70, 3], [60, 4], [50, 5], [40, 6], [30, 7], [20, 8], [10, 9]],k = 5) == 375\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 1], [70, 2], [80, 3], [90, 4], [100, 5], [110, 6], [120, 7], [130, 8], [140, 9], [150, 10], [160, 11], [170, 12], [180, 13], [190, 14], [200, 15]],k = 10) == 1650\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1]],k = 10) == 106\n assert candidate(items = [[10, 1], [9, 1], [8, 2], [7, 2], [6, 3], [5, 3], [4, 3], [3, 4], [2, 4], [1, 4], [100, 5], [99, 5], [98, 5], [97, 5], [96, 5]],k = 10) == 551\n assert candidate(items = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]],k = 5) == 50\n assert candidate(items = [[5, 1], [5, 1], [5, 2], [5, 2], [5, 3], [5, 3], [5, 4], [5, 4], [5, 5], [5, 5]],k = 5) == 50\n assert candidate(items = [[1000000000, 1], [1000000000, 2], [1000000000, 3], [1000000000, 4], [1000000000, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 7) == 5000000051\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],k = 7) == 539\n assert candidate(items = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],k = 5) == 2109\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [110, 1], [120, 2], [130, 3], [140, 4], [150, 5]],k = 12) == 1240\n assert candidate(items = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]],k = 3) == 24\n assert candidate(items = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 2], [70, 2], [80, 2], [90, 2], [100, 2], [110, 3], [120, 3], [130, 3], [140, 3], [150, 3]],k = 10) == 1054\n assert candidate(items = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [10, 6], [9, 7], [8, 8], [7, 9], [6, 10], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5]],k = 5) == 65\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],k = 4) == 36\n assert candidate(items = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],k = 10) == 155\n assert candidate(items = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 2], [70, 2], [80, 2], [90, 2], [100, 2]],k = 5) == 401\n assert candidate(items = [[1000000000, 1], [500000000, 1], [250000000, 1], [125000000, 1], [62500000, 1], [31250000, 2], [15625000, 2], [7812500, 2], [3906250, 2], [1953125, 2]],k = 4) == 1875000001\n assert candidate(items = [[1000000000, 1], [900000000, 2], [800000000, 3], [700000000, 4], [600000000, 5], [500000000, 6], [400000000, 7], [300000000, 8], [200000000, 9], [100000000, 10]],k = 5) == 4000000025\n assert candidate(items = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10], [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9], [9, 9], [10, 9]],k = 10) == 84\n assert candidate(items = [[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]],k = 7) == 84\n assert candidate(items = [[100, 1], [99, 2], [98, 3], [97, 4], [96, 5], [95, 1], [94, 2], [93, 3], [92, 4], [91, 5]],k = 3) == 306\n assert candidate(items = [[1, 1], [2, 1], [3, 2], [4, 2], [5, 3], [6, 3], [7, 4], [8, 4], [9, 5], [10, 5], [11, 6], [12, 6], [13, 7], [14, 7], [15, 8], [16, 8], [17, 9], [18, 9], [19, 10], [20, 10]],k = 5) == 105\n assert candidate(items = [[10, 1], [20, 1], [30, 2], [40, 2], [50, 3], [60, 3], [70, 4], [80, 4], [90, 5], [100, 5], [110, 6], [120, 6], [130, 7], [140, 7], [150, 8], [160, 8]],k = 8) == 1016\n", "comparison": "exact"}, "public_tests": ["[[3,2],[5,1],[10,1]]\n2", "[[3,1],[3,1],[2,2],[5,3]]\n3", "[[1,1],[2,1],[3,1]]\n3"], "hints": ["Greedy algorithm.", "Sort items in non-increasing order of profits.", "Select the first k items (the top k most profitable items). Keep track of the items as the candidate set.", "For the remaining n - k items sorted in non-increasing order of profits, try replacing an item in the candidate set using the current item.", "The replacing item should add a new category to the candidate set and should remove the item with the minimum profit that occurs more than once in the candidate set."], "metadata": {"canonical_parameter_names": ["items", "k"], "leetcode_dataset_entry_point": "Solution().findMaximumElegance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:54+00:00", "tests_total": 112, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "hash-table", "stack", "greedy", "sorting", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def find_maximum_elegance(items, k)", "container": null, "callable": "find_maximum_elegance", "parameters": [{"name": "items", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2815, "task_id": "max-pair-sum-in-an-array", "difficulty": "Easy", "problem_description": "You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal.\n\nFor example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them.\n\nReturn the maximum sum or -1 if no such pair exists.\n\nExample 1:\n\nInput: nums = [112,131,411]\nOutput: -1\nExplanation:\nEach numbers largest digit in order is [2,3,4].\n\nExample 2:\n\nInput: nums = [2536,1613,3366,162]\nOutput: 5902\nExplanation:\nAll the numbers have 6 as their largest digit, so the answer is 2536 + 3366 = 5902.\n\nExample 3:\n\nInput: nums = [51,71,17,24,42]\nOutput: 88\nExplanation:\nEach number's largest digit in order is [5,7,7,4,4].\nSo we have only two possible pairs, 71 + 17 = 88 and 24 + 42 = 66.\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [123, 321, 213, 132]) == 534\n assert candidate(nums = [100, 200, 300, 400]) == -1\n assert candidate(nums = [55, 44, 33, 22, 11]) == -1\n assert candidate(nums = [99, 88, 77, 66, 55]) == -1\n assert candidate(nums = [111, 222, 333, 444, 555]) == -1\n assert candidate(nums = [12, 21, 13, 31, 23, 32]) == 63\n assert candidate(nums = [111, 222, 333, 444]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [9000, 900, 90, 9]) == 9900\n assert candidate(nums = [11, 22, 33, 44]) == -1\n assert candidate(nums = [2536, 1613, 3366, 162]) == 5902\n assert candidate(nums = [123, 321, 213, 132]) == 534\n assert candidate(nums = [10, 20, 30, 40, 50]) == -1\n assert candidate(nums = [51, 71, 17, 24, 42]) == 88\n assert candidate(nums = [9, 99, 999, 9999]) == 10998\n assert candidate(nums = [1234, 4321, 2341, 3412, 1423, 2134]) == 7733\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == -1\n assert candidate(nums = [999, 888, 777, 666, 555]) == -1\n assert candidate(nums = [1000, 1001, 1010, 1100]) == 2110\n assert candidate(nums = [112, 131, 411]) == -1\n assert candidate(nums = [999, 888, 777, 666]) == -1\n assert candidate(nums = [1234, 4321, 2341, 1432]) == 6662\n assert candidate(nums = [12, 21, 13, 31, 14, 41, 23, 32, 24, 42, 34, 43]) == 85\n assert candidate(nums = [123, 321, 213, 132, 231, 312]) == 633\n assert candidate(nums = [123, 321, 213]) == 534\n assert candidate(nums = [999, 888, 777, 666]) == -1\n assert candidate(nums = [9990, 9909, 9099, 9991, 1999, 9919, 9199, 9992, 2999, 9929, 9299]) == 19983\n assert candidate(nums = [1001, 1010, 1100, 1000, 10, 1]) == 2110\n assert candidate(nums = [9876, 8769, 7698, 6987, 9875, 8759, 7598, 5987, 9874, 8749]) == 19751\n assert candidate(nums = [5689, 8956, 6958, 9586, 5869, 9658, 6598, 5698, 8965, 9865]) == 19523\n assert candidate(nums = [1999, 1888, 1777, 1666, 1555, 1444, 1333, 1222, 1111, 9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222]) == 11998\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 12, 21, 32, 23, 34, 43]) == 1791\n assert candidate(nums = [101, 110, 111, 202, 220, 222, 303, 330, 333]) == 663\n assert candidate(nums = [111, 112, 121, 211, 222, 221, 212, 122, 333, 332, 323, 233, 444, 443, 434, 344]) == 887\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 101]) == 212\n assert candidate(nums = [5005, 5500, 5050, 5000, 9999, 9998, 9989, 9899, 9988, 9889, 8999, 8989, 8899]) == 19997\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111, 1010, 1001, 1011, 1101, 1110, 9898, 8989]) == 19897\n assert candidate(nums = [1110, 1101, 1011, 2220, 2202, 2022, 3330, 3303, 3033]) == 6633\n assert candidate(nums = [1234, 4321, 2341, 3412, 4123, 1423, 2143, 3214]) == 8444\n assert candidate(nums = [123, 456, 789, 321, 654, 987, 213, 543, 879]) == 1866\n assert candidate(nums = [1234, 4321, 2341, 3412, 1432]) == 7733\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 234, 345, 456]) == 1791\n assert candidate(nums = [10000, 9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 11111\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == -1\n assert candidate(nums = [1234, 4321, 2134, 3412, 1111, 9876, 6789]) == 16665\n assert candidate(nums = [1234, 4321, 2134, 3412, 2341]) == 7733\n assert candidate(nums = [1099, 9910, 2088, 8820, 3077, 7730, 4066, 6640, 5055, 5505]) == 11009\n assert candidate(nums = [245, 452, 524, 199, 919, 991]) == 1910\n assert candidate(nums = [123, 123, 123, 456, 456, 456, 789, 789, 789]) == 1578\n assert candidate(nums = [1010, 1001, 1100, 1110, 1011, 1111, 2222, 2212, 2122, 2221]) == 4443\n assert candidate(nums = [999, 990, 909, 900, 888, 880, 808, 800, 777, 770, 707, 700]) == 1989\n assert candidate(nums = [1234, 4321, 3412, 2143, 4444]) == 8765\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1111]) == 1222\n assert candidate(nums = [123, 321, 213, 456, 654, 564]) == 1218\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == -1\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == -1\n assert candidate(nums = [1299, 2288, 3377, 4466, 5555, 6644, 7733, 8822, 9911]) == 11210\n assert candidate(nums = [1111, 1222, 1333, 2111, 2222, 2333, 3111, 3222, 3333]) == 6555\n assert candidate(nums = [9876, 8765, 7654, 6543, 5432, 4321, 3210, 2109, 1098, 987]) == 11985\n assert candidate(nums = [9876, 8765, 7654, 6543, 5432, 4321, 3210, 2109, 1098]) == 11985\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 32\n assert candidate(nums = [1234, 4321, 2341, 3124, 1324, 2413, 4132, 3412, 5678, 8765, 7658, 6587, 8657, 5867, 7568]) == 17422\n assert candidate(nums = [1234, 4321, 2134, 3412, 5678, 8765]) == 14443\n assert candidate(nums = [5678, 8765, 6543, 3456, 7890]) == 14443\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == -1\n assert candidate(nums = [5555, 5556, 5565, 5655, 6555, 5566, 6655, 6565, 5665, 6665]) == 13320\n assert candidate(nums = [1010, 2020, 3030, 4040, 5050, 6060, 7070, 8080, 9090]) == -1\n assert candidate(nums = [1000, 1001, 1010, 1100, 1110, 1101, 1011, 9000, 9001, 9010]) == 18011\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, 4444]) == 4888\n assert candidate(nums = [12, 21, 34, 43, 56, 65, 78, 87, 90, 90, 100, 101, 110, 111]) == 221\n assert candidate(nums = [1234, 4321, 2341, 3412, 4123, 2134, 1423, 3214, 4231]) == 8552\n assert candidate(nums = [1234, 4321, 2341, 3412, 3214]) == 7733\n assert candidate(nums = [2332, 3223, 2233, 3322, 3232, 2323, 3332, 3233, 3333, 2223]) == 6665\n assert candidate(nums = [5999, 5888, 5777, 5666, 5555, 5444, 5333, 5222, 5111]) == 10999\n assert candidate(nums = [1112, 2111, 1211, 1121, 1111, 2221, 2212, 2122, 1222, 2222]) == 4443\n assert candidate(nums = [5555, 5554, 5545, 5455, 4555]) == 11109\n assert candidate(nums = [199, 288, 377, 466, 555, 554, 467, 378, 289, 190, 290, 380, 470, 560]) == 1109\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == 9999\n assert candidate(nums = [9999, 9998, 9989, 9899, 9988, 9889, 8999, 8989, 8899, 8889]) == 19997\n", "comparison": "exact"}, "public_tests": ["[112,131,411]", "[2536,1613,3366,162]", "[51,71,17,24,42]"], "hints": ["Find the largest and second largest element with maximum digits equal to x where 1<=x<=9."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:03:59+00:00", "tests_total": 126, "tests_dropped": 47, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def max_sum(nums)", "container": null, "callable": "max_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2817, "task_id": "minimum-absolute-difference-between-elements-with-constraint", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer x.\n\nFind the minimum absolute difference between two elements in the array that are at least x indices apart.\n\nIn other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.\n\nReturn an integer denoting the minimum absolute difference between two elements that are at least x indices apart.\n\nExample 1:\n\nInput: nums = [4,3,2,4], x = 2\nOutput: 0\nExplanation: We can select nums[0] = 4 and nums[3] = 4.\nThey are at least 2 indices apart, and their absolute difference is the minimum, 0.\nIt can be shown that 0 is the optimal answer.\n\nExample 2:\n\nInput: nums = [5,3,2,10,15], x = 1\nOutput: 1\nExplanation: We can select nums[1] = 3 and nums[2] = 2.\nThey are at least 1 index apart, and their absolute difference is the minimum, 1.\nIt can be shown that 1 is the optimal answer.\n\nExample 3:\n\nInput: nums = [1,2,3,4], x = 3\nOutput: 3\nExplanation: We can select nums[0] = 1 and nums[3] = 4.\nThey are at least 3 indices apart, and their absolute difference is the minimum, 3.\nIt can be shown that 3 is the optimal answer.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 0 <= x < nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],x = 2) == 0\n assert candidate(nums = [10, 5, 3, 9, 2],x = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],x = 0) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],x = 3) == 0\n assert candidate(nums = [1, 2, 3, 4],x = 3) == 3\n assert candidate(nums = [4, 3, 2, 4],x = 2) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1],x = 1) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],x = 4) == 0\n assert candidate(nums = [1, 5, 3, 19, 18, 22],x = 3) == 13\n assert candidate(nums = [10, 5, 3, 6, 8, 1, 2],x = 2) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],x = 2) == 20\n assert candidate(nums = [5, 3, 2, 10, 15],x = 1) == 1\n assert candidate(nums = [10, 5, 3, 6, 8, 2, 9],x = 4) == 1\n assert candidate(nums = [10, 5, 3, 100, 20, 15],x = 2) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],x = 4) == 2\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],x = 2) == 1\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],x = 12) == 12\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],x = 7) == 3\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],x = 2) == 1\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],x = 25) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998],x = 2) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 7) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 0) == 0\n assert candidate(nums = [3, 8, 15, 17, 9, 5, 12, 3],x = 3) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 3) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 8) == 80\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],x = 3) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],x = 4) == 8\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],x = 5) == 0\n assert candidate(nums = [7, 3, 2, 8, 6, 5, 4, 9, 1, 10],x = 3) == 1\n assert candidate(nums = [5, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],x = 3) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 2) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 6) == 6\n assert candidate(nums = [5, 3, 3, 5, 5, 3, 3, 5, 5, 3, 3, 5],x = 2) == 0\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200],x = 5) == 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],x = 9) == 9\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10],x = 4) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 6) == 600\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 3) == 3\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],x = 4) == 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, 21, 22, 23, 24, 25],x = 10) == 10\n assert candidate(nums = [9, 1, 5, 7, 3, 8, 2, 6, 4, 10],x = 4) == 1\n assert candidate(nums = [5, 1, 4, 2, 3],x = 2) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],x = 4) == 4\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 35, 50, 45],x = 3) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 5) == 50\n assert candidate(nums = [2, 5, 1, 8, 3, 7, 4, 6],x = 2) == 1\n assert candidate(nums = [1, 3, 6, 8, 9, 10, 12, 15, 18, 20],x = 6) == 11\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 3) == 30\n assert candidate(nums = [1, 5, 9, 14, 20, 25, 30],x = 2) == 8\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],x = 3) == 29\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 10) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5) == 5\n assert candidate(nums = [9, 5, 12, 6, 18, 3],x = 2) == 1\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91],x = 5) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],x = 6) == 12\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],x = 5) == 2\n assert candidate(nums = [23, 1, 21, 3, 19, 5, 17, 7, 15, 9, 13, 11, 14, 12, 16, 10, 18, 8, 20, 6, 22, 4, 24, 2, 25],x = 7) == 1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],x = 9) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 6) == 600\n assert candidate(nums = [5, 8, 12, 15, 18, 21, 24, 27, 30, 33],x = 4) == 12\n assert candidate(nums = [3, 8, 15, 1, 6],x = 3) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],x = 1) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 4) == 4\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000],x = 3) == 109375000\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],x = 4) == 0\n assert candidate(nums = [7, 1, 14, 11],x = 2) == 4\n assert candidate(nums = [1, 3, 6, 8, 12, 15, 18, 20],x = 3) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 5) == 5\n assert candidate(nums = [1000000000, 999999999, 1, 2, 3, 4, 5, 6, 7, 8, 9],x = 5) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 2) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 9) == 9\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10],x = 2) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],x = 2) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 4) == 0\n assert candidate(nums = [2, 1, 2, 3, 1, 3, 4, 1, 4, 2, 4, 3, 5, 1, 5, 2, 5, 3, 5, 4],x = 4) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 4) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5) == 5\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 5) == 50\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5],x = 2) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],x = 2) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],x = 8) == 40\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],x = 2) == 0\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],x = 4) == 8\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],x = 15) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 2) == 200\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],x = 4) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 2) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 1) == 2\n assert candidate(nums = [100, 50, 10, 5, 1, 500, 1000, 200, 300, 400],x = 3) == 49\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],x = 5) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 4) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 5) == 50\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],x = 5) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],x = 1) == 1\n assert candidate(nums = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 3) == 1\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],x = 2) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],x = 4) == 8\n assert candidate(nums = [5, 3, 2, 4, 1, 6, 7, 8, 9, 10],x = 7) == 3\n assert candidate(nums = [4, 1, 7, 10, 3, 8, 2, 9, 5, 6],x = 2) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 10) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 4) == 4\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1],x = 2) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],x = 3) == 0\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],x = 8) == 0\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],x = 3) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 7) == 7\n assert candidate(nums = [7, 1, 3, 4, 1, 7],x = 3) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1],x = 2) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],x = 5) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1],x = 3) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 2) == 20\n assert candidate(nums = [8, 1, 5, 10, 18, 15, 22, 4, 7, 2],x = 5) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],x = 9) == 0\n assert candidate(nums = [1, 1000000000, 1, 1000000000],x = 2) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000],x = 1) == 0\n assert candidate(nums = [3, 5, 6, 7, 8, 8],x = 1) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4],x = 3) == 1\n assert candidate(nums = [1],x = 0) == 0\n assert candidate(nums = [6, 2, 1, 100, 1000, 3, 4],x = 4) == 1\n assert candidate(nums = [100, 100, 100, 100],x = 0) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 3) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 5) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 5) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11],x = 5) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1],x = 2) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 4) == 0\n assert candidate(nums = [1, 5, 9, 14, 20],x = 2) == 8\n assert candidate(nums = [10, 20, 30, 40, 50],x = 0) == 0\n assert candidate(nums = [7, 1, 4, 5, 9, 2, 6, 3],x = 2) == 1\n assert candidate(nums = [7, 1, 4, 5, 6, 2],x = 3) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 2) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],x = 4) == 40\n assert candidate(nums = [10, 5, 1, 7, 10, 3],x = 2) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50],x = 3) == 30\n assert candidate(nums = [1, 3, 6, 8, 9, 15],x = 0) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],x = 4) == 0\n assert candidate(nums = [10, 5, 3, 8, 12, 7, 6, 9, 1, 2],x = 4) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],x = 0) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 9) == 9\n assert candidate(nums = [1, 5, 3, 19, 18, 22, 6, 7],x = 3) == 1\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000],x = 4) == 0\n assert candidate(nums = [5, 8, 3, 9, 7, 6, 2, 4, 1, 10],x = 4) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 2) == 2\n assert candidate(nums = [8, 12, 4, 13, 7],x = 2) == 1\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],x = 5) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 0) == 0\n assert candidate(nums = [1, 1, 1, 1, 1],x = 2) == 0\n assert candidate(nums = [1, 100, 1, 100, 1, 100],x = 1) == 0\n assert candidate(nums = [10, 5, 3, 9, 2, 8],x = 2) == 1\n assert candidate(nums = [7, 1, 3, 4, 1, 9],x = 1) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 1) == 2\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],x = 0) == 0\n assert candidate(nums = [7, 1, 3, 4, 1, 9],x = 4) == 2\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1],x = 3) == 0\n assert candidate(nums = [7, 1, 3, 4, 1, 7],x = 2) == 0\n assert candidate(nums = [5, 1, 4, 1, 2],x = 2) == 0\n assert candidate(nums = [1000000000, 1, 1000000000, 1],x = 2) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997],x = 2) == 1\n assert candidate(nums = [1, 5, 3, 19, 18, 22, 6, 7, 20, 15],x = 4) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 4) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 0) == 0\n assert candidate(nums = [3, 5, 4, 2, 4],x = 1) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],x = 0) == 0\n assert candidate(nums = [7, 1, 3, 8, 6, 2, 5, 4],x = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 1) == 0\n assert candidate(nums = [10, 5, 4, 7, 8, 9],x = 4) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],x = 0) == 0\n assert candidate(nums = [1, 1000000000, 1, 1000000000],x = 1) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 9) == 0\n assert candidate(nums = [3, 5, 9, 8, 10, 1],x = 2) == 1\n assert candidate(nums = [1, 10, 3, 7, 5, 8, 6, 2, 4, 9],x = 5) == 1\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 1000000000, 999999999, 1],x = 3) == 0\n assert candidate(nums = [10, 5, 3, 9, 2, 8, 6],x = 2) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 8) == 16\n assert candidate(nums = [10, 5, 1, 15, 3, 7, 8],x = 2) == 2\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 5) == 50\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1],x = 3) == 0\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000],x = 2) == 0\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],x = 0) == 0\n assert candidate(nums = [1, 5, 3, 19, 18, 25],x = 3) == 13\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 0) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 5) == 5\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],x = 4) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 0) == 0\n assert candidate(nums = [1, 5, 3, 19, 18, 25],x = 2) == 2\n assert candidate(nums = [10, 5, 3, 8, 12],x = 2) == 2\n assert candidate(nums = [3, 5, 3, 5, 3, 5, 3, 5],x = 3) == 0\n assert candidate(nums = [10, 5, 4, 7, 8, 3, 6, 1],x = 4) == 1\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 9) == 90\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 5) == 0\n assert candidate(nums = [10, 5, 1, 9, 4, 8, 3, 7, 2, 6],x = 4) == 1\n assert candidate(nums = [7, 10, 4, 3, 20, 15],x = 2) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 2) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 3) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],x = 0) == 0\n assert candidate(nums = [1, 2, 3, 100, 101, 102],x = 2) == 2\n assert candidate(nums = [1, 5, 9, 13, 17],x = 4) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 4) == 40\n assert candidate(nums = [10, 5, 1, 100, 1000],x = 2) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 3) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300],x = 3) == 0\n", "comparison": "exact"}, "public_tests": ["[4,3,2,4]\n2", "[5,3,2,10,15]\n1", "[1,2,3,4]\n3"], "hints": ["Let's only consider the cases where i < j, as the problem is symmetric.", "For an index j, we are interested in an index i in the range [0, j - x] that minimizes abs(nums[i] - nums[j]).", "For every index j, while going from left to right, add nums[j - x] to a set (C++ set, Java TreeSet, and Python sorted set).", "After inserting nums[j - x], we can calculate the closest value to nums[j] in the set using binary search and store the absolute difference. In C++, we can achieve this by using lower_bound and/or upper_bound.", "Calculate the minimum absolute difference among all indices."], "metadata": {"canonical_parameter_names": ["nums", "x"], "leetcode_dataset_entry_point": "Solution().minAbsoluteDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:04+00:00", "tests_total": 213, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "binary-search", "ordered-set"]}, "language": "ruby", "interface": {"raw_signature": "def min_absolute_difference(nums, x)", "container": null, "callable": "min_absolute_difference", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2824, "task_id": "count-pairs-whose-sum-is-less-than-target", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.\n\nExample 1:\n\nInput: nums = [-1,1,2,3,1], target = 2\nOutput: 3\nExplanation: There are 3 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target\n- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target\nNote that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.\n\nExample 2:\n\nInput: nums = [-6,2,5,-2,-7,-1,3], target = -2\nOutput: 10\nExplanation: There are 10 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target\n- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target\n- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target\n- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target\n- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target\n- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target\n- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target\n- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target\n- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target\n\nConstraints:\n\n- 1 <= nums.length == n <= 50\n- -50 <= nums[i], target <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],target = 15) == 10\n assert candidate(nums = [1, 3, 5, 7, 9],target = 10) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],target = 3) == 10\n assert candidate(nums = [0, 0, 0, 0, 0],target = 0) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],target = 10) == 10\n assert candidate(nums = [-1, -2, -3, -4, -5],target = -3) == 9\n assert candidate(nums = [-5, -4, -3, -2, -1],target = -5) == 6\n assert candidate(nums = [-6, 2, 5, -2, -7, -1, 3],target = -2) == 10\n assert candidate(nums = [0, 0, 0, 0, 0],target = 1) == 10\n assert candidate(nums = [0, 0, 0, 0],target = 1) == 6\n assert candidate(nums = [-1, 1, 2, 3, 1],target = 2) == 3\n assert candidate(nums = [-5, -4, -3, -2, -1],target = -8) == 1\n assert candidate(nums = [50, -50, 25, -25],target = 0) == 2\n assert candidate(nums = [-5, -10, 3, 8, 0, -2],target = 1) == 9\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],target = -15) == 6\n assert candidate(nums = [25, -25, 0, 15, -15, 10, -10, 5, -5, 20, -20],target = 0) == 25\n assert candidate(nums = [-5, -4, -3, -2, -1],target = -2) == 10\n assert candidate(nums = [-1, -1, -2, -3, -4, -5, -6, -7, -8, -9],target = -3) == 42\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50],target = 25) == 32\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3],target = 1) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],target = 0) == 90\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15, -20, -25, -30, -35, -40, -45],target = 5) == 90\n assert candidate(nums = [0, 0, 0, 0, 0],target = 0) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],target = 50) == 64\n assert candidate(nums = [-30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30],target = -10) == 25\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],target = 1) == 1128\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 30) == 160\n assert candidate(nums = [-49, -47, -45, -43, -41, -39, -37, -35, -33, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11],target = -50) == 134\n assert candidate(nums = [45, 46, 47, 48, 49, 50, -45, -46, -47, -48, -49, -50],target = 0) == 30\n assert candidate(nums = [5, 2, 7, 1, 8, 4, 3, 6],target = 10) == 16\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35],target = 0) == 6\n assert candidate(nums = [5, 15, 25, 35, 45, 50, 45, 35, 25, 15, 5, 0, -5, -15, -25, -35, -45, -50, -45, -35, -25, -15, -5, 0, 5, 15, 25, 35, 45, 50, 45, 35, 25, 15, 5, 0, -5, -15, -25, -35, -45, -50, -45, -35, -25, -15, -5],target = 10) == 604\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],target = 1) == 45\n assert candidate(nums = [50, -50, 40, -40, 30, -30, 20, -20, 10, -10],target = 1) == 25\n assert candidate(nums = [-1, 0, 1, 2, -2, -3, 3],target = 1) == 12\n assert candidate(nums = [5, -5, 15, -15, 25, -25],target = 0) == 6\n assert candidate(nums = [-10, 0, 10, -20, 20, -30, 30, -40, 40, -50, 50],target = 10) == 30\n assert candidate(nums = [-45, -40, -35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45],target = -5) == 72\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3],target = 0) == 9\n assert candidate(nums = [-4, -3, -2, -1, 0, 1, 2, 3, 4],target = 1) == 20\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17],target = 15) == 8\n assert candidate(nums = [30, 20, 10, 0, -10, -20, -30],target = 10) == 12\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],target = 8) == 25\n assert candidate(nums = [-2, -3, -4, -5, -6, 1, 2, 3, 4, 5],target = -5) == 9\n assert candidate(nums = [48, 49, 50, -48, -49, -50],target = 0) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 15) == 12\n assert candidate(nums = [-40, -30, -20, -10, 0, 10, 20, 30, 40, 50],target = 10) == 20\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1],target = -5) == 41\n assert candidate(nums = [25, 20, 15, 10, 5, 0, -5, -10, -15, -20, -25],target = 10) == 35\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],target = 50) == 576\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],target = 1) == 20\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0],target = 1) == 21\n assert candidate(nums = [25, 20, 15, 10, 5, 0, -5, -10, -15, -20, -25, 30, 35, 40, 45, 50, -30, -35, -40, -45, -50],target = 15) == 129\n assert candidate(nums = [-1, 0, 1, 0, -1, 1, 0],target = 1) == 14\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],target = 0) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 25) == 29\n assert candidate(nums = [-40, -30, -20, -10, 0, 10, 20, 30, 40],target = -15) == 12\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],target = 0) == 25\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],target = 30) == 27\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1],target = -15) == 6\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5],target = 2) == 35\n assert candidate(nums = [30, 20, 10, 0, -10, -20, -30, -40, -50],target = -25) == 16\n assert candidate(nums = [23, 24, 25, 26, 27, 28, 29, 30],target = 50) == 4\n assert candidate(nums = [-50, 0, 50, -40, 40],target = 10) == 6\n assert candidate(nums = [1, -1, 2, -2, 3, -3],target = 0) == 6\n assert candidate(nums = [-25, -25, -25, -25, -25],target = -50) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 11) == 20\n assert candidate(nums = [-40, -30, -20, -10, 0, 10, 20, 30],target = -5) == 16\n assert candidate(nums = [0, 0, 0, 0, 0],target = 1) == 10\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 0],target = -5) == 25\n assert candidate(nums = [10, -10, 20, -20, 30, -30],target = 0) == 6\n assert candidate(nums = [-5, 0, 5, 10, 15, 20, 25, 30, 35, 40],target = 20) == 9\n assert candidate(nums = [45, -45, 44, -44, 43, -43, 42],target = 0) == 9\n assert candidate(nums = [-10, 0, 10, 20, 30, 40, 50],target = 0) == 1\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],target = 0) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 20) == 75\n assert candidate(nums = [5, 4, 3, 2, 1],target = 6) == 4\n assert candidate(nums = [5, 4, 3, 2, 1],target = 7) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1],target = 0) == 10\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5],target = 4) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 20) == 20\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5],target = 3) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 10) == 0\n assert candidate(nums = [49, -49, 48, -48, 47, -47, 46, -46, 45, -45],target = 0) == 20\n assert candidate(nums = [-5, -5, -5, -5, -5, 5, 5, 5, 5, 5],target = 0) == 10\n assert candidate(nums = [-10, -20, -30, 10, 20, 30, 0],target = -15) == 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],target = 21) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 15) == 36\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],target = -11) == 20\n assert candidate(nums = [5, 8, -3, 6, 2, 7, 4, 1, -5, -10],target = 5) == 24\n assert candidate(nums = [23, 17, 42, 8, 3, 19, 5, 28],target = 30) == 11\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3],target = 1) == 12\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15],target = 45) == 46\n", "comparison": "exact"}, "public_tests": ["[-1,1,2,3,1]\n2", "[-6,2,5,-2,-7,-1,3]\n-2"], "hints": ["The constraints are small enough for a brute-force solution to pass"], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:09+00:00", "tests_total": 112, "tests_dropped": 19, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def count_pairs(nums, target)", "container": null, "callable": "count_pairs", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2825, "task_id": "make-string-a-subsequence-using-cyclic-increments", "difficulty": "Medium", "problem_description": "You are given two 0-indexed strings str1 and str2.\n\nIn an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.\n\nReturn true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.\n\nNote: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n\nExample 1:\n\nInput: str1 = \"abc\", str2 = \"ad\"\nOutput: true\nExplanation: Select index 2 in str1.\nIncrement str1[2] to become 'd'.\nHence, str1 becomes \"abd\" and str2 is now a subsequence. Therefore, true is returned.\n\nExample 2:\n\nInput: str1 = \"zc\", str2 = \"ad\"\nOutput: true\nExplanation: Select indices 0 and 1 in str1.\nIncrement str1[0] to become 'a'.\nIncrement str1[1] to become 'd'.\nHence, str1 becomes \"ad\" and str2 is now a subsequence. Therefore, true is returned.\n\nExample 3:\n\nInput: str1 = \"ab\", str2 = \"d\"\nOutput: false\nExplanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.\nTherefore, false is returned.\n\nConstraints:\n\n- 1 <= str1.length <= 10^5\n- 1 <= str2.length <= 10^5\n- str1 and str2 consist of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(str1 = \"aaa\",str2 = \"a\") == True\n assert candidate(str1 = \"hello\",str2 = \"heo\") == True\n assert candidate(str1 = \"abcd\",str2 = \"bd\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(str1 = \"abacaba\",str2 = \"aaa\") == True\n assert candidate(str1 = \"xyz\",str2 = \"yza\") == True\n assert candidate(str1 = \"abc\",str2 = \"abc\") == True\n assert candidate(str1 = \"ab\",str2 = \"d\") == False\n assert candidate(str1 = \"az\",str2 = \"ba\") == True\n assert candidate(str1 = \"abcde\",str2 = \"aec\") == False\n assert candidate(str1 = \"azazaz\",str2 = \"zzz\") == True\n assert candidate(str1 = \"abcde\",str2 = \"ae\") == True\n assert candidate(str1 = \"aabbccddeeff\",str2 = \"abcdef\") == True\n assert candidate(str1 = \"abcde\",str2 = \"ace\") == True\n assert candidate(str1 = \"a\",str2 = \"b\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"aabbcc\",str2 = \"abc\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"z\") == True\n assert candidate(str1 = \"aaa\",str2 = \"b\") == True\n assert candidate(str1 = \"abc\",str2 = \"acb\") == False\n assert candidate(str1 = \"zc\",str2 = \"ad\") == True\n assert candidate(str1 = \"abcxyz\",str2 = \"adz\") == True\n assert candidate(str1 = \"abc\",str2 = \"ad\") == True\n assert candidate(str1 = \"abcd\",str2 = \"dddd\") == False\n assert candidate(str1 = \"a\",str2 = \"a\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"za\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"gh\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopqr\") == True\n assert candidate(str1 = \"acegikmoqsuwy\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(str1 = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",str2 = \"abcabcabc\") == True\n assert candidate(str1 = \"a\",str2 = \"z\") == False\n assert candidate(str1 = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",str2 = \"acegikmoqsuwy\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyza\",str2 = \"abcdefghijklmnopqrstuvwxyza\") == True\n assert candidate(str1 = \"b\",str2 = \"a\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"op\") == True\n assert candidate(str1 = \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"wx\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"acegikmoqsuwy\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"qr\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzaaa\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"abczyxwvutsrqponmlkjihgfedcba\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"monp\") == False\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mno\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"a\") == True\n assert candidate(str1 = \"abz\",str2 = \"abc\") == False\n assert candidate(str1 = \"abacabadabacaba\",str2 = \"abcd\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"nopqrstuvwxyz\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"zxcvbnmlkjhgfedcba\") == False\n assert candidate(str1 = \"abcdabcdabcdabcdabcdabcdabcd\",str2 = \"dddddddddd\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"nopqrstuvwy\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"zzz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"zz\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"mnopqrst\") == False\n assert candidate(str1 = \"abcdeffedcbaz\",str2 = \"zzzz\") == False\n assert candidate(str1 = \"ababababababababababababababab\",str2 = \"bababa\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mn\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyza\") == False\n assert candidate(str1 = \"abcdabcdabcd\",str2 = \"abdc\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopqrstu\") == True\n assert candidate(str1 = \"aaabbbccc\",str2 = \"abc\") == True\n assert candidate(str1 = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\",str2 = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\") == True\n assert candidate(str1 = \"bdfhjlnprtvxz\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(str1 = \"abcdeffedcba\",str2 = \"abcdef\") == True\n assert candidate(str1 = \"abcabcabcabcabcabcabcabc\",str2 = \"acbacbacbacbacbacbacbacbac\") == False\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopqrs\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"zzz\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaa\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"ef\") == True\n assert candidate(str1 = \"abcdeffedcba\",str2 = \"ace\") == True\n assert candidate(str1 = \"abcabcabcabcabcabcabcabcabcabc\",str2 = \"aaa\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == False\n assert candidate(str1 = \"z\",str2 = \"a\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(str1 = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"ad\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzaabcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"zaa\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"bd\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzaabcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"zabc\") == True\n assert candidate(str1 = \"aaaabbbbccccddddaaaabbbbccccdddd\",str2 = \"abcdabcd\") == True\n assert candidate(str1 = \"abcxyz\",str2 = \"abcxyz\") == True\n assert candidate(str1 = \"abcde\",str2 = \"edcba\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"mn\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"zzz\") == False\n assert candidate(str1 = \"mnopqrsmnopqrsmnopqrs\",str2 = \"mnopqrspqrsmn\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopqrstv\") == True\n assert candidate(str1 = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\",str2 = \"zyxzyxzyx\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"zzzzzzzzzz\") == False\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopqrst\") == True\n assert candidate(str1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"aaaabbbbcccc\",str2 = \"abac\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"uv\") == True\n assert candidate(str1 = \"xyzz\",str2 = \"az\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnop\") == True\n assert candidate(str1 = \"mnopqrstuvwxyzabcdefghijk\",str2 = \"mnopqrstuvwxyz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",str2 = \"zyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaaaaaa\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"az\") == True\n assert candidate(str1 = \"abz\",str2 = \"acz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"kl\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyza\",str2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"m\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"ij\") == True\n assert candidate(str1 = \"abcdexyz\",str2 = \"acz\") == True\n assert candidate(str1 = \"zzz\",str2 = \"aaa\") == True\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopqrstvw\") == True\n assert candidate(str1 = \"abcxyz\",str2 = \"zzz\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"ac\") == True\n assert candidate(str1 = \"zaaaaaaaaabcdezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"ad\") == True\n assert candidate(str1 = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",str2 = \"adadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadad\") == False\n assert candidate(str1 = \"bxyz\",str2 = \"abcd\") == False\n assert candidate(str1 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(str1 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"bdfhjlnprtvxz\") == True\n assert candidate(str1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",str2 = \"abcdefghijklmnopqrstuvwxyza\") == True\n assert candidate(str1 = \"yzabcd\",str2 = \"ad\") == True\n assert candidate(str1 = \"abcabcabcabcabcabcabcabc\",str2 = \"aaabbbccc\") == True\n assert candidate(str1 = \"aaaabbbbccccddddeeeeffffgggghhhhiiii\",str2 = \"abcdefghi\") == True\n assert candidate(str1 = \"aaaabbbbcccc\",str2 = \"abc\") == True\n assert candidate(str1 = \"abacabadabacaba\",str2 = \"abc\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"zabcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(str1 = \"mnopqrstuvwxyza\",str2 = \"mnopq\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyza\",str2 = \"xyz\") == True\n assert candidate(str1 = \"zyxwvutsrqponmlkjihgfedcba\",str2 = \"azbycxdwevfugthsisrjrqponmlkjihgfedcba\") == False\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"yz\") == True\n assert candidate(str1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",str2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(str1 = \"abcdefghijklmnopqrstuvwxyz\",str2 = \"st\") == True\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n\"ad\"", "\"zc\"\n\"ad\"", "\"ab\"\n\"d\""], "hints": ["Consider the indices we will increment separately.", "We can maintain two pointers: pointer i for str1 and pointer j for str2, while ensuring they remain within the bounds of the strings.", "If both str1[i] and str2[j] match, or if incrementing str1[i] matches str2[j], we increase both pointers; otherwise, we increment only pointer i.", "It is possible to make str2 a subsequence of str1 if j is at the end of str2, after we can no longer find a match."], "metadata": {"canonical_parameter_names": ["str1", "str2"], "leetcode_dataset_entry_point": "Solution().canMakeSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:11+00:00", "tests_total": 153, "tests_dropped": 16, "flags": [], "topic_tags": ["two-pointers", "string"]}, "language": "ruby", "interface": {"raw_signature": "def can_make_subsequence(str1, str2)", "container": null, "callable": "can_make_subsequence", "parameters": [{"name": "str1", "type": "String"}, {"name": "str2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2826, "task_id": "sorting-three-groups", "difficulty": "Medium", "problem_description": "You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.\n\nExample 1:\n\nInput: nums = [2,1,3,2,1]\nOutput: 3\nExplanation:\nOne of the optimal solutions is to remove nums[0], nums[2] and nums[3].\n\nExample 2:\n\nInput: nums = [1,3,2,1,3,3]\nOutput: 2\nExplanation:\nOne of the optimal solutions is to remove nums[1] and nums[2].\n\nExample 3:\n\nInput: nums = [2,2,2,2,3,3]\nOutput: 0\nExplanation:\nnums is already non-decreasing.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 3\n\nFollow-up: Can you come up with an algorithm that runs in O(n) time complexity?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 2, 2, 1]) == 3\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 3, 1, 2, 3]) == 2\n assert candidate(nums = [1, 1, 1]) == 0\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1]) == 4\n assert candidate(nums = [1, 2, 2, 1, 3]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 3, 3, 2, 1]) == 2\n assert candidate(nums = [1, 1, 1, 2, 2, 3]) == 0\n assert candidate(nums = [1, 3, 2, 1, 3, 3]) == 2\n assert candidate(nums = [1, 2, 2, 2, 2, 3, 3, 3]) == 0\n assert candidate(nums = [2, 1, 3, 2, 1]) == 3\n assert candidate(nums = [3, 2, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 4\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2]) == 3\n assert candidate(nums = [2, 2, 2, 2, 3, 3]) == 0\n assert candidate(nums = [3, 1, 2, 3, 1, 2]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [3, 3, 2, 2, 1]) == 3\n assert candidate(nums = [2, 2, 1, 1, 3, 3]) == 2\n assert candidate(nums = [3, 2, 1]) == 2\n assert candidate(nums = [3, 2, 1, 2, 1]) == 3\n assert candidate(nums = [3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 3, 3, 2, 2, 1, 1, 1]) == 5\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [1, 2, 3, 3, 3]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3]) == 0\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3]) == 4\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1]) == 4\n assert candidate(nums = [3, 3, 2, 2, 2, 1, 1, 1, 3, 3, 3, 2, 2, 1, 1]) == 9\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1]) == 2\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 2, 2, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 1, 3, 3, 3, 2, 2, 2, 1, 1, 1, 3, 3, 3]) == 12\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]) == 12\n assert candidate(nums = [3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 7\n assert candidate(nums = [2, 2, 3, 1, 1, 2, 3, 3, 2, 1]) == 5\n assert candidate(nums = [3, 2, 1, 2, 3, 1, 2, 3]) == 4\n assert candidate(nums = [1, 3, 2, 2, 3, 1, 3, 2, 1, 3, 2]) == 5\n assert candidate(nums = [2, 3, 2, 1, 2, 3, 2, 1, 2]) == 4\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 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]) == 0\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [3, 3, 2, 1, 1, 1, 2, 3]) == 3\n assert candidate(nums = [2, 1, 1, 2, 2, 3, 3, 3, 1, 1, 2, 2, 3]) == 5\n assert candidate(nums = [3, 3, 3, 1, 1, 1, 2, 2, 2]) == 3\n assert candidate(nums = [3, 3, 2, 2, 1, 1, 3, 3, 2, 2, 1, 1]) == 8\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]) == 13\n assert candidate(nums = [3, 3, 2, 2, 2, 1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3]) == 0\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3]) == 3\n assert candidate(nums = [1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3]) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2]) == 8\n assert candidate(nums = [1, 3, 1, 2, 3, 1, 2, 3, 1]) == 4\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 6\n assert candidate(nums = [3, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3]) == 1\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 10\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 7\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 7\n assert candidate(nums = [3, 1, 2, 2, 1, 3, 3, 2, 1, 1, 3, 3, 2, 2, 1, 1]) == 9\n assert candidate(nums = [3, 2, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 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]) == 20\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 8\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 1, 1, 3, 3, 3, 1, 1]) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 4\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [2, 1, 1, 3, 2, 3, 1, 2, 3]) == 4\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 0\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 12\n assert candidate(nums = [3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [3, 2, 1, 2, 1, 3, 1]) == 4\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 8\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]) == 0\n assert candidate(nums = [3, 1, 3, 2, 3, 1, 2, 1, 3]) == 5\n assert candidate(nums = [2, 3, 1, 3, 2, 1, 2, 3, 1, 3, 2, 1, 2, 3, 1, 3, 2, 1, 2, 3, 1, 3, 2, 1, 2, 3, 1, 3, 2, 1, 2, 3, 1]) == 21\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 1, 2, 2, 1, 1]) == 5\n assert candidate(nums = [2, 3, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 11\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 11\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 5\n assert candidate(nums = [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]) == 21\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2]) == 4\n assert candidate(nums = [3, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 6\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3]) == 4\n assert candidate(nums = [2, 2, 1, 1, 3, 3, 2, 2, 3, 3]) == 4\n assert candidate(nums = [1, 3, 3, 1, 2, 2, 1, 3, 3, 2]) == 4\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 5\n assert candidate(nums = [2, 2, 3, 1, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1]) == 9\n assert candidate(nums = [2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 19\n assert candidate(nums = [2, 3, 1, 3, 2, 1, 2, 3, 1, 3, 2, 1]) == 7\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 12\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 2, 3]) == 5\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1, 1]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 12\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 7\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 6\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 3, 3, 3, 2, 2, 2]) == 6\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2]) == 4\n assert candidate(nums = [2, 1, 2, 1, 3, 2, 1, 2, 3, 3]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [2, 2, 3, 1, 2, 3, 1, 2]) == 4\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 13\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 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]) == 0\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 8\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 10\n assert candidate(nums = [3, 2, 2, 1, 1, 1, 2, 3, 3, 3]) == 3\n assert candidate(nums = [3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3]) == 8\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 5\n assert candidate(nums = [1, 1, 1, 3, 3, 3, 2, 2, 2, 1, 1, 1, 3, 3, 3]) == 6\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 1, 1, 3]) == 4\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 6\n assert candidate(nums = [2, 3, 1, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 9\n assert candidate(nums = [2, 3, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 6\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1]) == 6\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 6\n assert candidate(nums = [2, 3, 1, 3, 2, 1, 2, 3, 1]) == 5\n", "comparison": "exact"}, "public_tests": ["[2,1,3,2,1]", "[1,3,2,1,3,3]", "[2,2,2,2,3,3]"], "hints": ["The problem asks to change the array nums to make it sorted (i.e., all the 1s are on the left of 2s, and all the 2s are on the left of 3s.).", "We can try all the possibilities to make nums indices range in [0, i) to 0 and [i, j) to 1 and [j, n) to 2. Note the ranges are left-close and right-open; each might be empty. Namely, 0 <= i <= j <= n.", "Count the changes we need for each possibility by comparing the expected and original values at each index position."], "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:04:13+00:00", "tests_total": 131, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations(nums)", "container": null, "callable": "minimum_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2827, "task_id": "number-of-beautiful-integers-in-the-range", "difficulty": "Hard", "problem_description": "You are given positive integers low, high, and k.\n\nA number is beautiful if it meets both of the following conditions:\n\n- The count of even digits in the number is equal to the count of odd digits.\n- The number is divisible by k.\n\nReturn the number of beautiful integers in the range [low, high].\n\nExample 1:\n\nInput: low = 10, high = 20, k = 3\nOutput: 2\nExplanation: There are 2 beautiful integers in the given range: [12,18].\n- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\n- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\nAdditionally we can see that:\n- 16 is not beautiful because it is not divisible by k = 3.\n- 15 is not beautiful because it does not contain equal counts even and odd digits.\nIt can be shown that there are only 2 beautiful integers in the given range.\n\nExample 2:\n\nInput: low = 1, high = 10, k = 1\nOutput: 1\nExplanation: There is 1 beautiful integer in the given range: [10].\n- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.\nIt can be shown that there is only 1 beautiful integer in the given range.\n\nExample 3:\n\nInput: low = 5, high = 5, k = 2\nOutput: 0\nExplanation: There are 0 beautiful integers in the given range.\n- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.\n\nConstraints:\n\n- 0 < low <= high <= 10^9\n- 0 < k <= 20\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(low = 100,high = 200,k = 4) == 0\n assert candidate(low = 100,high = 200,k = 5) == 0\n assert candidate(low = 10,high = 20,k = 3) == 2\n assert candidate(low = 1,high = 10,k = 1) == 1\n assert candidate(low = 100,high = 200,k = 7) == 0\n assert candidate(low = 123,high = 456,k = 7) == 0\n assert candidate(low = 1000,high = 10000,k = 7) == 483\n assert candidate(low = 123,high = 456,k = 5) == 0\n assert candidate(low = 5,high = 5,k = 2) == 0\n assert candidate(low = 1000,high = 10000,k = 11) == 460\n assert candidate(low = 999999,high = 999999,k = 1) == 0\n assert candidate(low = 123456,high = 654321,k = 15) == 11026\n assert candidate(low = 1000,high = 9999,k = 11) == 460\n assert candidate(low = 100000,high = 999999,k = 19) == 14801\n assert candidate(low = 9876543,high = 12345678,k = 16) == 44999\n assert candidate(low = 111111,high = 222222,k = 12) == 3183\n assert candidate(low = 99999,high = 100001,k = 1) == 0\n assert candidate(low = 1000000,high = 8000000,k = 7) == 0\n assert candidate(low = 100000,high = 500000,k = 19) == 6575\n assert candidate(low = 1234567,high = 7654321,k = 18) == 0\n assert candidate(low = 345678,high = 876543,k = 20) == 6510\n assert candidate(low = 5000,high = 15000,k = 13) == 147\n assert candidate(low = 100000,high = 1000000,k = 17) == 16544\n assert candidate(low = 1234,high = 5678,k = 9) == 251\n assert candidate(low = 10000000,high = 20000000,k = 9) == 306040\n assert candidate(low = 5000,high = 50000,k = 3) == 627\n assert candidate(low = 250000,high = 350000,k = 5) == 6500\n assert candidate(low = 1000000,high = 10000000,k = 19) == 0\n assert candidate(low = 50000000,high = 60000000,k = 20) == 156250\n assert candidate(low = 99999,high = 100000,k = 13) == 0\n assert candidate(low = 111111111,high = 222222222,k = 7) == 0\n assert candidate(low = 1000000,high = 2000000,k = 19) == 0\n assert candidate(low = 777777,high = 888888,k = 18) == 1644\n assert candidate(low = 1000,high = 10000,k = 12) == 276\n assert candidate(low = 987654321,high = 987654321,k = 11) == 0\n assert candidate(low = 1234,high = 5678,k = 17) == 101\n assert candidate(low = 100000000,high = 999999999,k = 3) == 0\n assert candidate(low = 123456,high = 789012,k = 17) == 12253\n assert candidate(low = 1111111,high = 2222222,k = 14) == 0\n assert candidate(low = 10000,high = 99999,k = 17) == 0\n assert candidate(low = 123456789,high = 987654321,k = 9) == 0\n assert candidate(low = 1000,high = 10000,k = 13) == 263\n assert candidate(low = 12345,high = 67890,k = 17) == 0\n assert candidate(low = 500000000,high = 600000000,k = 13) == 0\n assert candidate(low = 50000,high = 60000,k = 15) == 0\n assert candidate(low = 100000000,high = 999999999,k = 17) == 0\n assert candidate(low = 500,high = 2000,k = 17) == 21\n assert candidate(low = 11111,high = 22222,k = 14) == 0\n assert candidate(low = 123456,high = 789012,k = 15) == 13887\n assert candidate(low = 2000,high = 3000,k = 20) == 0\n assert candidate(low = 3333333,high = 4444444,k = 16) == 0\n assert candidate(low = 987654321,high = 987654321,k = 19) == 0\n assert candidate(low = 10000,high = 100000,k = 13) == 0\n assert candidate(low = 123456,high = 654321,k = 3) == 55100\n assert candidate(low = 555555,high = 666666,k = 16) == 1899\n assert candidate(low = 500000,high = 600000,k = 20) == 1875\n assert candidate(low = 111111,high = 222222,k = 13) == 2615\n assert candidate(low = 123456,high = 654321,k = 17) == 9719\n assert candidate(low = 99990,high = 100000,k = 2) == 0\n assert candidate(low = 12345678,high = 87654321,k = 16) == 1236425\n assert candidate(low = 987654,high = 9876543,k = 3) == 1120\n assert candidate(low = 1000,high = 9999,k = 12) == 276\n assert candidate(low = 123456789,high = 987654321,k = 5) == 0\n assert candidate(low = 100000,high = 1000000,k = 19) == 14801\n assert candidate(low = 123456,high = 654321,k = 19) == 8693\n assert candidate(low = 500000,high = 550000,k = 20) == 875\n assert candidate(low = 1234567,high = 8765432,k = 5) == 0\n assert candidate(low = 10000000,high = 20000000,k = 5) == 546875\n assert candidate(low = 11111111,high = 22222222,k = 7) == 426428\n assert candidate(low = 55555555,high = 88888888,k = 9) == 1034831\n assert candidate(low = 100,high = 1000,k = 3) == 0\n assert candidate(low = 999,high = 1000000,k = 13) == 21897\n assert candidate(low = 100000,high = 999999,k = 3) == 93760\n assert candidate(low = 100,high = 1000,k = 9) == 0\n assert candidate(low = 100,high = 999,k = 9) == 0\n assert candidate(low = 123456789,high = 987654321,k = 18) == 0\n assert candidate(low = 200000,high = 300000,k = 5) == 6250\n assert candidate(low = 100,high = 1000,k = 5) == 0\n assert candidate(low = 111111,high = 222222,k = 19) == 1785\n assert candidate(low = 500000,high = 600000,k = 19) == 1643\n assert candidate(low = 10000000,high = 20000000,k = 18) == 174880\n assert candidate(low = 100000,high = 999999,k = 17) == 16544\n assert candidate(low = 1000000,high = 10000000,k = 2) == 0\n assert candidate(low = 333333,high = 444444,k = 14) == 2525\n assert candidate(low = 1111111,high = 8888888,k = 20) == 0\n assert candidate(low = 10000,high = 100000,k = 11) == 0\n assert candidate(low = 100,high = 1000,k = 11) == 0\n assert candidate(low = 1234,high = 8765,k = 11) == 386\n assert candidate(low = 750000,high = 850000,k = 7) == 4287\n assert candidate(low = 1000000,high = 10000000,k = 15) == 0\n assert candidate(low = 111111,high = 222222,k = 18) == 2196\n assert candidate(low = 234567,high = 765432,k = 18) == 10488\n assert candidate(low = 11111,high = 99999,k = 13) == 0\n assert candidate(low = 333333333,high = 666666666,k = 7) == 0\n assert candidate(low = 1,high = 1000000000,k = 20) == 1105750\n assert candidate(low = 1000000,high = 2000000,k = 15) == 0\n assert candidate(low = 10000,high = 99999,k = 13) == 0\n", "comparison": "exact"}, "public_tests": ["10\n20\n3", "1\n10\n1", "5\n5\n2"], "hints": ["The intended solution uses Dynamic Programming.", "Let f(n) denote number of beautiful integers in the range [1…n] , then the answer is f(r) - f(l-1) ."], "metadata": {"canonical_parameter_names": ["low", "high", "k"], "leetcode_dataset_entry_point": "Solution().numberOfBeautifulIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:16+00:00", "tests_total": 99, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_beautiful_integers(low, high, k)", "container": null, "callable": "number_of_beautiful_integers", "parameters": [{"name": "low", "type": "Integer"}, {"name": "high", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2828, "task_id": "check-if-a-string-is-an-acronym-of-words", "difficulty": "Easy", "problem_description": "Given an array of strings words and a string s, determine if s is an acronym of words.\n\nThe string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, \"ab\" can be formed from [\"apple\", \"banana\"], but it can't be formed from [\"bear\", \"aardvark\"].\n\nReturn true if s is an acronym of words, and false otherwise.\n\nExample 1:\n\nInput: words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\nOutput: true\nExplanation: The first character in the words \"alice\", \"bob\", and \"charlie\" are 'a', 'b', and 'c', respectively. Hence, s = \"abc\" is the acronym.\n\nExample 2:\n\nInput: words = [\"an\",\"apple\"], s = \"a\"\nOutput: false\nExplanation: The first character in the words \"an\" and \"apple\" are 'a' and 'a', respectively.\nThe acronym formed by concatenating these characters is \"aa\".\nHence, s = \"a\" is not the acronym.\n\nExample 3:\n\nInput: words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\nOutput: true\nExplanation: By concatenating the first character of the words in the array, we get the string \"ngguoy\".\nHence, s = \"ngguoy\" is the acronym.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 10\n- 1 <= s.length <= 100\n- words[i] and s consist of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['different', 'words', 'here'],s = \"dwh\") == True\n assert candidate(words = ['dog', 'cat'],s = \"dc\") == True\n assert candidate(words = ['single'],s = \"s\") == True\n assert candidate(words = ['make', 'america', 'great', 'again'],s = \"mag\") == False\n assert candidate(words = ['quick', 'brown', 'fox'],s = \"qbf\") == True\n assert candidate(words = ['one', 'two', 'three', 'four'],s = \"otfh\") == False\n assert candidate(words = ['an', 'apple'],s = \"a\") == False\n assert candidate(words = ['python', 'is', 'fun'],s = \"pif\") == True\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],s = \"abcde\") == True\n assert candidate(words = ['a'],s = \"a\") == True\n assert candidate(words = ['hello', 'world'],s = \"hw\") == True\n assert candidate(words = ['never', 'gonna', 'give', 'up', 'on', 'you'],s = \"ngguoy\") == True\n assert candidate(words = ['ab', 'cd'],s = \"ac\") == True\n assert candidate(words = ['one'],s = \"o\") == True\n assert candidate(words = ['abc', 'def', 'ghi'],s = \"adg\") == True\n assert candidate(words = ['longer', 'words', 'example'],s = \"lwe\") == True\n assert candidate(words = ['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'],s = \"tqbfjotld\") == True\n assert candidate(words = ['alice', 'bob', 'charlie'],s = \"abc\") == True\n assert candidate(words = ['one', 'two', 'three'],s = \"ot\") == False\n assert candidate(words = ['unique', 'words', 'here'],s = \"uwh\") == True\n assert candidate(words = ['same', 'same', 'same'],s = \"sss\") == True\n assert candidate(words = ['hello', 'every', 'one'],s = \"heo\") == True\n assert candidate(words = ['cloud', 'computing', 'services'],s = \"ccs\") == True\n assert candidate(words = ['very', 'long', 'words', 'in', 'the', 'list'],s = \"vlwitl\") == True\n assert candidate(words = ['internet', 'of', 'things'],s = \"iot\") == True\n assert candidate(words = ['many', 'letters', 'make', 'the', 'longest', 'acronym'],s = \"mlmtla\") == True\n assert candidate(words = ['binary', 'search', 'tree'],s = \"bst\") == True\n assert candidate(words = ['repeated', 'characters', 'characters', 'in', 'words'],s = \"rcciw\") == True\n assert candidate(words = ['aardvark', 'bear', 'cat', 'dog', 'elephant', 'frog'],s = \"abcdef\") == True\n assert candidate(words = ['quick', 'brown', 'fox', 'jumps', 'over', 'lazy', 'dogs'],s = \"qbfjold\") == True\n assert candidate(words = ['cryptic', 'enigma', 'mystery'],s = \"cem\") == True\n assert candidate(words = ['gargantuan', 'colossal', 'tremendous'],s = \"gct\") == True\n assert candidate(words = ['phoenix', 'reborn', 'immortal'],s = \"pri\") == True\n assert candidate(words = ['algorithm', 'data', 'structures'],s = \"ads\") == True\n assert candidate(words = ['almost', 'correct', 'acronym'],s = \"aca\") == True\n assert candidate(words = ['various', 'lengths', 'words', 'here'],s = \"vlwh\") == True\n assert candidate(words = ['creating', 'additional', 'sample', 'data', 'for', 'testing'],s = \"cadft\") == False\n assert candidate(words = ['this', 'is', 'just', 'another', 'test', 'case'],s = \"tijatc\") == True\n assert candidate(words = ['xylophone', 'yak', 'zebra'],s = \"xyz\") == True\n assert candidate(words = ['algorithm', 'data', 'structure'],s = \"ads\") == True\n assert candidate(words = ['hello', 'world', 'this', 'is', 'a', 'test'],s = \"hwtiat\") == True\n assert candidate(words = ['panoramic', 'vista', 'landscape'],s = \"pvl\") == True\n assert candidate(words = ['united', 'states', 'of', 'america'],s = \"usoa\") == True\n assert candidate(words = ['unique', 'letters', 'every', 'word'],s = \"ulew\") == True\n assert candidate(words = ['sunshine', 'in', 'the', 'morning'],s = \"sitem\") == False\n assert candidate(words = ['mount', 'rainier', 'national', 'park'],s = \"mrnp\") == True\n assert candidate(words = ['washington', 'd', 'c'],s = \"wdc\") == True\n assert candidate(words = ['central', 'park', 'zoo'],s = \"cpz\") == True\n assert candidate(words = ['zephyr', 'whisper', 'gale'],s = \"zwg\") == True\n assert candidate(words = ['randomized', 'quick', 'sort'],s = \"rqs\") == True\n assert candidate(words = ['multiple', 'words', 'with', 'different', 'lengths', 'here'],s = \"mwdlh\") == False\n assert candidate(words = ['natural', 'language', 'processing'],s = \"nlp\") == True\n assert candidate(words = ['exquisite', 'ornate', 'lavish'],s = \"eol\") == True\n assert candidate(words = ['beautiful', 'day', 'at', 'the', 'beach'],s = \"bdatb\") == True\n assert candidate(words = ['make', 'sure', 'every', 'character', 'is', 'captured'],s = \"mseic\") == False\n assert candidate(words = ['machine', 'learning', 'models', 'are', 'awesome'],s = \"mlmaa\") == True\n assert candidate(words = ['almost', 'correct', 'but', 'one', 'letter', 'off'],s = \"accblo\") == False\n assert candidate(words = ['complex', 'example', 'with', 'repeated', 'characters'],s = \"cewrcc\") == False\n assert candidate(words = ['this', 'is', 'a', 'much', 'longer', 'acronym', 'test', 'case'],s = \"tiamalte\") == False\n assert candidate(words = ['golden', 'state', 'expressway'],s = \"gsex\") == False\n assert candidate(words = ['diamond', 'opal', 'emerald'],s = \"doe\") == True\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],s = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(words = ['multiple', 'characters', 'in', 'each', 'word'],s = \"mciew\") == True\n assert candidate(words = ['xylophone', 'yankee', 'zebra'],s = \"xyz\") == True\n assert candidate(words = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],s = \"xyzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(words = ['small', 'words', 'lead', 'to', 'big', 'results'],s = \"swlttbr\") == False\n assert candidate(words = ['random', 'words', 'for', 'testing', 'purposes'],s = \"rwftp\") == True\n assert candidate(words = ['repeated', 'words', 'words', 'repeated'],s = \"rwwr\") == True\n assert candidate(words = ['extremely', 'long', 'string', 'to', 'test'],s = \"elstt\") == True\n assert candidate(words = ['question', 'writing', 'exclusive', 'nice', 'documents'],s = \"qwend\") == True\n assert candidate(words = ['generate', 'multiple', 'complex', 'examples', 'to', 'ensure'],s = \"gmceet\") == False\n assert candidate(words = ['mismatch', 'example'],s = \"mme\") == False\n assert candidate(words = ['quick', 'brown', 'fox', 'jumps', 'over', 'lazy', 'dog'],s = \"qbfjold\") == True\n assert candidate(words = ['random', 'characters', 'generate', 'test', 'inputs'],s = \"rcgti\") == True\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same'],s = \"ssssssssss\") == True\n assert candidate(words = ['let', 'us', 'test', 'some', 'edge', 'cases', 'here'],s = \"lustsech\") == False\n assert candidate(words = ['algorithms', 'data', 'structures', 'and', 'interviews'],s = \"adssai\") == False\n assert candidate(words = ['golden', 'gate', 'bridge'],s = \"ggb\") == True\n assert candidate(words = ['cryptic', 'enigmatic', 'mysterious', 'obscure'],s = \"ceom\") == False\n assert candidate(words = ['augmented', 'reality', 'technology'],s = \"art\") == True\n assert candidate(words = ['repeated', 'repeated', 'repeated', 'repeated'],s = \"rrrr\") == True\n assert candidate(words = ['tiny', 'words'],s = \"tw\") == True\n assert candidate(words = ['xylophone', 'yellow', 'zoo'],s = \"xyz\") == True\n assert candidate(words = ['algorithms', 'data', 'structures'],s = \"ads\") == True\n assert candidate(words = ['find', 'the', 'hidden', 'pattern'],s = \"fthp\") == True\n assert candidate(words = ['machine', 'learning', 'algorithms'],s = \"mla\") == True\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],s = \"adgjmpsvy\") == True\n assert candidate(words = ['this', 'is', 'a', 'test', 'case', 'with', 'multiple', 'words'],s = \"tiatcmw\") == False\n assert candidate(words = ['deep', 'neural', 'networks'],s = \"dnn\") == True\n assert candidate(words = ['keep', 'coding', 'every', 'day'],s = \"kced\") == True\n assert candidate(words = ['a', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'],s = \"aqbfojtld\") == False\n assert candidate(words = ['fantastic', 'terrific', 'excellent'],s = \"fte\") == True\n assert candidate(words = ['quick', 'brown', 'fox', 'jumps', 'over', 'lazy', 'dog'],s = \"qbfojld\") == False\n assert candidate(words = ['quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'],s = \"qbfjotld\") == True\n assert candidate(words = ['virtual', 'reality', 'experience'],s = \"vre\") == True\n assert candidate(words = ['every', 'good', 'boy', 'does', 'fine'],s = \"egbdf\") == True\n assert candidate(words = ['new', 'york', 'city'],s = \"nyc\") == True\n", "comparison": "exact"}, "public_tests": ["[\"alice\",\"bob\",\"charlie\"]\n\"abc\"", "[\"an\",\"apple\"]\n\"a\"", "[\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"]\n\"ngguoy\""], "hints": ["Concatenate the first characters of the strings in words, and compare the resulting concatenation to s."], "metadata": {"canonical_parameter_names": ["words", "s"], "leetcode_dataset_entry_point": "Solution().isAcronym", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:18+00:00", "tests_total": 129, "tests_dropped": 32, "flags": [], "topic_tags": ["array", "string"]}, "language": "ruby", "interface": {"raw_signature": "def is_acronym(words, s)", "container": null, "callable": "is_acronym", "parameters": [{"name": "words", "type": "String[]"}, {"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2829, "task_id": "determine-the-minimum-sum-of-a-k-avoiding-array", "difficulty": "Medium", "problem_description": "You are given two integers, n and k.\n\nAn array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.\n\nReturn the minimum possible sum of a k-avoiding array of length n.\n\nExample 1:\n\nInput: n = 5, k = 4\nOutput: 18\nExplanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.\nIt can be proven that there is no k-avoiding array with a sum less than 18.\n\nExample 2:\n\nInput: n = 2, k = 6\nOutput: 3\nExplanation: We can construct the array [1,2], which has a sum of 3.\nIt can be proven that there is no k-avoiding array with a sum less than 3.\n\nConstraints:\n\n- 1 <= n, k <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,k = 8) == 10\n assert candidate(n = 3,k = 5) == 8\n assert candidate(n = 10,k = 15) == 76\n assert candidate(n = 4,k = 7) == 13\n assert candidate(n = 7,k = 10) == 36\n assert candidate(n = 2,k = 6) == 3\n assert candidate(n = 10,k = 10) == 75\n assert candidate(n = 5,k = 4) == 18\n assert candidate(n = 15,k = 8) == 153\n assert candidate(n = 10,k = 18) == 63\n assert candidate(n = 8,k = 16) == 36\n assert candidate(n = 35,k = 35) == 936\n assert candidate(n = 20,k = 30) == 280\n assert candidate(n = 15,k = 25) == 156\n assert candidate(n = 15,k = 3) == 134\n assert candidate(n = 30,k = 31) == 690\n assert candidate(n = 50,k = 1) == 1275\n assert candidate(n = 9,k = 11) == 65\n assert candidate(n = 30,k = 15) == 626\n assert candidate(n = 45,k = 30) == 1455\n assert candidate(n = 10,k = 9) == 79\n assert candidate(n = 12,k = 8) == 102\n assert candidate(n = 45,k = 40) == 1510\n assert candidate(n = 6,k = 11) == 26\n assert candidate(n = 40,k = 20) == 1090\n assert candidate(n = 12,k = 13) == 114\n assert candidate(n = 25,k = 16) == 444\n assert candidate(n = 5,k = 20) == 15\n assert candidate(n = 28,k = 18) == 558\n assert candidate(n = 25,k = 20) == 460\n assert candidate(n = 45,k = 11) == 1235\n assert candidate(n = 48,k = 49) == 1752\n assert candidate(n = 15,k = 12) == 165\n assert candidate(n = 49,k = 25) == 1669\n assert candidate(n = 15,k = 30) == 120\n assert candidate(n = 9,k = 12) == 60\n assert candidate(n = 9,k = 14) == 57\n assert candidate(n = 30,k = 25) == 681\n assert candidate(n = 10,k = 5) == 71\n assert candidate(n = 18,k = 18) == 243\n assert candidate(n = 17,k = 22) == 213\n assert candidate(n = 5,k = 10) == 15\n assert candidate(n = 49,k = 30) == 1701\n assert candidate(n = 18,k = 7) == 216\n assert candidate(n = 8,k = 9) == 52\n assert candidate(n = 30,k = 10) == 565\n assert candidate(n = 20,k = 12) == 280\n assert candidate(n = 30,k = 35) == 686\n assert candidate(n = 25,k = 30) == 465\n assert candidate(n = 35,k = 25) == 906\n assert candidate(n = 40,k = 45) == 1216\n assert candidate(n = 8,k = 12) == 46\n assert candidate(n = 15,k = 5) == 146\n assert candidate(n = 20,k = 15) == 301\n assert candidate(n = 20,k = 8) == 258\n assert candidate(n = 35,k = 20) == 855\n assert candidate(n = 30,k = 40) == 655\n assert candidate(n = 50,k = 50) == 1875\n assert candidate(n = 22,k = 27) == 370\n assert candidate(n = 45,k = 45) == 1541\n assert candidate(n = 28,k = 28) == 588\n assert candidate(n = 15,k = 20) == 165\n assert candidate(n = 45,k = 47) == 1541\n assert candidate(n = 14,k = 18) == 145\n assert candidate(n = 12,k = 18) == 102\n assert candidate(n = 8,k = 8) == 48\n assert candidate(n = 40,k = 35) == 1211\n assert candidate(n = 40,k = 30) == 1170\n assert candidate(n = 6,k = 35) == 21\n assert candidate(n = 14,k = 9) == 145\n assert candidate(n = 20,k = 25) == 306\n assert candidate(n = 40,k = 10) == 960\n assert candidate(n = 25,k = 50) == 325\n assert candidate(n = 50,k = 40) == 1845\n assert candidate(n = 45,k = 20) == 1350\n", "comparison": "exact"}, "public_tests": ["5\n4", "2\n6"], "hints": ["Try to start with the smallest possible integers.", "Check if the current number can be added to the array.", "To check if the current number can be added, keep track of already added numbers in a set.", "If the number i is added to the array, then i + k can not be added."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:20+00:00", "tests_total": 77, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_sum(n, k)", "container": null, "callable": "minimum_sum", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2830, "task_id": "maximize-the-profit-as-the-salesman", "difficulty": "Medium", "problem_description": "You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.\n\nAdditionally, you are given a 2D integer array offers where offers[i] = [start_i, end_i, gold_i], indicating that i^th buyer wants to buy all the houses from start_i to end_i for gold_i amount of gold.\n\nAs a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.\n\nReturn the maximum amount of gold you can earn.\n\nNote that different buyers can't buy the same house, and some houses may remain unsold.\n\nExample 1:\n\nInput: n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]\nOutput: 3\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,0] to 1^st buyer for 1 gold and houses in the range [1,3] to 3^rd buyer for 2 golds.\nIt can be proven that 3 is the maximum amount of gold we can achieve.\n\nExample 2:\n\nInput: n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]\nOutput: 10\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,2] to 2^nd buyer for 10 golds.\nIt can be proven that 10 is the maximum amount of gold we can achieve.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- 1 <= offers.length <= 10^5\n- offers[i].length == 3\n- 0 <= start_i <= end_i <= n - 1\n- 1 <= gold_i <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,offers = [[0, 4, 10], [1, 5, 15], [3, 7, 20], [8, 9, 5]]) == 25\n assert candidate(n = 10,offers = [[0, 4, 10], [1, 5, 11], [2, 6, 12]]) == 12\n assert candidate(n = 10,offers = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 9, 5]]) == 15\n assert candidate(n = 5,offers = [[0, 0, 1], [0, 2, 2], [1, 3, 2]]) == 3\n assert candidate(n = 8,offers = [[0, 1, 100], [1, 2, 200], [2, 3, 300], [3, 4, 400]]) == 600\n assert candidate(n = 3,offers = [[0, 0, 5], [1, 1, 5], [2, 2, 5]]) == 15\n assert candidate(n = 10,offers = [[0, 4, 5], [1, 5, 6], [2, 6, 7], [3, 7, 8]]) == 8\n assert candidate(n = 10,offers = [[0, 9, 100], [1, 8, 90], [2, 7, 80], [3, 6, 70], [4, 5, 60]]) == 100\n assert candidate(n = 10,offers = [[0, 4, 10], [1, 5, 11], [2, 6, 12], [3, 7, 13], [4, 8, 14]]) == 14\n assert candidate(n = 5,offers = [[0, 0, 1], [0, 2, 10], [1, 3, 2]]) == 10\n assert candidate(n = 7,offers = [[0, 6, 15], [1, 5, 20], [2, 4, 25], [3, 3, 30]]) == 30\n assert candidate(n = 3,offers = [[0, 0, 10], [1, 1, 10], [2, 2, 10]]) == 30\n assert candidate(n = 7,offers = [[0, 2, 3], [1, 3, 5], [2, 4, 7], [3, 5, 9], [4, 6, 11]]) == 16\n assert candidate(n = 10,offers = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]]) == 9\n assert candidate(n = 7,offers = [[0, 6, 100], [1, 3, 50], [2, 4, 60], [4, 5, 30]]) == 100\n assert candidate(n = 100000,offers = [[0, 99999, 1000], [50000, 99999, 500], [0, 49999, 500]]) == 1000\n assert candidate(n = 3,offers = [[0, 0, 5], [1, 1, 6], [2, 2, 7]]) == 18\n assert candidate(n = 100,offers = [[0, 99, 1000], [50, 99, 500], [0, 49, 500]]) == 1000\n assert candidate(n = 10,offers = [[0, 0, 5], [0, 9, 90], [1, 1, 5], [1, 8, 85], [2, 2, 5], [2, 7, 80], [3, 3, 5], [3, 6, 75], [4, 4, 5], [4, 5, 70], [5, 5, 5], [6, 6, 5], [7, 7, 5], [8, 8, 5], [9, 9, 5]]) == 110\n assert candidate(n = 50,offers = [[0, 9, 100], [10, 19, 200], [20, 29, 300], [30, 39, 400], [40, 49, 500]]) == 1500\n assert candidate(n = 15,offers = [[0, 4, 12], [1, 5, 15], [2, 6, 18], [3, 7, 20], [4, 8, 25]]) == 25\n assert candidate(n = 15,offers = [[0, 4, 10], [1, 5, 15], [2, 6, 12], [3, 7, 18], [4, 8, 14], [5, 9, 20], [6, 10, 22], [7, 11, 25], [8, 12, 30], [9, 13, 35], [10, 14, 40]]) == 70\n assert candidate(n = 100,offers = [[0, 10, 50], [20, 30, 60], [40, 50, 70], [60, 70, 80], [80, 90, 90]]) == 350\n assert candidate(n = 20,offers = [[0, 4, 50], [5, 9, 70], [10, 14, 90], [15, 19, 110]]) == 320\n assert candidate(n = 100,offers = [[0, 24, 50], [25, 49, 100], [50, 74, 150], [75, 99, 200]]) == 500\n assert candidate(n = 15,offers = [[0, 2, 5], [3, 5, 6], [6, 8, 7], [9, 11, 8], [12, 14, 9]]) == 35\n assert candidate(n = 10,offers = [[0, 2, 5], [1, 4, 10], [3, 5, 8], [4, 6, 7], [6, 8, 9]]) == 22\n assert candidate(n = 15,offers = [[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], [11, 11, 10], [12, 12, 10], [13, 13, 10], [14, 14, 10]]) == 150\n assert candidate(n = 50,offers = [[0, 49, 1000], [0, 24, 500], [25, 49, 500], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10], [6, 7, 10], [7, 8, 10], [8, 9, 10], [9, 10, 10], [10, 11, 10], [11, 12, 10], [12, 13, 10], [13, 14, 10], [14, 15, 10], [15, 16, 10], [16, 17, 10], [17, 18, 10], [18, 19, 10], [19, 20, 10], [20, 21, 10], [21, 22, 10], [22, 23, 10], [23, 24, 10], [24, 25, 10], [25, 26, 10], [26, 27, 10], [27, 28, 10], [28, 29, 10], [29, 30, 10], [30, 31, 10], [31, 32, 10], [32, 33, 10], [33, 34, 10], [34, 35, 10], [35, 36, 10], [36, 37, 10], [37, 38, 10], [38, 39, 10], [39, 40, 10], [40, 41, 10], [41, 42, 10], [42, 43, 10], [43, 44, 10], [44, 45, 10], [45, 46, 10], [46, 47, 10], [47, 48, 10], [48, 49, 10]]) == 1000\n assert candidate(n = 10,offers = [[0, 4, 10], [3, 5, 15], [5, 7, 20], [6, 9, 25], [8, 9, 5]]) == 40\n assert candidate(n = 20,offers = [[0, 4, 20], [5, 9, 30], [10, 14, 40], [15, 19, 50], [0, 9, 70], [10, 19, 80], [0, 14, 90], [5, 19, 100], [0, 19, 110]]) == 160\n assert candidate(n = 20,offers = [[0, 1, 1], [0, 19, 190], [1, 2, 2], [1, 18, 180], [2, 3, 3], [2, 17, 170], [3, 4, 4], [3, 16, 160], [4, 5, 5], [4, 15, 150], [5, 6, 6], [5, 14, 140], [6, 7, 7], [6, 13, 130], [7, 8, 8], [7, 12, 120], [8, 9, 9], [8, 11, 110], [9, 10, 10], [9, 10, 100]]) == 190\n assert candidate(n = 50,offers = [[0, 4, 10], [5, 9, 15], [10, 14, 20], [15, 19, 25], [20, 24, 30], [25, 29, 35], [30, 34, 40], [35, 39, 45], [40, 44, 50], [45, 49, 55]]) == 325\n assert candidate(n = 15,offers = [[0, 2, 100], [1, 4, 120], [2, 5, 130], [3, 6, 140], [4, 7, 150], [5, 8, 160], [6, 9, 170], [7, 10, 180], [8, 11, 190], [9, 12, 200], [10, 13, 210], [11, 14, 220], [12, 14, 230]]) == 670\n assert candidate(n = 100,offers = [[0, 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, 25, 25], [25, 26, 26], [26, 27, 27], [27, 28, 28], [28, 29, 29], [29, 30, 30], [30, 31, 31], [31, 32, 32], [32, 33, 33], [33, 34, 34], [34, 35, 35], [35, 36, 36], [36, 37, 37], [37, 38, 38], [38, 39, 39], [39, 40, 40], [40, 41, 41], [41, 42, 42], [42, 43, 43], [43, 44, 44], [44, 45, 45], [45, 46, 46], [46, 47, 47], [47, 48, 48], [48, 49, 49], [49, 50, 50], [50, 51, 51], [51, 52, 52], [52, 53, 53], [53, 54, 54], [54, 55, 55], [55, 56, 56], [56, 57, 57], [57, 58, 58], [58, 59, 59], [59, 60, 60], [60, 61, 61], [61, 62, 62], [62, 63, 63], [63, 64, 64], [64, 65, 65], [65, 66, 66], [66, 67, 67], [67, 68, 68], [68, 69, 69], [69, 70, 70], [70, 71, 71], [71, 72, 72], [72, 73, 73], [73, 74, 74], [74, 75, 75], [75, 76, 76], [76, 77, 77], [77, 78, 78], [78, 79, 79], [79, 80, 80], [80, 81, 81], [81, 82, 82], [82, 83, 83], [83, 84, 84], [84, 85, 85], [85, 86, 86], [86, 87, 87], [87, 88, 88], [88, 89, 89], [89, 90, 90], [90, 91, 91], [91, 92, 92], [92, 93, 93], [93, 94, 94], [94, 95, 95], [95, 96, 96], [96, 97, 97], [97, 98, 98], [98, 99, 99]]) == 2500\n assert candidate(n = 20,offers = [[0, 3, 7], [1, 4, 8], [2, 5, 9], [3, 6, 10], [4, 7, 11], [5, 8, 12], [6, 9, 13], [7, 10, 14]]) == 24\n assert candidate(n = 20,offers = [[0, 0, 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]]) == 210\n assert candidate(n = 8,offers = [[0, 1, 100], [1, 2, 100], [2, 3, 100], [3, 4, 100], [4, 5, 100], [5, 6, 100], [6, 7, 100]]) == 400\n assert candidate(n = 50,offers = [[0, 4, 100], [10, 14, 150], [20, 24, 200], [30, 34, 250], [40, 44, 300], [1, 5, 90], [11, 15, 140], [21, 25, 190], [31, 35, 240], [41, 45, 290]]) == 1000\n assert candidate(n = 50,offers = [[0, 24, 100], [25, 49, 150], [0, 49, 200], [24, 25, 50], [12, 37, 120]]) == 250\n assert candidate(n = 50,offers = [[0, 1, 1], [2, 3, 1], [4, 5, 1], [6, 7, 1], [8, 9, 1], [10, 11, 1], [12, 13, 1], [14, 15, 1], [16, 17, 1], [18, 19, 1], [20, 21, 1], [22, 23, 1], [24, 25, 1], [26, 27, 1], [28, 29, 1], [30, 31, 1], [32, 33, 1], [34, 35, 1], [36, 37, 1], [38, 39, 1], [40, 41, 1], [42, 43, 1], [44, 45, 1], [46, 47, 1], [48, 49, 1]]) == 25\n assert candidate(n = 25,offers = [[0, 3, 30], [4, 7, 40], [8, 11, 50], [12, 15, 60], [16, 19, 70], [20, 23, 80], [24, 24, 10]]) == 340\n assert candidate(n = 100,offers = [[0, 9, 50], [10, 19, 100], [20, 29, 150], [30, 39, 200], [40, 49, 250], [50, 59, 300], [60, 69, 350], [70, 79, 400], [80, 89, 450], [90, 99, 500]]) == 2750\n assert candidate(n = 10,offers = [[0, 0, 1], [0, 9, 10], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 9, 9]]) == 25\n assert candidate(n = 20,offers = [[0, 4, 10], [5, 9, 15], [10, 14, 20], [15, 19, 25]]) == 70\n assert candidate(n = 20,offers = [[0, 3, 50], [2, 5, 30], [4, 7, 60], [6, 9, 40], [8, 11, 70], [10, 13, 50], [12, 15, 60], [14, 17, 80], [16, 19, 70]]) == 310\n assert candidate(n = 20,offers = [[0, 5, 100], [1, 4, 80], [2, 3, 60], [3, 6, 70], [4, 7, 90], [5, 8, 120], [6, 9, 110], [7, 10, 130], [8, 11, 150], [9, 12, 140], [10, 13, 170], [11, 14, 160], [12, 15, 190], [13, 16, 180], [14, 17, 210], [15, 18, 200], [16, 19, 230], [17, 19, 220]]) == 740\n assert candidate(n = 20,offers = [[0, 1, 10], [2, 3, 20], [1, 2, 30], [0, 3, 40], [4, 5, 50], [6, 7, 60], [8, 9, 70], [10, 11, 80], [12, 13, 90], [14, 15, 100], [16, 17, 110], [18, 19, 120]]) == 720\n assert candidate(n = 20,offers = [[0, 5, 10], [1, 6, 15], [2, 7, 20], [3, 8, 25], [4, 9, 30], [5, 10, 35], [6, 11, 40], [7, 12, 45], [8, 13, 50], [9, 14, 55], [10, 15, 60], [11, 16, 65], [12, 17, 70], [13, 18, 75], [14, 19, 80]]) == 150\n assert candidate(n = 15,offers = [[0, 2, 10], [3, 5, 15], [6, 8, 20], [9, 11, 25], [12, 14, 30]]) == 100\n assert candidate(n = 15,offers = [[0, 0, 100], [1, 1, 100], [2, 2, 100], [3, 3, 100], [4, 4, 100], [5, 5, 100], [6, 6, 100], [7, 7, 100], [8, 8, 100], [9, 9, 100], [10, 10, 100], [11, 11, 100], [12, 12, 100], [13, 13, 100], [14, 14, 100]]) == 1500\n assert candidate(n = 50,offers = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 9, 5], [10, 11, 6], [12, 13, 7], [14, 15, 8], [16, 17, 9], [18, 19, 10], [20, 21, 11], [22, 23, 12], [24, 25, 13], [26, 27, 14], [28, 29, 15], [30, 31, 16], [32, 33, 17], [34, 35, 18], [36, 37, 19], [38, 39, 20], [40, 41, 21], [42, 43, 22], [44, 45, 23], [46, 47, 24], [48, 49, 25]]) == 325\n assert candidate(n = 75,offers = [[0, 24, 300], [25, 49, 400], [50, 74, 500], [0, 49, 700], [25, 74, 600], [0, 74, 800], [0, 24, 200], [25, 49, 300], [50, 74, 400]]) == 1200\n assert candidate(n = 75,offers = [[0, 10, 50], [11, 20, 55], [21, 30, 60], [31, 40, 65], [41, 50, 70], [51, 60, 75], [61, 70, 80], [71, 74, 85], [0, 74, 200], [1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9], [9, 10, 11], [11, 12, 12], [13, 14, 13], [15, 16, 14], [17, 18, 15], [19, 20, 16], [21, 22, 17], [23, 24, 18], [25, 26, 19], [27, 28, 20], [29, 30, 21], [31, 32, 22], [33, 34, 23], [35, 36, 24], [37, 38, 25], [39, 40, 26], [41, 42, 27], [43, 44, 28], [45, 46, 29], [47, 48, 30], [49, 50, 31], [51, 52, 32], [53, 54, 33], [55, 56, 34], [57, 58, 35], [59, 60, 36], [61, 62, 37], [63, 64, 38], [65, 66, 39], [67, 68, 40], [69, 70, 41], [71, 72, 42], [73, 74, 43]]) == 930\n assert candidate(n = 15,offers = [[0, 2, 10], [2, 4, 15], [3, 5, 10], [5, 7, 20], [7, 9, 10], [8, 10, 15], [10, 12, 20], [12, 14, 10]]) == 60\n assert candidate(n = 50,offers = [[0, 10, 500], [1, 9, 450], [2, 8, 400], [3, 7, 350], [4, 6, 300], [5, 5, 250], [6, 15, 550], [7, 14, 500], [8, 13, 450], [9, 12, 400], [10, 11, 350], [11, 20, 600], [12, 19, 550], [13, 18, 500], [14, 17, 450], [15, 16, 400], [16, 25, 650], [17, 24, 600], [18, 23, 550], [19, 22, 500], [20, 21, 450], [21, 30, 700], [22, 29, 650], [23, 28, 600], [24, 27, 550], [25, 26, 500], [26, 35, 750], [27, 34, 700], [28, 33, 650], [29, 32, 600], [30, 31, 550], [31, 40, 800], [32, 39, 750], [33, 38, 700], [34, 37, 650], [35, 36, 600]]) == 3750\n assert candidate(n = 25,offers = [[0, 1, 10], [0, 2, 15], [1, 3, 20], [1, 4, 25], [2, 5, 30], [2, 6, 35], [3, 7, 40], [3, 8, 45], [4, 9, 50], [4, 10, 55], [5, 11, 60], [5, 12, 65], [6, 13, 70], [6, 14, 75], [7, 15, 80], [7, 16, 85], [8, 17, 90], [8, 18, 95], [9, 19, 100], [9, 20, 105], [10, 21, 110], [10, 22, 115], [11, 23, 120], [11, 24, 125], [12, 24, 130]]) == 215\n assert candidate(n = 80,offers = [[0, 19, 200], [20, 39, 300], [40, 59, 400], [60, 79, 500]]) == 1400\n assert candidate(n = 15,offers = [[0, 4, 20], [1, 3, 15], [2, 6, 30], [3, 5, 25], [4, 8, 40], [5, 9, 35], [6, 10, 50], [7, 11, 45], [8, 12, 60], [9, 13, 55], [10, 14, 70], [11, 14, 65]]) == 140\n assert candidate(n = 120,offers = [[0, 29, 300], [30, 59, 400], [60, 89, 500], [90, 119, 600]]) == 1800\n assert candidate(n = 100,offers = [[0, 9, 100], [10, 19, 200], [20, 29, 300], [30, 39, 400], [40, 49, 500]]) == 1500\n assert candidate(n = 100,offers = [[0, 24, 50], [25, 49, 60], [50, 74, 70], [75, 99, 80], [0, 49, 150], [25, 74, 160], [50, 99, 170], [0, 74, 250], [25, 99, 260], [0, 99, 350]]) == 350\n assert candidate(n = 15,offers = [[0, 2, 5], [1, 4, 7], [2, 6, 8], [3, 7, 9], [4, 8, 10], [5, 9, 11], [6, 10, 12], [7, 11, 13], [8, 12, 14], [9, 13, 15]]) == 30\n assert candidate(n = 10,offers = [[0, 2, 3], [0, 5, 10], [0, 8, 12], [0, 9, 15], [1, 3, 4], [1, 4, 8], [1, 5, 10], [1, 6, 12], [1, 7, 14], [1, 8, 16], [1, 9, 18], [2, 4, 6], [2, 5, 9], [2, 6, 12], [2, 7, 15], [2, 8, 18], [2, 9, 21], [3, 5, 8], [3, 6, 11], [3, 7, 14], [3, 8, 17], [3, 9, 20], [4, 6, 10], [4, 7, 13], [4, 8, 16], [4, 9, 19], [5, 7, 12], [5, 8, 15], [5, 9, 18], [6, 8, 14], [6, 9, 17], [7, 9, 16]]) == 30\n assert candidate(n = 10,offers = [[0, 4, 15], [1, 3, 10], [2, 5, 8], [3, 6, 12], [5, 9, 20]]) == 35\n assert candidate(n = 80,offers = [[0, 9, 100], [10, 19, 120], [20, 29, 110], [30, 39, 130], [40, 49, 140], [50, 59, 150], [60, 69, 160], [70, 79, 170]]) == 1080\n assert candidate(n = 7,offers = [[0, 0, 5], [0, 6, 10], [1, 1, 6], [2, 2, 7], [3, 3, 8], [4, 4, 9], [5, 5, 10], [6, 6, 11]]) == 56\n assert candidate(n = 100,offers = [[0, 49, 500], [50, 99, 1000]]) == 1500\n assert candidate(n = 50,offers = [[0, 4, 50], [5, 9, 60], [10, 14, 40], [15, 19, 70], [20, 24, 65], [25, 29, 55], [30, 34, 80], [35, 39, 75], [40, 44, 90], [45, 49, 85]]) == 670\n assert candidate(n = 50,offers = [[0, 9, 100], [10, 19, 150], [20, 29, 200], [30, 39, 250], [40, 49, 300]]) == 1000\n assert candidate(n = 75,offers = [[0, 24, 300], [25, 49, 400], [50, 74, 500]]) == 1200\n assert candidate(n = 12,offers = [[0, 11, 50], [1, 10, 45], [2, 9, 40], [3, 8, 35], [4, 7, 30], [5, 6, 25]]) == 50\n assert candidate(n = 15,offers = [[0, 4, 20], [3, 7, 30], [6, 9, 40], [8, 12, 50], [11, 14, 60]]) == 120\n assert candidate(n = 25,offers = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70], [7, 8, 80], [8, 9, 90], [9, 10, 100], [10, 11, 110], [11, 12, 120], [12, 13, 130], [13, 14, 140], [14, 15, 150], [15, 16, 160], [16, 17, 170], [17, 18, 180], [18, 19, 190], [19, 20, 200], [20, 21, 210], [21, 22, 220], [22, 23, 230], [23, 24, 240], [24, 24, 250]]) == 1690\n assert candidate(n = 100,offers = [[0, 20, 100], [25, 45, 150], [50, 70, 200], [75, 99, 250]]) == 700\n", "comparison": "exact"}, "public_tests": ["5\n[[0,0,1],[0,2,2],[1,3,2]]", "5\n[[0,0,1],[0,2,10],[1,3,2]]"], "hints": ["The intended solution uses a dynamic programming approach to solve the problem.", "Sort the array offers by start_i.", "Let dp[i] = { the maximum amount of gold if the sold houses are in the range [0 … i] }."], "metadata": {"canonical_parameter_names": ["n", "offers"], "leetcode_dataset_entry_point": "Solution().maximizeTheProfit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:23+00:00", "tests_total": 90, "tests_dropped": 15, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "dynamic-programming", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximize_the_profit(n, offers)", "container": null, "callable": "maximize_the_profit", "parameters": [{"name": "n", "type": "Integer"}, {"name": "offers", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2831, "task_id": "find-the-longest-equal-subarray", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer k.\n\nA subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.\n\nReturn the length of the longest possible equal subarray after deleting at most k elements from nums.\n\nA subarray is a contiguous, possibly empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,2,3,1,3], k = 3\nOutput: 3\nExplanation: It's optimal to delete the elements at index 2 and index 4.\nAfter deleting them, nums becomes equal to [1, 3, 3, 3].\nThe longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.\nIt can be proven that no longer equal subarrays can be created.\n\nExample 2:\n\nInput: nums = [1,1,2,2,1,1], k = 2\nOutput: 4\nExplanation: It's optimal to delete the elements at index 2 and index 3.\nAfter deleting them, nums becomes equal to [1, 1, 1, 1].\nThe array itself is an equal subarray, so the answer is 4.\nIt can be proven that no longer equal subarrays can be created.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= nums.length\n- 0 <= k <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3],k = 3) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],k = 4) == 3\n assert candidate(nums = [1, 2, 2, 1, 2, 2],k = 2) == 4\n assert candidate(nums = [10, 1, 2, 2, 1, 3, 3, 3, 3, 4],k = 4) == 4\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 1, 1],k = 2) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 2) == 4\n assert candidate(nums = [5, 5, 5, 1, 5, 5],k = 1) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 4) == 1\n assert candidate(nums = [1, 2],k = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 1\n assert candidate(nums = [4, 4, 4, 1, 1],k = 2) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 1, 1, 1, 2, 2],k = 3) == 6\n assert candidate(nums = [1],k = 0) == 1\n assert candidate(nums = [1, 3, 2, 3, 1, 3],k = 3) == 3\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3],k = 2) == 2\n assert candidate(nums = [5, 5, 5, 5, 5],k = 2) == 5\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 2],k = 2) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 0) == 10\n assert candidate(nums = [1, 1, 2, 2, 1, 1],k = 2) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],k = 0) == 5\n assert candidate(nums = [7, 7, 7, 1, 7, 7, 7, 7],k = 4) == 7\n assert candidate(nums = [1, 1, 1, 1, 1],k = 0) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 0) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],k = 3) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 2, 2, 1, 1, 1, 1],k = 4) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 15) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6],k = 5) == 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, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8],k = 20) == 7\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 7) == 5\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],k = 8) == 4\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],k = 8) == 5\n assert candidate(nums = [1, 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],k = 25) == 10\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 5) == 29\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 20) == 11\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],k = 10) == 30\n assert candidate(nums = [1, 1, 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, 6, 6, 6],k = 15) == 10\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],k = 15) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 30) == 4\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5, 5, 5],k = 2) == 4\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9],k = 6) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 10) == 4\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],k = 10) == 45\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],k = 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, 1, 1, 1, 1, 1, 1],k = 15) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 4) == 5\n assert candidate(nums = [5, 5, 4, 4, 5, 5, 5, 3, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5],k = 7) == 14\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5],k = 10) == 7\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7],k = 8) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 9) == 11\n assert candidate(nums = [1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 10\n assert candidate(nums = [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],k = 20) == 3\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 15) == 11\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],k = 15) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1],k = 5) == 6\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],k = 20) == 4\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2],k = 7) == 4\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2],k = 6) == 6\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1],k = 12) == 15\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1],k = 12) == 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, 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) == 44\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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 15) == 10\n assert candidate(nums = [10, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 10) == 10\n assert candidate(nums = [5, 5, 5, 5, 1, 1, 5, 5, 5, 5, 1, 1, 5, 5, 5, 5],k = 6) == 12\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\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],k = 0) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 8) == 2\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3],k = 8) == 8\n assert candidate(nums = [1, 2, 2, 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],k = 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],k = 20) == 3\n assert candidate(nums = [3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 13\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3],k = 20) == 4\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 = 8) == 9\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],k = 10) == 2\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],k = 10) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 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, 1, 2, 3, 4, 5],k = 15) == 2\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],k = 18) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 15) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 5) == 2\n assert candidate(nums = [1, 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],k = 25) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 15) == 4\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10],k = 10) == 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, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 30) == 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],k = 15) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 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, 1, 2, 3, 4, 5],k = 15) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4],k = 6) == 8\n assert candidate(nums = [5, 5, 4, 4, 4, 5, 5, 5, 5, 5],k = 4) == 7\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1],k = 10) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],k = 7) == 8\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 = 10) == 1\n assert candidate(nums = [1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 1, 1],k = 4) == 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, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 15) == 16\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, 9, 9, 9, 10, 10, 10],k = 10) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 3) == 4\n assert candidate(nums = [1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2],k = 5) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5],k = 5) == 10\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 5) == 3\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],k = 5) == 6\n assert candidate(nums = [1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4],k = 5) == 5\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 5) == 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, 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 = 20) == 21\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 15\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],k = 12) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4],k = 8) == 4\n", "comparison": "exact"}, "public_tests": ["[1,3,2,3,1,3]\n3", "[1,1,2,2,1,1]\n2"], "hints": ["For each number x in nums, create a sorted list indices_x of all indices i such that nums[i] == x.", "On every indices_x, execute a sliding window technique.", "For each indices_x, find i, j such that (indices_x[j] - indices_x[i]) - (j - i) <= k and j - i + 1 is maximized.", "The answer would be the maximum of j - i + 1 for all indices_x."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().longestEqualSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:25+00:00", "tests_total": 120, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def longest_equal_subarray(nums, k)", "container": null, "callable": "longest_equal_subarray", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2833, "task_id": "furthest-point-from-origin", "difficulty": "Easy", "problem_description": "You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.\n\nIn the i^th move, you can choose one of the following directions:\n\n- move to the left if moves[i] = 'L' or moves[i] = '_'\n- move to the right if moves[i] = 'R' or moves[i] = '_'\n\nReturn the distance from the origin of the furthest point you can get to after n moves.\n\nExample 1:\n\nInput: moves = \"L_RL__R\"\nOutput: 3\nExplanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves \"LLRLLLR\".\n\nExample 2:\n\nInput: moves = \"_R__LL_\"\nOutput: 5\nExplanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves \"LRLLLLL\".\n\nExample 3:\n\nInput: moves = \"_______\"\nOutput: 7\nExplanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves \"RRRRRRR\".\n\nConstraints:\n\n- 1 <= moves.length == n <= 50\n- moves consists only of characters 'L', 'R' and '_'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(moves = \"________R\") == 9\n assert candidate(moves = \"L_RL__R\") == 3\n assert candidate(moves = \"L_____R\") == 5\n assert candidate(moves = \"R_L_R_L\") == 3\n assert candidate(moves = \"L________\") == 9\n assert candidate(moves = \"R________\") == 9\n assert candidate(moves = \"LLRRLLR\") == 1\n assert candidate(moves = \"LLRRRRR\") == 3\n assert candidate(moves = \"LRLRLRL\") == 1\n assert candidate(moves = \"_L_R_L_\") == 5\n assert candidate(moves = \"LLLLLLL\") == 7\n assert candidate(moves = \"________L\") == 9\n assert candidate(moves = \"__R____\") == 7\n assert candidate(moves = \"R_R_R_R\") == 7\n assert candidate(moves = \"____L__\") == 7\n assert candidate(moves = \"R_____L\") == 5\n assert candidate(moves = \"RLRLRLR\") == 1\n assert candidate(moves = \"_R__LL_\") == 5\n assert candidate(moves = \"_______\") == 7\n assert candidate(moves = \"RRRRRRR\") == 7\n assert candidate(moves = \"_________\") == 9\n assert candidate(moves = \"RRLLLLL\") == 3\n assert candidate(moves = \"_________________R_________________\") == 35\n assert candidate(moves = \"R__R__R__R__R__R__R__R__R\") == 25\n assert candidate(moves = \"LLLLLLLLLLL\") == 11\n assert candidate(moves = \"RR____LLRRRR\") == 8\n assert candidate(moves = \"RL_RLR_R_\") == 5\n assert candidate(moves = \"RLRLRLRLR\") == 1\n assert candidate(moves = \"LLLLLLLLLLLLLLLLLLLLLLLL\") == 24\n assert candidate(moves = \"R_L_R_L_R_L_R_L_R_L_R_L\") == 11\n assert candidate(moves = \"LR_LRLRL_\") == 3\n assert candidate(moves = \"________L________R________\") == 24\n assert candidate(moves = \"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 40\n assert candidate(moves = \"RRRR_LLLL_\") == 2\n assert candidate(moves = \"LLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRR\") == 6\n assert candidate(moves = \"R________R\") == 10\n assert candidate(moves = \"_LRLRLRLRLRLRLRLRLR_\") == 2\n assert candidate(moves = \"RRRRRRRRRRRRRRLLLLLLLLLLLLLLLLLLLL\") == 6\n assert candidate(moves = \"L_L_L_L_L\") == 9\n assert candidate(moves = \"___________\") == 11\n assert candidate(moves = \"L_____L_____L_____L_____L_\") == 26\n assert candidate(moves = \"RRRRLLLLLLLLLLLLLLLL\") == 12\n assert candidate(moves = \"_LRR_LRR_LRR_LRR_LRR_LRR_\") == 13\n assert candidate(moves = \"RRRR_LLLLL\") == 2\n assert candidate(moves = \"R__L__R__L__R__L__R__L__R__L__R__L__\") == 24\n assert candidate(moves = \"_LLRRLLRR__L\") == 4\n assert candidate(moves = \"_L__R_L__R_L\") == 8\n assert candidate(moves = \"________________R__________L______________\") == 40\n assert candidate(moves = \"LLLLRRRRR\") == 1\n assert candidate(moves = \"L_R__R_L__R\") == 7\n assert candidate(moves = \"R_RR_R_RRRR\") == 11\n assert candidate(moves = \"_L_L_L_L_L_\") == 11\n assert candidate(moves = \"LR_LR_LR_LR_LR_LR_LR_LR_\") == 8\n assert candidate(moves = \"_____________\") == 13\n assert candidate(moves = \"LR_RLR_RLR_RLR_RLR_RLR_RLR\") == 12\n assert candidate(moves = \"LR_LRLRLRLRLRLRLRLRLRLRLRL\") == 2\n assert candidate(moves = \"RL_RL_RL_RL_RL_RL_RL_RL_RL_RL\") == 9\n assert candidate(moves = \"_________________L_________________\") == 35\n assert candidate(moves = \"LRRLRRLLRRLLRR\") == 2\n assert candidate(moves = \"________________________\") == 24\n assert candidate(moves = \"____R____L____\") == 12\n assert candidate(moves = \"R____R____R____R____R_____\") == 26\n assert candidate(moves = \"LRLRLRLRLR\") == 0\n assert candidate(moves = \"L__R__L__R__L__R__L__R__\") == 16\n assert candidate(moves = \"____L___R____\") == 11\n assert candidate(moves = \"_L__R__L__R_\") == 8\n assert candidate(moves = \"LLRR__LLRR__LLRR\") == 4\n assert candidate(moves = \"_L_R_L_R_L_R\") == 6\n assert candidate(moves = \"LR_LR_LR_LR_LR_LR_LR\") == 6\n assert candidate(moves = \"________R_________\") == 18\n assert candidate(moves = \"R______L_\") == 7\n assert candidate(moves = \"_________L_________\") == 19\n assert candidate(moves = \"L_____R_____L_____R\") == 15\n assert candidate(moves = \"_L_L_L_L_L_L_L_L_L_L_L_L_\") == 25\n assert candidate(moves = \"RRRRRRRRRRRRRRRRRRRRRRRR\") == 24\n assert candidate(moves = \"L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R\") == 17\n assert candidate(moves = \"RL_RLR_RLR_RLR_RLR_RLR_R\") == 12\n assert candidate(moves = \"____L_____\") == 10\n assert candidate(moves = \"LLLLRRRRLLLLRRRRLLLLRRRRLLLLRRRRLLLL\") == 4\n assert candidate(moves = \"LLLLLLRRRRRR\") == 0\n assert candidate(moves = \"_L______R\") == 7\n assert candidate(moves = \"LLLL____R\") == 7\n assert candidate(moves = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 40\n assert candidate(moves = \"LL_R__R_L__L___\") == 11\n assert candidate(moves = \"L_____L_____L_____\") == 18\n assert candidate(moves = \"LLLLLLLLRRRRRRRRRRLLLLRRRRRRRR\") == 6\n assert candidate(moves = \"_________________________\") == 25\n assert candidate(moves = \"R_R_R_R_R_R_R\") == 13\n assert candidate(moves = \"RL_RL_RL_RL\") == 3\n assert candidate(moves = \"_R_L_R_L_R_\") == 7\n assert candidate(moves = \"_L__R__L__R__L__R__L__R__L__R_\") == 20\n assert candidate(moves = \"___________________________\") == 27\n assert candidate(moves = \"R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R\") == 23\n assert candidate(moves = \"__L__R__L__\") == 9\n assert candidate(moves = \"LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL\") == 1\n assert candidate(moves = \"R______L_____\") == 11\n assert candidate(moves = \"L_R__R_L__R_L_R_L__R_L_R_\") == 15\n assert candidate(moves = \"_LL_R_L_R_L_\") == 8\n assert candidate(moves = \"RRRRRRRRRRR\") == 11\n assert candidate(moves = \"RLLLLRRRRRRR\") == 4\n assert candidate(moves = \"L___R___L___R___L___R___\") == 18\n assert candidate(moves = \"____LR____LR____LR____LR__\") == 18\n assert candidate(moves = \"____R____R____L\") == 13\n assert candidate(moves = \"_____________L____________R_____________\") == 38\n assert candidate(moves = \"LRRLRLRLRLRLRLRLRLRL\") == 0\n assert candidate(moves = \"L_R_L_R_L_R\") == 5\n assert candidate(moves = \"L___R___L___R___L___R___L\") == 19\n assert candidate(moves = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 42\n assert candidate(moves = \"________________\") == 16\n assert candidate(moves = \"L_L_L_L_L_L_L_L_L_L_L_L\") == 23\n assert candidate(moves = \"LRRLRRLLRRRL\") == 2\n assert candidate(moves = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 44\n assert candidate(moves = \"RR___L__L___R_R\") == 11\n assert candidate(moves = \"RRRRRRRR____\") == 12\n assert candidate(moves = \"R_______L\") == 7\n assert candidate(moves = \"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 44\n assert candidate(moves = \"LR_RLR_LRLRLRLRLRL\") == 2\n assert candidate(moves = \"____R_______\") == 12\n assert candidate(moves = \"R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L\") == 17\n assert candidate(moves = \"__LLRR__L__\") == 7\n assert candidate(moves = \"L__L__L__L__L__L__L__L__L\") == 25\n assert candidate(moves = \"L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R_L_R\") == 23\n assert candidate(moves = \"L_____R_____L\") == 11\n assert candidate(moves = \"RR_RRRRRLLLL_LLLLLLLLL\") == 8\n assert candidate(moves = \"_L_L_L_L_L_L_L\") == 14\n assert candidate(moves = \"LRLRLRLRLRLR\") == 0\n assert candidate(moves = \"_LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL_\") == 3\n assert candidate(moves = \"R___L___R___L___R___L___R\") == 19\n assert candidate(moves = \"LLLLLLLLLLLLLLLLRRRRRRRRRR\") == 6\n assert candidate(moves = \"RRRRLLLLLLLLRRRRLLLLLLLLRRRRLLLLLLLL\") == 12\n assert candidate(moves = \"L_______R\") == 7\n assert candidate(moves = \"LLLLLLLL____\") == 12\n assert candidate(moves = \"R_______________________L\") == 23\n assert candidate(moves = \"LRRLRRLRL\") == 1\n assert candidate(moves = \"L_R_L_R_L_R_L_R_\") == 8\n assert candidate(moves = \"R_R_R_R_R\") == 9\n assert candidate(moves = \"_R_L__R_L__R\") == 8\n assert candidate(moves = \"RRRRRLLLLLL\") == 1\n assert candidate(moves = \"R__L__R__L__R__L__R__L__\") == 16\n assert candidate(moves = \"RRRRRRLLLLLLRRRRRRLLLLLL___\") == 3\n assert candidate(moves = \"L_L_L_L_L_L_L_L_L\") == 17\n assert candidate(moves = \"_L__R__L__R__L\") == 10\n assert candidate(moves = \"RRRR____L\") == 7\n assert candidate(moves = \"____L_R____R\") == 10\n assert candidate(moves = \"_LRRRR______L___\") == 12\n assert candidate(moves = \"_L___R__L_\") == 8\n assert candidate(moves = \"R_L_R_L_R_L\") == 5\n assert candidate(moves = \"LRRLRLRLRL\") == 0\n assert candidate(moves = \"LLLLLLLRRRR\") == 3\n", "comparison": "exact"}, "public_tests": ["\"L_RL__R\"", "\"_R__LL_\"", "\"_______\""], "hints": ["In an optimal answer, all occurrences of '_’ will be replaced with the same character.", "Replace all characters of '_’ with the character that occurs the most."], "metadata": {"canonical_parameter_names": ["moves"], "leetcode_dataset_entry_point": "Solution().furthestDistanceFromOrigin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:30+00:00", "tests_total": 151, "tests_dropped": 2, "flags": [], "topic_tags": ["string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def furthest_distance_from_origin(moves)", "container": null, "callable": "furthest_distance_from_origin", "parameters": [{"name": "moves", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2834, "task_id": "find-the-minimum-possible-sum-of-a-beautiful-array", "difficulty": "Medium", "problem_description": "You are given positive integers n and target.\n\nAn array nums is beautiful if it meets the following conditions:\n\n- nums.length == n.\n- nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.\n\nReturn the minimum possible sum that a beautiful array could have modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 2, target = 3\nOutput: 4\nExplanation: We can see that nums = [1,3] is beautiful.\n- The array nums has length n = 2.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 4 is the minimum possible sum that a beautiful array could have.\n\nExample 2:\n\nInput: n = 3, target = 3\nOutput: 8\nExplanation: We can see that nums = [1,3,4] is beautiful.\n- The array nums has length n = 3.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 8 is the minimum possible sum that a beautiful array could have.\n\nExample 3:\n\nInput: n = 1, target = 1\nOutput: 1\nExplanation: We can see, that nums = [1] is beautiful.\n\nConstraints:\n\n- 1 <= n <= 10^9\n- 1 <= target <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,target = 3) == 4\n assert candidate(n = 100,target = 100) == 7500\n assert candidate(n = 5,target = 8) == 18\n assert candidate(n = 1,target = 1) == 1\n assert candidate(n = 1000000000,target = 1000000000) == 750000042\n assert candidate(n = 3,target = 3) == 8\n assert candidate(n = 10,target = 15) == 76\n assert candidate(n = 10,target = 5) == 71\n assert candidate(n = 5,target = 10) == 15\n assert candidate(n = 100,target = 10) == 5430\n assert candidate(n = 50,target = 100) == 1275\n assert candidate(n = 100,target = 1) == 5050\n assert candidate(n = 10000,target = 10001) == 75005000\n assert candidate(n = 10000,target = 20000) == 50005000\n assert candidate(n = 5,target = 2) == 15\n assert candidate(n = 200,target = 250) == 29400\n assert candidate(n = 500,target = 250) == 171750\n assert candidate(n = 500,target = 10) == 127230\n assert candidate(n = 100000000,target = 10000000) == 916675007\n assert candidate(n = 10000000,target = 5000000) == 997018757\n assert candidate(n = 200000000,target = 150000000) == 769375007\n assert candidate(n = 80,target = 40) == 4380\n assert candidate(n = 1000000000,target = 1) == 21\n assert candidate(n = 1000,target = 500) == 687250\n assert candidate(n = 3000,target = 1500) == 6186750\n assert candidate(n = 3,target = 7) == 6\n assert candidate(n = 10000,target = 5000) == 68747500\n assert candidate(n = 1000,target = 1001) == 750500\n assert candidate(n = 100,target = 50) == 6850\n assert candidate(n = 500000000,target = 750000000) == 921875014\n assert candidate(n = 10000,target = 7500) == 73436250\n assert candidate(n = 100,target = 101) == 7550\n assert candidate(n = 75,target = 50) == 4050\n assert candidate(n = 1000,target = 1000) == 750000\n assert candidate(n = 20,target = 15) == 301\n assert candidate(n = 999999999,target = 1000000000) == 250000050\n assert candidate(n = 100000000,target = 100000000) == 947500007\n assert candidate(n = 500000000,target = 500000000) == 687500014\n assert candidate(n = 300,target = 301) == 67650\n assert candidate(n = 500000,target = 100000) == 499798971\n assert candidate(n = 30,target = 25) == 681\n assert candidate(n = 1000,target = 2000) == 500500\n assert candidate(n = 75,target = 100) == 4075\n assert candidate(n = 999999999,target = 999999999) == 750000049\n assert candidate(n = 1000000,target = 500000) == 499745191\n assert candidate(n = 200,target = 300) == 27550\n assert candidate(n = 5000000,target = 1000000) == 997896757\n assert candidate(n = 2,target = 5) == 3\n assert candidate(n = 300,target = 150) == 61800\n assert candidate(n = 50,target = 10) == 1455\n assert candidate(n = 25000000,target = 75000000) == 10312500\n assert candidate(n = 100000,target = 50000) == 874974958\n assert candidate(n = 999999999,target = 2) == 28\n assert candidate(n = 75,target = 150) == 2850\n assert candidate(n = 200,target = 150) == 29350\n assert candidate(n = 200000000,target = 800000000) == 960000007\n assert candidate(n = 500,target = 500) == 187500\n assert candidate(n = 50000,target = 25000) == 718737493\n assert candidate(n = 50,target = 20) == 1635\n assert candidate(n = 1000,target = 100) == 547050\n assert candidate(n = 750,target = 150) == 331575\n assert candidate(n = 25000000,target = 50000000) == 10312500\n assert candidate(n = 50,target = 25) == 1731\n assert candidate(n = 75000000,target = 25000000) == 949843757\n assert candidate(n = 150,target = 300) == 11325\n assert candidate(n = 500,target = 100) == 147300\n assert candidate(n = 250000000,target = 500000000) == 906250007\n assert candidate(n = 1000,target = 505) == 688996\n assert candidate(n = 1000000,target = 1000000) == 999994757\n assert candidate(n = 75,target = 75) == 4256\n assert candidate(n = 5000,target = 2000) == 16498500\n assert candidate(n = 100000000,target = 150000000) == 976875007\n assert candidate(n = 99999999,target = 100000000) == 797500008\n assert candidate(n = 5000,target = 5001) == 18752500\n assert candidate(n = 999999999,target = 500000000) == 687500050\n assert candidate(n = 90,target = 90) == 6075\n assert candidate(n = 100000,target = 100001) == 500049951\n assert candidate(n = 1,target = 1000000000) == 1\n assert candidate(n = 10,target = 11) == 80\n assert candidate(n = 50000000,target = 25000000) == 975468757\n assert candidate(n = 25,target = 15) == 451\n assert candidate(n = 150,target = 75) == 15506\n assert candidate(n = 10000,target = 10000) == 75000000\n assert candidate(n = 100000000,target = 1) == 15000000\n assert candidate(n = 500000000,target = 1000000000) == 375000007\n assert candidate(n = 500,target = 300) == 177400\n assert candidate(n = 150,target = 200) == 16275\n assert candidate(n = 1,target = 2) == 1\n assert candidate(n = 200,target = 200) == 30000\n assert candidate(n = 50,target = 30) == 1765\n assert candidate(n = 50000,target = 10000) == 474979993\n", "comparison": "exact"}, "public_tests": ["2\n3", "3\n3", "1\n1"], "hints": ["Greedily try to add the smallest possible number in the array nums, such that nums contains distinct positive integers, and there are no two indices i and j with nums[i] + nums[j] == target."], "metadata": {"canonical_parameter_names": ["n", "target"], "leetcode_dataset_entry_point": "Solution().minimumPossibleSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:32+00:00", "tests_total": 91, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_possible_sum(n, target)", "container": null, "callable": "minimum_possible_sum", "parameters": [{"name": "n", "type": "Integer"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2835, "task_id": "minimum-operations-to-form-subsequence-with-target-sum", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.\n\nIn one operation, you must apply the following changes to the array:\n\n- Choose any element of the array nums[i] such that nums[i] > 1.\n- Remove nums[i] from the array.\n- Add two occurrences of nums[i] / 2 to the end of nums.\n\nReturn the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [1,2,8], target = 7\nOutput: 1\nExplanation: In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].\nAt this stage, nums contains the subsequence [1,2,4] which sums up to 7.\nIt can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.\n\nExample 2:\n\nInput: nums = [1,32,1,2], target = 12\nOutput: 2\nExplanation: In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].\nIn the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]\nAt this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.\nIt can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.\n\nExample 3:\n\nInput: nums = [1,32,1], target = 35\nOutput: -1\nExplanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 2^30\n- nums consists only of non-negative powers of two.\n- 1 <= target < 2^31\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 4, 8, 16],target = 31) == -1\n assert candidate(nums = [32, 16, 8, 4, 2, 1],target = 63) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],target = 4) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 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],target = 15) == 0\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1],target = 255) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 2147483647) == 0\n assert candidate(nums = [1, 32, 1, 2],target = 12) == 2\n assert candidate(nums = [64],target = 32) == 1\n assert candidate(nums = [1024],target = 512) == 1\n assert candidate(nums = [1, 2, 8],target = 7) == 1\n assert candidate(nums = [1],target = 1) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],target = 1048575) == 0\n assert candidate(nums = [2, 4, 8, 16],target = 30) == 0\n assert candidate(nums = [1, 32, 1],target = 35) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 5) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64],target = 63) == 6\n assert candidate(nums = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1023) == 0\n assert candidate(nums = [1024],target = 1) == 10\n assert candidate(nums = [1073741824],target = 1073741824) == 0\n assert candidate(nums = [2, 2, 2, 2],target = 8) == 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],target = 16) == 0\n assert candidate(nums = [16, 8, 4, 2, 1],target = 31) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2047) == 0\n assert candidate(nums = [1, 1, 1, 1],target = 1) == 0\n assert candidate(nums = [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144],target = 524287) == -1\n assert candidate(nums = [512, 512, 256, 256, 128, 128, 64, 64, 32, 32, 16, 16, 8, 8, 4, 4, 2, 2, 1, 1],target = 1023) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1535) == 0\n assert candidate(nums = [2, 16, 32, 64, 128, 256, 512],target = 1015) == -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],target = 20) == 0\n assert candidate(nums = [1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],target = 65535) == 0\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],target = 100) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 100) == -1\n assert candidate(nums = [1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024],target = 4095) == 10\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 2147483647) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],target = 65535) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 1025) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 511) == 0\n assert candidate(nums = [256, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 512) == 0\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128],target = 1023) == -1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2],target = 1000) == 0\n assert candidate(nums = [16, 8, 4, 2, 1, 1, 1],target = 31) == 0\n assert candidate(nums = [256, 128, 64, 32, 16, 8, 4, 2, 1],target = 448) == 0\n assert candidate(nums = [1, 4, 16, 64, 256, 1024, 4096, 16384],target = 12345) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 4095) == -1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1536) == 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],target = 15) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],target = 32767) == 0\n assert candidate(nums = [16, 16, 16, 16, 8, 8, 8, 8, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1],target = 63) == 0\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],target = 4095) == -1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = 1024) == -1\n assert candidate(nums = [1, 4, 16, 64, 256, 1024, 4096],target = 2047) == 11\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 32, 32, 32, 32, 64, 64, 64, 64, 128, 128, 128, 128],target = 1023) == -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],target = 10) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 2147483647) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 5) == 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, 1, 1],target = 30) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 1023) == 10\n assert candidate(nums = [2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 2047) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64],target = 127) == -1\n assert candidate(nums = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],target = 32767) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 1073741823) == 0\n assert candidate(nums = [2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 2047) == 0\n assert candidate(nums = [1024, 512, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1, 1, 1, 1],target = 2047) == 0\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16],target = 31) == 0\n assert candidate(nums = [8, 4, 2, 1, 1, 1, 1, 1],target = 13) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2047) == -1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64, 128, 128, 128, 256, 256, 256, 512, 512, 512, 1024, 1024, 1024],target = 2047) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 15) == 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],target = 1023) == -1\n assert candidate(nums = [16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 32767) == 0\n assert candidate(nums = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 2147483647) == -1\n assert candidate(nums = [512, 512, 512, 512],target = 1024) == 0\n assert candidate(nums = [1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 2147483647) == 0\n assert candidate(nums = [1, 4, 16, 64, 256],target = 255) == 7\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256],target = 255) == 8\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1024) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],target = 32767) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 1023) == 10\n assert candidate(nums = [1, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144],target = 524287) == -1\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024, 2048, 2048, 4096, 4096, 8192, 8192, 16384, 16384, 32768, 32768, 65536, 65536, 131072, 131072, 262144, 262144, 524288, 524288, 1048576, 1048576, 2097152, 2097152, 4194304, 4194304, 8388608, 8388608, 16777216, 16777216, 33554432, 33554432, 67108864, 67108864, 134217728, 134217728, 268435456, 268435456, 536870912, 536870912, 1073741824, 1073741824],target = 1073741823) == 0\n assert candidate(nums = [1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2047) == 0\n assert candidate(nums = [1, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 2147483647) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],target = 4095) == 0\n assert candidate(nums = [1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2047) == 0\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2047) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],target = 15000) == 0\n assert candidate(nums = [2, 4, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512],target = 1023) == 2\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024],target = 2047) == 0\n assert candidate(nums = [512, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1023) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 32, 32, 32, 32, 64, 64, 64, 64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512, 1024, 1024, 1024, 1024, 2048, 2048, 2048, 2048, 4096, 4096, 4096, 4096, 8192, 8192, 8192, 8192, 16384, 16384, 16384, 16384, 32768, 32768, 32768, 32768, 65536, 65536, 65536, 65536, 131072, 131072, 131072, 131072, 262144, 262144, 262144, 262144, 524288, 524288, 524288, 524288, 1048576, 1048576, 1048576, 1048576, 2097152, 2097152, 2097152, 2097152, 4194304, 4194304, 4194304, 4194304, 8388608, 8388608, 8388608, 8388608, 16777216, 16777216, 16777216, 16777216, 33554432, 33554432, 33554432, 33554432, 67108864, 67108864, 67108864, 67108864, 134217728, 134217728, 134217728, 134217728, 268435456, 268435456, 268435456, 268435456, 536870912, 536870912, 536870912, 536870912, 1073741824, 1073741824, 1073741824, 1073741824],target = 2147483647) == 0\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],target = 1024) == 0\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024, 2048, 2048, 4096, 4096, 8192, 8192, 16384, 16384, 32768, 32768, 65536, 65536, 131072, 131072, 262144, 262144, 524288, 524288, 1048576, 1048576, 2097152, 2097152, 4194304, 4194304, 8388608, 8388608, 16777216, 16777216, 33554432, 33554432, 67108864, 67108864, 134217728, 134217728, 268435456, 268435456, 536870912, 536870912, 1073741824, 1073741824],target = 2147483647) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = 8) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 2047) == 0\n assert candidate(nums = [32, 32, 16, 16, 8, 8, 4, 4, 2, 2, 1, 1],target = 48) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],target = 8191) == 0\n assert candidate(nums = [4, 16, 64, 256],target = 317) == 6\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2047) == -1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],target = 2097151) == 21\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],target = 4095) == -1\n assert candidate(nums = [262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1048575) == -1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1023) == 0\n assert candidate(nums = [1, 1, 1, 1, 16],target = 15) == 2\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576],target = 1048575) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],target = 8191) == -1\n assert candidate(nums = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1],target = 1023) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 1023) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 1023) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],target = 8191) == 13\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],target = 31) == -1\n assert candidate(nums = [512, 512, 512, 512, 512, 512, 512, 512, 512, 512],target = 2048) == 0\n assert candidate(nums = [4, 8, 16, 32, 64],target = 100) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,8]\n7", "[1,32,1,2]\n12", "[1,32,1]\n35"], "hints": ["if target > sum(nums[i]) , return -1. Otherwise, an answer exists", "Solve the problem for each set bit of target, independently, from least significant to most significant bit.", "For each set bit of target from least to most significant, let X = sum(nums[i]) for nums[i] <= 2^bit.", "if X >= 2^bit, repeatedly select the maximum nums[i] such that nums[i]<=2^bit that has not been selected yet, until the sum of selected elements equals 2^bit. The selected nums[i] will be part of the subsequence whose elements sum to target, so those elements can not be selected again.", "Otherwise, select the smallest nums[i] such that nums[i] > 2^bit, delete nums[i] and add two occurences of nums[i]/2. Without moving to the next bit, go back to the step in hint 3."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:34+00:00", "tests_total": 117, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums, target)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2836, "task_id": "maximize-value-of-function-in-a-ball-passing-game", "difficulty": "Hard", "problem_description": "You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.\n\nYou choose the starting player, i. The game proceeds as follows: player i passes the ball to player receiver[i], who then passes it to receiver[receiver[i]], and so on, for k passes in total. The game's score is the sum of the indices of the players who touched the ball, including repetitions, i.e. i + receiver[i] + receiver[receiver[i]] + ... + receiver^(k)[i].\n\nReturn the maximum possible score.\n\nNotes:\n\n- receiver may contain duplicates.\n- receiver[i] may be equal to i.\n\nExample 1:\n\nInput: receiver = [2,0,1], k = 4\nOutput: 6\nExplanation:\nStarting with player i = 2 the initial score is 2:\n\nPass | Sender Index | Receiver Index | Score\n1 | 2 | 1 | 3\n2 | 1 | 0 | 3\n3 | 0 | 2 | 5\n4 | 2 | 1 | 6\n\nExample 2:\n\nInput: receiver = [1,1,1,2,3], k = 3\nOutput: 10\nExplanation:\nStarting with player i = 4 the initial score is 4:\n\nPass | Sender Index | Receiver Index | Score\n1 | 4 | 3 | 7\n2 | 3 | 2 | 9\n3 | 2 | 1 | 10\n\nConstraints:\n\n- 1 <= receiver.length == n <= 10^5\n- 0 <= receiver[i] <= n - 1\n- 1 <= k <= 10^10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(receiver = [4, 3, 2, 1, 0],k = 10) == 24\n assert candidate(receiver = [4, 3, 2, 1, 0],k = 5) == 12\n assert candidate(receiver = [3, 3, 3, 3],k = 10) == 33\n assert candidate(receiver = [0, 2, 1, 0],k = 5) == 9\n assert candidate(receiver = [1, 1, 1, 2, 3],k = 3) == 10\n assert candidate(receiver = [0, 2, 1, 3],k = 2) == 9\n assert candidate(receiver = [2, 0, 1],k = 4) == 6\n assert candidate(receiver = [1, 2, 3, 4, 0],k = 2) == 9\n assert candidate(receiver = [3, 2, 1, 0],k = 5) == 9\n assert candidate(receiver = [1, 2, 3, 4, 0],k = 10) == 24\n assert candidate(receiver = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1000000000) == 9\n assert candidate(receiver = [1, 2, 0, 3, 4, 5],k = 15) == 80\n assert candidate(receiver = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 5000000000) == 2500000009\n assert candidate(receiver = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4],k = 1000000000) == 11500000019\n assert candidate(receiver = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 100000) == 1900019\n assert candidate(receiver = [0, 0, 0, 0, 0],k = 1000000000) == 4\n assert candidate(receiver = [2, 0, 1, 3, 4, 5, 3, 2],k = 100) == 505\n assert candidate(receiver = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6],k = 875000000) == 6562500009\n assert candidate(receiver = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0],k = 1000000) == 9500019\n assert candidate(receiver = [1, 0, 3, 2, 5, 4],k = 999999999) == 4500000000\n assert candidate(receiver = [2, 3, 4, 5, 0, 1],k = 123456789) == 370370372\n assert candidate(receiver = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0],k = 1000000000) == 9500000019\n assert candidate(receiver = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 10000000000) == 9\n assert candidate(receiver = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 54\n assert candidate(receiver = [0, 1, 0, 1, 0, 1],k = 5000000000) == 5000000005\n assert candidate(receiver = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8],k = 200) == 1709\n assert candidate(receiver = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 20) == 99\n assert candidate(receiver = [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5],k = 1000) == 5011\n assert candidate(receiver = [3, 0, 1, 2, 7, 8, 9, 10, 5, 6, 11, 4],k = 500) == 4011\n assert candidate(receiver = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 0],k = 8765432109) == 43827160558\n assert candidate(receiver = [5, 6, 0, 1, 3, 2, 4],k = 100) == 356\n assert candidate(receiver = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1000000) == 9500019\n assert candidate(receiver = [4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4],k = 100000) == 200016\n assert candidate(receiver = [1, 0, 2, 4, 3, 5, 6, 7, 8, 9],k = 50) == 459\n assert candidate(receiver = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 10],k = 1000000000) == 12500000015\n assert candidate(receiver = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 1000000000) == 3000000009\n assert candidate(receiver = [2, 3, 4, 5, 6, 0, 1, 7, 8, 9],k = 20) == 189\n assert candidate(receiver = [1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2],k = 1000000) == 1000020\n assert candidate(receiver = [0, 0, 0, 0, 0, 0],k = 999999999) == 5\n assert candidate(receiver = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],k = 10000000000) == 80000000008\n assert candidate(receiver = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1000) == 4509\n assert candidate(receiver = [4, 3, 2, 1, 0, 4, 3, 2, 1, 0],k = 10000000000) == 20000000009\n assert candidate(receiver = [2, 3, 4, 5, 6, 7, 8, 9, 0, 1],k = 10000000) == 50000009\n assert candidate(receiver = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == 27\n assert candidate(receiver = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 1000000000) == 500000009\n assert candidate(receiver = [2, 3, 4, 5, 6, 1, 0],k = 10000000000) == 30000000006\n assert candidate(receiver = [5, 4, 3, 2, 1, 0, 6, 7, 8, 9],k = 10000000000) == 90000000009\n assert candidate(receiver = [3, 1, 2, 0, 5, 4, 7, 6, 9, 8],k = 1000) == 8509\n assert candidate(receiver = [2, 3, 4, 5, 6, 7, 8, 9, 0, 1],k = 1500000000) == 7500000009\n assert candidate(receiver = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8],k = 50) == 434\n assert candidate(receiver = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18],k = 100000000) == 1850000019\n assert candidate(receiver = [5, 3, 0, 1, 4, 2],k = 500000000) == 2000000004\n assert candidate(receiver = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 999999999) == 4000000005\n assert candidate(receiver = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],k = 100000) == 800008\n assert candidate(receiver = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 50) == 260\n assert candidate(receiver = [3, 2, 1, 0, 7, 6, 5, 4],k = 10000000000) == 55000000007\n assert candidate(receiver = [0, 0, 1, 2, 3, 4],k = 1000000000) == 15\n assert candidate(receiver = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],k = 1250000000) == 10000000008\n assert candidate(receiver = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9],k = 625000000) == 5625000009\n assert candidate(receiver = [3, 0, 1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18],k = 1000000000) == 18500000019\n assert candidate(receiver = [5, 3, 0, 2, 1, 4],k = 10000000000) == 25000000005\n assert candidate(receiver = [4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15],k = 900000000) == 15300000019\n assert candidate(receiver = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 500000000) == 9\n assert candidate(receiver = [2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 9999999999) == 190000000000\n assert candidate(receiver = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],k = 1000) == 13022\n assert candidate(receiver = [2, 3, 4, 5, 6, 7, 8, 9, 0, 1],k = 25) == 134\n assert candidate(receiver = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49],k = 10000000000) == 490000000049\n assert candidate(receiver = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],k = 10000000000) == 45000000009\n assert candidate(receiver = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 500000000) == 9500000019\n assert candidate(receiver = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 1000000000) == 19000000019\n assert candidate(receiver = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1000000000) == 9500000019\n assert candidate(receiver = [7, 6, 5, 4, 3, 2, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15],k = 9876543210) == 148148148165\n assert candidate(receiver = [5, 4, 3, 2, 1, 0],k = 15) == 40\n assert candidate(receiver = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 500000000) == 2250000009\n assert candidate(receiver = [0, 0, 0, 0, 0],k = 100000) == 4\n assert candidate(receiver = [5, 6, 0, 1, 4, 3, 2],k = 15) == 64\n assert candidate(receiver = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5000) == 25009\n assert candidate(receiver = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1000000000) == 5000000010\n assert candidate(receiver = [7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 11, 10, 15, 14, 13, 12],k = 100000000) == 1350000015\n assert candidate(receiver = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 50) == 34\n assert candidate(receiver = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 109\n assert candidate(receiver = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4],k = 750000000) == 4875000009\n assert candidate(receiver = [5, 4, 3, 2, 1, 0],k = 500000000) == 1250000005\n assert candidate(receiver = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0],k = 5000000000) == 10000000008\n assert candidate(receiver = [2, 0, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 0],k = 1000000000) == 17500000018\n assert candidate(receiver = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5000000000) == 5000000019\n assert candidate(receiver = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 9999999999) == 45000000000\n assert candidate(receiver = [5, 4, 3, 2, 1, 0],k = 100) == 255\n assert candidate(receiver = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 1000000000) == 9000000009\n assert candidate(receiver = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],k = 50) == 408\n assert candidate(receiver = [2, 1, 0, 3, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],k = 100000000) == 1450000015\n assert candidate(receiver = [5, 4, 3, 2, 1, 0],k = 10000000000) == 25000000005\n assert candidate(receiver = [0, 3, 6, 9, 2, 5, 8, 1, 4, 7],k = 50) == 259\n assert candidate(receiver = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10],k = 999999999) == 14500000000\n assert candidate(receiver = [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 100000) == 1500015\n assert candidate(receiver = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 1000) == 3009\n assert candidate(receiver = [5, 4, 3, 2, 1, 0],k = 1000000000) == 2500000005\n assert candidate(receiver = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1000000000) == 4500000009\n assert candidate(receiver = [0, 2, 3, 4, 5, 6, 7, 8, 9, 1],k = 100) == 512\n assert candidate(receiver = [3, 0, 1, 2, 5, 4],k = 100) == 455\n assert candidate(receiver = [3, 2, 1, 0, 7, 6, 5, 4, 9, 8],k = 50) == 434\n assert candidate(receiver = [1, 2, 0, 4, 5, 3, 6, 7, 8, 9],k = 50) == 459\n assert candidate(receiver = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10000000000) == 10000000019\n assert candidate(receiver = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 1000000000) == 1000000009\n assert candidate(receiver = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 999999999) == 500000008\n assert candidate(receiver = [1, 2, 3, 4, 5, 0, 1, 2, 3, 4],k = 9999999999) == 25000000010\n assert candidate(receiver = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1000000000) == 18500000019\n assert candidate(receiver = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8],k = 100000) == 850009\n", "comparison": "exact"}, "public_tests": ["[2,0,1]\n4", "[1,1,1,2,3]\n3"], "hints": ["We can solve the problem using binary lifting.", "For each player with id x and for every i in the range [0, ceil(log_2k)], we can determine the last receiver's id and compute the sum of player ids who receive the ball after 2^i passes, starting from x.", "Let last_receiver[x][i] = the last receiver's id after 2^i passes, and sum[x][i] = the sum of player ids who receive the ball after 2^i passes. For all x in the range [0, n - 1], last_receiver[x][0] = receiver[x], and sum[x][0] = receiver[x].", "Then for i in range [1, ceil(log_2k)], last_receiver[x][i] = last_receiver[last_receiver[x][i - 1]][i - 1] and sum[x][i] = sum[x][i - 1] + sum[last_receiver[x][i - 1]][i - 1], for all x in the range [0, n - 1].", "Starting from each player id x, we can now go through the powers of 2 in the binary representation of k and make jumps corresponding to each power, using the pre-computed values, to compute f(x).", "The answer is the maximum f(x) from each player id."], "metadata": {"canonical_parameter_names": ["receiver", "k"], "leetcode_dataset_entry_point": "Solution().getMaxFunctionValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:37+00:00", "tests_total": 109, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def get_max_function_value(receiver, k)", "container": null, "callable": "get_max_function_value", "parameters": [{"name": "receiver", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2839, "task_id": "check-if-strings-can-be-made-equal-with-operations-i", "difficulty": "Easy", "problem_description": "You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.\n\nYou can apply the following operation on any of the two strings any number of times:\n\n- Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.\n\nExample 1:\n\nInput: s1 = \"abcd\", s2 = \"cdab\"\nOutput: true\nExplanation: We can do the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbad\".\n- Choose the indices i = 1, j = 3. The resulting string is s1 = \"cdab\" = s2.\n\nExample 2:\n\nInput: s1 = \"abcd\", s2 = \"dacb\"\nOutput: false\nExplanation: It is not possible to make the two strings equal.\n\nConstraints:\n\n- s1.length == s2.length == 4\n- s1 and s2 consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"abcd\",s2 = \"cdab\") == True\n assert candidate(s1 = \"acbd\",s2 = \"bdac\") == True\n assert candidate(s1 = \"abab\",s2 = \"abcd\") == False\n assert candidate(s1 = \"abdc\",s2 = \"cdab\") == False\n assert candidate(s1 = \"abcd\",s2 = \"dacb\") == False\n assert candidate(s1 = \"abab\",s2 = \"baba\") == False\n assert candidate(s1 = \"abcd\",s2 = \"abcd\") == True\n assert candidate(s1 = \"aabb\",s2 = \"bbaa\") == True\n assert candidate(s1 = \"abcd\",s2 = \"dcba\") == False\n assert candidate(s1 = \"zzzz\",s2 = \"zzzz\") == True\n assert candidate(s1 = \"zabc\",s2 = \"cbaz\") == False\n assert candidate(s1 = \"efef\",s2 = \"fefo\") == False\n assert candidate(s1 = \"abcd\",s2 = \"dcab\") == False\n assert candidate(s1 = \"abcd\",s2 = \"dbca\") == False\n assert candidate(s1 = \"qrst\",s2 = \"tqsr\") == False\n assert candidate(s1 = \"mnop\",s2 = \"ponq\") == False\n assert candidate(s1 = \"ijkl\",s2 = \"lkji\") == False\n assert candidate(s1 = \"abcd\",s2 = \"cabd\") == False\n assert candidate(s1 = \"wxxy\",s2 = \"yxwx\") == False\n assert candidate(s1 = \"abcd\",s2 = \"abdc\") == False\n assert candidate(s1 = \"qrst\",s2 = \"tsqr\") == False\n assert candidate(s1 = \"abba\",s2 = \"baab\") == True\n assert candidate(s1 = \"abcd\",s2 = \"cadb\") == False\n assert candidate(s1 = \"abcd\",s2 = \"cdac\") == False\n assert candidate(s1 = \"wxyz\",s2 = \"yxwz\") == True\n assert candidate(s1 = \"abac\",s2 = \"cabd\") == False\n assert candidate(s1 = \"mnop\",s2 = \"npom\") == False\n assert candidate(s1 = \"ijkl\",s2 = \"lkij\") == False\n assert candidate(s1 = \"efgh\",s2 = \"fegh\") == False\n assert candidate(s1 = \"pqrs\",s2 = \"rqps\") == True\n assert candidate(s1 = \"uvwx\",s2 = \"xwvu\") == False\n assert candidate(s1 = \"wxyz\",s2 = \"xywz\") == False\n assert candidate(s1 = \"xyxy\",s2 = \"yxyx\") == False\n assert candidate(s1 = \"efgh\",s2 = \"hgfq\") == False\n assert candidate(s1 = \"abcd\",s2 = \"dbac\") == False\n assert candidate(s1 = \"aabb\",s2 = \"abab\") == False\n assert candidate(s1 = \"mnop\",s2 = \"ponm\") == False\n assert candidate(s1 = \"abcd\",s2 = \"bdca\") == False\n assert candidate(s1 = \"qrst\",s2 = \"tsrf\") == False\n assert candidate(s1 = \"qrst\",s2 = \"tsrq\") == False\n assert candidate(s1 = \"abcd\",s2 = \"badc\") == False\n assert candidate(s1 = \"qrst\",s2 = \"tqrs\") == False\n assert candidate(s1 = \"abcd\",s2 = \"adcb\") == True\n assert candidate(s1 = \"mnop\",s2 = \"pmno\") == False\n assert candidate(s1 = \"abba\",s2 = \"baba\") == False\n assert candidate(s1 = \"abcd\",s2 = \"bacd\") == False\n assert candidate(s1 = \"abca\",s2 = \"acba\") == False\n assert candidate(s1 = \"abcd\",s2 = \"bdac\") == False\n assert candidate(s1 = \"mnop\",s2 = \"onmp\") == True\n assert candidate(s1 = \"lwxy\",s2 = \"xylw\") == True\n assert candidate(s1 = \"zzza\",s2 = \"zzaa\") == False\n assert candidate(s1 = \"abcd\",s2 = \"acdb\") == False\n assert candidate(s1 = \"zzzz\",s2 = \"zzaz\") == False\n assert candidate(s1 = \"aabb\",s2 = \"abba\") == True\n assert candidate(s1 = \"abcd\",s2 = \"acbd\") == False\n assert candidate(s1 = \"wxyz\",s2 = \"xyzw\") == False\n assert candidate(s1 = \"xxyz\",s2 = \"zyxz\") == False\n assert candidate(s1 = \"abcd\",s2 = \"dabc\") == False\n assert candidate(s1 = \"pqrs\",s2 = \"rspq\") == True\n assert candidate(s1 = \"zyxw\",s2 = \"xwyz\") == False\n assert candidate(s1 = \"abcd\",s2 = \"abca\") == False\n assert candidate(s1 = \"abca\",s2 = \"cabd\") == False\n assert candidate(s1 = \"mnop\",s2 = \"nopm\") == False\n", "comparison": "exact"}, "public_tests": ["\"abcd\"\n\"cdab\"", "\"abcd\"\n\"dacb\""], "hints": ["Since the strings are very small you can try a brute-force approach.", "There are only 2 different swaps that are possible in a string."], "metadata": {"canonical_parameter_names": ["s1", "s2"], "leetcode_dataset_entry_point": "Solution().canBeEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:42+00:00", "tests_total": 63, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def can_be_equal(s1, s2)", "container": null, "callable": "can_be_equal", "parameters": [{"name": "s1", "type": "String"}, {"name": "s2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2840, "task_id": "check-if-strings-can-be-made-equal-with-operations-ii", "difficulty": "Medium", "problem_description": "You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.\n\nYou can apply the following operation on any of the two strings any number of times:\n\n- Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.\n\nExample 1:\n\nInput: s1 = \"abcdba\", s2 = \"cabdab\"\nOutput: true\nExplanation: We can apply the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbadba\".\n- Choose the indices i = 2, j = 4. The resulting string is s1 = \"cbbdaa\".\n- Choose the indices i = 1, j = 5. The resulting string is s1 = \"cabdab\" = s2.\n\nExample 2:\n\nInput: s1 = \"abe\", s2 = \"bea\"\nOutput: false\nExplanation: It is not possible to make the two strings equal.\n\nConstraints:\n\n- n == s1.length == s2.length\n- 1 <= n <= 10^5\n- s1 and s2 consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"aabbcc\",s2 = \"bbaacc\") == True\n assert candidate(s1 = \"abcdabcd\",s2 = \"dcbadcba\") == False\n assert candidate(s1 = \"abcdba\",s2 = \"cabdab\") == True\n assert candidate(s1 = \"a\",s2 = \"a\") == True\n assert candidate(s1 = \"hello\",s2 = \"olelh\") == False\n assert candidate(s1 = \"aabbcc\",s2 = \"acbbca\") == True\n assert candidate(s1 = \"abcd\",s2 = \"cdab\") == True\n assert candidate(s1 = \"abcdef\",s2 = \"fedcba\") == False\n assert candidate(s1 = \"xyz\",s2 = \"zyx\") == True\n assert candidate(s1 = \"ab\",s2 = \"ba\") == False\n assert candidate(s1 = \"abe\",s2 = \"bea\") == False\n assert candidate(s1 = \"abcd\",s2 = \"dcba\") == False\n assert candidate(s1 = \"aabbccddeeff\",s2 = \"ffeeddccbbaa\") == True\n assert candidate(s1 = \"mississippi\",s2 = \"ssimmppiiss\") == False\n assert candidate(s1 = \"palindrome\",s2 = \"paldinrome\") == False\n assert candidate(s1 = \"abcdefghijklmnopqrstuvwxyz\",s2 = \"zyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(s1 = \"racecar\",s2 = \"acecarr\") == False\n assert candidate(s1 = \"abcdefghijabcdefghijabcdefghij\",s2 = \"abcdefghijabcdefghijabcdefghjk\") == False\n assert candidate(s1 = \"level\",s2 = \"level\") == True\n assert candidate(s1 = \"deified\",s2 = \"deified\") == True\n assert candidate(s1 = \"aabbcc\",s2 = \"ccbbaa\") == True\n assert candidate(s1 = \"pqrstuv\",s2 = \"upqrsvt\") == False\n assert candidate(s1 = \"rotor\",s2 = \"rotar\") == False\n assert candidate(s1 = \"abcdefg\",s2 = \"gfedcba\") == True\n assert candidate(s1 = \"racecar\",s2 = \"carrace\") == False\n assert candidate(s1 = \"abababab\",s2 = \"babababa\") == False\n assert candidate(s1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",s2 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s1 = \"zxcvbnm\",s2 = \"mnbvcxz\") == True\n assert candidate(s1 = \"abcdefgh\",s2 = \"gfehdcba\") == False\n assert candidate(s1 = \"abcdefghijabcdefghijabcdefghij\",s2 = \"bacdfegihjbacdfegihjbacdfegihj\") == False\n assert candidate(s1 = \"aaaabbbbccccddddeeeeffffgggghhhh\",s2 = \"hhhhggggffffeeeeddddbbbbccccaaaa\") == True\n assert candidate(s1 = \"hellohello\",s2 = \"ehlolhloel\") == False\n assert candidate(s1 = \"abcdabcdabcdabcd\",s2 = \"bacdbacdbacdbacd\") == False\n assert candidate(s1 = \"banana\",s2 = \"ananab\") == False\n assert candidate(s1 = \"zzzzzzzzzz\",s2 = \"zzzzzzzzzz\") == True\n assert candidate(s1 = \"abacabadabacabad\",s2 = \"babaacabadabacab\") == False\n assert candidate(s1 = \"abcdabcdabcdabcd\",s2 = \"ddddccccbbbbaaaa\") == False\n assert candidate(s1 = \"aabbccddeeff\",s2 = \"abbaccddffee\") == True\n assert candidate(s1 = \"xyzxyzxyzxyz\",s2 = \"zyxzyxzyxzyx\") == True\n assert candidate(s1 = \"abcdefghijklmnopqrstuvwxyzz\",s2 = \"zzabcdefghijklmnopqrstuvwxy\") == True\n assert candidate(s1 = \"thisisaverylongstring\",s2 = \"tihisrasevylnsgtrnogi\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"ppissimissi\") == True\n assert candidate(s1 = \"abacabadabacaba\",s2 = \"aabacabadabacab\") == False\n assert candidate(s1 = \"abcdef\",s2 = \"fdecba\") == False\n assert candidate(s1 = \"abcdefghijk\",s2 = \"jihgfedcbaa\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"imississipp\") == False\n assert candidate(s1 = \"qwertqwert\",s2 = \"wqerqewtqw\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"ssissimippi\") == True\n assert candidate(s1 = \"abcdefgabcdefg\",s2 = \"gfedcbagfedcba\") == True\n assert candidate(s1 = \"abcdefghijklmnopqrstuvwx\",s2 = \"bacdfeghijklmnopqrstuvxw\") == False\n assert candidate(s1 = \"abcdefghijkll\",s2 = \"llijkgfhecdba\") == False\n assert candidate(s1 = \"abcabcabc\",s2 = \"bcabcbaca\") == False\n assert candidate(s1 = \"zaybzcyd\",s2 = \"dzbyazcy\") == False\n assert candidate(s1 = \"abcdefghef\",s2 = \"gdefhabcef\") == False\n assert candidate(s1 = \"aabbcc\",s2 = \"bbccaa\") == True\n assert candidate(s1 = \"abcabcabc\",s2 = \"cbacbacba\") == True\n assert candidate(s1 = \"abcdefghijklmnop\",s2 = \"ponmlkjihgfedcba\") == False\n assert candidate(s1 = \"programming\",s2 = \"pgmrnomggin\") == False\n assert candidate(s1 = \"repaper\",s2 = \"repaper\") == True\n assert candidate(s1 = \"abcdefgihjklmnopqrstuvwxyz\",s2 = \"bacdfegihjklmnopqrstuvwxzy\") == False\n assert candidate(s1 = \"sameorder\",s2 = \"sameorder\") == True\n assert candidate(s1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",s2 = \"bbaaccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s1 = \"abcdabcd\",s2 = \"dcbaabcd\") == False\n assert candidate(s1 = \"abcdefghij\",s2 = \"jihgfedcba\") == False\n assert candidate(s1 = \"pqrstuvw\",s2 = \"wvutsrqp\") == False\n assert candidate(s1 = \"zyxwvutsrqponmlkjihgfedcba\",s2 = \"yxwvuztsrqponmlkjihgfedcba\") == False\n assert candidate(s1 = \"abcdefghij\",s2 = \"aecgbdfhij\") == False\n assert candidate(s1 = \"acdbegfh\",s2 = \"bfegacdh\") == False\n assert candidate(s1 = \"abadecafagbahbbhacdg\",s2 = \"bdacegafabchbahbadcg\") == False\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghij\") == True\n assert candidate(s1 = \"aabbaabb\",s2 = \"bbaabbaa\") == True\n assert candidate(s1 = \"xyzzyxzyxzyx\",s2 = \"zyxzyxzyxzyx\") == True\n assert candidate(s1 = \"abcabcabcabc\",s2 = \"cbacbacbacba\") == True\n assert candidate(s1 = \"racecar\",s2 = \"racecar\") == True\n assert candidate(s1 = \"aabbccddeeff\",s2 = \"fbeeccddbaaa\") == False\n assert candidate(s1 = \"noon\",s2 = \"noon\") == True\n assert candidate(s1 = \"aaabbbcccddd\",s2 = \"dddcccbbbaaa\") == False\n assert candidate(s1 = \"zxyxzyzyx\",s2 = \"yxzyxzyxq\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"ppimississi\") == False\n assert candidate(s1 = \"abcdefghij\",s2 = \"gbihfedcja\") == False\n assert candidate(s1 = \"aabbccddeeffgghhiijj\",s2 = \"jjiihhggffeeeddccbaa\") == False\n assert candidate(s1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",s2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(s1 = \"aabbaabbaabb\",s2 = \"bbaabbaabbba\") == False\n assert candidate(s1 = \"abcdefg\",s2 = \"afedcba\") == False\n assert candidate(s1 = \"abacabad\",s2 = \"dcadcbab\") == False\n assert candidate(s1 = \"aabbccdd\",s2 = \"ddccbbaa\") == True\n assert candidate(s1 = \"ababababababababababababab\",s2 = \"bababababababababababababa\") == False\n assert candidate(s1 = \"noonnoon\",s2 = \"nnoonnou\") == False\n assert candidate(s1 = \"ababab\",s2 = \"bababa\") == False\n assert candidate(s1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",s2 = \"abbaccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s1 = \"abcdefgihjklmnopqrstuvwxyz\",s2 = \"zyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(s1 = \"abcdefghij\",s2 = \"jeihgfedcb\") == False\n assert candidate(s1 = \"abcdefghijk\",s2 = \"jihgfedcbak\") == False\n assert candidate(s1 = \"qwertypoiuytrewq\",s2 = \"qwertyuiytrewpoi\") == False\n assert candidate(s1 = \"rotor\",s2 = \"rotor\") == True\n assert candidate(s1 = \"pneumonoultramicroscopicsilicovolcanoconiosis\",s2 = \"pneumonoultramicroscopicsilicovolcanoconiosis\") == True\n assert candidate(s1 = \"noonoon\",s2 = \"nooouon\") == False\n assert candidate(s1 = \"detartrated\",s2 = \"detartrated\") == True\n assert candidate(s1 = \"abcdabcdabcd\",s2 = \"dcbaabcdabcd\") == False\n assert candidate(s1 = \"aabbaabbaabbaabb\",s2 = \"bbaabbaabbaabbaa\") == True\n assert candidate(s1 = \"mnopqrstuvwxyzabcdefghijkl\",s2 = \"onmpqrstuvwxyzabcdefghijkl\") == True\n assert candidate(s1 = \"abcdabcd\",s2 = \"cdabcdab\") == True\n assert candidate(s1 = \"xyxzyzyx\",s2 = \"yxzyxzyz\") == False\n assert candidate(s1 = \"pqrstuvwx\",s2 = \"vutsrqpwx\") == True\n assert candidate(s1 = \"abacabadabacabaa\",s2 = \"abaabacabadabaab\") == False\n assert candidate(s1 = \"abcdefghijklmnopqrstuvwxyz\",s2 = \"zabcdefghijklmnopqrstuvwxy\") == False\n assert candidate(s1 = \"aabbccddeeff\",s2 = \"bbccddeeffaa\") == True\n", "comparison": "exact"}, "public_tests": ["\"abcdba\"\n\"cabdab\"", "\"abe\"\n\"bea\""], "hints": ["Characters in two positions can be swapped if and only if the two positions have the same parity.", "To be able to make the two strings equal, the characters at even and odd positions in the strings should be the same."], "metadata": {"canonical_parameter_names": ["s1", "s2"], "leetcode_dataset_entry_point": "Solution().checkStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:44+00:00", "tests_total": 127, "tests_dropped": 20, "flags": [], "topic_tags": ["hash-table", "string", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def check_strings(s1, s2)", "container": null, "callable": "check_strings", "parameters": [{"name": "s1", "type": "String"}, {"name": "s2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2841, "task_id": "maximum-sum-of-almost-unique-subarray", "difficulty": "Medium", "problem_description": "You are given an integer array nums and two positive integers m and k.\n\nReturn the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.\n\nA subarray of nums is almost unique if it contains at least m distinct elements.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,6,7,3,1,7], m = 3, k = 4\nOutput: 18\nExplanation: There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.\n\nExample 2:\n\nInput: nums = [5,9,9,2,4,5,4], m = 1, k = 3\nOutput: 23\nExplanation: There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.\n\nExample 3:\n\nInput: nums = [1,2,1,2,1,2,1], m = 3, k = 3\nOutput: 0\nExplanation: There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0.\n\nConstraints:\n\n- 1 <= nums.length <= 2 * 10^4\n- 1 <= m <= k <= nums.length\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 2,k = 3) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],m = 4,k = 5) == 35\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],m = 5,k = 5) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],m = 2,k = 3) == 12\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],m = 3,k = 4) == 16\n assert candidate(nums = [5, 9, 9, 2, 4, 5, 4],m = 1,k = 3) == 23\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1],m = 3,k = 3) == 0\n assert candidate(nums = [2, 6, 7, 3, 1, 7],m = 3,k = 4) == 18\n assert candidate(nums = [1, 1, 1, 1, 1],m = 2,k = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],m = 2,k = 5) == 35\n assert candidate(nums = [10, 10, 10, 10, 10],m = 1,k = 2) == 20\n assert candidate(nums = [10, 20, 30, 40, 50],m = 3,k = 5) == 150\n assert candidate(nums = [5, 5, 5, 5, 5],m = 1,k = 2) == 10\n assert candidate(nums = [10, 10, 10, 10, 10],m = 2,k = 3) == 0\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],m = 5,k = 9) == 0\n assert candidate(nums = [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],m = 4,k = 10) == 54\n assert candidate(nums = [12, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],m = 5,k = 12) == 562\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],m = 3,k = 7) == 49\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],m = 4,k = 7) == 18\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],m = 3,k = 7) == 26\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, 9],m = 2,k = 25) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],m = 3,k = 3) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],m = 4,k = 5) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],m = 4,k = 4) == 0\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 5,k = 7) == 119\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],m = 3,k = 7) == 4900\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],m = 5,k = 7) == 119\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],m = 5,k = 9) == 189\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],m = 5,k = 5) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 1,k = 20) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 5,k = 5) == 400\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 5,k = 7) == 84\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],m = 3,k = 6) == 39\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],m = 15,k = 15) == 345\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2],m = 6,k = 10) == 54\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5,k = 6) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 5,k = 7) == 119\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],m = 2,k = 5) == 14\n assert candidate(nums = [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, 8, 8, 8],m = 1,k = 10) == 80\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4],m = 4,k = 5) == 18\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6],m = 2,k = 4) == 22\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],m = 4,k = 6) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],m = 5,k = 6) == 39\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 4,k = 4) == 30\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],m = 3,k = 5) == 27\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],m = 3,k = 4) == 30\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],m = 1,k = 3) == 3000000000\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],m = 5,k = 10) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],m = 3,k = 5) == 15\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],m = 5,k = 10) == 55\n assert candidate(nums = [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],m = 10,k = 15) == 1665\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 8],m = 4,k = 5) == 34\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, 9, 9, 9],m = 4,k = 6) == 0\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],m = 4,k = 7) == 161\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 10,k = 10) == 55\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],m = 5,k = 10) == 60\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],m = 5,k = 10) == 0\n assert candidate(nums = [5, 8, 2, 8, 3, 6, 1, 9, 7, 4, 10],m = 4,k = 5) == 31\n assert candidate(nums = [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, 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],m = 7,k = 9) == 45\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 8,k = 12) == 740\n assert candidate(nums = [7, 7, 1, 7, 7, 7, 1, 7, 7, 7, 1, 7, 7, 7, 1, 7, 7, 7, 1, 7],m = 2,k = 8) == 44\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],m = 2,k = 6) == 9\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, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50],m = 5,k = 10) == 300\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 6,k = 8) == 52\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],m = 5,k = 5) == 75\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6],m = 3,k = 5) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 6,k = 9) == 99\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],m = 5,k = 8) == 64\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],m = 3,k = 4) == 16\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10],m = 4,k = 7) == 55\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],m = 3,k = 5) == 15\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, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 1,k = 10) == 50\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],m = 7,k = 8) == 920\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 2,k = 10) == 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],m = 5,k = 10) == 30\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1],m = 3,k = 4) == 0\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8],m = 5,k = 6) == 33\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],m = 4,k = 8) == 108\n assert candidate(nums = [29, 18, 27, 29, 18, 27, 29, 18, 27, 29, 18, 27, 29, 18, 27, 29, 18, 27, 29, 18],m = 3,k = 7) == 177\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],m = 2,k = 5) == 0\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],m = 5,k = 5) == 4333333330\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5,k = 5) == 40\n assert candidate(nums = [2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4],m = 2,k = 3) == 9\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15],m = 7,k = 9) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8],m = 3,k = 6) == 39\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],m = 3,k = 6) == 135\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16],m = 4,k = 6) == 81\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 6,k = 8) == 52\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9],m = 5,k = 9) == 45\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555],m = 4,k = 5) == 4333333330\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],m = 2,k = 20) == 0\n assert candidate(nums = [2, 3, 3, 2, 3, 2, 2, 3, 2, 3, 2, 3],m = 2,k = 4) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 5,k = 6) == 45\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],m = 4,k = 5) == 28\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],m = 3,k = 5) == 4000\n assert candidate(nums = [5, 8, 6, 9, 2, 1, 5, 7, 4, 3],m = 3,k = 5) == 30\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],m = 4,k = 7) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],m = 2,k = 3) == 2700\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],m = 5,k = 5) == 900\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 4,k = 5) == 40\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 4,k = 15) == 95\n assert candidate(nums = [9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6],m = 3,k = 6) == 0\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9],m = 4,k = 6) == 0\n assert candidate(nums = [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],m = 4,k = 8) == 44\n assert candidate(nums = [5, 5, 5, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],m = 3,k = 5) == 20\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 5,k = 10) == 155\n", "comparison": "exact"}, "public_tests": ["[2,6,7,3,1,7]\n3\n4", "[5,9,9,2,4,5,4]\n1\n3", "[1,2,1,2,1,2,1]\n3\n3"], "hints": ["Use a set or map to keep track of the number of distinct elements.", "Use 2-pointers to maintain the size, the number of unique elements, and the sum of all the elements in all subarrays of size k from left to right dynamically.****"], "metadata": {"canonical_parameter_names": ["nums", "m", "k"], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:46+00:00", "tests_total": 108, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def max_sum(nums, m, k)", "container": null, "callable": "max_sum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "m", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2843, "task_id": "count-symmetric-integers", "difficulty": "Easy", "problem_description": "You are given two positive integers low and high.\n\nAn integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.\n\nReturn the number of symmetric integers in the range [low, high].\n\nExample 1:\n\nInput: low = 1, high = 100\nOutput: 9\nExplanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.\n\nExample 2:\n\nInput: low = 1200, high = 1230\nOutput: 4\nExplanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.\n\nConstraints:\n\n- 1 <= low <= high <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(low = 10,high = 20) == 1\n assert candidate(low = 1,high = 9999) == 624\n assert candidate(low = 500,high = 1500) == 20\n assert candidate(low = 1000,high = 1000) == 0\n assert candidate(low = 500,high = 550) == 0\n assert candidate(low = 1,high = 100) == 9\n assert candidate(low = 1,high = 10000) == 624\n assert candidate(low = 1000,high = 10000) == 615\n assert candidate(low = 1200,high = 1230) == 4\n assert candidate(low = 10,high = 1000) == 9\n assert candidate(low = 9999,high = 10000) == 1\n assert candidate(low = 2500,high = 2600) == 8\n assert candidate(low = 1000,high = 9999) == 615\n assert candidate(low = 2500,high = 3500) == 74\n assert candidate(low = 7777,high = 8888) == 70\n assert candidate(low = 7000,high = 7100) == 8\n assert candidate(low = 1001,high = 9990) == 614\n assert candidate(low = 1234,high = 4321) == 216\n assert candidate(low = 1,high = 10) == 0\n assert candidate(low = 2000,high = 2999) == 69\n assert candidate(low = 5000,high = 5500) == 40\n assert candidate(low = 1234,high = 5678) == 326\n assert candidate(low = 7500,high = 7600) == 7\n assert candidate(low = 8000,high = 8500) == 43\n assert candidate(low = 3000,high = 3100) == 4\n assert candidate(low = 3000,high = 3999) == 73\n assert candidate(low = 999,high = 9999) == 615\n assert candidate(low = 5000,high = 5050) == 6\n assert candidate(low = 1000,high = 2000) == 63\n assert candidate(low = 1111,high = 2222) == 70\n assert candidate(low = 8000,high = 8100) == 9\n assert candidate(low = 5000,high = 6000) == 75\n assert candidate(low = 2000,high = 3000) == 69\n assert candidate(low = 1000,high = 1010) == 2\n assert candidate(low = 9000,high = 9999) == 55\n assert candidate(low = 3000,high = 3300) == 15\n assert candidate(low = 6000,high = 6100) == 7\n assert candidate(low = 8888,high = 8888) == 1\n assert candidate(low = 9876,high = 9885) == 0\n assert candidate(low = 999,high = 1001) == 1\n assert candidate(low = 1111,high = 9999) == 612\n assert candidate(low = 9000,high = 9100) == 10\n assert candidate(low = 1000,high = 1100) == 2\n assert candidate(low = 8888,high = 9999) == 59\n assert candidate(low = 1001,high = 1020) == 2\n assert candidate(low = 3000,high = 7000) == 296\n assert candidate(low = 1234,high = 8765) == 542\n assert candidate(low = 9876,high = 9876) == 0\n assert candidate(low = 100,high = 10000) == 615\n assert candidate(low = 1100,high = 1400) == 12\n assert candidate(low = 1001,high = 1010) == 2\n assert candidate(low = 5000,high = 5100) == 6\n assert candidate(low = 7800,high = 7900) == 4\n assert candidate(low = 4999,high = 5001) == 0\n assert candidate(low = 1001,high = 9999) == 615\n assert candidate(low = 1001,high = 1099) == 2\n assert candidate(low = 8000,high = 8999) == 63\n assert candidate(low = 5000,high = 9999) == 335\n assert candidate(low = 9000,high = 10000) == 55\n assert candidate(low = 5000,high = 9000) == 280\n assert candidate(low = 5678,high = 8765) == 216\n assert candidate(low = 2000,high = 8000) == 434\n assert candidate(low = 10000,high = 10000) == 0\n assert candidate(low = 9900,high = 10000) == 1\n assert candidate(low = 4500,high = 4600) == 10\n", "comparison": "exact"}, "public_tests": ["1\n100", "1200\n1230"], "hints": ["Iterate over all numbers from low to high", "Convert each number to a string and compare the sum of the first half with that of the second."], "metadata": {"canonical_parameter_names": ["low", "high"], "leetcode_dataset_entry_point": "Solution().countSymmetricIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:51+00:00", "tests_total": 72, "tests_dropped": 7, "flags": [], "topic_tags": ["math", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def count_symmetric_integers(low, high)", "container": null, "callable": "count_symmetric_integers", "parameters": [{"name": "low", "type": "Integer"}, {"name": "high", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2844, "task_id": "minimum-operations-to-make-a-special-number", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string num representing a non-negative integer.\n\nIn one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.\n\nReturn the minimum number of operations required to make num special.\n\nAn integer x is considered special if it is divisible by 25.\n\nExample 1:\n\nInput: num = \"2245047\"\nOutput: 2\nExplanation: Delete digits num[5] and num[6]. The resulting number is \"22450\" which is special since it is divisible by 25.\nIt can be shown that 2 is the minimum number of operations required to get a special number.\n\nExample 2:\n\nInput: num = \"2908305\"\nOutput: 3\nExplanation: Delete digits num[3], num[4], and num[6]. The resulting number is \"2900\" which is special since it is divisible by 25.\nIt can be shown that 3 is the minimum number of operations required to get a special number.\n\nExample 3:\n\nInput: num = \"10\"\nOutput: 1\nExplanation: Delete digit num[0]. The resulting number is \"0\" which is special since it is divisible by 25.\nIt can be shown that 1 is the minimum number of operations required to get a special number.\n\nConstraints:\n\n- 1 <= num.length <= 100\n- num only consists of digits '0' through '9'.\n- num does not contain any leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"10\") == 1\n assert candidate(num = \"00000\") == 0\n assert candidate(num = \"75\") == 0\n assert candidate(num = \"52\") == 2\n assert candidate(num = \"500000\") == 0\n assert candidate(num = \"5252525252\") == 1\n assert candidate(num = \"1111111111\") == 10\n assert candidate(num = \"000\") == 0\n assert candidate(num = \"333\") == 3\n assert candidate(num = \"2468024680\") == 4\n assert candidate(num = \"99999\") == 5\n assert candidate(num = \"98765432109876543210\") == 4\n assert candidate(num = \"0246802468\") == 8\n assert candidate(num = \"55555\") == 5\n assert candidate(num = \"875\") == 0\n assert candidate(num = \"2245047\") == 2\n assert candidate(num = \"9876543210\") == 4\n assert candidate(num = \"0\") == 0\n assert candidate(num = \"2908305\") == 3\n assert candidate(num = \"2500\") == 0\n assert candidate(num = \"99999999999999999999\") == 20\n assert candidate(num = \"2050\") == 0\n assert candidate(num = \"55\") == 2\n assert candidate(num = \"375\") == 0\n assert candidate(num = \"999999999\") == 9\n assert candidate(num = \"625\") == 0\n assert candidate(num = \"123056789\") == 6\n assert candidate(num = \"11223344556677889900\") == 0\n assert candidate(num = \"100\") == 0\n assert candidate(num = \"5555555555\") == 10\n assert candidate(num = \"300\") == 0\n assert candidate(num = \"24680\") == 4\n assert candidate(num = \"00\") == 0\n assert candidate(num = \"1234567890\") == 4\n assert candidate(num = \"125\") == 0\n assert candidate(num = \"13579\") == 5\n assert candidate(num = \"50\") == 0\n assert candidate(num = \"1357913579\") == 5\n assert candidate(num = \"9999999999\") == 10\n assert candidate(num = \"25\") == 0\n assert candidate(num = \"57\") == 2\n assert candidate(num = \"2000\") == 0\n assert candidate(num = \"200\") == 0\n assert candidate(num = \"999999999999999999999999999999999999999999999999999\") == 51\n assert candidate(num = \"135792468050\") == 0\n assert candidate(num = \"246824682468\") == 12\n assert candidate(num = \"789012345678901234567890\") == 4\n assert candidate(num = \"500500500500500\") == 0\n assert candidate(num = \"33333333333333333333\") == 20\n assert candidate(num = \"11223344556677889900112233445566778899\") == 13\n assert candidate(num = \"7525105025007525105025007525105025007525105025\") == 0\n assert candidate(num = \"5050505050505050\") == 0\n assert candidate(num = \"246802468024680246802468024680246802468024680\") == 4\n assert candidate(num = \"9999000099990000\") == 0\n assert candidate(num = \"50050050050050050050\") == 0\n assert candidate(num = \"25000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"387625387625387625387625387625\") == 0\n assert candidate(num = \"97531975319753197531\") == 2\n assert candidate(num = \"257001025\") == 0\n assert candidate(num = \"0000000000\") == 0\n assert candidate(num = \"9999999990\") == 9\n assert candidate(num = \"50505050505050505050\") == 0\n assert candidate(num = \"135791357913579135791357913579135791357913579\") == 5\n assert candidate(num = \"99887766554433221100\") == 0\n assert candidate(num = \"499999999999999999999999999999999999999999999999999\") == 51\n assert candidate(num = \"111111111100\") == 0\n assert candidate(num = \"500500500500500500500500500500500500500500500500500\") == 0\n assert candidate(num = \"19387654321098765432101234567890\") == 4\n assert candidate(num = \"1234567890123456789012345678901234567890\") == 4\n assert candidate(num = \"959595959595959595959595959595959595959595959595959\") == 51\n assert candidate(num = \"579135791357913579135791357910\") == 3\n assert candidate(num = \"135791357913579135791357913579135791357913579135791\") == 6\n assert candidate(num = \"50000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"975319753197531975\") == 0\n assert candidate(num = \"2525252525252525252525252525252525252525\") == 0\n assert candidate(num = \"345678901234567890\") == 4\n assert candidate(num = \"3333333333333333333333333333333333333333333335\") == 46\n assert candidate(num = \"98765432109876543210987654321098765432109876543210\") == 4\n assert candidate(num = \"9876543210987654321098765432109876543210987654321098\") == 6\n assert candidate(num = \"2575257525752575257525752575257525752575\") == 0\n assert candidate(num = \"8888888888888888888888888888888888888888888888\") == 46\n assert candidate(num = \"0000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"12345678905\") == 3\n assert candidate(num = \"5432109876543210\") == 4\n assert candidate(num = \"4321098765432109876543210987654321098765\") == 1\n assert candidate(num = \"8765432109876543210987654321098765432109\") == 5\n assert candidate(num = \"3333333333333333333333333333333333333333333330\") == 45\n assert candidate(num = \"77777777777777777777777777777777777777777777777777\") == 50\n assert candidate(num = \"52505250525052505250525052505250\") == 0\n assert candidate(num = \"55555555555555555555\") == 20\n assert candidate(num = \"864208642086420864208642086420864208642086420864208\") == 5\n assert candidate(num = \"2468135792468135792468\") == 11\n assert candidate(num = \"2525252525252525252525252525252525252525252525252525\") == 0\n assert candidate(num = \"20000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"999999999999999999999999999999999999999999999999990\") == 50\n assert candidate(num = \"8765432109876543210\") == 4\n assert candidate(num = \"0000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"5050505050505050505050505050505050505050505050\") == 0\n assert candidate(num = \"8246824682468246\") == 16\n assert candidate(num = \"36925814703692581470\") == 4\n assert candidate(num = \"10101010101010101010101010101010101010101010101010101010\") == 1\n assert candidate(num = \"753153753153753153\") == 4\n assert candidate(num = \"1001001001001001001001001001001\") == 1\n assert candidate(num = \"246802468024680246802468024680246802468024680246802\") == 5\n assert candidate(num = \"000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"30000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"2525252525252525252525252525252525252525252525\") == 0\n assert candidate(num = \"4876543210987654321098765432109876543210\") == 4\n assert candidate(num = \"9999990\") == 6\n assert candidate(num = \"25002500250025002500250025002500250025002500\") == 0\n assert candidate(num = \"204861012141618202224262830323436384042444648\") == 17\n assert candidate(num = \"000111000222000333000444000555000666000777000\") == 0\n assert candidate(num = \"000000000000000000000000000000\") == 0\n assert candidate(num = \"11111111111111111111111111111111111111111111\") == 44\n assert candidate(num = \"805\") == 2\n assert candidate(num = \"50000000000000000000\") == 0\n assert candidate(num = \"19283746555555555555\") == 13\n assert candidate(num = \"5555555555555555555555555555555555555555\") == 40\n assert candidate(num = \"12345678909876543210123456789098765432101234567890\") == 4\n assert candidate(num = \"13579135791357913579\") == 5\n assert candidate(num = \"2222222222222222222222222222222222222222\") == 40\n assert candidate(num = \"25000000250000000025000000000000000025\") == 0\n assert candidate(num = \"2222222222222222222222222222222222222222222222\") == 46\n assert candidate(num = \"252525252525252525252525252525\") == 0\n assert candidate(num = \"5050505050505050505050505050505050505050\") == 0\n assert candidate(num = \"111111111111111111110\") == 20\n assert candidate(num = \"987654321098765432109876543210\") == 4\n assert candidate(num = \"222222222222222222222\") == 21\n assert candidate(num = \"12345678909876543210\") == 4\n assert candidate(num = \"012345678901234567890123456789012345678901234567890\") == 4\n assert candidate(num = \"222222222250\") == 0\n assert candidate(num = \"9999099990999909999099990999909999099990\") == 4\n assert candidate(num = \"5000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"9876543210987654321098765432109876543210\") == 4\n assert candidate(num = \"5734094321098765432100\") == 0\n assert candidate(num = \"101010101010101010101010101010101010101010\") == 1\n assert candidate(num = \"98765432101234567890\") == 4\n assert candidate(num = \"987654321098765432101234567890\") == 4\n assert candidate(num = \"02502502502502502502\") == 1\n assert candidate(num = \"19293949596979899909192939495969798999091929394\") == 17\n assert candidate(num = \"0101010101010101010101010101010101010101010101010101010101010\") == 1\n assert candidate(num = \"0123456789012345678901234567890123456789\") == 6\n assert candidate(num = \"555555555525\") == 0\n assert candidate(num = \"404040404040404040404040404040404040404040404040400\") == 0\n assert candidate(num = \"5555555555555525\") == 0\n assert candidate(num = \"25252525252525252525252525252525252525252525\") == 0\n assert candidate(num = \"86420864208642086420\") == 4\n assert candidate(num = \"25252525252525252525\") == 0\n assert candidate(num = \"555555555555555555555555555555555555555555555555555\") == 51\n assert candidate(num = \"01234567890123456789\") == 6\n assert candidate(num = \"55555555555555555555555555555555555555555555555550\") == 0\n assert candidate(num = \"24680246802468024680\") == 4\n assert candidate(num = \"50505050505050505050505050505050505050505050505050\") == 0\n assert candidate(num = \"1234567890123456789012345678901234567890123456\") == 3\n assert candidate(num = \"82468024680246802468\") == 8\n assert candidate(num = \"123456789012345678901234567890\") == 4\n assert candidate(num = \"222222222222222222222222222222222222222222222222225\") == 0\n assert candidate(num = \"33333353333333333335\") == 20\n assert candidate(num = \"62626262626262626262\") == 20\n assert candidate(num = \"123450\") == 0\n assert candidate(num = \"12345678901234567890123456789012345678901234567890\") == 4\n assert candidate(num = \"025025025025\") == 0\n assert candidate(num = \"112233445566778899\") == 13\n assert candidate(num = \"9438765432109876543210123456789050\") == 0\n assert candidate(num = \"12345678900\") == 0\n assert candidate(num = \"18642086420864208640\") == 3\n assert candidate(num = \"52357845968275982450\") == 0\n assert candidate(num = \"777777777777777777777777777777777777777777777777770\") == 50\n assert candidate(num = \"00000000000000000000\") == 0\n assert candidate(num = \"25252525252525\") == 0\n assert candidate(num = \"975310\") == 2\n assert candidate(num = \"10101010101010101010\") == 1\n assert candidate(num = \"333333333333333333333333333333333333333333333333335\") == 51\n assert candidate(num = \"11111111111111111111\") == 20\n assert candidate(num = \"1234567890123456789012345678901234567890123456789012\") == 6\n assert candidate(num = \"55555555555525\") == 0\n assert candidate(num = \"94387126540054321689745261098743652109876543210\") == 4\n assert candidate(num = \"12345678901234567890\") == 4\n assert candidate(num = \"555555555500\") == 0\n assert candidate(num = \"52525252525252525252\") == 1\n assert candidate(num = \"952595259525952595259525952595\") == 2\n assert candidate(num = \"09876543210987654321\") == 5\n assert candidate(num = \"77777777777777777777\") == 20\n assert candidate(num = \"10000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"1000000\") == 0\n assert candidate(num = \"0000000000000000\") == 0\n assert candidate(num = \"22450478900\") == 0\n assert candidate(num = \"22222222222222222222\") == 20\n", "comparison": "exact"}, "public_tests": ["\"2245047\"", "\"2908305\"", "\"10\""], "hints": ["If num contains a single zero digit then the answer is at most n - 1.", "A number is divisible by 25 if its last two digits are 75, 50, 25, or 00.", "Iterate over all possible pairs of indices i < j such that num[i] * 10 + num[j] is in [00,25,50,75]. Then, set the answer to min(answer, n - i - 2) ."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:53+00:00", "tests_total": 188, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string", "greedy", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations(num)", "container": null, "callable": "minimum_operations", "parameters": [{"name": "num", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2845, "task_id": "count-of-interesting-subarrays", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums, an integer modulo, and an integer k.\n\nYour task is to find the count of subarrays that are interesting.\n\nA subarray nums[l..r] is interesting if the following condition holds:\n\n- Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k.\n\nReturn an integer denoting the count of interesting subarrays.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [3,2,4], modulo = 2, k = 1\nOutput: 3\nExplanation: In this example the interesting subarrays are:\nThe subarray nums[0..0] which is [3].\n- There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..1] which is [3,2].\n- There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..2] which is [3,2,4].\n- There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nIt can be shown that there are no other interesting subarrays. So, the answer is 3.\n\nExample 2:\n\nInput: nums = [3,1,9,6], modulo = 3, k = 0\nOutput: 2\nExplanation: In this example the interesting subarrays are:\nThe subarray nums[0..3] which is [3,1,9,6].\n- There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k.\n- Hence, cnt = 3 and cnt % modulo == k.\nThe subarray nums[1..1] which is [1].\n- There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 0 and cnt % modulo == k.\nIt can be shown that there are no other interesting subarrays. So, the answer is 2.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= modulo <= 10^9\n- 0 <= k < modulo\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 2, 4],modulo = 2,k = 1) == 3\n assert candidate(nums = [8, 12, 16, 20, 24],modulo = 4,k = 0) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],modulo = 7,k = 0) == 1\n assert candidate(nums = [3, 1, 9, 6],modulo = 3,k = 0) == 2\n assert candidate(nums = [5, 5, 5, 5],modulo = 5,k = 0) == 0\n assert candidate(nums = [1, 3, 5, 7, 9],modulo = 2,k = 1) == 9\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],modulo = 7,k = 3) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],modulo = 11,k = 0) == 0\n assert candidate(nums = [7, 7, 7, 7, 7],modulo = 7,k = 0) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],modulo = 2,k = 0) == 6\n assert candidate(nums = [1, 1, 1, 1, 1],modulo = 2,k = 1) == 9\n assert candidate(nums = [7, 14, 21, 28, 35],modulo = 7,k = 0) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],modulo = 5,k = 0) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],modulo = 5,k = 0) == 1\n assert candidate(nums = [13, 19, 3, 5, 17],modulo = 5,k = 2) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],modulo = 10,k = 0) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],modulo = 2,k = 1) == 9\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195],modulo = 13,k = 0) == 3\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],modulo = 8,k = 4) == 0\n assert candidate(nums = [21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164, 175, 186],modulo = 7,k = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],modulo = 5,k = 2) == 30\n assert candidate(nums = [3, 8, 15, 12, 6, 18, 21],modulo = 3,k = 0) == 7\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39],modulo = 3,k = 0) == 26\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400],modulo = 9,k = 1) == 53\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],modulo = 3,k = 0) == 35\n assert candidate(nums = [13, 19, 23, 29, 31, 37, 41, 43, 47, 53],modulo = 11,k = 1) == 24\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],modulo = 2,k = 1) == 30\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29],modulo = 3,k = 1) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],modulo = 11,k = 2) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],modulo = 13,k = 0) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],modulo = 9,k = 0) == 2\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],modulo = 11,k = 0) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],modulo = 10,k = 5) == 12\n assert candidate(nums = [13, 19, 23, 29, 31, 37, 41, 43, 47, 53],modulo = 7,k = 3) == 0\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420],modulo = 42,k = 0) == 0\n assert candidate(nums = [99, 198, 297, 396, 495, 594, 693, 792, 891, 990],modulo = 99,k = 33) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],modulo = 3,k = 0) == 63\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],modulo = 11,k = 5) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6],modulo = 6,k = 4) == 0\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30],modulo = 7,k = 2) == 3\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266, 285],modulo = 19,k = 0) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],modulo = 2,k = 1) == 30\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],modulo = 11,k = 3) == 0\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],modulo = 4,k = 3) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],modulo = 4,k = 3) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],modulo = 3,k = 0) == 15\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],modulo = 5,k = 0) == 7\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],modulo = 9,k = 0) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],modulo = 4,k = 2) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],modulo = 4,k = 2) == 0\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],modulo = 8,k = 0) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],modulo = 3,k = 1) == 25\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],modulo = 5,k = 4) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],modulo = 3,k = 1) == 25\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],modulo = 21,k = 10) == 0\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44],modulo = 3,k = 2) == 40\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555],modulo = 9,k = 5) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143],modulo = 11,k = 0) == 3\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1012],modulo = 13,k = 4) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],modulo = 3,k = 2) == 70\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80],modulo = 4,k = 0) == 45\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],modulo = 10,k = 0) == 1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],modulo = 101,k = 0) == 0\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],modulo = 15,k = 5) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],modulo = 7,k = 3) == 0\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],modulo = 21,k = 10) == 0\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],modulo = 12,k = 3) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],modulo = 2,k = 1) == 64\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],modulo = 5,k = 0) == 7\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],modulo = 101,k = 50) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121],modulo = 11,k = 3) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],modulo = 250,k = 200) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],modulo = 2,k = 1) == 30\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],modulo = 5,k = 2) == 0\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],modulo = 9,k = 2) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],modulo = 11,k = 10) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],modulo = 5,k = 2) == 0\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255],modulo = 17,k = 0) == 0\n assert candidate(nums = [11, 13, 15, 17, 19, 21, 23, 25, 27, 29],modulo = 7,k = 3) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],modulo = 13,k = 2) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],modulo = 9,k = 1) == 18\n assert candidate(nums = [12, 23, 34, 45, 56, 67, 78, 89, 910, 1011],modulo = 13,k = 2) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],modulo = 10,k = 3) == 4\n assert candidate(nums = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],modulo = 5,k = 3) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],modulo = 10,k = 0) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],modulo = 13,k = 2) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169],modulo = 13,k = 2) == 0\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021],modulo = 7,k = 4) == 4\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],modulo = 101,k = 50) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],modulo = 7,k = 3) == 32\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],modulo = 3,k = 2) == 15\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],modulo = 11,k = 0) == 0\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1010],modulo = 11,k = 10) == 0\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420],modulo = 42,k = 21) == 0\n assert candidate(nums = [14, 28, 42, 56, 70, 84, 98, 112, 126, 140],modulo = 14,k = 7) == 0\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],modulo = 12,k = 6) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],modulo = 10,k = 5) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],modulo = 15,k = 5) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115],modulo = 5,k = 0) == 11\n assert candidate(nums = [2, 5, 10, 13, 18, 21, 26, 31, 34, 39],modulo = 7,k = 0) == 25\n assert candidate(nums = [100, 200, 300, 400, 500],modulo = 5,k = 1) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],modulo = 100,k = 50) == 0\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],modulo = 4,k = 0) == 10\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84],modulo = 7,k = 0) == 6\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60],modulo = 5,k = 0) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],modulo = 10,k = 5) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],modulo = 11,k = 1) == 0\n", "comparison": "exact"}, "public_tests": ["[3,2,4]\n2\n1", "[3,1,9,6]\n3\n0"], "hints": ["The problem can be solved using prefix sums.", "Let count[i] be the number of indices where nums[i] % modulo == k among the first i indices.", "count[0] = 0 and count[i] = count[i - 1] + (nums[i - 1] % modulo == k ? 1 : 0) for i = 1, 2, ..., n.", "Now we want to calculate for each i = 1, 2, ..., n, how many indices j < i such that (count[i] - count[j]) % modulo == k.", "Rewriting (count[i] - count[j]) % modulo == k becomes count[j] = (count[i] + modulo - k) % modulo.", "Using a map data structure, for each i = 0, 1, 2, ..., n, we just sum up all map[(count[i] + modulo - k) % modulo] before increasing map[count[i] % modulo], and the total sum is the final answer."], "metadata": {"canonical_parameter_names": ["nums", "modulo", "k"], "leetcode_dataset_entry_point": "Solution().countInterestingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:55+00:00", "tests_total": 110, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def count_interesting_subarrays(nums, modulo, k)", "container": null, "callable": "count_interesting_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "modulo", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2846, "task_id": "minimum-edge-weight-equilibrium-queries-in-a-tree", "difficulty": "Hard", "problem_description": "There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i, w_i] indicates that there is an edge between nodes u_i and v_i with weight w_i in the tree.\n\nYou are also given a 2D integer array queries of length m, where queries[i] = [a_i, b_i]. For each query, find the minimum number of operations required to make the weight of every edge on the path from a_i to b_i equal. In one operation, you can choose any edge of the tree and change its weight to any value.\n\nNote that:\n\n- Queries are independent of each other, meaning that the tree returns to its initial state on each new query.\n- The path from a_i to b_i is a sequence of distinct nodes starting with node a_i and ending with node b_i such that every two adjacent nodes in the sequence share an edge in the tree.\n\nReturn an array answer of length m where answer[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]\nOutput: [0,0,1,3]\nExplanation: In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.\nIn the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0.\nIn the third query, we change the weight of edge [2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.\nIn the fourth query, we change the weights of edges [0,1], [1,2] and [2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from a_i to b_i.\n\nExample 2:\n\nInput: n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]\nOutput: [1,2,2,3]\nExplanation: In the first query, we change the weight of edge [1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.\nIn the second query, we change the weight of edges [0,3] and [3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.\nIn the third query, we change the weight of edges [1,3] and [5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.\nIn the fourth query, we change the weights of edges [0,7], [0,3] and [1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from a_i to b_i.\n\nConstraints:\n\n- 1 <= n <= 10^4\n- edges.length == n - 1\n- edges[i].length == 3\n- 0 <= u_i, v_i < n\n- 1 <= w_i <= 26\n- The input is generated such that edges represents a valid tree.\n- 1 <= queries.length == m <= 2 * 10^4\n- queries[i].length == 2\n- 0 <= a_i, b_i < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 2], [4, 5, 2], [5, 6, 2]],queries = [[0, 3], [3, 6], [2, 6], [0, 6]]) == [0, 0, 1, 3]\n assert candidate(n = 8,edges = [[1, 2, 6], [1, 3, 4], [2, 4, 6], [2, 5, 3], [3, 6, 6], [3, 0, 8], [7, 0, 2]],queries = [[4, 6], [0, 4], [6, 5], [7, 4]]) == [1, 2, 2, 3]\n assert candidate(n = 20,edges = [[0, 1, 5], [1, 2, 4], [2, 3, 6], [3, 4, 5], [4, 5, 4], [5, 6, 6], [6, 7, 5], [7, 8, 4], [8, 9, 6], [0, 10, 3], [10, 11, 2], [11, 12, 3], [12, 13, 4], [13, 14, 3], [14, 15, 2], [15, 16, 3], [16, 17, 4], [17, 18, 3], [18, 19, 2]],queries = [[0, 4], [7, 14], [2, 13], [8, 15], [1, 16], [9, 18]]) == [2, 9, 4, 10, 4, 13]\n assert candidate(n = 30,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 2], [4, 5, 2], [5, 6, 2], [6, 7, 3], [7, 8, 3], [8, 9, 3], [9, 10, 4], [10, 11, 4], [11, 12, 4], [12, 13, 5], [13, 14, 5], [14, 15, 5], [15, 16, 6], [16, 17, 6], [17, 18, 6], [18, 19, 7], [19, 20, 7], [20, 21, 7], [21, 22, 8], [22, 23, 8], [23, 24, 8], [24, 25, 9], [25, 26, 9], [26, 27, 9], [27, 28, 10], [28, 29, 10]],queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25], [5, 24], [6, 23], [7, 22], [8, 21], [9, 20], [10, 19], [11, 18], [12, 17], [13, 16], [14, 15]]) == [26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0]\n assert candidate(n = 15,edges = [[0, 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]],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 8]]) == [13, 11, 9, 7, 5, 3, 1, 0]\n assert candidate(n = 15,edges = [[0, 1, 5], [0, 2, 3], [0, 3, 2], [1, 4, 1], [1, 5, 1], [2, 6, 4], [2, 7, 4], [3, 8, 3], [3, 9, 6], [4, 10, 2], [5, 11, 5], [6, 12, 3], [7, 13, 4], [8, 14, 6]],queries = [[10, 12], [5, 14], [1, 13], [0, 11], [8, 11]]) == [4, 4, 2, 1, 3]\n assert candidate(n = 9,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4]]) == [7, 5, 3, 1, 0]\n assert candidate(n = 12,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 2], [4, 5, 3], [5, 6, 3], [6, 7, 4], [7, 8, 4], [8, 9, 5], [9, 10, 5], [10, 11, 6]],queries = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 4], [8, 3], [9, 2], [10, 1]]) == [3, 3, 3, 3, 3, 3, 3, 1, 3, 5, 7]\n assert candidate(n = 25,edges = [[0, 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]],queries = [[0, 24], [1, 23], [2, 22], [3, 21]]) == [23, 21, 19, 17]\n assert candidate(n = 20,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5], [5, 6, 5], [6, 7, 5], [7, 8, 5], [8, 9, 5], [9, 10, 5], [10, 11, 5], [11, 12, 5], [12, 13, 5], [13, 14, 5], [14, 15, 5], [15, 16, 5], [16, 17, 5], [17, 18, 5], [18, 19, 5]],queries = [[0, 19], [0, 10], [5, 15], [10, 15], [0, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(n = 10,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 3], [1, 4, 7], [2, 5, 10], [2, 6, 5], [3, 7, 2], [4, 8, 8], [5, 9, 15]],queries = [[0, 7], [1, 8], [3, 6], [4, 9], [7, 9]]) == [2, 1, 2, 3, 4]\n assert candidate(n = 15,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 2], [4, 5, 3], [5, 6, 3], [6, 7, 4], [7, 8, 4], [8, 9, 5], [9, 10, 5], [10, 11, 6], [11, 12, 6], [12, 13, 7], [13, 14, 7]],queries = [[0, 7], [3, 11], [5, 13], [2, 14]]) == [5, 6, 6, 10]\n assert candidate(n = 12,edges = [[0, 1, 5], [0, 2, 3], [0, 3, 4], [1, 4, 5], [1, 5, 3], [2, 6, 4], [2, 7, 5], [3, 8, 3], [3, 9, 4], [4, 10, 2], [5, 11, 2]],queries = [[0, 10], [4, 8], [1, 6], [2, 9], [3, 11], [5, 7]]) == [1, 2, 2, 1, 3, 2]\n assert candidate(n = 18,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 10], [3, 4, 20], [4, 5, 10], [5, 6, 20], [6, 7, 10], [7, 8, 20], [8, 9, 10], [9, 10, 20], [10, 11, 10], [11, 12, 20], [12, 13, 10], [13, 14, 20], [14, 15, 10], [15, 16, 20], [16, 17, 10]],queries = [[0, 17], [1, 16], [2, 15], [3, 14], [4, 13], [5, 12], [6, 11], [7, 10], [8, 9]]) == [8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(n = 50,edges = [[0, 1, 20], [1, 2, 19], [2, 3, 18], [3, 4, 17], [4, 5, 16], [5, 6, 15], [6, 7, 14], [7, 8, 13], [8, 9, 12], [9, 10, 11], [10, 11, 10], [11, 12, 9], [12, 13, 8], [13, 14, 7], [14, 15, 6], [15, 16, 5], [16, 17, 4], [17, 18, 3], [18, 19, 2], [19, 20, 1], [20, 21, 20], [21, 22, 19], [22, 23, 18], [23, 24, 17], [24, 25, 16], [25, 26, 15], [26, 27, 14], [27, 28, 13], [28, 29, 12], [29, 30, 11], [30, 31, 10], [31, 32, 9], [32, 33, 8], [33, 34, 7], [34, 35, 6], [35, 36, 5], [36, 37, 4], [37, 38, 3], [38, 39, 2], [39, 40, 1], [40, 41, 20], [41, 42, 19], [42, 43, 18], [43, 44, 17], [44, 45, 16], [45, 46, 15], [46, 47, 14], [47, 48, 13], [48, 49, 12]],queries = [[0, 49], [0, 25], [10, 35], [25, 49], [10, 25]]) == [46, 23, 23, 22, 14]\n assert candidate(n = 15,edges = [[0, 1, 3], [1, 2, 2], [2, 3, 3], [0, 4, 1], [4, 5, 1], [5, 6, 3], [6, 7, 2], [7, 8, 3], [0, 9, 2], [9, 10, 2], [10, 11, 3], [11, 12, 2], [12, 13, 1], [13, 14, 1]],queries = [[0, 3], [5, 7], [2, 12], [8, 14], [1, 13], [6, 10]]) == [1, 1, 2, 7, 3, 3]\n assert candidate(n = 20,edges = [[0, 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]],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 20,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 2], [4, 5, 3], [5, 6, 3], [6, 7, 4], [7, 8, 4], [8, 9, 5], [9, 10, 5], [10, 11, 6], [11, 12, 6], [12, 13, 7], [13, 14, 7], [14, 15, 8], [15, 16, 8], [16, 17, 9], [17, 18, 9], [18, 19, 10]],queries = [[0, 19], [1, 18], [2, 17], [3, 16]]) == [17, 15, 13, 11]\n assert candidate(n = 15,edges = [[0, 1, 2], [1, 2, 2], [1, 3, 3], [2, 4, 4], [3, 5, 2], [3, 6, 3], [4, 7, 3], [4, 8, 4], [5, 9, 5], [5, 10, 2], [6, 11, 2], [6, 12, 3], [7, 13, 3], [8, 14, 4]],queries = [[0, 14], [1, 13], [2, 12], [4, 11]]) == [2, 2, 1, 3]\n assert candidate(n = 10,edges = [[0, 1, 3], [0, 2, 5], [1, 3, 2], [1, 4, 2], [2, 5, 4], [2, 6, 4], [3, 7, 6], [4, 8, 1], [5, 9, 3]],queries = [[0, 7], [1, 9], [3, 5], [2, 8], [6, 9]]) == [2, 2, 3, 3, 1]\n assert candidate(n = 15,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 5, 6], [2, 6, 7], [3, 7, 8], [4, 8, 9], [5, 9, 10], [6, 10, 11], [7, 11, 12], [8, 12, 13], [9, 13, 14], [10, 14, 15]],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7]]) == [3, 4, 4, 1, 4, 0, 4, 0]\n assert candidate(n = 25,edges = [[0, 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]],queries = [[0, 24], [1, 23], [2, 22], [3, 21], [4, 20], [5, 19], [6, 18], [7, 17], [8, 16], [9, 15]]) == [23, 21, 19, 17, 15, 13, 11, 9, 7, 5]\n assert candidate(n = 100,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 2], [4, 5, 2], [5, 6, 2], [6, 7, 3], [7, 8, 3], [8, 9, 3], [9, 10, 4], [10, 11, 4], [11, 12, 4], [12, 13, 5], [13, 14, 5], [14, 15, 5], [15, 16, 6], [16, 17, 6], [17, 18, 6], [18, 19, 7], [19, 20, 7], [20, 21, 7], [21, 22, 8], [22, 23, 8], [23, 24, 8], [24, 25, 9], [25, 26, 9], [26, 27, 9], [27, 28, 10], [28, 29, 10], [29, 30, 10], [30, 31, 11], [31, 32, 11], [32, 33, 11], [33, 34, 12], [34, 35, 12], [35, 36, 12], [36, 37, 13], [37, 38, 13], [38, 39, 13], [39, 40, 14], [40, 41, 14], [41, 42, 14], [42, 43, 15], [43, 44, 15], [44, 45, 15], [45, 46, 16], [46, 47, 16], [47, 48, 16], [48, 49, 17], [49, 50, 17], [50, 51, 17], [51, 52, 18], [52, 53, 18], [53, 54, 18], [54, 55, 19], [55, 56, 19], [56, 57, 19], [57, 58, 20], [58, 59, 20], [59, 60, 20], [60, 61, 21], [61, 62, 21], [62, 63, 21], [63, 64, 22], [64, 65, 22], [65, 66, 22], [66, 67, 23], [67, 68, 23], [68, 69, 23], [69, 70, 24], [70, 71, 24], [71, 72, 24], [72, 73, 25], [73, 74, 25], [74, 75, 25], [75, 76, 26], [76, 77, 26], [77, 78, 26], [78, 79, 1], [79, 80, 1], [80, 81, 2], [81, 82, 2], [82, 83, 3], [83, 84, 3], [84, 85, 4], [85, 86, 4], [86, 87, 5], [87, 88, 5], [88, 89, 6], [89, 90, 6], [90, 91, 7], [91, 92, 7], [92, 93, 8], [93, 94, 8], [94, 95, 9], [95, 96, 9], [96, 97, 10], [97, 98, 10], [98, 99, 10]],queries = [[0, 99], [1, 98], [2, 97], [3, 96], [4, 95], [5, 94], [6, 93], [7, 92], [8, 91], [9, 90], [10, 89], [11, 88], [12, 87], [13, 86], [14, 85], [15, 84], [16, 83], [17, 82], [18, 81], [19, 80], [20, 79], [21, 78], [22, 77], [23, 76], [24, 75], [25, 74], [26, 73], [27, 72], [28, 71], [29, 70], [30, 69], [31, 68], [32, 67], [33, 66], [34, 65], [35, 64], [36, 63], [37, 62], [38, 61], [39, 60], [40, 59], [41, 58], [42, 57], [43, 56], [44, 55], [45, 54], [46, 53], [47, 52], [48, 51], [49, 50]]) == [93, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 71, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0]\n assert candidate(n = 10,edges = [[0, 1, 3], [0, 2, 3], [1, 3, 5], [1, 4, 5], [2, 5, 7], [2, 6, 7], [3, 7, 9], [3, 8, 9], [4, 9, 11]],queries = [[0, 9], [1, 8], [2, 7], [4, 6]]) == [2, 1, 2, 2]\n assert candidate(n = 40,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 2], [4, 5, 2], [5, 6, 2], [6, 7, 3], [7, 8, 3], [8, 9, 3], [9, 10, 4], [10, 11, 4], [11, 12, 4], [12, 13, 5], [13, 14, 5], [14, 15, 5], [15, 16, 6], [16, 17, 6], [17, 18, 6], [18, 19, 7], [19, 20, 7], [20, 21, 7], [21, 22, 8], [22, 23, 8], [23, 24, 8], [24, 25, 9], [25, 26, 9], [26, 27, 9], [27, 28, 10], [28, 29, 10], [29, 30, 10], [30, 31, 11], [31, 32, 11], [32, 33, 11], [33, 34, 12], [34, 35, 12], [35, 36, 12], [36, 37, 13], [37, 38, 13], [38, 39, 13]],queries = [[0, 39], [1, 38], [2, 37], [3, 36], [4, 35], [5, 34], [6, 33], [7, 32], [8, 31], [9, 30], [10, 29], [11, 28], [12, 27], [13, 26], [14, 25], [15, 24], [16, 23], [17, 22], [18, 21], [19, 20]]) == [36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0]\n assert candidate(n = 12,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [3, 8, 8], [4, 9, 9], [5, 10, 10], [6, 11, 11]],queries = [[0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [7, 11], [8, 10]]) == [2, 3, 3, 0, 2, 1, 5, 5]\n", "comparison": "exact"}, "public_tests": ["7\n[[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]]\n[[0,3],[3,6],[2,6],[0,6]]", "8\n[[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]]\n[[4,6],[0,4],[6,5],[7,4]]"], "hints": ["Root the tree at any node.", "Define a 2D array freq[node][weight] which saves the frequency of each edge weight on the path from the root to each node.", "The frequency of edge weight w on the path from a to b is equal to freq[a][w] + freq[b][w] - freq[lca(a,b)][w] * 2, where lca(a,b) is the lowest common ancestor of a and b in the tree.", "lca(a,b) can be calculated using binary lifting algorithm or Tarjan algorithm."], "metadata": {"canonical_parameter_names": ["n", "edges", "queries"], "leetcode_dataset_entry_point": "Solution().minOperationsQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:04:58+00:00", "tests_total": 26, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "tree", "depth-first-search"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations_queries(n, edges, queries)", "container": null, "callable": "min_operations_queries", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2848, "task_id": "points-that-intersect-with-cars", "difficulty": "Easy", "problem_description": "You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [start_i, end_i] where start_i is the starting point of the i^th car and end_i is the ending point of the i^th car.\n\nReturn the number of integer points on the line that are covered with any part of a car.\n\nExample 1:\n\nInput: nums = [[3,6],[1,5],[4,7]]\nOutput: 7\nExplanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.\n\nExample 2:\n\nInput: nums = [[1,3],[5,8]]\nOutput: 7\nExplanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- nums[i].length == 2\n- 1 <= start_i <= end_i <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [[1, 100]]) == 100\n assert candidate(nums = [[1, 3], [5, 8]]) == 7\n assert candidate(nums = [[1, 1], [2, 2], [3, 3]]) == 3\n assert candidate(nums = [[10, 15], [20, 25]]) == 12\n assert candidate(nums = [[1, 100], [50, 60], [60, 90]]) == 100\n assert candidate(nums = [[5, 10], [10, 15]]) == 11\n assert candidate(nums = [[10, 15], [12, 20], [8, 14]]) == 13\n assert candidate(nums = [[1, 100], [50, 60], [60, 80]]) == 100\n assert candidate(nums = [[10, 15], [12, 20], [18, 25]]) == 16\n assert candidate(nums = [[3, 6], [1, 5], [4, 7]]) == 7\n assert candidate(nums = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15], [16, 18], [19, 21], [22, 24], [25, 27], [28, 30]]) == 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]]) == 20\n assert candidate(nums = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50], [45, 55], [50, 60], [55, 65], [60, 70], [65, 75], [70, 80], [75, 85], [80, 90], [85, 95], [90, 100]]) == 91\n assert candidate(nums = [[1, 20], [5, 25], [10, 30], [15, 35], [20, 40]]) == 40\n assert candidate(nums = [[2, 4], [6, 8], [10, 12], [14, 16], [18, 20]]) == 15\n assert candidate(nums = [[1, 5], [2, 4], [3, 3], [4, 4], [5, 5]]) == 5\n assert candidate(nums = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30], [31, 35], [36, 40]]) == 40\n assert candidate(nums = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70], [75, 80], [85, 90]]) == 54\n assert candidate(nums = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 9\n assert candidate(nums = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 10\n assert candidate(nums = [[1, 50], [51, 100], [1, 100]]) == 100\n assert candidate(nums = [[5, 10], [8, 12], [15, 20], [18, 25], [22, 30]]) == 24\n assert candidate(nums = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50]]) == 30\n assert candidate(nums = [[3, 6], [1, 5], [4, 7], [8, 10], [11, 13]]) == 13\n assert candidate(nums = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]]) == 21\n assert candidate(nums = [[30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [10, 20], [20, 30]]) == 91\n assert candidate(nums = [[1, 50], [51, 100], [25, 75], [76, 99], [1, 100]]) == 100\n assert candidate(nums = [[2, 10], [5, 15], [8, 20], [18, 30]]) == 29\n assert candidate(nums = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50]]) == 41\n assert candidate(nums = [[30, 40], [35, 45], [40, 50], [45, 55]]) == 26\n assert candidate(nums = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]) == 100\n assert candidate(nums = [[10, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100]]) == 91\n assert candidate(nums = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 10\n assert candidate(nums = [[1, 10], [5, 20], [15, 30], [25, 40]]) == 40\n assert candidate(nums = [[5, 8], [8, 11], [11, 14], [14, 17], [17, 20], [20, 23], [23, 26], [26, 29], [29, 32]]) == 28\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]]) == 20\n assert candidate(nums = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70]]) == 61\n assert candidate(nums = [[5, 10], [10, 15], [15, 20]]) == 16\n assert candidate(nums = [[1, 50], [20, 60], [55, 80], [70, 100]]) == 100\n assert candidate(nums = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17]]) == 17\n assert candidate(nums = [[1, 10], [11, 20], [21, 30]]) == 30\n assert candidate(nums = [[10, 30], [20, 40], [30, 50], [40, 60], [50, 70], [60, 80], [70, 90], [80, 100]]) == 91\n assert candidate(nums = [[5, 10], [15, 20], [25, 30], [5, 15], [10, 25]]) == 26\n assert candidate(nums = [[1, 5], [5, 9], [9, 13], [13, 17], [17, 21], [21, 25]]) == 25\n assert candidate(nums = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12]]) == 12\n assert candidate(nums = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15]]) == 15\n assert candidate(nums = [[1, 50], [51, 100], [1, 100], [25, 75], [50, 60]]) == 100\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\n assert candidate(nums = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70], [75, 80], [85, 90], [95, 100]]) == 60\n assert candidate(nums = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]]) == 10\n assert candidate(nums = [[1, 100], [2, 99], [3, 98]]) == 100\n assert candidate(nums = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30]]) == 26\n assert candidate(nums = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 10\n assert candidate(nums = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40]]) == 31\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]]) == 22\n assert candidate(nums = [[3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17], [19, 19]]) == 9\n assert candidate(nums = [[2, 4], [4, 6], [6, 8], [8, 10]]) == 9\n assert candidate(nums = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]]) == 51\n assert candidate(nums = [[1, 50], [5, 45], [10, 40], [15, 35], [20, 30]]) == 50\n assert candidate(nums = [[1, 100], [2, 99], [3, 98], [4, 97]]) == 100\n assert candidate(nums = [[3, 7], [7, 11], [11, 15], [15, 19], [19, 23], [23, 27], [27, 31], [31, 35]]) == 33\n assert candidate(nums = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 5\n assert candidate(nums = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15], [16, 18], [19, 21]]) == 21\n assert candidate(nums = [[1, 100], [50, 100], [1, 50]]) == 100\n assert candidate(nums = [[1, 100], [1, 100], [1, 100], [1, 100], [1, 100], [1, 100], [1, 100], [1, 100], [1, 100], [1, 100]]) == 100\n assert candidate(nums = [[1, 2], [4, 6], [8, 10], [12, 14], [16, 18], [20, 22]]) == 17\n assert candidate(nums = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50]]) == 50\n assert candidate(nums = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 14\n assert candidate(nums = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11]]) == 11\n assert candidate(nums = [[5, 10], [12, 15], [16, 20], [22, 25]]) == 19\n assert candidate(nums = [[1, 10], [5, 15], [10, 20], [15, 25]]) == 25\n assert candidate(nums = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100]]) == 100\n assert candidate(nums = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 10\n assert candidate(nums = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 10\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]]) == 30\n assert candidate(nums = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50], [45, 55], [50, 60]]) == 51\n assert candidate(nums = [[3, 9], [6, 12], [10, 14], [13, 19]]) == 17\n assert candidate(nums = [[5, 15], [15, 25], [25, 35], [35, 45], [45, 55], [55, 65], [65, 75], [75, 85], [85, 95], [95, 100]]) == 96\n assert candidate(nums = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35]]) == 31\n assert candidate(nums = [[1, 10], [2, 8], [3, 7], [4, 6], [5, 5]]) == 10\n assert candidate(nums = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20]]) == 14\n assert candidate(nums = [[30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90]]) == 61\n assert candidate(nums = [[2, 3], [5, 8], [10, 15], [20, 22], [25, 27], [30, 35], [38, 40], [45, 50]]) == 33\n assert candidate(nums = [[5, 10], [11, 15], [16, 20], [21, 25]]) == 21\n", "comparison": "exact"}, "public_tests": ["[[3,6],[1,5],[4,7]]", "[[1,3],[5,8]]"], "hints": ["Sort the array according to first element and then starting from the 0^th index remove the overlapping parts and return the count of non-overlapping points."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().numberOfPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:02+00:00", "tests_total": 85, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_points(nums)", "container": null, "callable": "number_of_points", "parameters": [{"name": "nums", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2849, "task_id": "determine-if-a-cell-is-reachable-at-a-given-time", "difficulty": "Medium", "problem_description": "You are given four integers sx, sy, fx, fy, and a non-negative integer t.\n\nIn an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.\n\nReturn true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.\n\nA cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.\n\nExample 1:\n\nInput: sx = 2, sy = 4, fx = 7, fy = 7, t = 6\nOutput: true\nExplanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.\n\nExample 2:\n\nInput: sx = 3, sy = 1, fx = 7, fy = 3, t = 3\nOutput: false\nExplanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.\n\nConstraints:\n\n- 1 <= sx, sy, fx, fy <= 10^9\n- 0 <= t <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 2,t = 1) == True\n assert candidate(sx = 2,sy = 4,fx = 7,fy = 7,t = 6) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 10,t = 14) == True\n assert candidate(sx = 1000000000,sy = 1000000000,fx = 1000000000,fy = 1000000000,t = 0) == True\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 1,t = 1) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 10,t = 15) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 2,t = 1000000000) == True\n assert candidate(sx = 3,sy = 1,fx = 7,fy = 3,t = 3) == False\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 1,t = 1) == False\n assert candidate(sx = 5,sy = 5,fx = 5,fy = 5,t = 10) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 1,t = 0) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 2,t = 1) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 1,t = 3) == True\n assert candidate(sx = 10,sy = 10,fx = 5,fy = 5,t = 10) == True\n assert candidate(sx = 1,sy = 1,fx = 3,fy = 3,t = 2) == True\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 2,t = 2) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 10) == True\n assert candidate(sx = 10,sy = 10,fx = 20,fy = 20,t = 21) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 2,t = 0) == False\n assert candidate(sx = 5,sy = 5,fx = 5,fy = 5,t = 3) == True\n assert candidate(sx = 10,sy = 10,fx = 10,fy = 10,t = 10) == True\n assert candidate(sx = 5,sy = 5,fx = 5,fy = 6,t = 2) == True\n assert candidate(sx = 1000000000,sy = 1,fx = 1000000000,fy = 1,t = 0) == True\n assert candidate(sx = 1,sy = 1,fx = 4,fy = 4,t = 6) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 5) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 1,t = 1000000000) == True\n assert candidate(sx = 1000,sy = 1000,fx = 999,fy = 999,t = 2) == True\n assert candidate(sx = 5,sy = 5,fx = 1,fy = 1,t = 4) == True\n assert candidate(sx = 500000000,sy = 500000000,fx = 1,fy = 1,t = 999999998) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 11) == True\n assert candidate(sx = 10,sy = 10,fx = 5,fy = 15,t = 10) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 10,t = 19) == True\n assert candidate(sx = 5,sy = 5,fx = 5,fy = 5,t = 1) == False\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 2,t = 4) == True\n assert candidate(sx = 10,sy = 10,fx = 10,fy = 10,t = 0) == True\n assert candidate(sx = 500,sy = 500,fx = 500,fy = 500,t = 0) == True\n assert candidate(sx = 1,sy = 1,fx = 5,fy = 5,t = 7) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 10,t = 10) == True\n assert candidate(sx = 10,sy = 10,fx = 9,fy = 9,t = 2) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 7) == True\n assert candidate(sx = 1,sy = 1,fx = 3,fy = 3,t = 4) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 10,t = 9) == True\n assert candidate(sx = 5,sy = 5,fx = 10,fy = 10,t = 15) == True\n assert candidate(sx = 500000000,sy = 500000000,fx = 500000000,fy = 500000000,t = 1000000000) == True\n assert candidate(sx = 1,sy = 1,fx = 5,fy = 5,t = 8) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 9) == True\n assert candidate(sx = 100,sy = 100,fx = 105,fy = 105,t = 10) == True\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 3,t = 2) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 1,t = 9) == True\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 2,t = 3) == True\n assert candidate(sx = 1000,sy = 1000,fx = 998,fy = 998,t = 4) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 6) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 1,t = 2) == True\n assert candidate(sx = 1,sy = 1,fx = 3,fy = 3,t = 3) == True\n assert candidate(sx = 500000000,sy = 500000000,fx = 600000000,fy = 600000000,t = 100000000) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 3,t = 2) == True\n assert candidate(sx = 10,sy = 10,fx = 15,fy = 15,t = 8) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 2,t = 2) == True\n assert candidate(sx = 5,sy = 5,fx = 15,fy = 15,t = 18) == True\n assert candidate(sx = 1,sy = 1,fx = 3,fy = 3,t = 6) == True\n assert candidate(sx = 1,sy = 1,fx = 3,fy = 1,t = 3) == True\n assert candidate(sx = 1,sy = 1,fx = 1000000000,fy = 1000000000,t = 1000000000) == True\n assert candidate(sx = 1,sy = 1,fx = 1,fy = 3,t = 3) == True\n assert candidate(sx = 999999999,sy = 999999999,fx = 1000000000,fy = 1000000000,t = 1) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 10,t = 18) == True\n assert candidate(sx = 10,sy = 10,fx = 10,fy = 15,t = 7) == True\n assert candidate(sx = 500,sy = 500,fx = 500,fy = 500,t = 5) == True\n assert candidate(sx = 100,sy = 100,fx = 105,fy = 95,t = 10) == True\n assert candidate(sx = 1000000000,sy = 1000000000,fx = 1000000000,fy = 1000000000,t = 1000000000) == True\n assert candidate(sx = 1,sy = 1,fx = 2,fy = 3,t = 3) == True\n assert candidate(sx = 10,sy = 10,fx = 5,fy = 5,t = 9) == True\n assert candidate(sx = 3,sy = 3,fx = 1,fy = 1,t = 4) == True\n assert candidate(sx = 5,sy = 5,fx = 5,fy = 5,t = 0) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 1,t = 10) == True\n assert candidate(sx = 1,sy = 1,fx = 3,fy = 3,t = 5) == True\n assert candidate(sx = 1,sy = 1,fx = 10,fy = 10,t = 17) == True\n assert candidate(sx = 1,sy = 1,fx = 4,fy = 4,t = 5) == True\n assert candidate(sx = 1,sy = 1,fx = 100,fy = 100,t = 198) == True\n assert candidate(sx = 1,sy = 2,fx = 3,fy = 4,t = 4) == True\n", "comparison": "exact"}, "public_tests": ["2\n4\n7\n7\n6", "3\n1\n7\n3\n3"], "hints": ["Minimum time to reach the cell should be less than or equal to given time.", "The answer is true if t is greater or equal than the Chebyshev distance from (sx, sy) to (fx, fy). However, there is one more edge case to be considered.", "The answer is false If sx == fx and sy == fy"], "metadata": {"canonical_parameter_names": ["sx", "sy", "fx", "fy", "t"], "leetcode_dataset_entry_point": "Solution().isReachableAtTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:04+00:00", "tests_total": 89, "tests_dropped": 10, "flags": ["figure_reference", "has_images"], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def is_reachable_at_time(sx, sy, fx, fy, t)", "container": null, "callable": "is_reachable_at_time", "parameters": [{"name": "sx", "type": "Integer"}, {"name": "sy", "type": "Integer"}, {"name": "fx", "type": "Integer"}, {"name": "fy", "type": "Integer"}, {"name": "t", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2850, "task_id": "minimum-moves-to-spread-stones-over-grid", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.\n\nIn one move, you can move a single stone from its current cell to any other cell if the two cells share a side.\n\nReturn the minimum number of moves required to place one stone in each cell.\n\nExample 1:\n\nInput: grid = [[1,1,0],[1,1,1],[1,2,1]]\nOutput: 3\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (2,1) to cell (2,2).\n2- Move one stone from cell (2,2) to cell (1,2).\n3- Move one stone from cell (1,2) to cell (0,2).\nIn total, it takes 3 moves to place one stone in each cell of the grid.\nIt can be shown that 3 is the minimum number of moves required to place one stone in each cell.\n\nExample 2:\n\nInput: grid = [[1,3,0],[1,0,0],[1,0,3]]\nOutput: 4\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (0,1) to cell (0,2).\n2- Move one stone from cell (0,1) to cell (1,1).\n3- Move one stone from cell (2,2) to cell (1,2).\n4- Move one stone from cell (2,2) to cell (2,1).\nIn total, it takes 4 moves to place one stone in each cell of the grid.\nIt can be shown that 4 is the minimum number of moves required to place one stone in each cell.\n\nConstraints:\n\n- grid.length == grid[i].length == 3\n- 0 <= grid[i][j] <= 9\n- Sum of grid is equal to 9.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[2, 2, 1], [1, 1, 1], [1, 1, 1]]) == 0\n assert candidate(grid = [[0, 0, 9], [0, 0, 0], [0, 0, 0]]) == 18\n assert candidate(grid = [[2, 2, 1], [1, 1, 1], [1, 1, 2]]) == 0\n assert candidate(grid = [[1, 3, 0], [1, 0, 0], [1, 0, 3]]) == 4\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 0\n assert candidate(grid = [[1, 2, 1], [2, 1, 2], [1, 2, 1]]) == 0\n assert candidate(grid = [[1, 1, 1], [1, 2, 2], [2, 2, 1]]) == 0\n assert candidate(grid = [[1, 2, 2], [2, 1, 1], [2, 1, 1]]) == 0\n assert candidate(grid = [[3, 0, 0], [0, 3, 0], [0, 0, 3]]) == 8\n assert candidate(grid = [[1, 1, 0], [1, 1, 1], [1, 2, 1]]) == 3\n assert candidate(grid = [[0, 0, 0], [0, 9, 0], [0, 0, 0]]) == 12\n assert candidate(grid = [[1, 1, 1], [1, 2, 1], [1, 1, 1]]) == 0\n assert candidate(grid = [[3, 1, 1], [0, 0, 0], [1, 1, 3]]) == 4\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 9]]) == 18\n assert candidate(grid = [[1, 0, 0], [0, 0, 0], [0, 0, 8]]) == 14\n assert candidate(grid = [[2, 2, 0], [1, 0, 2], [0, 1, 1]]) == 4\n assert candidate(grid = [[0, 1, 0], [1, 0, 0], [0, 0, 7]]) == 12\n assert candidate(grid = [[0, 1, 2], [3, 0, 0], [0, 0, 3]]) == 6\n assert candidate(grid = [[0, 0, 0], [0, 0, 2], [0, 0, 7]]) == 16\n assert candidate(grid = [[0, 1, 2], [2, 0, 1], [1, 2, 0]]) == 4\n assert candidate(grid = [[2, 1, 0], [1, 1, 1], [0, 1, 2]]) == 4\n assert candidate(grid = [[2, 0, 1], [1, 0, 3], [0, 3, 0]]) == 4\n assert candidate(grid = [[4, 0, 1], [0, 0, 0], [1, 0, 3]]) == 6\n assert candidate(grid = [[1, 0, 2], [2, 0, 0], [0, 1, 3]]) == 5\n assert candidate(grid = [[2, 1, 0], [1, 2, 1], [0, 1, 2]]) == 4\n assert candidate(grid = [[0, 2, 0], [3, 0, 0], [0, 1, 3]]) == 6\n assert candidate(grid = [[3, 0, 0], [0, 0, 3], [0, 3, 0]]) == 6\n assert candidate(grid = [[0, 0, 1], [1, 7, 0], [0, 0, 1]]) == 7\n assert candidate(grid = [[2, 2, 2], [1, 1, 1], [0, 0, 0]]) == 6\n assert candidate(grid = [[1, 1, 0], [0, 0, 0], [0, 0, 7]]) == 11\n assert candidate(grid = [[1, 2, 0], [0, 1, 2], [2, 0, 1]]) == 4\n assert candidate(grid = [[0, 2, 0], [1, 0, 3], [0, 4, 0]]) == 5\n assert candidate(grid = [[0, 0, 0], [1, 1, 1], [2, 2, 2]]) == 6\n assert candidate(grid = [[0, 0, 0], [0, 8, 1], [0, 0, 0]]) == 11\n assert candidate(grid = [[0, 1, 0], [0, 7, 0], [0, 1, 0]]) == 10\n assert candidate(grid = [[1, 2, 0], [2, 0, 1], [0, 3, 0]]) == 4\n assert candidate(grid = [[1, 2, 2], [2, 1, 1], [1, 1, 1]]) == 0\n assert candidate(grid = [[2, 2, 0], [1, 1, 0], [0, 0, 3]]) == 5\n assert candidate(grid = [[2, 2, 1], [1, 0, 1], [1, 1, 2]]) == 1\n", "comparison": "exact"}, "public_tests": ["[[1,1,0],[1,1,1],[1,2,1]]", "[[1,3,0],[1,0,0],[1,0,3]]"], "hints": ["There are at most 4 cells with more than one stone.", "Let a be the number of cells containing more than one stone, and b be the number of cells containing no stones. . b^a ≤ 6561. Use this fact to come up with a bruteforce.", "For all empty cells, bruteforce over all possible cells from which a stone can come. Note that a stone will always come from a cell containing at least 2 stones."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:06+00:00", "tests_total": 39, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "backtracking", "bit-manipulation", "matrix", "bitmask"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_moves(grid)", "container": null, "callable": "minimum_moves", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2851, "task_id": "string-transformation", "difficulty": "Hard", "problem_description": "You are given two strings s and t of equal length n. You can perform the following operation on the string s:\n\n- Remove a suffix of s of length l where 0 < l < n and append it at the start of s.\nFor example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab'.\n\nYou are also given an integer k. Return the number of ways in which s can be transformed into t in exactly k operations.\n\nSince the answer can be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: s = \"abcd\", t = \"cdab\", k = 2\nOutput: 2\nExplanation:\nFirst way:\nIn first operation, choose suffix from index = 3, so resulting s = \"dabc\".\nIn second operation, choose suffix from index = 3, so resulting s = \"cdab\".\n\nSecond way:\nIn first operation, choose suffix from index = 1, so resulting s = \"bcda\".\nIn second operation, choose suffix from index = 1, so resulting s = \"cdab\".\n\nExample 2:\n\nInput: s = \"ababab\", t = \"ababab\", k = 1\nOutput: 2\nExplanation:\nFirst way:\nChoose suffix from index = 2, so resulting s = \"ababab\".\n\nSecond way:\nChoose suffix from index = 4, so resulting s = \"ababab\".\n\nConstraints:\n\n- 2 <= s.length <= 5 * 10^5\n- 1 <= k <= 10^15\n- s.length == t.length\n- s and t consist of only lowercase English alphabets.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcd\",t = \"cdab\",k = 2) == 2\n assert candidate(s = \"abcdef\",t = \"defabc\",k = 3) == 21\n assert candidate(s = \"xyzabc\",t = \"abcxyz\",k = 5) == 521\n assert candidate(s = \"abcde\",t = \"eabcd\",k = 10) == 209715\n assert candidate(s = \"xyzxyz\",t = \"zxyzxy\",k = 5) == 1042\n assert candidate(s = \"aaaaaa\",t = \"aaaaaa\",k = 1000000000000000) == 410143883\n assert candidate(s = \"abcabcabc\",t = \"cababcabc\",k = 4) == 0\n assert candidate(s = \"abcdefg\",t = \"efgabcd\",k = 3) == 31\n assert candidate(s = \"zzzz\",t = \"zzzz\",k = 1000000000000000) == 468606845\n assert candidate(s = \"ababab\",t = \"ababab\",k = 1) == 2\n assert candidate(s = \"xyzxyz\",t = \"xyzxyz\",k = 5) == 1041\n assert candidate(s = \"aaaaaa\",t = \"aaaaaa\",k = 5) == 3125\n assert candidate(s = \"aabbcc\",t = \"ccbaab\",k = 4) == 0\n assert candidate(s = \"abababababababababab\",t = \"babababababababababa\",k = 3) == 3430\n assert candidate(s = \"abacabadabacaba\",t = \"dabacabaabacaba\",k = 8) == 98385937\n assert candidate(s = \"abcdabcdabcdabcd\",t = \"dabcdabcdabcdabc\",k = 10) == 162596648\n assert candidate(s = \"repeatedpatternrepeatedpattern\",t = \"atedpatternrepeatedpatternrepe\",k = 99999999999999) == 849771837\n assert candidate(s = \"abcabcabcabcabcabc\",t = \"cabcabcabcabcabcab\",k = 500000000000000) == 685999657\n assert candidate(s = \"mississippi\",t = \"ississippim\",k = 10000000000000) == 499109493\n assert candidate(s = \"aaaaabbbbb\",t = \"bbbbbbaaaa\",k = 15) == 0\n assert candidate(s = \"abcdefghij\",t = \"ghijklmnop\",k = 1) == 0\n assert candidate(s = \"aabbccddeeffgghhiijj\",t = \"ddeeffgghhiijjaabbcc\",k = 5) == 123805\n assert candidate(s = \"aaaaaaaaaaaaaaaa\",t = \"aaaaaaaaaaaaaaaa\",k = 999999999999999) == 644220373\n assert candidate(s = \"abababababababab\",t = \"babababababababa\",k = 987654321) == 765551830\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"mnopqrstuvwxyzabcdefghijkl\",k = 123456789) == 292665766\n assert candidate(s = \"aaaaaaaaaaab\",t = \"baaaaaaaaaaa\",k = 1000000000000000) == 229977291\n assert candidate(s = \"abababababababab\",t = \"babababababababa\",k = 1000000000000000) == 831652769\n assert candidate(s = \"abcdefgabcdefg\",t = \"defgabcdefgabc\",k = 8) == 116532960\n assert candidate(s = \"xyzabcxyzabcxyz\",t = \"abcxyzabcxyzabc\",k = 7) == 0\n assert candidate(s = \"abababababababab\",t = \"babababababababa\",k = 9) == 221679555\n assert candidate(s = \"aaaaabbbbbaaaaabbbbb\",t = \"bbbbbaaaaabbbbbaaaaa\",k = 1000000000000000) == 390681001\n assert candidate(s = \"abracadabraabracadabra\",t = \"racadabraabracadabraab\",k = 600000000000000) == 240096750\n assert candidate(s = \"mississippi\",t = \"issippimiss\",k = 700000000000000) == 393112130\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"ccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabb\",k = 123456789) == 882829284\n assert candidate(s = \"abcdefabcdef\",t = \"defabcdefabc\",k = 1000000000000000) == 459954582\n assert candidate(s = \"racecar\",t = \"caracer\",k = 1000000000000) == 0\n assert candidate(s = \"abcabcabcabcabcabc\",t = \"cabcabcabcabcabcab\",k = 200000000000000) == 265479843\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",t = \"efghijabcdefghijabcdefghijabcd\",k = 1000000000000000) == 154245892\n assert candidate(s = \"abcdefgabcdefg\",t = \"efgabcdefgabcd\",k = 1000000000000000) == 38019381\n assert candidate(s = \"aaaaabbbbbcccccddddd\",t = \"bbbbbcccccdddddaaaaa\",k = 1000000000000000) == 695340504\n assert candidate(s = \"uniquestringunique\",t = \"euniquestringuniqu\",k = 987654321) == 817134159\n assert candidate(s = \"abcdefgh\",t = \"efghabcd\",k = 1000000000000000) == 653970076\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",t = \"cabcabcabcabcabcabcabcabcabcab\",k = 400000000000000) == 403487855\n assert candidate(s = \"zzyzxzyzxzyz\",t = \"zyzxzyzxzyzz\",k = 12) == 535696233\n assert candidate(s = \"racecar\",t = \"caracer\",k = 3) == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",t = \"zzzzzzzzzzzzzzzzzzzz\",k = 500000000000000) == 415651994\n assert candidate(s = \"abcdefghij\",t = \"efghijabcd\",k = 1000000000000000) == 164370742\n assert candidate(s = \"aabbccddeeff\",t = \"ccddeeffaabb\",k = 3) == 111\n assert candidate(s = \"aaaabbbbccccdddd\",t = \"bbbbccccddddaaaa\",k = 987654321) == 845693984\n assert candidate(s = \"aaaaabbbbb\",t = \"bbbbbbaaaa\",k = 10) == 0\n assert candidate(s = \"abacabadabacaba\",t = \"cabacabadabacab\",k = 5) == 0\n assert candidate(s = \"abcabcabcabcabcabc\",t = \"cabcabcabcabcabcab\",k = 20) == 958338650\n assert candidate(s = \"abcdabcdabcdabcd\",t = \"dabcdabcdabcdabc\",k = 300000000000000) == 967363299\n assert candidate(s = \"abcdabcdabcdabcdabcd\",t = \"dabcdabcdabcdabcdabc\",k = 999999999999999) == 446142240\n assert candidate(s = \"abcabcabcabcabcabc\",t = \"cabcabcabcabcabcab\",k = 6) == 8045856\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"nopqrstuvwxyzabcdefghijklm\",k = 1000000000000000) == 907107378\n assert candidate(s = \"zzzzzzzzzzzzzzzz\",t = \"zzzzzzzzzzzzzzzz\",k = 1000000000000000) == 663305532\n assert candidate(s = \"thisthisthisthisthisthisthis\",t = \"histhisthisthisthisthisthist\",k = 10000000000000) == 937749612\n assert candidate(s = \"hellohellohellohello\",t = \"lohellohellohellohel\",k = 7) == 178774348\n", "comparison": "exact"}, "public_tests": ["\"abcd\"\n\"cdab\"\n2", "\"ababab\"\n\"ababab\"\n1"], "hints": ["String t can be only constructed if it is a rotated version of string s.", "Use KMP algorithm or Z algorithm to find the number of indices from where s is equal to t.", "Use Dynamic Programming to count the number of ways."], "metadata": {"canonical_parameter_names": ["s", "t", "k"], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:09+00:00", "tests_total": 89, "tests_dropped": 30, "flags": [], "topic_tags": ["math", "string", "dynamic-programming", "string-matching"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_ways(s, t, k)", "container": null, "callable": "number_of_ways", "parameters": [{"name": "s", "type": "String"}, {"name": "t", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2855, "task_id": "minimum-right-shifts-to-sort-the-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.\n\nA right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.\n\nExample 1:\n\nInput: nums = [3,4,5,1,2]\nOutput: 2\nExplanation:\nAfter the first right shift, nums = [2,3,4,5,1].\nAfter the second right shift, nums = [1,2,3,4,5].\nNow nums is sorted; therefore the answer is 2.\n\nExample 2:\n\nInput: nums = [1,3,5]\nOutput: 0\nExplanation: nums is already sorted therefore, the answer is 0.\n\nExample 3:\n\nInput: nums = [2,1,4]\nOutput: -1\nExplanation: It's impossible to sort the array using right shifts.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n- nums contains distinct integers.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [4, 5, 6, 1, 2, 3]) == 3\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [50, 10, 20, 30, 40]) == 4\n assert candidate(nums = [1, 3, 5]) == 0\n assert candidate(nums = [2, 1, 4]) == -1\n assert candidate(nums = [4, 5, 1, 2, 3]) == 3\n assert candidate(nums = [2, 3, 4, 5, 1]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 1, 2, 3, 4]) == 4\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 99]) == 9\n assert candidate(nums = [3, 1, 2]) == 2\n assert candidate(nums = [2, 3, 1]) == 1\n assert candidate(nums = [3, 4, 5, 1, 2]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [3, 1, 2, 4, 5]) == -1\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 1\n assert candidate(nums = [1, 3, 2, 4, 5]) == -1\n assert candidate(nums = [5, 4, 2, 1, 3]) == -1\n assert candidate(nums = [3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 1]) == -1\n assert candidate(nums = [3, 5, 4, 1, 2]) == -1\n assert candidate(nums = [15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 14\n assert candidate(nums = [6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [4, 2, 5, 1, 3]) == -1\n assert candidate(nums = [2, 3, 4, 5, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 11\n assert candidate(nums = [7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 0\n assert candidate(nums = [5, 1, 2, 3, 4]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12]) == -1\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [1, 2, 3, 5, 4]) == 1\n assert candidate(nums = [90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [15, 16, 17, 18, 19, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 12\n assert candidate(nums = [5, 1, 2, 3, 4, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == 3\n assert candidate(nums = [3, 1, 4, 2]) == -1\n assert candidate(nums = [7, 8, 9, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 1, 2]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 4\n assert candidate(nums = [9, 10, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [7, 8, 9, 10, 11, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [2, 5, 1, 3, 4]) == -1\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 1, 2]) == 2\n assert candidate(nums = [1, 2, 4, 5, 3]) == 1\n assert candidate(nums = [3, 5, 4, 1, 2]) == -1\n assert candidate(nums = [9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [5, 1, 3, 4, 2]) == -1\n assert candidate(nums = [3, 1, 2, 5, 4]) == -1\n assert candidate(nums = [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 2, 3, 5, 4]) == 1\n assert candidate(nums = [2, 3, 4, 1, 5]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [4, 3, 1, 2, 5]) == -1\n assert candidate(nums = [1, 3, 2]) == 1\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 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]) == 29\n assert candidate(nums = [8, 9, 10, 11, 1, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(nums = [5, 2, 3, 4, 1]) == -1\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4]) == 4\n assert candidate(nums = [20, 30, 40, 50, 60, 70, 80, 90, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == -1\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 1, 2, 3]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10]) == -1\n assert candidate(nums = [2, 3, 4, 5, 1, 6]) == -1\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == 2\n assert candidate(nums = [15, 25, 35, 45, 55, 10, 20, 30, 40]) == -1\n assert candidate(nums = [9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [4, 1, 2, 5, 3]) == -1\n assert candidate(nums = [4, 5, 1, 2, 3]) == 3\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 1]) == 1\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 1, 2]) == 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]) == 0\n assert candidate(nums = [3, 1, 2, 4, 6, 5]) == -1\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 1]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12]) == -1\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8]) == -1\n assert candidate(nums = [98, 99, 100, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97]) == 97\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == 99\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4]) == 4\n assert candidate(nums = [8, 1, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(nums = [11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 4, 3]) == 1\n assert candidate(nums = [2, 3, 4, 5, 1, 6, 7]) == -1\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4]) == 4\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 1, 2, 3]) == 3\n assert candidate(nums = [3, 2, 1]) == -1\n assert candidate(nums = [9, 10, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 1]) == 1\n assert candidate(nums = [10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [2, 4, 1, 5, 3]) == -1\n assert candidate(nums = [100, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == 99\n assert candidate(nums = [2, 3, 1, 5, 4]) == -1\n assert candidate(nums = [5, 3, 4, 1, 2]) == -1\n assert candidate(nums = [99, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == 18\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(nums = [99, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20]) == 18\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 12]) == -1\n assert candidate(nums = [1, 3, 2, 5, 4]) == -1\n assert candidate(nums = [2, 3, 5, 4, 1]) == -1\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4]) == 4\n assert candidate(nums = [6, 7, 8, 9, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 14\n assert candidate(nums = [1, 3, 2]) == 1\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == -1\n assert candidate(nums = [2, 1, 3, 4, 5]) == -1\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4]) == 4\n assert candidate(nums = [8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(nums = [20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 19\n assert candidate(nums = [3, 4, 1, 2, 5]) == -1\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 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]) == 49\n assert candidate(nums = [11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [2, 3, 1, 4, 5]) == -1\n assert candidate(nums = [99, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98]) == 97\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7]) == 7\n", "comparison": "exact"}, "public_tests": ["[3,4,5,1,2]", "[1,3,5]", "[2,1,4]"], "hints": ["Find the pivot point around which the array is rotated.", "Will the answer exist if there is more than one point where nums[i] < nums[i-1]?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumRightShifts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:14+00:00", "tests_total": 129, "tests_dropped": 1, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_right_shifts(nums)", "container": null, "callable": "minimum_right_shifts", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2856, "task_id": "minimum-array-length-after-pair-removals", "difficulty": "Medium", "problem_description": "Given an integer array num sorted in non-decreasing order.\n\nYou can perform the following operation any number of times:\n\n- Choose two indices, i and j, where nums[i] < nums[j].\n- Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.\n\nReturn the minimum length of nums after applying the operation zero or more times.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 0\nExplanation:\n\nExample 2:\n\nInput: nums = [1,1,2,2,3,3]\nOutput: 0\nExplanation:\n\nExample 3:\n\nInput: nums = [1000000000,1000000000]\nOutput: 2\nExplanation:\nSince both numbers are equal, they cannot be removed.\n\nExample 4:\n\nInput: nums = [2,3,4,4,4]\nOutput: 1\nExplanation:\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- nums is sorted in non-decreasing order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 9\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 4]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 3]) == 0\n assert candidate(nums = [1000000000, 1000000000]) == 2\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3]) == 1\n assert candidate(nums = [2, 3, 4, 4, 4]) == 1\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 3]) == 1\n assert candidate(nums = [1, 1, 2, 3, 3, 4, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 1\n assert candidate(nums = [1, 1, 1, 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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]) == 1\n assert candidate(nums = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6]) == 0\n assert candidate(nums = [1, 1, 1, 1, 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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 8, 9, 10, 11, 12, 12, 13, 14, 15, 16, 16, 17, 18, 19, 20, 20, 20, 20, 20, 20, 21, 22, 23, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\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, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 20\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]) == 0\n assert candidate(nums = [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, 5]) == 0\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, 7, 8, 9]) == 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, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 1, 1, 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, 8, 8, 8, 8, 8, 8, 8, 8]) == 0\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, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]) == 1\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 1, 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, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\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]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) == 1\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, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10]) == 1\n assert candidate(nums = [1, 2, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 14\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]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]) == 1\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, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]) == 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, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10]) == 1\n assert candidate(nums = [1, 2, 3, 3, 3, 3, 3, 3, 3, 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]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6]) == 1\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [1, 1, 1, 2, 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 1\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, 7]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]) == 0\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, 7, 7, 7, 7, 8, 8, 8, 8, 8]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4]) == 1\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, 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, 9, 9, 9, 9, 9, 9]) == 1\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [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, 3, 3, 4, 4, 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, 5]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 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]) == 42\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 9, 9]) == 1\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 10\n assert candidate(nums = [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]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 1\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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6]) == 1\n assert candidate(nums = [1, 1, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\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, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4]) == 1\n assert candidate(nums = [1, 1, 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]) == 0\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, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 0\n assert candidate(nums = [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, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 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, 3, 3, 3, 3, 3, 4, 4, 4, 4, 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, 5, 5, 5, 5, 5]) == 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, 21, 22, 23, 24, 25]) == 1\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]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 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]) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 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]) == 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, 1, 1, 1, 1, 1, 1, 1, 1]) == 38\n assert candidate(nums = [1, 2, 2, 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]) == 1\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]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 1\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, 2, 2, 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]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 3, 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, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 1\n assert candidate(nums = [1, 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]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8]) == 1\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]) == 0\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, 4, 4, 4, 4, 4, 4]) == 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, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 1\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]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4]) == 1\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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 16\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4]) == 1\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, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8]) == 0\n assert candidate(nums = [1, 2, 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, 3, 3, 3, 3, 3]) == 34\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 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, 8, 9]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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, 10, 10]) == 23\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[1,1,2,2,3,3]", "[1000000000,1000000000]", "[2,3,4,4,4]"], "hints": ["To minimize the length of the array, we should maximize the number of operations performed.", "To perform k operations, it is optimal to use the smallest k values and the largest k values in nums.", "What is the best way to make pairs from the smallest k values and the largest k values so it is possible to remove all the pairs?", "If we consider the smallest k values and the largest k values as two separate sorted 0-indexed arrays, a and b, It is optimal to pair a[i] and b[i]. So, a k is valid if a[i] < b[i] for all i in the range [0, k - 1].", "The greatest possible valid k can be found using binary search.", "The answer is nums.length - 2 * k."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minLengthAfterRemovals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:16+00:00", "tests_total": 121, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "two-pointers", "binary-search", "greedy", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def min_length_after_removals(nums)", "container": null, "callable": "min_length_after_removals", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2857, "task_id": "count-pairs-of-points-with-distance-k", "difficulty": "Medium", "problem_description": "You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [x_i, y_i] are the coordinates of the i^th point in a 2D plane.\n\nWe define the distance between two points (x_1, y_1) and (x_2, y_2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.\n\nReturn the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.\n\nExample 1:\n\nInput: coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5\nOutput: 2\nExplanation: We can choose the following pairs:\n- (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.\n- (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.\n\nExample 2:\n\nInput: coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0\nOutput: 10\nExplanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.\n\nConstraints:\n\n- 2 <= coordinates.length <= 50000\n- 0 <= x_i, y_i <= 10^6\n- 0 <= k <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3]],k = 2) == 2\n assert candidate(coordinates = [[1, 3], [1, 3], [1, 3], [1, 3], [1, 3]],k = 0) == 10\n assert candidate(coordinates = [[1, 2], [4, 2], [1, 3], [5, 2]],k = 5) == 2\n assert candidate(coordinates = [[0, 0], [0, 1], [1, 0], [1, 1]],k = 1) == 4\n assert candidate(coordinates = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100], [110, 110]],k = 20) == 3\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15]],k = 15) == 0\n assert candidate(coordinates = [[5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]],k = 0) == 45\n assert candidate(coordinates = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],k = 15) == 0\n assert candidate(coordinates = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],k = 10) == 0\n assert candidate(coordinates = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],k = 25) == 0\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19]],k = 15) == 0\n assert candidate(coordinates = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],k = 31) == 0\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 9) == 0\n assert candidate(coordinates = [[5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]],k = 0) == 36\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 2) == 5\n assert candidate(coordinates = [[0, 0], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]],k = 15) == 1\n assert candidate(coordinates = [[2, 3], [5, 7], [8, 10], [3, 6], [1, 2]],k = 8) == 0\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 0) == 0\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],k = 1) == 9\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 0) == 10\n assert candidate(coordinates = [[100000, 100000], [99999, 99999], [99998, 99998], [100001, 100001]],k = 1) == 0\n assert candidate(coordinates = [[1, 2], [4, 2], [1, 3], [5, 2], [2, 1], [5, 1], [3, 5], [2, 4], [4, 4], [5, 5]],k = 5) == 5\n assert candidate(coordinates = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],k = 30) == 0\n assert candidate(coordinates = [[0, 1], [1, 0], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6]],k = 3) == 0\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 9) == 0\n assert candidate(coordinates = [[1, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19]],k = 2) == 0\n assert candidate(coordinates = [[1, 0], [0, 1], [1, 1], [0, 0], [2, 2], [3, 3], [4, 4]],k = 2) == 3\n assert candidate(coordinates = [[50000, 50000], [50001, 50001], [50002, 50002], [50003, 50003], [50004, 50004], [50005, 50005], [50006, 50006], [50007, 50007], [50008, 50008], [50009, 50009]],k = 1) == 0\n assert candidate(coordinates = [[10, 20], [20, 10], [30, 40], [40, 30], [50, 60], [60, 50], [70, 80], [80, 70], [90, 100], [100, 90]],k = 20) == 0\n assert candidate(coordinates = [[2, 5], [3, 7], [10, 8], [5, 5], [1, 1], [6, 9]],k = 6) == 0\n assert candidate(coordinates = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],k = 15) == 0\n assert candidate(coordinates = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],k = 0) == 45\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 2) == 5\n assert candidate(coordinates = [[1, 0], [0, 1], [1, 1], [0, 0], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]],k = 2) == 5\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 3) == 0\n assert candidate(coordinates = [[1, 2], [4, 2], [1, 3], [5, 2], [2, 3], [3, 4], [5, 5], [6, 6], [7, 7], [8, 8]],k = 5) == 2\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 0) == 0\n assert candidate(coordinates = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9], [11, 12], [12, 11], [13, 14], [14, 13], [15, 16], [16, 15]],k = 3) == 0\n assert candidate(coordinates = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9]],k = 3) == 0\n assert candidate(coordinates = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],k = 15) == 3\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 5) == 0\n assert candidate(coordinates = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000]],k = 100) == 0\n assert candidate(coordinates = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],k = 0) == 45\n assert candidate(coordinates = [[1, 1], [2, 2], [1, 1], [2, 2], [1, 1], [2, 2], [1, 1], [2, 2], [1, 1], [2, 2]],k = 0) == 20\n assert candidate(coordinates = [[10, 1], [1, 10], [10, 10], [1, 1], [0, 0], [2, 2], [3, 3], [4, 4]],k = 9) == 0\n assert candidate(coordinates = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],k = 10) == 0\n assert candidate(coordinates = [[2, 3], [3, 2], [4, 1], [1, 4], [5, 0], [0, 5], [6, 7], [7, 6], [8, 9], [9, 8]],k = 7) == 0\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 18) == 2\n assert candidate(coordinates = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],k = 1) == 4\n assert candidate(coordinates = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],k = 50) == 0\n assert candidate(coordinates = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600]],k = 100) == 0\n assert candidate(coordinates = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80]],k = 10) == 0\n assert candidate(coordinates = [[500000, 500000], [500001, 500001], [500002, 500002], [500003, 500003], [500004, 500004]],k = 1) == 0\n assert candidate(coordinates = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],k = 1) == 0\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]],k = 0) == 0\n assert candidate(coordinates = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],k = 1) == 0\n assert candidate(coordinates = [[10, 10], [20, 10], [30, 10], [40, 10], [50, 10], [60, 10], [70, 10], [80, 10], [90, 10], [100, 10]],k = 10) == 2\n assert candidate(coordinates = [[255, 255], [254, 254], [253, 253], [252, 252], [251, 251], [250, 250]],k = 3) == 0\n assert candidate(coordinates = [[10, 20], [15, 25], [20, 10], [25, 15]],k = 15) == 0\n assert candidate(coordinates = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],k = 1) == 0\n assert candidate(coordinates = [[0, 1], [1, 0], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6], [8, 9], [9, 8]],k = 3) == 0\n assert candidate(coordinates = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]],k = 0) == 45\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 2) == 4\n assert candidate(coordinates = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],k = 3) == 0\n assert candidate(coordinates = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],k = 1) == 0\n assert candidate(coordinates = [[1, 2], [4, 6], [7, 8], [10, 12], [13, 14], [16, 18], [19, 20], [22, 24], [25, 26], [28, 30]],k = 3) == 0\n assert candidate(coordinates = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 0) == 0\n assert candidate(coordinates = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],k = 0) == 45\n", "comparison": "exact"}, "public_tests": ["[[1,2],[4,2],[1,3],[5,2]]\n5", "[[1,3],[1,3],[1,3],[1,3],[1,3]]\n0"], "hints": ["Suppose that x = x_1 XOR x_2 and y = y_1 XOR y_2 then we can get x_2 = x XOR x_1 and y_2 = y XOR y_1.", "We are supposed to have k = x + y so we can get x_2 = x XOR x_1 and y_2 = (k - x) XOR y_1.", "We can iterate over all possible values of x and count the number of points (x_1, x_2) and (x_2, y_2)."], "metadata": {"canonical_parameter_names": ["coordinates", "k"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:19+00:00", "tests_total": 91, "tests_dropped": 23, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def count_pairs(coordinates, k)", "container": null, "callable": "count_pairs", "parameters": [{"name": "coordinates", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2858, "task_id": "minimum-edge-reversals-so-every-node-is-reachable", "difficulty": "Hard", "problem_description": "There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.\n\nYou are given an integer n and a 2D integer array edges, where edges[i] = [u_i, v_i] represents a directed edge going from node u_i to node v_i.\n\nAn edge reversal changes the direction of an edge, i.e., a directed edge going from node u_i to node v_i becomes a directed edge going from node v_i to node u_i.\n\nFor every node i in the range [0, n - 1], your task is to independently calculate the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n\nReturn an integer array answer, where answer[i] is the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n\nExample 1:\n\nInput: n = 4, edges = [[2,0],[2,1],[1,3]]\nOutput: [1,1,0,2]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edge [2,0], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 1.\nFor node 1: after reversing the edge [2,1], it is possible to reach any other node starting from node 1.\nSo, answer[1] = 1.\nFor node 2: it is already possible to reach any other node starting from node 2.\nSo, answer[2] = 0.\nFor node 3: after reversing the edges [1,3] and [2,1], it is possible to reach any other node starting from node 3.\nSo, answer[3] = 2.\n\nExample 2:\n\nInput: n = 3, edges = [[1,2],[2,0]]\nOutput: [2,0,1]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edges [2,0] and [1,2], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 2.\nFor node 1: it is already possible to reach any other node starting from node 1.\nSo, answer[1] = 0.\nFor node 2: after reversing the edge [1, 2], it is possible to reach any other node starting from node 2.\nSo, answer[2] = 1.\n\nConstraints:\n\n- 2 <= n <= 10^5\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= u_i == edges[i][0] < n\n- 0 <= v_i == edges[i][1] < n\n- u_i != v_i\n- The input is generated such that if the edges were bi-directional, the graph would be a tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == [0, 1, 2, 3, 4, 5, 6]\n assert candidate(n = 4,edges = [[2, 0], [2, 1], [1, 3]]) == [1, 1, 0, 2]\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [0, 1, 2, 3, 4]\n assert candidate(n = 5,edges = [[0, 1], [2, 0], [3, 2], [4, 2]]) == [3, 4, 2, 1, 1]\n assert candidate(n = 5,edges = [[0, 1], [2, 0], [3, 2], [4, 3]]) == [3, 4, 2, 1, 0]\n assert candidate(n = 3,edges = [[1, 2], [2, 0]]) == [2, 0, 1]\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [0, 1, 2, 3, 4, 5]\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [6, 7], [3, 8], [8, 9], [9, 10], [10, 11]]) == [0, 1, 2, 3, 1, 2, 3, 4, 4, 5, 6, 7]\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8], [8, 9], [9, 10]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5]\n assert candidate(n = 13,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(n = 16,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14]]) == [0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7]]) == [0, 1, 1, 2, 2, 2, 2, 3]\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 14,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(n = 13,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == [0, 1, 1, 2, 2, 2, 2]\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(n = 7,edges = [[0, 1], [1, 3], [2, 1], [4, 1], [5, 2], [6, 2]]) == [4, 5, 4, 6, 4, 3, 3]\n assert candidate(n = 11,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3]\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [5, 8], [8, 9], [9, 10]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5]\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [6, 7]]) == [0, 1, 2, 3, 1, 2, 3, 4]\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3]\n assert candidate(n = 16,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3]\n assert candidate(n = 20,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]\n assert candidate(n = 7,edges = [[0, 1], [1, 3], [3, 2], [2, 4], [4, 5], [5, 6]]) == [0, 1, 3, 2, 4, 5, 6]\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == [0, 1, 1, 2, 2, 2]\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3]\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8], [8, 9], [9, 10], [10, 11]]) == [0, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5, 6]\n assert candidate(n = 6,edges = [[0, 1], [1, 3], [3, 4], [4, 5], [2, 3]]) == [1, 2, 2, 3, 4, 5]\n assert candidate(n = 14,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n", "comparison": "exact"}, "public_tests": ["4\n[[2,0],[2,1],[1,3]]", "3\n[[1,2],[2,0]]"], "hints": ["The problem can be solved using tree DP.", "Using node 0 as the root, let dp[x] be the minimum number of edge reversals so node x can reach every node in its subtree.", "Using a DFS traversing the edges bidirectionally, we can compute dp.\ndp[x] = dp[y] + (1 if the edge between x and y is going from y to x; 0 otherwise), where x is the parent of y.", "Let answer[x] be the minimum number of edge reversals so it is possible to reach any other node starting from node x.", "Using another DFS starting from node 0 and traversing the edges bidirectionally, we can compute answer.\nanswer[0] = dp[0]\nanswer[y] = answer[x] + (1 if the edge between x and y is going from x to y; -1 otherwise), where x is the parent of y."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().minEdgeReversals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:21+00:00", "tests_total": 42, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["dynamic-programming", "depth-first-search", "breadth-first-search", "graph"]}, "language": "ruby", "interface": {"raw_signature": "def min_edge_reversals(n, edges)", "container": null, "callable": "min_edge_reversals", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2859, "task_id": "sum-of-values-at-indices-with-k-set-bits", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums and an integer k.\n\nReturn an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.\n\nThe set bits in an integer are the 1's present when it is written in binary.\n\n- For example, the binary representation of 21 is 10101, which has 3 set bits.\n\nExample 1:\n\nInput: nums = [5,10,1,5,2], k = 1\nOutput: 13\nExplanation: The binary representation of the indices are:\n0 = 000_2\n1 = 001_2\n2 = 010_2\n3 = 011_2\n4 = 100_2Indices 1, 2, and 4 have k = 1 set bits in their binary representation.\nHence, the answer is nums[1] + nums[2] + nums[4] = 13.\n\nExample 2:\n\nInput: nums = [4,3,2,1], k = 2\nOutput: 1\nExplanation: The binary representation of the indices are:\n0 = 00_2\n1 = 01_2\n2 = 10_2\n3 = 11_2Only index 3 has k = 2 set bits in its binary representation.\nHence, the answer is nums[3] = 1.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^5\n- 0 <= k <= 10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 0) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 0\n assert candidate(nums = [32, 16, 8, 4, 2, 1],k = 3) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],k = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 8\n assert candidate(nums = [31, 14, 7, 3, 1],k = 0) == 31\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 2) == 17\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 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],k = 4) == 1\n assert candidate(nums = [4, 3, 2, 1],k = 2) == 1\n assert candidate(nums = [5, 10, 1, 5, 2],k = 1) == 13\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 3) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160],k = 4) == 160\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],k = 1) == 556\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215, 225, 235, 245, 255],k = 4) == 390\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 5) == 0\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128],k = 3) == 392\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],k = 0) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 5) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 2) == 255\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],k = 2) == 120\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],k = 4) == 80\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 2) == 880\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],k = 2) == 10\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 5) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 45\n assert candidate(nums = [31, 62, 93, 124, 155, 186, 217, 248, 279, 310, 341, 372, 403, 434, 465],k = 2) == 1581\n assert candidate(nums = [15, 23, 45, 67, 89, 101, 113, 125, 137, 149],k = 3) == 125\n assert candidate(nums = [12, 34, 56, 78, 90, 102, 114, 126, 138, 150, 162, 174],k = 3) == 300\n assert candidate(nums = [3, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41],k = 3) == 29\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175, 182, 189, 196, 203, 210, 217, 224, 231, 238, 245, 252, 259, 266, 273, 280, 287, 294, 301, 308, 315, 322, 329, 336, 343, 350, 357, 364, 371, 378, 385, 392, 399, 406, 413, 420, 427, 434, 441, 448, 455, 462, 469, 476, 483, 490, 497, 504, 511],k = 6) == 448\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600],k = 2) == 5100\n assert candidate(nums = [1234, 2345, 3456, 4567, 5678, 6789, 7890, 8901, 9012, 10123, 11234, 12345, 13456, 14567, 15678, 16789, 17890, 18901, 19012, 20123, 21234, 22345, 23456, 24567, 25678, 26789, 27890, 28901, 29012, 30123, 31234, 32345, 33456],k = 5) == 32345\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 5) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 80\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],k = 6) == 0\n assert candidate(nums = [12345, 67890, 54321, 98765, 43210, 87654, 32109, 76543, 21098, 65432],k = 2) == 283960\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],k = 3) == 196\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1) == 1900\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],k = 2) == 255\n assert candidate(nums = [65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 6) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3) == 800\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 4) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 2) == 2700\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],k = 2) == 357\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 24\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120],k = 4) == 0\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981],k = 5) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180, 189, 198, 207, 216, 225, 234, 243, 252, 261, 270, 279, 288, 297, 306, 315, 324, 333, 342, 351, 360, 369, 378, 387, 396, 405, 414, 423, 432, 441, 450, 459, 468, 477, 486, 495, 504, 513, 522, 531, 540, 549, 558, 567, 576, 585, 594, 603, 612, 621, 630],k = 7) == 0\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 6) == 0\n assert candidate(nums = [999, 888, 777, 666, 555, 444, 333, 222, 111],k = 1) == 2331\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1],k = 6) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1) == 1900\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 2) == 96\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767],k = 3) == 53500\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 4) == 31\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],k = 5) == 0\n assert candidate(nums = [12345, 23456, 34567, 45678, 56789, 67890, 78901, 89012, 90123, 12345],k = 3) == 89012\n assert candidate(nums = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 100000\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],k = 0) == 1\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987],k = 3) == 1152\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],k = 10) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 3) == 8\n assert candidate(nums = [98765, 43210, 11111, 88888, 55555, 22222, 77777, 33333, 66666, 44444, 7777, 5555, 2222, 8888, 9999],k = 3) == 57775\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140],k = 5) == 0\n", "comparison": "exact"}, "public_tests": ["[5,10,1,5,2]\n1", "[4,3,2,1]\n2"], "hints": ["Iterate through the indices i in the range [0, n - 1], for each index i count the number of bits in its binary representation. If it is k, add nums[i] to the result."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().sumIndicesWithKSetBits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:24+00:00", "tests_total": 79, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def sum_indices_with_k_set_bits(nums, k)", "container": null, "callable": "sum_indices_with_k_set_bits", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2860, "task_id": "happy-students", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.\n\nThe i^th student will become happy if one of these two conditions is met:\n\n- The student is selected and the total number of selected students is strictly greater than nums[i].\n- The student is not selected and the total number of selected students is strictly less than nums[i].\n\nReturn the number of ways to select a group of students so that everyone remains happy.\n\nExample 1:\n\nInput: nums = [1,1]\nOutput: 2\nExplanation:\nThe two possible ways are:\nThe class teacher selects no student.\nThe class teacher selects both students to form the group.\nIf the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.\n\nExample 2:\n\nInput: nums = [6,0,3,3,6,7,2,7]\nOutput: 3\nExplanation:\nThe three possible ways are:\nThe class teacher selects the student with index = 1 to form the group.\nThe class teacher selects the students with index = 1, 2, 3, 6 to form the group.\nThe class teacher selects all the students to form the group.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] < nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4]) == 2\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [10, 0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 1\n assert candidate(nums = [4, 4, 4, 4, 3, 3, 3, 3, 2, 2]) == 2\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4]) == 1\n assert candidate(nums = [3, 2, 1, 0]) == 1\n assert candidate(nums = [0]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 1\n assert candidate(nums = [6, 0, 3, 3, 6, 7, 2, 7]) == 3\n assert candidate(nums = [1, 1]) == 2\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [4, 3, 2, 1, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 0, 2, 3, 0, 2, 1, 3, 2, 1, 0, 3, 2, 1, 0]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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]) == 2\n assert candidate(nums = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == 2\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 1\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 0, 0, 0, 0, 0]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 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]) == 2\n assert candidate(nums = [2, 2, 2, 1, 1, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums = [3, 3, 2, 2, 1, 1, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 1\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [2, 0, 3, 1, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 1\n assert candidate(nums = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [10, 1, 10, 2, 10, 3, 10, 4, 10, 5, 10, 6, 10, 7, 10, 8, 10, 9, 10, 10]) == 2\n assert candidate(nums = [4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 2\n assert candidate(nums = [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, 4, 4, 4, 4]) == 2\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [5, 3, 8, 2, 7, 4, 1, 6, 9, 0]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 11, 10, 13, 12, 15, 14]) == 1\n assert candidate(nums = [7, 3, 1, 8, 5, 4, 9, 6, 2, 0, 10, 11, 12, 13, 14]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\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]) == 2\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(nums = [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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]) == 2\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 1\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]) == 2\n", "comparison": "exact"}, "public_tests": ["[1,1]", "[6,0,3,3,6,7,2,7]"], "hints": ["If a student with nums[i] = x is selected, all the students with nums[j] <= x must be selected.", "If a student with nums[i] = x is not selected, all the students with nums[j] >= x must not be selected.", "Sort values in nums and try all possible values for x from 0 to n separately."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:26+00:00", "tests_total": 120, "tests_dropped": 23, "flags": [], "topic_tags": ["array", "sorting", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def count_ways(nums)", "container": null, "callable": "count_ways", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2861, "task_id": "maximum-number-of-alloys", "difficulty": "Medium", "problem_description": "You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.\n\nFor the i^th machine to create an alloy, it needs composition[i][j] units of metal of type j. Initially, you have stock[i] units of metal type i, and purchasing one unit of metal type i costs cost[i] coins.\n\nGiven integers n, k, budget, a 1-indexed 2D array composition, and 1-indexed arrays stock and cost, your goal is to maximize the number of alloys the company can create while staying within the budget of budget coins.\n\nAll alloys must be created with the same machine.\n\nReturn the maximum number of alloys that the company can create.\n\nExample 1:\n\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]\nOutput: 2\nExplanation: It is optimal to use the 1^st machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 2 units of metal of the 1^st type.\n- 2 units of metal of the 2^nd type.\n- 2 units of metal of the 3^rd type.\nIn total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.\nNotice that we have 0 units of metal of each type and we have to buy all the required units of metal.\nIt can be proven that we can create at most 2 alloys.\n\nExample 2:\n\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]\nOutput: 5\nExplanation: It is optimal to use the 2^nd machine to create alloys.\nTo create 5 alloys we need to buy:\n- 5 units of metal of the 1^st type.\n- 5 units of metal of the 2^nd type.\n- 0 units of metal of the 3^rd type.\nIn total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.\nIt can be proven that we can create at most 5 alloys.\n\nExample 3:\n\nInput: n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]\nOutput: 2\nExplanation: It is optimal to use the 3^rd machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 1 unit of metal of the 1^st type.\n- 1 unit of metal of the 2^nd type.\nIn total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.\nIt can be proven that we can create at most 2 alloys.\n\nConstraints:\n\n- 1 <= n, k <= 100\n- 0 <= budget <= 10^8\n- composition.length == k\n- composition[i].length == n\n- 1 <= composition[i][j] <= 100\n- stock.length == cost.length == n\n- 0 <= stock[i] <= 10^8\n- 1 <= cost[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,k = 2,budget = 15,composition = [[1, 1, 1], [1, 1, 10]],stock = [0, 0, 0],cost = [1, 2, 3]) == 2\n assert candidate(n = 1,k = 1,budget = 100,composition = [[5]],stock = [0],cost = [20]) == 1\n assert candidate(n = 2,k = 2,budget = 20,composition = [[1, 2], [2, 1]],stock = [10, 10],cost = [1, 1]) == 13\n assert candidate(n = 3,k = 2,budget = 15,composition = [[1, 1, 1], [1, 1, 10]],stock = [0, 0, 100],cost = [1, 2, 3]) == 5\n assert candidate(n = 2,k = 3,budget = 10,composition = [[2, 1], [1, 2], [1, 1]],stock = [1, 1],cost = [5, 5]) == 2\n assert candidate(n = 6,k = 4,budget = 200,composition = [[1, 1, 1, 1, 1, 1], [2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2], [1, 3, 5, 7, 9, 11]],stock = [5, 10, 15, 20, 25, 30],cost = [1, 2, 3, 4, 5, 6]) == 31\n assert candidate(n = 2,k = 4,budget = 200,composition = [[1, 1], [2, 2], [3, 3], [4, 4]],stock = [10, 10],cost = [1, 2]) == 76\n assert candidate(n = 5,k = 3,budget = 250,composition = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3]],stock = [0, 0, 0, 0, 0],cost = [1, 1, 1, 1, 1]) == 50\n assert candidate(n = 6,k = 4,budget = 300,composition = [[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4]],stock = [0, 0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5, 6]) == 14\n assert candidate(n = 4,k = 3,budget = 100,composition = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 2, 2, 2]],stock = [5, 5, 5, 5],cost = [1, 1, 1, 1]) == 15\n assert candidate(n = 2,k = 3,budget = 150,composition = [[1, 1], [2, 1], [1, 2]],stock = [50, 50],cost = [10, 20]) == 55\n assert candidate(n = 4,k = 3,budget = 500,composition = [[1, 1, 1, 1], [2, 2, 2, 2], [1, 2, 3, 4]],stock = [10, 10, 10, 10],cost = [10, 20, 30, 40]) == 15\n assert candidate(n = 6,k = 2,budget = 300,composition = [[1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10]],stock = [5, 5, 5, 5, 5, 5],cost = [1, 1, 1, 1, 1, 1]) == 55\n assert candidate(n = 3,k = 5,budget = 500,composition = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],stock = [0, 0, 0],cost = [1, 2, 3]) == 83\n assert candidate(n = 4,k = 4,budget = 350,composition = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],stock = [50, 50, 50, 50],cost = [1, 2, 3, 4]) == 85\n assert candidate(n = 3,k = 3,budget = 200,composition = [[1, 1, 1], [10, 1, 1], [1, 10, 1]],stock = [100, 100, 100],cost = [1, 10, 100]) == 101\n assert candidate(n = 3,k = 2,budget = 50,composition = [[1, 2, 3], [3, 2, 1]],stock = [10, 20, 30],cost = [1, 2, 3]) == 14\n assert candidate(n = 3,k = 3,budget = 1000,composition = [[10, 20, 30], [20, 30, 40], [30, 40, 50]],stock = [0, 0, 0],cost = [1, 2, 3]) == 7\n assert candidate(n = 4,k = 3,budget = 50,composition = [[2, 1, 3, 1], [1, 2, 1, 2], [3, 3, 3, 3]],stock = [10, 5, 0, 0],cost = [5, 3, 2, 4]) == 5\n assert candidate(n = 2,k = 3,budget = 250,composition = [[10, 1], [1, 10], [5, 5]],stock = [100, 100],cost = [1, 1]) == 45\n assert candidate(n = 5,k = 3,budget = 500,composition = [[2, 3, 1, 4, 5], [1, 1, 1, 1, 1], [5, 5, 5, 5, 5]],stock = [10, 20, 30, 40, 50],cost = [1, 2, 3, 4, 5]) == 70\n assert candidate(n = 3,k = 1,budget = 50,composition = [[10, 10, 10]],stock = [5, 5, 5],cost = [1, 1, 1]) == 2\n assert candidate(n = 4,k = 3,budget = 100,composition = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]],stock = [5, 5, 5, 5],cost = [2, 3, 4, 5]) == 4\n assert candidate(n = 5,k = 4,budget = 100,composition = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 1, 1, 1, 1], [10, 10, 10, 10, 10]],stock = [5, 5, 5, 5, 5],cost = [1, 2, 3, 4, 5]) == 11\n assert candidate(n = 6,k = 2,budget = 300,composition = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]],stock = [0, 0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5, 6]) == 5\n assert candidate(n = 3,k = 2,budget = 300,composition = [[1, 1, 1], [2, 2, 2]],stock = [0, 0, 0],cost = [100, 50, 25]) == 1\n assert candidate(n = 4,k = 4,budget = 800,composition = [[1, 1, 1, 1], [2, 1, 1, 1], [1, 2, 1, 1], [1, 1, 2, 1]],stock = [10, 20, 30, 40],cost = [5, 10, 15, 20]) == 46\n assert candidate(n = 7,k = 3,budget = 1500,composition = [[1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [3, 3, 3, 3, 3, 3, 3]],stock = [50, 60, 70, 80, 90, 100, 110],cost = [1, 2, 3, 4, 5, 6, 7]) == 47\n assert candidate(n = 5,k = 5,budget = 1000,composition = [[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]],stock = [500, 500, 500, 500, 500],cost = [1, 1, 1, 1, 1]) == 700\n assert candidate(n = 4,k = 4,budget = 200,composition = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],stock = [0, 0, 0, 0],cost = [5, 5, 5, 5]) == 10\n assert candidate(n = 3,k = 4,budget = 300,composition = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [1, 3, 2]],stock = [20, 30, 40],cost = [5, 10, 15]) == 20\n assert candidate(n = 2,k = 3,budget = 10000,composition = [[100, 1], [1, 100], [50, 50]],stock = [5000, 5000],cost = [1, 1]) == 200\n assert candidate(n = 6,k = 2,budget = 3000,composition = [[1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10]],stock = [5, 10, 15, 20, 25, 30],cost = [1, 2, 3, 4, 5, 6]) == 164\n assert candidate(n = 4,k = 3,budget = 100,composition = [[2, 3, 1, 4], [1, 1, 1, 1], [5, 5, 5, 5]],stock = [10, 10, 10, 10],cost = [1, 2, 3, 4]) == 20\n assert candidate(n = 4,k = 2,budget = 1000,composition = [[1, 1, 1, 1], [99, 99, 99, 99]],stock = [100, 100, 100, 100],cost = [1, 1, 1, 1]) == 350\n assert candidate(n = 10,k = 2,budget = 5000,composition = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]],stock = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 90\n assert candidate(n = 7,k = 3,budget = 2500,composition = [[1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [2, 3, 2, 3, 2, 3, 2]],stock = [50, 50, 50, 50, 50, 50, 50],cost = [1, 1, 1, 1, 1, 1, 1]) == 167\n assert candidate(n = 7,k = 3,budget = 1000,composition = [[1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13]],stock = [100, 200, 300, 400, 500, 600, 700],cost = [1, 2, 3, 4, 5, 6, 7]) == 107\n assert candidate(n = 5,k = 3,budget = 500,composition = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 2, 2, 2, 2]],stock = [10, 20, 30, 40, 50],cost = [5, 4, 3, 2, 1]) == 28\n assert candidate(n = 3,k = 5,budget = 200,composition = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],stock = [10, 10, 10],cost = [10, 20, 30]) == 13\n assert candidate(n = 5,k = 2,budget = 250,composition = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]],stock = [0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5]) == 7\n assert candidate(n = 2,k = 3,budget = 50,composition = [[1, 1], [2, 2], [3, 3]],stock = [20, 20],cost = [1, 2]) == 36\n assert candidate(n = 6,k = 5,budget = 1000,composition = [[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]],stock = [0, 0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5, 6]) == 47\n assert candidate(n = 2,k = 4,budget = 500,composition = [[1, 1], [1, 2], [2, 1], [2, 2]],stock = [100, 100],cost = [1, 1]) == 350\n assert candidate(n = 3,k = 3,budget = 200,composition = [[1, 1, 1], [10, 10, 10], [5, 5, 5]],stock = [100, 100, 100],cost = [1, 2, 3]) == 133\n assert candidate(n = 4,k = 5,budget = 500,composition = [[1, 2, 3, 4], [4, 3, 2, 1], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],stock = [50, 50, 50, 50],cost = [10, 20, 30, 40]) == 55\n assert candidate(n = 6,k = 6,budget = 300,composition = [[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]],stock = [0, 0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5, 6]) == 14\n assert candidate(n = 4,k = 2,budget = 200,composition = [[1, 2, 3, 4], [4, 3, 2, 1]],stock = [0, 0, 0, 0],cost = [10, 20, 30, 40]) == 1\n assert candidate(n = 5,k = 3,budget = 1000,composition = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 2, 1, 2]],stock = [10, 20, 30, 40, 50],cost = [1, 2, 3, 4, 5]) == 55\n assert candidate(n = 5,k = 5,budget = 2000,composition = [[1, 1, 1, 1, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [10, 10, 10, 10, 10], [2, 3, 4, 5, 6]],stock = [0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5]) == 133\n assert candidate(n = 3,k = 2,budget = 50,composition = [[1, 1, 1], [1, 2, 3]],stock = [10, 10, 10],cost = [1, 1, 1]) == 26\n assert candidate(n = 5,k = 2,budget = 800,composition = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10]],stock = [100, 100, 100, 100, 100],cost = [1, 2, 3, 4, 5]) == 6\n assert candidate(n = 3,k = 3,budget = 100,composition = [[1, 2, 3], [3, 2, 1], [2, 3, 1]],stock = [10, 10, 10],cost = [10, 10, 10]) == 6\n assert candidate(n = 3,k = 5,budget = 300,composition = [[1, 1, 1], [2, 1, 1], [1, 2, 1], [1, 1, 2], [3, 3, 3]],stock = [0, 0, 0],cost = [10, 20, 30]) == 5\n assert candidate(n = 3,k = 3,budget = 450,composition = [[3, 3, 3], [4, 4, 4], [5, 5, 5]],stock = [0, 0, 0],cost = [5, 10, 15]) == 5\n assert candidate(n = 6,k = 3,budget = 300,composition = [[1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3]],stock = [10, 10, 10, 10, 10, 10],cost = [1, 2, 3, 4, 5, 6]) == 24\n assert candidate(n = 5,k = 3,budget = 1000,composition = [[2, 3, 1, 1, 2], [1, 2, 3, 4, 5], [3, 2, 1, 2, 1]],stock = [10, 20, 30, 40, 50],cost = [1, 2, 3, 4, 5]) == 67\n assert candidate(n = 2,k = 5,budget = 50,composition = [[1, 1], [2, 1], [1, 2], [2, 2], [3, 3]],stock = [5, 5],cost = [10, 20]) == 6\n assert candidate(n = 3,k = 3,budget = 1000,composition = [[2, 2, 2], [3, 3, 3], [1, 1, 1]],stock = [100, 200, 300],cost = [1, 1, 1]) == 533\n assert candidate(n = 5,k = 4,budget = 500,composition = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [10, 10, 10, 10, 10], [1, 1, 1, 1, 1]],stock = [50, 50, 50, 50, 50],cost = [5, 5, 5, 5, 5]) == 70\n assert candidate(n = 3,k = 3,budget = 50,composition = [[1, 1, 1], [2, 2, 2], [3, 3, 3]],stock = [15, 15, 15],cost = [1, 1, 1]) == 31\n assert candidate(n = 2,k = 5,budget = 300,composition = [[1, 1], [2, 1], [1, 2], [3, 1], [1, 3]],stock = [100, 100],cost = [50, 100]) == 102\n assert candidate(n = 6,k = 6,budget = 600,composition = [[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]],stock = [0, 0, 0, 0, 0, 0],cost = [1, 2, 3, 4, 5, 6]) == 28\n assert candidate(n = 3,k = 5,budget = 200,composition = [[1, 2, 3], [3, 2, 1], [2, 1, 3], [1, 3, 2], [3, 1, 2]],stock = [10, 20, 30],cost = [1, 2, 3]) == 34\n assert candidate(n = 3,k = 2,budget = 500,composition = [[10, 20, 30], [30, 20, 10]],stock = [50, 50, 50],cost = [5, 10, 15]) == 3\n assert candidate(n = 7,k = 3,budget = 1000,composition = [[1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3]],stock = [100, 100, 100, 100, 100, 100, 100],cost = [1, 2, 3, 4, 5, 6, 7]) == 135\n assert candidate(n = 4,k = 4,budget = 1000,composition = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70]],stock = [0, 0, 0, 0],cost = [5, 4, 3, 2]) == 3\n assert candidate(n = 5,k = 1,budget = 200,composition = [[10, 20, 30, 40, 50]],stock = [5, 10, 15, 20, 25],cost = [1, 2, 3, 4, 5]) == 0\n assert candidate(n = 5,k = 2,budget = 50,composition = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2]],stock = [5, 5, 5, 5, 5],cost = [1, 1, 1, 1, 1]) == 15\n assert candidate(n = 5,k = 2,budget = 1000,composition = [[10, 10, 10, 10, 10], [1, 1, 1, 1, 1]],stock = [100, 100, 100, 100, 100],cost = [1, 2, 3, 4, 5]) == 166\n assert candidate(n = 4,k = 3,budget = 500,composition = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 3, 4, 1]],stock = [100, 100, 100, 100],cost = [1, 2, 3, 4]) == 68\n assert candidate(n = 5,k = 4,budget = 100,composition = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 1, 5, 4], [3, 3, 3, 3, 3]],stock = [10, 10, 10, 10, 10],cost = [1, 2, 3, 4, 5]) == 6\n assert candidate(n = 4,k = 4,budget = 500,composition = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],stock = [100, 100, 100, 100],cost = [1, 2, 3, 4]) == 150\n assert candidate(n = 8,k = 2,budget = 3000,composition = [[1, 1, 1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10, 10, 10]],stock = [100, 100, 100, 100, 100, 100, 100, 100],cost = [1, 2, 3, 4, 5, 6, 7, 8]) == 183\n assert candidate(n = 10,k = 10,budget = 100000,composition = [[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], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [6, 6, 6, 6, 6, 6, 6, 6, 6, 6], [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], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]],stock = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2818\n assert candidate(n = 2,k = 5,budget = 50,composition = [[1, 1], [2, 1], [1, 2], [3, 1], [1, 3]],stock = [0, 0],cost = [5, 10]) == 3\n assert candidate(n = 3,k = 3,budget = 150,composition = [[1, 2, 3], [3, 2, 1], [2, 3, 1]],stock = [10, 20, 30],cost = [10, 20, 30]) == 11\n assert candidate(n = 5,k = 5,budget = 200,composition = [[1, 1, 1, 1, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1]],stock = [10, 10, 10, 10, 10],cost = [1, 2, 3, 4, 5]) == 23\n assert candidate(n = 3,k = 5,budget = 200,composition = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],stock = [50, 50, 50],cost = [10, 20, 30]) == 53\n assert candidate(n = 3,k = 5,budget = 500,composition = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],stock = [10, 10, 10],cost = [1, 1, 1]) == 176\n assert candidate(n = 4,k = 5,budget = 1200,composition = [[1, 1, 1, 1], [2, 1, 1, 2], [1, 2, 2, 1], [2, 2, 1, 1], [1, 1, 2, 2]],stock = [50, 50, 50, 50],cost = [10, 20, 30, 40]) == 62\n assert candidate(n = 4,k = 4,budget = 1000,composition = [[10, 20, 30, 40], [5, 15, 25, 35], [1, 1, 1, 1], [100, 50, 25, 10]],stock = [0, 0, 0, 0],cost = [1, 2, 3, 4]) == 100\n", "comparison": "exact"}, "public_tests": ["3\n2\n15\n[[1,1,1],[1,1,10]]\n[0,0,0]\n[1,2,3]", "3\n2\n15\n[[1,1,1],[1,1,10]]\n[0,0,100]\n[1,2,3]", "2\n3\n10\n[[2,1],[1,2],[1,1]]\n[1,1]\n[5,5]"], "hints": ["Use binary search to find the answer."], "metadata": {"canonical_parameter_names": ["n", "k", "budget", "composition", "stock", "cost"], "leetcode_dataset_entry_point": "Solution().maxNumberOfAlloys", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:28+00:00", "tests_total": 91, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "ruby", "interface": {"raw_signature": "def max_number_of_alloys(n, k, budget, composition, stock, cost)", "container": null, "callable": "max_number_of_alloys", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}, {"name": "budget", "type": "Integer"}, {"name": "composition", "type": "Integer[][]"}, {"name": "stock", "type": "Integer[]"}, {"name": "cost", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2862, "task_id": "maximum-element-sum-of-a-complete-subset-of-indices", "difficulty": "Hard", "problem_description": "You are given a 1-indexed array nums. Your task is to select a complete subset from nums where every pair of selected indices multiplied is a perfect square,. i. e. if you select a_i and a_j, i * j must be a perfect square.\n\nReturn the sum of the complete subset with the maximum sum.\n\nExample 1:\n\nInput: nums = [8,7,3,5,7,2,4,9]\nOutput: 16\nExplanation:\nWe select elements at indices 2 and 8 and 2 * 8 is a perfect square.\n\nExample 2:\n\nInput: nums = [8,10,3,8,1,13,7,9,4]\nOutput: 20\nExplanation:\nWe select elements at indices 1, 4, and 9. 1 * 4, 1 * 9, 4 * 9 are perfect squares.\n\nConstraints:\n\n- 1 <= n == nums.length <= 10^4\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [8, 10, 3, 8, 1, 13, 7, 9, 4]) == 20\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 30\n assert candidate(nums = [8, 7, 3, 5, 7, 2, 4, 9]) == 16\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 15\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 14\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 3000\n assert candidate(nums = [9, 64, 36, 49, 1, 64, 25, 81, 16, 4, 2, 9, 3, 1, 81, 9, 49, 1, 4, 36, 16, 4, 1, 9, 64, 25, 1, 1, 81, 9, 49, 1, 4, 36, 16, 4, 1, 9, 64, 25, 1, 1, 81, 9]) == 151\n assert candidate(nums = [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 469\n assert candidate(nums = [9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500]) == 3562\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, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199]) == 760\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]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\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]) == 55\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 26, 27, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 46, 47, 49]) == 85\n assert candidate(nums = [4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025]) == 4963\n assert candidate(nums = [16, 8, 4, 2, 1, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216]) == 16810258\n assert candidate(nums = [123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456, 123456]) == 864192\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 2999999989\n assert candidate(nums = [36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625]) == 754\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 56\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500]) == 5500\n assert candidate(nums = [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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293]) == 560\n assert candidate(nums = [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]) == 205\n assert candidate(nums = [10, 15, 21, 30, 35, 42, 56, 63, 70, 84, 91, 105, 112, 126, 133, 140, 154, 165, 182, 196, 210, 224, 231, 252, 266, 280, 308, 315, 322, 336, 364, 385, 392, 420, 441, 462, 490, 504, 532, 539, 550, 588, 616, 630, 646, 665, 672, 728, 735, 756, 770, 812, 840, 858, 882, 924, 931, 980, 990]) == 1713\n assert candidate(nums = [9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484]) == 533\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 30000\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130]) == 550\n assert candidate(nums = [16, 8, 4, 2, 1, 16, 8, 4, 2, 1, 16, 8, 4, 2, 1, 16, 8, 4, 2, 1, 16, 8, 4, 2, 1]) == 37\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]) == 55\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]) == 9\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]) == 6\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 425\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]) == 7\n assert candidate(nums = [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]) == 182\n assert candidate(nums = [9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 516\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 30\n assert candidate(nums = [31, 28, 30, 29, 33, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 139\n assert candidate(nums = [9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3]) == 24\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211]) == 360\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600]) == 2275\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 30\n assert candidate(nums = [8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9, 8, 7, 3, 5, 7, 2, 4, 9]) == 60\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 300\n assert candidate(nums = [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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 12\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 2999999989\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, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200]) == 455\n assert candidate(nums = [49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676]) == 858\n assert candidate(nums = [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, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200]) == 770\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991, 99999990, 99999989, 99999988, 99999987, 99999986, 99999985, 99999984, 99999983, 99999982, 99999981]) == 399999974\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 150\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]) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600]) == 3000\n assert candidate(nums = [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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229]) == 560\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]) == 91\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 30\n assert candidate(nums = [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]) == 182\n assert candidate(nums = [9, 4, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441]) == 477\n assert candidate(nums = [25, 16, 9, 4, 1, 64, 49, 36, 25, 16, 9, 4, 1, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1, 361, 324, 289, 256, 225, 196, 169, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1, 841, 810, 784, 756, 729, 676, 625, 576, 529, 484, 441, 400, 361, 324, 289, 256, 225, 196, 169, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1]) == 1109\n", "comparison": "exact"}, "public_tests": ["[8,7,3,5,7,2,4,9]", "[8,10,3,8,1,13,7,9,4]"], "hints": ["Define P(x) as the product of primes p with odd exponents in x's factorization. Examples: For x = 18, factorization 2^1 × 3^2, P(18) = 2; for x = 45, factorization 3^2 × 5^1, P(45) = 5; for x = 50, factorization 2^1 × 5^2, P(50) = 2; for x = 210, factorization 2^1 × 3^1 × 5^1 × 7^1, P(210) = 210.", "If P(i) = P(j), nums[i] and nums[j] can be grouped together.", "Pick the group with the largest sum."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:31+00:00", "tests_total": 62, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_sum(nums)", "container": null, "callable": "maximum_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2864, "task_id": "maximum-odd-binary-number", "difficulty": "Easy", "problem_description": "You are given a binary string s that contains at least one '1'.\n\nYou have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.\n\nReturn a string representing the maximum odd binary number that can be created from the given combination.\n\nNote that the resulting string can have leading zeros.\n\nExample 1:\n\nInput: s = \"010\"\nOutput: \"001\"\nExplanation: Because there is just one '1', it must be in the last position. So the answer is \"001\".\n\nExample 2:\n\nInput: s = \"0101\"\nOutput: \"1001\"\nExplanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is \"100\". So the answer is \"1001\".\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists only of '0' and '1'.\n- s contains at least one '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == \"1111\"\n assert candidate(s = \"101010101\") == \"111100001\"\n assert candidate(s = \"110011\") == \"111001\"\n assert candidate(s = \"111\") == \"111\"\n assert candidate(s = \"1110\") == \"1101\"\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000000000000001\") == \"0000000000000000000000000000000000000000000000000000000000000001\"\n assert candidate(s = \"111000\") == \"110001\"\n assert candidate(s = \"1001001\") == \"1100001\"\n assert candidate(s = \"001010\") == \"100001\"\n assert candidate(s = \"1100\") == \"1001\"\n assert candidate(s = \"100001\") == \"100001\"\n assert candidate(s = \"010\") == \"001\"\n assert candidate(s = \"001001001\") == \"110000001\"\n assert candidate(s = \"0101\") == \"1001\"\n assert candidate(s = \"000001\") == \"000001\"\n assert candidate(s = \"10001\") == \"10001\"\n assert candidate(s = \"1100001\") == \"1100001\"\n assert candidate(s = \"11111\") == \"11111\"\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101\") == \"1111111111111111111111111111111000000000000000000000000000000001\"\n assert candidate(s = \"101010\") == \"110001\"\n assert candidate(s = \"00001\") == \"00001\"\n assert candidate(s = \"1000\") == \"0001\"\n assert candidate(s = \"11100\") == \"11001\"\n assert candidate(s = \"0101010101\") == \"1111000001\"\n assert candidate(s = \"0001\") == \"0001\"\n assert candidate(s = \"11001001\") == \"11100001\"\n assert candidate(s = \"101010101010101010\") == \"111111110000000001\"\n assert candidate(s = \"01010101010101010101010101010101\") == \"11111111111111100000000000000001\"\n assert candidate(s = \"101010101010101\") == \"111111100000001\"\n assert candidate(s = \"00100100101010\") == \"11110000000001\"\n assert candidate(s = \"00000000000000000000001\") == \"00000000000000000000001\"\n assert candidate(s = \"1111000011110000\") == \"1111111000000001\"\n assert candidate(s = \"10000000000000000000000000000000000000000000000000000000000000001\") == \"10000000000000000000000000000000000000000000000000000000000000001\"\n assert candidate(s = \"1000001\") == \"1000001\"\n assert candidate(s = \"1001001001001001001001\") == \"1111111000000000000001\"\n assert candidate(s = \"00000000001\") == \"00000000001\"\n assert candidate(s = \"010011001100\") == \"111100000001\"\n assert candidate(s = \"100011100111\") == \"111111000001\"\n assert candidate(s = \"0000100010001\") == \"1100000000001\"\n assert candidate(s = \"1111000010\") == \"1111000001\"\n assert candidate(s = \"00000000000000000000000000000001\") == \"00000000000000000000000000000001\"\n assert candidate(s = \"00010010101\") == \"11100000001\"\n assert candidate(s = \"11110000\") == \"11100001\"\n assert candidate(s = \"1111111111110\") == \"1111111111101\"\n assert candidate(s = \"11010101010101010101\") == \"11111111110000000001\"\n assert candidate(s = \"00000001\") == \"00000001\"\n assert candidate(s = \"1111111111\") == \"1111111111\"\n assert candidate(s = \"010101010101\") == \"111110000001\"\n assert candidate(s = \"1010101010101010101\") == \"1111111110000000001\"\n assert candidate(s = \"000000000001\") == \"000000000001\"\n assert candidate(s = \"11111111111111110000\") == \"11111111111111100001\"\n assert candidate(s = \"11111111111111111111\") == \"11111111111111111111\"\n assert candidate(s = \"0010101010\") == \"1110000001\"\n assert candidate(s = \"11111111111111111111111111111111\") == \"11111111111111111111111111111111\"\n assert candidate(s = \"00000000000000000001\") == \"00000000000000000001\"\n assert candidate(s = \"1111111111111111\") == \"1111111111111111\"\n assert candidate(s = \"0000111111\") == \"1111100001\"\n assert candidate(s = \"111000011\") == \"111100001\"\n assert candidate(s = \"01010101010101010101\") == \"11111111100000000001\"\n assert candidate(s = \"1001101\") == \"1110001\"\n assert candidate(s = \"1100000000000000000000000000000001\") == \"1100000000000000000000000000000001\"\n assert candidate(s = \"111110000000\") == \"111100000001\"\n assert candidate(s = \"11111000000\") == \"11110000001\"\n assert candidate(s = \"10000000000\") == \"00000000001\"\n assert candidate(s = \"110100110\") == \"111100001\"\n assert candidate(s = \"1010101010\") == \"1111000001\"\n assert candidate(s = \"010101010101010101\") == \"111111110000000001\"\n assert candidate(s = \"1000000000000000000001\") == \"1000000000000000000001\"\n assert candidate(s = \"11111110000000000000000000000000\") == \"11111100000000000000000000000001\"\n assert candidate(s = \"1101001\") == \"1110001\"\n assert candidate(s = \"11001100\") == \"11100001\"\n assert candidate(s = \"1010101010101010\") == \"1111111000000001\"\n assert candidate(s = \"110000000000001\") == \"110000000000001\"\n assert candidate(s = \"1111111111111111111111\") == \"1111111111111111111111\"\n assert candidate(s = \"111000011000\") == \"111100000001\"\n assert candidate(s = \"0101010101010101010101\") == \"1111111111000000000001\"\n assert candidate(s = \"100010001\") == \"110000001\"\n assert candidate(s = \"10011001100110011001100110011001\") == \"11111111111111100000000000000001\"\n", "comparison": "exact"}, "public_tests": ["\"010\"", "\"0101\""], "hints": ["The binary representation of an odd number contains '1' in the least significant place."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maximumOddBinaryNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:35+00:00", "tests_total": 78, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_odd_binary_number(s)", "container": null, "callable": "maximum_odd_binary_number", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2865, "task_id": "beautiful-towers-i", "difficulty": "Medium", "problem_description": "You are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a mountain-shaped tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing.\n\nReturn the maximum possible sum of heights of a mountain-shaped tower arrangement.\n\nExample 1:\n\nInput: heights = [5,3,4,1,1]\nOutput: 13\nExplanation:\nWe remove some bricks to make heights = [5,3,3,1,1], the peak is at index 0.\n\nExample 2:\n\nInput: heights = [6,5,3,9,2,7]\nOutput: 22\nExplanation:\nWe remove some bricks to make heights = [3,3,3,9,2,2], the peak is at index 3.\n\nExample 3:\n\nInput: heights = [3,2,5,5,2,3]\nOutput: 18\nExplanation:\nWe remove some bricks to make heights = [2,2,5,5,2,2], the peak is at index 2 or 3.\n\nConstraints:\n\n- 1 <= n == heights.length <= 10^3\n- 1 <= heights[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(heights = [1, 3, 5, 7, 9, 7, 5, 3, 1]) == 41\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(heights = [7, 4, 7, 4, 7]) == 23\n assert candidate(heights = [3, 2, 5, 5, 2, 3]) == 18\n assert candidate(heights = [1, 2, 3, 4, 5]) == 15\n assert candidate(heights = [1, 2, 3, 2, 1]) == 9\n assert candidate(heights = [7, 4, 4, 4, 10, 6]) == 32\n assert candidate(heights = [1, 2, 1, 2, 1]) == 6\n assert candidate(heights = [9, 4, 8, 7, 5, 3, 2, 6, 1]) == 36\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(heights = [10, 9, 2, 5, 3, 7, 20]) == 39\n assert candidate(heights = [8, 6, 5, 7, 9]) == 31\n assert candidate(heights = [1, 3, 3, 3, 3, 3, 3, 2, 1]) == 22\n assert candidate(heights = [1, 3, 2, 3, 1]) == 9\n assert candidate(heights = [10, 20, 10, 20, 10]) == 60\n assert candidate(heights = [1, 1, 1, 1, 1]) == 5\n assert candidate(heights = [5, 3, 4, 1, 1]) == 13\n assert candidate(heights = [10, 20, 10]) == 40\n assert candidate(heights = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 13\n assert candidate(heights = [6, 5, 3, 9, 2, 7]) == 22\n assert candidate(heights = [5, 4, 3, 2, 1]) == 15\n assert candidate(heights = [5, 5, 5, 5, 5, 5]) == 30\n assert candidate(heights = [10, 9, 8, 7, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 109\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 36\n assert candidate(heights = [5, 1, 5, 10, 15, 10, 5, 1, 5]) == 49\n assert candidate(heights = [1, 2, 3, 4, 5, 10, 10, 10, 5, 4, 3, 2, 1]) == 60\n assert candidate(heights = [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]) == 108\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 104\n assert candidate(heights = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 83\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100\n assert candidate(heights = [1, 2, 3, 4, 3, 2, 3, 4, 3, 2, 1]) == 24\n assert candidate(heights = [1, 5, 1, 7, 1, 9, 1, 11, 1, 13, 1, 15, 1]) == 27\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10]) == 70\n assert candidate(heights = [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]) == 215\n assert candidate(heights = [1, 1, 1, 1, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1]) == 59\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100\n assert candidate(heights = [3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3]) == 36\n assert candidate(heights = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 56\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 761\n assert candidate(heights = [10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 40, 30, 20, 10]) == 330\n assert candidate(heights = [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]) == 58\n assert candidate(heights = [1, 1, 1, 10, 1, 1, 1, 10, 1, 1, 1]) == 20\n assert candidate(heights = [1, 2, 3, 4, 5, 10, 1, 2, 3, 4, 5]) == 30\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 46\n assert candidate(heights = [3, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 93\n assert candidate(heights = [1, 1, 1, 1, 1, 10, 1, 1, 1, 1, 1]) == 20\n assert candidate(heights = [1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 1000000018\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10]) == 70\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 65\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 605\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 40\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 550\n assert candidate(heights = [9, 9, 9, 10, 9, 9, 9, 10, 9, 9, 9, 10, 9, 9, 9]) == 136\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9000000020\n assert candidate(heights = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 29\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 46\n assert candidate(heights = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 75\n assert candidate(heights = [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, 3, 4, 5]) == 112\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 120\n assert candidate(heights = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 17\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 112\n assert candidate(heights = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 374\n assert candidate(heights = [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]) == 26\n assert candidate(heights = [10, 20, 30, 25, 35, 40, 30, 20, 10]) == 215\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 400\n assert candidate(heights = [7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 7, 7]) == 37\n assert candidate(heights = [5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5]) == 150\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(heights = [1, 2, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5]) == 207\n assert candidate(heights = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 100\n assert candidate(heights = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 42\n assert candidate(heights = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 1, 2, 3, 4, 3, 2, 1]) == 26\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 64\n assert candidate(heights = [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]) == 820\n assert candidate(heights = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 129\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10]) == 66\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 650\n assert candidate(heights = [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]) == 110\n assert candidate(heights = [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]) == 43\n assert candidate(heights = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 201\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 1000\n assert candidate(heights = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(heights = [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]) == 109\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 125\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 64\n assert candidate(heights = [1, 3, 5, 7, 9, 7, 5, 3, 1, 3, 5, 7, 9, 7, 5, 3, 1]) == 49\n assert candidate(heights = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 24\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 190\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 33\n assert candidate(heights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 210\n assert candidate(heights = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 10999999945\n assert candidate(heights = [10, 20, 30, 40, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1, 5, 10, 15, 20, 25, 30, 35, 40, 45]) == 385\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(heights = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 4999999990\n assert candidate(heights = [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]) == 45\n assert candidate(heights = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 100\n assert candidate(heights = [10, 20, 15, 10, 15, 20, 10, 5, 10, 15, 20, 25]) == 110\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10]) == 75\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 210\n assert candidate(heights = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 109\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 30\n assert candidate(heights = [1, 2, 3, 4, 5, 100, 5, 4, 3, 2, 1, 2, 3, 4, 5, 100, 5, 4, 3, 2, 1]) == 140\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 560\n assert candidate(heights = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 33\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10]) == 460\n assert candidate(heights = [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]) == 87\n assert candidate(heights = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1010\n assert candidate(heights = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 45\n assert candidate(heights = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 60\n assert candidate(heights = [100, 10, 1, 100, 10, 1, 100, 10, 1, 100, 10, 1, 100, 10, 1, 100]) == 124\n assert candidate(heights = [5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5]) == 45\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]) == 57\n assert candidate(heights = [1, 1, 1, 1, 10, 1, 1, 1, 1]) == 18\n assert candidate(heights = [2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 31\n assert candidate(heights = [1, 3, 2, 3, 4, 5, 3, 2, 1]) == 23\n assert candidate(heights = [6, 5, 4, 3, 2, 1]) == 21\n assert candidate(heights = [1, 5, 3, 7, 5, 3, 1]) == 23\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 550\n assert candidate(heights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 6000000000\n assert candidate(heights = [10, 10, 10, 10, 10]) == 50\n assert candidate(heights = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 20\n assert candidate(heights = [1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(heights = [1, 3, 2, 4, 3, 5, 4, 6, 5]) == 30\n assert candidate(heights = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 9999999955\n assert candidate(heights = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(heights = [9, 4, 8, 7, 5, 6, 3, 2, 1]) == 39\n assert candidate(heights = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 19\n assert candidate(heights = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 11\n assert candidate(heights = [10, 20, 30, 40, 50, 40, 30, 20, 10]) == 250\n assert candidate(heights = [9, 8, 7, 8, 9]) == 38\n assert candidate(heights = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 109\n assert candidate(heights = [1, 3, 2, 5, 4, 6, 5, 7, 6]) == 36\n assert candidate(heights = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 99\n assert candidate(heights = [5, 6, 7, 8, 9, 8, 7, 6, 5]) == 61\n assert candidate(heights = [9, 4, 2, 1, 3, 5, 7, 6, 8, 10]) == 42\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 19\n assert candidate(heights = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 30\n assert candidate(heights = [1, 2, 3, 2, 3, 4, 3, 4, 5]) == 25\n assert candidate(heights = [1, 3, 2, 1, 2, 1, 3, 1]) == 11\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(heights = [1, 2, 3, 4, 5, 1, 1, 1, 1, 1]) == 20\n assert candidate(heights = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 13\n assert candidate(heights = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 19\n assert candidate(heights = [1, 3, 2, 1, 2, 3, 1, 2, 3, 1]) == 13\n assert candidate(heights = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(heights = [1, 3, 2, 3, 1]) == 9\n assert candidate(heights = [1, 2, 1, 2, 1, 2]) == 7\n assert candidate(heights = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 13\n assert candidate(heights = [1, 2, 1]) == 4\n assert candidate(heights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(heights = [1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 23\n assert candidate(heights = [1000000000, 1, 1000000000, 1, 1000000000]) == 1000000004\n assert candidate(heights = [2, 1, 2]) == 4\n assert candidate(heights = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 36\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10]) == 62\n assert candidate(heights = [10, 20, 10, 30, 10, 40, 10]) == 100\n assert candidate(heights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(heights = [1, 2, 3, 4, 3, 2, 1]) == 16\n assert candidate(heights = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(heights = [1, 1, 1, 1, 1, 5, 4, 3, 2, 1]) == 20\n assert candidate(heights = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 25\n assert candidate(heights = [1, 3, 2, 1, 2, 3, 2, 1]) == 12\n assert candidate(heights = [9, 4, 4, 7, 2]) == 23\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11]) == 52\n assert candidate(heights = [1, 3, 2, 1]) == 7\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(heights = [1, 3, 5, 4, 7, 5, 6, 4, 3, 8, 9, 1]) == 43\n assert candidate(heights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10000000000\n assert candidate(heights = [1, 5, 3, 5, 1]) == 13\n assert candidate(heights = [1000000000, 1000000000, 1000000000, 1000000000]) == 4000000000\n assert candidate(heights = [1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(heights = [9, 7, 5, 3, 1, 3, 5, 7, 9]) == 29\n assert candidate(heights = [5, 4, 4, 4, 5]) == 21\n assert candidate(heights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 110\n", "comparison": "exact"}, "public_tests": ["[5,3,4,1,1]", "[6,5,3,9,2,7]", "[3,2,5,5,2,3]"], "hints": ["Try all the possible indices i as the peak.", "If i is the peak, i-1^th element, and heights[j] = min(heights[j], heights[j + 1]) for 0 <= j < i", "If i is the peak, start from i+1^th element, heights[j] = min(heights[j], heights[j - 1]) for i < j < heights.size()"], "metadata": {"canonical_parameter_names": ["heights"], "leetcode_dataset_entry_point": "Solution().maximumSumOfHeights", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:38+00:00", "tests_total": 184, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "stack", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_sum_of_heights(heights)", "container": null, "callable": "maximum_sum_of_heights", "parameters": [{"name": "heights", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2866, "task_id": "beautiful-towers-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array maxHeights of n integers.\n\nYou are tasked with building n towers in the coordinate line. The i^th tower is built at coordinate i and has a height of heights[i].\n\nA configuration of towers is beautiful if the following conditions hold:\n\n1. 1 <= heights[i] <= maxHeights[i]\n2. heights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\n- For all 0 < j <= i, heights[j - 1] <= heights[j]\n- For all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.\n\nExample 1:\n\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.\n\nExample 2:\n\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.\n\nExample 3:\n\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2.\nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.\n\nConstraints:\n\n- 1 <= n == maxHeights.length <= 10^5\n- 1 <= maxHeights[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(maxHeights = [1, 2, 3, 4, 5]) == 15\n assert candidate(maxHeights = [5, 4, 3, 2, 1]) == 15\n assert candidate(maxHeights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(maxHeights = [1, 3, 2, 4, 3, 5, 4, 6, 5]) == 30\n assert candidate(maxHeights = [10, 10, 10, 10, 10]) == 50\n assert candidate(maxHeights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(maxHeights = [1, 3, 2, 3, 1]) == 9\n assert candidate(maxHeights = [1, 3, 2, 1, 2, 3, 1, 2, 1]) == 12\n assert candidate(maxHeights = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(maxHeights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(maxHeights = [3, 2, 5, 5, 2, 3]) == 18\n assert candidate(maxHeights = [7, 8, 9, 10, 9, 8, 7]) == 58\n assert candidate(maxHeights = [5, 3, 4, 1, 1]) == 13\n assert candidate(maxHeights = [4, 4, 4, 4, 4, 4, 4]) == 28\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 25\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 25\n assert candidate(maxHeights = [1, 1, 1, 1, 1]) == 5\n assert candidate(maxHeights = [6, 5, 3, 9, 2, 7]) == 22\n assert candidate(maxHeights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10]) == 66\n assert candidate(maxHeights = [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, 3, 3, 3, 3, 3, 3, 3]) == 114\n assert candidate(maxHeights = [5, 5, 5, 5, 9, 5, 5, 5, 5]) == 49\n assert candidate(maxHeights = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 70\n assert candidate(maxHeights = [1, 10, 2, 8, 3, 7, 4, 6, 5]) == 30\n assert candidate(maxHeights = [3, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 6, 6]) == 54\n assert candidate(maxHeights = [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]) == 120\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 20\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 34\n assert candidate(maxHeights = [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]) == 40\n assert candidate(maxHeights = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 36\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3]) == 44\n assert candidate(maxHeights = [5, 6, 7, 8, 9, 10, 10, 10, 10, 9, 8, 7, 6, 5, 4]) == 114\n assert candidate(maxHeights = [1, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 26\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3]) == 46\n assert candidate(maxHeights = [2, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10]) == 111\n assert candidate(maxHeights = [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]) == 118\n assert candidate(maxHeights = [1, 3, 2, 5, 4, 6, 5, 7, 6, 8]) == 43\n assert candidate(maxHeights = [3, 3, 3, 3, 3, 5, 5, 5, 5, 5]) == 40\n assert candidate(maxHeights = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 500\n assert candidate(maxHeights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 44\n assert candidate(maxHeights = [7, 7, 7, 7, 1, 7, 7, 7, 7, 7]) == 40\n assert candidate(maxHeights = [5, 4, 4, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7]) == 85\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 120\n assert candidate(maxHeights = [5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 1, 1, 1, 1]) == 39\n assert candidate(maxHeights = [1, 5, 3, 7, 5, 9, 7, 11, 9, 13, 11, 9, 7, 5, 3, 1]) == 98\n assert candidate(maxHeights = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 60\n assert candidate(maxHeights = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5, 10, 15, 20, 25, 30, 25, 20, 15, 10]) == 300\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(maxHeights = [3, 3, 3, 3, 5, 5, 5, 5, 3, 3, 3, 3, 5, 5, 5, 5, 3, 3, 3, 3]) == 68\n assert candidate(maxHeights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 25\n assert candidate(maxHeights = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 45\n assert candidate(maxHeights = [2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 2, 2]) == 73\n assert candidate(maxHeights = [1, 1, 1, 1, 10, 1, 1, 1, 1, 1]) == 19\n assert candidate(maxHeights = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 120\n assert candidate(maxHeights = [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]) == 26\n assert candidate(maxHeights = [10, 20, 30, 40, 50, 40, 30, 20, 10]) == 250\n assert candidate(maxHeights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 7, 4, 8, 3, 9, 2, 10, 1]) == 65\n assert candidate(maxHeights = [1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1, 3, 5, 7, 9, 11, 9, 7, 5]) == 69\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 5, 4, 5, 4, 3, 2, 1]) == 41\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 110\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3]) == 35\n assert candidate(maxHeights = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15]) == 42\n assert candidate(maxHeights = [5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 90\n assert candidate(maxHeights = [5, 5, 5, 5, 6, 5, 5, 5, 5]) == 46\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 29\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100\n assert candidate(maxHeights = [5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 51\n assert candidate(maxHeights = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 19\n assert candidate(maxHeights = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10]) == 110\n assert candidate(maxHeights = [1, 1, 1, 10, 1, 1, 10, 1, 1, 10, 1, 1, 1]) == 22\n assert candidate(maxHeights = [1, 1, 1, 1, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1, 1]) == 29\n assert candidate(maxHeights = [10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10]) == 360\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1]) == 104\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1]) == 70\n assert candidate(maxHeights = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7]) == 68\n assert candidate(maxHeights = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 19\n assert candidate(maxHeights = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 210\n assert candidate(maxHeights = [5, 5, 5, 5, 1, 5, 5, 5, 5]) == 25\n assert candidate(maxHeights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 1000\n assert candidate(maxHeights = [5, 5, 5, 5, 5, 10, 5, 5, 5, 5, 5, 10, 5, 5, 5, 5, 5]) == 90\n assert candidate(maxHeights = [3, 1, 3, 1, 3, 1, 3]) == 9\n assert candidate(maxHeights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 85\n assert candidate(maxHeights = [3, 3, 3, 3, 10, 3, 3, 3, 3, 10, 3, 3, 3, 3]) == 49\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1]) == 65\n assert candidate(maxHeights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 650\n assert candidate(maxHeights = [1, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 20\n assert candidate(maxHeights = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 20\n assert candidate(maxHeights = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 150\n assert candidate(maxHeights = [1, 3, 2, 3, 4, 3, 2, 3, 1]) == 20\n assert candidate(maxHeights = [1, 3, 5, 7, 9, 11, 13, 15, 13, 11, 9, 7, 5, 3, 1]) == 113\n assert candidate(maxHeights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 65\n assert candidate(maxHeights = [2, 2, 3, 4, 5, 6, 5, 5, 5, 5, 6, 7, 8, 9, 10]) == 81\n assert candidate(maxHeights = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 101\n assert candidate(maxHeights = [9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7]) == 111\n assert candidate(maxHeights = [1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 103\n assert candidate(maxHeights = [9, 9, 9, 9, 9, 1, 1, 1, 1, 1]) == 50\n assert candidate(maxHeights = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(maxHeights = [100, 90, 80, 70, 60, 50, 60, 70, 80, 90, 100]) == 700\n assert candidate(maxHeights = [9, 7, 5, 3, 1, 1, 3, 5, 7, 9]) == 30\n assert candidate(maxHeights = [1, 3, 5, 7, 9, 7, 5, 3, 1]) == 41\n assert candidate(maxHeights = [1, 3, 5, 7, 9, 7, 5, 3, 1, 1, 3, 5, 7, 9, 7, 5, 3, 1]) == 50\n assert candidate(maxHeights = [1, 1, 2, 3, 4, 5, 4, 3, 2, 1, 1]) == 27\n assert candidate(maxHeights = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 53\n assert candidate(maxHeights = [100, 50, 50, 100, 50, 50, 100, 50, 50, 100]) == 550\n assert candidate(maxHeights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 64\n assert candidate(maxHeights = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 19\n assert candidate(maxHeights = [1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 1000000008\n assert candidate(maxHeights = [1, 2, 2, 3, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 3, 2, 2, 1]) == 28\n", "comparison": "exact"}, "public_tests": ["[5,3,4,1,1]", "[6,5,3,9,2,7]", "[3,2,5,5,2,3]"], "hints": ["Try all the possible indices i as the peak.", "Let left[i] be the maximum sum of heights for the prefix 0, …, i when index i is the peak.", "Let right[i] be the maximum sum of heights for suffix i, …, (n - 1) when i is the peak", "Compute values of left[i] from left to right using DP. For each i from 0 to n - 1, left[i] = maxHeights * (i - j) + answer[j], where j is the rightmost index to the left of i such that maxHeights[j] < maxHeights[i] .", "For each i from n - 1 to 0, right[i] = maxHeights * (j - i) + answer[j], where j is the leftmost index to the right of i such that maxHeights[j] < maxHeights[i] ."], "metadata": {"canonical_parameter_names": ["maxHeights"], "leetcode_dataset_entry_point": "Solution().maximumSumOfHeights", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:40+00:00", "tests_total": 111, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "stack", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_sum_of_heights(max_heights)", "container": null, "callable": "maximum_sum_of_heights", "parameters": [{"name": "max_heights", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2867, "task_id": "count-valid-paths-in-a-tree", "difficulty": "Hard", "problem_description": "There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i] indicates that there is an edge between nodes u_i and v_i in the tree.\n\nReturn the number of valid paths in the tree.\n\nA path (a, b) is valid if there exists exactly one prime number among the node labels in the path from a to b.\n\nNote that:\n\n- The path (a, b) is a sequence of distinct nodes starting with node a and ending with node b such that every two adjacent nodes in the sequence share an edge in the tree.\n- Path (a, b) and path (b, a) are considered the same and counted only once.\n\nExample 1:\n\nInput: n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]\nOutput: 4\nExplanation: The pairs with exactly one prime number on the path between them are:\n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\nIt can be shown that there are only 4 valid paths.\n\nExample 2:\n\nInput: n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]\nOutput: 6\nExplanation: The pairs with exactly one prime number on the path between them are:\n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (1, 6) since the path from 1 to 6 contains prime number 3.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\n- (3, 6) since the path from 3 to 6 contains prime number 3.\nIt can be shown that there are only 6 valid paths.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- edges.length == n - 1\n- edges[i].length == 2\n- 1 <= u_i, v_i <= n\n- The input is generated such that edges represent a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8]]) == 8\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [3, 6]]) == 6\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == 18\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [2, 7]]) == 7\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8], [6, 9], [9, 10]]) == 12\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7]]) == 9\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]]) == 6\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10]]) == 11\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [3, 6], [4, 7]]) == 9\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [5, 10]]) == 11\n assert candidate(n = 5,edges = [[1, 2], [1, 3], [2, 4], [2, 5]]) == 4\n assert candidate(n = 3,edges = [[1, 2], [2, 3]]) == 1\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [6, 11], [7, 12]]) == 13\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [10, 20]]) == 47\n assert candidate(n = 25,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25]]) == 63\n assert candidate(n = 50,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40], [20, 41], [21, 42], [21, 43], [22, 44], [22, 45], [23, 46], [23, 47], [24, 48], [24, 49], [25, 50]]) == 149\n assert candidate(n = 75,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40], [20, 41], [21, 42], [21, 43], [22, 44], [22, 45], [23, 46], [23, 47], [24, 48], [24, 49], [25, 50], [26, 51], [26, 52], [27, 53], [27, 54], [28, 55], [28, 56], [29, 57], [29, 58], [30, 59], [30, 60], [31, 61], [31, 62], [32, 63], [32, 64], [33, 65], [33, 66], [34, 67], [34, 68], [35, 69], [35, 70], [36, 71], [36, 72], [37, 73], [37, 74], [38, 75]]) == 348\n assert candidate(n = 50,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40], [20, 41], [21, 42], [21, 43], [22, 44], [22, 45], [23, 46], [23, 47], [24, 48], [24, 49], [25, 50]]) == 202\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15]]) == 34\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15]]) == 27\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]]) == 18\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12]]) == 13\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20]]) == 33\n assert candidate(n = 40,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40]]) == 120\n assert candidate(n = 25,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25]]) == 41\n assert candidate(n = 100,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40], [20, 41], [21, 42], [21, 43], [22, 44], [22, 45], [23, 46], [23, 47], [24, 48], [24, 49], [25, 50], [25, 51], [26, 52], [26, 53], [27, 54], [27, 55], [28, 56], [28, 57], [29, 58], [29, 59], [30, 60], [30, 61], [31, 62], [31, 63], [32, 64], [32, 65], [33, 66], [33, 67], [34, 68], [34, 69], [35, 70], [35, 71], [36, 72], [36, 73], [37, 74], [37, 75], [38, 76], [38, 77], [39, 78], [39, 79], [40, 80], [40, 81], [41, 82], [41, 83], [42, 84], [42, 85], [43, 86], [43, 87], [44, 88], [44, 89], [45, 90], [45, 91], [46, 92], [46, 93], [47, 94], [47, 95], [48, 96], [48, 97], [49, 98], [49, 99], [50, 100]]) == 499\n assert candidate(n = 150,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50], [50, 51], [51, 52], [52, 53], [53, 54], [54, 55], [55, 56], [56, 57], [57, 58], [58, 59], [59, 60], [60, 61], [61, 62], [62, 63], [63, 64], [64, 65], [65, 66], [66, 67], [67, 68], [68, 69], [69, 70], [70, 71], [71, 72], [72, 73], [73, 74], [74, 75], [75, 76], [76, 77], [77, 78], [78, 79], [79, 80], [80, 81], [81, 82], [82, 83], [83, 84], [84, 85], [85, 86], [86, 87], [87, 88], [88, 89], [89, 90], [90, 91], [91, 92], [92, 93], [93, 94], [94, 95], [95, 96], [96, 97], [97, 98], [98, 99], [99, 100], [100, 101], [101, 102], [102, 103], [103, 104], [104, 105], [105, 106], [106, 107], [107, 108], [108, 109], [109, 110], [110, 111], [111, 112], [112, 113], [113, 114], [114, 115], [115, 116], [116, 117], [117, 118], [118, 119], [119, 120], [120, 121], [121, 122], [122, 123], [123, 124], [124, 125], [125, 126], [126, 127], [127, 128], [128, 129], [129, 130], [130, 131], [131, 132], [132, 133], [133, 134], [134, 135], [135, 136], [136, 137], [137, 138], [138, 139], [139, 140], [140, 141], [141, 142], [142, 143], [143, 144], [144, 145], [145, 146], [146, 147], [147, 148], [148, 149], [149, 150]]) == 578\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [7, 13], [7, 14], [8, 15]]) == 16\n assert candidate(n = 100,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40], [20, 41], [21, 42], [21, 43], [22, 44], [22, 45], [23, 46], [23, 47], [24, 48], [24, 49], [25, 50], [26, 51], [26, 52], [27, 53], [27, 54], [28, 55], [28, 56], [29, 57], [29, 58], [30, 59], [30, 60], [31, 61], [31, 62], [32, 63], [32, 64], [33, 65], [33, 66], [34, 67], [34, 68], [35, 69], [35, 70], [36, 71], [36, 72], [37, 73], [37, 74], [38, 75], [38, 76], [39, 77], [39, 78], [40, 79], [40, 80], [41, 81], [41, 82], [42, 83], [42, 84], [43, 85], [43, 86], [44, 87], [44, 88], [45, 89], [45, 90], [46, 91], [46, 92], [47, 93], [47, 94], [48, 95], [48, 96], [49, 97], [49, 98], [50, 99], [50, 100]]) == 517\n assert candidate(n = 30,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30]]) == 59\n assert candidate(n = 18,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18]]) == 27\n assert candidate(n = 50,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50]]) == 138\n assert candidate(n = 100,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50], [50, 51], [51, 52], [52, 53], [53, 54], [54, 55], [55, 56], [56, 57], [57, 58], [58, 59], [59, 60], [60, 61], [61, 62], [62, 63], [63, 64], [64, 65], [65, 66], [66, 67], [67, 68], [68, 69], [69, 70], [70, 71], [71, 72], [72, 73], [73, 74], [74, 75], [75, 76], [76, 77], [77, 78], [78, 79], [79, 80], [80, 81], [81, 82], [82, 83], [83, 84], [84, 85], [85, 86], [86, 87], [87, 88], [88, 89], [89, 90], [90, 91], [91, 92], [92, 93], [93, 94], [94, 95], [95, 96], [96, 97], [97, 98], [98, 99], [99, 100]]) == 368\n", "comparison": "exact"}, "public_tests": ["5\n[[1,2],[1,3],[2,4],[2,5]]", "6\n[[1,2],[1,3],[2,4],[3,5],[3,6]]"], "hints": ["Use the sieve of Eratosthenes to find all prime numbers in the range [1, n].****", "Root the tree at any node.", "Let dp[i][0] = the number of vertical paths starting from i containing no prime nodes , and dp[i][1] = the number of vertical paths starting from i containing one prime node .", "If i is not prime, dp[i][0] = sum(dp[child][0]) + 1, and dp[i][1] = sum(dp[child][1]) for each child of i in the rooted tree.", "If i is prime, dp[i][0] = 0, and dp[i][1] = sum(dp[child][0]) + 1 for each child of i in the rooted tree.", "For each node i, and using the computed dp matrix, count the number of unordered pairs (a,b) such that lca(a,b) = i, and there exists exactly one prime number on the path from a to b."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().countPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:43+00:00", "tests_total": 34, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["math", "dynamic-programming", "tree", "depth-first-search", "number-theory", "primality-test", "sieve-theory", "prime-number-sieve"]}, "language": "ruby", "interface": {"raw_signature": "def count_paths(n, edges)", "container": null, "callable": "count_paths", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2869, "task_id": "minimum-operations-to-collect-elements", "difficulty": "Easy", "problem_description": "You are given an array nums of positive integers and an integer k.\n\nIn one operation, you can remove the last element of the array and add it to your collection.\n\nReturn the minimum number of operations needed to collect elements 1, 2, ..., k.\n\nExample 1:\n\nInput: nums = [3,1,5,4,2], k = 2\nOutput: 4\nExplanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.\n\nExample 2:\n\nInput: nums = [3,1,5,4,2], k = 5\nOutput: 5\nExplanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.\n\nExample 3:\n\nInput: nums = [3,2,5,3,1], k = 3\nOutput: 4\nExplanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= nums.length\n- 1 <= k <= nums.length\n- The input is generated such that you can collect elements 1, 2, ..., k.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 1, 2, 1, 2],k = 2) == 2\n assert candidate(nums = [2, 3, 1, 4, 5],k = 4) == 5\n assert candidate(nums = [3, 1, 5, 4, 2],k = 5) == 5\n assert candidate(nums = [4, 3, 2, 1, 5],k = 5) == 5\n assert candidate(nums = [1, 2, 2, 3, 3],k = 3) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(nums = [5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(nums = [1, 3, 2, 5, 4],k = 4) == 5\n assert candidate(nums = [2, 2, 2, 1, 3],k = 3) == 3\n assert candidate(nums = [5, 1, 2, 3, 4],k = 1) == 4\n assert candidate(nums = [3, 1, 5, 4, 2],k = 2) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [2, 4, 3, 1, 5],k = 4) == 5\n assert candidate(nums = [2, 4, 1, 3, 5],k = 2) == 5\n assert candidate(nums = [2, 4, 1, 3, 5],k = 4) == 5\n assert candidate(nums = [5, 3, 1, 4, 2],k = 2) == 3\n assert candidate(nums = [3, 2, 5, 3, 1],k = 3) == 4\n assert candidate(nums = [5, 4, 3, 2, 1],k = 3) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9],k = 5) == 10\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6],k = 6) == 6\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1],k = 7) == 7\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, 1],k = 1) == 1\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 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],k = 10) == 10\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],k = 50) == 50\n assert candidate(nums = [5, 3, 2, 1, 4, 6, 7],k = 7) == 7\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],k = 5) == 5\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],k = 25) == 25\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],k = 7) == 7\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 = 10) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1],k = 3) == 3\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1],k = 3) == 10\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 20) == 20\n assert candidate(nums = [5, 3, 2, 1, 4, 6, 7, 8, 9, 10],k = 10) == 10\n assert candidate(nums = [4, 5, 3, 2, 1, 6, 7],k = 5) == 7\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(nums = [3, 6, 5, 2, 8, 7, 4, 1, 9, 10],k = 5) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 3) == 5\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1],k = 1) == 1\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1],k = 1) == 1\n assert candidate(nums = [2, 1, 1, 3, 1, 2, 1, 2, 3],k = 3) == 3\n assert candidate(nums = [2, 1, 5, 4, 3, 6, 8, 7, 10, 9, 12, 11],k = 6) == 12\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13],k = 13) == 13\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 15\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) == 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, 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],k = 50) == 50\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2],k = 20) == 20\n assert candidate(nums = [4, 3, 2, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 15\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 7],k = 5) == 7\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 15\n assert candidate(nums = [6, 3, 1, 5, 4, 2, 7, 8, 9, 10],k = 10) == 10\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 = 20) == 20\n assert candidate(nums = [7, 1, 6, 2, 5, 3, 4, 8, 9, 10],k = 10) == 10\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3],k = 3) == 3\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10],k = 5) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 10) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 1, 2, 3],k = 3) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 9\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],k = 25) == 25\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 1) == None\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 5\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],k = 45) == 50\n assert candidate(nums = [7, 3, 5, 1, 2, 6, 4],k = 7) == 7\n assert candidate(nums = [5, 1, 4, 3, 2, 5, 1, 4, 3, 2, 5, 1, 4, 3, 2, 5, 1, 4, 3, 2],k = 5) == 5\n assert candidate(nums = [4, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2],k = 4) == 4\n assert candidate(nums = [3, 2, 1, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],k = 15) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(nums = [5, 3, 1, 2, 4, 6],k = 4) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 5) == 9\n assert candidate(nums = [5, 1, 3, 4, 2, 5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 15\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 10\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(nums = [5, 3, 6, 1, 2, 8, 4, 7, 9, 10],k = 10) == 10\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 10\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10],k = 10) == 10\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],k = 6) == 21\n assert candidate(nums = [5, 3, 1, 4, 2, 3, 1, 4, 2, 5],k = 5) == 5\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == None\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(nums = [4, 3, 2, 1, 4, 3, 2, 1],k = 4) == 4\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 10) == 10\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 = 15) == 15\n assert candidate(nums = [3, 5, 1, 2, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 15\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 18\n assert candidate(nums = [3, 6, 5, 3, 7, 8, 9, 1, 2, 4, 5, 6, 7, 8, 9],k = 9) == 12\n assert candidate(nums = [4, 4, 4, 4, 4, 1, 2, 3, 4, 5],k = 5) == 5\n", "comparison": "exact"}, "public_tests": ["[3,1,5,4,2]\n2", "[3,1,5,4,2]\n5", "[3,2,5,3,1]\n3"], "hints": ["Use an occurrence array.", "Iterate over the elements in reverse order.", "If the current element nums[i] is not marked in the occurrence array and nums[i] <= k, mark nums[i].", "Keep track of how many integers you have marked.", "Return the current index as soon as the number of marked integers becomes equal to k."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:47+00:00", "tests_total": 100, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums, k)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2870, "task_id": "minimum-number-of-operations-to-make-array-empty", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums consisting of positive integers.\n\nThere are two types of operations that you can apply on the array any number of times:\n\n- Choose two elements with equal values and delete them from the array.\n- Choose three elements with equal values and delete them from the array.\n\nReturn the minimum number of operations required to make the array empty, or -1 if it is not possible.\n\nExample 1:\n\nInput: nums = [2,3,3,2,2,4,2,3,4]\nOutput: 4\nExplanation: We can apply the following operations to make the array empty:\n- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].\n- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].\n- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].\n- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].\nIt can be shown that we cannot make the array empty in less than 4 operations.\n\nExample 2:\n\nInput: nums = [2,1,2,2,3,3]\nOutput: -1\nExplanation: It is impossible to empty the array.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n\nNote: This question is the same as 2244: Minimum Rounds to Complete All Tasks.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 6\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 4\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3]) == 4\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 4\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3]) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 3]) == -1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 4\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7]) == 3\n assert candidate(nums = [1000000, 1000000, 1000000]) == 1\n assert candidate(nums = [2, 1, 2, 2, 3, 3]) == -1\n assert candidate(nums = [2, 3, 3, 2, 2, 4, 2, 3, 4]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -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]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == -1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8]) == 3\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2]) == 3\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 5\n assert candidate(nums = [1000000, 1000000, 1000000]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 6\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 7\n assert candidate(nums = [10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 12\n assert candidate(nums = [10, 10, 10, 20, 20, 20, 30, 30, 30, 40, 40, 40, 50, 50, 50, 60, 60, 60, 70, 70, 70]) == 7\n assert candidate(nums = [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]) == 9\n assert candidate(nums = [36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37]) == 14\n assert candidate(nums = [6, 6, 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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 15\n assert candidate(nums = [48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49]) == 21\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 23\n assert candidate(nums = [33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36]) == 19\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 = [5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]) == 8\n assert candidate(nums = [6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 11\n assert candidate(nums = [43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]) == 24\n assert candidate(nums = [26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 9\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]) == -1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30]) == 8\n assert candidate(nums = [1, 1, 1, 1, 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, 3, 3, 3]) == 12\n assert candidate(nums = [10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 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]) == 16\n assert candidate(nums = [10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 12\n assert candidate(nums = [40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41]) == 16\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]) == 15\n assert candidate(nums = [38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39]) == 15\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]) == -1\n assert candidate(nums = [24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == 10\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]) == -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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 18\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 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, 5, 5, 5, 5]) == 16\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\n assert candidate(nums = [18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23]) == 19\n assert candidate(nums = [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20]) == 21\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 10\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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 15\n assert candidate(nums = [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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 14\n assert candidate(nums = [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, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 12\n assert candidate(nums = [11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15]) == 9\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, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 25\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]) == 16\n assert candidate(nums = [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, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == -1\n assert candidate(nums = [26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 19\n assert candidate(nums = [24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27]) == 19\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 12\n assert candidate(nums = [11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17]) == 18\n assert candidate(nums = [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]) == 18\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]) == 13\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\n assert candidate(nums = [44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]) == 19\n assert candidate(nums = [20, 20, 20, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23]) == 9\n assert candidate(nums = [100, 100, 100, 100, 101, 101, 101, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104]) == 12\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]) == 18\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, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43]) == 18\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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 26\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, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 14\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6]) == -1\n assert candidate(nums = [10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13]) == 8\n assert candidate(nums = [33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35]) == 13\n assert candidate(nums = [37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39]) == 17\n assert candidate(nums = [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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 15\n assert candidate(nums = [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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 14\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]) == 7\n assert candidate(nums = [16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]) == 9\n assert candidate(nums = [28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 22\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums = [21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == 18\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 20\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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 19\n assert candidate(nums = [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, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 18\n assert candidate(nums = [1, 1, 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]) == 13\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\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]) == 12\n assert candidate(nums = [1, 1, 2, 2, 2, 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, 5, 5, 5]) == 13\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 22\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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == -1\n assert candidate(nums = [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 20\n assert candidate(nums = [40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == 19\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, 9, 9, 9, 9, 9, 9, 9]) == 12\n assert candidate(nums = [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]) == 15\n assert candidate(nums = [46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47]) == 20\n assert candidate(nums = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 27\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]) == 9\n", "comparison": "exact"}, "public_tests": ["[2,3,3,2,2,4,2,3,4]", "[2,1,2,2,3,3]"], "hints": [], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:50+00:00", "tests_total": 107, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2871, "task_id": "split-array-into-maximum-number-of-subarrays", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of non-negative integers.\n\nWe define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.\n\nConsider splitting the array into one or more subarrays such that the following conditions are satisfied:\n\n- Each element of the array belongs to exactly one subarray.\n- The sum of scores of the subarrays is the minimum possible.\n\nReturn the maximum number of subarrays in a split that satisfies the conditions above.\n\nA subarray is a contiguous part of an array.\n\nExample 1:\n\nInput: nums = [1,0,2,0,1,2]\nOutput: 3\nExplanation: We can split the array into the following subarrays:\n- [1,0]. The score of this subarray is 1 AND 0 = 0.\n- [2,0]. The score of this subarray is 2 AND 0 = 0.\n- [1,2]. The score of this subarray is 1 AND 2 = 0.\nThe sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.\nIt can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.\n\nExample 2:\n\nInput: nums = [5,7,1,3]\nOutput: 1\nExplanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.\nIt can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [8, 12, 10, 14, 6, 7]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\n assert candidate(nums = [8, 8, 8, 8, 8]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9]) == 1\n assert candidate(nums = [15, 9, 8, 7, 14]) == 1\n assert candidate(nums = [8, 6, 7, 12, 0, 1]) == 2\n assert candidate(nums = [5, 7, 1, 3]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 4\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [8, 12, 10, 6, 14, 1, 9, 5, 3, 11, 7, 13, 2, 4]) == 3\n assert candidate(nums = [8, 12, 4, 6]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 5\n assert candidate(nums = [1, 0, 2, 0, 1, 2]) == 3\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 5\n assert candidate(nums = [8, 12, 10, 14, 6, 14, 10, 12, 8, 14, 10, 12, 8, 6, 14, 10, 12, 8]) == 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]) == 10\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0, 2, 4, 8, 16, 32, 64, 128, 256]) == 5\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 7\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 5\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]) == 1\n assert candidate(nums = [8, 4, 2, 1, 8, 4, 2, 1, 8, 4, 2, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 10\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\n assert candidate(nums = [1, 2, 3, 0, 4, 5, 0, 6, 7, 8, 0]) == 5\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255, 511]) == 1\n assert candidate(nums = [15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191]) == 1\n assert candidate(nums = [31, 15, 7, 3, 1, 31, 15, 7, 3, 1, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 1\n assert candidate(nums = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 10\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986]) == 1\n assert candidate(nums = [15, 7, 15, 7, 15, 7, 15, 7, 15, 7, 15, 7, 15, 7, 15, 7, 15, 7, 15, 7]) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255]) == 1\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 3\n assert candidate(nums = [1, 15, 3, 15, 3, 15, 3, 15, 3, 15]) == 1\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]) == 1\n assert candidate(nums = [16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240]) == 3\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 1\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584, 7168, 14336]) == 3\n assert candidate(nums = [1, 0, 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, 0, 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, 61, 62, 63, 0]) == 6\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 5\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 4\n assert candidate(nums = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015, 1014, 1013, 1012, 1011, 1010, 1009, 1008]) == 1\n assert candidate(nums = [3, 1, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 1\n assert candidate(nums = [31, 31, 31, 31, 31, 0, 31, 31, 31, 31, 31, 0, 31, 31, 31, 31, 31]) == 2\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 7\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 8\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 2\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095]) == 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, 0]) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 10\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023]) == 1\n assert candidate(nums = [16, 16, 16, 16, 16, 16, 16, 16, 16, 16]) == 1\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 32, 16, 8, 4, 64, 32, 16, 8, 128, 64, 32, 16, 256, 128, 64, 32, 512, 256, 128, 64]) == 14\n assert candidate(nums = [16, 8, 4, 2, 1, 16, 8, 4, 2, 1, 16, 8, 4, 2, 1, 16, 8, 4, 2, 1]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [16, 8, 4, 2, 1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 7\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0]) == 5\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 10\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\n assert candidate(nums = [1, 0, 3, 2, 1, 0, 3, 2, 1, 0]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 4\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 4\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984, 3968, 7936, 15872]) == 1\n assert candidate(nums = [15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]) == 1\n assert candidate(nums = [8, 4, 2, 1, 8, 4, 2, 1, 8, 4]) == 5\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 8\n assert candidate(nums = [31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095]) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535]) == 1\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79]) == 1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255]) == 1\n assert candidate(nums = [2, 1, 5, 6, 0, 3, 8, 0, 9, 7, 0, 11, 4, 0, 13, 12, 0, 15, 14, 0, 16, 17, 0, 18, 19, 0, 20, 21]) == 11\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 9\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15]) == 1\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, 0, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 0]) == 2\n", "comparison": "exact"}, "public_tests": ["[1,0,2,0,1,2]", "[5,7,1,3]"], "hints": ["The minimum score will always be the bitwise AND of all elements of the array.", "If the minimum score is not equal to 0, the only possible split will be to keep all elements in one subarray.", "Otherwise, all of the subarrays should have a score of 0, we can greedily split the array while trying to make each subarray as small as possible."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:53+00:00", "tests_total": 103, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "greedy", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def max_subarrays(nums)", "container": null, "callable": "max_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2872, "task_id": "maximum-number-of-k-divisible-components", "difficulty": "Hard", "problem_description": "There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.\n\nYou are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the i^th node, and an integer k.\n\nA valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.\n\nReturn the maximum number of components in any valid split.\n\nExample 1:\n\nInput: n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6\nOutput: 2\nExplanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:\n- The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.\n- The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.\nIt can be shown that no other valid split has more than 2 connected components.\n\nExample 2:\n\nInput: n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3\nOutput: 3\nExplanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:\n- The value of the component containing node 0 is values[0] = 3.\n- The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.\n- The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.\nIt can be shown that no other valid split has more than 3 connected components.\n\nConstraints:\n\n- 1 <= n <= 3 * 10^4\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= a_i, b_i < n\n- values.length == n\n- 0 <= values[i] <= 10^9\n- 1 <= k <= 10^9\n- Sum of values is divisible by k.\n- The input is generated such that edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [2, 3], [2, 4], [2, 5]],values = [2, 10, 5, 1, 1, 1],k = 5) == 2\n assert candidate(n = 5,edges = [[0, 2], [1, 2], [1, 3], [2, 4]],values = [1, 8, 1, 4, 4],k = 6) == 2\n assert candidate(n = 3,edges = [[0, 1], [0, 2]],values = [1, 1, 1],k = 2) == 0\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],values = [4, 6, 5, 9],k = 3) == 2\n assert candidate(n = 3,edges = [[0, 1], [1, 2]],values = [3, 9, 12],k = 3) == 3\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],values = [5, 5, 5, 5],k = 5) == 4\n assert candidate(n = 4,edges = [[0, 1], [2, 3], [1, 2]],values = [4, 4, 4, 4],k = 4) == 4\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],values = [3, 0, 6, 1, 5, 2, 1],k = 3) == 3\n assert candidate(n = 3,edges = [[0, 1], [0, 2]],values = [3, 0, 6],k = 3) == 3\n assert candidate(n = 3,edges = [[0, 1], [0, 2]],values = [1, 2, 3],k = 1) == 3\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5]],values = [12, 6, 6, 6, 6, 6],k = 12) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [0, 3], [3, 4], [3, 5]],values = [15, 15, 15, 15, 15, 15],k = 15) == 6\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [1, 3]],values = [4, 4, 4, 4],k = 4) == 4\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],values = [6, 6, 6, 6, 6, 6],k = 6) == 6\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],values = [6, 3, 9, 1, 12, 15, 3, 9, 6, 6],k = 3) == 7\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [7, 19], [7, 20], [8, 21], [8, 22], [9, 23], [9, 24]],values = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180, 189, 198, 207, 216, 225],k = 9) == 25\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],values = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 2) == 20\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 20\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [6, 19], [7, 20], [7, 21], [8, 22], [8, 23], [9, 24]],values = [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],k = 1) == 25\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],values = [6, 12, 18, 3, 3, 6, 9, 3, 6, 6],k = 3) == 10\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],values = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],k = 3) == 12\n assert candidate(n = 50,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [6, 19], [7, 20], [7, 21], [8, 22], [8, 23], [9, 24], [9, 25], [10, 26], [10, 27], [11, 28], [11, 29], [12, 30], [12, 31], [12, 32], [13, 33], [13, 34], [14, 35], [14, 36], [15, 37], [15, 38], [16, 39], [16, 40], [17, 41], [17, 42], [18, 43], [18, 44], [19, 45], [19, 46], [20, 47], [20, 48], [21, 49]],values = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220, 231, 242, 253, 264, 275, 286, 297, 308, 319, 330, 341, 352, 363, 374, 385, 396, 407, 418, 429, 440, 451, 462, 473, 484, 495, 506, 517, 528, 539, 550],k = 11) == 50\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],values = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],k = 15) == 25\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 7], [3, 8], [3, 9]],values = [10, 15, 20, 25, 30, 5, 3, 4, 2, 1],k = 5) == 4\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],values = [10, 20, 30, 40, 50, 60, 70, 80],k = 10) == 8\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 3) == 15\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 2) == 7\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],values = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 10\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 4\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24]],values = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75],k = 3) == 25\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],values = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120],k = 6) == 20\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 1) == 9\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],values = [7, 7, 7, 7, 7, 7, 7, 7, 7],k = 7) == 9\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 5) == 20\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [6, 19]],values = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 2) == 20\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11]],values = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 9) == 12\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],values = [12, 15, 3, 6, 9, 18, 21, 12, 15, 9],k = 3) == 10\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 5) == 20\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11]],values = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 3) == 12\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],values = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84],k = 7) == 12\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],values = [5, 10, 15, 5, 10, 15, 5, 10, 15, 5, 10, 15, 5, 10, 15, 5, 10, 15, 5, 5],k = 5) == 20\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],values = [7, 14, 21, 28, 35, 42, 49, 56],k = 7) == 8\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],values = [11, 22, 33, 11, 22, 33, 11, 22, 33, 11, 11],k = 11) == 11\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]],values = [1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 2\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],values = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == 20\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14]],values = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90],k = 6) == 15\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [6, 19], [7, 20], [7, 21], [8, 22], [8, 23], [9, 24]],values = [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],k = 5) == 25\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],values = [25, 50, 75, 100, 125, 150, 175, 200, 225],k = 25) == 9\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 3) == 4\n assert candidate(n = 18,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [8, 16], [9, 17]],values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 18\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11]],values = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96],k = 8) == 12\n assert candidate(n = 30,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29]],values = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],k = 20) == 30\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14]],values = [6, 3, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 3) == 15\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],values = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 10\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10) == 20\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],values = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 10\n assert candidate(n = 30,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [6, 19], [7, 20], [7, 21], [8, 22], [8, 23], [9, 24], [9, 25], [10, 26], [10, 27], [11, 28], [11, 29]],values = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175, 182, 189, 196, 203, 210],k = 7) == 30\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]],values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10) == 20\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 1\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7]],values = [8, 8, 8, 8, 8, 8, 8, 8],k = 8) == 8\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],values = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 4) == 12\n assert candidate(n = 16,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 3) == 5\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],values = [6, 12, 18, 24, 30, 36, 42, 48, 54],k = 18) == 4\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [3, 0, 6, 1, 5, 2, 1, 4, 3, 2, 1, 0, 5, 4, 3],k = 3) == 4\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90],k = 6) == 15\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 5) == 15\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],values = [2, 4, 6, 8, 10, 12, 14, 16],k = 4) == 5\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [15, 30, 45, 10, 10, 30, 45, 10, 10, 30, 10, 10, 30, 10, 10],k = 15) == 4\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 3) == 5\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 4\n assert candidate(n = 18,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17]],values = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108],k = 6) == 18\n assert candidate(n = 25,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12], [5, 13], [5, 14], [6, 15], [6, 16], [7, 17], [7, 18], [8, 19], [8, 20], [9, 21], [9, 22], [10, 23], [10, 24]],values = [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],k = 5) == 11\n assert candidate(n = 14,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [6, 13]],values = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168],k = 12) == 14\n assert candidate(n = 16,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15]],values = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 16\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 10) == 7\n", "comparison": "exact"}, "public_tests": ["5\n[[0,2],[1,2],[1,3],[2,4]]\n[1,8,1,4,4]\n6", "7\n[[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\n[3,0,6,1,5,2,1]\n3"], "hints": ["Root the tree at node 0.", "If a leaf node is not divisible by k, it must be in the same component as its parent node so we merge it with its parent node.", "If a leaf node is divisible by k, it will be in its own components so we separate it from its parent node.", "In each step, we either cut a leaf node down or merge a leaf node. The number of nodes on the tree reduces by one. Repeat this process until only one node is left."], "metadata": {"canonical_parameter_names": ["n", "edges", "values", "k"], "leetcode_dataset_entry_point": "Solution().maxKDivisibleComponents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:55+00:00", "tests_total": 78, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["tree", "depth-first-search"]}, "language": "ruby", "interface": {"raw_signature": "def max_k_divisible_components(n, edges, values, k)", "container": null, "callable": "max_k_divisible_components", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "values", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2873, "task_id": "maximum-value-of-an-ordered-triplet-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums.\n\nReturn the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n\nThe value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n\nExample 1:\n\nInput: nums = [12,6,1,2,7]\nOutput: 77\nExplanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\nIt can be shown that there are no ordered triplets of indices with a value greater than 77.\n\nExample 2:\n\nInput: nums = [1,10,3,4,19]\nOutput: 133\nExplanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\nIt can be shown that there are no ordered triplets of indices with a value greater than 133.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n\nConstraints:\n\n- 3 <= nums.length <= 100\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 2, 1, 5, 4, 6]) == 12\n assert candidate(nums = [10, 20, 3, 40, 5, 60, 7, 80, 9, 10]) == 4240\n assert candidate(nums = [12, 6, 1, 2, 7]) == 77\n assert candidate(nums = [8, 6, 4, 2, 10, 9, 7, 5, 3, 1]) == 60\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 42\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 10, 3, 4, 19]) == 133\n assert candidate(nums = [10, 9, 8, 7, 6]) == 18\n assert candidate(nums = [100, 90, 80, 70, 60]) == 1800\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 0\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97]) == 9702\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500]) == 0\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [10, 5, 15, 20, 25]) == 125\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 80\n assert candidate(nums = [3, 2, 1, 4, 5, 6]) == 12\n assert candidate(nums = [5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [3, 2, 1, 5, 4]) == 10\n assert candidate(nums = [100, 50, 200, 300, 400]) == 20000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 0\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500]) == 125000000000\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [100, 100, 100]) == 0\n assert candidate(nums = [5, 15, 10, 25, 20, 35, 30, 45, 40, 55, 50]) == 275\n assert candidate(nums = [999999, 1, 999998, 2, 999997, 3, 999996, 4, 999995, 5]) == 999996000004\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 125000000000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 0\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000]) == 999999000000\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 9702\n assert candidate(nums = [500, 400, 300, 200, 100, 101, 102, 103, 104, 105]) == 42000\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 63\n assert candidate(nums = [5, 15, 10, 20, 25, 30, 35, 40, 45, 50]) == 250\n assert candidate(nums = [1000000, 500000, 1, 2, 3, 4, 5, 6, 7, 8]) == 7999992\n assert candidate(nums = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000]) == 200000000000\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5, 999996]) == 999997000002\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 140\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60]) == 9000\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1]) == 500\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 0\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000, 1, 1000000]) == 999999000000\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [100, 10, 200, 20, 300, 30, 400, 40, 500, 50]) == 180000\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 6\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60]) == 600\n assert candidate(nums = [1000000, 1000000, 1, 2, 3, 1000000, 4, 5, 6, 1000000]) == 999999000000\n assert candidate(nums = [10, 5, 15, 20, 12, 25, 30, 5, 35, 40]) == 1000\n assert candidate(nums = [5, 25, 15, 45, 35, 65, 55, 75, 60, 85]) == 1275\n assert candidate(nums = [1, 2, 3, 10, 1, 2, 3, 10, 1, 2, 3, 10]) == 90\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(nums = [10, 100, 20, 200, 30, 300, 40, 400, 50, 500]) == 175000\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) == 0\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 80\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 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, 21, 22, 23, 24, 25]) == 0\n assert candidate(nums = [1, 2, 3, 1000000, 1000000, 1000000, 1, 2, 3, 1]) == 2999997\n assert candidate(nums = [100, 50, 25, 10, 5, 2, 1]) == 1250\n assert candidate(nums = [10, 20, 30, 15, 25, 35, 40, 5, 45, 50, 55, 60]) == 2100\n assert candidate(nums = [1, 100, 2, 200, 3, 300, 4, 400, 5, 500]) == 197500\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]) == 0\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 7999928\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 90\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 9702\n assert candidate(nums = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 0\n assert candidate(nums = [10, 20, 10, 30, 15, 40, 25, 50, 35, 60, 45, 70, 55, 80, 65, 90, 75, 100, 85, 95]) == 1500\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1980\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 6\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [30, 20, 10, 40, 50, 60, 5, 15, 25, 35]) == 1925\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10]) == 80\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 100000, 10000, 1000]) == 9000000000\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, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 200000\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 81\n assert candidate(nums = [1000000, 500000, 100000, 50000, 10000, 5000, 1000, 500, 100, 50, 10, 5, 1]) == 50000000000\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 1]) == 2000\n assert candidate(nums = [1000, 2000, 1500, 3000, 2500, 4000, 3500, 5000, 4500]) == 2500000\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 42\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991]) == 997002\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]) == 0\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 4, 7, 5]) == 14\n assert candidate(nums = [100, 200, 150, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000]) == 50000\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 = [1000, 500, 1500, 2000, 2500, 3000, 3500]) == 1750000\n assert candidate(nums = [100, 99, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94, 6, 93, 7, 92, 8, 91, 9, 90]) == 9702\n assert candidate(nums = [5, 3, 8, 6, 2, 9, 1, 7, 4, 10]) == 80\n assert candidate(nums = [100, 101, 99, 102, 98, 103, 97, 104, 96, 105]) == 840\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 9900\n assert candidate(nums = [5, 100, 50, 200, 150, 300, 250, 400, 350]) == 20000\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 0\n assert candidate(nums = [10, 5, 20, 15, 25, 30, 35, 40, 45, 50]) == 250\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5]) == 198000\n assert candidate(nums = [1, 999999, 2, 999998, 3, 999997, 4, 999996, 5, 999995]) == 999995000006\n assert candidate(nums = [10, 100, 10, 100, 10, 100, 10, 100, 10, 100, 10, 100, 10, 100, 10, 100, 10, 100, 10, 100]) == 9000\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 90\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11]) == 11\n assert candidate(nums = [5, 10, 3, 15, 20, 2, 25, 1, 30]) == 720\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50]) == 2250\n assert candidate(nums = [1, 200000, 2, 199999, 3, 199998, 4, 199997, 5, 199996, 6, 199995, 7, 199994, 8, 199993, 9, 199992, 10, 199991]) == 39999400002\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 0\n assert candidate(nums = [1000, 500, 750, 250, 300, 600, 400, 800, 900, 100]) == 675000\n assert candidate(nums = [5, 25, 10, 20, 15, 30, 2, 28, 29, 3]) == 812\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 0\n assert candidate(nums = [5, 3, 1, 8, 6, 4, 7, 9, 2, 10]) == 70\n assert candidate(nums = [50, 10, 100, 20, 150, 30, 200, 40, 250, 50]) == 40000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 0\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10]) == 20\n", "comparison": "exact"}, "public_tests": ["[12,6,1,2,7]", "[1,10,3,4,19]", "[1,2,3]"], "hints": ["Use three nested loops to find all the triplets."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumTripletValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:05:57+00:00", "tests_total": 126, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_triplet_value(nums)", "container": null, "callable": "maximum_triplet_value", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2874, "task_id": "maximum-value-of-an-ordered-triplet-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums.\n\nReturn the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n\nThe value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n\nExample 1:\n\nInput: nums = [12,6,1,2,7]\nOutput: 77\nExplanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\nIt can be shown that there are no ordered triplets of indices with a value greater than 77.\n\nExample 2:\n\nInput: nums = [1,10,3,4,19]\nOutput: 133\nExplanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\nIt can be shown that there are no ordered triplets of indices with a value greater than 133.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [12, 6, 1, 2, 7]) == 77\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 2000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250]) == 125000000000\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 42\n assert candidate(nums = [10, 9, 8, 7, 6, 5]) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6]) == 7\n assert candidate(nums = [1, 10, 3, 4, 19]) == 133\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13]) == 0\n assert candidate(nums = [100, 90, 80, 70, 60]) == 1800\n assert candidate(nums = [50, 40, 30, 20, 10]) == 400\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10]) == 11\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000]) == 999999000000\n assert candidate(nums = [999999, 1, 999998, 2, 999997, 3, 999996, 4, 999995, 5]) == 999996000004\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 0\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 16\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000]) == 999999000000\n assert candidate(nums = [100, 90, 101, 91, 102, 92, 103, 93, 104, 94]) == 1040\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 1]) == 7999920\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 90\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2000\n assert candidate(nums = [9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 1, 1]) == 64\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15]) == 135\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5, 999996]) == 999997000002\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 5, 10, 20, 40, 80, 160, 320, 640]) == 63360\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 100]) == 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]) == 210\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 0\n assert candidate(nums = [10, 20, 30, 15, 25, 35, 5, 40, 45, 50, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 3000\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 6\n assert candidate(nums = [1, 2, 3, 100, 4, 5, 6, 99, 7, 8, 98, 9, 10, 97, 11]) == 9504\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 999999\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20, 21, 22, 23, 24, 25]) == 25\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 1]) == 7999928\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1000000]) == 9000000\n assert candidate(nums = [500000, 1, 499999, 2, 499998, 3, 499997, 4, 499996, 5, 499995, 6, 499994, 7, 499993, 8, 499992, 9, 499991, 10]) == 249999000001\n assert candidate(nums = [3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13]) == 30\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10]) == 0\n assert candidate(nums = [10, 20, 30, 25, 40, 50, 15, 60, 70, 80]) == 2800\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, 12, 13, 14, 15]) == 135\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 1800\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6, 70, 7, 80, 8, 90, 9, 100, 10]) == 8100\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 45, 40, 35, 30, 25, 20, 15, 10]) == 500\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 80\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 = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9999990\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 7999928\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 990\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 10\n assert candidate(nums = [10, 20, 30, 25, 40, 35, 50, 45, 60, 55]) == 300\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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1000000]) == 0\n assert candidate(nums = [1, 100, 2, 101, 3, 102, 4, 103, 5, 104, 6, 105, 7, 106, 8, 107, 9, 108, 10, 109]) == 10682\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10]) == 40\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 800\n assert candidate(nums = [5, 3, 6, 7, 2, 8, 1, 4, 9, 10, 11, 12]) == 84\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1]) == 999999000000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [2, 1, 5, 4, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 40\n assert candidate(nums = [1, 10, 1, 20, 1, 30, 1, 40, 1, 50, 1, 60, 1, 70, 1, 80, 1, 90, 1, 100]) == 8900\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997]) == 999997000002\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 140\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91, 1000000]) == 98000000\n assert candidate(nums = [1000000, 1, 999999, 2, 999998, 3, 999997]) == 999998000001\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 90\n assert candidate(nums = [5, 3, 1, 6, 4, 2, 7, 9, 8, 10, 11, 12, 13, 14, 15]) == 60\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 160\n assert candidate(nums = [1000000, 500000, 100000, 50000, 10000, 5000, 1000, 500, 100, 50, 10, 5, 1]) == 50000000000\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 42\n assert candidate(nums = [5, 15, 25, 10, 35, 20, 45, 30, 55, 40]) == 825\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20]) == 600\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000000]) == 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 = [10, 20, 30, 25, 35, 40, 15, 50, 60, 45, 70]) == 1750\n assert candidate(nums = [1000000, 1, 999999, 2, 999998, 3, 999997, 4, 999996, 5]) == 999998000001\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1000000]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15]) == 60\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 90\n assert candidate(nums = [1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6, 70, 7, 80, 8, 90, 9, 100, 10, 110]) == 9900\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 0\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 90\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11]) == 99\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5, 4, 3, 2, 1]) == 380\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, 10]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5]) == 6\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5]) == 2000\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 361\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(nums = [500000, 400000, 300000, 200000, 100000, 99999, 89999, 79999, 69999, 59999, 49999, 39999, 29999, 19999, 9999]) == 40000000000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1000000]) == 999000000\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61, 30, 15, 7, 3, 1]) == 125000000000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100000, 1, 100001, 2, 100002, 3, 100003, 4, 100004, 5, 100005, 6, 100006, 7, 100007, 8, 100008, 9, 100009, 10]) == 10000799991\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 2000\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10]) == 80\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 0\n assert candidate(nums = [1000000, 900000, 1000000, 800000, 700000, 900000, 600000, 500000, 400000, 300000, 200000, 100000]) == 270000000000\n", "comparison": "exact"}, "public_tests": ["[12,6,1,2,7]", "[1,10,3,4,19]", "[1,2,3]"], "hints": ["Preprocess the prefix maximum array, prefix_max[i] = max(nums[0], nums[1], …, nums[i]) and the suffix maximum array, suffix_max[i] = max(nums[i], nums[i + 1], …, nums[n - 1]).", "For each index j, find two indices i and k such that i < j < k and (nums[i] - nums[j]) * nums[k] is the maximum, using the prefix and suffix maximum arrays.", "For index j, the maximum triplet value is (prefix_max[j - 1] - nums[j]) * suffix_max[j + 1]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumTripletValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:00+00:00", "tests_total": 119, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_triplet_value(nums)", "container": null, "callable": "maximum_triplet_value", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2875, "task_id": "minimum-size-subarray-in-infinite-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums and an integer target.\n\nA 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.\n\nReturn the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.\n\nExample 1:\n\nInput: nums = [1,2,3], target = 5\nOutput: 2\nExplanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].\nThe subarray in the range [1,2], has the sum equal to target = 5 and length = 2.\nIt can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.\n\nExample 2:\n\nInput: nums = [1,1,1,2,3], target = 4\nOutput: 2\nExplanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].\nThe subarray in the range [4,5], has the sum equal to target = 4 and length = 2.\nIt can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.\n\nExample 3:\n\nInput: nums = [2,4,6,8], target = 3\nOutput: -1\nExplanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].\nIt can be proven that there is no subarray with sum equal to target = 3.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- 1 <= target <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],target = 150) == 5\n assert candidate(nums = [7, 7, 7, 7, 7],target = 28) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],target = 15) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],target = 9) == 2\n assert candidate(nums = [3, 3, 3, 3, 3],target = 9) == 3\n assert candidate(nums = [1, 2, 3],target = 6) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],target = 1) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7],target = 42) == 6\n assert candidate(nums = [5, 5, 5, 5],target = 15) == 3\n assert candidate(nums = [2, 4, 6, 8],target = 3) == -1\n assert candidate(nums = [1, 1, 1, 2, 3],target = 4) == 2\n assert candidate(nums = [1],target = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],target = 15) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],target = 30) == 10\n assert candidate(nums = [1, 3, 5, 7],target = 15) == 3\n assert candidate(nums = [1, 2, 3],target = 5) == 2\n assert candidate(nums = [5, 5, 5, 5],target = 20) == 4\n assert candidate(nums = [100000],target = 100000) == 1\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3],target = 21) == 10\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19],target = 100) == 11\n assert candidate(nums = [7, 14, 28, 56, 112],target = 224) == 6\n assert candidate(nums = [10, 20, 30, 40, 50],target = 300) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 100) == 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],target = 90) == 12\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],target = 90) == 10\n assert candidate(nums = [7, 11, 15, 19],target = 100) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 55) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 110) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],target = 100) == 3\n assert candidate(nums = [5, 5, 5, 5, 5],target = 25) == 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],target = 100) == 100\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3],target = 27) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 100) == 100\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 20) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 550) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = 45) == 9\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],target = 315) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 10\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17],target = 100) == -1\n assert candidate(nums = [7, 8, 9],target = 40) == 5\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55],target = 10000) == 697\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 450) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 1000) == 181\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],target = 39) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30],target = 100) == 5\n assert candidate(nums = [1, 10, 100, 1000, 10000],target = 11111) == 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],target = 50) == 50\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 50) == 10\n assert candidate(nums = [29, 31, 37, 41, 43, 47, 53, 59, 61, 67],target = 300) == 6\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],target = 119) == 17\n assert candidate(nums = [1, 2, 4, 8, 16, 32],target = 127) == 13\n assert candidate(nums = [5, 5, 5, 5, 5],target = 75) == 15\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],target = 50) == 50\n assert candidate(nums = [9, 7, 5, 3, 1],target = 20) == 4\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 27) == 9\n assert candidate(nums = [2, 3, 6, 7, 9],target = 19) == -1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],target = 90) == 4\n assert candidate(nums = [3, 3, 3],target = 27) == 9\n assert candidate(nums = [5, 5, 5, 5, 5],target = 125) == 25\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 1023) == 10\n assert candidate(nums = [5, 7, 9, 11, 13],target = 100) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 120) == 15\n assert candidate(nums = [7, 14, 21, 28, 35],target = 98) == 4\n assert candidate(nums = [100000, 100000, 100000],target = 300000) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = 225) == 45\n assert candidate(nums = [100000],target = 500000) == 5\n assert candidate(nums = [10, 5, 15, 20, 25],target = 150) == 10\n assert candidate(nums = [23, 45, 67, 89, 12, 34, 56, 78],target = 500) == -1\n assert candidate(nums = [100000],target = 1000000000) == 10000\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 90) == 30\n assert candidate(nums = [5, 2, 7, 3, 9],target = 31) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 30) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 45) == 14\n assert candidate(nums = [10, 20, 30],target = 100) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],target = 120) == 3\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17],target = 101) == 11\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 27) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 30) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6],target = 15) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = 120) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 210) == 20\n assert candidate(nums = [1, 10, 100, 1000, 10000],target = 11111) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 100000) == 1816\n assert candidate(nums = [7, 8, 9],target = 60) == -1\n assert candidate(nums = [17, 19, 23, 29, 31],target = 150) == 6\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],target = 1000) == -1\n assert candidate(nums = [5, 2, 3, 1, 1, 1, 1, 1, 1, 1],target = 18) == 11\n assert candidate(nums = [100, 200, 300],target = 1000) == 5\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = 40) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 2500) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 120) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 55) == 10\n assert candidate(nums = [7, 1, 5, 3],target = 31) == 7\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],target = 180) == 20\n assert candidate(nums = [9, 7, 5, 3, 1],target = 30) == 6\n assert candidate(nums = [5, 2, 7],target = 22) == -1\n assert candidate(nums = [100, 200, 300, 400, 500],target = 2500) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 550) == 10\n assert candidate(nums = [7, 14, 21, 28, 35],target = 105) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16],target = 100) == 12\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 90) == 30\n assert candidate(nums = [100000, 100000, 100000, 100000],target = 400000) == 4\n assert candidate(nums = [10, 20, 30, 40, 50],target = 120) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 25) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],target = 9000) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 275) == 50\n assert candidate(nums = [1],target = 100000) == 100000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 55) == 10\n assert candidate(nums = [1, 2, 3],target = 30) == 15\n assert candidate(nums = [123, 456, 789],target = 1518) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 210) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 1000) == 181\n assert candidate(nums = [1],target = 1000000) == 1000000\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n5", "[1,1,1,2,3]\n4", "[2,4,6,8]\n3"], "hints": ["Notice that, target is either: A subarray of nums, or prefix_sum[i] + k * sum(nums) + suffix_sum[j] for some i, j, k.", "You can solve the problem for those two separate cases using hash map and prefix sums."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().minSizeSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:02+00:00", "tests_total": 117, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def min_size_subarray(nums, target)", "container": null, "callable": "min_size_subarray", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2876, "task_id": "count-visited-nodes-in-a-directed-graph", "difficulty": "Hard", "problem_description": "There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.\n\nYou are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].\n\nConsider the following process on the graph:\n\n- You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.\n\nReturn an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.\n\nExample 1:\n\nInput: edges = [1,2,0,0]\nOutput: [3,3,3,4]\nExplanation: We perform the process starting from each node in the following way:\n- Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.\n- Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.\n- Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.\n- Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.\n\nExample 2:\n\nInput: edges = [1,2,3,4,0]\nOutput: [5,5,5,5,5]\nExplanation: Starting from any node we can visit every node in the graph in the process.\n\nConstraints:\n\n- n == edges.length\n- 2 <= n <= 10^5\n- 0 <= edges[i] <= n - 1\n- edges[i] != i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [1, 0]) == [2, 2]\n assert candidate(edges = [3, 3, 4, 2, 3]) == [4, 4, 3, 3, 3]\n assert candidate(edges = [1, 2, 0, 0]) == [3, 3, 3, 4]\n assert candidate(edges = [2, 0, 1, 4, 5, 3, 1]) == [3, 3, 3, 3, 3, 3, 4]\n assert candidate(edges = [2, 0, 1, 4, 3]) == [3, 3, 3, 2, 2]\n assert candidate(edges = [2, 2, 3, 1]) == [4, 3, 3, 3]\n assert candidate(edges = [2, 0, 1, 4, 5, 3, 2, 0]) == [3, 3, 3, 3, 3, 3, 4, 4]\n assert candidate(edges = [1, 2, 3, 4, 0]) == [5, 5, 5, 5, 5]\n assert candidate(edges = [5, 4, 0, 2, 0, 4, 1]) == [3, 4, 4, 5, 3, 3, 5]\n assert candidate(edges = [1, 0, 0, 4, 1]) == [2, 2, 3, 4, 3]\n assert candidate(edges = [1, 0, 0, 0, 0]) == [2, 2, 3, 3, 3]\n assert candidate(edges = [5, 4, 5, 4, 3, 6, 2]) == [4, 3, 3, 2, 2, 3, 3]\n assert candidate(edges = [2, 0, 1, 4, 5, 3]) == [3, 3, 3, 3, 3, 3]\n assert candidate(edges = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(edges = [1, 2, 0, 1, 3, 4, 2, 5, 6, 7, 8, 9, 10]) == [3, 3, 3, 4, 5, 6, 4, 7, 5, 8, 6, 9, 7]\n assert candidate(edges = [1, 2, 3, 4, 5, 0, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0]) == [6, 6, 6, 6, 6, 6, 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]\n assert candidate(edges = [3, 8, 10, 5, 3, 4, 7, 9, 6, 2, 1, 5, 8, 11, 6, 0, 12, 13, 14, 2, 9]) == [4, 7, 7, 3, 3, 3, 7, 7, 7, 7, 7, 4, 8, 5, 8, 5, 9, 6, 9, 8, 8]\n assert candidate(edges = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 15]) == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 5, 5, 5, 5]\n assert candidate(edges = [2, 3, 4, 5, 6, 7, 8, 9, 0, 1]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(edges = [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, 0]) == [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]\n assert candidate(edges = [3, 4, 0, 1, 2, 0, 3, 5, 6, 7]) == [5, 5, 5, 5, 5, 6, 6, 7, 7, 8]\n assert candidate(edges = [4, 3, 0, 5, 3, 1, 4]) == [5, 3, 6, 3, 4, 3, 5]\n assert candidate(edges = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30, 33, 32, 35, 34, 37, 36, 39, 38, 41, 40, 43, 42, 45, 44, 47, 46, 49, 48, 51, 50, 53, 52, 55, 54, 57, 56, 59, 58, 61, 60, 63, 62, 65, 64, 67, 66, 69, 68, 71, 70, 73, 72, 75, 74, 77, 76, 79, 78, 81, 80, 83, 82, 85, 84, 87, 86, 89, 88, 91, 90, 93, 92, 95, 94, 97, 96, 99, 98, 0]) == [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, 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, 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, 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, 3]\n assert candidate(edges = [5, 6, 0, 5, 1, 3, 4, 2, 7]) == [3, 3, 4, 2, 3, 2, 3, 5, 6]\n assert candidate(edges = [7, 0, 1, 2, 3, 4, 5, 6]) == [8, 8, 8, 8, 8, 8, 8, 8]\n assert candidate(edges = [5, 4, 3, 2, 1, 0]) == [2, 2, 2, 2, 2, 2]\n assert candidate(edges = [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]) == [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31]\n assert candidate(edges = [2, 3, 1, 0, 2]) == [4, 4, 4, 4, 5]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 0]) == [9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(edges = [8, 5, 5, 5, 5, 0, 5, 5, 2]) == [4, 5, 4, 5, 5, 4, 5, 5, 4]\n assert candidate(edges = [1, 2, 3, 4, 5, 0, 1, 2, 3, 4]) == [6, 6, 6, 6, 6, 6, 7, 7, 7, 7]\n assert candidate(edges = [1, 2, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 3, 4]) == [3, 3, 3, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17]\n assert candidate(edges = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0]) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]) == [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]\n assert candidate(edges = [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, 0, 1, 2]) == [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]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0]) == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(edges = [3, 3, 3, 1]) == [3, 2, 3, 2]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0]) == [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]\n assert candidate(edges = [6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5]) == [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13]\n assert candidate(edges = [2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1]) == [11, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 13]\n assert candidate(edges = [3, 0, 0, 0]) == [2, 3, 3, 2]\n assert candidate(edges = [1, 2, 3, 4, 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5]) == [5, 5, 5, 5, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]\n assert candidate(edges = [1, 3, 0, 5, 0, 6, 0, 6, 6, 8, 8]) == [5, 5, 6, 5, 6, 5, 5, 6, 6, 7, 7]\n assert candidate(edges = [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, 0]) == [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\n assert candidate(edges = [5, 6, 7, 8, 9, 4, 5, 6, 7, 8]) == [7, 7, 7, 7, 6, 6, 6, 6, 6, 6]\n assert candidate(edges = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 50]) == [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, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]\n assert candidate(edges = [2, 3, 1, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 0]) == [120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120]\n assert candidate(edges = [99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 0]) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 101]\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 6, 6, 6, 6, 6]\n assert candidate(edges = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 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]\n assert candidate(edges = [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, 0]) == [40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40]\n", "comparison": "exact"}, "public_tests": ["[1,2,0,0]", "[1,2,3,4,0]"], "hints": ["Consider if the graph was only one cycle, what will be the answer for each node?", "The actual graph will always consist of at least one cycle and some other nodes.", "Calculate the answer for nodes in cycles the same way as in hint 1. How do you calculate the answer for the remaining nodes?"], "metadata": {"canonical_parameter_names": ["edges"], "leetcode_dataset_entry_point": "Solution().countVisitedNodes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:05+00:00", "tests_total": 91, "tests_dropped": 37, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "depth-first-search", "graph", "topological-sort", "memoization", "kosarajus-algorithm", "tarjans-scc-algorithm"]}, "language": "ruby", "interface": {"raw_signature": "def count_visited_nodes(edges)", "container": null, "callable": "count_visited_nodes", "parameters": [{"name": "edges", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2894, "task_id": "divisible-and-non-divisible-sums-difference", "difficulty": "Easy", "problem_description": "You are given positive integers n and m.\n\nDefine two integers as follows:\n\n- num1: The sum of all integers in the range [1, n] (both inclusive) that are not divisible by m.\n- num2: The sum of all integers in the range [1, n] (both inclusive) that are divisible by m.\n\nReturn the integer num1 - num2.\n\nExample 1:\n\nInput: n = 10, m = 3\nOutput: 19\nExplanation: In the given example:\n- Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.\n- Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.\nWe return 37 - 18 = 19 as the answer.\n\nExample 2:\n\nInput: n = 5, m = 6\nOutput: 15\nExplanation: In the given example:\n- Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.\n- Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.\nWe return 15 - 0 = 15 as the answer.\n\nExample 3:\n\nInput: n = 5, m = 1\nOutput: -15\nExplanation: In the given example:\n- Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.\n- Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.\nWe return 0 - 15 = -15 as the answer.\n\nConstraints:\n\n- 1 <= n, m <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1000,m = 1000) == 498500\n assert candidate(n = 5,m = 6) == 15\n assert candidate(n = 5,m = 1) == -15\n assert candidate(n = 20,m = 4) == 90\n assert candidate(n = 100,m = 10) == 3950\n assert candidate(n = 1,m = 1) == -1\n assert candidate(n = 7,m = 2) == 4\n assert candidate(n = 10,m = 3) == 19\n assert candidate(n = 600,m = 50) == 172500\n assert candidate(n = 300,m = 7) == 32508\n assert candidate(n = 120,m = 13) == 6090\n assert candidate(n = 250,m = 7) == 22555\n assert candidate(n = 350,m = 7) == 43575\n assert candidate(n = 800,m = 20) == 287600\n assert candidate(n = 250,m = 11) == 25809\n assert candidate(n = 950,m = 19) == 403275\n assert candidate(n = 600,m = 31) == 168520\n assert candidate(n = 750,m = 25) == 258375\n assert candidate(n = 999,m = 333) == 495504\n assert candidate(n = 600,m = 29) == 168120\n assert candidate(n = 600,m = 9) == 140502\n assert candidate(n = 300,m = 15) == 38850\n assert candidate(n = 1000,m = 999) == 498502\n assert candidate(n = 999,m = 17) == 441326\n assert candidate(n = 800,m = 23) == 293030\n assert candidate(n = 700,m = 29) == 227950\n assert candidate(n = 450,m = 19) == 90987\n assert candidate(n = 600,m = 5) == 107700\n assert candidate(n = 750,m = 19) == 251985\n assert candidate(n = 300,m = 25) == 41250\n assert candidate(n = 600,m = 42) == 171480\n assert candidate(n = 900,m = 29) == 376682\n assert candidate(n = 300,m = 11) == 36834\n assert candidate(n = 999,m = 13) == 423424\n assert candidate(n = 400,m = 37) == 76130\n assert candidate(n = 500,m = 41) == 118854\n assert candidate(n = 550,m = 11) == 123475\n assert candidate(n = 300,m = 4) == 22350\n assert candidate(n = 222,m = 37) == 23199\n assert candidate(n = 800,m = 31) == 300250\n assert candidate(n = 450,m = 18) == 89775\n assert candidate(n = 600,m = 20) == 161700\n assert candidate(n = 750,m = 15) == 243375\n assert candidate(n = 600,m = 19) == 161452\n assert candidate(n = 650,m = 17) == 186381\n assert candidate(n = 750,m = 50) == 269625\n assert candidate(n = 999,m = 11) == 409410\n assert candidate(n = 400,m = 41) == 76510\n assert candidate(n = 250,m = 13) == 26435\n assert candidate(n = 800,m = 33) == 300600\n assert candidate(n = 500,m = 13) == 105984\n assert candidate(n = 950,m = 31) == 422895\n assert candidate(n = 500,m = 250) == 123750\n assert candidate(n = 300,m = 19) == 40590\n assert candidate(n = 500,m = 30) == 117090\n assert candidate(n = 700,m = 11) == 200998\n assert candidate(n = 800,m = 400) == 318000\n assert candidate(n = 900,m = 55) == 390490\n assert candidate(n = 450,m = 2) == -225\n assert candidate(n = 375,m = 16) == 61668\n assert candidate(n = 200,m = 3) == 6834\n assert candidate(n = 333,m = 3) == 18315\n assert candidate(n = 250,m = 17) == 27805\n assert candidate(n = 350,m = 23) == 55905\n assert candidate(n = 300,m = 29) == 41960\n assert candidate(n = 400,m = 16) == 69800\n assert candidate(n = 500,m = 7) == 89466\n assert candidate(n = 333,m = 77) == 54071\n assert candidate(n = 750,m = 5) == 168375\n assert candidate(n = 200,m = 17) == 17856\n assert candidate(n = 450,m = 20) == 91355\n assert candidate(n = 600,m = 11) == 147630\n assert candidate(n = 800,m = 17) == 282048\n assert candidate(n = 500,m = 25) == 114750\n assert candidate(n = 800,m = 300) == 318600\n assert candidate(n = 100,m = 19) == 4480\n assert candidate(n = 450,m = 30) == 94275\n assert candidate(n = 800,m = 16) == 279600\n assert candidate(n = 200,m = 13) == 16980\n assert candidate(n = 750,m = 29) == 262775\n assert candidate(n = 500,m = 5) == 74750\n assert candidate(n = 200,m = 8) == 14900\n assert candidate(n = 750,m = 42) == 268773\n assert candidate(n = 400,m = 11) == 65548\n assert candidate(n = 900,m = 9) == 314550\n assert candidate(n = 450,m = 23) == 92735\n assert candidate(n = 300,m = 150) == 44250\n assert candidate(n = 420,m = 23) == 80544\n assert candidate(n = 999,m = 7) == 357358\n assert candidate(n = 800,m = 11) == 262584\n assert candidate(n = 900,m = 23) == 369570\n assert candidate(n = 800,m = 25) == 294000\n assert candidate(n = 600,m = 12) == 149700\n", "comparison": "exact"}, "public_tests": ["10\n3", "5\n6", "5\n1"], "hints": ["With arithmetic progression we know that the sum of integers in the range [1, n] is n * (n + 1) / 2 ."], "metadata": {"canonical_parameter_names": ["n", "m"], "leetcode_dataset_entry_point": "Solution().differenceOfSums", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:10+00:00", "tests_total": 93, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def difference_of_sums(n, m)", "container": null, "callable": "difference_of_sums", "parameters": [{"name": "n", "type": "Integer"}, {"name": "m", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2895, "task_id": "minimum-processing-time", "difficulty": "Medium", "problem_description": "You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.\n\nYou are given an array processorTime representing the time each processor becomes available and an array tasks representing how long each task takes to complete. Return the minimum time needed to complete all tasks.\n\nExample 1:\n\nInput: processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]\nOutput: 16\nExplanation:\nAssign the tasks at indices 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indices 0, 1, 2, 3 to the second processor which becomes available at time = 10.\nThe time taken by the first processor to finish the execution of all tasks is max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.\nThe time taken by the second processor to finish the execution of all tasks is max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.\n\nExample 2:\n\nInput: processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]\nOutput: 23\nExplanation:\nAssign the tasks at indices 1, 4, 5, 6 to the first processor and the others to the second processor.\nThe time taken by the first processor to finish the execution of all tasks is max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.\nThe time taken by the second processor to finish the execution of all tasks is max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.\n\nConstraints:\n\n- 1 <= n == processorTime.length <= 25000\n- 1 <= tasks.length <= 10^5\n- 0 <= processorTime[i] <= 10^9\n- 1 <= tasks[i] <= 10^9\n- tasks.length == 4 * n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(processorTime = [0, 0, 0, 0],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(processorTime = [1000000000],tasks = [1, 1, 1, 1]) == 1000000001\n assert candidate(processorTime = [10, 20],tasks = [2, 3, 1, 2, 5, 8, 4, 3]) == 23\n assert candidate(processorTime = [8, 10],tasks = [2, 2, 3, 1, 8, 7, 4, 5]) == 16\n assert candidate(processorTime = [100, 200, 300, 400, 500],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 540\n assert candidate(processorTime = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],tasks = [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]) == 1032\n assert candidate(processorTime = [1000000, 2000000, 3000000, 4000000],tasks = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 100000, 90000, 80000, 70000, 60000, 50000, 40000]) == 4070000\n assert candidate(processorTime = [100, 200, 300, 400, 500, 600, 700, 800],tasks = [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]) == 804\n assert candidate(processorTime = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45],tasks = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 46\n assert candidate(processorTime = [100, 200, 300, 400, 500, 600],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240]) == 640\n assert candidate(processorTime = [0, 10, 20, 30, 40, 50],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 54\n assert candidate(processorTime = [10, 20, 30, 40, 50, 60, 70, 80],tasks = [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]) == 84\n assert candidate(processorTime = [1000, 2000, 3000, 4000],tasks = [1, 1, 1, 1, 100, 100, 100, 100, 10000, 10000, 10000, 10000, 100000, 100000, 100000, 100000]) == 101000\n assert candidate(processorTime = [1, 1, 1, 1, 1, 1, 1, 1],tasks = [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\n assert candidate(processorTime = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],tasks = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]) == 104\n assert candidate(processorTime = [5, 15, 25, 35, 45],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 49\n assert candidate(processorTime = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],tasks = [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, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200]) == 208\n assert candidate(processorTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],tasks = [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]) == 104\n assert candidate(processorTime = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],tasks = [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]) == 140\n assert candidate(processorTime = [10, 10, 10, 10],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 26\n assert candidate(processorTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],tasks = [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]) == 154\n assert candidate(processorTime = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000],tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200]) == 8400\n assert candidate(processorTime = [50, 25, 0, 75],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 79\n assert candidate(processorTime = [50, 40, 30, 20, 10, 0],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 54\n assert candidate(processorTime = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],tasks = [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]) == 40\n", "comparison": "exact"}, "public_tests": ["[8,10]\n[2,2,3,1,8,7,4,5]", "[10,20]\n[2,3,1,2,5,8,4,3]"], "hints": ["It’s optimal to make the processor with earlier process time run 4 longer tasks.****", "The largest processTime[i] + tasks[j] (when matched) is the answer."], "metadata": {"canonical_parameter_names": ["processorTime", "tasks"], "leetcode_dataset_entry_point": "Solution().minProcessingTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:12+00:00", "tests_total": 85, "tests_dropped": 60, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def min_processing_time(processor_time, tasks)", "container": null, "callable": "min_processing_time", "parameters": [{"name": "processor_time", "type": "Integer[]"}, {"name": "tasks", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2896, "task_id": "apply-operations-to-make-two-strings-equal", "difficulty": "Medium", "problem_description": "You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.\n\nYou can perform any of the following operations on the string s1 any number of times:\n\n- Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.\n- Choose an index i such that i < n - 1 and flip both s1[i] and s1[i + 1]. The cost of this operation is 1.\n\nReturn the minimum cost needed to make the strings s1 and s2 equal, or return -1 if it is impossible.\n\nNote that flipping a character means changing it from 0 to 1 or vice-versa.\n\nExample 1:\n\nInput: s1 = \"1100011000\", s2 = \"0101001010\", x = 2\nOutput: 4\nExplanation: We can do the following operations:\n- Choose i = 3 and apply the second operation. The resulting string is s1 = \"1101111000\".\n- Choose i = 4 and apply the second operation. The resulting string is s1 = \"1101001000\".\n- Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = \"0101001010\" = s2.\nThe total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible.\n\nExample 2:\n\nInput: s1 = \"10110\", s2 = \"00011\", x = 4\nOutput: -1\nExplanation: It is not possible to make the two strings equal.\n\nConstraints:\n\n- n == s1.length == s2.length\n- 1 <= n, x <= 500\n- s1 and s2 consist only of the characters '0' and '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"101010\",s2 = \"010101\",x = 1) == 3\n assert candidate(s1 = \"1111\",s2 = \"1111\",x = 3) == 0\n assert candidate(s1 = \"101010\",s2 = \"010101\",x = 5) == 3\n assert candidate(s1 = \"1111\",s2 = \"1111\",x = 5) == 0\n assert candidate(s1 = \"1111\",s2 = \"1111\",x = 10) == 0\n assert candidate(s1 = \"001100\",s2 = \"110011\",x = 3) == 3\n assert candidate(s1 = \"101010\",s2 = \"010101\",x = 3) == 3\n assert candidate(s1 = \"1100011000\",s2 = \"0101001010\",x = 2) == 4\n assert candidate(s1 = \"0000\",s2 = \"1111\",x = 1) == 2\n assert candidate(s1 = \"0000\",s2 = \"1111\",x = 5) == 2\n assert candidate(s1 = \"10110\",s2 = \"00011\",x = 4) == -1\n assert candidate(s1 = \"110100001111001011010101010101010101010101\",s2 = \"001011110001010100101010101010101010101010\",x = 8) == 22\n assert candidate(s1 = \"01010101010101\",s2 = \"10101010101010\",x = 1) == 7\n assert candidate(s1 = \"00000000000000\",s2 = \"11111111111111\",x = 1) == 7\n assert candidate(s1 = \"1010101010101010101010\",s2 = \"1101101101101101101101\",x = 7) == 12\n assert candidate(s1 = \"000000000000\",s2 = \"111111111111\",x = 10) == 6\n assert candidate(s1 = \"000000000000000000000000000000000000\",s2 = \"111111111111111111111111111111111111\",x = 20) == 18\n assert candidate(s1 = \"110011001100\",s2 = \"001100110011\",x = 7) == 6\n assert candidate(s1 = \"111000111000111\",s2 = \"000111000111000\",x = 15) == -1\n assert candidate(s1 = \"101010101010\",s2 = \"010101010101\",x = 7) == 6\n assert candidate(s1 = \"11001100110011\",s2 = \"00110011001100\",x = 10) == 7\n assert candidate(s1 = \"0000000000000000000000\",s2 = \"1111111111111111111111\",x = 20) == 11\n assert candidate(s1 = \"110011001100\",s2 = \"001100110011\",x = 6) == 6\n assert candidate(s1 = \"1111000011\",s2 = \"0000111100\",x = 4) == 5\n assert candidate(s1 = \"1001001001001001\",s2 = \"0110110110110110\",x = 15) == 8\n assert candidate(s1 = \"111000111000\",s2 = \"000111000111\",x = 6) == 6\n assert candidate(s1 = \"000000000000\",s2 = \"111111111111\",x = 100) == 6\n assert candidate(s1 = \"1111000011110000\",s2 = \"0000111100001111\",x = 3) == 8\n assert candidate(s1 = \"01010101010\",s2 = \"10101010101\",x = 10) == -1\n assert candidate(s1 = \"111000000111\",s2 = \"000111111000\",x = 3) == 6\n assert candidate(s1 = \"101010101010\",s2 = \"010101010101\",x = 4) == 6\n assert candidate(s1 = \"100110011001\",s2 = \"011001100110\",x = 7) == 6\n assert candidate(s1 = \"111100001111\",s2 = \"000011110000\",x = 3) == 6\n assert candidate(s1 = \"10101010101010101010101010101010\",s2 = \"01010101010101010101010101010101\",x = 5) == 16\n assert candidate(s1 = \"1100101010101010\",s2 = \"0110010101010101\",x = 5) == 8\n assert candidate(s1 = \"10010010010010010010010010010010\",s2 = \"01101101101101101101101101101101\",x = 3) == 16\n assert candidate(s1 = \"100010001000\",s2 = \"011101110111\",x = 20) == 6\n assert candidate(s1 = \"111000111000\",s2 = \"000111000111\",x = 8) == 6\n assert candidate(s1 = \"0011001100\",s2 = \"1100110011\",x = 2) == 5\n assert candidate(s1 = \"010101010101010101010101\",s2 = \"101010101010101010101010\",x = 1) == 12\n assert candidate(s1 = \"1010101010101010101010\",s2 = \"0101010101010101010101\",x = 4) == 11\n assert candidate(s1 = \"0110011001\",s2 = \"1001100110\",x = 7) == 5\n assert candidate(s1 = \"101010101010\",s2 = \"101010101010\",x = 7) == 0\n assert candidate(s1 = \"10101010101010\",s2 = \"01010101010101\",x = 5) == 7\n assert candidate(s1 = \"0000000000\",s2 = \"1111111111\",x = 10) == 5\n assert candidate(s1 = \"101010101010\",s2 = \"101010101010\",x = 10) == 0\n assert candidate(s1 = \"111111111111\",s2 = \"000000000000\",x = 1) == 6\n assert candidate(s1 = \"101010101010\",s2 = \"010101010101\",x = 1) == 6\n assert candidate(s1 = \"110101010101\",s2 = \"001010101010\",x = 10) == 6\n assert candidate(s1 = \"101010101010\",s2 = \"110011001100\",x = 8) == 3\n assert candidate(s1 = \"111000001110\",s2 = \"111111111111\",x = 6) == 6\n assert candidate(s1 = \"11110000111100001111\",s2 = \"00001111000011110000\",x = 10) == 10\n assert candidate(s1 = \"1001100110\",s2 = \"1100110011\",x = 2) == -1\n assert candidate(s1 = \"010101010101\",s2 = \"101010101010\",x = 10) == 6\n assert candidate(s1 = \"10101010101010\",s2 = \"01010101010101\",x = 4) == 7\n assert candidate(s1 = \"0000000000000000000000\",s2 = \"0000000000000000000000\",x = 8) == 0\n assert candidate(s1 = \"11110000\",s2 = \"00001111\",x = 3) == 4\n assert candidate(s1 = \"101010101010\",s2 = \"101010101010\",x = 1) == 0\n assert candidate(s1 = \"0000000000\",s2 = \"1111111111\",x = 15) == 5\n assert candidate(s1 = \"1100110011\",s2 = \"0011001100\",x = 10) == 5\n assert candidate(s1 = \"1111000011110000\",s2 = \"0000111100001111\",x = 8) == 8\n assert candidate(s1 = \"111011101110\",s2 = \"000100010001\",x = 4) == 6\n assert candidate(s1 = \"11111111111111\",s2 = \"11111111111111\",x = 100) == 0\n assert candidate(s1 = \"000000000000000000000000000000\",s2 = \"111111111111111111111111111111\",x = 50) == 15\n assert candidate(s1 = \"110110110110\",s2 = \"111001100111\",x = 2) == 4\n assert candidate(s1 = \"111000111\",s2 = \"111111111\",x = 1) == -1\n assert candidate(s1 = \"0101010101\",s2 = \"1100110011\",x = 2) == -1\n assert candidate(s1 = \"0101010101010101010101010101010101010101\",s2 = \"1010101010101010101010101010101010101010\",x = 4) == 20\n assert candidate(s1 = \"01010101010101010101\",s2 = \"10101010101010101010\",x = 3) == 10\n assert candidate(s1 = \"1001100110\",s2 = \"0110011001\",x = 3) == 5\n assert candidate(s1 = \"1111111111\",s2 = \"0000000000\",x = 3) == 5\n assert candidate(s1 = \"1100110011\",s2 = \"0011001100\",x = 5) == 5\n assert candidate(s1 = \"110110110110110110\",s2 = \"001001001001001001\",x = 6) == 9\n assert candidate(s1 = \"1111111111111111111111\",s2 = \"1111111111111111111111\",x = 2) == 0\n assert candidate(s1 = \"111000111000\",s2 = \"000111000111\",x = 3) == 6\n assert candidate(s1 = \"01010101010101\",s2 = \"10101010101010\",x = 8) == 7\n assert candidate(s1 = \"1001001001\",s2 = \"0110110110\",x = 6) == 5\n assert candidate(s1 = \"0101010101\",s2 = \"1010101010\",x = 10) == 5\n assert candidate(s1 = \"1101101101\",s2 = \"1010101010\",x = 5) == 6\n assert candidate(s1 = \"010101010101\",s2 = \"101010101010\",x = 2) == 6\n assert candidate(s1 = \"111000111000\",s2 = \"000111000111\",x = 7) == 6\n assert candidate(s1 = \"1100110011001100\",s2 = \"0011001100110011\",x = 9) == 8\n assert candidate(s1 = \"1101010101\",s2 = \"0110101010\",x = 5) == -1\n assert candidate(s1 = \"110000110000\",s2 = \"001111001111\",x = 4) == 6\n assert candidate(s1 = \"1100110011\",s2 = \"0011001100\",x = 8) == 5\n assert candidate(s1 = \"111111111111\",s2 = \"000000000000\",x = 2) == 6\n assert candidate(s1 = \"100010001000\",s2 = \"011101110111\",x = 4) == 6\n assert candidate(s1 = \"10101010101010\",s2 = \"01010101010101\",x = 8) == 7\n assert candidate(s1 = \"10101010101010\",s2 = \"11001100110011\",x = 6) == -1\n assert candidate(s1 = \"11010101010101010101\",s2 = \"00101010101010101010\",x = 2) == 10\n assert candidate(s1 = \"110011001100110011001100\",s2 = \"001100110011001100110011\",x = 9) == 12\n assert candidate(s1 = \"111000111000\",s2 = \"000111000111\",x = 10) == 6\n assert candidate(s1 = \"10101010101010\",s2 = \"01010101010101\",x = 15) == 7\n assert candidate(s1 = \"1001001001\",s2 = \"1110111011\",x = 5) == 5\n assert candidate(s1 = \"111111000000\",s2 = \"000000111111\",x = 2) == 6\n assert candidate(s1 = \"110011001100110011001100110011001100\",s2 = \"110011001100110011001100110011001100\",x = 15) == 0\n assert candidate(s1 = \"110001100011\",s2 = \"001110011100\",x = 2) == 6\n assert candidate(s1 = \"100100100100\",s2 = \"011001100110\",x = 1) == 3\n assert candidate(s1 = \"110011001100\",s2 = \"001100110011\",x = 5) == 6\n assert candidate(s1 = \"1001010010\",s2 = \"0110101101\",x = 5) == 5\n assert candidate(s1 = \"111111111111\",s2 = \"000000000000\",x = 3) == 6\n assert candidate(s1 = \"111000111000111\",s2 = \"000111000111000\",x = 1) == -1\n assert candidate(s1 = \"110111011101\",s2 = \"001000100010\",x = 6) == 6\n assert candidate(s1 = \"11110000\",s2 = \"00001111\",x = 1) == 4\n assert candidate(s1 = \"011001100110\",s2 = \"100110011001\",x = 9) == 6\n assert candidate(s1 = \"11111111111111111111111111111111\",s2 = \"11111111111111111111111111111111\",x = 7) == 0\n assert candidate(s1 = \"10101010101010101010101010101010\",s2 = \"01010101010101010101010101010101\",x = 10) == 16\n assert candidate(s1 = \"1100101100\",s2 = \"0011010011\",x = 5) == 5\n assert candidate(s1 = \"000000000000\",s2 = \"111111111111\",x = 1) == 6\n assert candidate(s1 = \"100100100100\",s2 = \"100100100100\",x = 7) == 0\n assert candidate(s1 = \"111000111\",s2 = \"111111111\",x = 5) == -1\n assert candidate(s1 = \"1001010101\",s2 = \"0110101010\",x = 5) == 5\n assert candidate(s1 = \"110110110110\",s2 = \"001001001001\",x = 2) == 6\n", "comparison": "exact"}, "public_tests": ["\"1100011000\"\n\"0101001010\"\n2", "\"10110\"\n\"00011\"\n4"], "hints": ["Save all the indices that have different characters on s1 and s2 into a list, and work only with this list.", "Try to use dynamic programming on this list to solve the problem. What will be the states and transitions of this dp?"], "metadata": {"canonical_parameter_names": ["s1", "s2", "x"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:14+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(s1, s2, x)", "container": null, "callable": "min_operations", "parameters": [{"name": "s1", "type": "String"}, {"name": "s2", "type": "String"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2897, "task_id": "apply-operations-on-array-to-maximize-sum-of-squares", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums and a positive integer k.\n\nYou can do the following operation on the array any number of times:\n\n- Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwise OR operation, and AND denotes the bitwise AND operation.\n\nYou have to choose k elements from the final array and calculate the sum of their squares.\n\nReturn the maximum sum of squares you can achieve.\n\nSince the answer can be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: nums = [2,6,5,8], k = 2\nOutput: 261\nExplanation: We can do the following operations on the array:\n- Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10].\n- Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15].\nWe can choose the elements 15 and 6 from the final array. The sum of squares is 15^2 + 6^2 = 261.\nIt can be shown that this is the maximum value we can get.\n\nExample 2:\n\nInput: nums = [4,5,4,7], k = 3\nOutput: 90\nExplanation: We do not need to apply any operations.\nWe can choose the elements 7, 5, and 4 with a sum of squares: 7^2 + 5^2 + 4^2 = 90.\nIt can be shown that this is the maximum value we can get.\n\nConstraints:\n\n- 1 <= k <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 99\n assert candidate(nums = [10, 10, 10, 10],k = 4) == 400\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 2) == 98\n assert candidate(nums = [10, 10, 10, 10],k = 2) == 200\n assert candidate(nums = [1, 1, 1, 1],k = 4) == 4\n assert candidate(nums = [3, 3, 3, 3, 3, 3],k = 3) == 27\n assert candidate(nums = [2, 6, 5, 8],k = 2) == 261\n assert candidate(nums = [4, 5, 4, 7],k = 3) == 90\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 10\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777],k = 2) == 976625502\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 49\n assert candidate(nums = [1, 1, 1, 1, 1, 1],k = 6) == 6\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 = 20) == 20\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999],k = 20) == 1280\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 10) == 73676282\n assert candidate(nums = [123456789, 987654321, 234567890, 876543210, 456789012, 765432109, 654321098, 543210987, 432109876, 321098765],k = 10) == 686045577\n assert candidate(nums = [999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937],k = 5) == 24500\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 3) == 147\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73],k = 20) == 65732\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 7) == 64660\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1024, 2048, 4096, 8192, 16384],k = 15) == 74023771\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32],k = 6) == 7938\n assert candidate(nums = [123456789, 987654321, 111222333, 333222111, 444555666],k = 4) == 54499332\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17],k = 16) == 4624\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 15) == 509522932\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 11) == 4190209\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 10) == 9610\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 10) == 4186116\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999],k = 10) == 640\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17],k = 10) == 2890\n assert candidate(nums = [8, 4, 2, 1, 16, 32, 64, 128, 256, 512],k = 10) == 1046529\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],k = 5) == 847975472\n assert candidate(nums = [31, 15, 7, 3, 1, 128, 64, 32, 16, 8],k = 10) == 66221\n assert candidate(nums = [23456789, 987654321, 34567890, 876543210, 45678901, 765432109],k = 3) == 500137909\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],k = 10) == 10971971\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 10) == 509522932\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 25) == 24025\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 242976\n assert candidate(nums = [314159, 271828, 161803, 414159, 926535, 897932, 384626, 433832, 795028, 841971],k = 5) == 410299793\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728],k = 10) == 94637808\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],k = 5) == 320\n assert candidate(nums = [233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233],k = 20) == 1085780\n assert candidate(nums = [500000000, 500000001, 500000002, 500000003, 500000004, 500000005],k = 4) == 43\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575],k = 15) == 11297913\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000],k = 10) == 790321908\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 10\n assert candidate(nums = [256, 128, 64, 32, 16, 8, 4, 2, 1],k = 9) == 261121\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 20) == 509522932\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],k = 10) == 10\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 10) == 351846767\n assert candidate(nums = [65535, 65534, 65533, 65532, 65531, 65530, 65529, 65528, 65527, 65526, 65525, 65524, 65523, 65522, 65521],k = 10) == 944430306\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 = 20) == 20\n assert candidate(nums = [31, 17, 15, 13, 11, 7, 5, 3, 2],k = 5) == 2421\n assert candidate(nums = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 21) == 42286015\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888],k = 5) == 108685633\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 = 10) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 7) == 57663\n assert candidate(nums = [1000000000, 900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000],k = 5) == 757777593\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180],k = 15) == 420002\n assert candidate(nums = [1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006, 1000007, 1000008, 1000009],k = 5) == 89965549\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384],k = 3) == 7681529\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000],k = 5) == 216111556\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 5) == 53085\n assert candidate(nums = [123456789, 987654321, 135792468, 246813579, 864204680, 975318642, 789456123, 654321987, 321654987, 456789123],k = 5) == 103639635\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 245\n assert candidate(nums = [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, 101, 103, 107, 109, 113],k = 30) == 192245\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000],k = 6) == 785975284\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 = 20) == 500\n assert candidate(nums = [1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191],k = 8) == 272556040\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 8) == 1394008\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17],k = 5) == 1445\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 245\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 5) == 3461\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],k = 10) == 6250\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 1392773\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 5) == 704657727\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536],k = 8) == 179344781\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 11) == 8380418\n assert candidate(nums = [123456789, 987654321, 123456789, 987654321, 123456789, 987654321, 123456789, 987654321, 123456789, 987654321],k = 5) == 925171582\n assert candidate(nums = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048],k = 5) == 460740093\n assert candidate(nums = [13, 27, 39, 45, 51, 63, 75, 87, 99, 111, 123, 135, 147, 159, 171],k = 10) == 286506\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79],k = 10) == 80842\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047],k = 5) == 5579013\n assert candidate(nums = [1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024],k = 10) == 10485760\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13],k = 15) == 2535\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984, 3968, 7936, 15872],k = 5) == 357400917\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536],k = 7) == 912482192\n", "comparison": "exact"}, "public_tests": ["[2,6,5,8]\n2", "[4,5,4,7]\n3"], "hints": ["The operation described only transfers some bits from one element to another in their binary representation.", "To have a maximum sum of squares, it is optimal to greedily make each number as big as possible."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:17+00:00", "tests_total": 98, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def max_sum(nums, k)", "container": null, "callable": "max_sum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2899, "task_id": "last-visited-integers", "difficulty": "Easy", "problem_description": "Given an integer array nums where nums[i] is either a positive integer or -1. We need to find for each -1 the respective positive integer, which we call the last visited integer.\n\nTo achieve this goal, let's define two empty arrays: seen and ans.\n\nStart iterating from the beginning of the array nums.\n\n- If a positive integer is encountered, prepend it to the front of seen.\n- If -1 is encountered, let k be the number of consecutive -1s seen so far (including the current -1),\n - If k is less than or equal to the length of seen, append the k-th element of seen to ans.\n - If k is strictly greater than the length of seen, append -1 to ans.\n\nReturn the array ans.\n\nExample 1:\n\nInput: nums = [1,2,-1,-1,-1]\nOutput: [2,1,-1]\nExplanation:\nStart with seen = [] and ans = [].\n1. Process nums[0]: The first element in nums is 1. We prepend it to the front of seen. Now, seen == [1].\n2. Process nums[1]: The next element is 2. We prepend it to the front of seen. Now, seen == [2, 1].\n3. Process nums[2]: The next element is -1. This is the first occurrence of -1, so k == 1. We look for the first element in seen. We append 2 to ans. Now, ans == [2].\n4. Process nums[3]: Another -1. This is the second consecutive -1, so k == 2. The second element in seen is 1, so we append 1 to ans. Now, ans == [2, 1].\n5. Process nums[4]: Another -1, the third in a row, making k = 3. However, seen only has two elements ([2, 1]). Since k is greater than the number of elements in seen, we append -1 to ans. Finally, ans == [2, 1, -1].\n\nExample 2:\n\nInput: nums = [1,-1,2,-1,-1]\nOutput: [1,2,1]\nExplanation:\nStart with seen = [] and ans = [].\n1. Process nums[0]: The first element in nums is 1. We prepend it to the front of seen. Now, seen == [1].\n2. Process nums[1]: The next element is -1. This is the first occurrence of -1, so k == 1. We look for the first element in seen, which is 1. Append 1 to ans. Now, ans == [1].\n3. Process nums[2]: The next element is 2. Prepend this to the front of seen. Now, seen == [2, 1].\n4. Process nums[3]: The next element is -1. This -1 is not consecutive to the first -1 since 2 was in between. Thus, k resets to 1. The first element in seen is 2, so append 2 to ans. Now, ans == [1, 2].\n5. Process nums[4]: Another -1. This is consecutive to the previous -1, so k == 2. The second element in seen is 1, append 1 to ans. Finally, ans == [1, 2, 1].\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- nums[i] == -1 or 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, -1, 1, 2, -1]) == [-1, -1, 2]\n assert candidate(nums = [1, 2, 3, 4, -1, -1, -1, -1]) == [4, 3, 2, 1]\n assert candidate(nums = [1, -1, -1, -1, 2, -1, -1, 3, -1]) == [1, -1, -1, 2, 1, 3]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10]) == [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 1, 1, -1, -1, -1, -1]) == [1, 1, 1, -1]\n assert candidate(nums = [1, 2, 3, -1, 4, 5, -1, -1, 6, -1, -1, -1]) == [3, 5, 4, 6, 5, 4]\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == [1, 1, 1]\n assert candidate(nums = [1, -1, -1, -1, 2, -1]) == [1, -1, -1, 2]\n assert candidate(nums = [1, 2, 3, 4, 5]) == []\n assert candidate(nums = [5, 5, 5, -1, -1, -1, -1, -1]) == [5, 5, 5, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 1, -1, -1, -1, -1, -1]\n assert candidate(nums = [-1, -1, -1, -1]) == [-1, -1, -1, -1]\n assert candidate(nums = [10, -1, 20, -1, -1, 30, -1, -1, -1]) == [10, 20, 10, 30, 20, 10]\n assert candidate(nums = [5, -1, 5, -1, 5, -1]) == [5, 5, 5]\n assert candidate(nums = [-1, -1, 1, 2, -1, -1]) == [-1, -1, 2, 1]\n assert candidate(nums = [100, -1, -1, -1, -1, -1, -1, -1]) == [100, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, -1, -1, -1, -1, -1, -1, -1]) == [50, 40, 30, 20, 10, -1, -1]\n assert candidate(nums = [-1, -1, 1, 2, 3, -1]) == [-1, -1, 3]\n assert candidate(nums = [50, 25, 75, -1, -1, 100, -1, -1, -1]) == [75, 25, 100, 75, 25]\n assert candidate(nums = [1, 1, 1, -1, -1, -1, -1, -1]) == [1, 1, 1, -1, -1]\n assert candidate(nums = [1, -1, 2, -1, -1]) == [1, 2, 1]\n assert candidate(nums = [10, 20, 30, -1, -1, -1, 40, -1, -1, -1, -1]) == [30, 20, 10, 40, 30, 20, 10]\n assert candidate(nums = [3, -1, 4, -1, 5, -1, -1]) == [3, 4, 5, 4]\n assert candidate(nums = [5, 5, 5, -1, -1, 5, -1, -1, -1, -1]) == [5, 5, 5, 5, 5, 5]\n assert candidate(nums = [-1, 1, 2, -1, -1, -1]) == [-1, 2, 1, -1]\n assert candidate(nums = [3, 4, 5, -1, -1, -1, -1]) == [5, 4, 3, -1]\n assert candidate(nums = [-1, -1, -1]) == [-1, -1, -1]\n assert candidate(nums = [3, 4, 5, -1, -1, 6, -1]) == [5, 4, 6]\n assert candidate(nums = [5, -1, 4, -1, 3, -1, 2, -1, 1, -1]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, -1, -1, -1]) == [2, 1, -1]\n assert candidate(nums = [100, -1, -1, -1, 50, 60, -1, -1, -1, -1, -1]) == [100, -1, -1, 60, 50, 100, -1, -1]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, 96, -1]) == [100, 99, 98, 97, 96]\n assert candidate(nums = [1, -1, -1, 2, -1, 3, -1, -1]) == [1, -1, 2, 3, 2]\n assert candidate(nums = [1, -1, -1, 2, -1, -1, 3, -1, -1, 4, -1, -1]) == [1, -1, 2, 1, 3, 2, 4, 3]\n assert candidate(nums = [10, 20, 30, -1, -1, -1, -1]) == [30, 20, 10, -1]\n assert candidate(nums = [1, 2, 3, -1, 4, 5, -1, 6, 7, -1, 8, 9, -1, 10, 11, -1, -1, -1, -1]) == [3, 5, 7, 9, 11, 10, 9, 8]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1, 11, -1, 12, -1, 13, -1, 14, -1, 15, -1, 16, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]\n assert candidate(nums = [-1, -1, -1, -1, -1, 1, 2, 3, -1, -1, 4, 5, -1, -1, -1, 6, 7, -1, -1, -1, -1]) == [-1, -1, -1, -1, -1, 3, 2, 5, 4, 3, 7, 6, 5, 4]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1]) == [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [-1, 1, 2, -1, 3, 4, 5, -1, -1, -1, -1, 6, 7, 8, 9, -1, -1, -1, -1, -1]) == [-1, 2, 5, 4, 3, 2, 9, 8, 7, 6, 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, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, 96, -1, 95, -1]) == [100, 99, 98, 97, 96, 95]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, 6, 7, 8, 9, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 9, 8, 7, 6, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, 6, 7, 8, 9, 10, -1, -1, -1, 11, 12, 13, 14, 15, -1, -1, -1, 16, 17, 18, 19, 20, -1, -1, -1]) == [5, 4, 3, 10, 9, 8, 15, 14, 13, 20, 19, 18]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, -1, 97, -1, -1, -1, -1, -1]) == [100, 99, 98, 99, 97, 98, 99, 100, -1]\n assert candidate(nums = [1, 2, 3, -1, -1, -1, 4, 5, 6, -1, -1, -1, 7, 8, 9, -1, -1, -1, 10, 11, 12, -1, -1, -1]) == [3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10]\n assert candidate(nums = [1, 2, 3, -1, 4, -1, -1, 5, -1, -1, -1, -1]) == [3, 4, 3, 5, 4, 3, 2]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, -1, -1, -1]) == [-1, 1, 2, 3, 4, 5, 4, 3, 2]\n assert candidate(nums = [10, -1, 20, -1, 30, -1, 40, -1, 50, -1, 60, -1, 70, -1, 80, -1, 90, -1, 100, -1, -1, -1, -1]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70]\n assert candidate(nums = [-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, 10, -1, -1]) == [-1, -1, 1, -1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9]\n assert candidate(nums = [10, -1, 20, -1, 30, -1, 40, -1, 50, -1, 60, -1, 70, -1]) == [10, 20, 30, 40, 50, 60, 70]\n assert candidate(nums = [1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, -1, -1, -1, -1, -1]) == [4, 6, 5, 8, 7, 6, 5, 4]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1, 11, -1, 12, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [1, 2, 3, -1, 4, 5, -1, 6, 7, -1, 8, 9, -1, 10, 11, -1, 12, 13, -1, 14, 15, -1, 16, 17, -1, 18, 19, -1, 20, 21, -1, 22, 23, -1]) == [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\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]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\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]\n assert candidate(nums = [1, 2, 3, -1, -1, -1, 4, 5, 6, -1, -1, -1, -1, -1]) == [3, 2, 1, 6, 5, 4, 3, 2]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1, 11, -1, 12, -1, 13, -1, 14, -1, 15, -1, 16, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 7, 6, 5, 4, 3]\n assert candidate(nums = [100, 99, 98, 97, 96, -1, -1, 95, -1, -1, 94, -1, -1, 93, -1, -1, -1, -1]) == [96, 97, 95, 96, 94, 95, 93, 94, 95, 96]\n assert candidate(nums = [1, 2, -1, 3, 4, -1, 5, 6, -1, -1, -1, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, 12, 13, 14, -1, -1]) == [2, 4, 6, 5, 4, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, 13]\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]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 1, -1, 10, 9, 8, 7, 6, 5, 4]\n assert candidate(nums = [50, -1, 49, -1, 48, -1, 47, -1, 46, -1, 45, -1, 44, -1, 43, -1, 42, -1, 41, -1, 40, -1, 39, -1, 38, -1, 37, -1, 36, -1, 35, -1, 34, -1, 33, -1, 32, -1, 31, -1, 30, -1, 29, -1, 28, -1, 27, -1, 26, -1, 25, -1, 24, -1, 23, -1, 22, -1, 21, -1, 20, -1, 19, -1, 18, -1, 17, -1, 16, -1, 15, -1, 14, -1, 13, -1, 12, -1, 11, -1, 10, -1, 9, -1, 8, -1, 7, -1, 6, -1, 5, -1, 4, -1, 3, -1, 2, -1, 1, -1]) == [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]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, 16, -1, 17, -1, 18, -1, -1, -1, -1, -1]) == [15, 16, 17, 18, 17, 16, 15, 14]\n assert candidate(nums = [10, 20, 30, 40, 50, -1, -1, -1, 60, -1, -1, -1, -1, 70, -1, -1, -1, -1, -1]) == [50, 40, 30, 60, 50, 40, 30, 70, 60, 50, 40, 30]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6]\n assert candidate(nums = [50, -1, 51, -1, 52, -1, 53, -1, 54, -1, 55, -1, 56, -1, 57, -1, 58, -1, 59, -1, 60, -1, 61, -1, 62, -1]) == [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1, 6, 7, 8, -1, -1, -1, -1]) == [5, 4, 3, 2, 1, 8, 7, 6, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [15, 14, 13, 12, 11, 10, 9, 8, 7, 6]\n assert candidate(nums = [7, -1, 8, -1, -1, 9, -1, -1, -1, -1, 10, -1]) == [7, 8, 7, 9, 8, 7, -1, 10]\n assert candidate(nums = [1, 2, -1, 3, 4, -1, 5, 6, -1, 7, 8, -1, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [2, 4, 6, 8, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, -1, -1, 4, -1, -1]) == [1, 2, 3, 2, 1, 4, 3]\n assert candidate(nums = [5, -1, 10, -1, 15, -1, 20, -1, 25, -1, 30, -1, -1, -1, -1]) == [5, 10, 15, 20, 25, 30, 25, 20, 15]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, 6, 7, 8, -1, -1, -1, -1, 9, 10, -1, -1, -1, -1]) == [5, 4, 3, 2, 8, 7, 6, 5, 10, 9, 8, 7]\n assert candidate(nums = [1, 2, 3, -1, 4, 5, -1, -1, -1, -1]) == [3, 5, 4, 3, 2]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, 96, -1, 95, -1, 94, -1, 93, -1, 92, -1, 91, -1]) == [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, 96, -1, 95, -1, 94, -1]) == [100, 99, 98, 97, 96, 95, 94]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, 96, -1, 95, -1, 94, -1, 93, -1, 92, -1, 91, -1, 90, -1]) == [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]\n assert candidate(nums = [1, -1, -1, 2, -1, -1, 3, -1, -1, 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1]) == [1, -1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6]\n assert candidate(nums = [9, -1, 8, -1, 7, -1, 6, -1, 5, -1, 4, -1, 3, -1, 2, -1, 1, -1, -1, -1, -1, 10, -1, -1, -1, -1, 11, -1, -1, -1, -1]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 10, 1, 2, 3, 11, 10, 1, 2]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10]) == [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, -1, -1, -1, -1, 4, 4, -1, -1, -1, -1, 5, 5, -1, -1, -1, -1]) == [3, 3, 2, 2, 4, 4, 3, 3, 5, 5, 4, 4]\n assert candidate(nums = [1, -1, -1, -1, -1, 2, -1, -1, 3, -1, 4, -1, -1, 5, -1, -1, -1, 6, -1, -1]) == [1, -1, -1, -1, 2, 1, 3, 4, 3, 5, 4, 3, 6, 5]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1, 11, -1, 12, -1, 13, -1, 14, -1, 15, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [15, 14, 13, 12, 11, 10, 9, 8, 7, 6]\n assert candidate(nums = [100, 99, -1, 98, -1, 97, -1, -1, 96, -1, -1, -1, -1, -1]) == [99, 98, 97, 98, 96, 97, 98, 99, 100]\n assert candidate(nums = [1, 2, -1, 3, 4, -1, 5, 6, -1, 7, 8, -1, 9, 10, -1, 11, 12, -1, 13, 14, -1, 15, 16, -1, 17, 18, -1, 19, 20, -1]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, -1]) == [2, 4, 3, 5, 4, 3, 2]\n assert candidate(nums = [-1, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1]) == [-1, -1, -1, -1, 1, -1, -1, 2, 1, 3, 2, 4, 3, 2, 5, 4]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, 96, -1, 95, -1, 94, -1, 93, -1, 92, -1, 91, -1]) == [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]\n assert candidate(nums = [-1, -1, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1, 9, 10, -1, -1]) == [-1, -1, 2, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 70, 80]) == [60, 50, 40, 30, 20, 10, -1, -1, -1, -1]\n assert candidate(nums = [-1, -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, -1, -1, 1, -1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]\n assert candidate(nums = [-1, -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, 10, -1, -1, -1]) == [-1, -1, -1, 1, -1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 8]\n assert candidate(nums = [1, 2, -1, -1, 3, 4, -1, -1, -1, 5, 6, -1, -1, -1, -1, 7, 8, -1, -1, -1, -1, -1, 9, 10, -1, -1, -1, -1, -1, -1]) == [2, 1, 4, 3, 2, 6, 5, 4, 3, 8, 7, 6, 5, 4, 10, 9, 8, 7, 6, 5]\n assert candidate(nums = [1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1, 7, 8, 9, -1, -1, -1, -1, 10, 11, 12, -1, -1, -1, -1, -1, 13, 14, 15, -1, -1, -1, -1, -1]) == [3, 2, 6, 5, 4, 9, 8, 7, 6, 12, 11, 10, 9, 8, 15, 14, 13, 12, 11]\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -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, 10, -1, -1, 11, -1, -1, 12, -1, -1, 13, -1, -1, 14, -1, -1, 15, -1, -1, 16, -1, -1, 17, -1, -1, 18, -1, -1, 19, -1, -1, 20, -1, -1]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14, 16, 15, 17, 16, 18, 17, 19, 18, 20, 19]\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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1]) == [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -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]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [50, 49, 48, 47, 46, -1, 45, -1, -1, 44, -1, -1, -1, 43, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1]) == [46, 45, 46, 44, 45, 46, 43, 44, 45, 46, 42, 43, 44, 45, 46]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10, -1, 11, -1, 12, -1, 13, -1, 14, -1, 15, -1, 16, -1, 17, -1, 18, -1, 19, -1, 20, -1, 21, -1, 22, -1, 23, -1, 24, -1, 25, -1]) == [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]\n assert candidate(nums = [1, 2, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1, -1]) == [3, 2, 4, 3, 2, 5, 4, 3, 2]\n assert candidate(nums = [5, 4, 3, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, -1, -1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1]) == [1, 1, 1, 1]\n assert candidate(nums = [5, -1, -1, -1, -1, -1, -1]) == [5, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, -1, 20, -1, 30, -1, -1, -1]) == [10, 20, 30, 20, 10]\n assert candidate(nums = [100, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [100, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [3, 5, -1, -1, 2, -1, -1, -1]) == [5, 3, 2, 5, 3]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1, -1]) == [100, 99, 98, 97, 98]\n assert candidate(nums = [1, 1, 1, 1, -1, -1, -1, -1, -1, -1]) == [1, 1, 1, 1, -1, -1]\n assert candidate(nums = [10, -1, 20, -1, 30, -1, 40, -1, 50]) == [10, 20, 30, 40]\n assert candidate(nums = [1, -1, 2, 3, -1, -1, 4, -1, -1, -1]) == [1, 3, 2, 4, 3, 2]\n assert candidate(nums = [3, -1, -1, -1, 4]) == [3, -1, -1]\n assert candidate(nums = [1, -1, 2, -1, -1]) == [1, 2, 1]\n assert candidate(nums = [5, -1, 5, -1, 5, -1, 5]) == [5, 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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [5, 6, 7, -1, -1, 8, -1, -1, -1]) == [7, 6, 8, 7, 6]\n assert candidate(nums = [10, 9, 8, -1, 7, -1, -1, -1]) == [8, 7, 8, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 1, -1]\n assert candidate(nums = [-1, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1]) == [-1, -1, -1, 1, -1, 2, 1, 3, 2]\n assert candidate(nums = [10, -1, 9, -1, 11, -1, -1]) == [10, 9, 11, 9]\n assert candidate(nums = [1, 2, -1, -1, -1]) == [2, 1, -1]\n assert candidate(nums = [-1]) == [-1]\n assert candidate(nums = [5, -1, 4, -1, 3, -1, 2, -1, 1]) == [5, 4, 3, 2]\n assert candidate(nums = [-1, -1, -1, 1]) == [-1, -1, -1]\n assert candidate(nums = [10, 20, 30, -1, -1, -1, -1, -1, -1, -1]) == [30, 20, 10, -1, -1, -1, -1]\n assert candidate(nums = [5, -1, -1, 3, -1, -1, -1]) == [5, -1, 3, 5, -1]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1]\n assert candidate(nums = [1, -1, 2, -1, 3, -1, 4, -1, -1, -1]) == [1, 2, 3, 4, 3, 2]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1]\n assert candidate(nums = [-1, -1, -1, 1, 2, 3, -1, -1]) == [-1, -1, -1, 3, 2]\n assert candidate(nums = [5, -1, -1, 15, -1, 25, -1, -1, -1, -1]) == [5, -1, 15, 25, 15, 5, -1]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, -1, -1]) == [-1, 1, 2, 3, 2, 1]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1]) == [1, 1, 1]\n assert candidate(nums = [5, 10, -1, 15, -1, -1, 20, -1, -1, -1]) == [10, 15, 10, 20, 15, 10]\n assert candidate(nums = [1, -1, -1, -1, 2, -1, -1, -1]) == [1, -1, -1, 2, 1, -1]\n assert candidate(nums = [1]) == []\n assert candidate(nums = [-1, -1, -1, 1, 2]) == [-1, -1, -1]\n assert candidate(nums = [7, -1, 6, 5, -1, -1, 4, -1, -1, 3]) == [7, 5, 6, 4, 5]\n assert candidate(nums = [5, 5, 5, -1, -1, -1, -1]) == [5, 5, 5, -1]\n assert candidate(nums = [-1, -1, 1, -1, 2, -1, 3, -1, -1, -1]) == [-1, -1, 1, 2, 3, 2, 1]\n assert candidate(nums = [-1, -1, 1, -1, 2, -1, -1, 3, -1, -1, -1]) == [-1, -1, 1, 2, 1, 3, 2, 1]\n assert candidate(nums = [-1, -1, 1, -1, 2, -1, -1]) == [-1, -1, 1, 2, 1]\n assert candidate(nums = [1, -1, -1, 2, -1, -1, -1, 3, -1]) == [1, -1, 2, 1, -1, 3]\n assert candidate(nums = [1, 2, 3, -1, -1, -1, -1]) == [3, 2, 1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1]) == [5, 4, 3, 2]\n assert candidate(nums = [50, -1, -1, 50, -1, -1, -1, -1]) == [50, -1, 50, 50, -1, -1]\n assert candidate(nums = [100, -1, 50, -1, -1, 25, -1, -1, -1, -1]) == [100, 50, 100, 25, 50, 100, -1]\n assert candidate(nums = [5, -1, -1, 3, -1, 2, -1, -1, -1]) == [5, -1, 3, 2, 3, 5]\n assert candidate(nums = [1, -1, -1, -1, -1, -1, -1]) == [1, -1, -1, -1, -1, -1]\n assert candidate(nums = [50, -1, -1, 60, -1, -1, -1, -1]) == [50, -1, 60, 50, -1, -1]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, -1]) == [-1, 1, 2, 3, 2]\n assert candidate(nums = [5, -1, 4, -1, 3, -1, 2, -1, 1, -1]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [-1, -1, 1, 2, 3]) == [-1, -1]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1]) == [-1, 1, 2, 3]\n assert candidate(nums = [1, 1, 1, -1, -1, -1]) == [1, 1, 1]\n assert candidate(nums = [1, -1, -1, 2, -1, -1, 3, -1, -1, 4]) == [1, -1, 2, 1, 3, 2]\n assert candidate(nums = [1, -1, -1, -1, 2, -1, -1, 3, -1, -1, -1, -1]) == [1, -1, -1, 2, 1, 3, 2, 1, -1]\n assert candidate(nums = [-1, -1, -1, 1, -1, 2, -1, -1, 3, -1, -1, -1]) == [-1, -1, -1, 1, 2, 1, 3, 2, 1]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, 97, -1]) == [100, 99, 98, 97]\n assert candidate(nums = [1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, -1]) == [1, 1, 1, -1, -1, 1, 1, 1]\n assert candidate(nums = [1, 3, 5, -1, -1, 2, -1]) == [5, 3, 2]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, -1]) == [100, 99, 98, 99]\n assert candidate(nums = [1, 1, 1, -1, -1, -1, 1, -1, -1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [100, -1, -1, 99, -1, 98, -1, -1, -1, -1]) == [100, -1, 99, 98, 99, 100, -1]\n assert candidate(nums = [100, 99, 98, 97, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [97, 98, 99, 100, -1, -1, -1, -1, -1]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1]) == [-1, 1, 2, 3, 4]\n assert candidate(nums = [1, -1]) == [1]\n assert candidate(nums = [5, 3, -1, 4, -1, -1, -1]) == [3, 4, 3, 5]\n assert candidate(nums = [-1, -1, -1, 1, -1, 2, -1, -1, 3, -1]) == [-1, -1, -1, 1, 2, 1, 3]\n assert candidate(nums = [-1, 5, -1, 6, -1, -1]) == [-1, 5, 6, 5]\n assert candidate(nums = [5, -1, -1, 5, -1, -1, 5, -1]) == [5, -1, 5, 5, 5]\n assert candidate(nums = [1, -1, -1, 2, -1, 3, -1, -1, -1]) == [1, -1, 2, 3, 2, 1]\n assert candidate(nums = [7, -1, -1, 8, -1, 9, -1, -1, -1, 10]) == [7, -1, 8, 9, 8, 7]\n assert candidate(nums = [1, 1, 1, -1, -1, -1, -1]) == [1, 1, 1, -1]\n assert candidate(nums = [3, -1, -1, -1, 4]) == [3, -1, -1]\n assert candidate(nums = [10, 20, 30, -1, -1, -1, -1]) == [30, 20, 10, -1]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, -1, -1]) == [100, 99, 98, 99, 100]\n assert candidate(nums = [50, 25, -1, -1, 75, -1, -1, -1, 100]) == [25, 50, 75, 25, 50]\n assert candidate(nums = [5, -1, 3, -1, 2, -1, -1, -1]) == [5, 3, 2, 3, 5]\n assert candidate(nums = [5, 4, 3, 2, 1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [5, 6, 7, -1, -1, -1, -1, 8, 9, -1, -1]) == [7, 6, 5, -1, 9, 8]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4, -1, 5]) == [-1, 1, 2, 3, 4]\n assert candidate(nums = [50, 50, 50, 50, -1, -1, -1, -1, -1, -1]) == [50, 50, 50, 50, -1, -1]\n assert candidate(nums = [10, 20, 30, -1, -1, 40, -1, -1, -1, -1]) == [30, 20, 40, 30, 20, 10]\n assert candidate(nums = [5, -1, -1, 10, -1, -1, 20, -1]) == [5, -1, 10, 5, 20]\n assert candidate(nums = [-1, 1, -1, 2, -1, 3, -1, 4]) == [-1, 1, 2, 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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1]) == [5, 4, 3, 2]\n assert candidate(nums = [5, 3, -1, -1, 4, -1, 2, -1]) == [3, 5, 4, 2]\n assert candidate(nums = [3, -1, -1, 4, -1, 5]) == [3, -1, 4]\n assert candidate(nums = [5, -1, 5, -1, 5, -1, 5, -1, 5]) == [5, 5, 5, 5]\n assert candidate(nums = [1, -1, -1, -1]) == [1, -1, -1]\n assert candidate(nums = [3, 3, 3, -1, -1, -1]) == [3, 3, 3]\n assert candidate(nums = [3, 2, 1, -1, -1, -1, -1]) == [1, 2, 3, -1]\n assert candidate(nums = [5, -1, -1, -1, 3]) == [5, -1, -1]\n assert candidate(nums = [10, -1, 20, -1, 30, -1, 40, -1, 50, -1]) == [10, 20, 30, 40, 50]\n assert candidate(nums = [100, -1, -1, -1, -1, -1, -1]) == [100, -1, -1, -1, -1, -1]\n assert candidate(nums = [-1, -1, -1, -1, -1]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [-1, 1, 2, -1, -1, 3, -1]) == [-1, 2, 1, 3]\n assert candidate(nums = [1, 2, 3, -1, 4, 5, -1, -1, -1, 6]) == [3, 5, 4, 3]\n assert candidate(nums = [10, -1, 20, -1, 30, -1, -1, -1]) == [10, 20, 30, 20, 10]\n assert candidate(nums = [99, -1, 98, -1, 97, -1, 96, -1, 95, -1]) == [99, 98, 97, 96, 95]\n assert candidate(nums = [100, -1, -1, 50, -1, 25, -1, -1, -1, -1]) == [100, -1, 50, 25, 50, 100, -1]\n assert candidate(nums = [-1, -1, 1, -1, 2, -1, 3, -1, 4]) == [-1, -1, 1, 2, 3]\n assert candidate(nums = [-1, -1, -1, 1, 2]) == [-1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [3, -1, -1, -1, 5]) == [3, -1, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [10, -1, 11, 12, -1, -1, -1, -1, -1]) == [10, 12, 11, 10, -1, -1]\n assert candidate(nums = [-1, 1, -1, 2, -1, -1, 3, -1]) == [-1, 1, 2, 1, 3]\n assert candidate(nums = [1, 2, 3, -1, -1, -1, -1]) == [3, 2, 1, -1]\n assert candidate(nums = [10, 20, 30, -1, -1, 40, -1, -1, -1, -1]) == [30, 20, 40, 30, 20, 10]\n assert candidate(nums = [3, -1, -1, 4, -1, -1, -1]) == [3, -1, 4, 3, -1]\n assert candidate(nums = [10, 20, 30, -1, -1, -1, 40, -1]) == [30, 20, 10, 40]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [-1, -1, -1, 1, 2, 3]) == [-1, -1, -1]\n assert candidate(nums = [3, -1, 4, 5, -1, -1, -1]) == [3, 5, 4, 3]\n assert candidate(nums = [-1, -1, 1, 2, -1, -1, 3]) == [-1, -1, 2, 1]\n assert candidate(nums = [-1, -1, -1, 1, 2, 3, -1, -1, -1]) == [-1, -1, -1, 3, 2, 1]\n assert candidate(nums = [5, 5, -1, -1, 5, -1, -1, -1]) == [5, 5, 5, 5, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1]) == [5, 4, 3, 2, 1, -1]\n assert candidate(nums = [-1, -1, 1, 2, -1, -1, 3, -1]) == [-1, -1, 2, 1, 3]\n assert candidate(nums = [50, -1, 50, -1, 50, -1, 50]) == [50, 50, 50]\n assert candidate(nums = [50, 40, 30, 20, 10, -1, -1, -1, -1, -1, -1, -1]) == [10, 20, 30, 40, 50, -1, -1]\n assert candidate(nums = [-1, 1, 2, -1, -1, 3, -1, -1, -1]) == [-1, 2, 1, 3, 2, 1]\n assert candidate(nums = [100, -1, 99, -1, 98, -1, -1]) == [100, 99, 98, 99]\n assert candidate(nums = [-1, -1, 1, 2, -1, 3, -1, -1]) == [-1, -1, 2, 3, 2]\n assert candidate(nums = [1, -1, -1, -1, -1]) == [1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, -1, 4, -1, 5, -1, -1, -1]) == [3, 4, 5, 4, 3]\n assert candidate(nums = [1, 3, 5, -1, -1, 7, -1, -1, -1, -1]) == [5, 3, 7, 5, 3, 1]\n assert candidate(nums = [5, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [5, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [-1, -1, 1, 2, 3, -1, -1]) == [-1, -1, 3, 2]\n assert candidate(nums = [5, 2, 3, -1, 4, -1, -1, -1, 6, -1]) == [3, 4, 3, 2, 6]\n assert candidate(nums = [50, -1, -1, -1, -1, -1]) == [50, -1, -1, -1, -1]\n assert candidate(nums = [-1, -1, 1, 2, -1, -1]) == [-1, -1, 2, 1]\n assert candidate(nums = [100, -1, -1, -1, 99, -1, 98, -1, -1, -1, -1]) == [100, -1, -1, 99, 98, 99, 100, -1]\n assert candidate(nums = [7, -1, 8, -1, 9, -1, 10, -1, 11, -1, 12, -1]) == [7, 8, 9, 10, 11, 12]\n assert candidate(nums = [1, 1, 1, -1, -1, -1, -1, -1, -1]) == [1, 1, 1, -1, -1, -1]\n assert candidate(nums = [1, 1, 1, 1, -1, -1, -1, -1]) == [1, 1, 1, 1]\n assert candidate(nums = [-1, -1, -1, 1, -1, 2, -1, 3, -1, -1]) == [-1, -1, -1, 1, 2, 3, 2]\n assert candidate(nums = [42, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == [42, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, -1, -1, 4, 5, -1, -1, -1]) == [3, 2, 5, 4, 3]\n assert candidate(nums = [10, 9, 8, 7, -1, -1, -1, -1, 6, -1]) == [7, 8, 9, 10, 6]\n", "comparison": "exact"}, "public_tests": ["[1,2,-1,-1,-1]", "[1,-1,2,-1,-1]"], "hints": ["It is sufficient to implement what the description is stating."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().lastVisitedIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:22+00:00", "tests_total": 261, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def last_visited_integers(nums)", "container": null, "callable": "last_visited_integers", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2900, "task_id": "longest-unequal-adjacent-groups-subsequence-i", "difficulty": "Easy", "problem_description": "You are given a string array words and a binary array groups both of length n.\n\nA subsequence of words is alternating if for any two consecutive strings in the sequence, their corresponding elements at the same indices in groups are different (that is, there cannot be consecutive 0 or 1).\n\nYour task is to select the longest alternating subsequence from words.\n\nReturn the selected subsequence. If there are multiple answers, return any of them.\n\nNote: The elements in words are distinct.\n\nExample 1:\n\nInput: words = [\"e\",\"a\",\"b\"], groups = [0,0,1]\nOutput: [\"e\",\"b\"]\nExplanation: A subsequence that can be selected is [\"e\",\"b\"] because groups[0] != groups[2]. Another subsequence that can be selected is [\"a\",\"b\"] because groups[1] != groups[2]. It can be demonstrated that the length of the longest subsequence of indices that satisfies the condition is 2.\n\nExample 2:\n\nInput: words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,0,1,1]\nOutput: [\"a\",\"b\",\"c\"]\nExplanation: A subsequence that can be selected is [\"a\",\"b\",\"c\"] because groups[0] != groups[1] and groups[1] != groups[2]. Another subsequence that can be selected is [\"a\",\"b\",\"d\"] because groups[0] != groups[1] and groups[1] != groups[3]. It can be shown that the length of the longest subsequence of indices that satisfies the condition is 3.\n\nConstraints:\n\n- 1 <= n == words.length == groups.length <= 100\n- 1 <= words[i].length <= 10\n- groups[i] is either 0 or 1.\n- words consists of distinct strings.\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],groups = [0, 1, 1, 0]) == ['dog', 'cat', 'fish']\n assert candidate(words = ['x', 'y', 'z'],groups = [0, 1, 0]) == ['x', 'y', 'z']\n assert candidate(words = ['a', 'b', 'c', 'd'],groups = [1, 0, 1, 1]) == ['a', 'b', 'c']\n assert candidate(words = ['e', 'a', 'b'],groups = [0, 0, 1]) == ['e', 'b']\n assert candidate(words = ['one', 'two', 'three'],groups = [1, 1, 0]) == ['one', 'three']\n assert candidate(words = ['apple', 'banana', 'cherry'],groups = [1, 1, 0]) == ['apple', 'cherry']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [1, 0, 1, 0, 1]) == ['one', 'two', 'three', 'four', 'five']\n assert candidate(words = ['cat', 'dog', 'fish', 'bird'],groups = [1, 1, 0, 0]) == ['cat', 'fish']\n assert candidate(words = ['hello', 'world', 'python', 'code'],groups = [0, 1, 0, 1]) == ['hello', 'world', 'python', 'code']\n assert candidate(words = ['dog', 'cat', 'bat', 'rat'],groups = [0, 1, 0, 1]) == ['dog', 'cat', 'bat', 'rat']\n assert candidate(words = ['hello', 'world', 'python', 'code'],groups = [1, 0, 1, 0]) == ['hello', 'world', 'python', 'code']\n assert candidate(words = ['hello', 'world', 'abc', 'def'],groups = [0, 1, 0, 1]) == ['hello', 'world', 'abc', 'def']\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],groups = [0, 1, 0, 1]) == ['red', 'blue', 'green', 'yellow']\n assert candidate(words = ['umbrella', 'tornado', 'rainbow', 'ocean', 'mountain', 'lake', 'island', 'forest', 'desert', 'canyon', 'volcano', 'glacier', 'river'],groups = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == ['umbrella', 'tornado', 'ocean', 'lake', 'forest', 'canyon', 'glacier']\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'galaxy'],groups = [0, 1, 0, 1, 0]) == ['sun', 'moon', 'star', 'planet', 'galaxy']\n assert candidate(words = ['x', 'y', 'z', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['x', 'y', 'z', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w']\n assert candidate(words = ['ocean', 'sea', 'lake', 'river', 'stream', 'creek', 'pond'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['ocean', 'sea', 'lake', 'river', 'stream', 'creek', 'pond']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n assert candidate(words = ['sun', 'moon', 'star', 'comet', 'planet', 'galaxy', 'universe'],groups = [0, 1, 1, 0, 1, 0, 1]) == ['sun', 'moon', 'comet', 'planet', 'galaxy', 'universe']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta'],groups = [0, 1, 1, 0, 0, 1]) == ['alpha', 'beta', 'delta', 'zeta']\n assert candidate(words = ['quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'],groups = [1, 0, 1, 0, 1, 0, 1, 0]) == ['quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't']\n assert candidate(words = ['flower', 'tree', 'bush', 'shrub', 'vine', 'grass', 'moss'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['flower', 'tree', 'bush', 'shrub', 'vine', 'grass', 'moss']\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy', 'universe'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy', 'universe']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta'],groups = [1, 1, 0, 0, 1, 1, 0, 0]) == ['alpha', 'gamma', 'epsilon', 'eta']\n assert candidate(words = ['orange', 'lemon', 'lime', 'mango', 'papaya', 'guava', 'kiwi'],groups = [1, 0, 0, 1, 1, 0, 1]) == ['orange', 'lemon', 'mango', 'guava', 'kiwi']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']\n assert candidate(words = ['car', 'truck', 'bike', 'motorcycle', 'bicycle', 'scooter', 'skateboard', 'longboard', 'tricycle'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['car', 'truck', 'bike', 'motorcycle', 'bicycle', 'scooter', 'skateboard', 'longboard', 'tricycle']\n assert candidate(words = ['ocean', 'sea', 'lake', 'river', 'creek', 'stream', 'pond'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['ocean', 'sea', 'lake', 'river', 'creek', 'stream', 'pond']\n assert candidate(words = ['zebra', 'yak', 'xylophone', 'wolf', 'vulture', 'toucan', 'snake', 'raven', 'quetzal', 'parrot'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['zebra', 'yak', 'xylophone', 'wolf', 'vulture', 'toucan', 'snake', 'raven', 'quetzal', 'parrot']\n assert candidate(words = ['zebra', 'elephant', 'giraffe', 'hippo', 'rhino', 'lion', 'tiger', 'bear'],groups = [0, 0, 1, 1, 0, 0, 1, 1]) == ['zebra', 'giraffe', 'rhino', 'tiger']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']\n assert candidate(words = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],groups = [0, 1, 1, 0, 0, 1, 1]) == ['red', 'orange', 'green', 'indigo']\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape']\n assert candidate(words = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']\n assert candidate(words = ['puppy', 'kitten', 'fish', 'bird', 'dog', 'cat', 'hamster', 'gerbil', 'rabbit'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['puppy', 'kitten', 'fish', 'bird', 'dog', 'cat', 'hamster', 'gerbil', 'rabbit']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda'],groups = [1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1]) == ['alpha', 'beta', 'delta', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],groups = [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]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n assert candidate(words = ['ocean', 'sea', 'lake', 'river', 'pond', 'brook', 'creek', 'stream'],groups = [0, 1, 1, 0, 0, 1, 0, 0]) == ['ocean', 'sea', 'river', 'brook', 'creek']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa']\n assert candidate(words = ['cat', 'dog', 'bird', 'fish', 'ant', 'bee', 'moth', 'fly', 'antelope', 'giraffe'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['cat', 'dog', 'bird', 'fish', 'ant', 'bee', 'moth', 'fly', 'antelope', 'giraffe']\n assert candidate(words = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']\n assert candidate(words = ['car', 'bike', 'truck', 'bus', 'motorcycle', 'scooter', 'bicycle'],groups = [1, 0, 0, 1, 1, 0, 0]) == ['car', 'bike', 'bus', 'scooter']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']\n assert candidate(words = ['red', 'green', 'blue', 'yellow', 'purple', 'cyan', 'magenta', 'black', 'white'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['red', 'green', 'blue', 'yellow', 'purple', 'cyan', 'magenta', 'black', 'white']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],groups = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == ['one', 'three', 'five', 'seven', 'nine']\n assert candidate(words = ['cat', 'dog', 'rat', 'bat', 'owl', 'fox', 'wolf', 'bear'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['cat', 'dog', 'rat', 'bat', 'owl', 'fox', 'wolf', 'bear']\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy', 'universe', 'nebula', 'blackhole'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy', 'universe', 'nebula', 'blackhole']\n assert candidate(words = ['zebra', 'giraffe', 'elephant', 'lion', 'tiger', 'bear', 'wolf', 'hippo'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['zebra', 'giraffe', 'elephant', 'lion', 'tiger', 'bear', 'wolf', 'hippo']\n assert candidate(words = ['x', 'y', 'z', 'w', 'v', 'u', 't', 's', 'r', 'q'],groups = [1, 1, 0, 1, 0, 0, 1, 0, 1, 1]) == ['x', 'z', 'w', 'v', 't', 's', 'r']\n assert candidate(words = ['a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh', 'iiiiiiiii', 'jjjjjjjjjj'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh', 'iiiiiiiii', 'jjjjjjjjjj']\n assert candidate(words = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],groups = [1, 1, 0, 1, 0, 1, 0]) == ['red', 'yellow', 'green', 'blue', 'indigo', 'violet']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta']\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy'],groups = [0, 1, 1, 0, 1, 0, 1]) == ['sun', 'moon', 'planet', 'comet', 'asteroid', 'galaxy']\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'purple', 'pink', 'orange', 'black', 'white', 'gray', 'brown'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['red', 'blue', 'green', 'yellow', 'purple', 'pink', 'orange', 'black', 'white', 'gray', 'brown']\n assert candidate(words = ['zebra', 'giraffe', 'elephant', 'lion', 'tiger', 'bear', 'wolf', 'fox'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['zebra', 'giraffe', 'elephant', 'lion', 'tiger', 'bear', 'wolf', 'fox']\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape']\n assert candidate(words = ['sunrise', 'sunset', 'dawn', 'dusk', 'midnight', 'noon', 'evening', 'morning'],groups = [1, 0, 1, 0, 1, 0, 1, 0]) == ['sunrise', 'sunset', 'dawn', 'dusk', 'midnight', 'noon', 'evening', 'morning']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen']\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'nebula'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'nebula']\n assert candidate(words = ['piano', 'guitar', 'violin', 'drums', 'flute', 'trumpet', 'saxophone', 'balalaika'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['piano', 'guitar', 'violin', 'drums', 'flute', 'trumpet', 'saxophone', 'balalaika']\n assert candidate(words = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],groups = [1, 1, 0, 0, 1, 1, 0]) == ['red', 'yellow', 'blue', 'violet']\n assert candidate(words = ['ocean', 'river', 'lake', 'stream', 'pond', 'fountain', 'basin'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['ocean', 'river', 'lake', 'stream', 'pond', 'fountain', 'basin']\n assert candidate(words = ['zebra', 'giraffe', 'elephant', 'tiger', 'lion', 'bear', 'wolf', 'fox', 'coyote', 'lynx'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['zebra', 'giraffe', 'elephant', 'tiger', 'lion', 'bear', 'wolf', 'fox', 'coyote', 'lynx']\n assert candidate(words = ['zebra', 'lion', 'tiger', 'giraffe', 'elephant', 'rhino', 'hippo', 'monkey'],groups = [0, 1, 1, 0, 0, 1, 1, 0]) == ['zebra', 'lion', 'giraffe', 'rhino', 'monkey']\n assert candidate(words = ['mountain', 'hill', 'peak', 'valley', 'canyon', 'cliff', 'ridge'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['mountain', 'hill', 'peak', 'valley', 'canyon', 'cliff', 'ridge']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],groups = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == ['a', 'b', 'd', 'f', 'h', 'j']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda']\n assert candidate(words = ['cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird', 'cat', 'dog', 'fish', 'bird']\n assert candidate(words = ['sushi', 'pizza', 'burger', 'steak', 'salad', 'pasta', 'taco', 'burrito', 'sandwich', 'omelette'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['sushi', 'pizza', 'burger', 'steak', 'salad', 'pasta', 'taco', 'burrito', 'sandwich', 'omelette']\n assert candidate(words = ['zebra', 'giraffe', 'elephant', 'lion', 'tiger', 'bear', 'monkey'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['zebra', 'giraffe', 'elephant', 'lion', 'tiger', 'bear', 'monkey']\n assert candidate(words = ['zebra', 'giraffe', 'elephant', 'tiger', 'lion', 'bear', 'panda', 'rhino', 'hippo', 'flamingo'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['zebra', 'giraffe', 'elephant', 'tiger', 'lion', 'bear', 'panda', 'rhino', 'hippo', 'flamingo']\n assert candidate(words = ['ant', 'bee', 'cow', 'dog', 'elephant', 'frog', 'goat', 'horse', 'iguana', 'jaguar'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['ant', 'bee', 'cow', 'dog', 'elephant', 'frog', 'goat', 'horse', 'iguana', 'jaguar']\n assert candidate(words = ['zebra', 'elephant', 'tiger', 'lion', 'giraffe', 'rhino'],groups = [1, 0, 1, 0, 1, 0]) == ['zebra', 'elephant', 'tiger', 'lion', 'giraffe', 'rhino']\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'red', 'blue', 'green', 'yellow', 'red', 'blue', 'green', 'yellow', 'red', 'blue', 'green'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['red', 'blue', 'green', 'yellow', 'red', 'blue', 'green', 'yellow', 'red', 'blue', 'green', 'yellow', 'red', 'blue', 'green']\n assert candidate(words = ['orange', 'lemon', 'lime', 'mango', 'kiwi', 'papaya', 'guava', 'melon'],groups = [0, 1, 0, 1, 0, 1, 0, 1]) == ['orange', 'lemon', 'lime', 'mango', 'kiwi', 'papaya', 'guava', 'melon']\n assert candidate(words = ['ocean', 'river', 'lake', 'pond', 'stream', 'creek', 'bay', 'gulf'],groups = [1, 0, 1, 0, 1, 0, 1, 0]) == ['ocean', 'river', 'lake', 'pond', 'stream', 'creek', 'bay', 'gulf']\n assert candidate(words = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']\n assert candidate(words = ['panda', 'koala', 'kangaroo', 'polarbear', 'dolphin', 'seal', 'walrus'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['panda', 'koala', 'kangaroo', 'polarbear', 'dolphin', 'seal', 'walrus']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],groups = [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]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n assert candidate(words = ['ant', 'bee', 'ant', 'bee', 'ant', 'bee', 'ant', 'bee', 'ant', 'bee', 'ant', 'bee'],groups = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == ['ant', 'bee', 'ant', 'bee', 'ant', 'bee', 'ant', 'bee', 'ant', 'bee', 'ant', 'bee']\n assert candidate(words = ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['sun', 'moon', 'star', 'planet', 'comet', 'asteroid', 'galaxy']\n assert candidate(words = ['car', 'bike', 'plane', 'train', 'boat', 'ship', 'bus'],groups = [1, 0, 1, 0, 1, 0, 1]) == ['car', 'bike', 'plane', 'train', 'boat', 'ship', 'bus']\n assert candidate(words = ['ocean', 'river', 'lake', 'pond', 'waterfall', 'creek', 'stream'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['ocean', 'river', 'lake', 'pond', 'waterfall', 'creek', 'stream']\n assert candidate(words = ['north', 'south', 'east', 'west', 'northeast', 'northwest', 'southeast', 'southwest'],groups = [1, 0, 1, 0, 1, 0, 1, 0]) == ['north', 'south', 'east', 'west', 'northeast', 'northwest', 'southeast', 'southwest']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta'],groups = [0, 1, 0, 1, 0, 1]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi', 'omicron', 'pi', 'rho', 'sigma', 'tau', 'upsilon', 'phi', 'chi', 'psi', 'omega'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi', 'omicron', 'pi', 'rho', 'sigma', 'tau', 'upsilon', 'phi', 'chi', 'psi', 'omega']\n assert candidate(words = ['x', 'y', 'z', 'w', 'v', 'u', 't', 's', 'r', 'q'],groups = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == ['x', 'y', 'z', 'w', 'v', 'u', 't', 's', 'r', 'q']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [0, 1, 1, 0]) == ['one', 'two', 'four']\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],groups = [0, 0, 1, 1]) == ['red', 'green']\n assert candidate(words = ['red', 'green', 'blue'],groups = [1, 1, 0]) == ['red', 'blue']\n assert candidate(words = ['x', 'y', 'z'],groups = [0, 0, 0]) == ['x']\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],groups = [1, 0, 1, 0]) == ['dog', 'cat', 'bird', 'fish']\n assert candidate(words = ['hello', 'world', 'python'],groups = [0, 1, 0]) == ['hello', 'world', 'python']\n assert candidate(words = ['zebra', 'lion', 'tiger', 'bear'],groups = [1, 0, 1, 0]) == ['zebra', 'lion', 'tiger', 'bear']\n assert candidate(words = ['a', 'b'],groups = [0, 1]) == ['a', 'b']\n assert candidate(words = ['apple', 'banana', 'cherry'],groups = [0, 1, 0]) == ['apple', 'banana', 'cherry']\n assert candidate(words = ['dog', 'cat', 'mouse', 'elephant'],groups = [1, 0, 1, 0]) == ['dog', 'cat', 'mouse', 'elephant']\n assert candidate(words = ['x', 'y', 'z', 'w', 'v'],groups = [0, 1, 0, 1, 0]) == ['x', 'y', 'z', 'w', 'v']\n assert candidate(words = ['hello', 'world'],groups = [0, 0]) == ['hello']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],groups = [0, 1, 0, 1, 0]) == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['apple', 'banana', 'cherry', 'date'],groups = [1, 1, 0, 0]) == ['apple', 'cherry']\n assert candidate(words = ['a', 'b', 'a', 'b', 'a', 'b'],groups = [0, 1, 0, 1, 0, 1]) == ['a', 'b', 'a', 'b', 'a', 'b']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [1, 1, 1, 0]) == ['one', 'four']\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],groups = [1, 1, 0, 0]) == ['dog', 'bird']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [0, 1, 0, 1]) == ['sun', 'moon', 'star', 'planet']\n assert candidate(words = ['up', 'down', 'left', 'right'],groups = [1, 0, 1, 0]) == ['up', 'down', 'left', 'right']\n assert candidate(words = ['apple', 'banana', 'cherry'],groups = [0, 1, 0]) == ['apple', 'banana', 'cherry']\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'black'],groups = [0, 0, 1, 1, 0]) == ['red', 'green', 'black']\n assert candidate(words = ['up', 'down', 'left', 'right'],groups = [0, 1, 0, 1]) == ['up', 'down', 'left', 'right']\n assert candidate(words = ['light', 'dark'],groups = [0, 1]) == ['light', 'dark']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],groups = [1, 1, 1, 1, 1]) == ['a']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six'],groups = [1, 0, 1, 0, 1, 0]) == ['one', 'two', 'three', 'four', 'five', 'six']\n assert candidate(words = ['dog', 'cat', 'mouse'],groups = [1, 0, 1]) == ['dog', 'cat', 'mouse']\n assert candidate(words = ['fast', 'slow', 'big', 'small'],groups = [1, 0, 1, 0]) == ['fast', 'slow', 'big', 'small']\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],groups = [1, 0, 1, 0]) == ['red', 'blue', 'green', 'yellow']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta'],groups = [0, 1, 0, 1]) == ['alpha', 'beta', 'gamma', 'delta']\n assert candidate(words = ['red', 'blue', 'green'],groups = [0, 1, 0]) == ['red', 'blue', 'green']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [1, 1, 0, 0, 1]) == ['one', 'three', 'five']\n assert candidate(words = ['one', 'two', 'three'],groups = [1, 1, 1]) == ['one']\n assert candidate(words = ['cat', 'dog', 'mouse'],groups = [0, 0, 1]) == ['cat', 'mouse']\n assert candidate(words = ['apple', 'banana', 'cherry', 'date', 'elderberry'],groups = [1, 0, 1, 0, 1]) == ['apple', 'banana', 'cherry', 'date', 'elderberry']\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'purple', 'orange'],groups = [1, 0, 1, 0, 1, 0]) == ['red', 'blue', 'green', 'yellow', 'purple', 'orange']\n assert candidate(words = ['x', 'y', 'z'],groups = [0, 0, 0]) == ['x']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [0, 1, 1, 0]) == ['sun', 'moon', 'planet']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [1, 0, 1, 0, 1]) == ['one', 'two', 'three', 'four', 'five']\n assert candidate(words = ['hello', 'world', 'foo', 'bar'],groups = [0, 1, 0, 1]) == ['hello', 'world', 'foo', 'bar']\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],groups = [1, 1, 1, 0]) == ['red', 'yellow']\n assert candidate(words = ['sun', 'moon', 'star'],groups = [0, 1, 0]) == ['sun', 'moon', 'star']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta'],groups = [1, 0, 1, 0]) == ['alpha', 'beta', 'gamma', 'delta']\n assert candidate(words = ['fast', 'slow', 'high', 'low'],groups = [1, 0, 1, 0]) == ['fast', 'slow', 'high', 'low']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [1, 1, 1, 1]) == ['sun']\n assert candidate(words = ['cat', 'dog', 'elephant'],groups = [1, 0, 1]) == ['cat', 'dog', 'elephant']\n assert candidate(words = ['apple', 'banana', 'cherry', 'date'],groups = [0, 1, 0, 1]) == ['apple', 'banana', 'cherry', 'date']\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'purple'],groups = [0, 1, 0, 1, 0]) == ['red', 'blue', 'green', 'yellow', 'purple']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],groups = [1, 0, 1, 0, 1]) == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['dog', 'cat', 'fish', 'bird'],groups = [1, 0, 1, 1]) == ['dog', 'cat', 'fish']\n assert candidate(words = ['dog', 'cat', 'bird'],groups = [0, 0, 1]) == ['dog', 'bird']\n assert candidate(words = ['dog', 'cat', 'fish', 'bird'],groups = [1, 0, 1, 0]) == ['dog', 'cat', 'fish', 'bird']\n assert candidate(words = ['up', 'down', 'left', 'right'],groups = [1, 0, 1, 0]) == ['up', 'down', 'left', 'right']\n assert candidate(words = ['cat', 'dog', 'bird', 'fish'],groups = [0, 1, 0, 1]) == ['cat', 'dog', 'bird', 'fish']\n assert candidate(words = ['dog', 'cat', 'bird', 'fish'],groups = [1, 0, 1, 1]) == ['dog', 'cat', 'bird']\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],groups = [1, 1, 0, 0]) == ['red', 'green']\n assert candidate(words = ['hello', 'world'],groups = [0, 1]) == ['hello', 'world']\n assert candidate(words = ['cat', 'dog', 'elephant', 'fox'],groups = [1, 0, 1, 0]) == ['cat', 'dog', 'elephant', 'fox']\n assert candidate(words = ['red', 'blue', 'green'],groups = [0, 0, 0]) == ['red']\n assert candidate(words = ['cat', 'dog', 'bird'],groups = [0, 1, 0]) == ['cat', 'dog', 'bird']\n assert candidate(words = ['x', 'y', 'z', 'w'],groups = [0, 1, 0, 1]) == ['x', 'y', 'z', 'w']\n assert candidate(words = ['cat', 'dog', 'bird', 'fish'],groups = [1, 0, 1, 0]) == ['cat', 'dog', 'bird', 'fish']\n assert candidate(words = ['sun', 'moon', 'star'],groups = [0, 1, 1]) == ['sun', 'moon']\n assert candidate(words = ['red', 'green', 'blue', 'yellow'],groups = [1, 1, 0, 0]) == ['red', 'blue']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [1, 0, 1, 1]) == ['sun', 'moon', 'star']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [0, 1, 0, 1, 0]) == ['one', 'two', 'three', 'four', 'five']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [0, 1, 0, 1]) == ['one', 'two', 'three', 'four']\n assert candidate(words = ['red', 'blue', 'green'],groups = [0, 1, 1]) == ['red', 'blue']\n assert candidate(words = ['red', 'blue', 'green', 'yellow', 'black'],groups = [1, 0, 1, 0, 1]) == ['red', 'blue', 'green', 'yellow', 'black']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f'],groups = [1, 0, 1, 0, 1, 0]) == ['a', 'b', 'c', 'd', 'e', 'f']\n assert candidate(words = ['cat', 'dog', 'fish', 'bird', 'lizard'],groups = [0, 1, 0, 1, 0]) == ['cat', 'dog', 'fish', 'bird', 'lizard']\n assert candidate(words = ['x', 'y', 'z', 'w'],groups = [1, 0, 1, 0]) == ['x', 'y', 'z', 'w']\n assert candidate(words = ['x', 'y', 'z'],groups = [1, 0, 1]) == ['x', 'y', 'z']\n assert candidate(words = ['hello', 'world', 'python', 'code'],groups = [1, 0, 1, 0]) == ['hello', 'world', 'python', 'code']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f'],groups = [1, 0, 1, 0, 1, 0]) == ['a', 'b', 'c', 'd', 'e', 'f']\n assert candidate(words = ['apple', 'banana', 'cherry', 'date'],groups = [0, 1, 0, 1]) == ['apple', 'banana', 'cherry', 'date']\n assert candidate(words = ['hello', 'world', 'python', 'code'],groups = [0, 1, 0, 1]) == ['hello', 'world', 'python', 'code']\n assert candidate(words = ['red', 'blue', 'green'],groups = [1, 1, 1]) == ['red']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f'],groups = [0, 1, 0, 1, 0, 1]) == ['a', 'b', 'c', 'd', 'e', 'f']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [0, 0, 1, 1]) == ['sun', 'star']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [1, 0, 1, 0]) == ['sun', 'moon', 'star', 'planet']\n assert candidate(words = ['dog', 'cat', 'fish', 'bird'],groups = [0, 1, 0, 1]) == ['dog', 'cat', 'fish', 'bird']\n assert candidate(words = ['red', 'blue', 'green', 'yellow'],groups = [0, 1, 0, 1]) == ['red', 'blue', 'green', 'yellow']\n assert candidate(words = ['fast', 'slow', 'quick', 'lazy'],groups = [1, 0, 1, 0]) == ['fast', 'slow', 'quick', 'lazy']\n assert candidate(words = ['red', 'blue', 'green'],groups = [0, 0, 1]) == ['red', 'green']\n assert candidate(words = ['fast', 'slow', 'big', 'small'],groups = [1, 0, 1, 0]) == ['fast', 'slow', 'big', 'small']\n assert candidate(words = ['red', 'blue', 'green'],groups = [1, 0, 1]) == ['red', 'blue', 'green']\n assert candidate(words = ['hello', 'world'],groups = [1, 0]) == ['hello', 'world']\n assert candidate(words = ['hello', 'world', 'python', 'code'],groups = [1, 1, 0, 0]) == ['hello', 'python']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'],groups = [1, 0, 1, 0, 1]) == ['alpha', 'beta', 'gamma', 'delta', 'epsilon']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [0, 1, 0, 1]) == ['sun', 'moon', 'star', 'planet']\n assert candidate(words = ['dog', 'cat', 'fish'],groups = [1, 0, 1]) == ['dog', 'cat', 'fish']\n assert candidate(words = ['cat', 'dog', 'fish', 'bird', 'elephant'],groups = [1, 0, 1, 0, 1]) == ['cat', 'dog', 'fish', 'bird', 'elephant']\n assert candidate(words = ['left', 'right', 'up', 'down'],groups = [0, 1, 0, 1]) == ['left', 'right', 'up', 'down']\n assert candidate(words = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta'],groups = [0, 0, 1, 1, 0, 1]) == ['alpha', 'gamma', 'epsilon', 'zeta']\n assert candidate(words = ['sun', 'moon', 'star'],groups = [1, 0, 1]) == ['sun', 'moon', 'star']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six'],groups = [0, 0, 1, 1, 0, 0]) == ['one', 'three', 'five']\n assert candidate(words = ['hello', 'world'],groups = [0, 1]) == ['hello', 'world']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [0, 0, 1, 1, 0]) == ['one', 'three', 'five']\n assert candidate(words = ['hello', 'world', 'python', 'code'],groups = [0, 0, 1, 1]) == ['hello', 'python']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],groups = [0, 1, 0, 1, 0, 1, 0]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [0, 1, 0, 1, 0]) == ['one', 'two', 'three', 'four', 'five']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [1, 1, 0, 0, 1]) == ['one', 'three', 'five']\n assert candidate(words = ['quick', 'brown', 'fox'],groups = [1, 0, 1]) == ['quick', 'brown', 'fox']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [0, 0, 1, 1, 0]) == ['one', 'three', 'five']\n assert candidate(words = ['sun', 'moon', 'star', 'planet'],groups = [1, 0, 1, 1]) == ['sun', 'moon', 'star']\n assert candidate(words = ['x', 'y', 'z', 'w', 'v'],groups = [0, 0, 0, 1, 1]) == ['x', 'w']\n", "comparison": "exact"}, "public_tests": ["[\"c\"]\n[0]", "[\"d\"]\n[1]"], "hints": ["This problem can be solved greedily.", "Begin by constructing the answer starting with the first number in groups.", "For each index i in the range [1, n - 1], add i to the answer if groups[i] != groups[i - 1]."], "metadata": {"canonical_parameter_names": ["words", "groups"], "leetcode_dataset_entry_point": "Solution().getLongestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:24+00:00", "tests_total": 207, "tests_dropped": 11, "flags": ["multiple_answers"], "topic_tags": ["array", "string", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def get_longest_subsequence(words, groups)", "container": null, "callable": "get_longest_subsequence", "parameters": [{"name": "words", "type": "String[]"}, {"name": "groups", "type": "Integer[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2901, "task_id": "longest-unequal-adjacent-groups-subsequence-ii", "difficulty": "Medium", "problem_description": "You are given a string array words, and an array groups, both arrays having length n.\n\nThe hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different.\n\nYou need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i_0, i_1, ..., i_{k-1}] having length k, the following holds:\n\n- For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[i_j] != groups[i_{j+1}], for each j where 0 < j + 1 < k.\n- words[i_j] and words[i_{j+1}] are equal in length, and the hamming distance between them is 1, where 0 < j + 1 < k, for all indices in the subsequence.\n\nReturn a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.\n\nNote: strings in words may be unequal in length.\n\nExample 1:\n\nInput: words = [\"bab\",\"dab\",\"cab\"], groups = [1,2,2]\nOutput: [\"bab\",\"cab\"]\nExplanation: A subsequence that can be selected is [0,2].\n- groups[0] != groups[2]\n- words[0].length == words[2].length, and the hamming distance between them is 1.\n\nSo, a valid answer is [words[0],words[2]] = [\"bab\",\"cab\"].\nAnother subsequence that can be selected is [0,1].\n- groups[0] != groups[1]\n- words[0].length == words[1].length, and the hamming distance between them is 1.\n\nSo, another valid answer is [words[0],words[1]] = [\"bab\",\"dab\"].\nIt can be shown that the length of the longest subsequence of indices that satisfies the conditions is 2.\n\nExample 2:\n\nInput: words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,2,3,4]\nOutput: [\"a\",\"b\",\"c\",\"d\"]\nExplanation: We can select the subsequence [0,1,2,3].\nIt satisfies both conditions.\nHence, the answer is [words[0],words[1],words[2],words[3]] = [\"a\",\"b\",\"c\",\"d\"].\nIt has the longest length among all subsequences of indices that satisfy the conditions.\nHence, it is the only answer.\n\nConstraints:\n\n- 1 <= n == words.length == groups.length <= 1000\n- 1 <= words[i].length <= 10\n- 1 <= groups[i] <= n\n- words consists of distinct strings.\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'bac', 'bca', 'cab', 'cba', 'acb'],groups = [1, 2, 1, 2, 1, 2]) == ['abc']\n assert candidate(words = ['same', 'sane', 'same'],groups = [1, 2, 1]) == ['same', 'sane', 'same']\n assert candidate(words = ['test', 'tast', 'best', 'rest'],groups = [1, 2, 2, 3]) == ['test', 'best', 'rest']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hexlo'],groups = [1, 2, 2, 3]) == ['hello', 'hallo']\n assert candidate(words = ['abcd', 'abcf', 'abgf', 'abgh'],groups = [1, 2, 2, 3]) == ['abcd', 'abcf']\n assert candidate(words = ['hello', 'hallo', 'hbllo', 'hillo'],groups = [1, 1, 2, 3]) == ['hello', 'hbllo', 'hillo']\n assert candidate(words = ['bab', 'dab', 'cab'],groups = [1, 2, 2]) == ['bab', 'dab']\n assert candidate(words = ['word', 'worm', 'wore', 'core'],groups = [1, 2, 1, 2]) == ['word', 'worm', 'wore', 'core']\n assert candidate(words = ['same', 'sane', 'tame', 'game'],groups = [1, 2, 2, 3]) == ['same', 'tame', 'game']\n assert candidate(words = ['a', 'b', 'c', 'd'],groups = [1, 2, 3, 4]) == ['a', 'b', 'c', 'd']\n assert candidate(words = ['apple', 'appla', 'appel'],groups = [1, 2, 1]) == ['apple', 'appla']\n assert candidate(words = ['a', 'ab', 'abc', 'abcd'],groups = [1, 2, 3, 4]) == ['a']\n assert candidate(words = ['zzz', 'zzx', 'zzw', 'zzv'],groups = [1, 2, 3, 4]) == ['zzz', 'zzx', 'zzw', 'zzv']\n assert candidate(words = ['test', 'tast', 'tost', 'test'],groups = [1, 2, 1, 2]) == ['test', 'tast', 'tost', 'test']\n assert candidate(words = ['abc', 'bcd', 'cde', 'def'],groups = [1, 2, 3, 4]) == ['abc']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [1, 2, 2, 3]) == ['one']\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl'],groups = [1, 1, 2, 2]) == ['abc']\n assert candidate(words = ['word', 'wird', 'word', 'wird'],groups = [1, 2, 1, 2]) == ['word', 'wird', 'word', 'wird']\n assert candidate(words = ['abc', 'abb', 'aba', 'aaa', 'aab'],groups = [1, 2, 3, 4, 5]) == ['abc', 'abb', 'aba', 'aaa', 'aab']\n assert candidate(words = ['aabb', 'abab', 'abba', 'baab'],groups = [1, 2, 1, 2]) == ['aabb']\n assert candidate(words = ['aabb', 'abab', 'babb', 'baab'],groups = [1, 2, 1, 2]) == ['babb', 'baab']\n assert candidate(words = ['cat', 'cot', 'dog', 'dot', 'log'],groups = [1, 2, 1, 2, 3]) == ['cat', 'cot']\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'],groups = [1, 2, 1, 2, 1, 2]) == ['abc']\n assert candidate(words = ['xyz', 'xyw', 'xyv', 'xyu'],groups = [1, 2, 3, 4]) == ['xyz', 'xyw', 'xyv', 'xyu']\n assert candidate(words = ['aaaa', 'aaab', 'aabb', 'abbb', 'bbbb'],groups = [1, 2, 3, 4, 5]) == ['aaaa', 'aaab', 'aabb', 'abbb', 'bbbb']\n assert candidate(words = ['abc', 'bac', 'cab', 'bca', 'acb', 'cba'],groups = [1, 2, 3, 1, 2, 3]) == ['abc']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcg'],groups = [1, 2, 3, 4]) == ['abcd', 'abce', 'abcf', 'abcg']\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd', 'ace'],groups = [1, 2, 1, 2, 1]) == ['abc', 'abd', 'acd', 'bcd']\n assert candidate(words = ['abcd', 'abcf', 'abdf', 'abef', 'acdf', 'acef', 'bcdf', 'bcef'],groups = [1, 2, 1, 2, 1, 2, 1, 2]) == ['abcd', 'abcf', 'abdf', 'abef']\n assert candidate(words = ['code', 'codd', 'cods', 'coex', 'coey'],groups = [1, 2, 2, 3, 3]) == ['code', 'codd']\n assert candidate(words = ['abc', 'bcd', 'cde', 'def', 'efg'],groups = [1, 2, 3, 4, 5]) == ['abc']\n assert candidate(words = ['apple', 'apples', 'appl', 'app'],groups = [1, 2, 3, 4]) == ['apple']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n assert candidate(words = ['same', 'sane', 'sate', 'site'],groups = [1, 2, 1, 2]) == ['same', 'sane', 'sate', 'site']\n assert candidate(words = ['abcde', 'abfde', 'abcfe', 'abcef'],groups = [1, 2, 3, 4]) == ['abcde', 'abfde']\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd', 'bce', 'bde'],groups = [1, 2, 1, 2, 1, 2]) == ['abc', 'abd', 'acd', 'bcd', 'bce', 'bde']\n assert candidate(words = ['mnop', 'mnoq', 'mnrp', 'mnsp', 'mntp'],groups = [1, 2, 3, 2, 1]) == ['mnop', 'mnrp', 'mnsp', 'mntp']\n assert candidate(words = ['apple', 'apply', 'appla', 'appla'],groups = [1, 2, 1, 3]) == ['apple', 'apply', 'appla']\n assert candidate(words = ['aaaa', 'abaa', 'acaa', 'aada', 'aada', 'aadd'],groups = [1, 2, 3, 1, 2, 3]) == ['aaaa', 'abaa', 'acaa']\n assert candidate(words = ['dog', 'cog', 'dag', 'dog', 'dig'],groups = [1, 2, 1, 2, 1]) == ['dag', 'dog', 'dig']\n assert candidate(words = ['word', 'worm', 'wirm', 'wirm', 'wirn'],groups = [1, 2, 3, 4, 5]) == ['word', 'worm', 'wirm', 'wirn']\n assert candidate(words = ['test', 'tast', 'tost', 'test', 'teat'],groups = [1, 2, 1, 2, 1]) == ['test', 'tast', 'tost', 'test', 'teat']\n assert candidate(words = ['aaaaa', 'aaaba', 'aaaca', 'aaada'],groups = [1, 2, 1, 2]) == ['aaaaa', 'aaaba', 'aaaca', 'aaada']\n assert candidate(words = ['cat', 'bat', 'rat', 'tat'],groups = [1, 2, 1, 2]) == ['cat', 'bat', 'rat', 'tat']\n assert candidate(words = ['abcde', 'abcdf', 'abcgf', 'abchg', 'abchf'],groups = [1, 2, 3, 4, 3]) == ['abcde', 'abcdf', 'abcgf']\n assert candidate(words = ['abcde', 'abcdf', 'abcef', 'abcag'],groups = [1, 2, 1, 2]) == ['abcde', 'abcdf', 'abcef']\n assert candidate(words = ['apple', 'appla', 'appla', 'applb', 'applc'],groups = [1, 2, 2, 3, 3]) == ['apple', 'appla', 'applb']\n assert candidate(words = ['abc', 'acc', 'bcd', 'bce', 'bde'],groups = [1, 2, 1, 2, 1]) == ['bcd', 'bce', 'bde']\n assert candidate(words = ['start', 'starr', 'statr', 'strat', 'strot'],groups = [1, 2, 1, 2, 1]) == ['start', 'starr', 'statr']\n assert candidate(words = ['abcd', 'abcf', 'abdg', 'abef'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf', 'abef']\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa', 'baaa'],groups = [1, 2, 3, 4, 5]) == ['aaaa', 'aaab']\n assert candidate(words = ['kitten', 'sitten', 'bitten', 'bitter', 'bitter'],groups = [1, 2, 3, 4, 5]) == ['kitten', 'sitten', 'bitten', 'bitter']\n assert candidate(words = ['hello', 'hallo', 'hella', 'hellu'],groups = [1, 2, 1, 2]) == ['hello', 'hallo']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcg', 'abch', 'abcx'],groups = [1, 2, 3, 4, 5, 6]) == ['abcd', 'abce', 'abcf', 'abcg', 'abch', 'abcx']\n assert candidate(words = ['hello', 'hxllo', 'hexlo', 'helxo'],groups = [1, 2, 3, 4]) == ['hello', 'hxllo']\n assert candidate(words = ['aabb', 'abab', 'baba', 'bbaa'],groups = [1, 2, 1, 2]) == ['aabb']\n assert candidate(words = ['apple', 'abble', 'abble', 'abble'],groups = [1, 2, 3, 2]) == ['apple']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcg', 'abch', 'abci'],groups = [1, 2, 3, 4, 5, 6]) == ['abcd', 'abce', 'abcf', 'abcg', 'abch', 'abci']\n assert candidate(words = ['abc', 'abd', 'abe', 'bcd', 'bce'],groups = [1, 1, 2, 2, 3]) == ['abc', 'abe']\n assert candidate(words = ['abcd', 'abcf', 'abcd', 'abcf'],groups = [1, 2, 1, 2]) == ['abcd', 'abcf', 'abcd', 'abcf']\n assert candidate(words = ['abcd', 'abcf', 'abcd', 'abdf'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf', 'abcd']\n assert candidate(words = ['abcd', 'acbd', 'abzd', 'abxc'],groups = [1, 2, 3, 4]) == ['abcd', 'abzd']\n assert candidate(words = ['same', 'same', 'same', 'same'],groups = [1, 2, 3, 4]) == ['same']\n assert candidate(words = ['abc', 'abd', 'acc', 'bcd'],groups = [1, 2, 1, 3]) == ['abc', 'abd']\n assert candidate(words = ['zebra', 'zeara', 'zeraa', 'zerar'],groups = [1, 2, 1, 2]) == ['zebra', 'zeara']\n assert candidate(words = ['abcd', 'abdc', 'acdb', 'adcb', 'bacd', 'bcad', 'bdac', 'bdca'],groups = [1, 2, 1, 2, 1, 2, 1, 2]) == ['abcd']\n assert candidate(words = ['apple', 'apply', 'spoke', 'slope'],groups = [1, 2, 3, 4]) == ['apple', 'apply']\n assert candidate(words = ['abcd', 'abcf', 'abdc', 'abcf'],groups = [1, 2, 1, 2]) == ['abcd', 'abcf']\n assert candidate(words = ['hello', 'hallo', 'hullo', 'hella', 'hillo'],groups = [1, 2, 1, 2, 1]) == ['hello', 'hallo', 'hullo']\n assert candidate(words = ['hello', 'hallo', 'hella', 'hell'],groups = [1, 2, 1, 2]) == ['hello', 'hallo']\n assert candidate(words = ['test', 'tset', 'sett', 'stet'],groups = [1, 2, 1, 2]) == ['test']\n assert candidate(words = ['word', 'worm', 'wore', 'core', 'cord', 'cred'],groups = [1, 2, 1, 2, 1, 2]) == ['word', 'worm', 'wore', 'core', 'cord']\n assert candidate(words = ['zebra', 'zera', 'zeraa', 'zeara'],groups = [1, 2, 1, 2]) == ['zebra', 'zeara']\n assert candidate(words = ['zebra', 'zebra', 'zebra', 'zebra'],groups = [1, 2, 1, 2]) == ['zebra']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abca'],groups = [1, 2, 3, 4]) == ['abcd', 'abce', 'abcf', 'abca']\n assert candidate(words = ['dog', 'dig', 'dug', 'dot'],groups = [1, 2, 1, 2]) == ['dog', 'dig', 'dug']\n assert candidate(words = ['abcd', 'abcf', 'abde', 'abdc'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf']\n assert candidate(words = ['hello', 'hallo', 'hella', 'hellu'],groups = [1, 2, 1, 3]) == ['hello', 'hallo']\n assert candidate(words = ['abcd', 'abcf', 'abdg', 'abeg'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf']\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd', 'ace', 'bce', 'abe', 'bde', 'cde', 'abc'],groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == ['abc', 'abd', 'acd', 'bcd', 'bce', 'bde', 'cde']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],groups = [1, 2, 3, 4, 5]) == ['one']\n assert candidate(words = ['word', 'wird', 'wurd', 'wurd', 'wurk'],groups = [1, 2, 1, 2, 3]) == ['word', 'wird', 'wurd', 'wurk']\n assert candidate(words = ['same', 'sane', 'sane', 'sane', 'same'],groups = [1, 2, 2, 3, 3]) == ['same', 'sane', 'same']\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abc'],groups = [1, 2, 1, 2, 1, 2, 1]) == ['abc']\n assert candidate(words = ['abcd', 'abcf', 'abde', 'abce', 'abcd'],groups = [1, 2, 3, 4, 1]) == ['abcd', 'abcf', 'abce', 'abcd']\n assert candidate(words = ['xyza', 'xyzb', 'xyzc', 'xyzd'],groups = [1, 2, 3, 4]) == ['xyza', 'xyzb', 'xyzc', 'xyzd']\n assert candidate(words = ['abc', 'acd', 'bcd', 'bed'],groups = [1, 2, 1, 2]) == ['acd', 'bcd', 'bed']\n assert candidate(words = ['zebra', 'zera', 'zeraa', 'zerab', 'zercb'],groups = [1, 2, 1, 2, 1]) == ['zeraa', 'zerab', 'zercb']\n assert candidate(words = ['code', 'kode', 'coke', 'cide'],groups = [1, 2, 1, 2]) == ['code', 'kode']\n assert candidate(words = ['abc', 'abd', 'bcd', 'bce'],groups = [1, 2, 1, 2]) == ['abc', 'abd']\n assert candidate(words = ['word', 'worm', 'worn', 'word'],groups = [1, 2, 1, 2]) == ['word', 'worm', 'worn', 'word']\n assert candidate(words = ['python', 'phyton', 'phthon', 'pyhton'],groups = [1, 2, 1, 2]) == ['python']\n assert candidate(words = ['hello', 'hallo', 'hillo', 'hella', 'hellb'],groups = [1, 2, 2, 3, 3]) == ['hello', 'hallo']\n assert candidate(words = ['test', 'tast', 'tost', 'test'],groups = [1, 2, 3, 4]) == ['test', 'tast', 'tost', 'test']\n assert candidate(words = ['abc', 'aabb', 'abbb', 'babb', 'bbcc'],groups = [1, 2, 2, 3, 3]) == ['aabb', 'babb']\n assert candidate(words = ['abcd', 'abcf', 'abdf', 'acdf'],groups = [1, 2, 3, 1]) == ['abcd', 'abcf', 'abdf', 'acdf']\n assert candidate(words = ['hello', 'hallo', 'hullo', 'hella'],groups = [1, 2, 3, 4]) == ['hello', 'hallo', 'hullo']\n assert candidate(words = ['aaaa', 'aaab', 'aabb', 'abbb'],groups = [1, 1, 2, 2]) == ['aaab', 'aabb']\n assert candidate(words = ['abcd', 'abdd', 'acdd', 'acdd', 'acde', 'acdf'],groups = [1, 2, 3, 1, 2, 3]) == ['abcd', 'abdd', 'acdd', 'acde', 'acdf']\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno'],groups = [1, 1, 1, 1, 1]) == ['abc']\n assert candidate(words = ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa'],groups = [1, 2, 3, 4, 5, 6]) == ['aabb']\n assert candidate(words = ['hello', 'hallo', 'hillo', 'hollo'],groups = [1, 1, 2, 2]) == ['hello', 'hillo']\n assert candidate(words = ['aabb', 'aacc', 'aadd', 'aabb', 'aacc'],groups = [1, 2, 3, 1, 2]) == ['aabb']\n assert candidate(words = ['abcd', 'abcf', 'acdf', 'bcdf'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf']\n assert candidate(words = ['one', 'two', 'thr', 'fou', 'fiv'],groups = [1, 2, 1, 2, 1]) == ['one']\n assert candidate(words = ['apple', 'appla', 'applb', 'applc', 'appld'],groups = [1, 2, 2, 2, 3]) == ['apple', 'appla', 'appld']\n assert candidate(words = ['graph', 'grapf', 'graph', 'grapt', 'grapt'],groups = [1, 2, 3, 2, 1]) == ['graph', 'grapf', 'graph', 'grapt']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcd'],groups = [1, 2, 1, 2]) == ['abcd', 'abce', 'abcf', 'abcd']\n assert candidate(words = ['aaab', 'abab', 'abba', 'baaa'],groups = [1, 2, 3, 4]) == ['aaab', 'abab']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hexlo', 'hexxo'],groups = [1, 2, 2, 3, 3]) == ['hello', 'hallo']\n assert candidate(words = ['abc', 'bcd', 'bce', 'bde', 'bdf'],groups = [1, 2, 2, 3, 4]) == ['bce', 'bde', 'bdf']\n assert candidate(words = ['abcd', 'abcf', 'abde', 'abce'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf', 'abce']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcg', 'abch'],groups = [1, 2, 3, 4, 5]) == ['abcd', 'abce', 'abcf', 'abcg', 'abch']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abdg', 'abdh'],groups = [1, 2, 3, 4, 5]) == ['abcd', 'abce', 'abcf']\n assert candidate(words = ['abc', 'abd', 'abe', 'ace', 'adf', 'aeg'],groups = [1, 2, 1, 2, 1, 2]) == ['abc', 'abd', 'abe', 'ace']\n assert candidate(words = ['cat', 'bat', 'rat', 'mat'],groups = [1, 2, 1, 2]) == ['cat', 'bat', 'rat', 'mat']\n assert candidate(words = ['apple', 'apble', 'appla', 'applb', 'applc'],groups = [1, 2, 3, 2, 1]) == ['apple', 'appla', 'applb', 'applc']\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa'],groups = [1, 2, 1, 2]) == ['aaaa', 'aaab']\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abci', 'abcj'],groups = [1, 2, 3, 4, 5]) == ['abcd', 'abce', 'abcf', 'abci', 'abcj']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hexlo', 'hexxo'],groups = [1, 2, 3, 4, 5]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['cat', 'bat', 'rat', 'cap', 'car'],groups = [1, 2, 3, 4, 5]) == ['cat', 'bat', 'rat']\n assert candidate(words = ['aaaa', 'abaa', 'acaa', 'aada'],groups = [1, 1, 2, 2]) == ['aaaa', 'acaa']\n assert candidate(words = ['apple', 'abble', 'abble', 'abble', 'abble'],groups = [1, 2, 1, 2, 1]) == ['apple']\n assert candidate(words = ['zzzz', 'zzzw', 'zzzx', 'zzzy'],groups = [1, 2, 3, 4]) == ['zzzz', 'zzzw', 'zzzx', 'zzzy']\n assert candidate(words = ['abcd', 'abcc', 'abcb', 'abca'],groups = [1, 2, 1, 2]) == ['abcd', 'abcc', 'abcb', 'abca']\n assert candidate(words = ['aaaa', 'abaa', 'acaa', 'adab', 'adac'],groups = [1, 2, 3, 1, 2]) == ['aaaa', 'abaa', 'acaa']\n assert candidate(words = ['xylo', 'xyxo', 'xyxo', 'xylo', 'xylo'],groups = [1, 2, 3, 2, 1]) == ['xylo', 'xyxo', 'xylo']\n assert candidate(words = ['aaaa', 'aaba', 'abaa', 'abba', 'acaa', 'acba'],groups = [1, 2, 1, 2, 1, 2]) == ['aaaa', 'aaba']\n assert candidate(words = ['abcd', 'abdc', 'acdb', 'adcb'],groups = [1, 2, 1, 2]) == ['abcd']\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa', 'aaaa'],groups = [1, 2, 1, 2, 1]) == ['aaaa', 'aaab', 'aaaa']\n assert candidate(words = ['hello', 'hallo', 'hillo', 'hillo'],groups = [1, 2, 1, 3]) == ['hello', 'hallo', 'hillo']\n assert candidate(words = ['abcde', 'abxde', 'abxde', 'abcye'],groups = [1, 2, 2, 3]) == ['abcde', 'abxde']\n assert candidate(words = ['aaaa', 'abaa', 'acaa', 'aada', 'aada', 'aadd', 'aadd', 'aade'],groups = [1, 2, 1, 2, 3, 3, 4, 4]) == ['aaaa', 'aada', 'aadd', 'aade']\n assert candidate(words = ['apple', 'appla', 'abble', 'abble'],groups = [1, 2, 3, 2]) == ['apple', 'appla']\n assert candidate(words = ['hello', 'hallo', 'hullo', 'hellu'],groups = [1, 2, 1, 2]) == ['hello', 'hallo', 'hullo']\n assert candidate(words = ['test', 'tast', 'tost', 'test', 'tast', 'tost', 'test'],groups = [1, 2, 1, 2, 1, 2, 1]) == ['test', 'tast', 'tost', 'test', 'tast', 'tost', 'test']\n assert candidate(words = ['zzzz', 'zzzy', 'zzzx', 'zzxw'],groups = [1, 2, 1, 2]) == ['zzzz', 'zzzy', 'zzzx']\n assert candidate(words = ['apple', 'apply', 'appla', 'applu'],groups = [1, 2, 3, 4]) == ['apple', 'apply', 'appla', 'applu']\n assert candidate(words = ['word', 'ward', 'wird', 'wrod', 'wore', 'core'],groups = [1, 2, 1, 2, 1, 2]) == ['word', 'ward', 'wird']\n assert candidate(words = ['word', 'worm', 'womb', 'womb'],groups = [1, 2, 1, 3]) == ['word', 'worm']\n assert candidate(words = ['dog', 'dot', 'lot', 'log', 'cog'],groups = [1, 2, 2, 3, 4]) == ['dog', 'log', 'cog']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hellp'],groups = [1, 2, 3, 4]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['same', 'sane', 'sane', 'same'],groups = [1, 2, 3, 4]) == ['same', 'sane', 'same']\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd'],groups = [1, 2, 1, 2]) == ['abc', 'abd', 'acd', 'bcd']\n assert candidate(words = ['one', 'two', 'three'],groups = [1, 2, 1]) == ['one']\n assert candidate(words = ['abc', 'abd', 'acc', 'bcd'],groups = [1, 1, 2, 2]) == ['abc', 'acc']\n assert candidate(words = ['abc', 'abd', 'abc', 'abe'],groups = [1, 2, 3, 4]) == ['abc', 'abd', 'abc', 'abe']\n assert candidate(words = ['hello', 'hallo', 'hullo', 'hellu'],groups = [1, 1, 2, 2]) == ['hello', 'hullo']\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl'],groups = [1, 1, 1, 1]) == ['abc']\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa', 'abab', 'abba', 'bbaa', 'bbab', 'bbba', 'bbbb'],groups = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == ['aaaa']\n assert candidate(words = ['abc', 'abd', 'bcd', 'ace'],groups = [1, 2, 1, 2]) == ['abc', 'abd']\n assert candidate(words = ['loop', 'loap', 'leep', 'leap'],groups = [1, 2, 3, 4]) == ['loop', 'loap', 'leap']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hexlo'],groups = [1, 2, 1, 2]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['word', 'ward', 'wear', 'ware'],groups = [1, 2, 3, 2]) == ['word', 'ward']\n assert candidate(words = ['aaa', 'aab', 'aac', 'aba', 'abb'],groups = [1, 2, 3, 4, 5]) == ['aaa', 'aab', 'aac']\n assert candidate(words = ['fun', 'sun', 'tun', 'fum'],groups = [1, 2, 3, 4]) == ['fun', 'sun', 'tun']\n assert candidate(words = ['abcd', 'abcf', 'abdc'],groups = [1, 2, 1]) == ['abcd', 'abcf']\n assert candidate(words = ['test', 'tast', 'tist', 'best'],groups = [1, 2, 3, 1]) == ['test', 'tast', 'tist']\n assert candidate(words = ['cat', 'bat', 'rat', 'car'],groups = [1, 2, 1, 2]) == ['cat', 'bat', 'rat']\n assert candidate(words = ['test', 'text', 'tast', 'tect'],groups = [1, 2, 1, 2]) == ['test', 'text']\n assert candidate(words = ['apple', 'appla', 'applb', 'applc'],groups = [3, 3, 4, 4]) == ['apple', 'applb']\n assert candidate(words = ['zero', 'hero', 'hero', 'hero'],groups = [1, 2, 1, 2]) == ['zero', 'hero']\n assert candidate(words = ['cat', 'bat', 'rat', 'car'],groups = [1, 2, 3, 4]) == ['cat', 'bat', 'rat']\n assert candidate(words = ['abcd', 'abcf', 'abgd'],groups = [1, 2, 1]) == ['abcd', 'abcf']\n assert candidate(words = ['word', 'work', 'worm', 'worn'],groups = [1, 2, 1, 2]) == ['word', 'work', 'worm', 'worn']\n assert candidate(words = ['word', 'wird', 'word', 'wird'],groups = [1, 2, 3, 4]) == ['word', 'wird', 'word', 'wird']\n assert candidate(words = ['zebra', 'zebra', 'zebra'],groups = [1, 2, 1]) == ['zebra']\n assert candidate(words = ['hello', 'hallo', 'hella'],groups = [1, 2, 3]) == ['hello', 'hallo']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hexlo'],groups = [1, 1, 2, 2]) == ['hello', 'hxllo']\n assert candidate(words = ['hello', 'hallo', 'hxllo'],groups = [1, 1, 2]) == ['hello', 'hxllo']\n assert candidate(words = ['dog', 'dot', 'lot', 'log'],groups = [1, 2, 3, 4]) == ['dog', 'dot', 'lot', 'log']\n assert candidate(words = ['test', 'text', 'tast', 'tuxt'],groups = [1, 1, 2, 2]) == ['test', 'tast']\n assert candidate(words = ['star', 'tart', 'kart', 'tars'],groups = [1, 2, 3, 4]) == ['tart', 'kart']\n assert candidate(words = ['tiny', 'tint', 'tint', 'tank'],groups = [1, 2, 1, 2]) == ['tiny', 'tint']\n assert candidate(words = ['aaa', 'aab', 'aac', 'aba', 'aca', 'baa', 'bab', 'bac', 'caa', 'cab', 'cac'],groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == ['aaa', 'aab', 'aac', 'bac', 'cac']\n assert candidate(words = ['apple', 'appla', 'applu', 'appli'],groups = [1, 2, 1, 2]) == ['apple', 'appla', 'applu', 'appli']\n assert candidate(words = ['java', 'lava', 'slava', 'flava'],groups = [1, 2, 3, 4]) == ['java', 'lava']\n assert candidate(words = ['same', 'sane', 'tame', 'game'],groups = [1, 2, 1, 2]) == ['same', 'sane']\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],groups = [1, 2, 3, 4, 5]) == ['a']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hellp'],groups = [1, 1, 2, 2]) == ['hello', 'hxllo']\n assert candidate(words = ['word', 'wird', 'word', 'wird'],groups = [1, 2, 2, 3]) == ['word', 'wird']\n assert candidate(words = ['zzz', 'zyz', 'zxy', 'zyx'],groups = [1, 2, 3, 4]) == ['zzz', 'zyz', 'zyx']\n assert candidate(words = ['xyz', 'xyx', 'yzz', 'zzy'],groups = [3, 2, 3, 2]) == ['xyz', 'xyx']\n assert candidate(words = ['test', 'text', 'tset', 'best'],groups = [1, 2, 3, 4]) == ['test', 'text']\n assert candidate(words = ['apple', 'appla', 'applb', 'applc'],groups = [1, 2, 3, 4]) == ['apple', 'appla', 'applb', 'applc']\n assert candidate(words = ['abc', 'def', 'ghi'],groups = [1, 2, 3]) == ['abc']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'pxllo'],groups = [1, 2, 1, 2]) == ['hello', 'hallo', 'hxllo', 'pxllo']\n assert candidate(words = ['code', 'kode', 'kode'],groups = [1, 2, 1]) == ['code', 'kode']\n assert candidate(words = ['hello', 'hallo', 'hullo', 'hellp'],groups = [1, 2, 1, 2]) == ['hello', 'hallo', 'hullo']\n assert candidate(words = ['test', 'tast', 'west', 'lest'],groups = [1, 2, 1, 2]) == ['test', 'tast']\n assert candidate(words = ['cat', 'bat', 'rat', 'car'],groups = [1, 1, 2, 2]) == ['cat', 'rat']\n assert candidate(words = ['abc', 'abd', 'acc', 'bcd'],groups = [1, 2, 1, 2]) == ['abc', 'abd']\n assert candidate(words = ['abc', 'bcd', 'cde', 'dec'],groups = [1, 2, 3, 4]) == ['abc']\n assert candidate(words = ['test', 'tast', 'fest', 'best'],groups = [1, 2, 1, 2]) == ['test', 'tast']\n assert candidate(words = ['aaa', 'aab', 'aba', 'baa', 'bbb'],groups = [1, 2, 3, 2, 1]) == ['aaa', 'aab']\n assert candidate(words = ['hello', 'hallo', 'hellp', 'herlo'],groups = [1, 1, 2, 2]) == ['hello', 'hellp']\n assert candidate(words = ['test', 'tast', 'tist'],groups = [1, 2, 3]) == ['test', 'tast', 'tist']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [1, 1, 1, 1]) == ['one']\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa'],groups = [1, 2, 3, 4]) == ['aaaa', 'aaab']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [1, 1, 2, 2]) == ['one']\n assert candidate(words = ['hello', 'hallo', 'hella'],groups = [1, 2, 1]) == ['hello', 'hallo']\n assert candidate(words = ['test', 'tast', 'tist', 'teat'],groups = [1, 2, 1, 2]) == ['test', 'tast', 'tist']\n assert candidate(words = ['test', 'tast', 'tast'],groups = [1, 2, 1]) == ['test', 'tast']\n assert candidate(words = ['abc', 'abd', 'acc'],groups = [1, 2, 1]) == ['abc', 'abd']\n assert candidate(words = ['abc', 'abd', 'acc', 'acd'],groups = [1, 2, 3, 4]) == ['abc', 'abd', 'acd']\n assert candidate(words = ['abc', 'abcd', 'abce'],groups = [1, 2, 3]) == ['abcd', 'abce']\n assert candidate(words = ['apple', 'apble', 'aagle', 'apgle', 'applu'],groups = [1, 2, 1, 2, 1]) == ['apple', 'apble']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hell'],groups = [1, 2, 1, 2]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['hello', 'hallo', 'hella', 'hellu'],groups = [1, 2, 2, 3]) == ['hello', 'hella', 'hellu']\n assert candidate(words = ['same', 'sane', 'sane', 'same'],groups = [1, 2, 1, 2]) == ['same', 'sane']\n assert candidate(words = ['apple', 'appla', 'applb', 'applc'],groups = [1, 2, 1, 2]) == ['apple', 'appla', 'applb', 'applc']\n assert candidate(words = ['code', 'cide', 'codi', 'coie'],groups = [1, 1, 2, 2]) == ['code', 'codi']\n assert candidate(words = ['hello', 'hallo', 'hxllo'],groups = [1, 2, 1]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['zoom', 'boom', 'boon', 'boom'],groups = [1, 2, 1, 3]) == ['zoom', 'boom', 'boon', 'boom']\n assert candidate(words = ['abcd', 'abcf', 'abef', 'abeg'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf', 'abef', 'abeg']\n assert candidate(words = ['keep', 'peek', 'peel'],groups = [1, 2, 1]) == ['peek', 'peel']\n assert candidate(words = ['word', 'worm', 'worn'],groups = [1, 2, 3]) == ['word', 'worm', 'worn']\n assert candidate(words = ['apple', 'appla', 'applb', 'applc'],groups = [1, 2, 2, 3]) == ['apple', 'appla', 'applc']\n assert candidate(words = ['aaa', 'aab', 'aac', 'aad'],groups = [1, 2, 1, 2]) == ['aaa', 'aab', 'aac', 'aad']\n assert candidate(words = ['abc', 'bcd', 'cde', 'def'],groups = [1, 1, 2, 3]) == ['abc']\n assert candidate(words = ['aaa', 'aab', 'aac'],groups = [1, 2, 3]) == ['aaa', 'aab', 'aac']\n assert candidate(words = ['test', 'tast', 'tist', 'tast'],groups = [1, 2, 3, 1]) == ['test', 'tast', 'tist', 'tast']\n assert candidate(words = ['test', 'tast', 'tekt'],groups = [1, 2, 3]) == ['test', 'tast']\n assert candidate(words = ['abcd', 'abce', 'abcf'],groups = [1, 2, 3]) == ['abcd', 'abce', 'abcf']\n assert candidate(words = ['word', 'wore', 'word', 'worn'],groups = [1, 2, 3, 4]) == ['word', 'wore', 'word', 'worn']\n assert candidate(words = ['one', 'two', 'thr'],groups = [1, 1, 1]) == ['one']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'hellp'],groups = [1, 2, 1, 2]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['code', 'coed', 'cdeo'],groups = [2, 2, 3]) == ['code']\n assert candidate(words = ['loop', 'lopo', 'leep'],groups = [1, 2, 1]) == ['loop']\n assert candidate(words = ['same', 'sane', 'safe'],groups = [1, 1, 2]) == ['same', 'safe']\n assert candidate(words = ['apple', 'apply', 'spoil', 'spied'],groups = [1, 1, 2, 2]) == ['apple']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'pxllo'],groups = [1, 2, 3, 4]) == ['hello', 'hallo', 'hxllo', 'pxllo']\n assert candidate(words = ['test', 'text', 'tast', 'tast'],groups = [1, 2, 1, 3]) == ['test', 'text']\n assert candidate(words = ['abcd', 'abcf', 'abdf', 'abef'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf', 'abdf', 'abef']\n assert candidate(words = ['one', 'two', 'ton', 'oen'],groups = [1, 1, 2, 2]) == ['one']\n assert candidate(words = ['word', 'wird', 'word', 'wond'],groups = [1, 1, 2, 2]) == ['wird', 'word']\n assert candidate(words = ['test', 'tast', 'ttst'],groups = [1, 2, 3]) == ['test', 'tast', 'ttst']\n assert candidate(words = ['aaa', 'aab', 'aac'],groups = [1, 2, 1]) == ['aaa', 'aab', 'aac']\n assert candidate(words = ['dog', 'dot', 'lot', 'log'],groups = [1, 2, 1, 2]) == ['dog', 'dot', 'lot', 'log']\n assert candidate(words = ['test', 'tast', 'teat'],groups = [1, 2, 3]) == ['test', 'tast']\n assert candidate(words = ['same', 'sane', 'same', 'sane'],groups = [1, 2, 1, 2]) == ['same', 'sane', 'same', 'sane']\n assert candidate(words = ['apple', 'bpple', 'cppld'],groups = [1, 2, 1]) == ['apple', 'bpple']\n assert candidate(words = ['xyz', 'xyx', 'xzx', 'xxz'],groups = [1, 1, 1, 1]) == ['xyz']\n assert candidate(words = ['apple', 'appla', 'bpple', 'appea'],groups = [1, 2, 3, 4]) == ['apple', 'appla', 'appea']\n assert candidate(words = ['apple', 'appla', 'applp'],groups = [1, 2, 1]) == ['apple', 'appla', 'applp']\n assert candidate(words = ['abcd', 'abcf', 'abce', 'abdc'],groups = [1, 1, 2, 1]) == ['abcd', 'abce']\n assert candidate(words = ['same', 'sane', 'sale', 'tale'],groups = [1, 2, 3, 4]) == ['same', 'sane', 'sale', 'tale']\n assert candidate(words = ['test', 'tast', 'tost', 'fest'],groups = [1, 2, 3, 4]) == ['test', 'tast', 'tost']\n assert candidate(words = ['cat', 'bat', 'rat', 'hat'],groups = [1, 1, 2, 2]) == ['cat', 'rat']\n assert candidate(words = ['one', 'two', 'three', 'four'],groups = [1, 2, 3, 4]) == ['one']\n assert candidate(words = ['hello', 'hallo', 'hxllo', 'pxllo'],groups = [1, 2, 2, 3]) == ['hello', 'hxllo', 'pxllo']\n assert candidate(words = ['same', 'sane', 'sane', 'same'],groups = [1, 2, 2, 3]) == ['same', 'sane', 'same']\n assert candidate(words = ['apple', 'appla', 'applu', 'applp'],groups = [1, 1, 2, 2]) == ['apple', 'applu']\n assert candidate(words = ['same', 'sane', 'safe', 'same'],groups = [1, 2, 3, 1]) == ['same', 'sane', 'safe', 'same']\n assert candidate(words = ['xyz', 'xyw', 'xzz', 'xyx'],groups = [1, 2, 1, 2]) == ['xyz', 'xyw']\n assert candidate(words = ['cat', 'dog', 'bat'],groups = [1, 2, 3]) == ['cat', 'bat']\n assert candidate(words = ['word', 'ward', 'cord', 'card'],groups = [1, 2, 3, 4]) == ['word', 'ward', 'card']\n assert candidate(words = ['same', 'sane', 'sake'],groups = [1, 2, 1]) == ['same', 'sane', 'sake']\n assert candidate(words = ['abc', 'abd', 'acc', 'aba'],groups = [1, 2, 3, 2]) == ['abc', 'abd']\n assert candidate(words = ['apple', 'appla', 'abble', 'abble'],groups = [1, 2, 2, 3]) == ['apple', 'appla']\n assert candidate(words = ['test', 'text', 'tast'],groups = [1, 2, 1]) == ['test', 'text']\n assert candidate(words = ['abcd', 'abcf', 'abdf'],groups = [1, 1, 2]) == ['abcf', 'abdf']\n assert candidate(words = ['word', 'worm', 'wirm', 'wirt'],groups = [1, 2, 1, 3]) == ['word', 'worm', 'wirm', 'wirt']\n assert candidate(words = ['code', 'kode', 'cide', 'coke'],groups = [1, 2, 3, 4]) == ['code', 'kode']\n assert candidate(words = ['word', 'worm', 'worn'],groups = [1, 2, 1]) == ['word', 'worm', 'worn']\n assert candidate(words = ['xyz', 'xyw', 'xzz', 'xyy'],groups = [2, 3, 2, 3]) == ['xyz', 'xyw']\n assert candidate(words = ['xyz', 'xyx', 'xyy', 'xyw'],groups = [1, 2, 3, 4]) == ['xyz', 'xyx', 'xyy', 'xyw']\n assert candidate(words = ['same', 'sane', 'tame', 'game'],groups = [1, 2, 3, 4]) == ['same', 'tame', 'game']\n assert candidate(words = ['tree', 'trex', 'trey', 'gree'],groups = [1, 2, 1, 2]) == ['tree', 'trex', 'trey']\n assert candidate(words = ['abc', 'bcd', 'cde', 'def'],groups = [1, 1, 2, 2]) == ['abc']\n assert candidate(words = ['test', 'tets', 'tast', 'tast'],groups = [1, 2, 2, 3]) == ['test', 'tast']\n assert candidate(words = ['abcd', 'abcf', 'abdg'],groups = [1, 2, 3]) == ['abcd', 'abcf']\n assert candidate(words = ['hello', 'hallo', 'hullo'],groups = [1, 2, 1]) == ['hello', 'hallo', 'hullo']\n assert candidate(words = ['abc', 'bcd', 'cde'],groups = [1, 1, 2]) == ['abc']\n assert candidate(words = ['same', 'sane', 'game', 'tame'],groups = [1, 2, 1, 2]) == ['same', 'sane']\n assert candidate(words = ['test', 'tast', 'teat', 'teet'],groups = [1, 2, 3, 4]) == ['test', 'teat', 'teet']\n assert candidate(words = ['abc', 'abd', 'acc'],groups = [1, 2, 3]) == ['abc', 'abd']\n assert candidate(words = ['code', 'cide', 'kode', 'coda'],groups = [1, 2, 1, 2]) == ['code', 'cide']\n assert candidate(words = ['same', 'sane', 'game'],groups = [1, 1, 2]) == ['same', 'game']\n assert candidate(words = ['abc', 'abd', 'acc', 'bcd'],groups = [1, 2, 3, 4]) == ['abc', 'abd']\n assert candidate(words = ['hello', 'hallo', 'hullo', 'hellp'],groups = [1, 2, 1, 3]) == ['hello', 'hallo', 'hullo']\n assert candidate(words = ['play', 'plby', 'plya', 'plax'],groups = [1, 1, 2, 2]) == ['play', 'plax']\n assert candidate(words = ['test', 'tast', 'tost', 'tett'],groups = [1, 2, 1, 2]) == ['test', 'tast', 'tost']\n assert candidate(words = ['same', 'sane', 'sage', 'page'],groups = [1, 1, 2, 2]) == ['same', 'sage']\n assert candidate(words = ['test', 'tast', 'tell', 'tall'],groups = [1, 2, 3, 4]) == ['test', 'tast']\n assert candidate(words = ['same', 'sane', 'sale', 'male'],groups = [1, 2, 3, 4]) == ['same', 'sane', 'sale', 'male']\n assert candidate(words = ['abcd', 'abcf', 'abdf', 'acdf'],groups = [1, 2, 3, 4]) == ['abcd', 'abcf', 'abdf', 'acdf']\n assert candidate(words = ['apple', 'apply', 'spork'],groups = [1, 2, 1]) == ['apple', 'apply']\n assert candidate(words = ['test', 'text', 'tast', 'best'],groups = [1, 2, 1, 3]) == ['test', 'text']\n assert candidate(words = ['hello', 'hallo', 'hxllo'],groups = [1, 2, 3]) == ['hello', 'hallo', 'hxllo']\n assert candidate(words = ['abc', 'abd', 'bcd', 'bce'],groups = [1, 2, 2, 3]) == ['abc', 'abd']\n assert candidate(words = ['one', 'two', 'three'],groups = [1, 2, 3]) == ['one']\n assert candidate(words = ['same', 'sane', 'safe', 'sale'],groups = [1, 2, 1, 2]) == ['same', 'sane', 'safe', 'sale']\n assert candidate(words = ['dog', 'cog', 'rog'],groups = [1, 2, 3]) == ['dog', 'cog', 'rog']\n assert candidate(words = ['five', 'fife', 'five', 'five'],groups = [1, 2, 1, 2]) == ['five', 'fife', 'five']\n assert candidate(words = ['abc', 'bcd', 'cde', 'efg'],groups = [1, 1, 2, 2]) == ['abc']\n assert candidate(words = ['aaa', 'aab', 'aba', 'abb', 'baa', 'bab', 'bba', 'bbb'],groups = [1, 2, 3, 4, 5, 6, 7, 8]) == ['aaa', 'aab', 'abb', 'bbb']\n assert candidate(words = ['zzz', 'zzy', 'zyy', 'yyy'],groups = [1, 2, 1, 2]) == ['zzz', 'zzy', 'zyy', 'yyy']\n assert candidate(words = ['word', 'worm', 'worn', 'word'],groups = [1, 2, 1, 3]) == ['word', 'worm', 'worn', 'word']\n assert candidate(words = ['code', 'mode', 'mroe'],groups = [1, 2, 1]) == ['code', 'mode']\n assert candidate(words = ['word', 'worm', 'worn'],groups = [1, 1, 2]) == ['word', 'worn']\n assert candidate(words = ['apple', 'apply', 'appla'],groups = [1, 1, 2]) == ['apple', 'appla']\n assert candidate(words = ['cat', 'bat', 'rat', 'hat'],groups = [1, 2, 3, 4]) == ['cat', 'bat', 'rat', 'hat']\n assert candidate(words = ['abc', 'bcd', 'cde'],groups = [1, 1, 1]) == ['abc']\n assert candidate(words = ['cat', 'bat', 'rat', 'hat'],groups = [1, 1, 1, 2]) == ['cat', 'hat']\n assert candidate(words = ['word', 'wird', 'wordy'],groups = [1, 2, 3]) == ['word', 'wird']\n", "comparison": "exact"}, "public_tests": ["[\"bab\",\"dab\",\"cab\"]\n[1,2,2]", "[\"a\",\"b\",\"c\",\"d\"]\n[1,2,3,4]"], "hints": ["Let dp[i] represent the length of the longest subsequence ending with words[i] that satisfies the conditions.", "dp[i] = (maximum value of dp[j]) + 1 for indices j < i, where groups[i] != groups[j], words[i] and words[j] are equal in length, and the hamming distance between words[i] and words[j] is exactly 1.", "Keep track of the j values used to achieve the maximum dp[i] for each index i.", "The expected array's length is max(dp[0:n]), and starting from the index having the maximum value in dp, we can trace backward to get the words."], "metadata": {"canonical_parameter_names": ["words", "groups"], "leetcode_dataset_entry_point": "Solution().getWordsInLongestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:26+00:00", "tests_total": 310, "tests_dropped": 4, "flags": ["multiple_answers"], "topic_tags": ["array", "string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def get_words_in_longest_subsequence(words, groups)", "container": null, "callable": "get_words_in_longest_subsequence", "parameters": [{"name": "words", "type": "String[]"}, {"name": "groups", "type": "Integer[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2902, "task_id": "count-of-sub-multisets-with-bounded-sum", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array nums of non-negative integers, and two integers l and r.\n\nReturn the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].\n\nSince the answer may be large, return it modulo 10^9+ 7.\n\nA sub-multiset is an unordered collection of elements of the array in which a given value x can occur 0, 1, ..., occ[x] times, where occ[x] is the number of occurrences of x in the array.\n\nNote that:\n\n- Two sub-multisets are the same if sorting both sub-multisets results in identical multisets.\n- The sum of an empty multiset is 0.\n\nExample 1:\n\nInput: nums = [1,2,2,3], l = 6, r = 6\nOutput: 1\nExplanation: The only subset of nums that has a sum of 6 is {1, 2, 3}.\n\nExample 2:\n\nInput: nums = [2,1,4,2,7], l = 1, r = 5\nOutput: 7\nExplanation: The subsets of nums that have a sum within the range [1, 5] are {1}, {2}, {4}, {2, 2}, {1, 2}, {1, 4}, and {1, 2, 2}.\n\nExample 3:\n\nInput: nums = [1,2,1,3,5,2], l = 3, r = 5\nOutput: 9\nExplanation: The subsets of nums that have a sum within the range [3, 5] are {3}, {5}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {1, 1, 2}, {1, 1, 3}, and {1, 2, 2}.\n\nConstraints:\n\n- 1 <= nums.length <= 2 * 10^4\n- 0 <= nums[i] <= 2 * 10^4\n- Sum of nums does not exceed 2 * 10^4.\n- 0 <= l <= r <= 2 * 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3],l = 6,r = 6) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],l = 15,r = 100) == 23\n assert candidate(nums = [10, 20, 30, 40, 50],l = 15,r = 75) == 14\n assert candidate(nums = [10, 20, 30, 40, 50],l = 15,r = 60) == 11\n assert candidate(nums = [1, 2, 1, 3, 5, 2],l = 3,r = 5) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],l = 5,r = 5) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],l = 1,r = 5) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],l = 5,r = 10) == 18\n assert candidate(nums = [0, 0, 0],l = 0,r = 0) == 4\n assert candidate(nums = [2, 1, 4, 2, 7],l = 1,r = 5) == 7\n assert candidate(nums = [0, 0, 0, 0],l = 0,r = 0) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],l = 20,r = 30) == 104\n assert candidate(nums = [20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000],l = 10000,r = 20000) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],l = 5,r = 10) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],l = 10,r = 20) == 219\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],l = 25,r = 75) == 11\n assert candidate(nums = [1, 2, 3, 4, 5],l = 0,r = 15) == 32\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],l = 10,r = 20) == 247\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],l = 10,r = 40) == 11085\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],l = 100,r = 500) == 455555\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],l = 200,r = 500) == 796\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],l = 200,r = 400) == 704\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],l = 100,r = 1000) == 19\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5],l = 5,r = 15) == 169\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],l = 150,r = 300) == 531\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],l = 400,r = 600) == 12610\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],l = 5,r = 25) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],l = 50,r = 150) == 982553\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],l = 10,r = 50) == 23142\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],l = 0,r = 5) == 6\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],l = 5,r = 15) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],l = 20,r = 30) == 3\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1],l = 4,r = 9) == 33\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],l = 15,r = 25) == 11\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],l = 2500,r = 4500) == 597\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],l = 250,r = 500) == 436865\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],l = 5,r = 15) == 119\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],l = 100,r = 400) == 192776\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],l = 20,r = 40) == 3\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],l = 15,r = 30) == 839\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],l = 20,r = 30) == 1254\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],l = 10,r = 20) == 11\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],l = 150,r = 400) == 826\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],l = 5,r = 15) == 205\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],l = 10,r = 20) == 316\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],l = 2000,r = 4000) == 2001\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20],l = 20,r = 60) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],l = 150,r = 450) == 892\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],l = 15,r = 50) == 918\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],l = 10,r = 30) == 1480\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],l = 20,r = 50) == 614\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],l = 10,r = 30) == 5\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],l = 20,r = 50) == 269\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],l = 20,r = 100) == 455555\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],l = 30,r = 100) == 3571\n assert candidate(nums = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500],l = 2500,r = 5000) == 6\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],l = 150,r = 300) == 4992\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],l = 100,r = 200) == 77629\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],l = 5000,r = 10000) == 6\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],l = 5000,r = 10000) == 23274\n assert candidate(nums = [10000],l = 10000,r = 10000) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],l = 20,r = 50) == 269\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],l = 1500,r = 3500) == 704\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],l = 500,r = 1000) == 501\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],l = 30,r = 100) == 865\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],l = 50,r = 100) == 20215\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],l = 20,r = 50) == 473\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],l = 30,r = 50) == 218\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],l = 50,r = 100) == 9146\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],l = 5,r = 8) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],l = 1500,r = 4500) == 892\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],l = 1000,r = 6000) == 50984\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],l = 5,r = 10) == 6\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],l = 10,r = 20) == 64\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],l = 30,r = 70) == 1093\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],l = 1000,r = 3000) == 597\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],l = 100,r = 500) == 984\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],l = 15,r = 30) == 531\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],l = 70,r = 280) == 892\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],l = 50,r = 100) == 51\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],l = 15,r = 35) == 704\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],l = 100,r = 200) == 86894\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],l = 10,r = 30) == 597\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],l = 30,r = 150) == 620\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],l = 10,r = 20) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],l = 5,r = 15) == 11\n", "comparison": "exact"}, "public_tests": ["[1,2,2,3]\n6\n6", "[2,1,4,2,7]\n1\n5", "[1,2,1,3,5,2]\n3\n5"], "hints": ["Since the sum of numsis at most 20000, the number of distinct elements of nums is 200.", "Let dp[x] be the number of submultisets of nums with sum x.", "The answer to the problem is dp[l] + dp[l+1] + … + dp[r].", "Use coin change dp to transition between states."], "metadata": {"canonical_parameter_names": ["nums", "l", "r"], "leetcode_dataset_entry_point": "Solution().countSubMultisets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:28+00:00", "tests_total": 89, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming", "sliding-window", "knapsack-problem", "multiple-knapsack"]}, "language": "ruby", "interface": {"raw_signature": "def count_sub_multisets(nums, l, r)", "container": null, "callable": "count_sub_multisets", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "l", "type": "Integer"}, {"name": "r", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2903, "task_id": "find-indices-with-index-and-value-difference-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n\nYour task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n\n- abs(i - j) >= indexDifference, and\n- abs(nums[i] - nums[j]) >= valueDifference\n\nReturn an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nNote: i and j may be equal.\n\nExample 1:\n\nInput: nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\nOutput: [0,3]\nExplanation: In this example, i = 0 and j = 3 can be selected.\nabs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\nHence, a valid answer is [0,3].\n[3,0] is also a valid answer.\n\nExample 2:\n\nInput: nums = [2,1], indexDifference = 0, valueDifference = 0\nOutput: [0,0]\nExplanation: In this example, i = 0 and j = 0 can be selected.\nabs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\nHence, a valid answer is [0,0].\nOther valid answers are [0,1], [1,0], and [1,1].\n\nExample 3:\n\nInput: nums = [1,2,3], indexDifference = 2, valueDifference = 4\nOutput: [-1,-1]\nExplanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\nHence, [-1,-1] is returned.\n\nConstraints:\n\n- 1 <= n == nums.length <= 100\n- 0 <= nums[i] <= 50\n- 0 <= indexDifference <= 100\n- 0 <= valueDifference <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9],indexDifference = 2,valueDifference = 6) == [0, 3]\n assert candidate(nums = [0, 0, 0, 0, 0],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference = 1,valueDifference = 25) == [0, 3]\n assert candidate(nums = [0, 0, 0, 0],indexDifference = 3,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [0, 0, 0, 0],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [10, 5, 15, 20, 25],indexDifference = 2,valueDifference = 10) == [1, 3]\n assert candidate(nums = [4, 2, 3, 1, 5],indexDifference = 1,valueDifference = 2) == [0, 1]\n assert candidate(nums = [1, 3, 5, 7, 9],indexDifference = 3,valueDifference = 4) == [0, 3]\n assert candidate(nums = [45, 46, 47, 48, 49, 50],indexDifference = 2,valueDifference = 5) == [0, 5]\n assert candidate(nums = [4, 2, 3, 4, 5],indexDifference = 1,valueDifference = 2) == [0, 1]\n assert candidate(nums = [50, 40, 30, 20, 10],indexDifference = 2,valueDifference = 15) == [0, 2]\n assert candidate(nums = [1, 2, 3],indexDifference = 2,valueDifference = 4) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 5,valueDifference = 5) == [0, 5]\n assert candidate(nums = [2, 1],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [50, 40, 30, 20, 10],indexDifference = 2,valueDifference = 30) == [0, 3]\n assert candidate(nums = [3, 5, 7, 9, 11],indexDifference = 1,valueDifference = 2) == [0, 1]\n assert candidate(nums = [5, 5, 5, 5, 5],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [3, 3, 3, 3, 3],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference = 3,valueDifference = 15) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference = 3,valueDifference = 20) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference = 2,valueDifference = 25) == [0, 3]\n assert candidate(nums = [50, 40, 30, 20, 10],indexDifference = 2,valueDifference = 25) == [0, 3]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],indexDifference = 3,valueDifference = 6) == [0, 3]\n assert candidate(nums = [5, 1, 4, 1],indexDifference = 2,valueDifference = 4) == [0, 3]\n assert candidate(nums = [9, 7, 5, 3, 1],indexDifference = 2,valueDifference = 6) == [0, 3]\n assert candidate(nums = [8, 8, 8, 8, 8, 8],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [9, 7, 5, 3, 1],indexDifference = 3,valueDifference = 4) == [0, 3]\n assert candidate(nums = [4, 2, 3, 4, 1],indexDifference = 1,valueDifference = 2) == [0, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 5,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],indexDifference = 3,valueDifference = 5) == [0, 5]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],indexDifference = 3,valueDifference = 6) == [0, 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],indexDifference = 10,valueDifference = 10) == [0, 10]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],indexDifference = 5,valueDifference = 15) == [0, 5]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10],indexDifference = 2,valueDifference = 4) == [2, 4]\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11],indexDifference = 5,valueDifference = 10) == [0, 10]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 5,valueDifference = 5) == [0, 5]\n assert candidate(nums = [10, 10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 30, 40, 40],indexDifference = 2,valueDifference = 10) == [0, 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],indexDifference = 5,valueDifference = 10) == [0, 10]\n assert candidate(nums = [9, 7, 5, 3, 1, 3, 5, 7, 9, 11],indexDifference = 6,valueDifference = 6) == [3, 9]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31],indexDifference = 10,valueDifference = 5) == [0, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1],indexDifference = 2,valueDifference = 2) == [0, 2]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [0, 10, 20, 30, 40, 50, 40, 30, 20, 10, 0],indexDifference = 3,valueDifference = 20) == [0, 3]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],indexDifference = 1,valueDifference = 8) == [0, 1]\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, 0],indexDifference = 12,valueDifference = 10) == [0, 12]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],indexDifference = 3,valueDifference = 25) == [0, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 6,valueDifference = 7) == [0, 7]\n assert candidate(nums = [0, 50, 0, 50, 0, 50, 0, 50, 0, 50],indexDifference = 1,valueDifference = 50) == [0, 1]\n assert candidate(nums = [50, 25, 0, 25, 50, 25, 0, 25, 50, 25, 0],indexDifference = 5,valueDifference = 30) == [0, 6]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 1,valueDifference = 0) == [0, 1]\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50],indexDifference = 4,valueDifference = 25) == [0, 4]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],indexDifference = 2,valueDifference = 8) == [0, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 8,valueDifference = 7) == [0, 8]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],indexDifference = 1,valueDifference = 1) == [0, 2]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],indexDifference = 8,valueDifference = 15) == [0, 8]\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],indexDifference = 15,valueDifference = 15) == [0, 15]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 1,valueDifference = 1) == [-1, -1]\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],indexDifference = 10,valueDifference = 15) == [0, 15]\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49],indexDifference = 7,valueDifference = 20) == [0, 7]\n assert candidate(nums = [8, 6, 4, 2, 0, 2, 4, 6, 8, 10],indexDifference = 4,valueDifference = 6) == [0, 4]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10],indexDifference = 3,valueDifference = 9) == [0, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 8,valueDifference = 3) == [0, 8]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],indexDifference = 7,valueDifference = 16) == [0, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 9,valueDifference = 9) == [0, 9]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],indexDifference = 6,valueDifference = 10) == [-1, -1]\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],indexDifference = 15,valueDifference = 15) == [0, 15]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],indexDifference = 4,valueDifference = 8) == [0, 4]\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50],indexDifference = 3,valueDifference = 20) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5],indexDifference = 4,valueDifference = 25) == [0, 4]\n assert candidate(nums = [42, 24, 35, 16, 27, 38, 49, 10, 21, 32],indexDifference = 5,valueDifference = 15) == [1, 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],indexDifference = 10,valueDifference = 10) == [0, 10]\n assert candidate(nums = [45, 35, 25, 15, 5, 0, 5, 15, 25, 35, 45],indexDifference = 6,valueDifference = 20) == [0, 6]\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5],indexDifference = 3,valueDifference = 2) == [0, 3]\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],indexDifference = 10,valueDifference = 10) == [0, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],indexDifference = 7,valueDifference = 10) == [0, 10]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],indexDifference = 9,valueDifference = 45) == [0, 9]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 2,valueDifference = 0) == [0, 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],indexDifference = 8,valueDifference = 10) == [0, 10]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],indexDifference = 10,valueDifference = 5) == [0, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],indexDifference = 5,valueDifference = 10) == [0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 30,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50],indexDifference = 5,valueDifference = 30) == [0, 5]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],indexDifference = 3,valueDifference = 3) == [0, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 5,valueDifference = 5) == [0, 5]\n assert candidate(nums = [45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33],indexDifference = 6,valueDifference = 5) == [0, 6]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4],indexDifference = 3,valueDifference = 1) == [0, 3]\n", "comparison": "exact"}, "public_tests": ["[5,1,4,1]\n2\n4", "[2,1]\n0\n0", "[1,2,3]\n2\n4"], "hints": ["Use bruteforce.", "You can use a nested loop to compare each pair of indices (i, j) and check if the conditions are satisfied."], "metadata": {"canonical_parameter_names": ["nums", "indexDifference", "valueDifference"], "leetcode_dataset_entry_point": "Solution().findIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:31+00:00", "tests_total": 137, "tests_dropped": 45, "flags": ["multiple_answers"], "topic_tags": ["array", "two-pointers"]}, "language": "ruby", "interface": {"raw_signature": "def find_indices(nums, index_difference, value_difference)", "container": null, "callable": "find_indices", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "index_difference", "type": "Integer"}, {"name": "value_difference", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2904, "task_id": "shortest-and-lexicographically-smallest-beautiful-string", "difficulty": "Medium", "problem_description": "You are given a binary string s and a positive integer k.\n\nA substring of s is beautiful if the number of 1's in it is exactly k.\n\nLet len be the length of the shortest beautiful substring.\n\nReturn the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful substring, return an empty string.\n\nA string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n\n- For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n\nExample 1:\n\nInput: s = \"100011001\", k = 3\nOutput: \"11001\"\nExplanation: There are 7 beautiful substrings in this example:\n1. The substring \"100011001\".\n2. The substring \"100011001\".\n3. The substring \"100011001\".\n4. The substring \"100011001\".\n5. The substring \"100011001\".\n6. The substring \"100011001\".\n7. The substring \"100011001\".\nThe length of the shortest beautiful substring is 5.\nThe lexicographically smallest beautiful substring with length 5 is the substring \"11001\".\n\nExample 2:\n\nInput: s = \"1011\", k = 2\nOutput: \"11\"\nExplanation: There are 3 beautiful substrings in this example:\n1. The substring \"1011\".\n2. The substring \"1011\".\n3. The substring \"1011\".\nThe length of the shortest beautiful substring is 2.\nThe lexicographically smallest beautiful substring with length 2 is the substring \"11\".\n\nExample 3:\n\nInput: s = \"000\", k = 1\nOutput: \"\"\nExplanation: There are no beautiful substrings in this example.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- 1 <= k <= s.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1100110011001100110011001100\",k = 6) == \"1100110011\"\n assert candidate(s = \"100011001\",k = 3) == \"11001\"\n assert candidate(s = \"1010101010\",k = 5) == \"101010101\"\n assert candidate(s = \"1111111111\",k = 5) == \"11111\"\n assert candidate(s = \"100100100\",k = 3) == \"1001001\"\n assert candidate(s = \"000\",k = 1) == \"\"\n assert candidate(s = \"111010101\",k = 2) == \"11\"\n assert candidate(s = \"0000000000\",k = 1) == \"\"\n assert candidate(s = \"111000\",k = 2) == \"11\"\n assert candidate(s = \"1001001001\",k = 4) == \"1001001001\"\n assert candidate(s = \"1111\",k = 2) == \"11\"\n assert candidate(s = \"0101010101010101010101010101\",k = 5) == \"101010101\"\n assert candidate(s = \"11001100110011001100\",k = 5) == \"100110011\"\n assert candidate(s = \"010101\",k = 3) == \"10101\"\n assert candidate(s = \"1010101\",k = 4) == \"1010101\"\n assert candidate(s = \"1011\",k = 2) == \"11\"\n assert candidate(s = \"10101010101010101010\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\",k = 12) == \"10101010101010101010101\"\n assert candidate(s = \"101010101010101010101010101010101010101010101010\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"110110110110110110110110110110\",k = 5) == \"1011011\"\n assert candidate(s = \"00000000000000000000000000000000\",k = 5) == \"\"\n assert candidate(s = \"1001001001001001001001001001001\",k = 5) == \"1001001001001\"\n assert candidate(s = \"1010101010101010101010101010101010101010\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"00000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"1111000011110000111100001111000011110000111100001111000011110000\",k = 8) == \"111100001111\"\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111111111111111111\",k = 15) == \"111111111111111\"\n assert candidate(s = \"01001001001001001001001001001001001001001001001001001001001001001001\",k = 8) == \"1001001001001001001001\"\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101\",k = 12) == \"10101010101010101010101\"\n assert candidate(s = \"111000111000111000\",k = 3) == \"111\"\n assert candidate(s = \"1100011000110001100011000110001100011000\",k = 6) == \"110001100011\"\n assert candidate(s = \"101010101010101010101010101010101010101010101010\",k = 9) == \"10101010101010101\"\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111\",k = 50) == \"11111111111111111111111111111111111111111111111111\"\n assert candidate(s = \"010101010101010101010101010101010101010101010101\",k = 5) == \"101010101\"\n assert candidate(s = \"10101010101010101010101010101010\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"111111111111111111111111111111\",k = 10) == \"1111111111\"\n assert candidate(s = \"111000111000111000111000111000111000111000111000\",k = 9) == \"111000111000111\"\n assert candidate(s = \"010101010101010101010101010101010101010101010101\",k = 8) == \"101010101010101\"\n assert candidate(s = \"01010101010101010101010101010101010101010101\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"1001100110011001100110011001100110011001100110011001100110011001100110011001\",k = 6) == \"1100110011\"\n assert candidate(s = \"0101010101010101010101010101\",k = 3) == \"10101\"\n assert candidate(s = \"111000111000111000111000111000111000111\",k = 6) == \"111000111\"\n assert candidate(s = \"01010101010101010101010101010101010101010101010101\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"111000111000111000111000111000111000111000\",k = 11) == \"11000111000111000111\"\n assert candidate(s = \"1101001101001101001101001101\",k = 4) == \"1001101\"\n assert candidate(s = \"111011101110111011101110\",k = 7) == \"101110111\"\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100\",k = 15) == \"10011001100110011001100110011\"\n assert candidate(s = \"00000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"000000000000000000000000000000000000000000000001\",k = 1) == \"1\"\n assert candidate(s = \"0001000100010001000100010001000100010001000100010001\",k = 3) == \"100010001\"\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\",k = 7) == \"1010101010101\"\n assert candidate(s = \"000000000000000000000000000000000000000000000000\",k = 3) == \"\"\n assert candidate(s = \"1110011100011100111000011100000111000000\",k = 6) == \"11100111\"\n assert candidate(s = \"1110000001110000011100000111000001110000011100000111\",k = 6) == \"11100000111\"\n assert candidate(s = \"110011001100110011001100110011001100110011001100110011001100\",k = 11) == \"100110011001100110011\"\n assert candidate(s = \"0000000000000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"110011001100110011001100110011001100\",k = 6) == \"1100110011\"\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010\",k = 13) == \"1010101010101010101010101\"\n assert candidate(s = \"111000111000111000111000111000111000111000\",k = 6) == \"111000111\"\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\",k = 15) == \"10101010101010101010101010101\"\n assert candidate(s = \"0101010101010101010101010101010101010101\",k = 15) == \"10101010101010101010101010101\"\n assert candidate(s = \"10001000100010001000100010001000100010001000\",k = 5) == \"10001000100010001\"\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010101010101\",k = 15) == \"10101010101010101010101010101\"\n assert candidate(s = \"110001100011000110001100011000110001100011000\",k = 5) == \"10001100011\"\n assert candidate(s = \"11000110001100011000110001100011000\",k = 6) == \"110001100011\"\n assert candidate(s = \"010101010101010101010101010101010101010101\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"01010101010101010101010101010101\",k = 5) == \"101010101\"\n assert candidate(s = \"101010101010101010101010101010101010\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"0101010101010101010101010101010101010101\",k = 5) == \"101010101\"\n assert candidate(s = \"111000111000111000111000111\",k = 6) == \"111000111\"\n assert candidate(s = \"111110000000000000000000000000000000000000000000\",k = 5) == \"11111\"\n assert candidate(s = \"1101101101101101101101101101101101101101\",k = 7) == \"1011011011\"\n assert candidate(s = \"11100111001110011100111001110011100111001110011100\",k = 8) == \"110011100111\"\n assert candidate(s = \"10000001000000100000010000001\",k = 3) == \"100000010000001\"\n assert candidate(s = \"11110000111100001111000011110000\",k = 4) == \"1111\"\n assert candidate(s = \"0010010010010010010010010010010010010010\",k = 2) == \"1001\"\n assert candidate(s = \"101010101010101010101010101010101010101010101010\",k = 8) == \"101010101010101\"\n assert candidate(s = \"111110000011111000001111100000111110000011111\",k = 8) == \"1110000011111\"\n assert candidate(s = \"1010101010101010101010101010101010101010\",k = 15) == \"10101010101010101010101010101\"\n assert candidate(s = \"111000111000111000111000\",k = 9) == \"111000111000111\"\n assert candidate(s = \"1000001000001000001000001000001000001000001000001000001000001\",k = 2) == \"1000001\"\n assert candidate(s = \"1000000000000000000000000000000000000001\",k = 1) == \"1\"\n assert candidate(s = \"1110000111000011100001110000\",k = 4) == \"10000111\"\n assert candidate(s = \"10101010101010101010101010101010101010101010\",k = 7) == \"1010101010101\"\n assert candidate(s = \"000100010001000100010001\",k = 2) == \"10001\"\n assert candidate(s = \"1000100010001000100010001\",k = 3) == \"100010001\"\n assert candidate(s = \"1001001001001001001001001001001001001001001001\",k = 5) == \"1001001001001\"\n assert candidate(s = \"0000000000000000000000000000000000000000000000000001\",k = 1) == \"1\"\n assert candidate(s = \"11111000001111100000111110000011111\",k = 5) == \"11111\"\n assert candidate(s = \"0110110110110110110110110110110110110110110110\",k = 4) == \"11011\"\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"11000001110000011100000111000001110000011100000111\",k = 7) == \"10000011100000111\"\n assert candidate(s = \"001001001001001001001001001001001001001\",k = 3) == \"1001001\"\n assert candidate(s = \"11111111111111111111111111111111\",k = 15) == \"111111111111111\"\n assert candidate(s = \"1010101010101010101010101010101010101010101010\",k = 8) == \"101010101010101\"\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"111111111111111111111111111111111111111111111111\",k = 9) == \"111111111\"\n assert candidate(s = \"010101010101010101010101010101010101\",k = 10) == \"1010101010101010101\"\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100\",k = 10) == \"110011001100110011\"\n assert candidate(s = \"100000100000100000100000100000100000100000100000\",k = 3) == \"1000001000001\"\n assert candidate(s = \"100110011001100110011001100110011001100110011001100110011001100110011001\",k = 9) == \"10011001100110011\"\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111000111000111000111000111000\",k = 7) == \"1000111000111\"\n assert candidate(s = \"10101010101010101010\",k = 7) == \"1010101010101\"\n assert candidate(s = \"1111000011110000111100001111\",k = 8) == \"111100001111\"\n assert candidate(s = \"1010101010101010101010101010101010101010\",k = 12) == \"10101010101010101010101\"\n assert candidate(s = \"01010101010101010101\",k = 3) == \"10101\"\n assert candidate(s = \"001001001001001001001001001001001001001001001001\",k = 5) == \"1001001001001\"\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001\",k = 12) == \"1001001001001001001001001001001001\"\n assert candidate(s = \"000000000011111111111111111111111111111111111111111111111111111111111111\",k = 20) == \"11111111111111111111\"\n assert candidate(s = \"110110110110110110110110110110110110110\",k = 7) == \"1011011011\"\n assert candidate(s = \"10101010101010101010\",k = 6) == \"10101010101\"\n assert candidate(s = \"01001001001001001001001001001001001001001001001001001001001001001001001001001001\",k = 4) == \"1001001001\"\n assert candidate(s = \"1001001001001001001001001001001001001001\",k = 12) == \"1001001001001001001001001001001001\"\n assert candidate(s = \"00000000000000000000000000000000000000000000\",k = 1) == \"\"\n assert candidate(s = \"010101010101010101010101010101\",k = 5) == \"101010101\"\n", "comparison": "exact"}, "public_tests": ["\"100011001\"\n3", "\"1011\"\n2", "\"000\"\n1"], "hints": ["Notice that if we consider that index i is the leftmost index of a beautiful substring, it has only one candidate j, such that s[i:j] is beautiful and shortest too.", "We can iterate over all possibilities of leftmost index i take s[i:j] and compare with the shortest and the lexicographically smallest beautiful string we could get before index i."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().shortestBeautifulSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:33+00:00", "tests_total": 119, "tests_dropped": 3, "flags": [], "topic_tags": ["string", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def shortest_beautiful_substring(s, k)", "container": null, "callable": "shortest_beautiful_substring", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2905, "task_id": "find-indices-with-index-and-value-difference-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n\nYour task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n\n- abs(i - j) >= indexDifference, and\n- abs(nums[i] - nums[j]) >= valueDifference\n\nReturn an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nNote: i and j may be equal.\n\nExample 1:\n\nInput: nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\nOutput: [0,3]\nExplanation: In this example, i = 0 and j = 3 can be selected.\nabs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\nHence, a valid answer is [0,3].\n[3,0] is also a valid answer.\n\nExample 2:\n\nInput: nums = [2,1], indexDifference = 0, valueDifference = 0\nOutput: [0,0]\nExplanation: In this example, i = 0 and j = 0 can be selected.\nabs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\nHence, a valid answer is [0,0].\nOther valid answers are [0,1], [1,0], and [1,1].\n\nExample 3:\n\nInput: nums = [1,2,3], indexDifference = 2, valueDifference = 4\nOutput: [-1,-1]\nExplanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\nHence, [-1,-1] is returned.\n\nConstraints:\n\n- 1 <= n == nums.length <= 10^5\n- 0 <= nums[i] <= 10^9\n- 0 <= indexDifference <= 10^5\n- 0 <= valueDifference <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 90, 80, 70, 60],indexDifference = 2,valueDifference = 25) == [0, 3]\n assert candidate(nums = [1, 10, 1, 10, 1, 10],indexDifference = 2,valueDifference = 8) == [0, 3]\n assert candidate(nums = [100, 90, 80, 70, 60, 50],indexDifference = 4,valueDifference = 30) == [0, 4]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference = 1,valueDifference = 15) == [0, 2]\n assert candidate(nums = [10, 20, 30, 40, 50],indexDifference = 2,valueDifference = 20) == [0, 2]\n assert candidate(nums = [1, 5, 3, 6, 7, 8, 2],indexDifference = 3,valueDifference = 4) == [0, 3]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 3,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9],indexDifference = 4,valueDifference = 8) == [0, 4]\n assert candidate(nums = [4, 5, 6, 7, 8, 9],indexDifference = 3,valueDifference = 3) == [0, 3]\n assert candidate(nums = [1, 5, 3, 6, 7, 8, 9],indexDifference = 3,valueDifference = 4) == [0, 3]\n assert candidate(nums = [4, 1, 3, 2],indexDifference = 1,valueDifference = 2) == [0, 1]\n assert candidate(nums = [1, 3, 5, 7, 9],indexDifference = 3,valueDifference = 4) == [0, 3]\n assert candidate(nums = [1, 1, 1, 1, 1, 1],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 2, 3],indexDifference = 2,valueDifference = 4) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 5,valueDifference = 5) == [0, 5]\n assert candidate(nums = [2, 1],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [5, 5, 5, 5],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [9, 7, 5, 3, 1],indexDifference = 4,valueDifference = 8) == [0, 4]\n assert candidate(nums = [9, 7, 5, 3, 1],indexDifference = 3,valueDifference = 6) == [0, 3]\n assert candidate(nums = [1, 1, 1, 1, 1],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [5, 1, 4, 1],indexDifference = 2,valueDifference = 4) == [0, 3]\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6],indexDifference = 3,valueDifference = 2) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],indexDifference = 7,valueDifference = 50) == [0, 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],indexDifference = 10,valueDifference = 10) == [0, 10]\n assert candidate(nums = [500, 400, 300, 200, 100, 0, 100, 200, 300, 400],indexDifference = 5,valueDifference = 200) == [0, 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],indexDifference = 10,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [5, 3, 6, 8, 1, 9, 2, 7, 4, 10],indexDifference = 3,valueDifference = 5) == [1, 5]\n assert candidate(nums = [10, 50, 30, 60, 20, 70, 40, 80, 100, 90],indexDifference = 3,valueDifference = 30) == [0, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1],indexDifference = 2,valueDifference = 2) == [0, 2]\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 8, 7, 10, 9],indexDifference = 2,valueDifference = 2) == [0, 3]\n assert candidate(nums = [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],indexDifference = 15,valueDifference = 30) == [0, 15]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],indexDifference = 6,valueDifference = 400) == [0, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 8,valueDifference = 2) == [0, 8]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 0,valueDifference = 0) == [0, 0]\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350, 500],indexDifference = 2,valueDifference = 250) == [0, 5]\n assert candidate(nums = [1000000000, 900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000],indexDifference = 5,valueDifference = 200000000) == [0, 5]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],indexDifference = 3,valueDifference = 6) == [0, 6]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],indexDifference = 3,valueDifference = 25) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],indexDifference = 6,valueDifference = 40) == [0, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 6,valueDifference = 7) == [0, 7]\n assert candidate(nums = [1000000000, 0, 1000000000, 0, 1000000000, 0],indexDifference = 2,valueDifference = 1000000000) == [0, 3]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],indexDifference = 4,valueDifference = 8) == [0, 4]\n assert candidate(nums = [5, 8, 12, 15, 3, 1, 9, 11, 6, 2, 7, 10],indexDifference = 3,valueDifference = 8) == [0, 3]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],indexDifference = 4,valueDifference = 300) == [0, 4]\n assert candidate(nums = [5, 1, 9, 3, 7, 11, 2, 8, 6, 10],indexDifference = 3,valueDifference = 8) == [1, 5]\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],indexDifference = 1,valueDifference = 1000000000) == [-1, -1]\n assert candidate(nums = [1000000000, 0, 500000000, 250000000, 750000000, 1, 999999999, 2, 999999998, 3],indexDifference = 4,valueDifference = 500000000) == [0, 5]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],indexDifference = 4,valueDifference = 6) == [0, 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],indexDifference = 9,valueDifference = 8) == [0, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],indexDifference = 3,valueDifference = 10) == [0, 5]\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],indexDifference = 3,valueDifference = 6) == [0, 3]\n assert candidate(nums = [10, 100, 10, 100, 10, 100, 10, 100, 10, 100],indexDifference = 5,valueDifference = 80) == [0, 5]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],indexDifference = 6,valueDifference = 8) == [0, 6]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],indexDifference = 4,valueDifference = 20) == [0, 4]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130],indexDifference = 6,valueDifference = 70) == [0, 7]\n assert candidate(nums = [100, 50, 150, 100, 50, 150, 100, 50, 150, 100],indexDifference = 5,valueDifference = 50) == [0, 5]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 6,valueDifference = 5) == [0, 6]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],indexDifference = 4,valueDifference = 5) == [0, 5]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],indexDifference = 4,valueDifference = 30) == [0, 4]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],indexDifference = 7,valueDifference = 300) == [0, 7]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],indexDifference = 8,valueDifference = 7) == [0, 8]\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 0],indexDifference = 2,valueDifference = 4) == [0, 2]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],indexDifference = 2,valueDifference = 2) == [0, 4]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],indexDifference = 10,valueDifference = 10) == [0, 10]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],indexDifference = 3,valueDifference = 400) == [0, 4]\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],indexDifference = 4,valueDifference = 8) == [0, 5]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],indexDifference = 1,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],indexDifference = 8,valueDifference = 12) == [0, 8]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],indexDifference = 0,valueDifference = 90) == [0, 9]\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],indexDifference = 5,valueDifference = 45) == [0, 5]\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],indexDifference = 12,valueDifference = 20) == [0, 12]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],indexDifference = 4,valueDifference = 4) == [0, 4]\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],indexDifference = 1,valueDifference = 999999990) == [0, 1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],indexDifference = 2,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5],indexDifference = 5,valueDifference = 18) == [1, 6]\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3],indexDifference = 2,valueDifference = 1) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],indexDifference = 10,valueDifference = 50) == [0, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],indexDifference = 5,valueDifference = 10) == [0, 5]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],indexDifference = 5,valueDifference = 1000) == [0, 10]\n assert candidate(nums = [100, 200, 101, 201, 102, 202, 103, 203, 104, 204, 105, 205, 106, 206, 107, 207, 108, 208, 109, 209],indexDifference = 3,valueDifference = 100) == [0, 3]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],indexDifference = 3,valueDifference = 45) == [0, 5]\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],indexDifference = 10,valueDifference = 10) == [0, 10]\n assert candidate(nums = [10, 20, 30, 25, 15, 5, 10, 15, 20, 25],indexDifference = 4,valueDifference = 15) == [1, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],indexDifference = 5,valueDifference = 40) == [0, 5]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],indexDifference = 5,valueDifference = 10) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 7,valueDifference = 6) == [0, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],indexDifference = 8,valueDifference = 30) == [0, 8]\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500],indexDifference = 4,valueDifference = 150) == [0, 4]\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],indexDifference = 10,valueDifference = 25) == [0, 10]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993],indexDifference = 4,valueDifference = 5) == [0, 5]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],indexDifference = 5,valueDifference = 25) == [0, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],indexDifference = 10,valueDifference = 0) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],indexDifference = 3,valueDifference = 6) == [0, 6]\n assert candidate(nums = [8, 6, 7, 5, 3, 0, 9],indexDifference = 2,valueDifference = 3) == [0, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],indexDifference = 7,valueDifference = 30) == [0, 7]\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],indexDifference = 2,valueDifference = 9) == [0, 3]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],indexDifference = 1,valueDifference = 1) == [-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],indexDifference = 10,valueDifference = 0) == [0, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],indexDifference = 7,valueDifference = 7) == [0, 7]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],indexDifference = 2,valueDifference = 5) == [0, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 7,valueDifference = 5) == [0, 7]\n assert candidate(nums = [8, 6, 4, 2, 0, 1, 3, 5, 7, 9],indexDifference = 2,valueDifference = 4) == [0, 2]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],indexDifference = 7,valueDifference = 200) == [0, 7]\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],indexDifference = 5,valueDifference = 10) == [0, 5]\n assert candidate(nums = [3, 1, 2, 4, 6, 5, 9, 8, 7, 10],indexDifference = 5,valueDifference = 5) == [1, 6]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],indexDifference = 5,valueDifference = 300) == [0, 5]\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],indexDifference = 12,valueDifference = 12) == [0, 12]\n assert candidate(nums = [9, 3, 7, 1, 8, 5, 6, 2, 4, 10],indexDifference = 4,valueDifference = 7) == [0, 7]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],indexDifference = 5,valueDifference = 4) == [0, 5]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],indexDifference = 5,valueDifference = 25) == [0, 5]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12],indexDifference = 3,valueDifference = 4) == [0, 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],indexDifference = 5,valueDifference = 1) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],indexDifference = 6,valueDifference = 6) == [0, 6]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],indexDifference = 4,valueDifference = 5) == [0, 5]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],indexDifference = 6,valueDifference = 10) == [0, 6]\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],indexDifference = 5,valueDifference = 27) == [0, 5]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],indexDifference = 3,valueDifference = 6) == [0, 3]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],indexDifference = 5,valueDifference = 10) == [0, 5]\n assert candidate(nums = [8, 6, 4, 2, 0, 1, 3, 5, 7, 9],indexDifference = 3,valueDifference = 3) == [0, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],indexDifference = 2,valueDifference = 3) == [0, 3]\n", "comparison": "exact"}, "public_tests": ["[5,1,4,1]\n2\n4", "[2,1]\n0\n0", "[1,2,3]\n2\n4"], "hints": ["For each index i >= indexDifference, keep the indices j_1 and j_2 in the range [0, i - indexDifference] such that nums[j_1] and nums[j_2] are the minimum and maximum values in the index range.", "Check if abs(nums[i] - nums[j_1]) >= valueDifference or abs(nums[i] - nums[j_2]) >= valueDifference.", "j_1 and j_2 can be updated dynamically, or they can be pre-computed since they are just prefix minimum and maximum."], "metadata": {"canonical_parameter_names": ["nums", "indexDifference", "valueDifference"], "leetcode_dataset_entry_point": "Solution().findIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:36+00:00", "tests_total": 126, "tests_dropped": 3, "flags": ["multiple_answers"], "topic_tags": ["array", "two-pointers"]}, "language": "ruby", "interface": {"raw_signature": "def find_indices(nums, index_difference, value_difference)", "container": null, "callable": "find_indices", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "index_difference", "type": "Integer"}, {"name": "value_difference", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2906, "task_id": "construct-product-matrix", "difficulty": "Medium", "problem_description": "Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:\n\n- Each element p[i][j] is calculated as the product of all elements in grid except for the element grid[i][j]. This product is then taken modulo 12345.\n\nReturn the product matrix of grid.\n\nExample 1:\n\nInput: grid = [[1,2],[3,4]]\nOutput: [[24,12],[8,6]]\nExplanation: p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24\np[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12\np[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8\np[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6\nSo the answer is [[24,12],[8,6]].\n\nExample 2:\n\nInput: grid = [[12345],[2],[1]]\nOutput: [[2],[0],[0]]\nExplanation: p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2.\np[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0. So p[0][1] = 0.\np[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0. So p[0][2] = 0.\nSo the answer is [[2],[0],[0]].\n\nConstraints:\n\n- 1 <= n == grid.length <= 10^5\n- 1 <= m == grid[i].length <= 10^5\n- 2 <= n * m <= 10^5\n- 1 <= grid[i][j] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == [[1, 1, 1], [1, 1, 1], [1, 1, 1]]\n assert candidate(grid = [[7], [11], [13]]) == [[143], [91], [77]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]]) == [[720, 360, 240], [180, 144, 120]]\n assert candidate(grid = [[12345], [2], [1]]) == [[2], [0], [0]]\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1]]) == [[1, 1, 1, 1], [1, 1, 1, 1]]\n assert candidate(grid = [[5, 10, 15], [20, 25, 30]]) == [[3210, 1605, 9300], [6975, 5580, 4650]]\n assert candidate(grid = [[5, 6, 7], [8, 9, 10]]) == [[5550, 510, 9255], [6555, 4455, 2775]]\n assert candidate(grid = [[1, 2], [3, 4]]) == [[24, 12], [8, 6]]\n assert candidate(grid = [[5, 10], [15, 20]]) == [[3000, 1500], [1000, 750]]\n assert candidate(grid = [[999999999, 888888888], [777777777, 666666666]]) == [[12126, 4383], [1482, 5844]]\n assert candidate(grid = [[1000000000, 999999999], [888888888, 777777777]]) == [[5844, 7785], [7215, 2955]]\n assert candidate(grid = [[5, 3], [2, 4]]) == [[24, 40], [60, 30]]\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]]\n assert candidate(grid = [[2, 3], [4, 5], [6, 7]]) == [[2520, 1680], [1260, 1008], [840, 720]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == [[11715, 12030, 12135, 6015, 9750, 12240, 12255, 9180, 8160, 4875]]\n assert candidate(grid = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == [[1, 1], [1, 1], [1, 1], [1, 1], [1, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(grid = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == [[11715], [12030], [12135], [6015], [9750], [12240], [12255], [9180], [8160], [4875]]\n assert candidate(grid = [[1000000000, 1], [1, 1000000000]]) == [[5620, 5890], [5890, 5620]]\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == [[11505, 11925, 7950], [12135, 4770, 3975], [12225, 12240, 6765]]\n assert candidate(grid = [[12345, 12345, 12345], [12345, 12345, 12345], [12345, 12345, 12345]]) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[12345, 24690, 37035], [49380, 61725, 74070]]) == [[0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[12344, 12343, 12342], [12341, 12340, 12339], [12338, 12337, 12336]]) == [[4875, 8610, 9855], [4305, 10851, 11100], [2460, 8325, 3285]]\n assert candidate(grid = [[2, 3, 5, 7], [11, 13, 17, 19], [23, 29, 31, 37]]) == [[780, 520, 312, 3750], [9120, 120, 5175, 5280], [3825, 3885, 1245, 3045]]\n assert candidate(grid = [[12345, 67890, 54321], [10101, 20202, 30303], [40404, 50505, 60606]]) == [[10875, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[12345], [24690], [37035], [49380], [61665]]) == [[0], [0], [0], [0], [0]]\n assert candidate(grid = [[12345, 12346, 12347], [12348, 12349, 12350], [12351, 12352, 12353]]) == [[3285, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[2, 3], [5, 7], [11, 13], [17, 19], [23, 29], [31, 37]]) == [[780, 520], [312, 3750], [9120, 120], [5175, 5280], [3825, 3885], [1245, 3045]]\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]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == [[10740, 5370, 7695, 2685, 9555, 10020, 6825, 7515, 2565, 10950], [7710, 5010, 3675, 9585, 11415, 9930, 5715, 7455, 1215, 5475]]\n assert candidate(grid = [[1000000, 2000000, 3000000], [4000000, 5000000, 6000000]]) == [[2145, 7245, 4830], [9795, 10305, 2415]]\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]]) == [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(grid = [[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]]) == [[8280, 4140], [2760, 2070], [4125, 1380], [4710, 1035], [9150, 8235], [1875, 690], [5385, 2355], [5490, 6690], [8475, 4575], [2385, 10290], [5685, 7110], [360, 345], [825, 8865], [11280, 7350], [9225, 2745], [1860, 3345], [4740, 10410], [5880, 8460], [8565, 7365], [5910, 5145], [6525, 9015], [10815, 3555], [1830, 180], [6480, 6345], [4200, 6585]]\n assert candidate(grid = [[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]]) == [[8850, 4425, 7065, 8385, 1770, 9705, 6555, 10365, 2355, 885], [10905, 11025, 2580, 9450, 8820, 11355, 6330, 7350, 2415, 6615], [6300, 11625, 1995, 11685, 10230, 1290, 9015, 4725, 3285, 4410]]\n assert candidate(grid = [[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]]) == [[6570, 3285, 2190, 7815, 11190], [1095, 11520, 10080, 4845, 5595], [11820, 6720, 1455, 5760, 7845], [5040, 2565, 8595, 2295, 8970], [3840, 5910, 7800, 3360, 9645]]\n assert candidate(grid = [[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60]]) == [[4860, 2430, 1620], [1215, 5910, 810], [5985, 6780, 540], [2955, 9420, 405]]\n assert candidate(grid = [[100000, 200000, 300000], [400000, 500000, 600000], [700000, 800000, 900000]]) == [[765, 6555, 255], [9450, 7560, 6300], [5400, 4725, 4200]]\n assert candidate(grid = [[1000000000, 999999999], [888888888, 777777777]]) == [[5844, 7785], [7215, 2955]]\n assert candidate(grid = [[987654321, 876543210, 765432109], [654321098, 543210987, 432109876]]) == [[480, 7659, 5820], [5835, 3135, 12270]]\n assert candidate(grid = [[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]]) == [[8850, 4425, 7065], [8385, 1770, 9705], [6555, 10365, 2355], [885, 10905, 11025], [2580, 9450, 8820], [11355, 6330, 7350], [2415, 6615, 6300], [11625, 1995, 11685], [10230, 1290, 9015], [4725, 3285, 4410]]\n assert candidate(grid = [[1000, 2000, 3000], [4000, 5000, 6000], [7000, 8000, 9000], [10000, 11000, 12000]]) == [[4305, 8325, 5550], [10335, 3330, 2775], [615, 11340, 10080], [1665, 7125, 7560]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == [[3255, 7800, 9315], [3900, 3120, 10830], [465, 1950, 3105], [1560, 4785, 5415]]\n assert candidate(grid = [[12345, 24690, 37035], [49380, 61725, 74070], [86415, 98760, 111105]]) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[12345, 6789, 11111], [22222, 33333, 44444], [55555, 66666, 77777]]) == [[9615, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[123, 456, 789], [101112, 131415, 161718], [192021, 222324, 252627]]) == [[3705, 8715, 8745], [4335, 3591, 4815], [8760, 10170, 8745]]\n assert candidate(grid = [[50000, 50001, 50002], [50003, 50004, 50005], [50006, 50007, 50008], [50009, 50010, 50011], [50012, 50013, 50014]]) == [[3615, 1005, 9240], [9780, 6045, 5265], [7485, 4185, 7815], [3210, 6105, 8130], [8625, 9645, 225]]\n assert candidate(grid = [[99999, 88888], [77777, 66666], [55555, 44444]]) == [[210, 9495], [270, 315], [5316, 6645]]\n assert candidate(grid = [[1000000000, 999999999, 999999998], [999999997, 999999996, 999999995], [999999994, 999999993, 999999992]]) == [[7200, 11670, 6495], [7050, 6150, 4755], [7410, 9195, 4245]]\n assert candidate(grid = [[1000000000, 1000000000], [1000000000, 1000000000]]) == [[4855, 4855], [4855, 4855]]\n assert candidate(grid = [[2, 3, 5], [7, 11, 13], [17, 19, 23], [29, 31, 37]]) == [[780, 520, 312], [3750, 9120, 120], [5175, 5280, 3825], [3885, 1245, 3045]]\n assert candidate(grid = [[2, 3, 5, 7], [11, 13, 17, 19], [23, 29, 31, 37], [41, 43, 47, 53]]) == [[7830, 9335, 5601, 11055], [7035, 255, 195, 11220], [6585, 540, 7275, 11100], [6705, 12135, 7425, 11010]]\n assert candidate(grid = [[12345, 24690, 37035, 49380, 61725, 74070, 86415, 98760, 111105, 123450], [135795, 148140, 160485, 172830, 185175, 197520, 209865, 222210, 234555, 246900]]) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(grid = [[98765, 43210, 24680], [13579, 86420, 97531], [23456, 78901, 65432]]) == [[5845, 11690, 3250], [3275, 5845, 10925], [9070, 11495, 8350]]\n assert candidate(grid = [[12345], [24690], [37035], [49380], [61275]]) == [[0], [0], [0], [0], [0]]\n assert candidate(grid = [[98765, 43210, 11111], [22222, 33333, 55555], [66666, 77777, 88888]]) == [[1740, 3480, 5055], [8700, 9915, 3480], [11130, 9540, 2175]]\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, 3, 5, 7, 9, 11, 13, 15, 17, 19]]) == [[240, 120, 8310, 60, 7455, 4155, 5325, 30, 6885, 9900], [9900, 6885, 30, 5325, 4155, 7455, 60, 8310, 120, 240], [240, 8310, 7455, 5325, 6885, 9000, 8565, 6600, 3645, 6510]]\n assert candidate(grid = [[12345, 6789, 101112], [131415, 161718, 192021]]) == [[6510, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[12345, 6789, 2345], [9876, 5432, 1234]]) == [[0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[12345, 12345, 12345, 12345, 12345], [12345, 12345, 12345, 12345, 12345]]) == [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]\n assert candidate(grid = [[12345, 1, 12345], [1, 12345, 1], [12345, 1, 12345]]) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]) == [[10095, 11220, 11595, 5610, 11895], [11970, 10260, 2805, 7980, 12120], [2040, 5985, 4575, 5130, 12195]]\n assert candidate(grid = [[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]]) == [[366, 366, 366, 366, 366, 366, 366, 366, 366, 366], [183, 183, 183, 183, 183, 183, 183, 183, 183, 183], [8352, 8352, 8352, 8352, 8352, 8352, 8352, 8352, 8352, 8352]]\n assert candidate(grid = [[123, 456, 789], [101, 202, 303], [404, 505, 606], [707, 808, 909]]) == [[6930, 6255, 9060], [7095, 9720, 6480], [4860, 6357, 3240], [11595, 2430, 2160]]\n assert candidate(grid = [[99999, 99998, 99997], [99996, 99995, 99994], [99993, 99992, 99991]]) == [[5010, 8205, 4080], [2685, 5586, 4290], [9660, 8265, 4140]]\n assert candidate(grid = [[12345], [12345], [12345], [12345]]) == [[0], [0], [0], [0]]\n assert candidate(grid = [[2], [3], [5], [7], [11], [13], [17], [19], [23], [29], [31], [37], [41], [43], [47], [53], [59], [61], [67], [71]]) == [[9915], [2495], [11373], [6360], [2925], [2475], [3345], [10140], [9450], [4515], [11790], [11880], [7710], [3045], [9615], [840], [2010], [4575], [1770], [4800]]\n assert candidate(grid = [[2, 3, 5, 7, 11], [13, 17, 19, 23, 29], [31, 37, 41, 43, 47]]) == [[5505, 3670, 2202, 5100, 5490], [5595, 2100, 11625, 10140, 6765], [7125, 4635, 4785, 6285, 9690]]\n assert candidate(grid = [[999999999, 999999998, 999999997], [999999996, 999999995, 999999994], [999999993, 999999992, 999999991]]) == [[8475, 3495, 7500], [2340, 9156, 7095], [6630, 2940, 7200]]\n assert candidate(grid = [[12345, 12344, 12343], [12342, 12341, 12340]]) == [[12225, 0, 0], [0, 0, 0]]\n assert candidate(grid = [[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]]) == [[1530, 765, 510, 6555, 2775], [255, 10800, 9450, 8400, 7560], [7995, 6300, 6765, 5400, 5040], [4725, 90, 4200, 1380, 3780], [3600, 10170, 1140, 3150, 555]]\n assert candidate(grid = [[12345], [1], [2], [3], [4], [5], [6], [7], [8], [9]]) == [[4875], [0], [0], [0], [0], [0], [0], [0], [0], [0]]\n assert candidate(grid = [[100000, 100000, 100000], [100000, 100000, 100000], [100000, 100000, 100000]]) == [[7630, 7630, 7630], [7630, 7630, 7630], [7630, 7630, 7630]]\n assert candidate(grid = [[12345, 12345, 12345, 12345], [12345, 12345, 12345, 12345], [12345, 12345, 12345, 12345]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n assert candidate(grid = [[1000000, 1000001, 1000002], [1000003, 1000004, 1000005], [1000006, 1000007, 1000008]]) == [[1530, 180, 4725], [4005, 10005, 7575], [570, 9720, 4275]]\n assert candidate(grid = [[98765, 43210], [13579, 24680], [111111, 222222]]) == [[900, 1800], [3345, 11895], [750, 375]]\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]]\n assert candidate(grid = [[1000000000, 1000000000, 1000000000], [1000000000, 1000000000, 1000000000]]) == [[4930, 4930, 4930], [4930, 4930, 4930]]\n assert candidate(grid = [[999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]]) == [[4155, 3090, 3240, 4665, 9960, 2670, 11160, 480, 11505, 6360]]\n", "comparison": "exact"}, "public_tests": ["[[1,2],[3,4]]", "[[12345],[2],[1]]"], "hints": ["Try to solve this without using the '/' (division operation).", "Create two 2D arrays for suffix and prefix product, and use them to find the product for each position."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().constructProductMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:38+00:00", "tests_total": 82, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def construct_product_matrix(grid)", "container": null, "callable": "construct_product_matrix", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2908, "task_id": "minimum-sum-of-mountain-triplets-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array nums of integers.\n\nA triplet of indices (i, j, k) is a mountain if:\n\n- i < j < k\n- nums[i] < nums[j] and nums[k] < nums[j]\n\nReturn the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n\nExample 1:\n\nInput: nums = [8,6,1,5,3]\nOutput: 9\nExplanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n- 2 < 3 < 4\n- nums[2] < nums[3] and nums[4] < nums[3]\nAnd the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n\nExample 2:\n\nInput: nums = [5,4,8,7,10,2]\nOutput: 13\nExplanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n- 1 < 3 < 5\n- nums[1] < nums[3] and nums[5] < nums[3]\nAnd the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n\nExample 3:\n\nInput: nums = [6,5,4,3,4,5]\nOutput: -1\nExplanation: It can be shown that there are no mountain triplets in nums.\n\nConstraints:\n\n- 3 <= nums.length <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 8, 7, 10, 2]) == 13\n assert candidate(nums = [1, 5, 3, 6, 4, 7, 2]) == 6\n assert candidate(nums = [10, 20, 15, 30, 25, 40]) == 45\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == -1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 6\n assert candidate(nums = [4, 3, 2, 1, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [1, 3, 1, 3, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [1, 3, 2, 1, 2, 3]) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2]) == 4\n assert candidate(nums = [2, 1, 3, 4, 3, 2, 1]) == 4\n assert candidate(nums = [3, 1, 4, 2, 5]) == 7\n assert candidate(nums = [6, 5, 4, 3, 4, 5]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8]) == 6\n assert candidate(nums = [1, 5, 3, 5, 1]) == 5\n assert candidate(nums = [7, 1, 3, 2, 4, 6, 5]) == 6\n assert candidate(nums = [8, 6, 1, 5, 3]) == 9\n assert candidate(nums = [3, 2, 1, 4, 5, 3, 2, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 8, 7, 6, 5, 4, 3, 2]) == 6\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 40, 35, 45]) == 30\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]) == 4\n assert candidate(nums = [7, 8, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15]) == 13\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 4\n assert candidate(nums = [42, 21, 31, 41, 10, 20, 30, 50, 15, 25, 35, 45, 5, 1, 6, 11, 16, 26, 36, 46]) == 26\n assert candidate(nums = [8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 26\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8, 12, 9, 13, 10, 14]) == 8\n assert candidate(nums = [2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 4\n assert candidate(nums = [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 = [50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == -1\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [5, 3, 1, 2, 4, 6, 7, 8, 10, 9]) == 20\n assert candidate(nums = [30, 25, 20, 15, 10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == -1\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 6\n assert candidate(nums = [2, 1, 3, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 8\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3]) == 4\n assert candidate(nums = [8, 1, 5, 10, 3, 12, 7, 9]) == 9\n assert candidate(nums = [2, 3, 1, 4, 5, 3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\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]) == -1\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 45, 50]) == 30\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 50]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 50]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 5]) == 12\n assert candidate(nums = [47, 45, 43, 41, 39, 40, 42, 44, 46, 48, 50, 49, 47, 45, 43]) == 126\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15]) == 12\n assert candidate(nums = [2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1]) == 5\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10]) == 12\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]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 4\n assert candidate(nums = [15, 10, 12, 11, 13, 9, 14, 8, 16, 7, 17, 6, 18, 5, 19, 4, 20, 3, 21, 2]) == 23\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]) == -1\n assert candidate(nums = [50, 1, 50, 2, 50, 3, 50, 4, 50, 5, 50, 6, 50, 7, 50]) == 53\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19]) == 70\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == -1\n assert candidate(nums = [30, 10, 20, 15, 25, 5, 35, 5, 10, 40]) == 30\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, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11]) == 14\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 4\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\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 40, 35]) == 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, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9, 10]) == 6\n assert candidate(nums = [10, 20, 15, 25, 5, 30, 22, 18, 17, 28]) == 30\n assert candidate(nums = [2, 5, 3, 8, 6, 4, 9, 7, 10, 1]) == 6\n assert candidate(nums = [4, 5, 1, 6, 2, 7, 3, 8, 9, 10, 11]) == 9\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 12\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\n assert candidate(nums = [20, 15, 10, 5, 6, 7, 8, 12, 11, 16]) == 28\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12]) == -1\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == -1\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 4\n assert candidate(nums = [4, 3, 2, 1, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [10, 20, 30, 40, 35, 25, 15, 10, 20, 30, 40, 35, 25, 15]) == 35\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -1\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]) == 4\n assert candidate(nums = [50, 1, 50, 1, 50, 1, 50, 1, 50, 1]) == 52\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 6\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 6\n assert candidate(nums = [10, 20, 30, 25, 15, 5, 25, 30, 10]) == 30\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, 9, 8]) == 18\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 13\n assert candidate(nums = [25, 20, 15, 30, 25, 20, 35, 30, 25, 40, 35, 30, 45, 40, 35]) == 60\n assert candidate(nums = [5, 3, 8, 6, 7, 4, 9, 2, 10, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 8\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\n assert candidate(nums = [20, 15, 10, 25, 30, 5, 40, 45, 50]) == 40\n assert candidate(nums = [9, 1, 2, 3, 8, 5, 6, 4, 7]) == 10\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == -1\n assert candidate(nums = [10, 20, 5, 15, 25, 10, 30, 5, 40]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 5, 3, 4, 2, 6, 8, 7, 9, 10, 1, 2, 3, 4, 5]) == 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]) == 4\n assert candidate(nums = [25, 20, 15, 10, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == -1\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5]) == 8\n assert candidate(nums = [2, 1, 3, 4, 3, 5, 6, 5, 7, 8, 7, 9, 10]) == 8\n assert candidate(nums = [10, 20, 15, 25, 5, 30, 10]) == 30\n assert candidate(nums = [10, 20, 30, 25, 15, 27, 17, 28, 18, 29, 9, 19, 21, 22, 23]) == 34\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5]) == 8\n assert candidate(nums = [3, 2, 1, 4, 3, 2, 5, 4, 3, 6, 5, 4, 7, 6, 5, 8, 7, 6, 9, 8, 7, 10, 9, 8]) == 6\n assert candidate(nums = [3, 5, 1, 4, 2, 6, 7, 8, 9, 10, 11, 12, 13]) == 7\n assert candidate(nums = [2, 1, 3, 4, 3, 2, 4, 3, 2, 1, 3, 4, 3, 2, 4, 3, 2, 1, 3, 4, 3, 2]) == 4\n assert candidate(nums = [30, 25, 20, 15, 10, 5, 10, 15, 20, 25, 30]) == -1\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(nums = [8, 1, 9, 3, 7, 5, 11, 2, 13, 4]) == 6\n assert candidate(nums = [30, 20, 10, 25, 15, 35, 40, 45, 50]) == 50\n", "comparison": "exact"}, "public_tests": ["[8,6,1,5,3]", "[5,4,8,7,10,2]", "[6,5,4,3,4,5]"], "hints": ["Bruteforce over all possible triplets."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:42+00:00", "tests_total": 118, "tests_dropped": 6, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_sum(nums)", "container": null, "callable": "minimum_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2909, "task_id": "minimum-sum-of-mountain-triplets-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums of integers.\n\nA triplet of indices (i, j, k) is a mountain if:\n\n- i < j < k\n- nums[i] < nums[j] and nums[k] < nums[j]\n\nReturn the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n\nExample 1:\n\nInput: nums = [8,6,1,5,3]\nOutput: 9\nExplanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n- 2 < 3 < 4\n- nums[2] < nums[3] and nums[4] < nums[3]\nAnd the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n\nExample 2:\n\nInput: nums = [5,4,8,7,10,2]\nOutput: 13\nExplanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n- 1 < 3 < 5\n- nums[1] < nums[3] and nums[5] < nums[3]\nAnd the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n\nExample 3:\n\nInput: nums = [6,5,4,3,4,5]\nOutput: -1\nExplanation: It can be shown that there are no mountain triplets in nums.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 1, 3, 1, 4, 1, 3, 1]) == 5\n assert candidate(nums = [100000000, 1, 100000000, 2, 100000000]) == 100000003\n assert candidate(nums = [5, 4, 8, 7, 10, 2]) == 13\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 3, 1, 4, 1, 5, 1, 6, 1]) == 5\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 6\n assert candidate(nums = [1, 100000000, 2, 99999999, 3, 99999998]) == 100000003\n assert candidate(nums = [1, 3, 1, 3, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [10, 20, 30, 15, 25, 35, 40, 10]) == 35\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == -1\n assert candidate(nums = [6, 5, 4, 3, 4, 5]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3]) == -1\n assert candidate(nums = [1, 5, 3, 7, 6, 8]) == 9\n assert candidate(nums = [8, 6, 1, 5, 3]) == 9\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1]) == 5\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]) == 4\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 4\n assert candidate(nums = [8, 1, 2, 3, 4, 5, 6, 7, 8]) == -1\n assert candidate(nums = [2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8]) == 6\n assert candidate(nums = [5, 1, 3, 7, 2, 6, 4, 8, 9]) == 6\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == 31\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 103\n assert candidate(nums = [15, 10, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == -1\n assert candidate(nums = [5, 10, 15, 10, 5, 20, 25, 20, 15, 10, 5]) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 11, 12, 13, 14, 15]) == -1\n assert candidate(nums = [8, 6, 1, 5, 3, 7, 2, 4, 9, 10, 11]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [7, 7, 7, 8, 7, 7, 7]) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == -1\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == -1\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 12\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 102\n assert candidate(nums = [3, 5, 1, 8, 4, 7, 6, 9, 2, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 7\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 7\n assert candidate(nums = [5, 1, 4, 3, 7, 6, 8]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == -1\n assert candidate(nums = [7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5]) == 20\n assert candidate(nums = [8, 1, 5, 6, 3, 2, 4, 7]) == 6\n assert candidate(nums = [8, 1, 5, 3, 7, 2, 6, 4, 9]) == 6\n assert candidate(nums = [8, 6, 1, 5, 3, 7, 2, 10, 4, 9, 11, 13, 12]) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 5, 1, 4, 1, 3, 1, 2, 1]) == 4\n assert candidate(nums = [100, 101, 99, 102, 98, 103, 97, 104, 96]) == 297\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\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]) == 4\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 103\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15]) == 7\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 21]) == -1\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5]) == 103\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [1, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100, 2, 100]) == 103\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10]) == 22\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 7, 8, 9, 10, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 4\n assert candidate(nums = [9, 8, 7, 6, 5, 10, 15, 20, 25, 1, 2, 3, 4, 5]) == 16\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 6\n assert candidate(nums = [100, 200, 150, 250, 100, 300, 50, 400, 250, 500, 200, 450, 300, 550, 600, 525, 475, 650, 700, 625]) == 300\n assert candidate(nums = [5, 1, 3, 7, 2, 6, 4, 8]) == 6\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 13\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6, 7, 8, 9]) == 10\n assert candidate(nums = [10, 20, 10, 30, 5, 40, 25, 50, 15]) == 35\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 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]) == 4\n assert candidate(nums = [10, 20, 5, 15, 10, 25, 5]) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12]) == -1\n assert candidate(nums = [1, 5, 3, 7, 2, 6, 4, 8]) == 6\n assert candidate(nums = [7, 1, 3, 5, 9, 6, 8, 2, 4]) == 6\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 500, 400, 300, 200, 100]) == 400\n assert candidate(nums = [100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [2, 3, 1, 4, 6, 5, 8, 7, 9, 10, 11, 12]) == 6\n assert candidate(nums = [8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13]) == 12\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == 13\n assert candidate(nums = [10, 20, 15, 25, 10, 30, 5, 40, 25, 50]) == 30\n assert candidate(nums = [2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1, 11, 12, 13, 14, 15]) == -1\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [7, 1, 5, 3, 6, 4, 2, 8, 10, 1, 12]) == 4\n", "comparison": "exact"}, "public_tests": ["[8,6,1,5,3]", "[5,4,8,7,10,2]", "[6,5,4,3,4,5]"], "hints": ["If you fix index j, i will be the smallest integer to the left of j, and k the largest integer to the right of j.", "To find i and k, preprocess the prefix minimum array prefix_min[i] = min(nums[0], nums[1], ..., nums[i]), and the suffix minimum array suffix_min[i] = min(nums[i], nums[i + 1], ..., nums[i - 1])."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:45+00:00", "tests_total": 110, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_sum(nums)", "container": null, "callable": "minimum_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2911, "task_id": "minimum-changes-to-make-k-semi-palindromes", "difficulty": "Hard", "problem_description": "Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized.\n\nReturn the minimum number of letter changes required.\n\nA semi-palindrome is a special type of string that can be divided into palindromes based on a repeating pattern. To check if a string is a semi-palindrome:\n\n1. Choose a positive divisor d of the string's length. d can range from 1 up to, but not including, the string's length. For a string of length 1, it does not have a valid divisor as per this definition, since the only divisor is its length, which is not allowed.\n2. For a given divisor d, divide the string into groups where each group contains characters from the string that follow a repeating pattern of length d. Specifically, the first group consists of characters at positions 1, 1 + d, 1 + 2d, and so on; the second group includes characters at positions 2, 2 + d, 2 + 2d, etc.\n3. The string is considered a semi-palindrome if each of these groups forms a palindrome.\n\nConsider the string \"abcabc\":\n\n- The length of \"abcabc\" is 6. Valid divisors are 1, 2, and 3.\n- For d = 1: The entire string \"abcabc\" forms one group. Not a palindrome.\n- For d = 2:\n - Group 1 (positions 1, 3, 5): \"acb\"\n - Group 2 (positions 2, 4, 6): \"bac\"\n - Neither group forms a palindrome.\n- For d = 3:\n - Group 1 (positions 1, 4): \"aa\"\n - Group 2 (positions 2, 5): \"bb\"\n - Group 3 (positions 3, 6): \"cc\"\n - All groups form palindromes. Therefore, \"abcabc\" is a semi-palindrome.\n\nExample 1:\n\nInput: s = \"abcac\", k = 2\nOutput: 1\nExplanation: Divide s into \"ab\" and \"cac\". \"cac\" is already semi-palindrome. Change \"ab\" to \"aa\", it becomes semi-palindrome with d = 1.\n\nExample 2:\n\nInput: s = \"abcdef\", k = 2\nOutput: 2\nExplanation: Divide s into substrings \"abc\" and \"def\". Each needs one change to become semi-palindrome.\n\nExample 3:\n\nInput: s = \"aabbaa\", k = 3\nOutput: 0\nExplanation: Divide s into substrings \"aa\", \"bb\" and \"aa\". All are already semi-palindromes.\n\nConstraints:\n\n- 2 <= s.length <= 200\n- 1 <= k <= s.length / 2\n- s contains only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc\",k = 3) == 0\n assert candidate(s = \"abccba\",k = 2) == 2\n assert candidate(s = \"aabbccdd\",k = 4) == 0\n assert candidate(s = \"abcabcabc\",k = 4) == 4\n assert candidate(s = \"aaaaaa\",k = 2) == 0\n assert candidate(s = \"abcabcabcabc\",k = 4) == 3\n assert candidate(s = \"abccba\",k = 1) == 0\n assert candidate(s = \"aabbaa\",k = 3) == 0\n assert candidate(s = \"racecar\",k = 1) == 0\n assert candidate(s = \"abcac\",k = 2) == 1\n assert candidate(s = \"zzzzzz\",k = 2) == 0\n assert candidate(s = \"abcdabc\",k = 2) == 2\n assert candidate(s = \"abcdefg\",k = 2) == 3\n assert candidate(s = \"abcdcba\",k = 3) == 2\n assert candidate(s = \"abcdefg\",k = 3) == 3\n assert candidate(s = \"abcabcabc\",k = 3) == 3\n assert candidate(s = \"aaaa\",k = 2) == 0\n assert candidate(s = \"abcdabc\",k = 3) == 3\n assert candidate(s = \"abcabc\",k = 3) == 3\n assert candidate(s = \"abcdef\",k = 2) == 2\n assert candidate(s = \"abccba\",k = 3) == 2\n assert candidate(s = \"ababab\",k = 3) == 3\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiop\",k = 6) == 5\n assert candidate(s = \"aabbccddeeaabbccddeeaabbccdd\",k = 6) == 2\n assert candidate(s = \"abcdefedcbafedcba\",k = 3) == 1\n assert candidate(s = \"abcdabcdabcdabcdabcdabcd\",k = 5) == 2\n assert candidate(s = \"abcdabcdabcdabcd\",k = 4) == 2\n assert candidate(s = \"xyzxyzxyzxyz\",k = 4) == 3\n assert candidate(s = \"xyzxyzxyzxyzxyz\",k = 3) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",k = 5) == 4\n assert candidate(s = \"abcdeabcdeabcde\",k = 4) == 5\n assert candidate(s = \"level\",k = 1) == 0\n assert candidate(s = \"banana\",k = 2) == 1\n assert candidate(s = \"aabbaabbaabbaabb\",k = 4) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmlloo\",k = 5) == 6\n assert candidate(s = \"abccbaabccbaabccba\",k = 4) == 2\n assert candidate(s = \"abracadabraabracadabra\",k = 4) == 5\n assert candidate(s = \"redder\",k = 2) == 2\n assert candidate(s = \"repaper\",k = 2) == 3\n assert candidate(s = \"abababaabab\",k = 3) == 0\n assert candidate(s = \"abcdefghij\",k = 2) == 4\n assert candidate(s = \"abcdefabcdef\",k = 4) == 4\n assert candidate(s = \"abcdefghiabcdefghiabcdefghi\",k = 4) == 3\n assert candidate(s = \"xyzxyzxyzxyzxyz\",k = 5) == 4\n assert candidate(s = \"aabbaaabbbaa\",k = 3) == 1\n assert candidate(s = \"aaabbbcccdddaaa\",k = 4) == 2\n assert candidate(s = \"abcdefgabcdefg\",k = 4) == 5\n assert candidate(s = \"xyxzyxzyxzyxzyxzyx\",k = 4) == 1\n assert candidate(s = \"xyxyxyxyxyxyxy\",k = 3) == 0\n assert candidate(s = \"aaaaabbbbbcccc\",k = 3) == 0\n assert candidate(s = \"ababababababab\",k = 3) == 0\n assert candidate(s = \"abcdefghabcdefghabcdefgh\",k = 6) == 5\n assert candidate(s = \"mississippi\",k = 2) == 2\n assert candidate(s = \"abccbaabccba\",k = 2) == 0\n assert candidate(s = \"abcdefabcdefabcdef\",k = 6) == 6\n assert candidate(s = \"abcdefggfedcba\",k = 2) == 5\n assert candidate(s = \"noonnoonnoon\",k = 3) == 0\n assert candidate(s = \"aabbccddeeffgghhiijj\",k = 5) == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnoopp\",k = 6) == 8\n assert candidate(s = \"aaabaaabaaabaaab\",k = 5) == 1\n assert candidate(s = \"aabbccddeeff\",k = 3) == 4\n assert candidate(s = \"abcdefgabcdefg\",k = 2) == 5\n assert candidate(s = \"racecar\",k = 3) == 2\n assert candidate(s = \"abababab\",k = 3) == 1\n assert candidate(s = \"ababababababab\",k = 5) == 1\n assert candidate(s = \"abcabcabcabcabcabc\",k = 6) == 5\n assert candidate(s = \"mnopqrnopqr\",k = 3) == 4\n assert candidate(s = \"deified\",k = 1) == 0\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",k = 5) == 4\n assert candidate(s = \"abcabcabcabcabcabcabc\",k = 7) == 6\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 7) == 0\n assert candidate(s = \"abcdefghij\",k = 5) == 5\n assert candidate(s = \"noon\",k = 1) == 0\n assert candidate(s = \"aaaaaaaaaa\",k = 5) == 0\n assert candidate(s = \"abcdefghijklnmopqrstuvwxyz\",k = 5) == 9\n assert candidate(s = \"abcdefghij\",k = 3) == 4\n assert candidate(s = \"racecar\",k = 2) == 3\n assert candidate(s = \"rotor\",k = 1) == 0\n assert candidate(s = \"abracadabraabracadabra\",k = 5) == 4\n assert candidate(s = \"xyzyxzyxzyx\",k = 4) == 3\n assert candidate(s = \"aaaaabbbbccccdddd\",k = 4) == 0\n assert candidate(s = \"aaabbbcccdddeeefffggg\",k = 5) == 3\n assert candidate(s = \"aaaabbbbccccdddd\",k = 4) == 0\n assert candidate(s = \"abcabcabcabcabcabcabcabc\",k = 6) == 3\n assert candidate(s = \"ababababab\",k = 3) == 0\n assert candidate(s = \"aabaaabaaabaaa\",k = 4) == 1\n assert candidate(s = \"aabbccddeeffgg\",k = 4) == 4\n assert candidate(s = \"aaaaabbbbcccc\",k = 3) == 0\n assert candidate(s = \"mnopqrsmnopqrsmno\",k = 3) == 6\n assert candidate(s = \"aabbccddeeffgg\",k = 6) == 2\n assert candidate(s = \"zzzaaaabbbccc\",k = 4) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 10) == 10\n assert candidate(s = \"abababababababab\",k = 4) == 0\n assert candidate(s = \"mnopqrspqrspqr\",k = 3) == 2\n assert candidate(s = \"abacabadaba\",k = 3) == 1\n assert candidate(s = \"mississippi\",k = 3) == 1\n assert candidate(s = \"abacabadabacaba\",k = 5) == 2\n assert candidate(s = \"abacabadabacaba\",k = 3) == 0\n assert candidate(s = \"zzzzzyzzzzzz\",k = 5) == 0\n assert candidate(s = \"xyxyxyxyxyxy\",k = 6) == 6\n assert candidate(s = \"abcdeedcba\",k = 2) == 4\n assert candidate(s = \"abcdabcdabcdabcdabcd\",k = 4) == 1\n assert candidate(s = \"abcdefedcba\",k = 5) == 4\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaa\",k = 5) == 0\n assert candidate(s = \"zzzzzyzzzzz\",k = 2) == 0\n assert candidate(s = \"abcabcabcabcabc\",k = 5) == 4\n assert candidate(s = \"abcdefabcdef\",k = 2) == 1\n assert candidate(s = \"abcdefabcdefabcdefabcdef\",k = 5) == 3\n assert candidate(s = \"anana\",k = 1) == 0\n assert candidate(s = \"abcdefghijabcdefghij\",k = 5) == 7\n assert candidate(s = \"aaaabbbb\",k = 2) == 0\n assert candidate(s = \"xyzyzyzyz\",k = 4) == 3\n assert candidate(s = \"mnopqrstuvwx\",k = 4) == 4\n assert candidate(s = \"zzzzzzyyyzzzzzyyy\",k = 2) == 0\n assert candidate(s = \"reviled\",k = 2) == 3\n assert candidate(s = \"aaabbbbccccaaa\",k = 3) == 3\n assert candidate(s = \"abacabadabacaba\",k = 4) == 1\n assert candidate(s = \"aabbccddeeff\",k = 4) == 2\n assert candidate(s = \"xyzxyzxyzxyzxyz\",k = 4) == 3\n", "comparison": "exact"}, "public_tests": ["\"abcac\"\n2"], "hints": ["Define dp[i][j] as the minimum count of letter changes needed to split the suffix of string s starting from s[i] into j valid parts.", "We have dp[i][j] = min(dp[x + 1][j - 1] + v[i][x]). Here v[i][x] is the minimum number of letter changes to change substring s[i..x] into semi-palindrome.", "v[i][j] can be calculated separately by brute-force. We can create a table of v[i][j] independently to improve the complexity. Also note that semi-palindrome’s length is at least 2."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().minimumChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:47+00:00", "tests_total": 119, "tests_dropped": 0, "flags": [], "topic_tags": ["two-pointers", "string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_changes(s, k)", "container": null, "callable": "minimum_changes", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2913, "task_id": "subarrays-distinct-element-sum-of-squares-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums.\n\nThe distinct count of a subarray of nums is defined as:\n\n- Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n\nReturn the sum of the squares of distinct counts of all subarrays of nums.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: 15\nExplanation: Six possible subarrays are:\n[1]: 1 distinct value\n[2]: 1 distinct value\n[1]: 1 distinct value\n[1,2]: 2 distinct values\n[2,1]: 2 distinct values\n[1,2,1]: 2 distinct values\nThe sum of the squares of the distinct counts in all subarrays is equal to 1^2 + 1^2 + 1^2 + 2^2 + 2^2 + 2^2 = 15.\n\nExample 2:\n\nInput: nums = [1,1]\nOutput: 3\nExplanation: Three possible subarrays are:\n[1]: 1 distinct value\n[1]: 1 distinct value\n[1,1]: 1 distinct value\nThe sum of the squares of the distinct counts in all subarrays is equal to 1^2 + 1^2 + 1^2 = 3.\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 = [1, 3, 3, 2, 2, 1]) == 85\n assert candidate(nums = [10, 20, 10, 20, 10]) == 45\n assert candidate(nums = [1, 2, 2, 1]) == 25\n assert candidate(nums = [1, 3, 2, 3, 1]) == 70\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [100, 100, 99, 99, 98]) == 49\n assert candidate(nums = [1, 2, 3, 4]) == 50\n assert candidate(nums = [10, 20, 30, 40, 50]) == 105\n assert candidate(nums = [5, 6, 7, 8, 9]) == 105\n assert candidate(nums = [7, 7, 7, 7, 7, 7]) == 21\n assert candidate(nums = [1, 2, 1]) == 15\n assert candidate(nums = [5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 105\n assert candidate(nums = [10, 10, 10]) == 6\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 184\n assert candidate(nums = [4, 4, 4, 4]) == 10\n assert candidate(nums = [4, 5, 6, 7]) == 50\n assert candidate(nums = [1, 2]) == 6\n assert candidate(nums = [2, 3, 2, 3]) == 28\n assert candidate(nums = [1, 2, 3]) == 20\n assert candidate(nums = [1, 1]) == 3\n assert candidate(nums = [5]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 1730\n assert candidate(nums = [3, 4, 3, 2, 3, 1]) == 120\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4]) == 410\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 171\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 755\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2]) == 293\n assert candidate(nums = [10, 20, 30, 20, 10, 30, 20, 10]) == 220\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1210\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 1716\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]) == 1811\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 825\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 551\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 778\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 210\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 551\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 78\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1]) == 220\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 1210\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 263\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 778\n assert candidate(nums = [1, 2, 3, 2, 1]) == 70\n assert candidate(nums = [3, 1, 2, 3, 4, 5, 3, 2]) == 370\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 50, 10]) == 367\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 278\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 4635\n assert candidate(nums = [1, 3, 3, 1, 2, 2, 3, 1]) == 194\n assert candidate(nums = [50, 50, 51, 51, 52, 52, 53, 53, 54, 54]) == 415\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 451\n assert candidate(nums = [5, 6, 5, 7, 8, 7, 6, 5, 9, 10, 9, 8, 7, 6]) == 1899\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 77\n assert candidate(nums = [10, 20, 30, 20, 10, 30]) == 111\n assert candidate(nums = [10, 20, 30, 20, 10, 30, 20, 10, 30]) == 288\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 415\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4830\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 120\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4830\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 415\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 415\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 1210\n assert candidate(nums = [3, 1, 2, 3, 4, 2, 5]) == 240\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 55\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 778\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1210\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10560\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 438\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 5440\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1210\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 1645\n assert candidate(nums = [10, 20, 30, 40, 50]) == 105\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1]) == 861\n assert candidate(nums = [10, 20, 10, 30, 20, 30, 40, 50]) == 298\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 930\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 1645\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 553\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 930\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 5415\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 438\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 1285\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 3]) == 367\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 36\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10560\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 1794\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 825\n assert candidate(nums = [9, 7, 5, 3, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 3910\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10560\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9]) == 551\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 5415\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 962\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]) == 8670850\n assert candidate(nums = [1, 1, 2, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 751\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]) == 6455\n assert candidate(nums = [1, 3, 2, 3, 4, 5, 4, 3, 2, 1]) == 611\n assert candidate(nums = [5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 415\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1210\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 55\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 2, 3]) == 419\n assert candidate(nums = [10, 20, 30, 20, 10, 30]) == 111\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 4635\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 1285\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 2366\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 350\n", "comparison": "exact"}, "public_tests": ["[1,2,1]", "[1,1]"], "hints": ["Use a set/heap to keep track of distinct element counts."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumCounts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:52+00:00", "tests_total": 105, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "binary-indexed-tree", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def sum_counts(nums)", "container": null, "callable": "sum_counts", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2914, "task_id": "minimum-number-of-changes-to-make-binary-string-beautiful", "difficulty": "Medium", "problem_description": "You are given a 0-indexed binary string s having an even length.\n\nA string is beautiful if it's possible to partition it into one or more substrings such that:\n\n- Each substring has an even length.\n- Each substring contains only 1's or only 0's.\n\nYou can change any character in s to 0 or 1.\n\nReturn the minimum number of changes required to make the string s beautiful.\n\nExample 1:\n\nInput: s = \"1001\"\nOutput: 2\nExplanation: We change s[1] to 1 and s[3] to 0 to get string \"1100\".\nIt can be seen that the string \"1100\" is beautiful because we can partition it into \"11|00\".\nIt can be proven that 2 is the minimum number of changes needed to make the string beautiful.\n\nExample 2:\n\nInput: s = \"10\"\nOutput: 1\nExplanation: We change s[1] to 1 to get string \"11\".\nIt can be seen that the string \"11\" is beautiful because we can partition it into \"11\".\nIt can be proven that 1 is the minimum number of changes needed to make the string beautiful.\n\nExample 3:\n\nInput: s = \"0000\"\nOutput: 0\nExplanation: We don't need to make any changes as the string \"0000\" is beautiful already.\n\nConstraints:\n\n- 2 <= s.length <= 10^5\n- s has an even length.\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"101010\") == 3\n assert candidate(s = \"11001100\") == 0\n assert candidate(s = \"001100\") == 0\n assert candidate(s = \"10\") == 1\n assert candidate(s = \"110011\") == 0\n assert candidate(s = \"00110011\") == 0\n assert candidate(s = \"11110000\") == 0\n assert candidate(s = \"0101\") == 2\n assert candidate(s = \"010101\") == 3\n assert candidate(s = \"1001\") == 2\n assert candidate(s = \"0000\") == 0\n assert candidate(s = \"00001111\") == 0\n assert candidate(s = \"111111111111111111111111\") == 0\n assert candidate(s = \"000000111111000000111111\") == 0\n assert candidate(s = \"110011001100110011001100\") == 0\n assert candidate(s = \"1100110011001100\") == 0\n assert candidate(s = \"010101010101010101010101\") == 12\n assert candidate(s = \"00000000111111110000000011111111\") == 0\n assert candidate(s = \"10101001010101\") == 7\n assert candidate(s = \"10101010101010101010101010\") == 13\n assert candidate(s = \"0000111111000011111100001111\") == 0\n assert candidate(s = \"00001111000011110000\") == 0\n assert candidate(s = \"101010101010101010101010\") == 12\n assert candidate(s = \"1010101010\") == 5\n assert candidate(s = \"0000000000000000\") == 0\n assert candidate(s = \"1010100101010101\") == 8\n assert candidate(s = \"1010101010101010\") == 8\n assert candidate(s = \"011101110111\") == 3\n assert candidate(s = \"110011001100\") == 0\n assert candidate(s = \"111111000000111111000000\") == 0\n assert candidate(s = \"10011001100110011001\") == 10\n assert candidate(s = \"10111000111000111000\") == 4\n assert candidate(s = \"0100100100100100\") == 5\n assert candidate(s = \"01001001001001\") == 5\n assert candidate(s = \"0011001100110011\") == 0\n assert candidate(s = \"00001100001100001100\") == 0\n assert candidate(s = \"000111000111\") == 2\n assert candidate(s = \"110101010101\") == 5\n assert candidate(s = \"111111111111\") == 0\n assert candidate(s = \"0110110110110110\") == 6\n assert candidate(s = \"11110000111100001111\") == 0\n assert candidate(s = \"1010010101010101\") == 8\n assert candidate(s = \"0101011010101010\") == 8\n assert candidate(s = \"101010101010\") == 6\n assert candidate(s = \"11111111111111111111\") == 0\n assert candidate(s = \"000011110000\") == 0\n assert candidate(s = \"1100111100000011\") == 0\n assert candidate(s = \"1111111111111111\") == 0\n assert candidate(s = \"110000110000\") == 0\n assert candidate(s = \"01100110011001\") == 7\n assert candidate(s = \"11111111000000001111111100000000\") == 0\n assert candidate(s = \"11010101\") == 3\n assert candidate(s = \"1111001111001111\") == 0\n assert candidate(s = \"11001100110011000000\") == 0\n assert candidate(s = \"0110100100110001\") == 5\n assert candidate(s = \"1011001100110011\") == 1\n assert candidate(s = \"11010101101010101010\") == 9\n assert candidate(s = \"000000000000\") == 0\n assert candidate(s = \"100000000001\") == 2\n assert candidate(s = \"1001001001001001\") == 6\n assert candidate(s = \"11001100110011001100\") == 0\n assert candidate(s = \"11100011100011100011\") == 3\n assert candidate(s = \"1010101010101010101010101010\") == 14\n assert candidate(s = \"0000110000110000\") == 0\n assert candidate(s = \"0000111111110000\") == 0\n assert candidate(s = \"111000111000\") == 2\n assert candidate(s = \"1111111100000000\") == 0\n assert candidate(s = \"111100001111\") == 0\n assert candidate(s = \"1100101011110000\") == 2\n assert candidate(s = \"1010101001010101\") == 8\n assert candidate(s = \"01100110011001100110\") == 10\n assert candidate(s = \"1000100010001000100010001000\") == 7\n assert candidate(s = \"010101010101\") == 6\n assert candidate(s = \"11010101010101\") == 6\n assert candidate(s = \"0101010101010101\") == 8\n assert candidate(s = \"000000000000000000000000\") == 0\n assert candidate(s = \"00000000\") == 0\n assert candidate(s = \"0101010101010101010101010101\") == 14\n assert candidate(s = \"11110011000011110000111100\") == 0\n assert candidate(s = \"00010001000100010001\") == 5\n assert candidate(s = \"01010101010110101010\") == 10\n assert candidate(s = \"11001011001011\") == 2\n assert candidate(s = \"1111000011111100\") == 0\n assert candidate(s = \"0111011101110111011101110111\") == 7\n assert candidate(s = \"100010001000\") == 3\n assert candidate(s = \"00110011001100110011\") == 0\n assert candidate(s = \"1110001110001110\") == 3\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"1111000011110000\") == 0\n assert candidate(s = \"110000111100110000111100\") == 0\n assert candidate(s = \"0000000011111111\") == 0\n assert candidate(s = \"0101010110101010\") == 8\n assert candidate(s = \"1111000000001111\") == 0\n assert candidate(s = \"1100001100001100\") == 0\n assert candidate(s = \"0110011001100110\") == 8\n assert candidate(s = \"1101001101001101\") == 3\n assert candidate(s = \"100110011001\") == 6\n assert candidate(s = \"1001100110011001\") == 8\n assert candidate(s = \"001001001001\") == 4\n assert candidate(s = \"01010101010101010101\") == 10\n assert candidate(s = \"110000111100\") == 0\n assert candidate(s = \"110110110110\") == 4\n assert candidate(s = \"11111111\") == 0\n assert candidate(s = \"1111000011000011\") == 0\n assert candidate(s = \"01010101\") == 4\n assert candidate(s = \"11111111000000001111\") == 0\n assert candidate(s = \"0101101010101010\") == 8\n assert candidate(s = \"10101010101010101010\") == 10\n assert candidate(s = \"00000000111111110000\") == 0\n assert candidate(s = \"0000001111110000\") == 0\n assert candidate(s = \"1111110000001111\") == 0\n assert candidate(s = \"1101010101\") == 4\n assert candidate(s = \"1011101110111011\") == 4\n assert candidate(s = \"001100110011\") == 0\n assert candidate(s = \"0000111100001111\") == 0\n", "comparison": "exact"}, "public_tests": ["\"1001\"", "\"10\"", "\"0000\""], "hints": ["For any valid partition, since each part consists of an even number of the same characters, we can further partition each part into lengths of exactly 2.", "After noticing the first hint, we can decompose the whole string into disjoint blocks of size 2 and find the minimum number of changes required to make those blocks beautiful."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:54+00:00", "tests_total": 116, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def min_changes(s)", "container": null, "callable": "min_changes", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2915, "task_id": "length-of-the-longest-subsequence-that-sums-to-target", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of integers nums, and an integer target.\n\nReturn the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], target = 9\nOutput: 3\nExplanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.\n\nExample 2:\n\nInput: nums = [4,1,3,2,1,5], target = 7\nOutput: 4\nExplanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.\n\nExample 3:\n\nInput: nums = [1,1,5,4,5], target = 3\nOutput: -1\nExplanation: It can be shown that nums has no subsequence that sums up to 3.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n- 1 <= target <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 7, 8, 10],target = 15) == 3\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 8, 9, 10],target = 15) == 4\n assert candidate(nums = [10, 20, 30, 40, 50],target = 50) == 2\n assert candidate(nums = [999, 1],target = 1000) == 2\n assert candidate(nums = [100, 200, 300],target = 100) == 1\n assert candidate(nums = [1, 2, 3],target = 7) == -1\n assert candidate(nums = [4, 1, 3, 2, 1, 5],target = 7) == 4\n assert candidate(nums = [1],target = 1) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],target = 100) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],target = 3) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 25) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],target = 9) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],target = 60) == 3\n assert candidate(nums = [5, 5, 5, 5, 5],target = 15) == 3\n assert candidate(nums = [500, 500, 500, 500],target = 1000) == 2\n assert candidate(nums = [1, 2, 3],target = 6) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],target = 1) == 1\n assert candidate(nums = [1000],target = 1000) == 1\n assert candidate(nums = [1, 1, 5, 4, 5],target = 3) == -1\n assert candidate(nums = [1, 2, 3, 4, 5],target = 15) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],target = 5) == 5\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = 25) == -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],target = 15) == 15\n assert candidate(nums = [999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 1000) == 2\n assert candidate(nums = [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],target = 600) == 24\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 30) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = 75) == 7\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],target = 210) == 11\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],target = 700) == 13\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980],target = 990) == 1\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],target = 500) == 22\n assert candidate(nums = [10, 20, 30, 40, 50],target = 100) == 4\n assert candidate(nums = [333, 334, 333, 334, 333, 334, 333, 334, 333, 334, 333, 334, 333, 334, 333, 334, 333, 334, 333, 334],target = 1000) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],target = 1000) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 50) == 9\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],target = 400) == 9\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 100) == 5\n assert candidate(nums = [10, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90],target = 900) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],target = 500) == 9\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],target = 210) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 550) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 50) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 300) == 7\n assert candidate(nums = [999, 500, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 1000) == 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],target = 100) == 13\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55],target = 100) == 5\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448],target = 500) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],target = 900) == 12\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 5) == 5\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135],target = 675) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 5) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],target = 100) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 150) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],target = 30) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 27) == 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],target = 190) == 19\n assert candidate(nums = [500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 999) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],target = 1000) == 13\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],target = 210) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = 225) == 15\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],target = 600) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 300) == 7\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160],target = 600) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 7) == 7\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],target = 750) == -1\n assert candidate(nums = [250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 499) == 27\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 150) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],target = 150) == 16\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 5) == 5\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],target = 100) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 150) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],target = 500) == 9\n assert candidate(nums = [333, 334, 333, 334, 333, 334, 333, 334],target = 1000) == 3\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140],target = 420) == 10\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],target = 143) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 150) == 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],target = 20) == 8\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],target = 200) == 13\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 20) == 4\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120],target = 600) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 25) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],target = 20) == 8\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],target = 300) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 50) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],target = 55) == 13\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],target = 150) == 11\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],target = 105) == 5\n assert candidate(nums = [500, 300, 200, 100, 50, 25, 10, 5, 1],target = 1000) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 15) == 6\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]\n9", "[4,1,3,2,1,5]\n7", "[1,1,5,4,5]\n3"], "hints": ["Use dynamic programming.", "Let dp[i][j] be the maximum length of any subsequence of nums[0..i - 1] that sums to j.", "dp[0][0] = 1, and dp[0][j] = 1 for all target ≥ j > 0.", "dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - nums[i -1]) for all n ≥ i > 0 and target ≥ j > nums[i - 1]."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().lengthOfLongestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:56+00:00", "tests_total": 110, "tests_dropped": 18, "flags": [], "topic_tags": ["array", "dynamic-programming", "knapsack-problem", "0-1-knapsack"]}, "language": "ruby", "interface": {"raw_signature": "def length_of_longest_subsequence(nums, target)", "container": null, "callable": "length_of_longest_subsequence", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2916, "task_id": "subarrays-distinct-element-sum-of-squares-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums.\n\nThe distinct count of a subarray of nums is defined as:\n\n- Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n\nReturn the sum of the squares of distinct counts of all subarrays of nums.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: 15\nExplanation: Six possible subarrays are:\n[1]: 1 distinct value\n[2]: 1 distinct value\n[1]: 1 distinct value\n[1,2]: 2 distinct values\n[2,1]: 2 distinct values\n[1,2,1]: 2 distinct values\nThe sum of the squares of the distinct counts in all subarrays is equal to 1^2 + 1^2 + 1^2 + 2^2 + 2^2 + 2^2 = 15.\n\nExample 2:\n\nInput: nums = [2,2]\nOutput: 3\nExplanation: Three possible subarrays are:\n[2]: 1 distinct value\n[2]: 1 distinct value\n[2,2]: 1 distinct value\nThe sum of the squares of the distinct counts in all subarrays is equal to 1^2 + 1^2 + 1^2 = 3.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 105\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 105\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 77\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [1, 1, 1, 1, 1]) == 15\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 3, 2, 1]) == 241\n assert candidate(nums = [1, 3, 2, 3, 1, 4, 2]) == 210\n assert candidate(nums = [5, 5, 5, 5, 5]) == 15\n assert candidate(nums = [1, 3, 3, 1, 2, 2, 4]) == 156\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == 15\n assert candidate(nums = [1, 2, 1]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5]) == 105\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1210\n assert candidate(nums = [2, 2]) == 3\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 105\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 1730\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7]) == 17100\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 1794\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 68610\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 435\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16170\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, 3, 3, 3, 4]) == 4219\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]) == 7398\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, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 51040\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 776\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 3010\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 755\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]) == 3003\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 3010\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 1210\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 778\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 1650\n assert candidate(nums = [5, 3, 8, 3, 9, 1, 5, 3, 8, 3, 9, 1, 5, 3, 8, 3, 9, 1, 5, 3, 8, 3, 9, 1]) == 5698\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 1]) == 26382\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 5440\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]) == 21745\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8085\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]) == 2605\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 510\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 4635\n assert candidate(nums = [5, 3, 8, 3, 9, 1, 5, 3, 8, 3, 9, 1]) == 1098\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 451\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 763\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110]) == 6558\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4830\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 1210\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 415\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4830\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 190\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 16131\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2]) == 178\n assert candidate(nums = [1, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9, 10, 9, 10]) == 11874\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]) == 1939\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 564\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 3291\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 16170\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 59260\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 3850\n assert candidate(nums = [1, 2, 1, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9, 10]) == 7710\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]) == 3828\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5]) == 724\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == 1026\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, 1, 1, 2, 1, 1, 2, 1, 1, 2]) == 1740\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 1590\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981]) == 16170\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 6455\n assert candidate(nums = [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, 1, 2, 3, 4, 5]) == 38385\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 778\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]) == 76880\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1210\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10560\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 438\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 370\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 1, 2, 3, 2, 1, 3, 2, 1, 1, 2, 3, 2]) == 1584\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 1210\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 3480\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 3930\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 860\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 23190\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1210\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]) == 38025\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1210\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3]) == 11847\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 866\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 16170\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 14574\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2]) == 4409\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]) == 435\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 16170\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1]) == 1688\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 2030\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]) == 465\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, 7, 6, 5, 4, 3, 2, 1]) == 12194\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 3480\n assert candidate(nums = [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]) == 24960\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10560\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 1210\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 1794\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]) == 5942\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]) == 917\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]) == 741\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 2475\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]) == 3865\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10560\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]) == 6455\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 1495\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 658\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 3930\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 210\n assert candidate(nums = [7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]) == 470\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]) == 6455\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 18525\n", "comparison": "exact"}, "public_tests": ["[1,2,1]", "[2,2]"], "hints": ["Consider the sum of the count of distinct values of subarrays ending with index i, let’s call it sum. Now if you need the sum of all subarrays ending with index i + 1 think how it can be related to sum and what extra will be needed to add to this.", "You can find that extra sum using the segment tree."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumCounts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:06:59+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "binary-indexed-tree", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def sum_counts(nums)", "container": null, "callable": "sum_counts", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2917, "task_id": "find-the-k-or-of-an-array", "difficulty": "Easy", "problem_description": "You are given an integer array nums, and an integer k. Let's introduce K-or operation by extending the standard bitwise OR. In K-or, a bit position in the result is set to 1 if at least k numbers in nums have a 1 in that position.\n\nReturn the K-or of nums.\n\nExample 1:\n\nInput: nums = [7,12,9,8,9,15], k = 4\nOutput: 9\nExplanation:\nRepresent numbers in binary:\n\nNumber | Bit 3 | Bit 2 | Bit 1 | Bit 0\n7 | 0 | 1 | 1 | 1\n12 | 1 | 1 | 0 | 0\n9 | 1 | 0 | 0 | 1\n8 | 1 | 0 | 0 | 0\n9 | 1 | 0 | 0 | 1\n15 | 1 | 1 | 1 | 1\nResult = 9 | 1 | 0 | 0 | 1\n\nBit 0 is set in 7, 9, 9, and 15. Bit 3 is set in 12, 9, 8, 9, and 15.\nOnly bits 0 and 3 qualify. The result is (1001)_2 = 9.\n\nExample 2:\n\nInput: nums = [2,12,1,11,4,5], k = 6\nOutput: 0\nExplanation: No bit appears as 1 in all six array numbers, as required for K-or with k = 6. Thus, the result is 0.\n\nExample 3:\n\nInput: nums = [10,8,5,9,11,6,8], k = 1\nOutput: 15\nExplanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 0 <= nums[i] < 2^31\n- 1 <= k <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 8, 5, 9, 11, 6, 8],k = 1) == 15\n assert candidate(nums = [7, 12, 9, 8, 9, 15],k = 4) == 9\n assert candidate(nums = [2, 12, 1, 11, 4, 5],k = 6) == 0\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 3) == 63\n assert candidate(nums = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22],k = 5) == 23\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384],k = 7) == 0\n assert candidate(nums = [32, 64, 128, 256, 512, 1024, 2048, 4096],k = 4) == 0\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31],k = 3) == 31\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 6) == 0\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555],k = 2) == 536870879\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444],k = 3) == 534769557\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 6) == 31\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 6) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 15\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],k = 10) == 63\n assert candidate(nums = [31, 14, 7, 28, 15, 13, 29],k = 3) == 31\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 3) == 262143\n assert candidate(nums = [5, 17, 2, 3, 1, 6, 8, 16, 10, 4],k = 5) == 0\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048],k = 2) == 0\n assert candidate(nums = [13, 29, 53, 79, 101, 131, 157, 181, 211, 239],k = 5) == 157\n assert candidate(nums = [31, 14, 7, 28, 15, 23, 11, 9],k = 3) == 31\n assert candidate(nums = [32, 16, 8, 4, 2, 1, 64, 128, 256, 512, 1024],k = 7) == 0\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17],k = 10) == 17\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 5) == 31\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 2) == 511\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535],k = 4) == 8191\n assert candidate(nums = [4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 6) == 127\n assert candidate(nums = [8388607, 8388606, 8388605, 8388604, 8388603, 8388602, 8388601, 8388600],k = 4) == 8388607\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 = 25) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 6) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 8) == 0\n assert candidate(nums = [31, 14, 7, 28, 15, 24, 29, 30],k = 5) == 30\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 10) == 0\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],k = 5) == 24\n assert candidate(nums = [29, 38, 47, 56, 65, 74, 83, 92, 101, 110],k = 7) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(nums = [18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180, 186, 192],k = 10) == 254\n assert candidate(nums = [18, 33, 51, 48, 47, 38, 21, 50, 49, 23],k = 5) == 51\n assert candidate(nums = [3, 5, 6, 7, 10, 12, 15],k = 4) == 7\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984],k = 4) == 248\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 10) == 1\n assert candidate(nums = [31, 14, 28, 15, 23, 29, 27, 19],k = 5) == 31\n assert candidate(nums = [1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152],k = 3) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 2) == 0\n assert candidate(nums = [2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647],k = 25) == 2147483647\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15],k = 10) == 15\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 4) == 127\n assert candidate(nums = [31, 14, 7, 28, 15, 29, 10],k = 3) == 31\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229],k = 10) == 255\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 5) == 31\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256],k = 5) == 0\n assert candidate(nums = [1073741823, 1073741823, 1073741823, 1073741823, 1073741823, 1073741823, 1073741823, 1073741823, 1073741823, 1073741823],k = 5) == 1073741823\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 8) == 31\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035],k = 7) == 2097088\n assert candidate(nums = [255, 254, 253, 252, 251, 250, 249, 248],k = 4) == 255\n assert candidate(nums = [2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647],k = 10) == 2147483647\n assert candidate(nums = [63, 37, 19, 31, 15, 7, 1, 3, 11],k = 3) == 31\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575],k = 20) == 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],k = 10) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 5) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 7) == 0\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 5) == 0\n assert candidate(nums = [3, 6, 12, 24, 48, 96],k = 3) == 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],k = 30) == 1\n assert candidate(nums = [1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048],k = 15) == 0\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767],k = 5) == 2047\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 1000000000\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0],k = 4) == 31\n assert candidate(nums = [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],k = 15) == 31\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 5) == 2044\n assert candidate(nums = [1000000000, 1000000001, 1000000002, 1000000003, 1000000004],k = 2) == 1000000003\n assert candidate(nums = [2147483647, 2147483646, 2147483645, 2147483644, 2147483643, 2147483642],k = 3) == 2147483647\n assert candidate(nums = [2147483647, 1073741823, 536870911, 268435455, 134217727, 67108863, 33554431, 16777215, 8388607, 4194303, 2097151, 1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 134217727\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 15) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 63\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64],k = 1) == 127\n assert candidate(nums = [31, 17, 14, 19, 28, 15, 30],k = 3) == 31\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 2) == 1020\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400],k = 7) == 127\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536],k = 8) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 1\n assert candidate(nums = [33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431, 33554431],k = 15) == 33554431\n assert candidate(nums = [31, 28, 19, 14, 23, 15, 27],k = 3) == 31\n assert candidate(nums = [31, 14, 7, 28, 15, 21, 19],k = 3) == 31\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824],k = 30) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128],k = 2) == 0\n assert candidate(nums = [2147483647, 1073741823, 536870911, 268435455, 134217727, 67108863, 33554431, 16777215, 8388607, 4194303, 2097151, 1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 25) == 127\n", "comparison": "exact"}, "public_tests": ["[7,12,9,8,9,15]\n4"], "hints": ["Fix a bit from the range [0, 31], then count the number of elements of nums that have bit set in them.", "bit is set in integer x if and only if 2^bit AND x == 2^bit, where AND is the bitwise AND operation."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().findKOr", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:01+00:00", "tests_total": 92, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_k_or(nums, k)", "container": null, "callable": "find_k_or", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2918, "task_id": "minimum-equal-sum-of-two-arrays-after-replacing-zeros", "difficulty": "Medium", "problem_description": "You are given two arrays nums1 and nums2 consisting of positive integers.\n\nYou have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.\n\nReturn the minimum equal sum you can obtain, or -1 if it is impossible.\n\nExample 1:\n\nInput: nums1 = [3,2,0,1,0], nums2 = [6,5,0]\nOutput: 12\nExplanation: We can replace 0's in the following way:\n- Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].\n- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].\nBoth arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.\n\nExample 2:\n\nInput: nums1 = [2,0,2,0], nums2 = [1,4]\nOutput: -1\nExplanation: It is impossible to make the sum of both arrays equal.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 10^5\n- 0 <= nums1[i], nums2[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 0, 0, 0],nums2 = [0, 0, 0, 1]) == 4\n assert candidate(nums1 = [2, 0, 2, 0],nums2 = [1, 4]) == -1\n assert candidate(nums1 = [3, 2, 0, 1, 0],nums2 = [6, 5, 0]) == 12\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1]) == 6\n assert candidate(nums1 = [1, 0, 3],nums2 = [2, 0, 2]) == 5\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [2, 2, 2, 2]) == -1\n assert candidate(nums1 = [0, 0, 0],nums2 = [1, 1, 1]) == 3\n assert candidate(nums1 = [0, 0, 0],nums2 = [0, 0, 0]) == 3\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0]) == 4\n assert candidate(nums1 = [1, 0],nums2 = [0, 1]) == 2\n assert candidate(nums1 = [10, 20, 30, 0, 0],nums2 = [0, 0, 0, 40, 50]) == 93\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [1000000, 0, 0],nums2 = [500000, 500000, 0]) == 1000002\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 65\n assert candidate(nums1 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 15\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1000000]) == 1000000\n assert candidate(nums1 = [1000000, 0, 0, 0, 0],nums2 = [500000, 500000, 0, 0, 0]) == 1000004\n assert candidate(nums1 = [1000000, 1000000, 0],nums2 = [500000, 500000, 500000, 500000, 500000, 500000, 0]) == 3000001\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums1 = [1000000],nums2 = [1000000]) == 1000000\n assert candidate(nums1 = [1000000],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 0, 0],nums2 = [5, 4, 3, 2, 1, 0, 0]) == 17\n assert candidate(nums1 = [1, 2, 3, 0, 0],nums2 = [4, 5, 0, 0, 0]) == 12\n assert candidate(nums1 = [1000000, 0, 0, 0],nums2 = [500000, 500000, 0, 0]) == 1000003\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(nums1 = [999999, 0, 0, 0],nums2 = [500000, 500000, 0]) == 1000002\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0, 1]) == 17\n assert candidate(nums1 = [1, 1, 1, 1, 1, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 0, 0, 0]) == 9\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1000000, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1000009\n assert candidate(nums1 = [999999, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums1 = [999999, 0, 0, 0, 0, 0],nums2 = [1000000, 1, 1, 1, 1, 1]) == 1000005\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums1 = [3, 0, 5, 0, 7],nums2 = [2, 0, 6, 0, 0]) == 17\n assert candidate(nums1 = [1000000, 0, 0, 500000],nums2 = [750000, 250000, 0, 0]) == 1500002\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100, 0]) == -1\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums1 = [999999, 0, 0, 0],nums2 = [1, 1, 1, 1]) == -1\n assert candidate(nums1 = [1000000, 0, 0, 0],nums2 = [500000, 500000, 0, 0]) == 1000003\n assert candidate(nums1 = [1, 2, 3, 4, 0, 0, 0],nums2 = [7, 8, 9, 0, 0]) == 26\n assert candidate(nums1 = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [500000, 500000, 0, 0],nums2 = [250000, 250000, 250000, 250000, 0, 0]) == 1000002\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 15\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 46\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0]) == 16\n assert candidate(nums1 = [1, 0, 1, 0, 1],nums2 = [0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0]) == -1\n assert candidate(nums1 = [100, 200, 300, 0, 0, 0, 0, 0, 0, 0],nums2 = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 750\n assert candidate(nums1 = [10, 20, 30, 0, 0],nums2 = [5, 15, 25, 0, 0]) == 62\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 46\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums1 = [0, 1000000, 0, 1000000],nums2 = [500000, 0, 0, 500000]) == 2000002\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [0, 0, 0, 0, 0, 0]) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums1 = [10, 20, 30, 0, 0],nums2 = [15, 15, 0, 0, 0]) == 62\n assert candidate(nums1 = [0, 1, 0, 2, 0, 3],nums2 = [4, 0, 5, 0, 6]) == 17\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums1 = [1, 2, 3, 0, 0, 0],nums2 = [6, 5, 0, 0, 0]) == 14\n assert candidate(nums1 = [5, 10, 15, 20],nums2 = [20, 15, 10, 5, 0, 0]) == -1\n assert candidate(nums1 = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0],nums2 = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5]) == 20\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 165\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 20\n assert candidate(nums1 = [1000000, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [500000, 500000, 0, 0, 0, 0, 0, 0, 0, 0]) == 1000009\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 0]) == 167\n assert candidate(nums1 = [1000000, 0, 0, 0],nums2 = [500000, 500000, 0]) == 1000003\n assert candidate(nums1 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums1 = [1, 2, 3, 0, 0, 0],nums2 = [6, 0, 0, 0, 0, 0]) == 11\n assert candidate(nums1 = [1, 0, 3, 0, 5, 0, 7, 0, 9, 0],nums2 = [0, 2, 0, 4, 0, 6, 0, 8, 0, 10]) == 35\n assert candidate(nums1 = [1, 0, 1, 0, 1, 0],nums2 = [0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums1 = [1, 2, 3, 0, 0, 0],nums2 = [4, 5, 0, 0, 0, 0]) == 13\n assert candidate(nums1 = [10, 20, 30, 40, 50, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == 151\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 100\n assert candidate(nums1 = [1, 2, 3, 4, 5, 0, 0],nums2 = [5, 4, 3, 2, 1, 0, 0]) == 17\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums1 = [999999, 999999, 999999],nums2 = [999999, 999999, 0]) == 2999997\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 12\n assert candidate(nums1 = [1, 0, 0, 0, 0, 0],nums2 = [2, 0, 0, 0, 0, 0]) == 7\n assert candidate(nums1 = [100, 200, 300, 400, 500, 0, 0, 0, 0, 0],nums2 = [150, 150, 150, 150, 150, 150, 150, 150, 150, 150]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [0, 0, 0, 0, 0]) == 15\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0, 0]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 0, 0, 0],nums2 = [10, 0, 0, 0, 0, 0, 0, 0]) == 18\n assert candidate(nums1 = [999999],nums2 = [1, 0, 0, 0, 0, 0, 0]) == 999999\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums1 = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0],nums2 = [5, 0, 4, 0, 3, 0, 2, 0, 1, 0]) == 20\n assert candidate(nums1 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 15\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [5, 15, 25, 35, 0, 0]) == 100\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0, 0, 0]) == -1\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n", "comparison": "exact"}, "public_tests": ["[3,2,0,1,0]\n[6,5,0]", "[2,0,2,0]\n[1,4]"], "hints": ["Consider we replace all the 0’s with 1’s on both arrays, the answer will be -1 if there was no 0 in the array with the smaller sum of elements.", "Otherwise, how can you update the value of exactly one of these 1’s to make the sum of the two arrays equal?"], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:04+00:00", "tests_total": 104, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def min_sum(nums1, nums2)", "container": null, "callable": "min_sum", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2919, "task_id": "minimum-increment-operations-to-make-array-beautiful", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums having length n, and an integer k.\n\nYou can perform the following increment operation any number of times (including zero):\n\n- Choose an index i in the range [0, n - 1], and increase nums[i] by 1.\n\nAn array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.\n\nReturn an integer denoting the minimum number of increment operations needed to make nums beautiful.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,0,0,2], k = 4\nOutput: 3\nExplanation: We can perform the following increment operations to make nums beautiful:\nChoose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].\nChoose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].\nChoose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].\nThe subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].\nIn all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.\nIt can be shown that nums cannot be made beautiful with fewer than 3 increment operations.\nHence, the answer is 3.\n\nExample 2:\n\nInput: nums = [0,1,3,3], k = 5\nOutput: 2\nExplanation: We can perform the following increment operations to make nums beautiful:\nChoose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].\nChoose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].\nThe subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].\nIn all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.\nIt can be shown that nums cannot be made beautiful with fewer than 2 increment operations.\nHence, the answer is 2.\n\nExample 3:\n\nInput: nums = [1,1,2], k = 1\nOutput: 0\nExplanation: The only subarray with a size of 3 or more in this example is [1,1,2].\nThe maximum element, 2, is already greater than k = 1, so we don't need any increment operation.\nHence, the answer is 0.\n\nConstraints:\n\n- 3 <= n == nums.length <= 10^5\n- 0 <= nums[i] <= 10^9\n- 0 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [10, 9, 8, 7, 6],k = 10) == 2\n assert candidate(nums = [1000000000, 0, 1000000000, 0, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1],k = 3) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 2\n assert candidate(nums = [1, 0, 0, 0, 1],k = 2) == 2\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1],k = 2) == 3\n assert candidate(nums = [5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 10) == 3\n assert candidate(nums = [2, 3, 0, 0, 2],k = 4) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 12\n assert candidate(nums = [0, 1, 3, 3],k = 5) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 7) == 5\n assert candidate(nums = [5, 5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0],k = 0) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 12\n assert candidate(nums = [1, 1, 2],k = 1) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0],k = 1) == 2\n assert candidate(nums = [0, 0, 0, 0, 0],k = 3) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == 3\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 1000000000) == 2\n assert candidate(nums = [3, 2, 1, 5, 4, 6, 7, 8, 9, 10],k = 5) == 2\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 5) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 12\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 500) == 200\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 25) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 7) == 5\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0],k = 1) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 10) == 15\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 7) == 14\n assert candidate(nums = [3, 0, 0, 3, 0, 0, 3, 0, 0],k = 3) == 0\n assert candidate(nums = [5, 1, 4, 2, 8, 3, 6, 9, 7],k = 5) == 1\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0],k = 5) == 6\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 2) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 3\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 = 10) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 15) == 12\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 5) == 10\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 10) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 15\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],k = 3) == 3\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 1) == 0\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4],k = 4) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 20) == 27\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],k = 50) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 3) == 4\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2],k = 2) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == 15\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == 6\n assert candidate(nums = [5, 1, 9, 3, 7, 8, 2, 6, 4],k = 6) == 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, 1, 1],k = 2) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 100) == 120\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 100) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],k = 4) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == 3\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],k = 4) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 1) == 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 = 3) == 9\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 0) == 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 = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],k = 105) == 3\n assert candidate(nums = [8, 6, 7, 5, 3, 0, 9],k = 8) == 3\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 15) == 12\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 4) == 6\n assert candidate(nums = [10, 15, 0, 20, 5, 25, 1, 30],k = 10) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 25) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 6) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 15) == 12\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 15) == 35\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5],k = 5) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 7\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 500) == 200\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 0\n assert candidate(nums = [5, 3, 2, 1, 0, 6, 4, 8, 7],k = 5) == 3\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],k = 900000000) == 800000001\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 7) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1],k = 4) == 2\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2) == 6\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555],k = 777777777) == 0\n assert candidate(nums = [10, 0, 10, 0, 10, 0, 10, 0, 10],k = 5) == 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],k = 2) == 6\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 10) == 3\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 50) == 132\n assert candidate(nums = [2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0],k = 2) == 0\n assert candidate(nums = [5, 3, 2, 7, 1, 4, 6, 8, 0],k = 6) == 1\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2],k = 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],k = 10) == 12\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 25\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == 5\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 10) == 3\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 12\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6],k = 6) == 5\n assert candidate(nums = [2, 1, 0, 1, 2, 1, 0, 2, 1, 0],k = 2) == 1\n assert candidate(nums = [5, 3, 2, 8, 6, 7, 10, 1, 4],k = 6) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 2) == 5\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 25\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],k = 600) == 300\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 10) == 30\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 55) == 25\n", "comparison": "exact"}, "public_tests": ["[2,3,0,0,2]\n4", "[0,1,3,3]\n5", "[1,1,2]\n1"], "hints": ["There needs to be at least one value among 3 consecutive values in the array that is greater than or equal to k.", "The problem can be solved using dynamic programming.", "Let dp[i] be the minimum number of increment operations required to make the subarray consisting of the first i values beautiful, while also having the value at nums[i] >= k.", "dp[0] = max(0, k - nums[0]), dp[1] = max(0, k - nums[1]), and dp[2] = max(0, k - nums[2]).", "dp[i] = max(0, k - nums[i]) + min(dp[i - 1], dp[i - 2], dp[i - 3]) for i in the range [3, n - 1].", "The answer to the problem is min(dp[n - 1], dp[n - 2], dp[n - 3])."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minIncrementOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:06+00:00", "tests_total": 118, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def min_increment_operations(nums, k)", "container": null, "callable": "min_increment_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2920, "task_id": "maximum-points-after-collecting-coins-from-all-nodes", "difficulty": "Hard", "problem_description": "There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.\n\nStarting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.\n\nCoins at node_i can be collected in one of the following ways:\n\n- Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.\n- Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the node_j present in the subtree of node_i, coins[j] will get reduced to floor(coins[j] / 2).\n\nReturn the maximum points you can get after collecting the coins from all the tree nodes.\n\nExample 1:\n\nInput: edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5\nOutput: 11\nExplanation:\nCollect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.\nCollect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.\nCollect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.\nCollect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.\nIt can be shown that the maximum points we can get after collecting coins from all the nodes is 11.\n\nExample 2:\n\nInput: edges = [[0,1],[0,2]], coins = [8,4,4], k = 0\nOutput: 16\nExplanation:\nCoins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.\n\nConstraints:\n\n- n == coins.length\n- 2 <= n <= 10^5\n- 0 <= coins[i] <= 10^4\n- edges.length == n - 1\n- 0 <= edges[i][0], edges[i][1] < n\n- 0 <= k <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [1, 2], [2, 3]],coins = [10, 10, 3, 3],k = 5) == 11\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]],coins = [10, 20, 30, 40, 50, 60],k = 15) == 120\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4]],coins = [100, 50, 25, 12, 6],k = 10) == 152\n assert candidate(edges = [[0, 1], [0, 2], [0, 3]],coins = [1000, 2000, 3000, 4000],k = 500) == 8000\n assert candidate(edges = [[0, 1]],coins = [10000, 1],k = 5000) == 5000\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]],coins = [100, 50, 20, 10, 5, 2],k = 10) == 146\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4]],coins = [15, 10, 5, 2, 3],k = 6) == 16\n assert candidate(edges = [[0, 1], [0, 2]],coins = [8, 4, 4],k = 0) == 16\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],coins = [10, 20, 30, 40, 5, 6, 7, 8, 9, 1],k = 5) == 96\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8]],coins = [100, 50, 50, 20, 20, 10, 10, 5, 5],k = 10) == 204\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 20) == 540\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31]],coins = [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],k = 1) == 496\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],coins = [500, 250, 125, 62, 31, 15, 7, 3, 1, 0, 100, 50, 25, 12, 6],k = 10) == 1076\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13]],coins = [8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 500) == 13863\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]],coins = [1000, 200, 300, 400, 500, 600, 700, 800, 900],k = 200) == 3600\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],coins = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100],k = 50) == 6050\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],coins = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985, 9984],k = 5000) == 79912\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],coins = [5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 2, 1, 0, 0],k = 500) == 7851\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13]],coins = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0],k = 512) == 991\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]],coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1) == 190\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],coins = [10000, 5000, 3000, 2000, 1500, 1000, 800, 600, 400, 300, 200, 100, 50, 25, 12, 6],k = 200) == 22846\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],coins = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 10) == 1967\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],coins = [1000, 500, 300, 200, 150, 100, 50],k = 100) == 1750\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],coins = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100],k = 100) == 5500\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],coins = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1],k = 50) == 5047\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8]],coins = [4000, 3000, 2000, 1500, 1200, 1000, 800, 600, 400],k = 500) == 10600\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],coins = [9999, 4999, 3333, 2500, 1250, 625, 312, 156, 78, 39],k = 1000) == 18060\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],coins = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 5) == 275\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],coins = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100],k = 25) == 6325\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19]],coins = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1024, 512, 256, 128, 64, 32, 16, 8, 4],k = 100) == 3018\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [5, 10], [6, 11], [7, 12], [7, 13], [8, 14], [9, 15], [10, 16], [11, 17], [12, 18], [13, 19]],coins = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 100) == 19000\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],coins = [1000, 500, 250, 125, 62, 31, 15, 7],k = 50) == 1731\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]],coins = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985, 9984, 9983, 9982, 9981, 9980],k = 5000) == 99800\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11]],coins = [500, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600],k = 50) == 3750\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12]],coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],k = 1) == 78\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],coins = [100, 200, 300, 400, 500, 600, 700],k = 100) == 2100\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],coins = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985],k = 1000) == 134880\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],coins = [10, 20, 30, 40, 50, 60, 70, 80],k = 15) == 240\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],coins = [500, 300, 200, 150, 100, 80, 60, 40, 30, 20, 10],k = 50) == 1120\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20]],coins = [10000, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0],k = 1000) == 15706\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],coins = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 0],k = 100) == 1566\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22]],coins = [10000, 5000, 3000, 2000, 1500, 1000, 800, 600, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1, 0, 9, 8, 7, 6],k = 50) == 24361\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],coins = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],k = 50) == 1714\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],coins = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 50) == 11250\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],coins = [100, 200, 150, 50, 10, 20, 30],k = 25) == 430\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23]],coins = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 0, 100, 50, 25, 12, 6, 3, 1, 0, 100, 50, 25, 12, 6],k = 100) == 1619\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],coins = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],k = 100) == 1566\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16]],coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170],k = 10) == 1360\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],coins = [10000, 5000, 3000, 2000, 1500, 1000, 800, 600, 400, 300, 200],k = 1000) == 18275\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220],k = 10) == 2310\n", "comparison": "exact"}, "public_tests": ["[[0,1],[1,2],[2,3]]\n[10,10,3,3]\n5", "[[0,1],[0,2]]\n[8,4,4]\n0"], "hints": ["Let dp[x][t] be the maximum points we can get from the subtree rooted at node x and the second operation has been used t times in its ancestors.", "Note that the value of each node <= 10^4, so when t >= 14 dp[x][t] is always 0.", "General equation will be: dp[x][t] = max((coins[x] >> t) - k + sigma(dp[y][t]), (coins[x] >> (t + 1)) + sigma(dp[y][t + 1])) where nodes denoted by y in the sigma, are the direct children of node x."], "metadata": {"canonical_parameter_names": ["edges", "coins", "k"], "leetcode_dataset_entry_point": "Solution().maximumPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:08+00:00", "tests_total": 55, "tests_dropped": 5, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "tree", "depth-first-search", "memoization", "dp-on-trees"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_points(edges, coins, k)", "container": null, "callable": "maximum_points", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "coins", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2923, "task_id": "find-champion-i", "difficulty": "Easy", "problem_description": "There are n teams numbered from 0 to n - 1 in a tournament.\n\nGiven a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.\n\nTeam a will be the champion of the tournament if there is no team b that is stronger than team a.\n\nReturn the team that will be the champion of the tournament.\n\nExample 1:\n\nInput: grid = [[0,1],[0,0]]\nOutput: 0\nExplanation: There are two teams in this tournament.\ngrid[0][1] == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.\n\nExample 2:\n\nInput: grid = [[0,0,1],[1,0,1],[0,0,0]]\nOutput: 1\nExplanation: There are three teams in this tournament.\ngrid[1][0] == 1 means that team 1 is stronger than team 0.\ngrid[1][2] == 1 means that team 1 is stronger than team 2.\nSo team 1 will be the champion.\n\nConstraints:\n\n- n == grid.length\n- n == grid[i].length\n- 2 <= n <= 100\n- grid[i][j] is either 0 or 1.\n- For all i grid[i][i] is 0.\n- For all i, j that i != j, grid[i][j] != grid[j][i].\n- The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 1, 1, 1], [0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 0, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 1], [1, 0, 0, 1], [1, 1, 0, 1], [0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 1], [1, 0, 1], [0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1], [0, 0, 0], [0, 1, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 1], [1, 0, 1, 1], [1, 0, 0, 1], [0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1], [0, 0, 1], [0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1], [0, 0]]) == 0\n assert candidate(grid = [[0, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[0, 1, 1, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 1, 1], [1, 0, 0, 0, 1], [1, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 1], [1, 0, 1, 1, 1], [1, 0, 0, 1, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 1, 0, 0, 1], [0, 1, 0, 1, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 0], [0, 0, 0, 0, 1], [0, 0, 1, 0, 1], [1, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 0, 1, 0], [1, 1, 0, 0, 1, 0, 1, 0, 0], [1, 0, 0, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 0, 1, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 1, 1], [1, 0, 1, 1, 0, 0], [1, 0, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1], [0, 1, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 1, 0, 1, 1, 0], [1, 0, 0, 0, 0, 1, 1, 0, 1], [1, 1, 1, 0, 0, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1, 1, 0, 1], [1, 1, 0, 1, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [1, 0, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 0, 0, 1, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 0, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 1, 0, 0], [1, 0, 1, 1, 1, 0, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0, 0, 1], [1, 0, 1, 0, 1, 1, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 1, 1, 0], [1, 1, 0, 1, 0, 0, 1, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 1, 0, 1, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 1], [1, 0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 0], [1, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 0, 0, 1], [0, 0, 0, 1, 0, 1, 1, 0], [1, 0, 0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 0, 1, 0, 1], [1, 1, 0, 0, 0, 0, 1, 1], [0, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 1, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 1, 0], [1, 0, 0, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0, 0], [1, 1, 0, 1, 0, 1, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 1], [1, 0, 0, 1, 1], [1, 1, 0, 1, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 1, 1, 0], [1, 0, 0, 1, 1], [0, 1, 0, 1, 0], [0, 0, 0, 0, 1], [1, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 1, 0, 0, 0, 1], [1, 1, 0, 0, 1, 0, 0, 0], [1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 1, 1, 0, 0, 1, 0], [1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 1], [0, 0, 1, 0, 1], [1, 0, 0, 1, 0], [1, 1, 0, 0, 1], [0, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 0, 0, 1], [1, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 0, 0, 0], [1, 1, 1, 0, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 1], [1, 1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 0, 0, 1], [1, 1, 0, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1], [1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 1, 1, 1], [1, 0, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1], [0, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 1], [0, 0, 1, 0, 1, 1, 0], [1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0], [1, 0, 1, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 1, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 1, 1, 1, 0, 1, 1], [1, 1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 0, 1, 0, 1, 1], [1, 1, 0, 1, 0, 0, 1, 1, 1], [1, 0, 1, 0, 1, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 1, 0, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 1, 0], [1, 1, 1, 1, 0, 0, 1, 0], [1, 0, 0, 0, 1, 0, 0, 1], [1, 1, 1, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 1], [0, 0, 0, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 0, 0, 1, 1], [0, 1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1], [0, 1, 0, 1, 1, 1], [0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0], [1, 0, 0, 0, 0, 1], [0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 0, 0], [0, 1, 0, 1, 1, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0], [1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1], [1, 1, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 0, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 1, 1, 0, 1], [1, 1, 1, 0, 1, 0, 0, 1], [1, 0, 0, 0, 0, 1, 1, 0], [0, 1, 0, 1, 0, 0, 0, 1], [0, 0, 1, 1, 0, 1, 0, 1], [0, 0, 0, 0, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [1, 0, 0, 1, 0, 0], [1, 1, 0, 0, 1, 0], [1, 1, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 1, 1, 0, 1, 0], [0, 0, 1, 1, 1, 0, 0, 1], [1, 0, 0, 0, 1, 1, 1, 0], [0, 0, 1, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 0, 1, 1], [0, 1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 1], [1, 0, 1, 1, 0], [1, 0, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 1, 1], [1, 0, 0, 1, 1], [1, 1, 0, 1, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 0, 1, 1, 0], [0, 0, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0], [0, 0, 0, 1, 1], [0, 1, 0, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 1], [0, 1, 0, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 1, 1, 1], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 1], [1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 0, 1, 1], [1, 0, 0, 0, 1], [0, 1, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1], [1, 1, 1, 0, 1, 1], [1, 1, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 0, 0, 1, 0], [1, 1, 0, 0, 1], [1, 1, 1, 0, 0]]) == None\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 0, 1, 1], [1, 0, 0, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0], [0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0]]) == None\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 0, 0, 1], [1, 1, 0, 0, 1, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 1, 0, 1], [1, 1, 1, 1, 0, 0, 1, 1, 0], [1, 1, 1, 0, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 1, 0, 1, 0, 1, 0, 0, 0]]) == None\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,0]]", "[[0,0,1],[1,0,1],[0,0,0]]"], "hints": ["The champion should be stronger than all the other teams."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().findChampion", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:13+00:00", "tests_total": 56, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def find_champion(grid)", "container": null, "callable": "find_champion", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2924, "task_id": "find-champion-ii", "difficulty": "Medium", "problem_description": "There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.\n\nYou are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [u_i, v_i] indicates that there is a directed edge from team u_i to team v_i in the graph.\n\nA directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.\n\nTeam a will be the champion of the tournament if there is no team b that is stronger than team a.\n\nReturn the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.\n\nNotes\n\n- A cycle is a series of nodes a_1, a_2, ..., a_n, a_{n+1} such that node a_1 is the same node as node a_{n+1}, the nodes a_1, a_2, ..., a_n are distinct, and there is a directed edge from the node a_i to node a_{i+1} for every i in the range [1, n].\n- A DAG is a directed graph that does not have any cycle.\n\nExample 1:\n\nInput: n = 3, edges = [[0,1],[1,2]]\nOutput: 0\nExplanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.\n\nExample 2:\n\nInput: n = 4, edges = [[0,2],[1,3],[1,2]]\nOutput: -1\nExplanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.\n\nConstraints:\n\n- 1 <= n <= 100\n- m == edges.length\n- 0 <= m <= n * (n - 1) / 2\n- edges[i].length == 2\n- 0 <= edge[i][j] <= n - 1\n- edges[i][0] != edges[i][1]\n- The input is generated such that if team a is stronger than team b, team b is not stronger than team a.\n- The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 2,edges = [[0, 1]]) == 0\n assert candidate(n = 3,edges = [[0, 1]]) == -1\n assert candidate(n = 2,edges = []) == -1\n assert candidate(n = 6,edges = [[0, 1], [2, 3], [4, 5]]) == -1\n assert candidate(n = 4,edges = [[0, 1], [0, 2], [1, 3], [2, 3]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == 0\n assert candidate(n = 3,edges = [[0, 1], [1, 2]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [0, 3], [0, 4]]) == 0\n assert candidate(n = 4,edges = [[0, 1], [2, 3]]) == -1\n assert candidate(n = 1,edges = []) == 0\n assert candidate(n = 3,edges = [[1, 2], [2, 0]]) == 1\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [2, 4]]) == 0\n assert candidate(n = 3,edges = [[1, 0], [2, 0]]) == -1\n assert candidate(n = 4,edges = [[0, 2], [1, 3], [1, 2]]) == -1\n assert candidate(n = 4,edges = [[0, 1], [0, 2], [0, 3]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [2, 3], [3, 4]]) == -1\n assert candidate(n = 6,edges = [[0, 1], [2, 3], [4, 5]]) == -1\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5]]) == 0\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [3, 4], [5, 6]]) == -1\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 0], [3, 4]]) == 3\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 2], [2, 3], [2, 4]]) == 0\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [5, 6], [6, 7], [7, 8], [8, 9]]) == -1\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 8], [6, 8], [7, 9], [8, 10], [9, 11], [10, 11]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 0], [0, 4]]) == -1\n assert candidate(n = 10,edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 2], [1, 3], [4, 6], [5, 7], [8, 0]]) == -1\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 0\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 8]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [0, 2], [3, 4]]) == -1\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [2, 3]]) == 0\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7]]) == 0\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 4]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 0], [5, 1]]) == -1\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 6], [4, 6]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 4], [4, 5]]) == 0\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [2, 3], [3, 0]]) == -1\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0]]) == -1\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [2, 3], [4, 5], [0, 2], [1, 3], [4, 0], [5, 1], [2, 4], [3, 5]]) == -1\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 0\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 5], [3, 6]]) == 0\n assert candidate(n = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 0\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == 1\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 3], [2, 4]]) == 0\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0]]) == -1\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]) == -1\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == -1\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 0\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == -1\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 9], [6, 9]]) == 0\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [4, 13], [5, 13], [6, 13], [7, 14], [8, 14], [9, 14]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 4], [3, 4], [4, 5]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == -1\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]]) == 0\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 6], [7, 8]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 7], [6, 8]]) == 0\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 0]]) == 1\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 7], [6, 7]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 0\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 4]]) == 0\n assert candidate(n = 8,edges = [[0, 2], [0, 3], [1, 2], [1, 4], [2, 5], [3, 5], [4, 5], [5, 6], [6, 7]]) == -1\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == 0\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8]]) == 0\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3]]) == -1\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == 0\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 6], [4, 5]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 6]]) == 0\n", "comparison": "exact"}, "public_tests": ["3\n[[0,1],[1,2]]", "4\n[[0,2],[1,3],[1,2]]"], "hints": ["The champion(s) should have in-degree 0 in the DAG."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().findChampion", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:16+00:00", "tests_total": 78, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["graph"]}, "language": "ruby", "interface": {"raw_signature": "def find_champion(n, edges)", "container": null, "callable": "find_champion", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2925, "task_id": "maximum-score-after-applying-operations-on-a-tree", "difficulty": "Medium", "problem_description": "There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.\n\nYou are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the i^th node.\n\nYou start with a score of 0. In one operation, you choose a node i, add values[i] to your score, and then set values[i] to 0. All three steps happen together as a single operation.\n\nA tree is healthy if, for every leaf node, the sum of the current values on the path from the root to that leaf is not equal to 0.\n\nReturn the maximum score you can obtain by performing this operation on the tree any number of times, so that the tree remains healthy at the end.\n\nExample 1:\n\nInput: edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]\nOutput: 11\nExplanation: We apply the operation to nodes 1, 2, 3, 4, and 5, so the values become [5,0,0,0,0,0]. The leaves are nodes 1, 3, and 5.\n- The sum of values on the path from 0 to 1 is equal to 5.\n- The sum of values on the path from 0 to 3 is equal to 5.\n- The sum of values on the path from 0 to 5 is equal to 5.\nEvery leaf has a non-zero path sum, so the tree is healthy. The score is the sum of the original values of the chosen nodes: 2 + 5 + 2 + 1 + 1 = 11.\nIt can be shown that 11 is the maximum score obtainable by performing any number of operations on the tree.\n\nExample 2:\n\nInput: edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]\nOutput: 40\nExplanation: We apply the operation to nodes 0, 2, 3, and 4, so the values become [0,10,0,0,0,3,5]. The leaves are nodes 3, 4, 5, and 6.\n- The sum of values on the path from 0 to 3 is equal to 10.\n- The sum of values on the path from 0 to 4 is equal to 10.\n- The sum of values on the path from 0 to 5 is equal to 3.\n- The sum of values on the path from 0 to 6 is equal to 5.\nEvery leaf has a non-zero path sum, so the tree is healthy. The score is the sum of the original values of the chosen nodes: 20 + 9 + 7 + 4 = 40.\nIt can be shown that 40 is the maximum score obtainable by performing any number of operations on the tree.\n\nConstraints:\n\n- 2 <= n <= 2 * 10^4\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= a_i, b_i < n\n- values.length == n\n- 1 <= values[i] <= 10^9\n- The input is generated such that edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],values = [20, 10, 9, 7, 4, 3, 5]) == 40\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [2, 4], [4, 5]],values = [5, 2, 5, 2, 1, 1]) == 11\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 135\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 118\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11]],values = [15, 8, 12, 6, 3, 9, 4, 10, 2, 7, 5, 1]) == 68\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [5, 8]],values = [20, 10, 9, 7, 4, 3, 5, 6, 2]) == 48\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [5, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15], [8, 16], [11, 17], [11, 18], [12, 19], [12, 20]],values = [1000000000, 500000000, 300000000, 200000000, 200000000, 150000000, 150000000, 100000000, 100000000, 50000000, 50000000, 50000000, 50000000, 30000000, 30000000, 30000000, 30000000, 20000000, 20000000, 20000000, 20000000]) == 2600000000\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11], [6, 12]],values = [15, 10, 20, 5, 6, 7, 8, 1, 2, 3, 4, 9, 10]) == 85\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15], [10, 16], [11, 17], [12, 18], [13, 19]],values = [100, 50, 30, 20, 10, 5, 5, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 229\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15]],values = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4]) == 550\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) == 252\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]) == 675\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26]],values = [100, 50, 30, 20, 25, 15, 10, 5, 8, 12, 9, 4, 6, 7, 3, 2, 1, 11, 13, 14, 16, 17, 18, 19, 21, 22, 23]) == 429\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11]],values = [15, 10, 8, 3, 4, 2, 5, 1, 2, 3, 6, 7]) == 53\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12]],values = [100, 50, 75, 25, 20, 15, 10, 5, 15, 10, 5, 3, 2]) == 285\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11]],values = [100, 200, 300, 10, 10, 10, 5, 5, 5, 5, 5, 5]) == 630\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [5, 8], [5, 9], [7, 10], [7, 11]],values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 770\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [5, 8], [6, 9]],values = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 585\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11]],values = [10, 20, 30, 5, 5, 5, 5, 2, 2, 1, 1, 1]) == 77\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [5, 9], [6, 10]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 65\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105]) == 1150\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],values = [30, 25, 20, 15, 10, 9, 8, 7, 6, 5, 4]) == 117\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],values = [10, 20, 30, 40, 5, 6, 7, 8, 9, 1]) == 126\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8]],values = [100, 20, 30, 40, 50, 10, 20, 30, 40]) == 320\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],values = [15, 12, 11, 8, 7, 6, 4, 2, 1, 3]) == 54\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],values = [25, 15, 12, 8, 10, 9, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 159\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],values = [10, 20, 30, 40, 50, 60, 70, 80]) == 350\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12], [5, 13], [5, 14], [6, 15], [6, 16], [7, 17], [7, 18], [8, 19], [8, 20]],values = [30, 20, 40, 50, 35, 25, 45, 15, 25, 5, 10, 6, 18, 3, 9, 2, 4, 1, 7, 12, 14]) == 346\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12]],values = [50, 30, 20, 10, 20, 15, 10, 5, 5, 1, 1, 1, 1]) == 130\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [4, 9], [5, 10], [6, 11]],values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == 7700\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [10, 23], [11, 24], [11, 25]],values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600]) == 35000\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13]],values = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5]) == 72\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],values = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 234\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 54\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],values = [5, 15, 10, 7, 3, 20, 1, 12, 8, 6, 4]) == 86\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16], [12, 17], [13, 18], [14, 19]],values = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 57\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12], [5, 13], [6, 14], [7, 15], [8, 16], [9, 17], [10, 18], [11, 19], [12, 20], [13, 21], [14, 22], [15, 23], [16, 24], [17, 25], [18, 26], [19, 27], [20, 28], [21, 29]],values = [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]) == 464\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 595\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26]],values = [50, 50, 50, 20, 20, 20, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 280\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,2],[0,3],[2,4],[4,5]]\n[5,2,5,2,1,1]", "[[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\n[20,10,9,7,4,3,5]"], "hints": ["Let dp[i] be the maximum score we can get on the subtree rooted at i and sum[i] be the sum of all the values of the subtree rooted at i.", "If we don’t take value[i] into the final score, we can take all the nodes of the subtrees rooted at i’s children.", "If we take value[i] into the score, then each subtree rooted at its children should satisfy the constraints.", "dp[x] = max(value[x] + sigma(dp[y]), sigma(sum[y])), where y is a direct child of x."], "metadata": {"canonical_parameter_names": ["edges", "values"], "leetcode_dataset_entry_point": "Solution().maximumScoreAfterOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:18+00:00", "tests_total": 47, "tests_dropped": 8, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "tree", "depth-first-search", "dp-on-trees"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_score_after_operations(edges, values)", "container": null, "callable": "maximum_score_after_operations", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "values", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2926, "task_id": "maximum-balanced-subsequence-sum", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums.\n\nA subsequence of nums having length k and consisting of indices i_0 < i_1 < ... < i_{k-1} is balanced if the following holds:\n\n- nums[i_j] - nums[i_{j-1}] >= i_j - i_{j-1}, for every j in the range [1, k - 1].\n\nA subsequence of nums having length 1 is considered balanced.\n\nReturn an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.\n\nA subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nExample 1:\n\nInput: nums = [3,3,5,6]\nOutput: 14\nExplanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.\nnums[2] - nums[0] >= 2 - 0.\nnums[3] - nums[2] >= 3 - 2.\nHence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\nThe subsequence consisting of indices 1, 2, and 3 is also valid.\nIt can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.\n\nExample 2:\n\nInput: nums = [5,-1,-3,8]\nOutput: 13\nExplanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.\nnums[3] - nums[0] >= 3 - 0.\nHence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\nIt can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.\n\nExample 3:\n\nInput: nums = [-2,-1]\nOutput: -1\nExplanation: In this example, the subsequence [-1] can be selected.\nIt is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^9 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-2, -1]) == -1\n assert candidate(nums = [3, 3, 5, 6]) == 14\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18]) == 115\n assert candidate(nums = [1, 2, 3, 5, 8, 13]) == 32\n assert candidate(nums = [-1, 0, 1, 0, -1]) == 1\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [10, 20, 30, 40, 50]) == 150\n assert candidate(nums = [-5, -4, -3, -2, -1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, -1, -3, 8]) == 13\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91]) == -91\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 231\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 11\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [-10, -20, -30, -40, -50]) == -10\n assert candidate(nums = [10, -5, 1, 100, -3]) == 110\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 5\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 1000000000\n assert candidate(nums = [-1000000000, -999999999, -999999998, -999999997, -999999996]) == -999999996\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5]) == 5\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 29\n assert candidate(nums = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55]) == 100\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 256\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]) == 375\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 5500\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 1048575\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [1, 2, 0, 3, 1, 4, 2, 5, 3, 6, 4, 7, 5, 8, 6, 9, 7, 10, 8, 11]) == 19\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\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5]) == 5\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 225\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 18\n assert candidate(nums = [33, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, -1, -3, -5, -7]) == 33\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\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]) == 30\n assert candidate(nums = [-1000000000, 1000000000, -999999999, 999999999, -999999998, 999999998, -999999997, 999999997, -999999996, 999999996]) == 1000000000\n assert candidate(nums = [-1000000000, -999999999, -999999998, -999999997, -999999996, -999999995, -999999994, -999999993, -999999992, -999999991]) == -999999991\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 10\n assert candidate(nums = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46]) == 175\n assert candidate(nums = [999999999, -999999999, 999999998, -999999998, 999999997, -999999997, 999999996, -999999996, 999999995, -999999995]) == 999999999\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 300\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50]) == 150\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 275\n assert candidate(nums = [1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609]) == 23248\n assert candidate(nums = [10, 20, 30, 40, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15, -20, -25]) == 150\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]) == 4179\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 150\n assert candidate(nums = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) == 165\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 220\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 20\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 150\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 30\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 1000000000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4]) == 10\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 100\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 1000000000\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 15, 20, 25, 30]) == 115\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 10\n assert candidate(nums = [-5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33]) == 289\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == 325\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]) == 36\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [-1000000000, 1000000000, -1000000000, 1000000000, -1000000000]) == 1000000000\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16]) == 64\n assert candidate(nums = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 150\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8]) == 8\n assert candidate(nums = [1, 4, 5, 6, 8, 10, 13, 16, 20, 25]) == 108\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 32767\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 100\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 231\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]) == 465\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4]) == 10\n assert candidate(nums = [-1, 0, 1, 0, -1, 0, 1, 0, -1, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0]) == 15\n assert candidate(nums = [1, 10, 11, 20, 30, 31, 40, 50, 51, 60]) == 304\n assert candidate(nums = [-1, -2, -3, -4, -5, 5, 4, 3, 2, 1]) == 5\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\n assert candidate(nums = [16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 16384\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10]) == 19\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [-1000000000, -999999999, -999999998, -999999997, -999999996]) == -999999996\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 100\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 1000\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 8, 7, 10, 9]) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50]) == 150\n assert candidate(nums = [-5, -5, -5, -5, -5, -5, -5, -5, -5, -5]) == -5\n assert candidate(nums = [-1000000000, 0, 1000000000, -1000000000, 0, 1000000000, -1000000000, 0, 1000000000, -1000000000]) == 1000000000\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 15\n assert candidate(nums = [1, 100, 2, 101, 3, 102, 4, 103, 5, 104]) == 109\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 50, 55, 60, 65, 70, 75, 80]) == 615\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 780\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 11\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 1000000000\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == 1045\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [-1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [-1, -2, -3, -4, -5, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5]) == 5\n assert candidate(nums = [10, 9, 8, 8, 8, 8, 8, 7, 6, 5]) == 10\n assert candidate(nums = [10, 1, 21, 2, 32, 3, 43, 4, 54, 5, 65, 6, 76, 7, 87, 8, 98, 9, 109, 10]) == 595\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 39\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5]) == 10\n assert candidate(nums = [0, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 5\n assert candidate(nums = [40, 35, 30, 25, 20, 15, 10, 5, 1, -5]) == 40\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120]) == 2310\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 400\n assert candidate(nums = [100, 200, 300, 400, 500, -100, -200, -300, -400, -500, 150, 250, 350, 450, 550]) == 2050\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == 30\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == -1\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 11\n assert candidate(nums = [1, -1000000000, 2, -999999999, 3, -999999998, 4, -999999997, 5, -999999996]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 15\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000]) == 1000000000\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\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 1540\n assert candidate(nums = [524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 524288\n assert candidate(nums = [5, 3, 8, 6, 11, 9, 14, 12, 17, 15, 20, 18, 23, 21, 26, 24, 29, 27, 30, 25]) == 165\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 100\n assert candidate(nums = [10, 1, 11, 2, 12, 3, 13, 4, 14, 5]) == 18\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(nums = [0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13]) == 36\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000]) == -100\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\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [10, -9, 8, -7, 6, -5, 4, -3, 2, -1]) == 10\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15]) == 64\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6]) == 6\n assert candidate(nums = [5, 3, 5, 10, 15, 20, 25, 30, 35, 40]) == 183\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 1200\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5]) == 17\n", "comparison": "exact"}, "public_tests": ["[3,3,5,6]", "[5,-1,-3,8]", "[-2,-1]"], "hints": ["Let dp[x] represent the maximum sum of a balanced subsequence ending at x.", "Rewriting the formula nums[i_j] - nums[i_{j-1}] >= i_j - i_{j-1} gives nums[i_j] - i_j >= nums[i_{j-1}] - i_{j-1}.", "So, for some index x, we need to find an index y, y < x, such that dp[x] = nums[x] + dp[y] is maximized, and nums[x] - x >= nums[y] - y.", "There are many ways to achieve this. One method involves sorting the values of nums[x] - x for all indices x and using a segment/Fenwick tree with coordinate compression.", "Hence, using a dictionary or map, let's call it dict, where dict[nums[x] - x] represents the position of the value, nums[x] - x, in the segment tree.", "The tree is initialized with zeros initially.", "For indices x in order from [0, n - 1], dp[x] = max(nums[x], nums[x] + the maximum query from the tree in the range [0, dict[nums[x] - x]]), and if dp[x] is greater than the value in the tree at position dict[nums[x] - x], we update the value in the tree.", "The answer to the problem is the maximum value in dp."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxBalancedSubsequenceSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:20+00:00", "tests_total": 159, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "binary-indexed-tree", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def max_balanced_subsequence_sum(nums)", "container": null, "callable": "max_balanced_subsequence_sum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2928, "task_id": "distribute-candies-among-children-i", "difficulty": "Easy", "problem_description": "You are given two positive integers n and limit.\n\nReturn the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n\nExample 1:\n\nInput: n = 5, limit = 2\nOutput: 3\nExplanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n\nExample 2:\n\nInput: n = 3, limit = 3\nOutput: 10\nExplanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n\nConstraints:\n\n- 1 <= n <= 50\n- 1 <= limit <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,limit = 5) == 21\n assert candidate(n = 3,limit = 3) == 10\n assert candidate(n = 5,limit = 2) == 3\n assert candidate(n = 4,limit = 2) == 6\n assert candidate(n = 7,limit = 3) == 6\n assert candidate(n = 4,limit = 4) == 15\n assert candidate(n = 25,limit = 10) == 21\n assert candidate(n = 1,limit = 1) == 3\n assert candidate(n = 20,limit = 10) == 66\n assert candidate(n = 20,limit = 15) == 186\n assert candidate(n = 50,limit = 50) == 1326\n assert candidate(n = 15,limit = 10) == 91\n assert candidate(n = 10,limit = 1) == 0\n assert candidate(n = 35,limit = 12) == 3\n assert candidate(n = 50,limit = 1) == 0\n assert candidate(n = 18,limit = 6) == 1\n assert candidate(n = 28,limit = 8) == 0\n assert candidate(n = 31,limit = 9) == 0\n assert candidate(n = 42,limit = 3) == 0\n assert candidate(n = 30,limit = 3) == 0\n assert candidate(n = 40,limit = 15) == 21\n assert candidate(n = 32,limit = 11) == 3\n assert candidate(n = 32,limit = 8) == 0\n assert candidate(n = 15,limit = 3) == 0\n assert candidate(n = 50,limit = 20) == 66\n assert candidate(n = 27,limit = 9) == 1\n assert candidate(n = 45,limit = 15) == 1\n assert candidate(n = 28,limit = 7) == 0\n assert candidate(n = 30,limit = 5) == 0\n assert candidate(n = 33,limit = 8) == 0\n assert candidate(n = 15,limit = 7) == 28\n assert candidate(n = 50,limit = 25) == 351\n assert candidate(n = 22,limit = 7) == 0\n assert candidate(n = 37,limit = 18) == 171\n assert candidate(n = 30,limit = 8) == 0\n assert candidate(n = 49,limit = 17) == 6\n assert candidate(n = 40,limit = 20) == 231\n assert candidate(n = 10,limit = 2) == 0\n assert candidate(n = 38,limit = 19) == 210\n assert candidate(n = 33,limit = 6) == 0\n assert candidate(n = 49,limit = 25) == 375\n assert candidate(n = 30,limit = 12) == 28\n assert candidate(n = 35,limit = 8) == 0\n assert candidate(n = 42,limit = 12) == 0\n assert candidate(n = 30,limit = 10) == 1\n assert candidate(n = 50,limit = 10) == 0\n assert candidate(n = 49,limit = 16) == 0\n assert candidate(n = 30,limit = 20) == 331\n assert candidate(n = 45,limit = 20) == 136\n assert candidate(n = 48,limit = 16) == 1\n assert candidate(n = 49,limit = 14) == 0\n assert candidate(n = 10,limit = 3) == 0\n assert candidate(n = 28,limit = 10) == 6\n assert candidate(n = 15,limit = 5) == 1\n assert candidate(n = 40,limit = 5) == 0\n assert candidate(n = 15,limit = 4) == 0\n assert candidate(n = 35,limit = 10) == 0\n assert candidate(n = 10,limit = 4) == 6\n assert candidate(n = 33,limit = 11) == 1\n assert candidate(n = 49,limit = 18) == 21\n assert candidate(n = 27,limit = 10) == 10\n assert candidate(n = 10,limit = 20) == 66\n assert candidate(n = 22,limit = 11) == 78\n assert candidate(n = 27,limit = 8) == 0\n assert candidate(n = 35,limit = 7) == 0\n assert candidate(n = 10,limit = 10) == 66\n assert candidate(n = 42,limit = 21) == 253\n assert candidate(n = 42,limit = 9) == 0\n assert candidate(n = 49,limit = 20) == 78\n assert candidate(n = 20,limit = 2) == 0\n assert candidate(n = 35,limit = 20) == 306\n", "comparison": "exact"}, "public_tests": ["5\n2", "3\n3"], "hints": ["Use three nested for loops to check all the triplets."], "metadata": {"canonical_parameter_names": ["n", "limit"], "leetcode_dataset_entry_point": "Solution().distributeCandies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:25+00:00", "tests_total": 71, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "combinatorics", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def distribute_candies(n, limit)", "container": null, "callable": "distribute_candies", "parameters": [{"name": "n", "type": "Integer"}, {"name": "limit", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2929, "task_id": "distribute-candies-among-children-ii", "difficulty": "Medium", "problem_description": "You are given two positive integers n and limit.\n\nReturn the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n\nExample 1:\n\nInput: n = 5, limit = 2\nOutput: 3\nExplanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n\nExample 2:\n\nInput: n = 3, limit = 3\nOutput: 10\nExplanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n\nConstraints:\n\n- 1 <= n <= 10^6\n- 1 <= limit <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 7,limit = 7) == 36\n assert candidate(n = 1000000,limit = 1000000) == 500001500001\n assert candidate(n = 10,limit = 5) == 21\n assert candidate(n = 3,limit = 3) == 10\n assert candidate(n = 5,limit = 2) == 3\n assert candidate(n = 100,limit = 10) == 0\n assert candidate(n = 1000000,limit = 1) == 0\n assert candidate(n = 7,limit = 3) == 6\n assert candidate(n = 1,limit = 1) == 3\n assert candidate(n = 7,limit = 10) == 36\n assert candidate(n = 100,limit = 50) == 1326\n assert candidate(n = 10000,limit = 500) == 0\n assert candidate(n = 150,limit = 20) == 0\n assert candidate(n = 20,limit = 10) == 66\n assert candidate(n = 1000,limit = 50) == 0\n assert candidate(n = 100000,limit = 1000) == 0\n assert candidate(n = 123456,limit = 123456) == 7620877153\n assert candidate(n = 123,limit = 45) == 91\n assert candidate(n = 123456,limit = 45678) == 92201410\n assert candidate(n = 10000,limit = 1000) == 0\n assert candidate(n = 25,limit = 10) == 21\n assert candidate(n = 30,limit = 15) == 136\n assert candidate(n = 20,limit = 7) == 3\n assert candidate(n = 1000,limit = 30) == 0\n assert candidate(n = 75,limit = 35) == 496\n assert candidate(n = 80,limit = 40) == 861\n assert candidate(n = 9,limit = 3) == 1\n assert candidate(n = 15,limit = 4) == 0\n assert candidate(n = 2000,limit = 500) == 0\n assert candidate(n = 1000000,limit = 500000) == 125000750001\n assert candidate(n = 20,limit = 4) == 0\n assert candidate(n = 456,limit = 123) == 0\n assert candidate(n = 999999,limit = 100000) == 0\n assert candidate(n = 789,limit = 234) == 0\n assert candidate(n = 1000,limit = 100) == 0\n assert candidate(n = 12345,limit = 3456) == 0\n assert candidate(n = 10000,limit = 5000) == 12507501\n assert candidate(n = 500000,limit = 250000) == 31250375001\n assert candidate(n = 1000000,limit = 1000) == 0\n assert candidate(n = 999999,limit = 1000000) == 500000500000\n assert candidate(n = 20,limit = 3) == 0\n assert candidate(n = 5000,limit = 50) == 0\n assert candidate(n = 25,limit = 7) == 0\n assert candidate(n = 9,limit = 2) == 0\n assert candidate(n = 150,limit = 15) == 0\n assert candidate(n = 1000,limit = 25) == 0\n assert candidate(n = 30,limit = 30) == 496\n assert candidate(n = 800,limit = 200) == 0\n assert candidate(n = 8,limit = 8) == 45\n assert candidate(n = 999999,limit = 333333) == 1\n assert candidate(n = 50,limit = 20) == 66\n assert candidate(n = 789012,limit = 12345) == 0\n assert candidate(n = 500,limit = 10) == 0\n assert candidate(n = 20,limit = 5) == 0\n assert candidate(n = 500000,limit = 100000) == 0\n assert candidate(n = 999999,limit = 999999) == 500000500000\n assert candidate(n = 500000,limit = 1000) == 0\n assert candidate(n = 300000,limit = 1000) == 0\n assert candidate(n = 75,limit = 20) == 0\n assert candidate(n = 50,limit = 15) == 0\n assert candidate(n = 250,limit = 25) == 0\n assert candidate(n = 15,limit = 5) == 1\n assert candidate(n = 12,limit = 6) == 28\n assert candidate(n = 1000,limit = 20) == 0\n assert candidate(n = 9,limit = 4) == 10\n assert candidate(n = 5000,limit = 2000) == 501501\n assert candidate(n = 100000,limit = 300) == 0\n assert candidate(n = 75,limit = 25) == 1\n assert candidate(n = 500000,limit = 150000) == 0\n assert candidate(n = 500,limit = 200) == 5151\n assert candidate(n = 999,limit = 100) == 0\n assert candidate(n = 10000,limit = 50) == 0\n assert candidate(n = 100000,limit = 50000) == 1250075001\n assert candidate(n = 6,limit = 2) == 1\n assert candidate(n = 500000,limit = 5000) == 0\n assert candidate(n = 6,limit = 1) == 0\n assert candidate(n = 1000,limit = 1000) == 501501\n assert candidate(n = 200,limit = 50) == 0\n assert candidate(n = 200,limit = 20) == 0\n assert candidate(n = 67890,limit = 1000) == 0\n assert candidate(n = 1000,limit = 500) == 125751\n assert candidate(n = 30,limit = 10) == 1\n assert candidate(n = 50,limit = 10) == 0\n assert candidate(n = 999,limit = 333) == 1\n assert candidate(n = 25,limit = 5) == 0\n assert candidate(n = 100000,limit = 30000) == 0\n assert candidate(n = 5000,limit = 200) == 0\n assert candidate(n = 100,limit = 30) == 0\n assert candidate(n = 500,limit = 5) == 0\n assert candidate(n = 10,limit = 1) == 0\n", "comparison": "exact"}, "public_tests": ["5\n2", "3\n3"], "hints": ["We can enumerate the number of candies of one particular child, let it be i which means 0 <= i <= min(limit, n).", "Suppose the 2nd child gets j candies. Then 0 <= j <= limit and i + j <= n.", "The 3rd child will hence get n - i - j candies and we should have 0 <= n - i - j <= limit.", "After some transformations, for each i, we have max(0, n - i - limit) <= j <= min(limit, n - i), each j corresponding to a solution. So the number of solutions for some i is max(min(limit, n - i) - max(0, n - i - limit) + 1, 0). Sum the expression for every i in [0, min(n, limit)]."], "metadata": {"canonical_parameter_names": ["n", "limit"], "leetcode_dataset_entry_point": "Solution().distributeCandies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:27+00:00", "tests_total": 90, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "combinatorics", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def distribute_candies(n, limit)", "container": null, "callable": "distribute_candies", "parameters": [{"name": "n", "type": "Integer"}, {"name": "limit", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2930, "task_id": "number-of-strings-which-can-be-rearranged-to-contain-substring", "difficulty": "Medium", "problem_description": "You are given an integer n.\n\nA string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains \"leet\" as a substring.\n\nFor example:\n\n- The string \"lteer\" is good because we can rearrange it to form \"leetr\" .\n- \"letl\" is not good because we cannot rearrange it to contain \"leet\" as a substring.\n\nReturn the total number of good strings of length n.\n\nSince the answer may be large, return it modulo 10^9 + 7.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: n = 4\nOutput: 12\nExplanation: The 12 strings which can be rearranged to have \"leet\" as a substring are: \"eelt\", \"eetl\", \"elet\", \"elte\", \"etel\", \"etle\", \"leet\", \"lete\", \"ltee\", \"teel\", \"tele\", and \"tlee\".\n\nExample 2:\n\nInput: n = 10\nOutput: 83943898\nExplanation: The number of strings with length 10 which can be rearranged to have \"leet\" as a substring is 526083947580. Hence the answer is 526083947580 % (10^9 + 7) = 83943898.\n\nConstraints:\n\n- 1 <= n <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4) == 12\n assert candidate(n = 1) == 0\n assert candidate(n = 10) == 83943898\n assert candidate(n = 5) == 1460\n assert candidate(n = 3) == 0\n assert candidate(n = 125) == 558399309\n assert candidate(n = 100) == 86731066\n assert candidate(n = 50) == 232825199\n assert candidate(n = 30) == 52805056\n assert candidate(n = 2) == 0\n assert candidate(n = 80) == 974106352\n assert candidate(n = 8) == 295164156\n assert candidate(n = 250) == 889526859\n assert candidate(n = 75) == 842828500\n assert candidate(n = 20) == 291395991\n assert candidate(n = 15) == 430509685\n assert candidate(n = 9) == 947613240\n assert candidate(n = 6) == 106620\n assert candidate(n = 7) == 6058192\n assert candidate(n = 90) == 122933939\n assert candidate(n = 25) == 935610434\n", "comparison": "exact"}, "public_tests": ["4", "10"], "hints": ["A good string must contain at least one l, one t, and two e.", "Divide the problem into subproblems and use Dynamic Programming."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().stringCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:30+00:00", "tests_total": 21, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "dynamic-programming", "combinatorics"]}, "language": "ruby", "interface": {"raw_signature": "def string_count(n)", "container": null, "callable": "string_count", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2931, "task_id": "maximum-spending-after-buying-items", "difficulty": "Hard", "problem_description": "You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the j^th item in the i^th shop has a value of values[i][j]. Additionally, the items in the i^th shop are sorted in non-increasing order of value. That is, values[i][j] >= values[i][j + 1] for all 0 <= j < n - 1.\n\nOn each day, you would like to buy a single item from one of the shops. Specifically, On the d^th day you can:\n\n- Pick any shop i.\n- Buy the rightmost available item j for the price of values[i][j] * d. That is, find the greatest index j such that item j was never bought before, and buy it for the price of values[i][j] * d.\n\nNote that all items are pairwise different. For example, if you have bought item 0 from shop 1, you can still buy item 0 from any other shop.\n\nReturn the maximum amount of money that can be spent on buying all m * n products.\n\nExample 1:\n\nInput: values = [[8,5,2],[6,4,1],[9,7,3]]\nOutput: 285\nExplanation: On the first day, we buy product 2 from shop 1 for a price of values[1][2] * 1 = 1.\nOn the second day, we buy product 2 from shop 0 for a price of values[0][2] * 2 = 4.\nOn the third day, we buy product 2 from shop 2 for a price of values[2][2] * 3 = 9.\nOn the fourth day, we buy product 1 from shop 1 for a price of values[1][1] * 4 = 16.\nOn the fifth day, we buy product 1 from shop 0 for a price of values[0][1] * 5 = 25.\nOn the sixth day, we buy product 0 from shop 1 for a price of values[1][0] * 6 = 36.\nOn the seventh day, we buy product 1 from shop 2 for a price of values[2][1] * 7 = 49.\nOn the eighth day, we buy product 0 from shop 0 for a price of values[0][0] * 8 = 64.\nOn the ninth day, we buy product 0 from shop 2 for a price of values[2][0] * 9 = 81.\nHence, our total spending is equal to 285.\nIt can be shown that 285 is the maximum amount of money that can be spent buying all m * n products.\n\nExample 2:\n\nInput: values = [[10,8,6,4,2],[9,7,5,3,2]]\nOutput: 386\nExplanation: On the first day, we buy product 4 from shop 0 for a price of values[0][4] * 1 = 2.\nOn the second day, we buy product 4 from shop 1 for a price of values[1][4] * 2 = 4.\nOn the third day, we buy product 3 from shop 1 for a price of values[1][3] * 3 = 9.\nOn the fourth day, we buy product 3 from shop 0 for a price of values[0][3] * 4 = 16.\nOn the fifth day, we buy product 2 from shop 1 for a price of values[1][2] * 5 = 25.\nOn the sixth day, we buy product 2 from shop 0 for a price of values[0][2] * 6 = 36.\nOn the seventh day, we buy product 1 from shop 1 for a price of values[1][1] * 7 = 49.\nOn the eighth day, we buy product 1 from shop 0 for a price of values[0][1] * 8 = 64\nOn the ninth day, we buy product 0 from shop 1 for a price of values[1][0] * 9 = 81.\nOn the tenth day, we buy product 0 from shop 0 for a price of values[0][0] * 10 = 100.\nHence, our total spending is equal to 386.\nIt can be shown that 386 is the maximum amount of money that can be spent buying all m * n products.\n\nConstraints:\n\n- 1 <= m == values.length <= 10\n- 1 <= n == values[i].length <= 10^4\n- 1 <= values[i][j] <= 10^6\n- values[i] are sorted in non-increasing order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(values = [[10, 8, 6, 4, 2], [9, 7, 5, 3, 2]]) == 386\n assert candidate(values = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 78\n assert candidate(values = [[1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]) == 55\n assert candidate(values = [[1000000], [999999], [999998], [999997]]) == 9999990\n assert candidate(values = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 1485\n assert candidate(values = [[10], [20], [30], [40], [50]]) == 550\n assert candidate(values = [[1000000, 999999, 999998], [999997, 999996, 999995]]) == 20999965\n assert candidate(values = [[8, 5, 2], [6, 4, 1], [9, 7, 3]]) == 285\n assert candidate(values = [[5, 4, 3], [2, 1, 1]]) == 71\n assert candidate(values = [[5, 3, 1], [6, 4, 2], [7, 5, 3]]) == 222\n assert candidate(values = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 1155\n assert candidate(values = [[1000000, 999999, 999998], [1000000, 999999, 999998], [1000000, 999999, 999998]]) == 44999973\n assert candidate(values = [[100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000]]) == 32500000\n assert candidate(values = [[100, 50, 25, 10, 5], [200, 150, 75, 20, 10], [50, 25, 10, 5, 1], [400, 300, 150, 40, 20]]) == 27441\n assert candidate(values = [[15, 12, 9, 6, 3], [14, 11, 8, 5, 2], [13, 10, 7, 4, 1]]) == 1240\n assert candidate(values = [[6, 6, 6, 6, 6, 6, 6, 6, 6, 6], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 8155\n assert candidate(values = [[5, 4, 3, 2, 1], [15, 14, 13, 12, 11], [25, 24, 23, 22, 21], [35, 34, 33, 32, 31], [45, 44, 43, 42, 41]]) == 10025\n assert candidate(values = [[20, 15, 10, 5], [30, 25, 20, 15], [40, 35, 30, 25]]) == 2160\n assert candidate(values = [[1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]]) == 54999835\n assert candidate(values = [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]) == 1225\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]]) == 2550\n assert candidate(values = [[1000, 900, 800, 700, 600, 500, 400, 300, 200, 100], [950, 850, 750, 650, 550, 450, 350, 250, 150, 50], [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]]) == 454750\n assert candidate(values = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 1953\n assert candidate(values = [[1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61, 30, 15, 7, 3, 1]]) == 37999973\n assert candidate(values = [[1000000], [999999], [999998], [999997], [999996], [999995], [999994], [999993], [999992], [999991]]) == 54999835\n assert candidate(values = [[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]]) == 5425\n assert candidate(values = [[20, 18, 16, 14, 12], [19, 17, 15, 13, 11], [21, 19, 17, 15, 13], [22, 20, 18, 16, 14]]) == 3814\n assert candidate(values = [[20, 18, 16, 14, 12, 10, 8, 6, 4, 2], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]]) == 2870\n assert candidate(values = [[3, 2, 1], [6, 5, 4], [9, 8, 7]]) == 285\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]]) == 7800\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]]) == 7745\n assert candidate(values = [[1000, 500, 100], [900, 400, 90], [800, 300, 80], [700, 200, 70], [600, 100, 60]]) == 67300\n assert candidate(values = [[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], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]]) == 2520\n assert candidate(values = [[8, 6, 4, 2, 1], [10, 8, 6, 4, 2], [9, 7, 5, 3, 2]]) == 793\n assert candidate(values = [[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], [3, 3, 3, 3, 3, 3, 3, 3, 3, 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, 4, 4], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]]) == 19150\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]]) == 2550\n assert candidate(values = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 1176\n assert candidate(values = [[1000000, 500000, 250000, 125000, 62500], [100000, 50000, 25000, 12500, 6250], [1000, 500, 250, 125, 62]]) == 29258062\n assert candidate(values = [[1000000, 999998, 999996], [999999, 999997, 999995], [999994, 999992, 999990]]) == 44999876\n assert candidate(values = [[5, 3, 1], [10, 8, 6], [15, 13, 11]]) == 462\n assert candidate(values = [[9, 8, 7, 6, 5], [8, 7, 6, 5, 4], [7, 6, 5, 4, 3], [6, 5, 4, 3, 2], [5, 4, 3, 2, 1]]) == 1979\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 6, 7, 8, 9, 1, 2, 3, 4, 10], [10, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 10, 1, 2, 3, 4, 5, 6, 7, 8], [8, 9, 10, 1, 2, 3, 4, 5, 6, 7]]) == 11080\n assert candidate(values = [[1000, 500, 250, 125, 62, 31, 15, 7, 3, 1], [900, 450, 225, 112, 56, 28, 14, 7, 3, 1], [800, 400, 200, 100, 50, 25, 12, 6, 3, 1]]) == 140756\n assert candidate(values = [[100000, 90000, 80000, 70000, 60000], [100000, 90000, 80000, 70000, 60000], [100000, 90000, 80000, 70000, 60000], [100000, 90000, 80000, 70000, 60000]]) == 18400000\n assert candidate(values = [[30, 25, 20, 15, 10], [28, 23, 18, 13, 8], [26, 21, 16, 11, 6]]) == 2630\n assert candidate(values = [[7, 5, 3, 1], [8, 6, 4, 2], [9, 7, 5, 3], [10, 8, 6, 4], [11, 9, 7, 5]]) == 1562\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]) == 2775\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8, 10], [10, 8, 6, 4, 2, 1, 3, 5, 7, 9]]) == 4650\n assert candidate(values = [[500, 400, 300], [450, 350, 250], [600, 500, 400], [350, 250, 150]]) == 34200\n assert candidate(values = [[100, 90, 80, 70, 60], [95, 85, 75, 65, 55], [90, 80, 70, 60, 50], [85, 75, 65, 55, 45]]) == 16970\n assert candidate(values = [[800, 700, 600, 500], [750, 650, 550, 450], [900, 800, 700, 600], [600, 500, 400, 300]]) == 94600\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]]) == 8285\n assert candidate(values = [[15, 10, 5, 1], [14, 9, 4, 1], [13, 8, 3, 1], [12, 7, 2, 1], [11, 6, 1, 1], [10, 5, 1, 1], [9, 4, 1, 1], [8, 3, 1, 1], [7, 2, 1, 1], [6, 1, 1, 1]]) == 5735\n assert candidate(values = [[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], [3, 3, 3, 3, 3, 3, 3, 3, 3, 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, 4, 4]]) == 10100\n assert candidate(values = [[123456, 111111, 100000], [98765, 87654, 76543], [65432, 54321, 43210], [32109, 21098, 10987]]) == 6816158\n assert candidate(values = [[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]]) == 1225\n assert candidate(values = [[999999, 999998, 999997], [999996, 999995, 999994], [999993, 999992, 999991], [999990, 999989, 999988], [999987, 999986, 999985]]) == 119999320\n assert candidate(values = [[1000000, 999999, 999998, 999997, 999996], [999995, 999994, 999993, 999992, 999991], [999990, 999989, 999988, 999987, 999986]]) == 119999440\n assert candidate(values = [[20, 18, 16, 14, 12], [19, 17, 15, 13, 11], [21, 19, 17, 15, 13]]) == 2110\n assert candidate(values = [[8, 6, 4, 2, 1], [7, 5, 3, 2, 1], [9, 8, 7, 6, 5], [10, 9, 8, 7, 6]]) == 1501\n assert candidate(values = [[100, 90, 80, 70, 60], [50, 40, 30, 20, 10], [95, 85, 75, 65, 55], [45, 35, 25, 15, 5]]) == 14350\n assert candidate(values = [[50, 45, 40, 35, 30, 25, 20, 15, 10, 5], [48, 43, 38, 33, 28, 23, 18, 13, 8, 3], [46, 41, 36, 31, 26, 21, 16, 11, 6, 1]]) == 15610\n assert candidate(values = [[1000000], [999999], [999998], [999997], [999996], [999995], [999994], [999993], [999992], [999991]]) == 54999835\n assert candidate(values = [[10000, 9000, 8000, 7000, 6000], [9000, 8000, 7000, 6000, 5000], [8000, 7000, 6000, 5000, 4000], [7000, 6000, 5000, 4000, 3000], [6000, 5000, 4000, 3000, 2000]]) == 2304000\n assert candidate(values = [[5, 4, 3, 2, 1], [10, 9, 8, 7, 6], [15, 14, 13, 12, 11], [20, 19, 18, 17, 16], [25, 24, 23, 22, 21]]) == 5525\n assert candidate(values = [[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]]) == 3250\n assert candidate(values = [[50, 40, 30, 20, 10], [90, 80, 70, 60, 50], [130, 120, 110, 100, 90], [170, 160, 150, 140, 130]]) == 24300\n assert candidate(values = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11], [30, 29, 28, 27, 26, 25, 24, 23, 22, 21]]) == 9455\n assert candidate(values = [[1000, 500, 250, 125, 62], [500, 250, 125, 62, 31], [250, 125, 62, 31, 15], [125, 62, 31, 15, 7], [62, 31, 15, 7, 3]]) == 78347\n assert candidate(values = [[9, 8, 7], [6, 5, 4], [3, 2, 1], [9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 1095\n assert candidate(values = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]]) == 6225\n assert candidate(values = [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]) == 790\n", "comparison": "exact"}, "public_tests": ["[[8,5,2],[6,4,1],[9,7,3]]", "[[10,8,6,4,2],[9,7,5,3,2]]"], "hints": ["Iterate on days 1 to m * n.", "On each day, buy the product that minimizes values[i][values[i].length - 1], and pop it from values[i]."], "metadata": {"canonical_parameter_names": ["values"], "leetcode_dataset_entry_point": "Solution().maxSpending", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:32+00:00", "tests_total": 97, "tests_dropped": 25, "flags": [], "topic_tags": ["array", "greedy", "sorting", "heap-priority-queue", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def max_spending(values)", "container": null, "callable": "max_spending", "parameters": [{"name": "values", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2932, "task_id": "maximum-strong-pair-xor-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n\n- |x - y| <= min(x, y)\n\nYou need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\n\nReturn the maximum XOR value out of all possible strong pairs in the array nums.\n\nNote that you can pick the same integer twice to form a pair.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 7\nExplanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\nThe maximum XOR possible from these pairs is 3 XOR 4 = 7.\n\nExample 2:\n\nInput: nums = [10,100]\nOutput: 0\nExplanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\nThe maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n\nExample 3:\n\nInput: nums = [5,6,25,30]\nOutput: 7\nExplanation: There are 6 strong pairs in the array nums: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30).\nThe maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [15, 25, 35, 45, 55]) == 58\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == 14\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 4, 8, 16]) == 24\n assert candidate(nums = [2, 2, 4, 4, 6, 6]) == 6\n assert candidate(nums = [3, 5, 7, 9, 11]) == 14\n assert candidate(nums = [99, 98, 97, 96, 95]) == 63\n assert candidate(nums = [2, 4, 6, 8, 10]) == 14\n assert candidate(nums = [1, 3, 5, 7, 9]) == 14\n assert candidate(nums = [100]) == 0\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50]) == 60\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 122\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == 14\n assert candidate(nums = [100, 90, 80, 70, 60]) == 122\n assert candidate(nums = [10, 100]) == 0\n assert candidate(nums = [5, 6, 25, 30]) == 7\n assert candidate(nums = [7, 14, 21, 28, 35]) == 63\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == 48\n assert candidate(nums = [15, 30, 45, 60, 75]) == 119\n assert candidate(nums = [50, 40, 30, 20, 10]) == 60\n assert candidate(nums = [49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35]) == 31\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 125\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 126\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91]) == 126\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21]) == 15\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 63\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64]) == 96\n assert candidate(nums = [99, 1, 49, 50, 98, 51]) == 83\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80]) == 120\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1]) == 61\n assert candidate(nums = [100, 99, 98, 97, 96, 95]) == 63\n assert candidate(nums = [1, 10, 20, 30, 40, 50]) == 60\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 61\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == 63\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 15\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36]) == 31\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 62\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 7\n assert candidate(nums = [1, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 61\n assert candidate(nums = [29, 31, 37, 41, 43, 47, 53, 59, 61, 67]) == 126\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 63\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 124\n assert candidate(nums = [88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == 63\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 63\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99]) == 126\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 7\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 110\n assert candidate(nums = [8, 15, 23, 42, 55, 60, 62, 71]) == 123\n assert candidate(nums = [50, 49, 48, 47, 46, 45]) == 31\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [8, 10, 14, 15, 20, 22, 25]) == 30\n assert candidate(nums = [99, 99, 98, 98, 97, 97, 96, 96, 95, 95]) == 63\n assert candidate(nums = [2, 18, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]) == 125\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 31\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]) == 125\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 126\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79]) == 124\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 61\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 122\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]) == 63\n assert candidate(nums = [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 63\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 63\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77]) == 124\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[10,100]", "[5,6,25,30]"], "hints": ["The constraints are small enough to make brute-force solutions pass."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumStrongPairXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:35+00:00", "tests_total": 125, "tests_dropped": 57, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation", "trie", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_strong_pair_xor(nums)", "container": null, "callable": "maximum_strong_pair_xor", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2933, "task_id": "high-access-employees", "difficulty": "Medium", "problem_description": "You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All entries in access_times are within the same day.\n\nThe access time is represented as four digits using a 24-hour time format, for example, \"0800\" or \"2250\".\n\nAn employee is said to be high-access if he has accessed the system three or more times within a one-hour period.\n\nTimes with exactly one hour of difference are not considered part of the same one-hour period. For example, \"0815\" and \"0915\" are not part of the same one-hour period.\n\nAccess times at the start and end of the day are not counted within the same one-hour period. For example, \"0005\" and \"2350\" are not part of the same one-hour period.\n\nReturn a list that contains the names of high-access employees with any order you want.\n\nExample 1:\n\nInput: access_times = [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]\nOutput: [\"a\"]\nExplanation: \"a\" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.\nBut \"b\" does not have more than two access times at all.\nSo the answer is [\"a\"].\n\nExample 2:\n\nInput: access_times = [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]\nOutput: [\"c\",\"d\"]\nExplanation: \"c\" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.\n\"d\" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.\nHowever, \"e\" has just one access time, so it can not be in the answer and the final answer is [\"c\",\"d\"].\n\nExample 3:\n\nInput: access_times = [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]]\nOutput: [\"ab\",\"cd\"]\nExplanation: \"ab\" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.\n\"cd\" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.\nSo the answer is [\"ab\",\"cd\"].\n\nConstraints:\n\n- 1 <= access_times.length <= 100\n- access_times[i].length == 2\n- 1 <= access_times[i][0].length <= 10\n- access_times[i][0] consists only of English small letters.\n- access_times[i][1].length == 4\n- access_times[i][1] is in 24-hour time format.\n- access_times[i][1] consists only of '0' to '9'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(access_times = [['z', '1200'], ['z', '1201'], ['z', '1202'], ['z', '1203']]) == ['z']\n assert candidate(access_times = [['r', '0100'], ['r', '0159'], ['r', '0130'], ['r', '0145']]) == ['r']\n assert candidate(access_times = [['x', '0001'], ['x', '0059'], ['x', '0100'], ['x', '0159'], ['x', '0200']]) == ['x']\n assert candidate(access_times = [['m', '0001'], ['m', '2359'], ['m', '0002'], ['m', '2358']]) == []\n assert candidate(access_times = [['y', '1200'], ['y', '1201'], ['y', '1202'], ['y', '1300'], ['y', '1301'], ['y', '1302']]) == ['y']\n assert candidate(access_times = [['a', '0001'], ['a', '0002'], ['a', '2359'], ['b', '0100'], ['b', '0101'], ['b', '0102']]) == ['b']\n assert candidate(access_times = [['z', '2300'], ['z', '2359'], ['z', '0000'], ['z', '0059']]) == []\n assert candidate(access_times = [['a', '0549'], ['b', '0457'], ['a', '0532'], ['a', '0621'], ['b', '0540']]) == ['a']\n assert candidate(access_times = [['one', '1230'], ['two', '1231'], ['three', '1232'], ['four', '1233'], ['five', '1234']]) == []\n assert candidate(access_times = [['d', '0002'], ['c', '0808'], ['c', '0829'], ['e', '0215'], ['d', '1508'], ['d', '1444'], ['d', '1410'], ['c', '0809']]) == ['d', 'c']\n assert candidate(access_times = [['d', '0002'], ['c', '0808'], ['c', '0829'], ['e', '0215'], ['d', '1508'], ['d', '1444'], ['d', '1410'], ['c', '0809']]) == ['d', 'c']\n assert candidate(access_times = [['m', '1130'], ['m', '1131'], ['m', '1132'], ['m', '1230'], ['m', '1231'], ['m', '1232']]) == ['m']\n assert candidate(access_times = [['cd', '1025'], ['ab', '1025'], ['cd', '1046'], ['cd', '1055'], ['ab', '1124'], ['ab', '1120']]) == ['cd', 'ab']\n assert candidate(access_times = [['m', '0900'], ['n', '0901'], ['m', '0902'], ['m', '0903'], ['n', '0902']]) == ['m']\n assert candidate(access_times = [['x', '1200'], ['x', '1201'], ['x', '1202'], ['y', '1200'], ['y', '1201']]) == ['x']\n assert candidate(access_times = [['p', '1300'], ['q', '1400'], ['p', '1330'], ['p', '1315'], ['q', '1359']]) == ['p']\n assert candidate(access_times = [['a', '0549'], ['b', '0457'], ['a', '0532'], ['a', '0621'], ['b', '0540']]) == ['a']\n assert candidate(access_times = [['abc', '1000'], ['def', '1030'], ['ghi', '1100'], ['abc', '1001'], ['def', '1031'], ['ghi', '1101']]) == []\n assert candidate(access_times = [['u', '1300'], ['u', '1330'], ['u', '1400'], ['u', '1430'], ['u', '1500']]) == []\n assert candidate(access_times = [['p', '0859'], ['p', '0900'], ['p', '0901'], ['p', '0959'], ['p', '1000']]) == ['p']\n assert candidate(access_times = [['v', '0900'], ['v', '0915'], ['v', '0930'], ['v', '0945'], ['v', '1000']]) == ['v']\n assert candidate(access_times = [['x', '0900'], ['y', '0930'], ['x', '0915'], ['x', '0945'], ['y', '0931']]) == ['x']\n assert candidate(access_times = [['single', '1000'], ['single', '1001'], ['single', '1002']]) == ['single']\n assert candidate(access_times = [['s', '1100'], ['s', '1100'], ['s', '1100'], ['t', '1100'], ['t', '1100']]) == ['s']\n assert candidate(access_times = [['q', '0001'], ['q', '2359'], ['r', '0002'], ['r', '0003']]) == []\n assert candidate(access_times = [['repeat', '0000'], ['repeat', '0000'], ['repeat', '0000']]) == ['repeat']\n assert candidate(access_times = [['x', '0900'], ['y', '0930'], ['x', '0901'], ['x', '0959'], ['y', '0931']]) == ['x']\n assert candidate(access_times = [['f', '0001'], ['g', '0002'], ['f', '0003'], ['g', '0004'], ['f', '0005'], ['g', '0006'], ['f', '0007'], ['g', '0008'], ['f', '0009'], ['g', '0010']]) == ['f', 'g']\n assert candidate(access_times = [['a', '0100'], ['a', '0159'], ['a', '0200'], ['a', '0259'], ['a', '0300'], ['a', '0359'], ['a', '0400'], ['a', '0459']]) == []\n assert candidate(access_times = [['z', '0001'], ['z', '0101'], ['z', '0201'], ['z', '0301'], ['z', '0401'], ['z', '0501'], ['z', '0601'], ['z', '0701'], ['z', '0801'], ['z', '0901'], ['z', '1001'], ['z', '1101'], ['z', '1201'], ['z', '1301'], ['z', '1401'], ['z', '1501'], ['z', '1601'], ['z', '1701'], ['z', '1801'], ['z', '1901'], ['z', '2001'], ['z', '2101'], ['z', '2201'], ['z', '2301']]) == []\n assert candidate(access_times = [['k', '1200'], ['k', '1230'], ['k', '1259'], ['k', '1300'], ['k', '1330'], ['k', '1359'], ['k', '1400'], ['k', '1430'], ['k', '1459']]) == ['k']\n assert candidate(access_times = [['c', '1200'], ['c', '1230'], ['c', '1300'], ['c', '1330'], ['c', '1400'], ['c', '1430'], ['c', '1500'], ['c', '1530']]) == []\n assert candidate(access_times = [['charlie', '1200'], ['charlie', '1201'], ['charlie', '1202'], ['charlie', '1203'], ['charlie', '1204'], ['charlie', '1205'], ['charlie', '1206'], ['charlie', '1207'], ['charlie', '1208'], ['charlie', '1209'], ['charlie', '1210'], ['charlie', '1211'], ['charlie', '1212'], ['charlie', '1213'], ['charlie', '1214'], ['charlie', '1215'], ['charlie', '1216'], ['charlie', '1217'], ['charlie', '1218'], ['charlie', '1219'], ['charlie', '1220'], ['charlie', '1221'], ['charlie', '1222'], ['charlie', '1223'], ['charlie', '1224'], ['charlie', '1225'], ['charlie', '1226'], ['charlie', '1227'], ['charlie', '1228'], ['charlie', '1229'], ['charlie', '1230']]) == ['charlie']\n assert candidate(access_times = [['tech', '1400'], ['tech', '1405'], ['tech', '1410'], ['tech', '1415'], ['tech', '1420'], ['tech', '1425'], ['tech', '1430'], ['tech', '1435'], ['tech', '1440'], ['tech', '1445'], ['tech', '1450']]) == ['tech']\n assert candidate(access_times = [['eve', '0001'], ['eve', '0030'], ['eve', '0059'], ['eve', '0100'], ['eve', '0101'], ['eve', '0130'], ['eve', '0159'], ['eve', '0200'], ['eve', '0201'], ['eve', '0230'], ['eve', '0259'], ['eve', '0300'], ['eve', '0301'], ['eve', '0330'], ['eve', '0359'], ['eve', '0400'], ['eve', '0401'], ['eve', '0430'], ['eve', '0459'], ['eve', '0500'], ['eve', '0501'], ['eve', '0530'], ['eve', '0559'], ['eve', '0600'], ['eve', '0601'], ['eve', '0630'], ['eve', '0659'], ['eve', '0700'], ['eve', '0701'], ['eve', '0730'], ['eve', '0759'], ['eve', '0800'], ['eve', '0801'], ['eve', '0830'], ['eve', '0859'], ['eve', '0900'], ['eve', '0901'], ['eve', '0930'], ['eve', '0959'], ['eve', '1000'], ['eve', '1001'], ['eve', '1030'], ['eve', '1059'], ['eve', '1100'], ['eve', '1101'], ['eve', '1130'], ['eve', '1159'], ['eve', '1200'], ['eve', '1201'], ['eve', '1230'], ['eve', '1259'], ['eve', '1300'], ['eve', '1301'], ['eve', '1330'], ['eve', '1359'], ['eve', '1400'], ['eve', '1401'], ['eve', '1430'], ['eve', '1459'], ['eve', '1500'], ['eve', '1501'], ['eve', '1530'], ['eve', '1559'], ['eve', '1600'], ['eve', '1601'], ['eve', '1630'], ['eve', '1659'], ['eve', '1700'], ['eve', '1701'], ['eve', '1730'], ['eve', '1759'], ['eve', '1800'], ['eve', '1801'], ['eve', '1830'], ['eve', '1859'], ['eve', '1900'], ['eve', '1901'], ['eve', '1930'], ['eve', '1959'], ['eve', '2000'], ['eve', '2001'], ['eve', '2030'], ['eve', '2059'], ['eve', '2100'], ['eve', '2101'], ['eve', '2130'], ['eve', '2159'], ['eve', '2200'], ['eve', '2201'], ['eve', '2230'], ['eve', '2259'], ['eve', '2300'], ['eve', '2301'], ['eve', '2330'], ['eve', '2359']]) == ['eve']\n assert candidate(access_times = [['h', '0100'], ['i', '0101'], ['h', '0102'], ['i', '0103'], ['h', '0104'], ['i', '0105'], ['h', '0106'], ['i', '0107'], ['h', '0108'], ['i', '0109']]) == ['h', 'i']\n assert candidate(access_times = [['r', '1100'], ['r', '1130'], ['r', '1200'], ['r', '1230'], ['r', '1300'], ['r', '1330'], ['r', '1400'], ['r', '1430'], ['r', '1500'], ['r', '1530']]) == []\n assert candidate(access_times = [['t', '0515'], ['t', '0545'], ['t', '0615'], ['t', '0645'], ['t', '0715'], ['t', '0745'], ['t', '0815'], ['t', '0845'], ['t', '0915'], ['t', '0945']]) == []\n assert candidate(access_times = [['m', '0500'], ['n', '0501'], ['m', '0502'], ['n', '0503'], ['m', '0504'], ['n', '0505'], ['m', '0506'], ['n', '0507'], ['m', '0508'], ['n', '0509']]) == ['m', 'n']\n assert candidate(access_times = [['tech', '0900'], ['tech', '0930'], ['tech', '1000'], ['tech', '1030'], ['tech', '1100'], ['tech', '1130'], ['tech', '1200'], ['tech', '1230'], ['tech', '1300'], ['tech', '1330'], ['tech', '1400'], ['tech', '1430'], ['tech', '1500'], ['tech', '1530'], ['tech', '1600'], ['tech', '1630']]) == []\n assert candidate(access_times = [['z', '1500'], ['z', '1530'], ['z', '1600'], ['z', '1630'], ['z', '1700'], ['z', '1730'], ['z', '1800'], ['z', '1830'], ['z', '1900']]) == []\n assert candidate(access_times = [['m', '1200'], ['m', '1205'], ['m', '1210'], ['n', '1215'], ['n', '1220'], ['n', '1225'], ['m', '1230'], ['m', '1235'], ['m', '1240'], ['n', '1245'], ['n', '1250'], ['n', '1255']]) == ['m', 'n']\n assert candidate(access_times = [['y', '1100'], ['y', '1159'], ['y', '1200'], ['y', '1259'], ['y', '1300'], ['y', '1359'], ['y', '1400'], ['y', '1459']]) == []\n assert candidate(access_times = [['eve', '1100'], ['eve', '1101'], ['eve', '1102'], ['eve', '1159'], ['eve', '1200'], ['eve', '1201'], ['eve', '1202'], ['eve', '1259']]) == ['eve']\n assert candidate(access_times = [['beta', '1400'], ['beta', '1401'], ['beta', '1402'], ['beta', '1403'], ['beta', '1404'], ['beta', '1405'], ['beta', '1406'], ['beta', '1407']]) == ['beta']\n assert candidate(access_times = [['s', '2200'], ['s', '2230'], ['s', '2300'], ['s', '2330'], ['s', '0000'], ['s', '0030'], ['s', '0100'], ['s', '0130'], ['s', '0200'], ['s', '0230']]) == []\n assert candidate(access_times = [['r', '1300'], ['r', '1330'], ['r', '1400'], ['r', '1430'], ['r', '1500'], ['r', '1530'], ['r', '1600'], ['r', '1630'], ['r', '1700']]) == []\n assert candidate(access_times = [['a', '0001'], ['a', '0059'], ['b', '0100'], ['b', '0159'], ['c', '0200'], ['c', '0259'], ['d', '0300'], ['d', '0359'], ['e', '0400'], ['e', '0459']]) == []\n assert candidate(access_times = [['x', '0001'], ['x', '0059'], ['x', '0100'], ['x', '0159'], ['x', '0200'], ['x', '0259'], ['x', '0300'], ['x', '0359']]) == ['x']\n assert candidate(access_times = [['a', '0100'], ['a', '0115'], ['a', '0130'], ['a', '0145'], ['a', '0200'], ['a', '0215'], ['a', '0230'], ['a', '0245']]) == ['a']\n assert candidate(access_times = [['x', '1200'], ['x', '1210'], ['x', '1220'], ['x', '1300'], ['x', '1310'], ['x', '1320'], ['y', '1330'], ['y', '1340'], ['y', '1350'], ['y', '1400'], ['y', '1410'], ['y', '1420']]) == ['x', 'y']\n assert candidate(access_times = [['charlie', '1010'], ['charlie', '1011'], ['delta', '1012'], ['charlie', '1013'], ['delta', '1014'], ['charlie', '1015'], ['delta', '1016'], ['charlie', '1017']]) == ['charlie', 'delta']\n assert candidate(access_times = [['hannah', '0810'], ['hannah', '0840'], ['hannah', '0910'], ['hannah', '0940'], ['hannah', '1010'], ['hannah', '1040'], ['hannah', '1110'], ['hannah', '1140'], ['hannah', '1210'], ['hannah', '1240'], ['hannah', '1310'], ['hannah', '1340'], ['hannah', '1410'], ['hannah', '1440'], ['hannah', '1510'], ['hannah', '1540'], ['hannah', '1610'], ['hannah', '1640'], ['hannah', '1710'], ['hannah', '1740'], ['hannah', '1810'], ['hannah', '1840'], ['hannah', '1910'], ['hannah', '1940'], ['hannah', '2010'], ['hannah', '2040'], ['hannah', '2110'], ['hannah', '2140'], ['hannah', '2210'], ['hannah', '2240'], ['hannah', '2310'], ['hannah', '2340'], ['hannah', '0010'], ['hannah', '0040'], ['hannah', '0110'], ['hannah', '0140'], ['hannah', '0210'], ['hannah', '0240'], ['hannah', '0310'], ['hannah', '0340'], ['hannah', '0410'], ['hannah', '0440'], ['hannah', '0510'], ['hannah', '0540'], ['hannah', '0610'], ['hannah', '0640'], ['hannah', '0710'], ['hannah', '0740'], ['hannah', '0810'], ['hannah', '0840'], ['hannah', '0910'], ['hannah', '0940']]) == ['hannah']\n assert candidate(access_times = [['d', '1400'], ['d', '1430'], ['d', '1500'], ['d', '1530'], ['d', '1600'], ['d', '1630'], ['d', '1700'], ['d', '1730']]) == []\n assert candidate(access_times = [['v', '0800'], ['w', '0801'], ['v', '0802'], ['w', '0803'], ['v', '0804'], ['w', '0805'], ['v', '0806'], ['w', '0807'], ['v', '0808'], ['w', '0809'], ['v', '0810'], ['w', '0811'], ['v', '0812'], ['w', '0813']]) == ['v', 'w']\n assert candidate(access_times = [['x', '0101'], ['y', '0102'], ['z', '0103'], ['x', '0104'], ['y', '0105'], ['z', '0106'], ['x', '0107'], ['y', '0108'], ['z', '0109']]) == ['x', 'y', 'z']\n assert candidate(access_times = [['alice', '0800'], ['bob', '0801'], ['alice', '0830'], ['bob', '0900'], ['alice', '0930'], ['bob', '0931'], ['alice', '1000'], ['bob', '1030']]) == []\n assert candidate(access_times = [['worker', '0859'], ['worker', '0900'], ['worker', '0901'], ['worker', '0959'], ['worker', '1000'], ['worker', '1001'], ['worker', '1059'], ['worker', '1100'], ['worker', '1101']]) == ['worker']\n assert candidate(access_times = [['v', '1100'], ['v', '1101'], ['v', '1102'], ['v', '1103'], ['v', '1104'], ['v', '1105'], ['v', '1106'], ['v', '1107'], ['v', '1108'], ['v', '1109'], ['v', '1110'], ['v', '1111'], ['v', '1112'], ['v', '1113'], ['v', '1114'], ['v', '1115'], ['v', '1116'], ['v', '1117'], ['v', '1118'], ['v', '1119']]) == ['v']\n assert candidate(access_times = [['w', '2359'], ['w', '2301'], ['x', '2358'], ['x', '0002'], ['y', '2357'], ['y', '0003'], ['z', '2356'], ['z', '0004']]) == []\n assert candidate(access_times = [['l', '0715'], ['m', '0716'], ['l', '0717'], ['m', '0718'], ['l', '0719'], ['m', '0720'], ['l', '0721'], ['m', '0722'], ['l', '0723'], ['m', '0724'], ['l', '0725'], ['m', '0726'], ['l', '0727'], ['m', '0728'], ['l', '0729'], ['m', '0730']]) == ['l', 'm']\n assert candidate(access_times = [['x', '0001'], ['y', '0002'], ['x', '0003'], ['y', '0004'], ['x', '0005'], ['y', '0006'], ['x', '0007'], ['y', '0008'], ['x', '0009'], ['y', '0010']]) == ['x', 'y']\n assert candidate(access_times = [['admin', '2300'], ['admin', '2305'], ['admin', '2310'], ['admin', '2315'], ['admin', '2320'], ['admin', '2325'], ['admin', '2330'], ['admin', '2335'], ['admin', '2340'], ['admin', '2345'], ['admin', '2350']]) == ['admin']\n assert candidate(access_times = [['b', '0800'], ['b', '0859'], ['b', '0900'], ['b', '0959'], ['b', '1000'], ['b', '1059'], ['b', '1100'], ['b', '1159']]) == []\n assert candidate(access_times = [['x', '1000'], ['x', '1010'], ['x', '1020'], ['x', '1030'], ['x', '1040'], ['x', '1050']]) == ['x']\n assert candidate(access_times = [['alice', '0800'], ['alice', '0805'], ['alice', '0810'], ['bob', '0900'], ['bob', '0905'], ['bob', '0910'], ['alice', '0915'], ['alice', '0920'], ['alice', '0925']]) == ['alice', 'bob']\n assert candidate(access_times = [['s', '2300'], ['s', '2330'], ['s', '2359'], ['s', '0001'], ['s', '0030'], ['s', '0100'], ['s', '0130'], ['s', '0200'], ['s', '0230']]) == ['s']\n assert candidate(access_times = [['x', '0915'], ['y', '0916'], ['x', '0917'], ['x', '0918'], ['y', '0919'], ['y', '0920'], ['x', '0921'], ['y', '0922'], ['x', '0923']]) == ['x', 'y']\n assert candidate(access_times = [['u', '1200'], ['u', '1205'], ['u', '1210'], ['u', '1215'], ['u', '1220'], ['u', '1225'], ['u', '1230'], ['u', '1235'], ['u', '1240'], ['u', '1245'], ['u', '1250'], ['u', '1255'], ['u', '1300'], ['u', '1305']]) == ['u']\n assert candidate(access_times = [['z', '1345'], ['w', '1346'], ['z', '1347'], ['w', '1348'], ['z', '1349'], ['w', '1350'], ['z', '1351'], ['w', '1352'], ['z', '1353']]) == ['z', 'w']\n assert candidate(access_times = [['m', '1200'], ['n', '1210'], ['m', '1220'], ['n', '1230'], ['m', '1240'], ['n', '1250'], ['m', '1300'], ['n', '1310'], ['m', '1320'], ['n', '1330'], ['m', '1340'], ['n', '1350'], ['m', '1400'], ['n', '1410'], ['m', '1420'], ['n', '1430']]) == ['m', 'n']\n assert candidate(access_times = [['dev', '0100'], ['dev', '0105'], ['dev', '0110'], ['dev', '0115'], ['dev', '0120'], ['dev', '0125'], ['dev', '0130'], ['dev', '0135'], ['dev', '0140'], ['dev', '0145'], ['dev', '0150']]) == ['dev']\n assert candidate(access_times = [['y', '2359'], ['y', '0001'], ['y', '0010'], ['y', '0020'], ['y', '0030'], ['y', '0040']]) == ['y']\n assert candidate(access_times = [['a', '0800'], ['a', '0830'], ['b', '0830'], ['a', '0900'], ['b', '0900'], ['a', '0930'], ['b', '0930'], ['a', '1000'], ['b', '1000'], ['a', '1030'], ['b', '1030'], ['a', '1100'], ['b', '1100']]) == []\n assert candidate(access_times = [['q', '1000'], ['q', '1010'], ['q', '1020'], ['q', '1030'], ['q', '1040'], ['q', '1050'], ['q', '1100'], ['q', '1110'], ['q', '1120'], ['q', '1130'], ['q', '1140']]) == ['q']\n assert candidate(access_times = [['z', '0001'], ['z', '0002'], ['z', '0003'], ['z', '0004'], ['z', '0005'], ['z', '0006'], ['z', '0007'], ['z', '0008'], ['z', '0009'], ['z', '0010']]) == ['z']\n assert candidate(access_times = [['alice', '0910'], ['bob', '0911'], ['alice', '0912'], ['alice', '1009'], ['bob', '0913'], ['alice', '1010'], ['alice', '1011'], ['bob', '1008']]) == ['alice', 'bob']\n assert candidate(access_times = [['a', '0900'], ['a', '0905'], ['a', '0910'], ['a', '0915'], ['a', '0920'], ['a', '0925'], ['a', '0930'], ['a', '0935']]) == ['a']\n assert candidate(access_times = [['j', '0549'], ['k', '0457'], ['j', '0532'], ['j', '0621'], ['k', '0540'], ['j', '0533'], ['k', '0539'], ['j', '0534'], ['k', '0538'], ['j', '0535'], ['k', '0537'], ['j', '0536']]) == ['j', 'k']\n assert candidate(access_times = [['alice', '0900'], ['bob', '0901'], ['alice', '0902'], ['bob', '0903'], ['alice', '0904'], ['bob', '0905'], ['alice', '0906'], ['bob', '0907'], ['alice', '0908'], ['bob', '0909']]) == ['alice', 'bob']\n assert candidate(access_times = [['t', '0800'], ['t', '0805'], ['t', '0810'], ['t', '0815'], ['t', '0820'], ['t', '0825'], ['t', '0830'], ['t', '0835'], ['t', '0840'], ['t', '0845'], ['t', '0850'], ['t', '0855'], ['t', '0900']]) == ['t']\n assert candidate(access_times = [['u', '0910'], ['u', '0911'], ['u', '0912'], ['u', '0913'], ['u', '0914'], ['u', '0915'], ['u', '0916'], ['u', '0917'], ['u', '0918'], ['u', '0919']]) == ['u']\n assert candidate(access_times = [['a', '2300'], ['b', '2301'], ['a', '2302'], ['b', '2303'], ['a', '2304'], ['b', '2305'], ['a', '2306'], ['b', '2307'], ['a', '2308'], ['b', '2309']]) == ['a', 'b']\n assert candidate(access_times = [['grace', '1200'], ['grace', '1230'], ['grace', '1300'], ['grace', '1330'], ['grace', '1400'], ['grace', '1430'], ['grace', '1500'], ['grace', '1530'], ['grace', '1600'], ['grace', '1630'], ['grace', '1700'], ['grace', '1730'], ['grace', '1800'], ['grace', '1830'], ['grace', '1900'], ['grace', '1930'], ['grace', '2000'], ['grace', '2030'], ['grace', '2100'], ['grace', '2130'], ['grace', '2200'], ['grace', '2230'], ['grace', '2300'], ['grace', '2330'], ['grace', '0000'], ['grace', '0030'], ['grace', '0100'], ['grace', '0130'], ['grace', '0200'], ['grace', '0230'], ['grace', '0300'], ['grace', '0330'], ['grace', '0400'], ['grace', '0430'], ['grace', '0500'], ['grace', '0530'], ['grace', '0600'], ['grace', '0630'], ['grace', '0700'], ['grace', '0730'], ['grace', '0800'], ['grace', '0830'], ['grace', '0900'], ['grace', '0930'], ['grace', '1000'], ['grace', '1030'], ['grace', '1100'], ['grace', '1130']]) == []\n assert candidate(access_times = [['g', '0300'], ['g', '0315'], ['g', '0330'], ['g', '0345'], ['g', '0400'], ['g', '0415'], ['g', '0430'], ['g', '0445']]) == ['g']\n assert candidate(access_times = [['m', '0600'], ['n', '0601'], ['m', '0602'], ['n', '0603'], ['m', '0604'], ['n', '0605'], ['m', '0606'], ['n', '0607'], ['m', '0608']]) == ['m', 'n']\n assert candidate(access_times = [['omega', '0730'], ['omega', '0731'], ['omega', '0732'], ['omega', '0829'], ['omega', '0830'], ['omega', '0831'], ['omega', '0832'], ['omega', '0833']]) == ['omega']\n assert candidate(access_times = [['o', '0600'], ['o', '0630'], ['o', '0700'], ['o', '0730'], ['o', '0800'], ['o', '0830'], ['o', '0900'], ['o', '0930'], ['o', '1000'], ['o', '1030']]) == []\n assert candidate(access_times = [['x', '2350'], ['x', '0005'], ['y', '1200'], ['y', '1259'], ['z', '1300'], ['z', '1359'], ['z', '1400'], ['x', '2355']]) == []\n assert candidate(access_times = [['abc', '0910'], ['def', '0911'], ['ghi', '0912'], ['jkl', '0913'], ['mno', '0914'], ['pqr', '0915'], ['stu', '0916'], ['vwx', '0917'], ['yz', '0918']]) == []\n assert candidate(access_times = [['p', '0859'], ['q', '0900'], ['r', '0901'], ['s', '0959'], ['t', '1000'], ['u', '0859'], ['v', '0900'], ['w', '0901'], ['x', '0959'], ['y', '1000']]) == []\n assert candidate(access_times = [['p', '1000'], ['q', '1001'], ['p', '1002'], ['q', '1003'], ['p', '1004'], ['q', '1005'], ['p', '1006'], ['q', '1007'], ['p', '1008'], ['q', '1009'], ['p', '1010'], ['q', '1011']]) == ['p', 'q']\n assert candidate(access_times = [['w', '0001'], ['w', '0059'], ['w', '0101'], ['w', '0159'], ['w', '0201'], ['w', '0259'], ['w', '0301'], ['w', '0359'], ['w', '0401'], ['w', '0459']]) == []\n assert candidate(access_times = [['a', '0700'], ['a', '0710'], ['a', '0720'], ['a', '0730'], ['a', '0740'], ['a', '0750'], ['b', '0800'], ['b', '0810'], ['b', '0820'], ['b', '0830'], ['b', '0840'], ['b', '0850']]) == ['a', 'b']\n assert candidate(access_times = [['x', '1200'], ['x', '1201'], ['x', '1202'], ['y', '1200'], ['y', '1230'], ['y', '1231'], ['y', '1259'], ['x', '1300'], ['x', '1301']]) == ['x', 'y']\n assert candidate(access_times = [['alpha', '0830'], ['alpha', '0845'], ['alpha', '0859'], ['alpha', '0900'], ['alpha', '0901'], ['alpha', '0902'], ['alpha', '0903'], ['alpha', '0904']]) == ['alpha']\n assert candidate(access_times = [['l', '2300'], ['l', '2359'], ['l', '0001'], ['l', '0059'], ['l', '0101'], ['l', '0159'], ['l', '0201'], ['l', '0259'], ['l', '0301'], ['l', '0359']]) == []\n assert candidate(access_times = [['z', '0900'], ['z', '0930'], ['z', '1000'], ['z', '1030'], ['z', '1100'], ['z', '1130']]) == []\n assert candidate(access_times = [['alpha', '1330'], ['beta', '1331'], ['gamma', '1332'], ['alpha', '1333'], ['beta', '1334'], ['gamma', '1335'], ['alpha', '1336'], ['beta', '1337'], ['gamma', '1338']]) == ['alpha', 'beta', 'gamma']\n assert candidate(access_times = [['gamma', '0550'], ['gamma', '0551'], ['gamma', '0552'], ['gamma', '0649'], ['gamma', '0650'], ['gamma', '0651'], ['gamma', '0652'], ['gamma', '0653']]) == ['gamma']\n assert candidate(access_times = [['alice', '0800'], ['alice', '0830'], ['alice', '0859'], ['alice', '0900'], ['alice', '0901'], ['alice', '0930'], ['alice', '1000'], ['alice', '1030'], ['alice', '1100'], ['alice', '1130'], ['alice', '1200'], ['alice', '1230'], ['alice', '1300'], ['alice', '1330'], ['alice', '1400'], ['alice', '1430'], ['alice', '1500'], ['alice', '1530'], ['alice', '1600'], ['alice', '1630'], ['alice', '1700'], ['alice', '1730'], ['alice', '1800'], ['alice', '1830'], ['alice', '1900'], ['alice', '1930'], ['alice', '2000'], ['alice', '2030'], ['alice', '2100'], ['alice', '2130'], ['alice', '2200'], ['alice', '2230'], ['alice', '2300'], ['alice', '2330']]) == ['alice']\n assert candidate(access_times = [['dev', '0800'], ['dev', '0830'], ['dev', '0900'], ['dev', '0930'], ['dev', '1000'], ['dev', '1030'], ['dev', '1100'], ['dev', '1130'], ['dev', '1200'], ['dev', '1230'], ['dev', '1300'], ['dev', '1330'], ['dev', '1400'], ['dev', '1430'], ['dev', '1500'], ['dev', '1530'], ['dev', '1600'], ['dev', '1630'], ['dev', '1700'], ['dev', '1730']]) == []\n assert candidate(access_times = [['frank', '0001'], ['frank', '2359'], ['frank', '0002'], ['frank', '0003'], ['frank', '0004'], ['frank', '0005'], ['frank', '0006'], ['frank', '0007'], ['frank', '0008'], ['frank', '0009'], ['frank', '0010'], ['frank', '0011'], ['frank', '0012'], ['frank', '0013'], ['frank', '0014'], ['frank', '0015'], ['frank', '0016'], ['frank', '0017'], ['frank', '0018'], ['frank', '0019'], ['frank', '0020'], ['frank', '0021'], ['frank', '0022'], ['frank', '0023'], ['frank', '0024'], ['frank', '0025'], ['frank', '0026'], ['frank', '0027'], ['frank', '0028'], ['frank', '0029'], ['frank', '0030']]) == ['frank']\n assert candidate(access_times = [['n', '1234'], ['n', '1235'], ['n', '1236'], ['n', '1237'], ['n', '1238'], ['n', '1239'], ['n', '1240'], ['n', '1241'], ['n', '1242'], ['n', '1243'], ['n', '1244'], ['n', '1245'], ['n', '1246'], ['n', '1247'], ['n', '1248'], ['n', '1249']]) == ['n']\n assert candidate(access_times = [['sigma', '1100'], ['sigma', '1101'], ['sigma', '1102'], ['sigma', '1159'], ['sigma', '1200'], ['sigma', '1201'], ['sigma', '1202'], ['sigma', '1259'], ['sigma', '1300']]) == ['sigma']\n assert candidate(access_times = [['worker', '0859'], ['worker', '0900'], ['worker', '0901'], ['worker', '0959'], ['worker', '1000'], ['worker', '1001'], ['worker', '1059'], ['worker', '1100'], ['worker', '1101'], ['worker', '1159']]) == ['worker']\n assert candidate(access_times = [['z', '0001'], ['z', '0059'], ['z', '0101'], ['z', '0159'], ['z', '0201'], ['z', '0259'], ['z', '0301'], ['z', '0359']]) == []\n assert candidate(access_times = [['one', '0501'], ['two', '0502'], ['three', '0503'], ['four', '0504'], ['five', '0505'], ['six', '0506'], ['seven', '0507'], ['eight', '0508'], ['nine', '0509']]) == []\n assert candidate(access_times = [['alice', '0915'], ['bob', '1000'], ['alice', '1005'], ['alice', '1010'], ['bob', '1005'], ['alice', '1030'], ['bob', '1025'], ['alice', '1045']]) == ['alice', 'bob']\n assert candidate(access_times = [['a', '0910'], ['b', '0911'], ['a', '0912'], ['b', '0913'], ['a', '0914'], ['b', '0915'], ['a', '0916'], ['b', '0917'], ['a', '0918']]) == ['a', 'b']\n assert candidate(access_times = [['x', '0900'], ['y', '0901'], ['x', '0902'], ['x', '0959'], ['y', '0958'], ['y', '0959'], ['x', '1000'], ['y', '1001']]) == ['x', 'y']\n assert candidate(access_times = [['tom', '0800'], ['jerry', '0801'], ['tom', '0802'], ['tom', '0900'], ['jerry', '0901'], ['jerry', '0902'], ['tom', '0959'], ['jerry', '1000']]) == ['jerry']\n assert candidate(access_times = [['f', '0500'], ['f', '0515'], ['f', '0530'], ['f', '0545'], ['f', '0600'], ['f', '0615'], ['f', '0630'], ['f', '0645']]) == ['f']\n assert candidate(access_times = [['e', '0000'], ['e', '0059'], ['e', '0100'], ['e', '0159'], ['e', '0200'], ['e', '0259'], ['e', '0300'], ['e', '0359']]) == []\n", "comparison": "exact"}, "public_tests": ["[[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]", "[[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]", "[[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]]"], "hints": ["Sort the access times in each person’s list.", "A person’s name should be in the answer list if there are 2 access times in his/her access time list (after sorting), where the index difference is at least 2 and the time difference is strictly less than 60 minutes."], "metadata": {"canonical_parameter_names": ["access_times"], "leetcode_dataset_entry_point": "Solution().findHighAccessEmployees", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:37+00:00", "tests_total": 120, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "string", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def find_high_access_employees(access_times)", "container": null, "callable": "find_high_access_employees", "parameters": [{"name": "access_times", "type": "String[][]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2934, "task_id": "minimum-operations-to-maximize-last-elements-in-arrays", "difficulty": "Medium", "problem_description": "You are given two 0-indexed integer arrays, nums1 and nums2, both having length n.\n\nYou are allowed to perform a series of operations (possibly none).\n\nIn an operation, you select an index i in the range [0, n - 1] and swap the values of nums1[i] and nums2[i].\n\nYour task is to find the minimum number of operations required to satisfy the following conditions:\n\n- nums1[n - 1] is equal to the maximum value among all elements of nums1, i.e., nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]).\n- nums2[n - 1] is equal to the maximum value among all elements of nums2, i.e., nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]).\n\nReturn an integer denoting the minimum number of operations needed to meet both conditions, or -1 if it is impossible to satisfy both conditions.\n\nExample 1:\n\nInput: nums1 = [1,2,7], nums2 = [4,5,3]\nOutput: 1\nExplanation: In this example, an operation can be performed using index i = 2.\nWhen nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7].\nBoth conditions are now satisfied.\nIt can be shown that the minimum number of operations needed to be performed is 1.\nSo, the answer is 1.\n\nExample 2:\n\nInput: nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4]\nOutput: 2\nExplanation: In this example, the following operations can be performed:\nFirst operation using index i = 4.\nWhen nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9].\nAnother operation using index i = 3.\nWhen nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9].\nBoth conditions are now satisfied.\nIt can be shown that the minimum number of operations needed to be performed is 2.\nSo, the answer is 2.\n\nExample 3:\n\nInput: nums1 = [1,5,4], nums2 = [2,5,3]\nOutput: -1\nExplanation: In this example, it is not possible to satisfy both conditions.\nSo, the answer is -1.\n\nConstraints:\n\n- 1 <= n == nums1.length == nums2.length <= 1000\n- 1 <= nums1[i] <= 10^9\n- 1 <= nums2[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [5, 5, 5],nums2 = [5, 5, 5]) == 0\n assert candidate(nums1 = [1, 2],nums2 = [2, 1]) == 1\n assert candidate(nums1 = [10, 9, 8],nums2 = [7, 6, 5]) == -1\n assert candidate(nums1 = [3, 3, 3],nums2 = [3, 3, 3]) == 0\n assert candidate(nums1 = [1, 1, 1],nums2 = [1, 1, 1]) == 0\n assert candidate(nums1 = [3, 1],nums2 = [2, 2]) == -1\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [5, 3, 1],nums2 = [4, 2, 6]) == -1\n assert candidate(nums1 = [2, 3, 4, 5, 9],nums2 = [8, 8, 4, 4, 4]) == 2\n assert candidate(nums1 = [9],nums2 = [9]) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [5, 5, 5, 5]) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [15, 25, 20]) == 1\n assert candidate(nums1 = [1],nums2 = [2]) == 0\n assert candidate(nums1 = [1, 3, 5],nums2 = [2, 4, 6]) == 0\n assert candidate(nums1 = [1, 5, 4],nums2 = [2, 5, 3]) == -1\n assert candidate(nums1 = [1, 2, 7],nums2 = [4, 5, 3]) == 1\n assert candidate(nums1 = [1],nums2 = [1]) == 0\n assert candidate(nums1 = [6, 4, 2],nums2 = [5, 3, 1]) == -1\n assert candidate(nums1 = [10, 10, 10],nums2 = [10, 10, 10]) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [10, 20, 30]) == 0\n assert candidate(nums1 = [1000000000, 1000000000],nums2 = [1000000000, 1000000000]) == 0\n assert candidate(nums1 = [1, 9, 3, 7, 5],nums2 = [6, 2, 8, 4, 10]) == 2\n assert candidate(nums1 = [9, 5, 1, 4, 7, 3, 6, 8, 2, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [1000000000, 999999999, 999999998],nums2 = [1, 2, 3]) == -1\n assert candidate(nums1 = [2, 4, 6, 8, 10, 12, 14],nums2 = [14, 12, 10, 8, 6, 4, 2]) == -1\n assert candidate(nums1 = [1, 1, 2, 2, 3],nums2 = [3, 3, 2, 2, 1]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 1]) == -1\n assert candidate(nums1 = [1, 10, 3, 9, 5, 6, 4],nums2 = [2, 8, 4, 7, 10, 1, 5]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60],nums2 = [60, 50, 40, 30, 20, 10]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums1 = [3, 1, 2],nums2 = [3, 1, 2]) == -1\n assert candidate(nums1 = [5, 15, 25, 35, 45],nums2 = [45, 35, 25, 15, 5]) == -1\n assert candidate(nums1 = [1, 2, 2, 1, 2],nums2 = [2, 1, 1, 2, 1]) == 2\n assert candidate(nums1 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],nums2 = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 5\n assert candidate(nums1 = [5, 3, 8, 6, 7],nums2 = [4, 6, 2, 9, 1]) == -1\n assert candidate(nums1 = [1000000000, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 1000000000]) == 1\n assert candidate(nums1 = [8, 6, 4, 3, 1],nums2 = [7, 5, 9, 2, 10]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [10, 9, 8, 7, 6]) == -1\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 100, 200, 300, 400]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11]) == 0\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [2, 4, 6, 8, 10]) == -1\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums1 = [5, 3, 8, 6, 2, 7, 4, 1, 9],nums2 = [9, 1, 4, 7, 2, 6, 8, 3, 5]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 0\n assert candidate(nums1 = [100, 90, 80, 70, 60],nums2 = [60, 70, 80, 90, 100]) == -1\n assert candidate(nums1 = [5, 9, 1, 3, 7],nums2 = [8, 4, 6, 2, 5]) == -1\n assert candidate(nums1 = [3, 3, 3, 3, 3],nums2 = [3, 3, 3, 3, 3]) == 0\n assert candidate(nums1 = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10],nums2 = [1, 5, 3, 9, 2, 8, 4, 7, 10, 6]) == 4\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [3, 3, 3, 3, 3],nums2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums1 = [3, 2, 1, 4, 5, 6],nums2 = [6, 5, 4, 1, 2, 3]) == 3\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums1 = [1, 3, 2, 4, 5],nums2 = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [9, 1, 8, 2, 7],nums2 = [3, 6, 5, 4, 10]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [2, 4, 6, 8, 10]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [9, 7, 5, 3, 1]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums1 = [9, 8, 7, 6, 5],nums2 = [10, 9, 8, 7, 6]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == -1\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [10, 8, 6, 4, 2]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 1000000000],nums2 = [1000000000, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [2, 2, 2, 2, 2],nums2 = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [3, 3, 2, 2, 1, 1]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums1 = [5, 3, 8, 6, 7],nums2 = [4, 9, 2, 1, 10]) == 1\n assert candidate(nums1 = [7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 0\n assert candidate(nums1 = [1000000000, 1, 2],nums2 = [1, 2, 1000000000]) == 1\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [6, 6, 6, 6, 6]) == 0\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1000000000],nums2 = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [7, 14, 21, 28, 35, 42, 49],nums2 = [49, 42, 35, 28, 21, 14, 7]) == -1\n assert candidate(nums1 = [3, 3, 3, 3, 3],nums2 = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums1 = [5, 3, 1, 7, 9],nums2 = [8, 6, 4, 2, 10]) == 0\n assert candidate(nums1 = [7, 7, 7, 7, 1],nums2 = [8, 8, 8, 8, 2]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [2, 4, 6, 8, 10, 12]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [11, 9, 7, 5, 3, 1]) == -1\n assert candidate(nums1 = [9, 8, 7, 6, 5],nums2 = [1, 2, 3, 4, 10]) == 1\n assert candidate(nums1 = [1, 2, 1000000000],nums2 = [1000000000, 1, 2]) == 1\n assert candidate(nums1 = [1000000000, 1, 1, 1, 1],nums2 = [1, 1000000000, 1, 1, 1]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 3, 1, 2, 4]) == 1\n assert candidate(nums1 = [1, 2, 2, 2, 2],nums2 = [2, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1, 3, 2, 5, 4],nums2 = [4, 2, 3, 1, 5]) == 1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums1 = [9, 2, 5, 7, 1],nums2 = [1, 8, 3, 4, 6]) == -1\n assert candidate(nums1 = [3, 6, 9, 12, 15],nums2 = [15, 12, 9, 6, 3]) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 0\n assert candidate(nums1 = [50, 40, 30, 20, 10],nums2 = [10, 20, 30, 40, 50]) == -1\n assert candidate(nums1 = [5, 7, 3, 9, 2],nums2 = [8, 1, 6, 4, 10]) == -1\n assert candidate(nums1 = [10, 10, 10, 10],nums2 = [10, 10, 10, 10]) == 0\n assert candidate(nums1 = [3, 5, 1, 4, 2, 6, 8, 7, 10, 9],nums2 = [9, 7, 10, 8, 6, 4, 2, 5, 1, 3]) == -1\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == -1\n assert candidate(nums1 = [5, 8, 10, 2, 9],nums2 = [7, 6, 1, 10, 3]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [7, 3, 5, 8, 6],nums2 = [2, 4, 1, 9, 5]) == -1\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [9, 18, 27, 36, 45]) == 0\n assert candidate(nums1 = [10, 10, 10, 10, 1],nums2 = [1, 10, 10, 10, 10]) == -1\n assert candidate(nums1 = [1, 1, 2, 2, 3],nums2 = [3, 3, 2, 2, 1]) == -1\n assert candidate(nums1 = [5, 1, 8, 3, 7, 6, 4],nums2 = [4, 9, 2, 6, 1, 8, 5]) == -1\n assert candidate(nums1 = [1, 9, 3, 7, 5, 2],nums2 = [6, 8, 4, 2, 9, 1]) == -1\n assert candidate(nums1 = [9, 1, 4, 8, 5, 3],nums2 = [2, 7, 6, 3, 10, 9]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == -1\n assert candidate(nums1 = [2, 2, 2, 2, 2],nums2 = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [1, 9, 9, 9, 9, 9],nums2 = [9, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90],nums2 = [90, 80, 70, 60, 50, 40, 30, 20, 10]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10]) == -1\n assert candidate(nums1 = [5, 6, 3, 4, 7],nums2 = [4, 5, 6, 7, 8]) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == -1\n assert candidate(nums1 = [3, 3, 3, 3, 3],nums2 = [3, 3, 3, 3, 3]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,7]\n[4,5,3]", "[2,3,4,5,9]\n[8,8,4,4,4]", "[1,5,4]\n[2,5,3]"], "hints": ["Consider how to calculate the minimum number of operations when nums1[n - 1] and nums2[n - 1] are fixed (they are not swapped).", "For each index i, there are only 3 possibilities:\n- nums1[i] <= nums1[n - 1] && nums2[i] <= nums2[n - 1]. We don't need to swap them.\n- nums1[i] <= nums2[n - 1] && nums2[i] <= nums1[n - 1]. We have to swap them.\n- Otherwise, there is no solution.", "There are 2 cases to determine the minimum number of operations:\n- The first case is the number of indices that need to be swapped when nums1[n - 1] and nums2[n - 1] are fixed.\n- The second case is 1 + the number of indices that need to be swapped when nums1[n - 1] and nums2[n - 1] are swapped.", "The answer is the minimum of both cases or -1 if there is no solution in either case."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:39+00:00", "tests_total": 130, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums1, nums2)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2935, "task_id": "maximum-strong-pair-xor-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n\n- |x - y| <= min(x, y)\n\nYou need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\n\nReturn the maximum XOR value out of all possible strong pairs in the array nums.\n\nNote that you can pick the same integer twice to form a pair.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 7\nExplanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\nThe maximum XOR possible from these pairs is 3 XOR 4 = 7.\n\nExample 2:\n\nInput: nums = [10,100]\nOutput: 0\nExplanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\nThe maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n\nExample 3:\n\nInput: nums = [500,520,2500,3000]\nOutput: 1020\nExplanation: There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000).\nThe maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.\n\nConstraints:\n\n- 1 <= nums.length <= 5 * 10^4\n- 1 <= nums[i] <= 2^20 - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128]) == 192\n assert candidate(nums = [1023, 2047, 3071, 4095, 5119]) == 7168\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [100000, 100001, 100002, 100003]) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == 14\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [1023, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 768\n assert candidate(nums = [1, 3, 5, 7, 9]) == 14\n assert candidate(nums = [15, 30, 45, 60, 75, 90]) == 119\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == 14\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1023, 1024, 2047, 2048]) == 4095\n assert candidate(nums = [10, 100]) == 0\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383]) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == 0\n assert candidate(nums = [500, 520, 2500, 3000]) == 1020\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == 48\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1536\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [15, 30, 45, 60, 75]) == 119\n assert candidate(nums = [1000, 1023, 1048, 1071, 1094, 1117, 1140, 1163, 1186, 1209]) == 2032\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 30\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 125\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1992\n assert candidate(nums = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500]) == 484\n assert candidate(nums = [500, 520, 1000, 1020, 1500, 1520, 2000, 2020, 2500, 2520]) == 3644\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144]) == 393216\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 786432\n assert candidate(nums = [16384, 16385, 16386, 16387, 16388, 16389, 16390, 16391]) == 7\n assert candidate(nums = [16384, 16385, 16386, 16387, 16388, 16389, 16390, 16391, 16392, 16393, 16394, 16395, 16396, 16397, 16398, 16399, 16400, 16401, 16402, 16403, 16404, 16405, 16406, 16407, 16408, 16409, 16410, 16411, 16412, 16413, 16414, 16415]) == 31\n assert candidate(nums = [13, 29, 47, 71, 97, 131, 167, 211, 257, 307, 359, 419, 479, 541, 601]) == 1018\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 31\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984, 3968]) == 2112\n assert candidate(nums = [98765, 87654, 76543, 65432, 54321, 43210, 32109, 21098, 10987]) == 130766\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 61\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]) == 62\n assert candidate(nums = [1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240]) == 15360\n assert candidate(nums = [10000, 10050, 10100, 10150, 10200, 10250, 10300, 10350, 10400, 10450]) == 4068\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 786432\n assert candidate(nums = [127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]) == 0\n assert candidate(nums = [2047, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061]) == 4095\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 30\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 1992\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 0\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180]) == 255\n assert candidate(nums = [123456, 234567, 345678, 456789, 567890, 678901, 789012, 890123, 901234]) == 990651\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383]) == 0\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047]) == 0\n assert candidate(nums = [1048575, 1048574, 1048573, 1048572, 1048571, 1048570, 1048569, 1048568]) == 7\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225]) == 255\n assert candidate(nums = [123, 246, 369, 492, 615, 738, 861, 984, 1107, 1230, 1353]) == 1963\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]) == 62\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165]) == 253\n assert candidate(nums = [17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73]) == 126\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 35, 40]) == 61\n assert candidate(nums = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144]) == 393216\n assert candidate(nums = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 968\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 24576\n assert candidate(nums = [10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009]) == 15\n assert candidate(nums = [1, 21845, 21846, 21847, 21848, 21849, 21850, 21851, 21852, 21853, 21854, 21855]) == 15\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 786432\n assert candidate(nums = [1, 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]) == 15360\n assert candidate(nums = [1, 2, 3, 6, 7, 14, 15, 30, 31, 62, 63, 126, 127, 254, 255, 510, 511, 1022, 1023, 2046, 2047, 4094, 4095]) == 2049\n assert candidate(nums = [16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 24576\n assert candidate(nums = [123456, 123457, 123458, 123459, 123460, 123461, 123462, 123463, 123464, 123465, 123466, 123467, 123468, 123469, 123470]) == 15\n assert candidate(nums = [2047, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056]) == 4095\n assert candidate(nums = [220, 440, 880, 1760, 3520, 7040, 14080, 28160, 56320, 112640, 225280]) == 182272\n assert candidate(nums = [1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239, 11263, 12287, 13311, 14335, 15359]) == 15360\n assert candidate(nums = [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]) == 126\n assert candidate(nums = [8191, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200]) == 16383\n assert candidate(nums = [100000, 100002, 100004, 100006, 100008, 100010, 100012, 100014, 100016, 100018, 100020, 100022, 100024, 100026, 100028, 100030, 100032, 100034, 100036, 100038, 100040, 100042, 100044, 100046, 100048]) == 126\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239]) == 15360\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 250\n assert candidate(nums = [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]) == 250\n assert candidate(nums = [150000, 150001, 150002, 150003, 150004, 150005, 150006, 150007, 150008, 150009, 150010]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 210, 220, 230, 240, 250]) == 122\n assert candidate(nums = [5, 9, 14, 23, 37, 59, 92, 144, 233, 377]) == 400\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287]) == 0\n assert candidate(nums = [7, 23, 45, 79, 121, 177, 247, 327, 417, 517, 627, 747, 877, 1017]) == 978\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000]) == 15752\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 31\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]) == 795\n assert candidate(nums = [10, 20, 21, 30, 31, 32, 40, 41, 42, 43, 50, 51, 52, 53, 54, 60, 61, 62, 63, 64]) == 127\n assert candidate(nums = [314159, 271828, 141421, 161803, 707106, 353553, 414213]) == 1027891\n assert candidate(nums = [16384, 32768, 49152, 65536, 81920, 98304, 114688, 131072, 147456, 163840]) == 245760\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]) == 12463\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095]) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 12288\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 62\n assert candidate(nums = [1, 1048575, 2, 1048574, 3, 1048573, 4, 1048572, 5, 1048571]) == 7\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 6144\n assert candidate(nums = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992]) == 31\n assert candidate(nums = [1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032]) == 15\n assert candidate(nums = [511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000]) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1536\n assert candidate(nums = [500000, 500001, 500002, 500003, 500004, 500005, 500006, 500007, 500008, 500009]) == 15\n assert candidate(nums = [8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202]) == 15\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800]) == 996\n assert candidate(nums = [1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360]) == 15360\n assert candidate(nums = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 786432\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 15464\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015]) == 31\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[10,100]", "[500,520,2500,3000]"], "hints": ["Sort the array, now let x <= y which means |x - y| <= min(x, y) can now be written as y - x <= x or in other words, y <= 2 * x.", "If x and y have the same number of bits, try makingy’s bits different from x if possible for each bit starting from the second most significant bit.", "If y has 1 more bit than x and y <= 2 * x use the idea about Digit DP to make y’s prefix smaller than 2 * x + 1 as well as trying to make each bit different from x using a Hashmap.", "Alternatively, use Trie data structure to find the pair with maximum XOR."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumStrongPairXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:41+00:00", "tests_total": 127, "tests_dropped": 15, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation", "trie", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_strong_pair_xor(nums)", "container": null, "callable": "maximum_strong_pair_xor", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2937, "task_id": "make-three-strings-equal", "difficulty": "Easy", "problem_description": "You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings and delete its rightmost character. Note that you cannot completely empty a string.\n\nReturn the minimum number of operations required to make the strings equal. If it is impossible to make them equal, return -1.\n\nExample 1:\n\nInput: s1 = \"abc\", s2 = \"abb\", s3 = \"ab\"\nOutput: 2\nExplanation: Deleting the rightmost character from both s1 and s2 will result in three equal strings.\n\nExample 2:\n\nInput: s1 = \"dac\", s2 = \"bac\", s3 = \"cac\"\nOutput: -1\nExplanation: Since the first letters of s1 and s2 differ, they cannot be made equal.\n\nConstraints:\n\n- 1 <= s1.length, s2.length, s3.length <= 100\n- s1, s2 and s3 consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"abc\",s2 = \"abb\",s3 = \"ab\") == 2\n assert candidate(s1 = \"abcde\",s2 = \"abcdf\",s3 = \"abcde\") == 3\n assert candidate(s1 = \"abcd\",s2 = \"abcf\",s3 = \"abcd\") == 3\n assert candidate(s1 = \"abcd\",s2 = \"abce\",s3 = \"abcd\") == 3\n assert candidate(s1 = \"xyz\",s2 = \"xyw\",s3 = \"xyv\") == 3\n assert candidate(s1 = \"abcde\",s2 = \"abcde\",s3 = \"abcdef\") == 1\n assert candidate(s1 = \"abcde\",s2 = \"abfde\",s3 = \"abcde\") == 9\n assert candidate(s1 = \"abcdef\",s2 = \"abcghi\",s3 = \"abcjkl\") == 9\n assert candidate(s1 = \"aaa\",s2 = \"aaa\",s3 = \"aaa\") == 0\n assert candidate(s1 = \"abc\",s2 = \"abc\",s3 = \"abcd\") == 1\n assert candidate(s1 = \"a\",s2 = \"a\",s3 = \"a\") == 0\n assert candidate(s1 = \"xyz\",s2 = \"xyw\",s3 = \"xy\") == 2\n assert candidate(s1 = \"dac\",s2 = \"bac\",s3 = \"cac\") == -1\n assert candidate(s1 = \"xyz\",s2 = \"xyw\",s3 = \"xyx\") == 3\n assert candidate(s1 = \"aaaaa\",s2 = \"aaaaab\",s3 = \"aaaaac\") == 2\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdegh\",s3 = \"abcdexh\") == 7\n assert candidate(s1 = \"zzzzzzz\",s2 = \"zzzzzzz\",s3 = \"zzzzzzz\") == 0\n assert candidate(s1 = \"same\",s2 = \"same\",s3 = \"same\") == 0\n assert candidate(s1 = \"abcdabcdabcdabcd\",s2 = \"abcdabcdabcdabcd\",s3 = \"abcdabcdabcdabc\") == 2\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefg\",s3 = \"abcdefg\") == 0\n assert candidate(s1 = \"different\",s2 = \"differences\",s3 = \"differentl\") == 6\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghik\",s3 = \"abcdefghi\") == 2\n assert candidate(s1 = \"abcdefg\",s2 = \"ghijklm\",s3 = \"nopqrst\") == -1\n assert candidate(s1 = \"aabbaabb\",s2 = \"aabbaacc\",s3 = \"aabbaadd\") == 6\n assert candidate(s1 = \"pqrstu\",s2 = \"pqrstv\",s3 = \"pqrstu\") == 3\n assert candidate(s1 = \"abcdeabcde\",s2 = \"abcdeabcdf\",s3 = \"abcdeabcde\") == 3\n assert candidate(s1 = \"qwerty\",s2 = \"qwerty\",s3 = \"qwertyu\") == 1\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdeghi\",s3 = \"abcdefgj\") == 9\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbc\",s3 = \"aabcc\") == 7\n assert candidate(s1 = \"abcabcabcabcabcabc\",s2 = \"abcabcabcabcabcabc\",s3 = \"abcabcabcabcabcab\") == 2\n assert candidate(s1 = \"mississippi\",s2 = \"mississipp\",s3 = \"mississipp\") == 1\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdefga\",s3 = \"abcdefg\") == 2\n assert candidate(s1 = \"hello\",s2 = \"hell\",s3 = \"helo\") == 4\n assert candidate(s1 = \"abcdef\",s2 = \"abcde\",s3 = \"abcd\") == 3\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbc\",s3 = \"aab\") == 5\n assert candidate(s1 = \"testcase\",s2 = \"testcase\",s3 = \"testcases\") == 1\n assert candidate(s1 = \"zzzzzzzzzz\",s2 = \"zzzzzzzzzz\",s3 = \"zzzzzzzzzzz\") == 1\n assert candidate(s1 = \"aabbccdd\",s2 = \"aabbccdd\",s3 = \"aabbcddd\") == 9\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdefgh\",s3 = \"abcdefgh\") == 0\n assert candidate(s1 = \"abcdef\",s2 = \"abcxyz\",s3 = \"abcuvw\") == 9\n assert candidate(s1 = \"xyzz\",s2 = \"xyyz\",s3 = \"xyzz\") == 6\n assert candidate(s1 = \"zzzzzzzz\",s2 = \"zzzzzzzz\",s3 = \"zzzzzzzz\") == 0\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefg\",s3 = \"abcdef\") == 2\n assert candidate(s1 = \"abcdef\",s2 = \"abcdef\",s3 = \"ghijkl\") == -1\n assert candidate(s1 = \"abracadabra\",s2 = \"abracadabr\",s3 = \"abracadaba\") == 4\n assert candidate(s1 = \"abcdabcd\",s2 = \"abcdabc\",s3 = \"abcdab\") == 3\n assert candidate(s1 = \"aaaaabbbb\",s2 = \"aaaaacccc\",s3 = \"aaaaadddd\") == 12\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdefgj\",s3 = \"abcdefg\") == 2\n assert candidate(s1 = \"aaaaaa\",s2 = \"aaaaaa\",s3 = \"aaaaaaa\") == 1\n assert candidate(s1 = \"abcdef\",s2 = \"abcdeg\",s3 = \"abcdef\") == 3\n assert candidate(s1 = \"abcdef\",s2 = \"fedcba\",s3 = \"abcdef\") == -1\n assert candidate(s1 = \"qrstuv\",s2 = \"qrstuw\",s3 = \"qrstvv\") == 6\n assert candidate(s1 = \"mnop\",s2 = \"mnoq\",s3 = \"mnop\") == 3\n assert candidate(s1 = \"longerstring\",s2 = \"longeststring\",s3 = \"longerstrings\") == 23\n assert candidate(s1 = \"abcdefgxyz\",s2 = \"abcdefgxyw\",s3 = \"abcdefgxy\") == 2\n assert candidate(s1 = \"xylophone\",s2 = \"xylophon\",s3 = \"xylopho\") == 3\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdehi\",s3 = \"abcdejk\") == 6\n assert candidate(s1 = \"python\",s2 = \"pythpn\",s3 = \"pythpn\") == 6\n assert candidate(s1 = \"abcdabcd\",s2 = \"abcdabce\",s3 = \"abcdabcd\") == 3\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefg\",s3 = \"abcdefx\") == 3\n assert candidate(s1 = \"abcdabcdabcd\",s2 = \"abcdabcdabcd\",s3 = \"abcdabcdabc\") == 2\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghij\",s3 = \"abcdefghijk\") == 1\n assert candidate(s1 = \"aaaabbbb\",s2 = \"aaaabbbb\",s3 = \"aaaabbb\") == 2\n assert candidate(s1 = \"aabbccdd\",s2 = \"aabbccde\",s3 = \"aabbccdf\") == 3\n assert candidate(s1 = \"abcabc\",s2 = \"abcabc\",s3 = \"abcabd\") == 3\n assert candidate(s1 = \"a\",s2 = \"a\",s3 = \"b\") == -1\n assert candidate(s1 = \"abcdef\",s2 = \"ghijkl\",s3 = \"mnopqr\") == -1\n assert candidate(s1 = \"aabbaabb\",s2 = \"aabbaabb\",s3 = \"aabbaab\") == 2\n assert candidate(s1 = \"matching\",s2 = \"match\",s3 = \"matchi\") == 4\n assert candidate(s1 = \"unique\",s2 = \"uniquely\",s3 = \"uniquer\") == 3\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefg\",s3 = \"abcdefh\") == 3\n assert candidate(s1 = \"abcdxyz\",s2 = \"abcdwxy\",s3 = \"abcdvwx\") == 9\n assert candidate(s1 = \"programming\",s2 = \"programmer\",s3 = \"programing\") == 10\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbbc\",s3 = \"aabbbcc\") == 7\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdefgg\",s3 = \"abcdefg\") == 2\n assert candidate(s1 = \"abcdefghijk\",s2 = \"abcdefghij\",s3 = \"abcdefgh\") == 5\n assert candidate(s1 = \"mnopqr\",s2 = \"mnopqs\",s3 = \"mnopqt\") == 3\n assert candidate(s1 = \"aabbcc\",s2 = \"aabccc\",s3 = \"aabccx\") == 9\n assert candidate(s1 = \"abcxyz\",s2 = \"abcxyw\",s3 = \"abcxy\") == 2\n assert candidate(s1 = \"abcdabcd\",s2 = \"abcdabcde\",s3 = \"abcdabcd\") == 1\n assert candidate(s1 = \"zxy\",s2 = \"zyx\",s3 = \"xyz\") == -1\n assert candidate(s1 = \"zzzzz\",s2 = \"zzzzz\",s3 = \"zzzz\") == 2\n assert candidate(s1 = \"abcabcabc\",s2 = \"abcabcabc\",s3 = \"abcabcabd\") == 3\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbcd\",s3 = \"aabbbc\") == 6\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefh\",s3 = \"abcdefi\") == 3\n assert candidate(s1 = \"abcabcabcabc\",s2 = \"abcabcabcabc\",s3 = \"abcabcabcab\") == 2\n assert candidate(s1 = \"aaaaa\",s2 = \"aaaaa\",s3 = \"aaaab\") == 3\n assert candidate(s1 = \"xyzxyz\",s2 = \"xyzxyw\",s3 = \"xyzxy\") == 2\n assert candidate(s1 = \"aaaaab\",s2 = \"aaaabb\",s3 = \"aaaaab\") == 6\n assert candidate(s1 = \"abcabcabc\",s2 = \"abcabcabcd\",s3 = \"abcabcabcde\") == 3\n assert candidate(s1 = \"abcdef\",s2 = \"abcdfe\",s3 = \"abcdee\") == 6\n assert candidate(s1 = \"abcd\",s2 = \"abcde\",s3 = \"abcdf\") == 2\n assert candidate(s1 = \"xyzxyzxyz\",s2 = \"xyzxyzxy\",s3 = \"xyzxyz\") == 5\n assert candidate(s1 = \"abcdabcd\",s2 = \"abcdbcd\",s3 = \"abcdabcd\") == 11\n assert candidate(s1 = \"programming\",s2 = \"prognmming\",s3 = \"progrmming\") == 19\n assert candidate(s1 = \"abcdefghijk\",s2 = \"abcdefghijl\",s3 = \"abcdefghijk\") == 3\n assert candidate(s1 = \"abcdabcd\",s2 = \"abcdeabc\",s3 = \"abcdabcd\") == 12\n assert candidate(s1 = \"abcdabcdabcd\",s2 = \"abcdabcdabca\",s3 = \"abcdabcdabcd\") == 3\n assert candidate(s1 = \"abcabcabcabcabc\",s2 = \"abcabcabcabcabc\",s3 = \"abcabcabcabc\") == 6\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdegh\",s3 = \"abcdefg\") == 7\n assert candidate(s1 = \"zzzzzz\",s2 = \"zzzzz\",s3 = \"zzzz\") == 3\n assert candidate(s1 = \"abcabcabc\",s2 = \"abcabcaba\",s3 = \"abcabcabc\") == 3\n assert candidate(s1 = \"aaaaaaaa\",s2 = \"aaaaaaab\",s3 = \"aaaaaaac\") == 3\n assert candidate(s1 = \"aabbccdd\",s2 = \"aabbccdee\",s3 = \"aabbccdde\") == 5\n assert candidate(s1 = \"xyxzyxzy\",s2 = \"xyxzyxzz\",s3 = \"xyxzyxzq\") == 3\n assert candidate(s1 = \"abcabcabc\",s2 = \"abcabcabc\",s3 = \"abcabcab\") == 2\n assert candidate(s1 = \"zzzzzzzz\",s2 = \"zzzzzzz\",s3 = \"zzzzzz\") == 3\n assert candidate(s1 = \"abcdeabcde\",s2 = \"abcdeabced\",s3 = \"abcdeabcde\") == 6\n assert candidate(s1 = \"aabbccddeeff\",s2 = \"aabbccddeeffg\",s3 = \"aabbccddeeffh\") == 2\n assert candidate(s1 = \"hello\",s2 = \"hallo\",s3 = \"hella\") == 12\n assert candidate(s1 = \"abcabcabc\",s2 = \"abcabcabc\",s3 = \"abcabcabcd\") == 1\n assert candidate(s1 = \"aabbaabb\",s2 = \"aabbaaba\",s3 = \"aabbaabb\") == 3\n assert candidate(s1 = \"sameprefix\",s2 = \"sameprefixa\",s3 = \"sameprefixb\") == 2\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghik\",s3 = \"abcdefghil\") == 3\n assert candidate(s1 = \"aabbccddeeffgg\",s2 = \"aabbccddeeffgg\",s3 = \"aabbccddeeffgghh\") == 2\n assert candidate(s1 = \"abcabcabc\",s2 = \"abcabcabc\",s3 = \"abcabcabx\") == 3\n assert candidate(s1 = \"abacabad\",s2 = \"abacabae\",s3 = \"abacabad\") == 3\n assert candidate(s1 = \"xyzxyzxyz\",s2 = \"xyzxyzxyw\",s3 = \"xyzxyzxyv\") == 3\n assert candidate(s1 = \"xyzz\",s2 = \"xyzz\",s3 = \"xyzy\") == 3\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdexyz\",s3 = \"abcdefyz\") == 9\n assert candidate(s1 = \"abababab\",s2 = \"babababa\",s3 = \"abababab\") == -1\n assert candidate(s1 = \"abcdef\",s2 = \"abcdef\",s3 = \"abc\") == 6\n assert candidate(s1 = \"xyzxyz\",s2 = \"xyzxyz\",s3 = \"xyzxyzz\") == 1\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbbcc\",s3 = \"aabcccc\") == 11\n assert candidate(s1 = \"zzzzzz\",s2 = \"zzzzzz\",s3 = \"zzzzzz\") == 0\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n\"abb\"\n\"ab\"", "\"dac\"\n\"bac\"\n\"cac\""], "hints": ["Calculate the length of the longest common prefix of the 3 strings."], "metadata": {"canonical_parameter_names": ["s1", "s2", "s3"], "leetcode_dataset_entry_point": "Solution().findMinimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:44+00:00", "tests_total": 126, "tests_dropped": 1, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def find_minimum_operations(s1, s2, s3)", "container": null, "callable": "find_minimum_operations", "parameters": [{"name": "s1", "type": "String"}, {"name": "s2", "type": "String"}, {"name": "s3", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2938, "task_id": "separate-black-and-white-balls", "difficulty": "Medium", "problem_description": "There are n balls on a table, each ball has a color black or white.\n\nYou are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.\n\nIn each step, you can choose two adjacent balls and swap them.\n\nReturn the minimum number of steps to group all the black balls to the right and all the white balls to the left.\n\nExample 1:\n\nInput: s = \"101\"\nOutput: 1\nExplanation: We can group all the black balls to the right in the following way:\n- Swap s[0] and s[1], s = \"011\".\nInitially, 1s are not grouped together, requiring at least 1 step to group them to the right.\n\nExample 2:\n\nInput: s = \"100\"\nOutput: 2\nExplanation: We can group all the black balls to the right in the following way:\n- Swap s[0] and s[1], s = \"010\".\n- Swap s[1] and s[2], s = \"001\".\nIt can be proven that the minimum number of steps needed is 2.\n\nExample 3:\n\nInput: s = \"0111\"\nOutput: 0\nExplanation: All the black balls are already grouped to the right.\n\nConstraints:\n\n- 1 <= n == s.length <= 10^5\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"110100\") == 8\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"100100101\") == 9\n assert candidate(s = \"110011\") == 4\n assert candidate(s = \"00110011\") == 4\n assert candidate(s = \"11110000\") == 16\n assert candidate(s = \"0000\") == 0\n assert candidate(s = \"0111\") == 0\n assert candidate(s = \"111000\") == 9\n assert candidate(s = \"100\") == 2\n assert candidate(s = \"00001111\") == 0\n assert candidate(s = \"000111\") == 0\n assert candidate(s = \"101\") == 1\n assert candidate(s = \"1001001001\") == 12\n assert candidate(s = \"11111\") == 0\n assert candidate(s = \"01010101\") == 6\n assert candidate(s = \"10101010\") == 10\n assert candidate(s = \"1010101010\") == 15\n assert candidate(s = \"010101\") == 3\n assert candidate(s = \"101010\") == 6\n assert candidate(s = \"1101001\") == 8\n assert candidate(s = \"11001100\") == 12\n assert candidate(s = \"0101010101\") == 10\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"101010101010101010\") == 45\n assert candidate(s = \"11111111110000000000000000000000111111111100000000000000000\") == 560\n assert candidate(s = \"1111111111111111111110\") == 21\n assert candidate(s = \"010101010101010101010101010101010101010101010101010101010101010101010101010101010\") == 820\n assert candidate(s = \"111000111000111000\") == 54\n assert candidate(s = \"010101010101010101010101010101010101\") == 153\n assert candidate(s = \"000000000000000000000000000000111111\") == 0\n assert candidate(s = \"1000001000001000001000001000\") == 65\n assert candidate(s = \"0110110110110110110110110110\") == 90\n assert candidate(s = \"00101011010\") == 12\n assert candidate(s = \"0000000000000000000000001111\") == 0\n assert candidate(s = \"1111111111111111111111110000\") == 96\n assert candidate(s = \"110110110110110110110110110110110110110110110110110110110110110\") == 462\n assert candidate(s = \"000111000111000111000111000111000111\") == 135\n assert candidate(s = \"10101010101010101010101010\") == 91\n assert candidate(s = \"00001111000011110000\") == 48\n assert candidate(s = \"11111111111100000000\") == 96\n assert candidate(s = \"11110000000000111100\") == 56\n assert candidate(s = \"101010101010101010101010\") == 78\n assert candidate(s = \"0000000000\") == 0\n assert candidate(s = \"101010101010101010101010101\") == 91\n assert candidate(s = \"1101101101101101101101101101\") == 90\n assert candidate(s = \"0000000000000000000001\") == 0\n assert candidate(s = \"1001001001001001001001001001001001001\") == 156\n assert candidate(s = \"011011011011011011011011011011011011011011011011011011011011011\") == 420\n assert candidate(s = \"0001110001110001110001110001\") == 90\n assert candidate(s = \"000111000111000111000111\") == 54\n assert candidate(s = \"100100100100100100100\") == 56\n assert candidate(s = \"0111110111110111110111110111\") == 50\n assert candidate(s = \"10000000000000000000\") == 19\n assert candidate(s = \"111000111000111000111000111000111000\") == 189\n assert candidate(s = \"0101010101010101010101\") == 55\n assert candidate(s = \"00000000000000000000000000000000111111\") == 0\n assert candidate(s = \"0011001100110011\") == 24\n assert candidate(s = \"0000000000000000000000000000111111\") == 0\n assert candidate(s = \"00001111000011110000111100001111000011110000111100001111\") == 336\n assert candidate(s = \"00000001111111111111\") == 0\n assert candidate(s = \"0010010010010010010010010010\") == 81\n assert candidate(s = \"1001001001001001001001001001001\") == 110\n assert candidate(s = \"11110000111100001111\") == 48\n assert candidate(s = \"01010101010101010101010101\") == 78\n assert candidate(s = \"1111100000000000\") == 55\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010\") == 406\n assert candidate(s = \"100100100100100\") == 30\n assert candidate(s = \"10101001010101010101\") == 48\n assert candidate(s = \"0110110110110110110110\") == 56\n assert candidate(s = \"0000011111\") == 0\n assert candidate(s = \"11111111111111111111\") == 0\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000001\") == 0\n assert candidate(s = \"01101101101101101101101101\") == 72\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101010101010101\") == 561\n assert candidate(s = \"0000111111\") == 0\n assert candidate(s = \"111000000000\") == 27\n assert candidate(s = \"0000000000000000000000111111\") == 0\n assert candidate(s = \"001100110011\") == 12\n assert candidate(s = \"1110000000000000000000000000\") == 75\n assert candidate(s = \"001001001001001001001001001001001\") == 110\n assert candidate(s = \"01010110101010101010\") == 52\n assert candidate(s = \"00000000001111111111\") == 0\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010\") == 666\n assert candidate(s = \"100000000001\") == 10\n assert candidate(s = \"100000100001000010001000010000100001\") == 109\n assert candidate(s = \"0000000000001111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"11111111110000000000\") == 100\n assert candidate(s = \"11100011100011100011\") == 54\n assert candidate(s = \"10010010010010010010\") == 49\n assert candidate(s = \"1010101010101010101010101010\") == 105\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"000111111100000000\") == 56\n assert candidate(s = \"1001001001001001001001\") == 56\n assert candidate(s = \"00000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"11110000111100001111000011110000111100001111000011110000\") == 448\n assert candidate(s = \"011001100110011001100110011001100110\") == 162\n assert candidate(s = \"1111111000000000000000000000\") == 147\n assert candidate(s = \"11111000011110000111\") == 56\n assert candidate(s = \"000011111111111111110000\") == 64\n assert candidate(s = \"01100110011001100110\") == 50\n assert candidate(s = \"111110000111100001111\") == 56\n assert candidate(s = \"11011011011011011011\") == 42\n assert candidate(s = \"10000000001111111111100000000000111111111111100000000000\") == 416\n assert candidate(s = \"00000000001111111111111111111111000000000011111111111111111\") == 220\n assert candidate(s = \"1111111111111111111111111111\") == 0\n assert candidate(s = \"1110001110001110001110001110\") == 105\n assert candidate(s = \"00000100000100000100\") == 21\n assert candidate(s = \"0101010101010101010101010101\") == 91\n assert candidate(s = \"11111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"0110101010101010101010101010101010101010101010101010\") == 350\n assert candidate(s = \"10001000100010001000\") == 45\n assert candidate(s = \"11111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"01001001001001001001\") == 42\n assert candidate(s = \"00110011001100110011\") == 40\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001\") == 380\n assert candidate(s = \"0010010010\") == 9\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101010101\") == 465\n assert candidate(s = \"111111000000000000000000000000000000\") == 180\n assert candidate(s = \"00000111100001111000\") == 40\n assert candidate(s = \"100101001010101010\") == 40\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"00110011001100110011001100110011001100\") == 180\n assert candidate(s = \"1001001001001001001001001\") == 72\n assert candidate(s = \"0000000000000001\") == 0\n assert candidate(s = \"111110000000000000000000000000000000\") == 155\n assert candidate(s = \"0110001100001111\") == 22\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010101010101010\") == 741\n assert candidate(s = \"1010101010101010101010\") == 66\n assert candidate(s = \"1111111111\") == 0\n assert candidate(s = \"110011001100110011001100110011001100\") == 180\n assert candidate(s = \"0000000000000000011111111111111\") == 0\n assert candidate(s = \"00011100011100011100\") == 45\n assert candidate(s = \"11101110111011101110\") == 45\n assert candidate(s = \"001001001001001001001001001001001001001001001001001001001001001001\") == 462\n assert candidate(s = \"11100000011\") == 18\n assert candidate(s = \"1111110000000000000000000000000000000000000000000000000\") == 294\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\") == 351\n assert candidate(s = \"110011001100110011001100110011\") == 112\n assert candidate(s = \"01010101010101010101\") == 45\n assert candidate(s = \"1001001001001001001001001001\") == 90\n assert candidate(s = \"1000011110000111100001\") == 60\n assert candidate(s = \"101010101010101010101010101010101010\") == 171\n assert candidate(s = \"011111111111111111111111111111111111\") == 0\n assert candidate(s = \"110110110110110\") == 30\n assert candidate(s = \"10101010101010101010\") == 55\n assert candidate(s = \"111000111000111000111000\") == 90\n assert candidate(s = \"1000010000100001000010000100001\") == 84\n assert candidate(s = \"0111100001110000111000\") == 74\n assert candidate(s = \"0000000000000000000000000000\") == 0\n assert candidate(s = \"000111000111000\") == 27\n assert candidate(s = \"0000111100001111\") == 16\n", "comparison": "exact"}, "public_tests": ["\"101\"", "\"100\"", "\"0111\""], "hints": ["Every 1 in the string s should be swapped with every 0 on its right side.", "Iterate right to left and count the number of 0 that have already occurred, whenever you iterate on 1 add that counter to the answer."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumSteps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:46+00:00", "tests_total": 152, "tests_dropped": 0, "flags": [], "topic_tags": ["two-pointers", "string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_steps(s)", "container": null, "callable": "minimum_steps", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2939, "task_id": "maximum-xor-product", "difficulty": "Medium", "problem_description": "Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2^n.\n\nSince the answer may be too large, return it modulo 10^9+ 7.\n\nNote that XOR is the bitwise XOR operation.\n\nExample 1:\n\nInput: a = 12, b = 5, n = 4\nOutput: 98\nExplanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.\nIt can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2^n.\n\nExample 2:\n\nInput: a = 6, b = 7 , n = 5\nOutput: 930\nExplanation: For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.\nIt can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2^n.\n\nExample 3:\n\nInput: a = 1, b = 6, n = 3\nOutput: 12\nExplanation: For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.\nIt can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2^n.\n\nConstraints:\n\n- 0 <= a, b < 2^50\n- 0 <= n <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(a = 7,b = 14,n = 4) == 98\n assert candidate(a = 15,b = 9,n = 4) == 143\n assert candidate(a = 1,b = 2,n = 1) == 2\n assert candidate(a = 6,b = 7,n = 5) == 930\n assert candidate(a = 1024,b = 512,n = 11) == 1570305\n assert candidate(a = 3,b = 12,n = 4) == 56\n assert candidate(a = 12,b = 5,n = 4) == 98\n assert candidate(a = 249,b = 249,n = 50) == 178448631\n assert candidate(a = 0,b = 0,n = 50) == 178448631\n assert candidate(a = 0,b = 0,n = 5) == 961\n assert candidate(a = 3,b = 3,n = 2) == 9\n assert candidate(a = 8,b = 8,n = 4) == 225\n assert candidate(a = 1024,b = 512,n = 10) == 1570305\n assert candidate(a = 249,b = 248,n = 50) == 279487308\n assert candidate(a = 7,b = 3,n = 3) == 21\n assert candidate(a = 1,b = 1,n = 1) == 1\n assert candidate(a = 1,b = 6,n = 3) == 12\n assert candidate(a = 1099511627776,b = 2199023255552,n = 42) == 421746426\n assert candidate(a = 123,b = 456,n = 10) == 647348\n assert candidate(a = 1000000000,b = 1000000000,n = 30) == 388912871\n assert candidate(a = 1023456789,b = 9876543210,n = 30) == 443244632\n assert candidate(a = 4294967295,b = 1,n = 32) == 145586001\n assert candidate(a = 256,b = 1024,n = 11) == 1832193\n assert candidate(a = 25,b = 25,n = 5) == 961\n assert candidate(a = 1,b = 2499999999999,n = 50) == 63711638\n assert candidate(a = 4294967295,b = 4294967295,n = 32) == 992409480\n assert candidate(a = 0,b = 1,n = 50) == 279487308\n assert candidate(a = 1023,b = 512,n = 10) == 589056\n assert candidate(a = 123456,b = 654321,n = 20) == 306001604\n assert candidate(a = 123456789,b = 987654321,n = 35) == 251423918\n assert candidate(a = 4294967294,b = 4294967295,n = 32) == 697442213\n assert candidate(a = 8,b = 15,n = 4) == 132\n assert candidate(a = 2,b = 3,n = 50) == 279487308\n assert candidate(a = 500000000,b = 500000001,n = 30) == 315171055\n assert candidate(a = 45,b = 28,n = 6) == 1426\n assert candidate(a = 500000000,b = 1000000000,n = 35) == 632039372\n assert candidate(a = 8,b = 4,n = 3) == 77\n assert candidate(a = 1023,b = 2047,n = 11) == 2094081\n assert candidate(a = 456789123,b = 234567891,n = 35) == 765343141\n assert candidate(a = 999999999,b = 888888888,n = 45) == 179328999\n assert candidate(a = 789,b = 101112,n = 15) == 211542482\n assert candidate(a = 123456789,b = 987654321,n = 20) == 309102622\n assert candidate(a = 67890,b = 13579,n = 15) == 715925548\n assert candidate(a = 31,b = 15,n = 5) == 465\n assert candidate(a = 1000000000,b = 500000000,n = 30) == 446861332\n assert candidate(a = 111111111,b = 222222222,n = 40) == 554920250\n assert candidate(a = 1000000000,b = 2000000000,n = 49) == 857287546\n assert candidate(a = 1,b = 2147483647,n = 30) == 536396503\n assert candidate(a = 987654321,b = 123456789,n = 30) == 664805056\n assert candidate(a = 555555555,b = 666666666,n = 48) == 651387213\n assert candidate(a = 299999999,b = 299999998,n = 28) == 523486406\n assert candidate(a = 1048576,b = 2097152,n = 22) == 64477598\n assert candidate(a = 2147483647,b = 1073741823,n = 31) == 851567558\n assert candidate(a = 1,b = 2147483647,n = 50) == 519485508\n assert candidate(a = 135792468,b = 246813579,n = 32) == 736568943\n assert candidate(a = 1000000000000,b = 999999999999,n = 40) == 810111777\n assert candidate(a = 1,b = 2,n = 50) == 481564664\n assert candidate(a = 50,b = 50,n = 10) == 1046529\n assert candidate(a = 2147483647,b = 2147483647,n = 32) == 992409480\n assert candidate(a = 65535,b = 131071,n = 17) == 589737929\n assert candidate(a = 13,b = 29,n = 5) == 465\n assert candidate(a = 123456789,b = 987654321,n = 30) == 664805056\n assert candidate(a = 2147483647,b = 1,n = 30) == 536396503\n assert candidate(a = 1000000000,b = 1000000000,n = 31) == 850618742\n assert candidate(a = 123,b = 456,n = 8) == 84660\n assert candidate(a = 12345,b = 67890,n = 15) == 742597886\n assert candidate(a = 2,b = 3,n = 1) == 6\n assert candidate(a = 1,b = 2147483647,n = 31) == 536396503\n assert candidate(a = 248,b = 231,n = 10) == 1015056\n assert candidate(a = 999999999,b = 999999998,n = 30) == 315171055\n assert candidate(a = 511,b = 1023,n = 10) == 522753\n assert candidate(a = 1,b = 0,n = 50) == 279487308\n", "comparison": "exact"}, "public_tests": ["12\n5\n4", "6\n7\n5", "1\n6\n3"], "hints": ["Iterate over bits from most significant to least significant.", "For the i^th bit, if both a and b have the same value, we can always make x’s i^th bit different from a and b, so a ^ x and b ^ x both have the i^th bit set.", "Otherwise, we can only set the i^th bit of one of a ^ x or b ^ x. Depending on the previous bits of a ^ x or b ^ x, we should set the smaller value’s i^th bit."], "metadata": {"canonical_parameter_names": ["a", "b", "n"], "leetcode_dataset_entry_point": "Solution().maximumXorProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:49+00:00", "tests_total": 74, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "greedy", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_xor_product(a, b, n)", "container": null, "callable": "maximum_xor_product", "parameters": [{"name": "a", "type": "Integer"}, {"name": "b", "type": "Integer"}, {"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2940, "task_id": "find-building-where-alice-and-bob-can-meet", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the i^th building.\n\nIf a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].\n\nYou are also given another array queries where queries[i] = [a_i, b_i]. On the i^th query, Alice is in building a_i while Bob is in building b_i.\n\nReturn an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the i^th query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.\n\nExample 1:\n\nInput: heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]\nOutput: [2,5,-1,5,2]\nExplanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2].\nIn the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5].\nIn the third query, Alice cannot meet Bob since Alice cannot move to any other building.\nIn the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].\nIn the fifth query, Alice and Bob are already in the same building.\nFor ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\nFor ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n\nExample 2:\n\nInput: heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]\nOutput: [7,6,-1,4,6]\nExplanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].\nIn the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].\nIn the third query, Alice cannot meet Bob since Bob cannot move to any other building.\nIn the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].\nIn the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].\nFor ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\nFor ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n\nConstraints:\n\n- 1 <= heights.length <= 5 * 10^4\n- 1 <= heights[i] <= 10^9\n- 1 <= queries.length <= 5 * 10^4\n- queries[i] = [a_i, b_i]\n- 0 <= a_i, b_i <= heights.length - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(heights = [10, 20, 30, 40, 50],queries = [[0, 4], [1, 3], [2, 2], [3, 1]]) == [4, 3, 2, 3]\n assert candidate(heights = [1, 2, 3, 4, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 4]]) == [1, 2, 3, 4, 4]\n assert candidate(heights = [5, 4, 3, 2, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [-1, -1, -1, -1]\n assert candidate(heights = [5, 5, 5, 5, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [1, 3, 5, 7, 9],queries = [[0, 2], [1, 3], [2, 4], [3, 4]]) == [2, 3, 4, 4]\n assert candidate(heights = [1, 2, 3, 2, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [1, 2, -1, -1]\n assert candidate(heights = [1, 2, 3, 4, 5],queries = [[0, 4], [1, 3], [2, 2], [3, 1], [4, 0]]) == [4, 3, 2, 3, 4]\n assert candidate(heights = [5, 4, 3, 2, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [6, 4, 8, 5, 2, 7],queries = [[0, 1], [0, 3], [2, 4], [3, 4], [2, 2]]) == [2, 5, -1, 5, 2]\n assert candidate(heights = [100, 200, 150, 300, 250],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4]]) == [1, 3, 3, -1, 4]\n assert candidate(heights = [50, 40, 30, 20, 10],queries = [[0, 4], [1, 3], [2, 2], [3, 1]]) == [-1, -1, 2, -1]\n assert candidate(heights = [10, 20, 30, 40, 50],queries = [[0, 2], [1, 3], [2, 4], [0, 4], [1, 4]]) == [2, 3, 4, 4, 4]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6]]) == [-1, -1, -1, -1]\n assert candidate(heights = [1, 2, 3, 4, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [1, 2, 3, 4]\n assert candidate(heights = [1, 2, 3, 4, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4]]) == [1, 2, 3, 4, 4]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [1, 1, 1, 1, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [-1, -1, -1, -1]\n assert candidate(heights = [5, 3, 8, 2, 6, 1, 4, 6],queries = [[0, 7], [3, 5], [5, 2], [3, 0], [1, 6]]) == [7, 6, -1, 4, 6]\n assert candidate(heights = [10, 20, 30, 40, 50],queries = [[0, 2], [1, 3], [2, 4], [0, 4], [1, 2]]) == [2, 3, 4, 4, 2]\n assert candidate(heights = [1, 1, 1, 1, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [1, 9, 2, 8, 3, 7, 4, 6, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [1, -1, 3, -1, 5, -1, 7, -1]\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7], [8, 6], [9, 5], [10, 4], [11, 3], [12, 2], [13, 1]]) == [14, 13, 12, 11, 10, 9, 8, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100],queries = [[0, 9], [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9], [0, 8]]) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [10, 10, 10, 10, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4], [4, 0], [3, 2], [2, 1], [1, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [5, 3, 8, 2, 6, 1, 4, 6, 9, 7, 11, 13, 12],queries = [[0, 12], [1, 11], [2, 10], [3, 9], [4, 8], [5, 7], [6, 6], [7, 5], [8, 4], [9, 3], [10, 2], [11, 1], [12, 0]]) == [12, 11, 10, 9, 8, 7, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(heights = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == [1, -1, 3, -1, 5, -1, 7, -1, 9, 9]\n assert candidate(heights = [5, 3, 8, 6, 7, 2, 4, 1, 9, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 8, 8, 8, 8, 8, 8, 8, 9]\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 13], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8], [6, 7]]) == [13, 12, 11, 10, 9, 8, 7]\n assert candidate(heights = [5, 4, 3, 2, 1, 2, 3, 4, 5],queries = [[0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [0, 8], [1, 7], [2, 6], [3, 5]]) == [-1, 8, 7, 7, 8, -1, 8, 7, 6]\n assert candidate(heights = [1, 2, 3, 2, 1, 3, 2, 1, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [-1, -1, -1, -1, 5, 5, -1, -1, -1, -1]\n assert candidate(heights = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 9, 7, 9, 5, 5, 9, 7, 9, 9]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [0, 15], [1, 16], [2, 17], [3, 18], [0, 18], [1, 17], [2, 16], [3, 15]]) == [19, 18, 17, 16, 15, 15, 16, 17, 18, 18, 17, 16, 15]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7]]) == [14, 13, 12, 11, 10, 9, 8, 7]\n assert candidate(heights = [5, 4, 3, 2, 1, 10],queries = [[0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [0, 4]]) == [5, 5, 5, 5, 5, 5]\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 9]\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [50, 40, 30, 20, 10],queries = [[0, 4], [1, 3], [2, 2], [3, 1], [4, 0]]) == [-1, -1, 2, -1, -1]\n assert candidate(heights = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [1, -1, 3, -1, 5, -1, 7, -1, 9]\n assert candidate(heights = [100, 200, 150, 300, 250, 400, 350, 500, 450, 600],queries = [[0, 9], [2, 5], [3, 7], [1, 8], [4, 6]]) == [9, 5, 7, 8, 6]\n assert candidate(heights = [1, 2, 3, 2, 1, 2, 3, 2, 1],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [5, 3], [6, 2], [7, 1], [8, 0]]) == [-1, -1, -1, 6, 4, 6, -1, -1, -1]\n assert candidate(heights = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2],queries = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [0, 9]]) == [2, 6, -1, 6, 6, -1, -1, -1, 9]\n assert candidate(heights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [1, 0], [3, 2], [5, 4], [7, 6], [9, 8]]) == [1, 3, 5, 7, 9, 1, 3, 5, 7, 9]\n assert candidate(heights = [1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [0, 5], [1, 6], [2, 7]]) == [8, 7, 6, 5, 4, 5, 6, 7]\n assert candidate(heights = [1, 2, 3, 4, 5, 4, 3, 2, 1],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [5, 3], [6, 2], [7, 1], [8, 0]]) == [-1, -1, -1, -1, 4, -1, -1, -1, -1]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 5], [1, 6], [2, 7], [3, 8], [0, 8]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [-1, -1, -1, -1, -1, 14, 13, 12, 11, 10]\n assert candidate(heights = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],queries = [[0, 5], [5, 0], [2, 8], [8, 2], [4, 4]]) == [5, 5, 8, 8, 4]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, -1, 7, -1, 5, 5, -1, 7, -1, 9]\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 7, 6, 5, 5, 6, 7, 8, 9]\n assert candidate(heights = [1, 5, 3, 7, 9, 2, 8, 6, 4, 10],queries = [[0, 9], [2, 5], [3, 7], [1, 8], [4, 6]]) == [9, 6, 9, 9, 9]\n assert candidate(heights = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 10, 8, 9, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [-1, -1, 17, -1, 15, -1, 13, 12, 11, 10]\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [1, 10, 3, 12, 5, 14, 7, 16, 9, 18],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == [1, 3, 3, 5, 5, 7, 7, 9, 9, 9]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],queries = [[0, 9], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18]]) == [10, 10, 11, 12, 13, 14, 15, 16, 17, 18]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10],queries = [[0, 10], [1, 9], [2, 8], [3, 7], [4, 6], [0, 6], [1, 5], [2, 4], [3, 5], [4, 5], [5, 7], [6, 8]]) == [10, 9, 8, 7, 6, 6, 5, 4, 5, 5, 7, 8]\n assert candidate(heights = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [2, 2, 4, 4, 6, 6, 8, 8, -1]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[9, 0], [8, 1], [7, 2], [6, 3], [5, 4], [4, 5], [3, 6], [2, 7], [1, 8], [0, 9]]) == [9, 8, 7, 6, 5, 5, 6, 7, 8, 9]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100],queries = [[0, 9], [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9]]) == [9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 7, 6, 5, 5, 6, 7, 8, 9]\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [100, 200, 150, 250, 300, 100, 150, 200, 250, 300],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 7, 9, -1, -1, 9, 7, 8, 9]\n assert candidate(heights = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [0, 8]]) == [-1, 8, 8, 6, 6, 6, 6, 8, 8, 8]\n assert candidate(heights = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10], [0, 5], [5, 0]]) == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 5, 5]\n assert candidate(heights = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 7, 6, 5, 5, 6, 7, 8, 9]\n assert candidate(heights = [5, 15, 25, 35, 45, 30, 20, 10, 50, 60],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 8, 8, 8, 8, 8, 8, 8, 9]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11],queries = [[0, 10], [1, 9], [2, 8], [3, 7], [4, 6], [0, 6], [1, 5], [2, 4], [3, 5], [4, 5]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [100, 200, 150, 300, 250, 350],queries = [[0, 2], [1, 5], [2, 3], [3, 4], [4, 5], [0, 5]]) == [2, 5, 3, 5, 5, 5]\n assert candidate(heights = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7], [8, 6], [9, 5], [10, 4], [11, 3], [12, 2], [13, 1]]) == [14, 13, 12, 11, 10, 9, 8, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(heights = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [5, 1, 4, 3, 2, 6, 7, 8],queries = [[0, 6], [1, 5], [2, 7], [3, 4], [5, 7], [6, 7], [0, 7]]) == [6, 5, 7, 5, 7, 7, 7]\n assert candidate(heights = [50, 40, 30, 20, 10],queries = [[4, 0], [3, 1], [2, 2], [1, 3], [0, 4]]) == [-1, -1, 2, -1, -1]\n assert candidate(heights = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 6, 4, 7, 3, 8, 2, 9, 1],queries = [[0, 17], [1, 16], [2, 15], [3, 14], [4, 13], [5, 12], [6, 11], [7, 10], [8, 9], [9, 8], [10, 7], [11, 6], [12, 5], [13, 4], [14, 3], [15, 2], [16, 1], [17, 0]]) == [-1, -1, 16, 16, 14, 14, 12, 12, 10, 10, 12, 12, 14, 14, 16, 16, -1, -1]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 5], [1, 6], [2, 7], [3, 8], [0, 8]]) == [9, -1, 7, -1, 5, 5, -1, 7, -1, 8]\n assert candidate(heights = [1, 2, 3, 4, 5, 4, 3, 2, 1],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0]]) == [-1, -1, -1, -1, 4, 3, 2, 1, 0]\n assert candidate(heights = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [0, 5], [1, 6], [2, 7]]) == [-1, -1, -1, -1, 4, -1, -1, -1]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7]]) == [14, 13, 12, 11, 10, 9, 8, 7]\n assert candidate(heights = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [-1, 8, -1, 6, -1]\n assert candidate(heights = [1, 5, 3, 6, 7, 8, 2, 4],queries = [[0, 7], [1, 6], [2, 5], [3, 4], [0, 4], [1, 5], [6, 7]]) == [7, -1, 5, 4, 4, 5, 7]\n assert candidate(heights = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [-1, 8, -1, 6, -1, -1, 6, -1, 8, -1]\n assert candidate(heights = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [9, 8, 7, 6, 5]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [0, 8]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [-1, -1, -1, -1, -1, 14, 13, 12, 11, 10]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10], [10, 9], [11, 8], [12, 7], [13, 6], [14, 5], [15, 4], [16, 3], [17, 2], [18, 1], [19, 0]]) == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(heights = [1, 3, 2, 4, 7, 6, 5, 8, 9, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 7, 6, 7, 7, 6, 7, 8, 9]\n assert candidate(heights = [1, 10, 1, 10, 1, 10, 1, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [1, -1, 3, -1, 5, -1, 7]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(heights = [1000000000, 999999999, 999999998, 999999997, 999999996],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4]]) == [-1, -1, -1, -1, -1]\n assert candidate(heights = [5, 1, 4, 2, 3, 6, 8, 7, 10, 9],queries = [[0, 4], [1, 3], [2, 5], [6, 9], [7, 8]]) == [5, 3, 5, 9, 8]\n assert candidate(heights = [5, 1, 3, 7, 9, 2, 8, 6, 10],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 3], [5, 2], [6, 1], [7, 0]]) == [8, 7, 6, 6, 4, 6, 6, 7]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 1], [1, 0]]) == [9, -1, 7, -1, 5, 1, 1]\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2],queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == [9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [0, 8]]) == [9, 8, 7, 6, 5, 5, 6, 7, 8, 8]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10], [0, 10], [5, 15]]) == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 10, 15]\n assert candidate(heights = [1, 3, 2, 4, 3, 5, 4],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 6]]) == [1, 3, 3, 5, 5, -1, 6]\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7]]) == [14, 13, 12, 11, 10, 9, 8, 7]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [9, 8, 7, 6, 5, 5, 6, 7, 8, 9]\n assert candidate(heights = [5, 3, 8, 2, 6, 1, 4, 6],queries = [[0, 7], [3, 5], [5, 2], [3, 0], [1, 6], [2, 4], [6, 3], [4, 5]]) == [7, 6, -1, 4, 6, -1, 6, -1]\n assert candidate(heights = [100, 200, 150, 300, 250, 400, 350, 500],queries = [[0, 7], [1, 6], [2, 5], [3, 4], [0, 4], [1, 5], [2, 6], [0, 6], [1, 7]]) == [7, 6, 5, 5, 4, 5, 6, 6, 7]\n assert candidate(heights = [1, 3, 2, 5, 4, 6, 7, 8, 9, 10],queries = [[0, 9], [2, 5], [4, 8], [1, 7], [3, 6]]) == [9, 5, 8, 7, 6]\n assert candidate(heights = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [-1, -1, 7, 7, -1, -1, 7, 7, -1, -1]\n assert candidate(heights = [5, 5, 5, 5, 5, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 5]]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(heights = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7]]) == [-1, -1, -1, -1, -1, -1, -1, 7]\n assert candidate(heights = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [5, 3], [6, 2], [7, 1], [8, 0]]) == [-1, -1, -1, -1, 4, -1, -1, -1, -1]\n", "comparison": "exact"}, "public_tests": ["[6,4,8,5,2,7]\n[[0,1],[0,3],[2,4],[3,4],[2,2]]", "[5,3,8,2,6,1,4,6]\n[[0,7],[3,5],[5,2],[3,0],[1,6]]"], "hints": ["For each query [x, y], if x > y, swap x and y. Now, we can assume that x <= y.", "For each query [x, y], if x == y or heights[x] < heights[y], then the answer is y since x ≤ y.", "Otherwise, we need to find the smallest index t such that y < t and heights[x] < heights[t]. Note that heights[y] <= heights[x], so heights[x] < heights[t] is a sufficient condition.", "To find index t for each query, sort the queries in descending order of y. Iterate over the queries while maintaining a monotonic stack which we can binary search over to find index t."], "metadata": {"canonical_parameter_names": ["heights", "queries"], "leetcode_dataset_entry_point": "Solution().leftmostBuildingQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:51+00:00", "tests_total": 111, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "stack", "binary-indexed-tree", "segment-tree", "heap-priority-queue", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def leftmost_building_queries(heights, queries)", "container": null, "callable": "leftmost_building_queries", "parameters": [{"name": "heights", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2942, "task_id": "find-words-containing-character", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array of strings words and a character x.\n\nReturn an array of indices representing the words that contain the character x.\n\nNote that the returned array may be in any order.\n\nExample 1:\n\nInput: words = [\"leet\",\"code\"], x = \"e\"\nOutput: [0,1]\nExplanation: \"e\" occurs in both words: \"leet\", and \"code\". Hence, we return indices 0 and 1.\n\nExample 2:\n\nInput: words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"a\"\nOutput: [0,2]\nExplanation: \"a\" occurs in \"abc\", and \"aaaa\". Hence, we return indices 0 and 2.\n\nExample 3:\n\nInput: words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"z\"\nOutput: []\nExplanation: \"z\" does not occur in any of the words. Hence, we return an empty array.\n\nConstraints:\n\n- 1 <= words.length <= 50\n- 1 <= words[i].length <= 50\n- x is a lowercase English letter.\n- words[i] consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(words=['abc', 'bcd', 'aaaa', 'cbc'], x='z'), [])\n assert answers_match(candidate(words=['python', 'programming'], x='o'), [0, 1])\n assert answers_match(candidate(words=['ab', 'cd', 'ef'], x='g'), [])\n assert answers_match(candidate(words=['aaaaa', 'bbbbb', 'ccccc'], x='a'), [0])\n assert answers_match(candidate(words=['apple', 'banana', 'cherry'], x='a'), [0, 1])\n assert answers_match(candidate(words=['hello', 'world'], x='l'), [0, 1])\n assert answers_match(candidate(words=['hello', 'world'], x='o'), [0, 1])\n assert answers_match(candidate(words=['algorithm', 'data', 'structure'], x='t'), [0, 1, 2])\n assert answers_match(candidate(words=['leet', 'code'], x='e'), [0, 1])\n assert answers_match(candidate(words=['red', 'blue', 'green'], x='e'), [0, 1, 2])\n assert answers_match(candidate(words=['sun', 'moon', 'star'], x='u'), [0])\n assert answers_match(candidate(words=['test', 'example', 'input'], x='t'), [0, 2])\n assert answers_match(candidate(words=['abc', 'bcd', 'aaaa', 'cbc'], x='a'), [0, 2])\n assert answers_match(candidate(words=['algorithm', 'data', 'structure'], x='a'), [0, 1])\n assert answers_match(candidate(words=['example', 'test', 'case'], x='x'), [0])\n assert answers_match(candidate(words=['unique', 'characters'], x='u'), [0])\n assert answers_match(candidate(words=['a', 'b', 'c'], x='d'), [])\n assert answers_match(candidate(words=['hello', 'world', 'python'], x='o'), [0, 1, 2])\n assert answers_match(candidate(words=['one', 'two', 'three'], x='t'), [1, 2])\n assert answers_match(candidate(words=['meeting', 'event', 'conference'], x='e'), [0, 1, 2])\n assert answers_match(candidate(words=['find', 'words', 'containing'], x='n'), [0, 2])\n assert answers_match(candidate(words=['python', 'java', 'csharp'], x='p'), [0, 2])\n assert answers_match(candidate(words=['dog', 'cat', 'bird'], x='d'), [0, 2])\n assert answers_match(candidate(words=['one', 'two', 'three'], x='e'), [0, 2])\n assert answers_match(candidate(words=['algorithm', 'datastructure', 'programming', 'interview'], x='m'), [0, 2])\n assert answers_match(candidate(words=['banana', 'apple', 'orange', 'grape'], x='o'), [2])\n assert answers_match(candidate(words=['interface', 'function', 'method', 'parameter', 'argument'], x='p'), [3])\n assert answers_match(candidate(words=['mississippi', 'delaware', 'indiana', 'illinois'], x='i'), [0, 2, 3])\n assert answers_match(candidate(words=['repeated', 'character', 'example'], x='e'), [0, 1, 2])\n assert answers_match(candidate(words=['mississippi', 'hawaii', 'alaska'], x='i'), [0, 1])\n assert answers_match(candidate(words=['quizzing', 'quiz', 'quizzes'], x='z'), [0, 1, 2])\n assert answers_match(candidate(words=['sunshine', 'rainbow', 'cloud', 'sky', 'ocean', 'beach'], x='n'), [0, 1, 4])\n assert answers_match(candidate(words=['xylophone', 'triangle', 'square', 'rectangle', 'pentagon'], x='p'), [0, 4])\n assert answers_match(candidate(words=['repetition', 'repeated', 'repetitive', 'repetition'], x='p'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['mississippi', 'mississippian', 'mississippians', 'mississippify'], x='p'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['xylophone', 'xylography', 'xylophonist'], x='x'), [0, 1, 2])\n assert answers_match(candidate(words=['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'], x='a'), [0, 1, 3])\n assert answers_match(candidate(words=['mississippi', 'hannah', 'racecar', 'level'], x='i'), [0])\n assert answers_match(candidate(words=['university', 'college', 'school', 'institute'], x='u'), [0, 3])\n assert answers_match(candidate(words=['docker', 'kubernetes', 'container', 'orchestration', 'deployment'], x='d'), [0, 4])\n assert answers_match(candidate(words=['python', 'java', 'c', 'javascript'], x='v'), [1, 3])\n assert answers_match(candidate(words=['repetition', 'occurrence', 'continuous', 'discontinuous'], x='o'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['fantastic', 'extraordinary', 'remarkable', 'astonishing', 'amazing'], x='a'), [0, 1, 2, 3, 4])\n assert answers_match(candidate(words=['onlyonecharacter', 'twochars', 'threechars'], x='c'), [0, 1, 2])\n assert answers_match(candidate(words=['zebra', 'elephant', 'giraffe', 'hippopotamus'], x='e'), [0, 1, 2])\n assert answers_match(candidate(words=['antidisestablishmentarianism', 'floccinaucinihilipilification', 'supercalifragilisticexpialidocious'], x='t'), [0, 1, 2])\n assert answers_match(candidate(words=['abcdefg', 'hijklmn', 'opqrstu'], x='x'), [])\n assert answers_match(candidate(words=['floccinaucinihilipilification', 'supercalifragilisticexpialidocious'], x='c'), [0, 1])\n assert answers_match(candidate(words=['mississippi', 'misterious', 'mismatch', 'misconduct'], x='m'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['responsive', 'design', 'user', 'interface'], x='e'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['same', 'same', 'same'], x='a'), [0, 1, 2])\n assert answers_match(candidate(words=['abcdefghij', 'klmnopqrstu', 'vwxyz'], x='x'), [2])\n assert answers_match(candidate(words=['angular', 'react', 'vue', 'ember', 'svelte'], x='a'), [0, 1])\n assert answers_match(candidate(words=['algorithm', 'datastructure', 'programming'], x='a'), [0, 1, 2])\n assert answers_match(candidate(words=['programming', 'coding', 'software', 'development'], x='o'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['encyclopedia', 'dictionary', 'thesaurus'], x='o'), [0, 1])\n assert answers_match(candidate(words=['environment', 'environmental', 'environments', 'environmentalist'], x='v'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['abcdefghij', 'jihgfedcba', 'abcdefgh', 'dcba'], x='f'), [0, 1, 2])\n assert answers_match(candidate(words=['sequential', 'search', 'binary', 'hashmap'], x='h'), [1, 3])\n assert answers_match(candidate(words=['multifaceted', 'multicolored', 'multifarious', 'multilingual'], x='m'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['optimization', 'complexity', 'graph', 'matrix'], x='i'), [0, 1, 3])\n assert answers_match(candidate(words=['xyz', 'zyx', 'yxz', 'zyzxzyx'], x='x'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['database', 'schema', 'table', 'column', 'index'], x='b'), [0, 2])\n assert answers_match(candidate(words=['single'], x='s'), [0])\n assert answers_match(candidate(words=['university', 'algorithm', 'quantum', 'computer'], x='u'), [0, 2, 3])\n assert answers_match(candidate(words=['embedded', 'real', 'time', 'system'], x='z'), [])\n assert answers_match(candidate(words=['xylophone', 'guitar', 'drum', 'flute'], x='u'), [1, 2, 3])\n assert answers_match(candidate(words=['algorithm', 'datastructure', 'code', 'debug'], x='a'), [0, 1])\n assert answers_match(candidate(words=['pneumonoultramicroscopicsilicovolcanoconiosis', 'super', 'hyper', 'sub'], x='o'), [0])\n assert answers_match(candidate(words=['unbelievable', 'unbelievably', 'unbelievable', 'unbelievable'], x='u'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['interstellar', 'galaxy', 'cosmic', 'universe'], x='i'), [0, 2, 3])\n assert answers_match(candidate(words=['mississippi', 'massachusetts', 'minimum'], x='i'), [0, 2])\n assert answers_match(candidate(words=['unitedstates', 'canada', 'mexico', 'brazil'], x='a'), [0, 1, 3])\n assert answers_match(candidate(words=['xylophone', 'xylo', 'xy', 'x'], x='x'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['congratulations', 'celebration', 'felicitation'], x='t'), [0, 1, 2])\n assert answers_match(candidate(words=['apple', 'banana', 'cherry', 'date'], x='b'), [1])\n assert answers_match(candidate(words=['repetition', 'occurrence', 'frequency', 'infrequent'], x='r'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['machine', 'learning', 'artificial', 'intelligence', 'neural'], x='a'), [0, 1, 2, 4])\n assert answers_match(candidate(words=['character', 'charts', 'chocolate', 'chartreuse'], x='c'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['supercalifragilisticexpialidocious', 'pneumonoultramicroscopicsilicovolcanoconiosis'], x='s'), [0, 1])\n assert answers_match(candidate(words=['hello', 'world', 'python', 'programming'], x='m'), [3])\n assert answers_match(candidate(words=['complexity', 'analysis', 'optimization'], x='x'), [0])\n assert answers_match(candidate(words=['banana', 'bandana', 'panacea'], x='a'), [0, 1, 2])\n assert answers_match(candidate(words=['python', 'java', 'csharp', 'javascript'], x='p'), [0, 2, 3])\n assert answers_match(candidate(words=['compiler', 'interpreter', 'virtual', 'machine'], x='r'), [0, 1, 2])\n assert answers_match(candidate(words=['repetition', 'character', 'sequence', 'word', 'dictionary'], x='e'), [0, 1, 2])\n assert answers_match(candidate(words=['typescript', 'javascript', 'python', 'java', 'csharp'], x='s'), [0, 1, 4])\n assert answers_match(candidate(words=['network', 'protocol', 'security', 'encryption', 'decryption'], x='c'), [1, 2, 3, 4])\n assert answers_match(candidate(words=['rain', 'rainbow', 'raining', 'raincoat'], x='n'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], x='b'), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(words=['xylophone', 'xylography', 'xylophone'], x='x'), [0, 1, 2])\n assert answers_match(candidate(words=['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd'], x='a'), [0, 4])\n assert answers_match(candidate(words=['algorithm', 'data', 'structure', 'programming'], x='a'), [0, 1, 3])\n assert answers_match(candidate(words=['qwertyuiop', 'asdfghjkl', 'zxcvbnm', 'qwerty'], x='t'), [0, 3])\n assert answers_match(candidate(words=['environment', 'variable', 'configuration', 'parameter', 'setting'], x='e'), [0, 1, 3, 4])\n assert answers_match(candidate(words=['internet', 'of', 'things', 'iot'], x='t'), [0, 2, 3])\n assert answers_match(candidate(words=['xyz', 'zyx', 'yxz'], x='z'), [0, 1, 2])\n assert answers_match(candidate(words=['repetition', 'recursion', 'iteration', 'permutation'], x='e'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['zebra', 'xylophone', 'zoo', 'zest'], x='z'), [0, 2, 3])\n assert answers_match(candidate(words=['quintessential', 'quotation', 'quiver', 'quadrilateral'], x='q'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['unique', 'united', 'union', 'unity'], x='i'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['supercalifragilisticexpialidocious', 'supercalifragilisticexpialidocious', 'supercalifragilisticexpialidocious'], x='x'), [0, 1, 2])\n assert answers_match(candidate(words=['database', 'management', 'query', 'optimization'], x='q'), [2])\n assert answers_match(candidate(words=['sequence', 'subsequence', 'consequence', 'dessequence'], x='q'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['programming', 'language', 'python'], x='o'), [0, 2])\n assert answers_match(candidate(words=['compiler', 'interpreter', 'debugger', 'profiler', 'virtual'], x='o'), [0, 3])\n assert answers_match(candidate(words=['fantastic', 'fantasy', 'fantastic', 'fantastically'], x='f'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['interview', 'question', 'answer', 'example'], x='i'), [0, 1])\n assert answers_match(candidate(words=['responsive', 'layout', 'flexbox', 'grid', 'animation'], x='n'), [0, 4])\n assert answers_match(candidate(words=['quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'], x='z'), [6])\n assert answers_match(candidate(words=['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyzabcdefghijkl'], x='m'), [0, 1, 2])\n assert answers_match(candidate(words=['artificial', 'intelligence', 'machine', 'learning'], x='i'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['encyclopedia', 'encyclopedia', 'encyclopedia', 'encyclopedia'], x='n'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['apple', 'banana', 'cherry', 'date', 'elderberry'], x='a'), [0, 1, 3])\n assert answers_match(candidate(words=['filesystem', 'directory', 'permission', 'read', 'write'], x='r'), [1, 2, 3, 4])\n assert answers_match(candidate(words=['xylophone', 'xylography', 'xylophonist', 'xylophone'], x='x'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['algorithm', 'data', 'structure', 'programming', 'design'], x='g'), [0, 3, 4])\n assert answers_match(candidate(words=['binary', 'search', 'tree', 'avl', 'hashmap'], x='h'), [1, 4])\n assert answers_match(candidate(words=['abcdefghij', 'klmnopqr', 'stuvwxyz'], x='z'), [2])\n assert answers_match(candidate(words=['verylongwordthatcontainsmanycharacters', 'short', 'tiny'], x='w'), [0])\n assert answers_match(candidate(words=['alphabet', 'beta', 'gamma', 'delta', 'epsilon'], x='a'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['nineteen', 'eighteen', 'seventeen'], x='e'), [0, 1, 2])\n assert answers_match(candidate(words=['concurrent', 'parallel', 'distributed', 'systems'], x='c'), [0])\n assert answers_match(candidate(words=['banana', 'ananas', 'pineapple', 'mango'], x='n'), [0, 1, 2, 3])\n assert answers_match(candidate(words=['supercalifragilisticexpialidocious', 'pneumonoultramicroscopicsilicovolcanoconiosis'], x='o'), [0, 1])\n assert answers_match(candidate(words=['frontend', 'backend', 'database', 'api', 'client'], x='d'), [0, 1, 2])\n assert answers_match(candidate(words=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], x='q'), [16])\n assert answers_match(candidate(words=['embedded', 'real', 'time', 'system'], x='b'), [0])\n assert answers_match(candidate(words=['unique', 'words', 'only'], x='q'), [0])\n assert answers_match(candidate(words=['alphabet', 'xylophone', 'encyclopedia', 'dictionary', 'glossary'], x='y'), [1, 2, 3, 4])\n assert answers_match(candidate(words=['repeated', 'characters', 'in', 'words'], x='e'), [0, 1])\n assert answers_match(candidate(words=['longitudinal', 'lateral', 'longest', 'longevity'], x='o'), [0, 2, 3])\n assert answers_match(candidate(words=['continuous', 'integration', 'deployment', 'pipeline', 'automation'], x='n'), [0, 1, 2, 3, 4])\n assert answers_match(candidate(words=['algorithm', 'data', 'structures', 'binary'], x='a'), [0, 1, 3])\n assert answers_match(candidate(words=['documentation', 'repository', 'commit', 'branch', 'merge'], x='m'), [0, 2, 4])\n assert answers_match(candidate(words=['programming', 'language', 'python', 'java'], x='o'), [0, 2])\n assert answers_match(candidate(words=['blockchain', 'cryptography', 'security', 'privacy'], x='y'), [1, 2, 3])\n assert answers_match(candidate(words=['programming', 'language', 'python'], x='p'), [0, 2])\n assert answers_match(candidate(words=['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyza'], x='a'), [0, 1, 2])\n", "comparison": "unordered"}, "public_tests": ["[\"leet\",\"code\"]\n\"e\"", "[\"abc\",\"bcd\",\"aaaa\",\"cbc\"]\n\"a\"", "[\"abc\",\"bcd\",\"aaaa\",\"cbc\"]\n\"z\""], "hints": ["Use two nested loops."], "metadata": {"canonical_parameter_names": ["words", "x"], "leetcode_dataset_entry_point": "Solution().findWordsContaining", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:56+00:00", "tests_total": 141, "tests_dropped": 2, "flags": ["any_order"], "topic_tags": ["array", "string"]}, "language": "ruby", "interface": {"raw_signature": "def find_words_containing(words, x)", "container": null, "callable": "find_words_containing", "parameters": [{"name": "words", "type": "String[]"}, {"name": "x", "type": "Character"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2943, "task_id": "maximize-area-of-square-hole-in-grid", "difficulty": "Medium", "problem_description": "You are given the two integers, n and m and two integer arrays, hBars and vBars. The grid has n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.\n\nYou can remove some of the bars in hBars from horizontal bars and some of the bars in vBars from vertical bars. Note that other bars are fixed and cannot be removed.\n\nReturn an integer denoting the maximum area of a square-shaped hole in the grid, after removing some bars (possibly none).\n\nExample 1:\n\nInput: n = 2, m = 1, hBars = [2,3], vBars = [2]\nOutput: 4\nExplanation:\nThe left image shows the initial grid formed by the bars. The horizontal bars are [1,2,3,4], and the vertical bars are [1,2,3].\nOne way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.\n\nExample 2:\n\nInput: n = 1, m = 1, hBars = [2], vBars = [2]\nOutput: 4\nExplanation:\nTo get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.\n\nExample 3:\n\nInput: n = 2, m = 3, hBars = [2,3], vBars = [2,4]\nOutput: 4\nExplanation:\nOne way to get the maximum square-shaped hole is by removing horizontal bar 3, and vertical bar 4.\n\nConstraints:\n\n- 1 <= n <= 10^9\n- 1 <= m <= 10^9\n- 1 <= hBars.length <= 100\n- 2 <= hBars[i] <= n + 1\n- 1 <= vBars.length <= 100\n- 2 <= vBars[i] <= m + 1\n- All values in hBars are distinct.\n- All values in vBars are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1,m = 1,hBars = [2],vBars = [2]) == 4\n assert candidate(n = 2,m = 3,hBars = [2, 3],vBars = [2, 4]) == 4\n assert candidate(n = 2,m = 1,hBars = [2, 3],vBars = [2]) == 4\n assert candidate(n = 5,m = 5,hBars = [2, 3, 4],vBars = [2, 3, 4]) == 16\n assert candidate(n = 10,m = 10,hBars = [3, 5, 7],vBars = [4, 6, 8]) == 4\n assert candidate(n = 20,m = 10,hBars = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],vBars = [2, 4, 6, 8, 10]) == 4\n assert candidate(n = 15,m = 15,hBars = [3, 5, 7, 9, 11],vBars = [3, 5, 7, 9, 11]) == 4\n assert candidate(n = 15,m = 15,hBars = [3, 5, 7, 9, 11, 13, 15],vBars = [3, 5, 7, 9, 11, 13, 15]) == 4\n assert candidate(n = 10,m = 10,hBars = [2, 3, 5, 6],vBars = [3, 5, 7]) == 4\n assert candidate(n = 20,m = 10,hBars = [2, 4, 6, 8, 10],vBars = [3, 6, 9]) == 4\n assert candidate(n = 8,m = 6,hBars = [2, 3, 5, 7, 8],vBars = [2, 4, 6]) == 4\n assert candidate(n = 100,m = 50,hBars = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],vBars = [10, 20, 30, 40, 50]) == 4\n assert candidate(n = 20,m = 20,hBars = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],vBars = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 4\n assert candidate(n = 20,m = 20,hBars = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],vBars = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 400\n assert candidate(n = 6,m = 4,hBars = [2, 3, 4, 5, 6],vBars = [2, 4]) == 4\n assert candidate(n = 7,m = 6,hBars = [2, 4, 5, 7],vBars = [2, 4, 5]) == 9\n assert candidate(n = 3,m = 2,hBars = [2, 3],vBars = [2]) == 4\n assert candidate(n = 40,m = 30,hBars = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],vBars = [5, 7, 9, 11, 13, 15]) == 4\n assert candidate(n = 300,m = 200,hBars = [50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100],vBars = [40, 60, 80, 100, 120, 140, 160, 180, 200]) == 4\n assert candidate(n = 25,m = 25,hBars = [5, 10, 15, 20, 25],vBars = [5, 10, 15, 20, 25]) == 4\n assert candidate(n = 10,m = 10,hBars = [2, 3, 5, 7, 9],vBars = [2, 3, 5, 7, 9]) == 9\n assert candidate(n = 25,m = 25,hBars = [2, 5, 7, 10, 13, 15, 18, 20, 23],vBars = [3, 6, 9, 12, 15, 18, 21, 24]) == 4\n assert candidate(n = 9,m = 9,hBars = [2, 3, 5, 7, 8, 9],vBars = [2, 4, 6, 8]) == 4\n assert candidate(n = 9,m = 9,hBars = [3, 6, 9],vBars = [3, 6, 9]) == 4\n assert candidate(n = 50,m = 50,hBars = [10, 15, 20, 25, 30, 35, 40, 45, 50],vBars = [10, 15, 20, 25, 30, 35, 40, 45, 50]) == 4\n assert candidate(n = 200,m = 150,hBars = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44],vBars = [30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 4\n assert candidate(n = 20,m = 15,hBars = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],vBars = [2, 4, 6, 8, 10, 12, 14]) == 4\n assert candidate(n = 100,m = 100,hBars = [2, 50, 51, 52, 100],vBars = [2, 50, 51, 52, 100]) == 16\n assert candidate(n = 10,m = 10,hBars = [3, 5, 7],vBars = [3, 5, 7]) == 4\n assert candidate(n = 3,m = 3,hBars = [2, 3],vBars = [2, 3, 4]) == 9\n assert candidate(n = 30,m = 25,hBars = [6, 12, 18, 24],vBars = [5, 10, 15, 20]) == 4\n assert candidate(n = 10,m = 10,hBars = [2, 3, 5, 7, 9],vBars = [2, 4, 6, 8, 10]) == 4\n assert candidate(n = 8,m = 8,hBars = [2, 3, 5, 6, 7],vBars = [2, 3, 5, 6, 7]) == 16\n assert candidate(n = 5,m = 5,hBars = [2, 4, 5],vBars = [2, 4]) == 4\n assert candidate(n = 150,m = 100,hBars = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38],vBars = [20, 30, 40, 50, 60, 70, 80, 90, 100]) == 4\n assert candidate(n = 6,m = 3,hBars = [2, 3, 4, 5],vBars = [2, 3]) == 9\n assert candidate(n = 50,m = 50,hBars = [2, 25, 26, 50],vBars = [2, 25, 26, 50]) == 9\n assert candidate(n = 50,m = 50,hBars = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50],vBars = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]) == 4\n assert candidate(n = 5,m = 5,hBars = [2, 3, 4, 5],vBars = [2, 3, 4]) == 16\n assert candidate(n = 10,m = 20,hBars = [2, 3, 4, 5, 6],vBars = [5, 10, 15, 20]) == 4\n assert candidate(n = 15,m = 10,hBars = [3, 5, 7, 9, 11, 13, 15],vBars = [3, 5, 7, 9]) == 4\n assert candidate(n = 9,m = 9,hBars = [2, 3, 4, 5, 6, 7, 8, 9, 10],vBars = [2, 3, 4, 5, 6, 7, 8, 9, 10]) == 100\n assert candidate(n = 7,m = 7,hBars = [3, 4, 5],vBars = [3, 4, 5]) == 16\n assert candidate(n = 30,m = 20,hBars = [2, 3, 4, 5, 6, 7, 8, 9, 10],vBars = [2, 4, 6, 8, 10, 12]) == 4\n assert candidate(n = 5,m = 4,hBars = [2, 4, 5],vBars = [2, 4]) == 4\n assert candidate(n = 50,m = 50,hBars = [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],vBars = [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]) == 4\n assert candidate(n = 10,m = 10,hBars = [2, 4, 6, 8],vBars = [2, 4, 6, 8]) == 4\n assert candidate(n = 7,m = 7,hBars = [2, 3, 5, 6],vBars = [2, 4, 5, 7]) == 9\n assert candidate(n = 7,m = 7,hBars = [3, 4, 5, 6],vBars = [3, 4, 5, 6]) == 25\n assert candidate(n = 9,m = 9,hBars = [2, 3, 5, 6, 8, 9],vBars = [2, 3, 5, 6, 8, 9]) == 9\n assert candidate(n = 12,m = 12,hBars = [2, 4, 6, 8, 10],vBars = [2, 4, 6, 8, 10]) == 4\n assert candidate(n = 15,m = 10,hBars = [2, 4, 6, 8, 10, 12, 14],vBars = [2, 4, 6, 8, 10]) == 4\n assert candidate(n = 10,m = 10,hBars = [2, 3, 4, 5],vBars = [2, 3, 4, 5]) == 25\n assert candidate(n = 7,m = 7,hBars = [3, 5, 6],vBars = [3, 5, 6]) == 9\n assert candidate(n = 25,m = 20,hBars = [5, 10, 15, 20],vBars = [4, 8, 12, 16]) == 4\n assert candidate(n = 100,m = 100,hBars = [10, 20, 30, 40, 50],vBars = [15, 25, 35, 45, 55]) == 4\n assert candidate(n = 8,m = 8,hBars = [2, 4, 6, 8],vBars = [2, 4, 6, 8]) == 4\n assert candidate(n = 6,m = 6,hBars = [2, 3, 4, 5],vBars = [2, 3, 4, 5]) == 25\n assert candidate(n = 3,m = 3,hBars = [2, 3, 4],vBars = [2, 3, 4]) == 16\n assert candidate(n = 4,m = 3,hBars = [2, 3, 4],vBars = [2, 3]) == 9\n assert candidate(n = 10,m = 10,hBars = [2, 4, 6, 8, 10],vBars = [2, 4, 6, 8, 10]) == 4\n assert candidate(n = 10,m = 8,hBars = [2, 4, 6, 8],vBars = [2, 4, 6, 8]) == 4\n assert candidate(n = 100,m = 100,hBars = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],vBars = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 4\n assert candidate(n = 5,m = 4,hBars = [2, 3, 4],vBars = [2, 3, 4]) == 16\n assert candidate(n = 12,m = 12,hBars = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11],vBars = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 121\n assert candidate(n = 7,m = 6,hBars = [2, 3, 4, 5, 6],vBars = [2, 3, 4, 5]) == 25\n assert candidate(n = 9,m = 9,hBars = [2, 3, 5, 7, 9],vBars = [2, 4, 6, 8]) == 4\n assert candidate(n = 3,m = 4,hBars = [2, 3],vBars = [2, 3, 4]) == 9\n assert candidate(n = 100,m = 100,hBars = [50, 51, 52, 53, 54],vBars = [50, 51, 52, 53, 54]) == 36\n assert candidate(n = 7,m = 3,hBars = [2, 3, 4, 5],vBars = [2, 3]) == 9\n assert candidate(n = 7,m = 7,hBars = [2, 3, 5, 6],vBars = [2, 3, 5, 6]) == 9\n assert candidate(n = 3,m = 3,hBars = [2, 3],vBars = [2, 3]) == 9\n assert candidate(n = 20,m = 30,hBars = [10, 12, 13, 15],vBars = [15, 16, 18, 20]) == 9\n assert candidate(n = 5,m = 5,hBars = [2, 3, 4],vBars = [2, 3, 4]) == 16\n assert candidate(n = 5,m = 4,hBars = [2, 3, 5],vBars = [2, 3, 4]) == 9\n assert candidate(n = 8,m = 7,hBars = [3, 5, 6],vBars = [3, 5, 6, 7]) == 9\n assert candidate(n = 15,m = 10,hBars = [2, 3, 5, 7, 9, 11, 13, 15],vBars = [2, 4, 6, 8, 10]) == 4\n assert candidate(n = 6,m = 5,hBars = [2, 3, 5],vBars = [2, 4, 5]) == 9\n assert candidate(n = 5,m = 4,hBars = [2, 3, 4],vBars = [2, 3]) == 9\n assert candidate(n = 12,m = 15,hBars = [2, 3, 4, 6, 8, 10, 12],vBars = [3, 5, 7, 9, 11, 13, 15]) == 4\n assert candidate(n = 4,m = 2,hBars = [2, 3, 4],vBars = [2]) == 4\n assert candidate(n = 30,m = 40,hBars = [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],vBars = [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]) == 961\n assert candidate(n = 100,m = 100,hBars = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],vBars = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 4\n assert candidate(n = 100,m = 50,hBars = [20, 22, 24, 26, 28, 30, 32, 34, 36, 38],vBars = [10, 15, 20, 25, 30, 35, 40]) == 4\n assert candidate(n = 10,m = 5,hBars = [3, 4, 5, 6],vBars = [3, 4]) == 9\n assert candidate(n = 5,m = 5,hBars = [2, 3, 4, 5, 6],vBars = [2, 3, 4, 5, 6]) == 36\n assert candidate(n = 4,m = 6,hBars = [2, 4],vBars = [2, 3, 4, 5, 6]) == 4\n assert candidate(n = 12,m = 12,hBars = [3, 6, 9, 12],vBars = [3, 6, 9, 12]) == 4\n assert candidate(n = 8,m = 6,hBars = [2, 3, 5, 6],vBars = [2, 4, 6]) == 4\n assert candidate(n = 9,m = 9,hBars = [2, 3, 4, 5, 6, 7, 8],vBars = [2, 3, 4, 5, 6, 7, 8]) == 64\n assert candidate(n = 15,m = 15,hBars = [3, 4, 5, 7, 8],vBars = [5, 6, 7, 9, 10]) == 16\n", "comparison": "exact"}, "public_tests": ["2\n1\n[2,3]\n[2]", "1\n1\n[2]\n[2]", "2\n3\n[2,3]\n[2,4]"], "hints": ["Sort hBars and vBars and consider them separately.", "Compute the longest sequence of consecutive integer values in each array, denoted as [hx, hy] and [vx, vy], respectively.", "The maximum square length we can get is min(hy - hx + 2, vy - vx + 2).", "Square the maximum square length to get the area."], "metadata": {"canonical_parameter_names": ["n", "m", "hBars", "vBars"], "leetcode_dataset_entry_point": "Solution().maximizeSquareHoleArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:07:58+00:00", "tests_total": 100, "tests_dropped": 9, "flags": ["has_images"], "topic_tags": ["array", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximize_square_hole_area(n, m, h_bars, v_bars)", "container": null, "callable": "maximize_square_hole_area", "parameters": [{"name": "n", "type": "Integer"}, {"name": "m", "type": "Integer"}, {"name": "h_bars", "type": "Integer[]"}, {"name": "v_bars", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2944, "task_id": "minimum-number-of-coins-for-fruits", "difficulty": "Medium", "problem_description": "You are given an 0-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the (i + 1)^th fruit.\n\nThe fruit market has the following reward for each fruit:\n\n- If you purchase the (i + 1)^th fruit at prices[i] coins, you can get any number of the next i fruits for free.\n\nNote that even if you can take fruit j for free, you can still purchase it for prices[j - 1] coins to receive its reward.\n\nReturn the minimum number of coins needed to acquire all the fruits.\n\nExample 1:\n\nInput: prices = [3,1,2]\nOutput: 4\nExplanation:\n- Purchase the 1^st fruit with prices[0] = 3 coins, you are allowed to take the 2^nd fruit for free.\n- Purchase the 2^nd fruit with prices[1] = 1 coin, you are allowed to take the 3^rd fruit for free.\n- Take the 3^rd fruit for free.\n\nNote that even though you could take the 2^nd fruit for free as a reward of buying 1^st fruit, you purchase it to receive its reward, which is more optimal.\n\nExample 2:\n\nInput: prices = [1,10,1,1]\nOutput: 2\nExplanation:\n- Purchase the 1^st fruit with prices[0] = 1 coin, you are allowed to take the 2^nd fruit for free.\n- Take the 2^nd fruit for free.\n- Purchase the 3^rd fruit for prices[2] = 1 coin, you are allowed to take the 4^th fruit for free.\n- Take the 4^t^h fruit for free.\n\nExample 3:\n\nInput: prices = [26,18,6,12,49,7,45,45]\nOutput: 39\nExplanation:\n- Purchase the 1^st fruit with prices[0] = 26 coin, you are allowed to take the 2^nd fruit for free.\n- Take the 2^nd fruit for free.\n- Purchase the 3^rd fruit for prices[2] = 6 coin, you are allowed to take the 4^th, 5^th and 6^th (the next three) fruits for free.\n- Take the 4^t^h fruit for free.\n- Take the 5^t^h fruit for free.\n- Purchase the 6^th fruit with prices[5] = 7 coin, you are allowed to take the 8^th and 9^th fruit for free.\n- Take the 7^t^h fruit for free.\n- Take the 8^t^h fruit for free.\n\nNote that even though you could take the 6^th fruit for free as a reward of buying 3^rd fruit, you purchase it to receive its reward, which is more optimal.\n\nConstraints:\n\n- 1 <= prices.length <= 1000\n- 1 <= prices[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(prices = [1, 10, 1, 1]) == 2\n assert candidate(prices = [5, 5, 5, 5]) == 10\n assert candidate(prices = [1]) == 1\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 22\n assert candidate(prices = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 15\n assert candidate(prices = [3, 1, 2]) == 4\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(prices = [1, 2, 3, 4, 5]) == 4\n assert candidate(prices = [5, 5, 5, 5, 5, 5]) == 10\n assert candidate(prices = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 40\n assert candidate(prices = [10, 20, 30, 40, 50]) == 40\n assert candidate(prices = [100, 1, 100, 1, 100]) == 102\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 18\n assert candidate(prices = [5, 4, 3, 2, 1]) == 8\n assert candidate(prices = [26, 18, 6, 12, 49, 7, 45, 45]) == 39\n assert candidate(prices = [5]) == 5\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(prices = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 300000\n assert candidate(prices = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 104\n assert candidate(prices = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1266\n assert candidate(prices = [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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317]) == 221\n assert candidate(prices = [50, 40, 30, 20, 10, 5, 4, 3, 2, 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 85\n assert candidate(prices = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 5\n assert candidate(prices = [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]) == 374\n assert candidate(prices = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 3\n assert candidate(prices = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 20\n assert candidate(prices = [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]) == 10\n assert candidate(prices = [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]) == 42\n assert candidate(prices = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900]) == 225000\n assert candidate(prices = [10, 1, 5, 2, 8, 3, 6, 4, 7, 9]) == 16\n assert candidate(prices = [16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 20737\n assert candidate(prices = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 1004\n assert candidate(prices = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 6\n assert candidate(prices = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 14\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(prices = [1000, 1, 500, 2, 250, 3, 125, 4, 62, 5, 31, 6, 15, 7, 7]) == 1007\n assert candidate(prices = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 801\n assert candidate(prices = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 72\n assert candidate(prices = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 14\n assert candidate(prices = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 20\n assert candidate(prices = [26, 18, 6, 12, 49, 7, 45, 45, 100, 50, 25, 12, 6, 3, 1]) == 45\n assert candidate(prices = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 180\n assert candidate(prices = [3, 6, 2, 8, 4, 10, 1]) == 6\n assert candidate(prices = [3, 1, 2, 2, 1, 3, 1, 2, 2, 1, 3, 1, 2, 2, 1]) == 6\n assert candidate(prices = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 21\n assert candidate(prices = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 58\n assert candidate(prices = [26, 18, 6, 12, 49, 7, 45, 45, 10, 20, 30, 40, 50]) == 49\n assert candidate(prices = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 10\n assert candidate(prices = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16]) == 98\n assert candidate(prices = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 2, 4, 6, 8]) == 45\n assert candidate(prices = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 41\n assert candidate(prices = [5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(prices = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 12\n assert candidate(prices = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 1]) == 46\n assert candidate(prices = [26, 18, 6, 12, 49, 7, 45, 45, 30, 20, 10, 5, 2, 1, 10, 20, 30, 40, 50, 60]) == 41\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(prices = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(prices = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 4\n assert candidate(prices = [10, 25, 5, 7, 12, 20, 3, 8, 15, 6, 2, 9, 11, 4, 14]) == 20\n assert candidate(prices = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 26\n assert candidate(prices = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 40\n assert candidate(prices = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]) == 17\n assert candidate(prices = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 40\n assert candidate(prices = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 220\n assert candidate(prices = [5, 2, 1, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 8\n assert candidate(prices = [5, 5, 5, 5, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(prices = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 139\n assert candidate(prices = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10]) == 40\n assert candidate(prices = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 139\n assert candidate(prices = [100, 50, 20, 10, 5, 2, 1, 2, 5, 10, 20, 50, 100]) == 121\n assert candidate(prices = [10, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 13\n assert candidate(prices = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 19\n assert candidate(prices = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 32\n assert candidate(prices = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 4\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 18\n assert candidate(prices = [3, 1, 2, 5, 4, 6, 3]) == 8\n assert candidate(prices = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1]) == 1266\n assert candidate(prices = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 30\n assert candidate(prices = [10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40]) == 90\n assert candidate(prices = [1000, 1, 100, 1, 10, 1, 1000, 1, 100, 1, 10, 1, 1000, 1, 100]) == 1003\n assert candidate(prices = [10, 5, 2, 1, 3, 1, 2, 1]) == 13\n assert candidate(prices = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 2200\n assert candidate(prices = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2]) == 4\n assert candidate(prices = [1, 100, 2, 200, 3, 300, 4, 400, 5, 500]) == 6\n assert candidate(prices = [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, 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]) == 30\n assert candidate(prices = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 100003\n assert candidate(prices = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 25\n assert candidate(prices = [100, 200, 50, 75, 300, 100, 50, 150]) == 200\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1]) == 18\n assert candidate(prices = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 6\n assert candidate(prices = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 7\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(prices = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 10, 20, 30, 40, 50]) == 9\n assert candidate(prices = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 150\n assert candidate(prices = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 374\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(prices = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 3\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == 23\n assert candidate(prices = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 74\n assert candidate(prices = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 9\n assert candidate(prices = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 300\n assert candidate(prices = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(prices = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 4\n assert candidate(prices = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110]) == 130\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 22\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(prices = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 13\n assert candidate(prices = [210, 190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1]) == 507\n assert candidate(prices = [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]) == 89\n assert candidate(prices = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 24\n assert candidate(prices = [100, 200, 1, 500, 10, 300, 20, 400, 3, 600]) == 111\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(prices = [100, 50, 20, 10, 5, 1]) == 120\n", "comparison": "exact"}, "public_tests": ["[3,1,2]", "[1,10,1,1]", "[26,18,6,12,49,7,45,45]"], "hints": ["The intended solution uses Dynamic Programming.", "Let dp[i] denote the minimum number of coins, such that we bought i^th fruit and acquired all the fruits in the range [i...n].", "dp[i] = min(dp[i], dp[j] + prices[i]) , where j is in the range [i + 1, i + 1 + i]."], "metadata": {"canonical_parameter_names": ["prices"], "leetcode_dataset_entry_point": "Solution().minimumCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:01+00:00", "tests_total": 122, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "dynamic-programming", "queue", "heap-priority-queue", "monotonic-queue"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_coins(prices)", "container": null, "callable": "minimum_coins", "parameters": [{"name": "prices", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2945, "task_id": "find-maximum-non-decreasing-array-length", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums.\n\nYou can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you select subarray [3,5] the array will convert to [1,8,6].\n\nReturn the maximum length of a non-decreasing array that can be made after applying operations.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [5,2,2]\nOutput: 1\nExplanation: This array with length 3 is not non-decreasing.\nWe have two ways to make the array length two.\nFirst, choosing subarray [2,2] converts the array to [5,4].\nSecond, choosing subarray [5,2] converts the array to [7,2].\nIn these two ways the array is not non-decreasing.\nAnd if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing.\nSo the answer is 1.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 4\nExplanation: The array is non-decreasing. So the answer is 4.\n\nExample 3:\n\nInput: nums = [4,3,2,6]\nOutput: 3\nExplanation: Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.\nBecause the given array is not non-decreasing, the maximum possible answer is 3.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8]) == 10\n assert candidate(nums = [1, 100, 1000]) == 3\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [3, 3, 3, 3]) == 4\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8]) == 4\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [1, 2, 4, 3, 5]) == 4\n assert candidate(nums = [4, 3, 2, 6]) == 3\n assert candidate(nums = [100, 10, 1]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [7, 7, 7, 7, 7]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [9, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [10, 5, 7, 10]) == 2\n assert candidate(nums = [10, 5, 7, 10, 6]) == 3\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == 5\n assert candidate(nums = [1, 100, 2, 101, 1]) == 3\n assert candidate(nums = [5, 2, 2]) == 1\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000]) == 2\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 4\n assert candidate(nums = [3, 5, 2, 5, 6]) == 3\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 2\n assert candidate(nums = [5, 6, 2, 8, 3, 9, 1, 10, 4, 11]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [1, 10, 1, 10, 1, 10]) == 4\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 19\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 500, 600, 700, 800, 900]) == 12\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 12\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 11\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93]) == 9\n assert candidate(nums = [10, 20, 15, 25, 30, 35, 40, 45, 50]) == 5\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 40, 45]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 12\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 12\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 13\n assert candidate(nums = [100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 1]) == 4\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 6\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 7\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]) == 10\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 10\n assert candidate(nums = [100, 200, 100, 300, 200, 400, 300, 500]) == 5\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15]) == 20\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 6\n assert candidate(nums = [10, 5, 3, 8, 12, 7, 9, 11]) == 4\n assert candidate(nums = [1, 3, 5, 4, 6, 7, 5, 8, 9, 10, 11, 9, 12, 13, 14]) == 9\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 3\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 8\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 6\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 6, 7, 8, 9]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 20\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 5\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6]) == 5\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1]) == 13\n assert candidate(nums = [1, 100, 2, 101, 3, 102, 4, 103, 5, 104]) == 6\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15]) == 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]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 10, 100, 1000, 10000, 1, 10, 100, 1000, 10000]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 3\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 5]) == 6\n assert candidate(nums = [5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 20\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 13\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 10\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5]) == 8\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 11\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 7\n assert candidate(nums = [100, 200, 150, 250, 300, 100, 400, 500, 350, 450]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 11\n assert candidate(nums = [10, 5, 3, 7, 8, 12, 1]) == 3\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 8, 5, 9, 10]) == 7\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [10, 5, 1, 1, 1, 15, 20, 25, 30]) == 5\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 45, 50]) == 5\n assert candidate(nums = [5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 7\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9]) == 5\n", "comparison": "exact"}, "public_tests": ["[5,2,2]", "[1,2,3,4]", "[4,3,2,6]"], "hints": ["Let dp[i] be the maximum number of elements in the increasing sequence after processing the first i elements of the original array.", "We have dp[0] = 0. dp[i + 1] >= dp[i] (since if we have the solution for the first i elements, we can always merge the last one of the first i + 1 elements which is nums[i] into the solution of the first i elements.", "For i > 0, we want to dp[i] = max(dp[j] + 1) where sum(nums[i - 1] + nums[i - 2] +… + nums[j]) >= v[j] and v[j] is the last element of the solution ending with nums[j - 1]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findMaximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:04+00:00", "tests_total": 111, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "stack", "queue", "monotonic-stack", "prefix-sum", "monotonic-queue"]}, "language": "ruby", "interface": {"raw_signature": "def find_maximum_length(nums)", "container": null, "callable": "find_maximum_length", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2946, "task_id": "matrix-similarity-after-cyclic-shifts", "difficulty": "Easy", "problem_description": "You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed.\n\nThe following process happens k times:\n\n- Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left.\n\n- Odd-indexed rows (1, 3, 5, ...) are cyclically shifted to the right.\n\nReturn true if the final modified matrix after k steps is identical to the original matrix, and false otherwise.\n\nExample 1:\n\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 4\nOutput: false\nExplanation:\nIn each step left shift is applied to rows 0 and 2 (even indices), and right shift to row 1 (odd index).\n\nExample 2:\n\nInput: mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\nOutput: true\nExplanation:\n\nExample 3:\n\nInput: mat = [[2,2],[2,2]], k = 3\nOutput: true\nExplanation:\nAs all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same.\n\nConstraints:\n\n- 1 <= mat.length <= 25\n- 1 <= mat[i].length <= 25\n- 1 <= mat[i][j] <= 25\n- 1 <= k <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[2, 2], [2, 2]],k = 3) == True\n assert candidate(mat = [[1, 2, 1, 2], [5, 5, 5, 5], [6, 3, 6, 3]],k = 2) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],k = 1) == False\n assert candidate(mat = [[3, 3, 3], [3, 3, 3], [3, 3, 3]],k = 25) == True\n assert candidate(mat = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 10) == True\n assert candidate(mat = [[3, 4, 5], [6, 7, 8]],k = 1) == False\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],k = 50) == True\n assert candidate(mat = [[5, 10], [15, 20]],k = 1) == False\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 4) == False\n assert candidate(mat = [[3, 4, 5], [8, 7, 6]],k = 2) == False\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 4) == True\n assert candidate(mat = [[2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [3, 3, 3, 3, 3]],k = 7) == False\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15], [16, 14, 12, 10, 8, 6, 4, 2]],k = 8) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 17) == False\n assert candidate(mat = [[7, 7, 7], [7, 7, 7], [7, 7, 7], [7, 7, 7], [7, 7, 7]],k = 20) == True\n assert candidate(mat = [[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, 1, 2, 3]],k = 7) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 20) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]],k = 12) == True\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21]],k = 1) == False\n assert candidate(mat = [[7, 8, 9], [8, 9, 7], [9, 7, 8]],k = 9) == True\n assert candidate(mat = [[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, 24, 23, 22, 21, 20]],k = 30) == True\n assert candidate(mat = [[7, 8, 9, 10], [11, 12, 13, 14], [15, 16, 17, 18], [19, 20, 21, 22]],k = 8) == True\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1, 1], [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 = 25) == True\n assert candidate(mat = [[7, 8, 9, 10], [11, 12, 13, 14], [15, 16, 17, 18], [19, 20, 21, 22]],k = 40) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 25) == False\n assert candidate(mat = [[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]],k = 25) == True\n assert candidate(mat = [[1, 2, 1, 2], [2, 1, 2, 1], [1, 2, 1, 2], [2, 1, 2, 1]],k = 3) == False\n assert candidate(mat = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],k = 1) == False\n assert candidate(mat = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]],k = 1) == False\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],k = 3) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 5) == False\n assert candidate(mat = [[1, 2, 3], [3, 2, 1], [1, 2, 3], [3, 2, 1], [1, 2, 3]],k = 7) == False\n assert candidate(mat = [[1, 1, 2, 2, 3, 3], [3, 3, 1, 1, 2, 2], [2, 2, 3, 3, 1, 1], [1, 1, 2, 2, 3, 3]],k = 6) == True\n assert candidate(mat = [[25, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]],k = 10) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]],k = 15) == False\n assert candidate(mat = [[1, 1, 2, 2], [3, 3, 4, 4], [1, 1, 2, 2], [3, 3, 4, 4]],k = 2) == False\n assert candidate(mat = [[1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1]],k = 12) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]],k = 6) == True\n assert candidate(mat = [[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 = 25) == True\n assert candidate(mat = [[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 = 30) == True\n assert candidate(mat = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],k = 50) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2]],k = 12) == True\n assert candidate(mat = [[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, 2, 2, 2, 2, 2]],k = 30) == True\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],k = 10) == False\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2]],k = 3) == False\n assert candidate(mat = [[7, 7, 7, 7, 7, 7], [8, 8, 8, 8, 8, 8], [9, 9, 9, 9, 9, 9], [10, 10, 10, 10, 10, 10]],k = 15) == True\n assert candidate(mat = [[2, 3, 2, 3], [3, 2, 3, 2], [2, 3, 2, 3], [3, 2, 3, 2]],k = 7) == False\n assert candidate(mat = [[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 = 20) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 8) == True\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [10, 9, 8, 7, 6]],k = 5) == True\n assert candidate(mat = [[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]],k = 5) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6]],k = 6) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1]],k = 16) == True\n assert candidate(mat = [[1, 2, 3, 4], [4, 3, 2, 1], [1, 2, 3, 4], [4, 3, 2, 1]],k = 2) == False\n assert candidate(mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],k = 5) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]],k = 12) == True\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]],k = 8) == True\n assert candidate(mat = [[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 = 10) == True\n assert candidate(mat = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]],k = 49) == True\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2]],k = 5) == True\n assert candidate(mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],k = 5) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11], [12, 10, 8, 6, 4, 2]],k = 3) == False\n assert candidate(mat = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]],k = 1) == False\n assert candidate(mat = [[1, 1, 2, 2, 3, 3], [4, 4, 5, 5, 6, 6], [7, 7, 8, 8, 9, 9]],k = 3) == False\n assert candidate(mat = [[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]],k = 24) == False\n assert candidate(mat = [[5, 5, 5, 5, 5], [4, 4, 4, 4, 4], [3, 3, 3, 3, 3], [2, 2, 2, 2, 2]],k = 50) == True\n assert candidate(mat = [[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, 1, 2, 3]],k = 12) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7]],k = 14) == True\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],k = 3) == True\n assert candidate(mat = [[23, 24, 25, 23, 24], [24, 25, 23, 24, 25], [25, 23, 24, 25, 23], [23, 24, 25, 23, 24], [24, 25, 23, 24, 25]],k = 7) == False\n assert candidate(mat = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]],k = 30) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8, 10], [10, 8, 6, 4, 2, 1, 3, 5, 7, 9]],k = 25) == False\n assert candidate(mat = [[1, 2, 3], [6, 5, 4], [7, 8, 9], [12, 11, 10], [13, 14, 15]],k = 15) == True\n assert candidate(mat = [[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]],k = 30) == True\n assert candidate(mat = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9]],k = 25) == False\n assert candidate(mat = [[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]],k = 40) == True\n assert candidate(mat = [[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]],k = 1) == False\n assert candidate(mat = [[1, 2, 3], [3, 2, 1], [1, 2, 3], [3, 2, 1]],k = 6) == True\n assert candidate(mat = [[1, 2], [2, 1], [1, 2], [2, 1]],k = 3) == False\n assert candidate(mat = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [3, 4, 5, 6, 7]],k = 15) == True\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2]],k = 14) == True\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],k = 15) == True\n assert candidate(mat = [[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 = 15) == True\n assert candidate(mat = [[25, 24, 23], [22, 21, 20], [19, 18, 17]],k = 20) == False\n assert candidate(mat = [[1, 1, 2, 2], [2, 2, 1, 1], [3, 3, 4, 4], [4, 4, 3, 3]],k = 15) == False\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15]],k = 8) == True\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[4,5,6],[7,8,9]]\n4", "[[1,2,1,2],[5,5,5,5],[6,3,6,3]]\n2", "[[2,2],[2,2]]\n3"], "hints": ["You can reduce k shifts to (k % n) shifts as after n shifts the matrix will become similar to the initial matrix."], "metadata": {"canonical_parameter_names": ["mat", "k"], "leetcode_dataset_entry_point": "Solution().areSimilar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:06+00:00", "tests_total": 99, "tests_dropped": 13, "flags": ["has_images"], "topic_tags": ["array", "math", "matrix", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def are_similar(mat, k)", "container": null, "callable": "are_similar", "parameters": [{"name": "mat", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2947, "task_id": "count-beautiful-substrings-i", "difficulty": "Medium", "problem_description": "You are given a string s and a positive integer k.\n\nLet vowels and consonants be the number of vowels and consonants in a string.\n\nA string is beautiful if:\n\n- vowels == consonants.\n- (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n\nReturn the number of non-empty beautiful substrings in the given string s.\n\nA substring is a contiguous sequence of characters in a string.\n\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\n\nConsonant letters in English are every letter except vowels.\n\nExample 1:\n\nInput: s = \"baeyh\", k = 2\nOutput: 2\nExplanation: There are 2 beautiful substrings in the given string.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\nYou can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]).\nYou can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\nIt can be shown that there are only 2 beautiful substrings in the given string.\n\nExample 2:\n\nInput: s = \"abba\", k = 1\nOutput: 3\nExplanation: There are 3 beautiful substrings in the given string.\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\nIt can be shown that there are only 3 beautiful substrings in the given string.\n\nExample 3:\n\nInput: s = \"bcdf\", k = 1\nOutput: 0\nExplanation: There are no beautiful substrings in the given string.\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- 1 <= k <= 1000\n- s consists of only English lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aeaeaeae\",k = 8) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyz\",k = 2) == 0\n assert candidate(s = \"aebcdfe\",k = 3) == 0\n assert candidate(s = \"baeyh\",k = 2) == 2\n assert candidate(s = \"aebcdeedaa\",k = 4) == 6\n assert candidate(s = \"bcdf\",k = 1) == 0\n assert candidate(s = \"abcd\",k = 1) == 1\n assert candidate(s = \"abba\",k = 1) == 3\n assert candidate(s = \"bcdfgh\",k = 2) == 0\n assert candidate(s = \"aabbccdd\",k = 2) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 2) == 0\n assert candidate(s = \"a\",k = 1) == 0\n assert candidate(s = \"aabb\",k = 2) == 1\n assert candidate(s = \"aeiou\",k = 5) == 0\n assert candidate(s = \"abcdefgh\",k = 4) == 0\n assert candidate(s = \"b\",k = 1) == 0\n assert candidate(s = \"aabbccddeeff\",k = 4) == 4\n assert candidate(s = \"aeiouaeiouaeiouaeiou\",k = 25) == 0\n assert candidate(s = \"aabbaaeeiioouuccddffgg\",k = 10) == 1\n assert candidate(s = \"aeiouaeiouaeiouaeiou\",k = 200) == 0\n assert candidate(s = \"aeioubcdfgh\",k = 5) == 1\n assert candidate(s = \"aeioubcdfghjklmnpqrstvwxyzaeioubcdfghjklmnpqrstvwxyz\",k = 12) == 0\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 7) == 0\n assert candidate(s = \"vowelsandconsonantsareimportant\",k = 12) == 0\n assert candidate(s = \"abacabadabacaba\",k = 3) == 14\n assert candidate(s = \"aebcdfeab\",k = 2) == 4\n assert candidate(s = \"aeioubcdefghijklmnopqrstuvwxyz\",k = 10) == 0\n assert candidate(s = \"vowelsconsonantsvowelsconsonants\",k = 8) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 20) == 0\n assert candidate(s = \"vowelsandconsonants\",k = 6) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 100) == 0\n assert candidate(s = \"aabbccddeeffgg\",k = 12) == 0\n assert candidate(s = \"aebcdefghijklmnopqrstuvwxyz\",k = 7) == 0\n assert candidate(s = \"aaaaaaaaaaaabbbbbbbbbbcccccccccc\",k = 25) == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 7) == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 0\n assert candidate(s = \"bbbbbbaaaaeiiuuuccccc\",k = 15) == 0\n assert candidate(s = \"thisisaverylongstringwithmixedcharacters\",k = 7) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 12) == 0\n assert candidate(s = \"beautifulstring\",k = 3) == 2\n assert candidate(s = \"abcdefghijabcdefghij\",k = 20) == 0\n assert candidate(s = \"consonantsandvowelsareequal\",k = 14) == 0\n assert candidate(s = \"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc\",k = 2) == 0\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\",k = 25) == 0\n assert candidate(s = \"zzzzzaaaaabbbbcccc\",k = 16) == 2\n assert candidate(s = \"aeioubcdfg\",k = 5) == 1\n assert candidate(s = \"bcdfg\",k = 1) == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 100) == 0\n assert candidate(s = \"aeiouaeiou\",k = 5) == 0\n assert candidate(s = \"aeiou\",k = 1) == 0\n assert candidate(s = \"aabbaaeebbeeaabbaa\",k = 3) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 49) == 0\n assert candidate(s = \"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc\",k = 3) == 0\n assert candidate(s = \"aaeeiioouubbbccddffgg\",k = 10) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 9) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 6) == 0\n assert candidate(s = \"vowelsandconsonants\",k = 10) == 0\n assert candidate(s = \"xylophoneaeiouaeiou\",k = 12) == 1\n assert candidate(s = \"exampleexampleexample\",k = 9) == 10\n assert candidate(s = \"aabbccddeeff\",k = 6) == 0\n assert candidate(s = \"xylophoneisfun\",k = 7) == 0\n assert candidate(s = \"beautifulstringwithvowelsandconsonants\",k = 20) == 0\n assert candidate(s = \"aeiouaeiou\",k = 25) == 0\n assert candidate(s = \"aeiouzzzzzzzzzz\",k = 200) == 0\n assert candidate(s = \"aeioubcdfghjklmnpqrstvwxyz\",k = 5) == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 21) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 10) == 0\n assert candidate(s = \"bbaaeeddbb\",k = 4) == 5\n assert candidate(s = \"eeeeeeeeeeaaaaaaaaaaiiiiiiiiiiooooooooouuuuuuuuuu\",k = 100) == 0\n assert candidate(s = \"zzzzyyyyxxxx\",k = 9) == 0\n assert candidate(s = \"thisisaverylongstringwithvowelsandconsonants\",k = 20) == 0\n assert candidate(s = \"thisisbeautifulstringwithvariousvowelsandconsonants\",k = 8) == 10\n assert candidate(s = \"aeiouaeiouaeiouaeioubcdfghjklmnpqrstvwxy\",k = 11) == 1\n assert candidate(s = \"beautifulstringwithvowelandconsonants\",k = 7) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 5) == 0\n assert candidate(s = \"consonantsconsonantsconsonants\",k = 30) == 0\n assert candidate(s = \"mamamamamamamamama\",k = 2) == 36\n assert candidate(s = \"thisisaverylongstringwithmanyvowelsandconsonants\",k = 12) == 0\n assert candidate(s = \"vowelsarebeautiful\",k = 6) == 3\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzaeiou\",k = 10) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 8) == 0\n assert candidate(s = \"aeaeaeaeaeaeaeaeaeae\",k = 2) == 0\n assert candidate(s = \"aeiouaeiouaeiouaeiou\",k = 4) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 15) == 0\n assert candidate(s = \"aaaeeeiioouu\",k = 1) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxybcdfghjklmnpqrstvwxy\",k = 9) == 0\n assert candidate(s = \"zzzzzzzzzz\",k = 100) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 50) == 0\n", "comparison": "exact"}, "public_tests": ["\"baeyh\"\n2", "\"abba\"\n1", "\"bcdf\"\n1"], "hints": ["Iterate over all substrings and maintain the frequencies of vowels and consonants."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().beautifulSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:08+00:00", "tests_total": 90, "tests_dropped": 2, "flags": [], "topic_tags": ["hash-table", "math", "string", "enumeration", "number-theory", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def beautiful_substrings(s, k)", "container": null, "callable": "beautiful_substrings", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2948, "task_id": "make-lexicographically-smallest-array-by-swapping-elements", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of positive integers nums and a positive integer limit.\n\nIn one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.\n\nReturn the lexicographically smallest array that can be obtained by performing the operation any number of times.\n\nAn array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is less than the corresponding element in b. For example, the array [2,10,3] is lexicographically smaller than the array [10,2,3] because they differ at index 0 and 2 < 10.\n\nExample 1:\n\nInput: nums = [1,5,3,9,8], limit = 2\nOutput: [1,3,5,8,9]\nExplanation: Apply the operation 2 times:\n- Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]\n- Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\nNote that it may be possible to get the same result by doing different operations.\n\nExample 2:\n\nInput: nums = [1,7,6,18,2,1], limit = 3\nOutput: [1,6,7,18,1,2]\nExplanation: Apply the operation 3 times:\n- Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]\n- Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]\n- Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\n\nExample 3:\n\nInput: nums = [1,7,28,19,10], limit = 3\nOutput: [1,7,28,19,10]\nExplanation: [1,7,28,19,10] is the lexicographically smallest array we can obtain because we cannot apply the operation on any two indices.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= limit <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],limit = 1) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],limit = 2) == [1, 1, 2, 3, 3, 9, 4, 5, 5, 5, 6]\n assert candidate(nums = [9, 7, 5, 3, 1],limit = 2) == [1, 3, 5, 7, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 20, 30, 40, 50],limit = 5) == [10, 20, 30, 40, 50]\n assert candidate(nums = [10, 9, 8, 7, 6],limit = 1) == [6, 7, 8, 9, 10]\n assert candidate(nums = [1, 7, 28, 19, 10],limit = 3) == [1, 7, 28, 19, 10]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],limit = 9) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 3, 5, 7, 9],limit = 2) == [1, 3, 5, 7, 9]\n assert candidate(nums = [5, 4, 3, 2, 1],limit = 1) == [1, 2, 3, 4, 5]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],limit = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 7, 6, 18, 2, 1],limit = 3) == [1, 6, 7, 18, 1, 2]\n assert candidate(nums = [5, 5, 5, 5, 5],limit = 1) == [5, 5, 5, 5, 5]\n assert candidate(nums = [1, 2, 3, 4, 5],limit = 10) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1, 5, 3, 9, 8],limit = 2) == [1, 3, 5, 8, 9]\n assert candidate(nums = [10, 20, 15, 18, 17, 25, 30, 35, 40, 45],limit = 5) == [10, 15, 17, 18, 20, 25, 30, 35, 40, 45]\n assert candidate(nums = [3, 8, 13, 18, 23, 28, 33],limit = 10) == [3, 8, 13, 18, 23, 28, 33]\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [5, 9, 2, 8, 1, 7, 3, 6, 4, 10],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 5, 1, 8, 7, 2, 4, 6],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\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],limit = 1) == [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],limit = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [10, 14, 13, 12, 11, 9, 8, 7, 6, 5],limit = 2) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [1, 3, 2, 6, 5, 4, 9, 7, 8, 10],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],limit = 2) == [1, 1, 2, 3, 3, 9, 4, 5, 5, 5, 6]\n assert candidate(nums = [100, 101, 99, 102, 103, 98, 104, 105, 97, 106],limit = 5) == [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99],limit = 10) == [9, 19, 29, 39, 49, 59, 69, 79, 89, 99]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],limit = 50) == [1, 96, 2, 97, 3, 98, 4, 99, 5, 100]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],limit = 15) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],limit = 3) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],limit = 25) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 5, 3, 9, 8, 4, 6, 7, 2, 10],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],limit = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 2) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],limit = 2) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],limit = 1) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 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],limit = 1) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(nums = [1, 6, 8, 2, 4, 3, 9, 10, 12, 11],limit = 3) == [1, 2, 3, 4, 6, 8, 9, 10, 11, 12]\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],limit = 1) == [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],limit = 2) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],limit = 2) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],limit = 5) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],limit = 10) == [999999995, 999999996, 999999997, 999999998, 999999999, 1000000000]\n assert candidate(nums = [109, 98, 87, 76, 65, 54, 43, 32, 21, 10],limit = 10) == [109, 98, 87, 76, 65, 54, 43, 32, 21, 10]\n assert candidate(nums = [1, 5, 3, 9, 8, 2, 6, 4, 10, 7],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5],limit = 5) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [2, 1, 5, 6, 3, 4, 8, 7, 10, 9],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],limit = 1) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 3, 9, 1, 5, 11, 13, 12, 14, 10],limit = 3) == [1, 3, 5, 7, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [4, 1, 5, 3, 2, 8, 7, 6],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = [1, 5, 3, 7, 2, 6, 4, 8, 10, 9],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],limit = 5) == [91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],limit = 5) == [999999991, 999999992, 999999993, 999999994, 999999995, 999999996, 999999997, 999999998, 999999999, 1000000000]\n assert candidate(nums = [15, 20, 10, 12, 14, 13, 9, 8, 7, 6],limit = 3) == [6, 20, 7, 8, 9, 10, 12, 13, 14, 15]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],limit = 2) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],limit = 6) == [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],limit = 5) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],limit = 2) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],limit = 100000000) == [999999990, 999999991, 999999992, 999999993, 999999994, 999999995, 999999996, 999999997, 999999998, 999999999]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],limit = 50) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],limit = 4) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5],limit = 9) == [1, 2, 20, 3, 30, 4, 40, 5, 50, 10]\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59],limit = 6) == [5, 11, 17, 23, 29, 35, 41, 47, 53, 59]\n assert candidate(nums = [5, 1, 4, 3, 2, 8, 7, 6, 10, 9],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],limit = 15) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 4, 2, 5, 3, 8, 6, 7, 10, 9],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],limit = 1000000000) == [1, 2, 3, 4, 5, 999999996, 999999997, 999999998, 999999999, 1000000000]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],limit = 2) == [91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],limit = 500000000) == [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],limit = 3) == [999999995, 999999996, 999999997, 999999998, 999999999, 1000000000]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],limit = 1) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],limit = 15) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],limit = 10) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],limit = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5],limit = 4) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 8, 7, 10, 9],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5],limit = 9) == [1, 2, 20, 3, 30, 4, 40, 5, 50, 10]\n assert candidate(nums = [10, 2, 14, 4, 18, 6, 20, 8, 22, 10],limit = 6) == [2, 4, 6, 8, 10, 10, 14, 18, 20, 22]\n assert candidate(nums = [3, 8, 2, 6, 5, 10, 7, 1],limit = 3) == [1, 2, 3, 5, 6, 7, 8, 10]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],limit = 1) == [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109],limit = 10) == [10, 21, 32, 43, 54, 65, 76, 87, 98, 109]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],limit = 2) == [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],limit = 5) == [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [3, 8, 1, 6, 2, 7, 5, 10, 4, 9],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 9) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],limit = 1) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [10, 5, 15, 20, 25, 30, 35, 40, 45, 50],limit = 5) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 4) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16],limit = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100],limit = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [5, 9, 2, 6, 3, 8, 1, 7, 4, 10],limit = 3) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 1, 2, 5, 4, 7, 6, 9, 8, 10],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 15, 13, 12, 11, 20, 19, 18, 17, 16],limit = 2) == [10, 11, 12, 13, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [10, 25, 20, 30, 35, 15, 5, 40, 45, 50],limit = 5) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],limit = 5) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],limit = 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],limit = 2) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36],limit = 15) == [1, 6, 11, 16, 21, 26, 31, 36]\n assert candidate(nums = [5, 15, 10, 20, 25, 30, 35, 40, 45, 50],limit = 10) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56],limit = 21) == [7, 14, 21, 28, 35, 42, 49, 56]\n assert candidate(nums = [15, 10, 5, 20, 25, 30, 35, 40, 45, 50],limit = 5) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [3, 12, 21, 30, 39, 48, 57, 66, 75, 84],limit = 9) == [3, 12, 21, 30, 39, 48, 57, 66, 75, 84]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],limit = 1) == [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [5, 1, 4, 2, 3, 8, 6, 7, 10, 9],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 5, 15, 20, 25, 30],limit = 5) == [5, 10, 15, 20, 25, 30]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],limit = 15) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],limit = 4) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],limit = 500) == [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],limit = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],limit = 4) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\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],limit = 1) == [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]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],limit = 1) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(nums = [3, 1, 2, 5, 4, 7, 6, 9, 8, 10],limit = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", "comparison": "exact"}, "public_tests": ["[1,5,3,9,8]\n2", "[1,7,6,18,2,1]\n3", "[1,7,28,19,10]\n3"], "hints": ["Construct a virtual graph where all elements in nums are nodes and the pairs satisfying the condition have an edge between them.", "Instead of constructing all edges, we only care about the connected components.", "Can we use DSU?", "Sort nums. Now we just need to consider if the consecutive elements have an edge to check if they belong to the same connected component. Hence, all connected components become a list of position-consecutive elements after sorting.", "For each index of nums from 0 to nums.length - 1 we can change it to the current minimum value we have in its connected component and remove that value from the connected component."], "metadata": {"canonical_parameter_names": ["nums", "limit"], "leetcode_dataset_entry_point": "Solution().lexicographicallySmallestArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:10+00:00", "tests_total": 138, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "union-find", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def lexicographically_smallest_array(nums, limit)", "container": null, "callable": "lexicographically_smallest_array", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "limit", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2949, "task_id": "count-beautiful-substrings-ii", "difficulty": "Hard", "problem_description": "You are given a string s and a positive integer k.\n\nLet vowels and consonants be the number of vowels and consonants in a string.\n\nA string is beautiful if:\n\n- vowels == consonants.\n- (vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n\nReturn the number of non-empty beautiful substrings in the given string s.\n\nA substring is a contiguous sequence of characters in a string.\n\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\n\nConsonant letters in English are every letter except vowels.\n\nExample 1:\n\nInput: s = \"baeyh\", k = 2\nOutput: 2\nExplanation: There are 2 beautiful substrings in the given string.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\nYou can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]).\nYou can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\nIt can be shown that there are only 2 beautiful substrings in the given string.\n\nExample 2:\n\nInput: s = \"abba\", k = 1\nOutput: 3\nExplanation: There are 3 beautiful substrings in the given string.\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\nIt can be shown that there are only 3 beautiful substrings in the given string.\n\nExample 3:\n\nInput: s = \"bcdf\", k = 1\nOutput: 0\nExplanation: There are no beautiful substrings in the given string.\n\nConstraints:\n\n- 1 <= s.length <= 5 * 10^4\n- 1 <= k <= 1000\n- s consists of only English lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aeiaaioaaaaeiiiiouuuooououuoiiiuuuuaeiou\",k = 10) == 0\n assert candidate(s = \"aabbcc\",k = 4) == 1\n assert candidate(s = \"zzzzz\",k = 1) == 0\n assert candidate(s = \"baeyh\",k = 2) == 2\n assert candidate(s = \"bbaeaeaaeiou\",k = 3) == 0\n assert candidate(s = \"bcdf\",k = 1) == 0\n assert candidate(s = \"aeiou\",k = 25) == 0\n assert candidate(s = \"vowelsandconsonants\",k = 10) == 0\n assert candidate(s = \"abba\",k = 1) == 3\n assert candidate(s = \"abcdefghij\",k = 2) == 0\n assert candidate(s = \"aebcde\",k = 3) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 7) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 2) == 0\n assert candidate(s = \"a\",k = 1) == 0\n assert candidate(s = \"aeiou\",k = 5) == 0\n assert candidate(s = \"beautifulstring\",k = 7) == 0\n assert candidate(s = \"aabbccddeeff\",k = 4) == 4\n assert candidate(s = \"aaabbbcccddd\",k = 6) == 0\n assert candidate(s = \"consonantsandvowels\",k = 20) == 0\n assert candidate(s = \"bbaaccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 12) == 0\n assert candidate(s = \"vowelsvowelsvowelsvowels\",k = 4) == 8\n assert candidate(s = \"thisisaverylongstringwithabunchoflettersandvariousvowelsandconsonants\",k = 10) == 0\n assert candidate(s = \"bcbcbcbcbcbcbcbcbcbcbcbcbc\",k = 11) == 0\n assert candidate(s = \"aebcdefghijklmnopqrstuvwxyz\",k = 5) == 0\n assert candidate(s = \"abacabadabacaba\",k = 10) == 0\n assert candidate(s = \"vowelsandconsonants\",k = 6) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 100) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 13) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 20) == 0\n assert candidate(s = \"aeiouaeiouaeiou\",k = 25) == 0\n assert candidate(s = \"vwxyzvwxyzvwxyzvwxyz\",k = 20) == 0\n assert candidate(s = \"abcdabcdabcdabcdabcdabcd\",k = 9) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 10) == 0\n assert candidate(s = \"aaaabbbbccccddddeeeeffff\",k = 16) == 6\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",k = 3) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzbcd\",k = 15) == 0\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",k = 11) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzz\",k = 20) == 0\n assert candidate(s = \"abcdeffedcba\",k = 4) == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 2) == 0\n assert candidate(s = \"repeatedcharactersaaaaaaaabbbbbbbbcccccccc\",k = 16) == 13\n assert candidate(s = \"aaeeiioouu\",k = 10) == 0\n assert candidate(s = \"thisisalongstringwithvariousvowelsandconsonants\",k = 36) == 6\n assert candidate(s = \"beautifulstring\",k = 3) == 2\n assert candidate(s = \"abcdefghefghijklmnopqrstuvwxyz\",k = 8) == 0\n assert candidate(s = \"aeioubcdfghjklmnpqrstvwxyz\",k = 25) == 1\n assert candidate(s = \"zzzzzaaaaabbbbbbccccccdddddd\",k = 12) == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 0\n assert candidate(s = \"aeiouaeiou\",k = 5) == 0\n assert candidate(s = \"aeioubcdfg\",k = 5) == 1\n assert candidate(s = \"bcaedfghioklmnpqrstuvwxyz\",k = 7) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzzzzzzzz\",k = 11) == 0\n assert candidate(s = \"beautifulstring\",k = 2) == 5\n assert candidate(s = \"abababababababababab\",k = 6) == 9\n assert candidate(s = \"aaeeiioouubbccddeeffgghhjjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 10) == 1\n assert candidate(s = \"aeeeeiiioouu\",k = 10) == 0\n assert candidate(s = \"aeiouaeiouaeiou\",k = 3) == 0\n assert candidate(s = \"vowelvowelvowelvowelvowel\",k = 10) == 0\n assert candidate(s = \"aaaaaaaaaaabbbbbbbbbb\",k = 1) == 10\n assert candidate(s = \"abacabadabacaba\",k = 2) == 24\n assert candidate(s = \"aaaabbbbcccc\",k = 10) == 0\n assert candidate(s = \"eiouaeiouaeiouaeiou\",k = 5) == 0\n assert candidate(s = \"aeioubcdfghjklmnpqrstvwxyz\",k = 5) == 1\n assert candidate(s = \"thisisaverylongstringwithvariouscharacters\",k = 11) == 0\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 3) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzbcdfghjklmnpqrstvwxyz\",k = 30) == 0\n assert candidate(s = \"aeiaeiouaeiaeiouaeiaeiou\",k = 18) == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\",k = 50) == 0\n assert candidate(s = \"consonantconsonantconsonant\",k = 15) == 0\n assert candidate(s = \"bcbcbcbcbcbcbc\",k = 3) == 0\n assert candidate(s = \"vowelsconsonants\",k = 4) == 5\n assert candidate(s = \"aebcdeioufhgjk\",k = 12) == 1\n assert candidate(s = \"xylophone\",k = 2) == 2\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 25) == 0\n assert candidate(s = \"xyzabcxyzabc\",k = 9) == 0\n assert candidate(s = \"thisisateststring\",k = 7) == 0\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbb\",k = 100) == 1\n assert candidate(s = \"vowelsandconsonants\",k = 18) == 0\n assert candidate(s = \"bcdfghjklmnpqrstvwxyz\",k = 26) == 0\n assert candidate(s = \"aabbbbcccc\",k = 4) == 1\n assert candidate(s = \"beautifulsubstring\",k = 5) == 2\n assert candidate(s = \"xyzxyzxyzxyz\",k = 9) == 0\n assert candidate(s = \"abecidofug\",k = 8) == 3\n assert candidate(s = \"xyzxyzxyzxyz\",k = 3) == 0\n assert candidate(s = \"aaaabbbbccccdddd\",k = 8) == 1\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewwq\",k = 11) == 0\n assert candidate(s = \"aeiouaeiouaeiouaeiou\",k = 25) == 0\n assert candidate(s = \"aaaaaaaaaeeeeeeiiioooouuuu\",k = 10) == 0\n assert candidate(s = \"consonantsconsonantsconsonants\",k = 9) == 3\n", "comparison": "exact"}, "public_tests": ["\"baeyh\"\n2", "\"abba\"\n1", "\"bcdf\"\n1"], "hints": ["For the given k find all the x integers such that x^2 % k == 0. Notice, that there aren’t many such candidates.", "We can iterate over all such x values and count the number of substrings such that vowels == consonants == x.", "This can be done with prefix sums and hash map."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().beautifulSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:12+00:00", "tests_total": 91, "tests_dropped": 2, "flags": [], "topic_tags": ["hash-table", "math", "string", "number-theory", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def beautiful_substrings(s, k)", "container": null, "callable": "beautiful_substrings", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2951, "task_id": "find-the-peaks", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.\n\nReturn an array that consists of indices of peaks in the given array in any order.\n\nNotes:\n\n- A peak is defined as an element that is strictly greater than its neighboring elements.\n- The first and last elements of the array are not a peak.\n\nExample 1:\n\nInput: mountain = [2,4,4]\nOutput: []\nExplanation: mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.\nmountain[1] also can not be a peak because it is not strictly greater than mountain[2].\nSo the answer is [].\n\nExample 2:\n\nInput: mountain = [1,4,3,8,5]\nOutput: [1,3]\nExplanation: mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.\nmountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].\nBut mountain [1] and mountain[3] are strictly greater than their neighboring elements.\nSo the answer is [1,3].\n\nConstraints:\n\n- 3 <= mountain.length <= 100\n- 1 <= mountain[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5]), [])\n assert answers_match(candidate(mountain=[5, 6, 7, 8, 9, 10, 8, 6, 4]), [5])\n assert answers_match(candidate(mountain=[2, 4, 4]), [])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 4, 3, 2, 1]), [4])\n assert answers_match(candidate(mountain=[10, 20, 10, 20, 10]), [1, 3])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 7]), [])\n assert answers_match(candidate(mountain=[7, 6, 5, 4, 3, 2, 1]), [])\n assert answers_match(candidate(mountain=[1, 4, 3, 8, 5]), [1, 3])\n assert answers_match(candidate(mountain=[1, 2, 3, 1, 2, 3, 1]), [2, 5])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 6, 5]), [1, 3, 5])\n assert answers_match(candidate(mountain=[3, 2, 1, 4, 3, 2, 1]), [3])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 1]), [1, 3, 5])\n assert answers_match(candidate(mountain=[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]), [2, 5, 7])\n assert answers_match(candidate(mountain=[1, 3, 1, 3, 1]), [1, 3])\n assert answers_match(candidate(mountain=[1, 3, 2, 1]), [1])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4]), [1, 3, 5])\n assert answers_match(candidate(mountain=[5, 4, 3, 2, 1]), [])\n assert answers_match(candidate(mountain=[10, 9, 8, 7, 6, 5, 4, 5, 6, 7, 8, 9, 10]), [])\n assert answers_match(candidate(mountain=[50, 40, 30, 20, 10, 20, 30, 20, 10, 20, 30, 20, 10, 20, 30]), [6, 10])\n assert answers_match(candidate(mountain=[10, 20, 15, 25, 20, 30, 25, 35, 30]), [1, 3, 5, 7])\n assert answers_match(candidate(mountain=[8, 9, 7, 10, 8, 11, 9, 12, 10, 13, 11, 14, 12, 15, 13, 16, 14, 17, 15, 18, 16, 19, 17]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21])\n assert answers_match(candidate(mountain=[3, 4, 3, 5, 6, 5, 7, 8, 7, 9, 10, 9, 11, 12, 11, 13, 14, 13, 15, 16, 15]), [1, 4, 7, 10, 13, 16, 19])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6]), [1, 3, 5, 7, 9])\n assert answers_match(candidate(mountain=[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 1, 3, 5, 7, 9, 2, 6, 5, 3, 5, 9]), [2, 5, 7, 11, 13, 17, 19, 21, 29, 31])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 5, 7, 8, 7, 9, 10, 9, 11, 12, 11, 13, 14, 13, 15, 16, 15, 17, 18, 17]), [5, 8, 11, 14, 17, 20, 23])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]), [3, 9])\n assert answers_match(candidate(mountain=[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]), [9, 27])\n assert answers_match(candidate(mountain=[10, 20, 15, 25, 30, 5, 35, 40, 38, 45, 50]), [1, 4, 7])\n assert answers_match(candidate(mountain=[10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 40, 30]), [4, 12])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 2, 1]), [3, 8])\n assert answers_match(candidate(mountain=[5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]), [1, 3, 5, 7, 9])\n assert answers_match(candidate(mountain=[5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]), [9])\n assert answers_match(candidate(mountain=[3, 5, 4, 5, 4, 5, 4, 5, 4, 5]), [1, 3, 5, 7])\n assert answers_match(candidate(mountain=[1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1, 3, 5, 7, 9, 11, 9, 7, 5, 3]), [5, 15])\n assert answers_match(candidate(mountain=[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]), [2, 5, 7])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7, 6, 5, 4, 3]), [1, 3, 5, 7, 9, 11, 13])\n assert answers_match(candidate(mountain=[10, 20, 15, 25, 20, 30, 25, 35, 30, 40]), [1, 3, 5, 7])\n assert answers_match(candidate(mountain=[5, 3, 1, 2, 4, 6, 5, 4, 3, 5, 7, 9, 7, 5, 6, 8, 6, 4, 3, 2]), [5, 11, 15])\n assert answers_match(candidate(mountain=[2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]), [2, 4, 6, 8])\n assert answers_match(candidate(mountain=[3, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]), [1, 3, 5, 7, 9, 11])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7]), [1, 3, 5, 7, 9, 11])\n assert answers_match(candidate(mountain=[8, 1, 9, 2, 10, 3, 11, 4, 12, 5]), [2, 4, 6, 8])\n assert answers_match(candidate(mountain=[6, 7, 5, 8, 6, 9, 7, 10, 8, 11, 9, 12, 10, 13, 11, 14, 12, 15, 13, 16, 14, 17, 15]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]), [3, 9])\n assert answers_match(candidate(mountain=[1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19])\n assert answers_match(candidate(mountain=[2, 4, 3, 5, 6, 4, 7, 8, 6, 9, 10, 7, 11, 12, 9, 13, 14, 11, 15, 16, 12, 17, 18, 13]), [1, 4, 7, 10, 13, 16, 19, 22])\n assert answers_match(candidate(mountain=[1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2]), [2, 6, 10])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 2, 1]), [4, 10])\n assert answers_match(candidate(mountain=[8, 9, 7, 10, 6, 11, 5, 12, 4, 13, 3]), [1, 3, 5, 7, 9])\n assert answers_match(candidate(mountain=[5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5]), [4, 8])\n assert answers_match(candidate(mountain=[2, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7, 6, 8, 7, 9, 8, 7, 6]), [1, 3, 5, 7, 9, 11, 13, 17, 19])\n assert answers_match(candidate(mountain=[2, 1, 4, 1, 6, 1, 8, 1, 10, 1, 12, 1, 14, 1, 16, 1, 18, 1]), [2, 4, 6, 8, 10, 12, 14, 16])\n assert answers_match(candidate(mountain=[1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]), [2, 7, 14])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 3, 2, 1, 4, 5, 6, 5, 4, 3, 2, 1]), [3, 9])\n assert answers_match(candidate(mountain=[1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]), [2, 6, 10])\n assert answers_match(candidate(mountain=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 45, 40, 35, 30, 25]), [9])\n assert answers_match(candidate(mountain=[2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]), [2, 4, 6, 8, 10, 12])\n assert answers_match(candidate(mountain=[9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9]), [17])\n assert answers_match(candidate(mountain=[2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]), [1, 3, 5, 7, 9, 11])\n assert answers_match(candidate(mountain=[10, 20, 15, 25, 30, 28, 35, 40, 38, 45, 43]), [1, 4, 7, 9])\n assert answers_match(candidate(mountain=[1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]), [2, 5, 8, 11, 14, 17, 20])\n assert answers_match(candidate(mountain=[9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9]), [2, 4, 6, 8, 10])\n assert answers_match(candidate(mountain=[10, 20, 15, 30, 25, 40, 35]), [1, 3, 5])\n assert answers_match(candidate(mountain=[9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5]), [8])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7]), [1, 3, 5, 7, 9, 11, 13])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [10])\n assert answers_match(candidate(mountain=[5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5]), [2, 4, 6, 8, 10, 12, 14, 16, 18])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3]), [6])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7]), [1, 3, 5, 7, 9, 11])\n assert answers_match(candidate(mountain=[10, 20, 15, 30, 25, 35, 40, 20, 50, 45]), [1, 3, 6, 8])\n assert answers_match(candidate(mountain=[5, 10, 5, 15, 10, 20, 15, 25, 20, 30, 25]), [1, 3, 5, 7, 9])\n assert answers_match(candidate(mountain=[9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 8, 9, 8, 7, 6, 5]), [8, 12])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [9])\n assert answers_match(candidate(mountain=[7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [10])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4]), [4, 6, 8, 10, 12, 14, 16, 18])\n assert answers_match(candidate(mountain=[1, 9, 8, 7, 6, 7, 8, 9, 8, 7, 6, 7, 8, 9, 8, 7, 6, 7, 8, 9]), [1, 7, 13])\n assert answers_match(candidate(mountain=[5, 3, 8, 6, 7, 2, 9, 4, 10, 1, 11]), [2, 4, 6, 8])\n assert answers_match(candidate(mountain=[2, 3, 4, 3, 5, 4, 6, 5, 7, 6, 8]), [2, 4, 6, 8])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]), [3, 9, 15, 21])\n assert answers_match(candidate(mountain=[1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19])\n assert answers_match(candidate(mountain=[5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]), [8])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]), [4, 11])\n assert answers_match(candidate(mountain=[1, 3, 2, 5, 4, 7, 6, 8, 7]), [1, 3, 5, 7])\n assert answers_match(candidate(mountain=[1, 3, 2, 5, 4, 7, 6]), [1, 3, 5])\n assert answers_match(candidate(mountain=[8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13]), [2, 4, 6, 8])\n assert answers_match(candidate(mountain=[5, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 10, 12, 11, 13, 14, 12, 15, 16, 14, 17, 18, 16]), [2, 5, 7, 12, 15, 18, 21, 24])\n assert answers_match(candidate(mountain=[8, 7, 6, 7, 8, 7, 6, 7, 8, 7, 6, 7, 8, 7, 6]), [4, 8, 12])\n assert answers_match(candidate(mountain=[9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]), [16])\n assert answers_match(candidate(mountain=[1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1]), [1, 3, 5, 7, 9, 11])\n assert answers_match(candidate(mountain=[1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]), [2, 6, 10])\n assert answers_match(candidate(mountain=[2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4]), [2, 6, 10, 14])\n assert answers_match(candidate(mountain=[5, 3, 4, 3, 5, 3, 5, 7, 5, 8, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11]), [2, 4, 7, 9, 11, 13, 15, 17, 19])\n assert answers_match(candidate(mountain=[10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [10])\n assert answers_match(candidate(mountain=[1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1]), [5])\n assert answers_match(candidate(mountain=[2, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21])\n assert answers_match(candidate(mountain=[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), [])\n assert answers_match(candidate(mountain=[1, 10, 5, 15, 10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35]), [1, 3, 5, 7, 9, 11, 13])\n assert answers_match(candidate(mountain=[1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]), [1, 4, 7, 10, 13, 16, 19])\n assert answers_match(candidate(mountain=[10, 20, 15, 25, 30, 20, 50, 45, 60, 55]), [1, 4, 6, 8])\n assert answers_match(candidate(mountain=[1, 3, 5, 7, 9, 11, 13, 11, 9, 7, 5, 3, 1]), [6])\n assert answers_match(candidate(mountain=[10, 20, 15, 25, 30, 20, 35, 40, 50, 45]), [1, 4, 8])\n assert answers_match(candidate(mountain=[2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]), [6])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]), [6])\n assert answers_match(candidate(mountain=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [19])\n assert answers_match(candidate(mountain=[1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [11])\n assert answers_match(candidate(mountain=[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]), [4, 12, 20])\n assert answers_match(candidate(mountain=[5, 10, 5, 15, 10, 20, 15, 25, 20, 30, 25]), [1, 3, 5, 7, 9])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10]), [1, 3, 5, 7, 9, 11, 13, 15, 17])\n assert answers_match(candidate(mountain=[5, 10, 5, 15, 10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35]), [1, 3, 5, 7, 9, 11, 13])\n assert answers_match(candidate(mountain=[3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]), [4, 8, 12])\n assert answers_match(candidate(mountain=[1, 3, 2, 4, 1, 5, 4, 6, 1]), [1, 3, 5, 7])\n assert answers_match(candidate(mountain=[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 1, 3, 5, 7, 9, 2, 6, 5, 3, 5, 9, 1, 3, 4, 6, 5, 4, 3, 2, 1, 2, 3]), [2, 5, 7, 11, 13, 17, 19, 21, 29, 31, 35, 39])\n assert answers_match(candidate(mountain=[2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20])\n", "comparison": "unordered"}, "public_tests": ["[2,4,4]", "[1,4,3,8,5]"], "hints": ["If nums[i] > num[i - 1] and nums[i] > nums[i + 1] nums[i] is a peak."], "metadata": {"canonical_parameter_names": ["mountain"], "leetcode_dataset_entry_point": "Solution().findPeaks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:17+00:00", "tests_total": 115, "tests_dropped": 2, "flags": ["any_order"], "topic_tags": ["array", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def find_peaks(mountain)", "container": null, "callable": "find_peaks", "parameters": [{"name": "mountain", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2952, "task_id": "minimum-number-of-coins-to-be-added", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.\n\nAn integer x is obtainable if there exists a subsequence of coins that sums to x.\n\nReturn the minimum number of coins of any value that need to be added to the array so that every integer in the range [1, target] is obtainable.\n\nA subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nExample 1:\n\nInput: coins = [1,4,10], target = 19\nOutput: 2\nExplanation: We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].\nIt can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.\n\nExample 2:\n\nInput: coins = [1,4,10,5,7,19], target = 19\nOutput: 1\nExplanation: We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].\nIt can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.\n\nExample 3:\n\nInput: coins = [1,1,1], target = 20\nOutput: 3\nExplanation: We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].\nIt can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.\n\nConstraints:\n\n- 1 <= target <= 10^5\n- 1 <= coins.length <= 10^5\n- 1 <= coins[i] <= target\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(coins = [3, 6, 9],target = 15) == 2\n assert candidate(coins = [2, 5, 10],target = 20) == 2\n assert candidate(coins = [1, 4, 10],target = 19) == 2\n assert candidate(coins = [1, 1, 1],target = 20) == 3\n assert candidate(coins = [1, 4, 10, 5, 7, 19],target = 19) == 1\n assert candidate(coins = [1, 2, 4, 8, 16],target = 31) == 0\n assert candidate(coins = [1, 3, 7, 15, 31, 63, 127],target = 256) == 2\n assert candidate(coins = [1, 2, 5, 10, 20],target = 99) == 3\n assert candidate(coins = [1, 5, 10, 25, 50, 100],target = 500) == 5\n assert candidate(coins = [1, 10, 25, 50, 100],target = 300) == 4\n assert candidate(coins = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31],target = 150) == 1\n assert candidate(coins = [1, 3, 6, 13, 26, 52],target = 100) == 1\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 100) == 1\n assert candidate(coins = [2, 3, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101],target = 100000) == 8\n assert candidate(coins = [1, 2, 3, 5, 10, 20, 50, 100],target = 1000) == 4\n assert candidate(coins = [10, 20, 30, 40, 50],target = 150) == 4\n assert candidate(coins = [1, 3, 6, 12, 24, 48],target = 100) == 2\n assert candidate(coins = [5, 11, 17, 23, 29, 35, 41, 47, 53],target = 200) == 3\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256],target = 512) == 1\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 1023) == 0\n assert candidate(coins = [1, 2, 5, 10, 20, 50],target = 99) == 2\n assert candidate(coins = [2, 6, 18, 54],target = 150) == 5\n assert candidate(coins = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],target = 400) == 4\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],target = 2048) == 1\n assert candidate(coins = [1, 1, 2, 2, 5, 5, 10, 10],target = 50) == 1\n assert candidate(coins = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23],target = 100) == 0\n assert candidate(coins = [1, 2, 5, 10, 20, 50, 100],target = 500) == 4\n assert candidate(coins = [2, 4, 6, 8, 10],target = 25) == 1\n assert candidate(coins = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000],target = 100000) == 5\n assert candidate(coins = [3, 7, 15, 23],target = 50) == 3\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 30) == 0\n assert candidate(coins = [1, 3, 6, 12],target = 50) == 3\n assert candidate(coins = [2, 6, 10, 14, 18, 22],target = 50) == 2\n assert candidate(coins = [2, 6, 10, 14, 18, 22],target = 100) == 3\n assert candidate(coins = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99],target = 100) == 2\n assert candidate(coins = [3, 6, 9, 12, 15, 18, 21, 24, 27],target = 100) == 2\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64],target = 128) == 1\n assert candidate(coins = [1, 2, 3, 6, 12, 24, 48],target = 100) == 1\n assert candidate(coins = [5, 12, 19, 26, 33, 40, 47, 54, 61, 68, 75],target = 200) == 3\n assert candidate(coins = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 250) == 3\n assert candidate(coins = [1, 3, 7, 11, 15],target = 30) == 1\n assert candidate(coins = [2, 3, 6, 9, 18],target = 50) == 2\n assert candidate(coins = [3, 6, 9, 12],target = 45) == 3\n assert candidate(coins = [1, 3, 5, 7, 9, 11],target = 50) == 2\n assert candidate(coins = [5, 9, 12, 18, 23, 34, 41, 50, 65, 78, 90, 100, 120, 150, 200],target = 500) == 3\n assert candidate(coins = [1, 3, 6, 12, 24, 48, 96, 192],target = 500) == 2\n assert candidate(coins = [1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16],target = 100) == 1\n assert candidate(coins = [1, 2, 3, 5, 11, 21, 41],target = 100) == 1\n assert candidate(coins = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000],target = 100000) == 5\n assert candidate(coins = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 100) == 4\n assert candidate(coins = [2, 6, 18, 54],target = 100) == 4\n assert candidate(coins = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],target = 200) == 3\n assert candidate(coins = [1, 5, 10, 25, 50],target = 120) == 3\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64],target = 127) == 0\n assert candidate(coins = [2, 3, 5, 7, 11, 13],target = 50) == 2\n assert candidate(coins = [1, 5, 10, 25],target = 100) == 4\n assert candidate(coins = [1, 1, 2, 2, 5, 5],target = 50) == 2\n assert candidate(coins = [5, 10, 20, 50],target = 100) == 4\n assert candidate(coins = [2, 3, 5, 7, 11],target = 30) == 2\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],target = 32767) == 0\n assert candidate(coins = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89],target = 200) == 0\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 50) == 0\n assert candidate(coins = [1, 5, 10, 25, 50],target = 99) == 3\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 1024) == 1\n assert candidate(coins = [5, 7, 11, 23],target = 100) == 4\n assert candidate(coins = [1, 3, 9, 30],target = 50) == 3\n assert candidate(coins = [1, 5, 10, 25, 50],target = 100) == 3\n assert candidate(coins = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],target = 2047) == 2\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128],target = 255) == 0\n assert candidate(coins = [7, 14, 21, 28, 35, 42, 49],target = 100) == 3\n assert candidate(coins = [5, 10, 20, 50, 100],target = 200) == 4\n assert candidate(coins = [1, 3, 4, 7, 10, 12, 15, 18],target = 100) == 2\n assert candidate(coins = [5, 10, 20, 50, 100, 200],target = 1000) == 6\n assert candidate(coins = [1, 5, 10, 20, 50, 100],target = 300) == 4\n assert candidate(coins = [1, 1, 2, 4, 8, 16, 32, 64, 128],target = 255) == 0\n assert candidate(coins = [10, 20, 30, 40, 50],target = 100) == 4\n assert candidate(coins = [1, 2, 5, 10, 20, 50],target = 100) == 2\n assert candidate(coins = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],target = 100) == 3\n assert candidate(coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 550) == 4\n assert candidate(coins = [1, 5, 10, 25, 50, 100],target = 300) == 4\n assert candidate(coins = [1, 5, 10, 25],target = 100) == 4\n assert candidate(coins = [2, 4, 8, 16, 32],target = 100) == 2\n assert candidate(coins = [2, 3, 6, 11],target = 30) == 2\n assert candidate(coins = [1, 2, 5, 10, 20, 50],target = 100) == 2\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 55) == 0\n assert candidate(coins = [1, 2, 4, 8, 16],target = 100) == 2\n assert candidate(coins = [1, 3, 5, 7, 9, 11, 13, 15],target = 100) == 2\n assert candidate(coins = [7, 14, 28, 56],target = 100) == 3\n assert candidate(coins = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],target = 60) == 2\n assert candidate(coins = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175, 182, 189, 196, 203, 210],target = 210) == 3\n assert candidate(coins = [1, 2, 3, 5, 8, 13, 21],target = 50) == 0\n assert candidate(coins = [1, 3, 7, 15, 31, 63],target = 128) == 2\n assert candidate(coins = [10, 20, 30, 40, 50],target = 200) == 5\n assert candidate(coins = [5, 10, 20, 40, 80],target = 200) == 4\n assert candidate(coins = [1, 2, 6, 14, 30],target = 63) == 2\n assert candidate(coins = [2, 6, 14, 30, 62, 126],target = 255) == 3\n assert candidate(coins = [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],target = 60) == 1\n assert candidate(coins = [3, 9, 27, 81],target = 243) == 6\n assert candidate(coins = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],target = 100) == 3\n assert candidate(coins = [1, 3, 6, 12, 24],target = 100) == 3\n assert candidate(coins = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],target = 200) == 2\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 50) == 0\n assert candidate(coins = [3, 7, 11, 25],target = 60) == 3\n assert candidate(coins = [1, 2, 5, 10, 25],target = 100) == 3\n assert candidate(coins = [5, 10, 25],target = 100) == 5\n assert candidate(coins = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300],target = 300) == 1\n", "comparison": "exact"}, "public_tests": ["[1,4,10]\n19", "[1,4,10,5,7,19]\n19", "[1,1,1]\n20"], "hints": ["Sort the coins array and maintain the smallest sum that is unobtainable by induction.", "If we don’t use any coins, the smallest integer that we cannot obtain by sum is 1. Suppose currently, for a fixed set of the first several coins the smallest integer that we cannot obtain is x + 1, namely we can form all integers in the range [1, x] but not x + 1.", "If the next unused coin’s value is NOT x + 1 (note the array is sorted), we have to add x + 1 to the array. After this addition, we can form all values from x + 1 to 2 * x + 1 by adding x + 1 in [1, x]'s formations. So now we can form all the numbers of [1, 2 * x + 1]. After this iteration the new value of x becomes 2 * x + 1."], "metadata": {"canonical_parameter_names": ["coins", "target"], "leetcode_dataset_entry_point": "Solution().minimumAddedCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:19+00:00", "tests_total": 110, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_added_coins(coins, target)", "container": null, "callable": "minimum_added_coins", "parameters": [{"name": "coins", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2953, "task_id": "count-complete-substrings", "difficulty": "Hard", "problem_description": "You are given a string word and an integer k.\n\nA substring s of word is complete if:\n\n- Each character in s occurs exactly k times.\n- The difference between two adjacent characters is at most 2. That is, for any two adjacent characters c1 and c2 in s, the absolute difference in their positions in the alphabet is at most 2.\n\nReturn the number of complete substrings of word.\n\nA substring is a non-empty contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: word = \"igigee\", k = 2\nOutput: 3\nExplanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.\n\nExample 2:\n\nInput: word = \"aaabbbccc\", k = 3\nOutput: 6\nExplanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.\n\nConstraints:\n\n- 1 <= word.length <= 10^5\n- word consists only of lowercase English letters.\n- 1 <= k <= word.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"xyzyxzyzxzyz\",k = 2) == 2\n assert candidate(word = \"mississippi\",k = 1) == 11\n assert candidate(word = \"zzzzzzzzz\",k = 9) == 1\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",k = 1) == 351\n assert candidate(word = \"ababababab\",k = 1) == 19\n assert candidate(word = \"ababab\",k = 2) == 3\n assert candidate(word = \"ababababab\",k = 2) == 7\n assert candidate(word = \"abcdabcdabcd\",k = 4) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 1) == 77\n assert candidate(word = \"qrstuvqrstuvqrstuv\",k = 3) == 0\n assert candidate(word = \"mnopqrspqr\",k = 2) == 0\n assert candidate(word = \"zzzzzzzzz\",k = 3) == 7\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\",k = 1) == 351\n assert candidate(word = \"aabbccddeeffgghhii\",k = 2) == 45\n assert candidate(word = \"abacabadabacaba\",k = 1) == 31\n assert candidate(word = \"zzzzzzzzz\",k = 2) == 8\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 5) == 46\n assert candidate(word = \"mnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrs\",k = 4) == 0\n assert candidate(word = \"abcdefg\",k = 1) == 28\n assert candidate(word = \"abcd\",k = 1) == 10\n assert candidate(word = \"abcabcabcabcabc\",k = 3) == 7\n assert candidate(word = \"aaabbbccc\",k = 3) == 6\n assert candidate(word = \"abcde\",k = 1) == 15\n assert candidate(word = \"abababababababababababababababababababababababababababababababababa\",k = 2) == 64\n assert candidate(word = \"xyzxyzxyz\",k = 3) == 1\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 1) == 114\n assert candidate(word = \"zzzzzzyyyxx\",k = 2) == 10\n assert candidate(word = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 31\n assert candidate(word = \"abcabcabcabc\",k = 4) == 1\n assert candidate(word = \"a\",k = 1) == 1\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 26) == 25\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 5) == 40\n assert candidate(word = \"abcabcabcabc\",k = 3) == 4\n assert candidate(word = \"igigee\",k = 2) == 3\n assert candidate(word = \"aaaaaa\",k = 6) == 1\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 3) == 58\n assert candidate(word = \"abcabcabc\",k = 3) == 1\n assert candidate(word = \"xxxxxxyyyyyzzzzz\",k = 5) == 7\n assert candidate(word = \"abcabcabcabcabcabcabc\",k = 3) == 13\n assert candidate(word = \"aabbaa\",k = 2) == 6\n assert candidate(word = \"qqqqqqqqqqqqqqqqqqqq\",k = 5) == 16\n assert candidate(word = \"aaaabbbbcccc\",k = 4) == 6\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 50\n assert candidate(word = \"acacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacaca\",k = 2) == 64\n assert candidate(word = \"ababababababababababababab\",k = 2) == 23\n assert candidate(word = \"zzzzzz\",k = 2) == 5\n assert candidate(word = \"zzzzzzzzzz\",k = 5) == 6\n assert candidate(word = \"zzzyyyxxxwwvvuuttrrqqqppponnmmllkkjjiihhggffeeddccbbbaaa\",k = 3) == 12\n assert candidate(word = \"aaaabbbbccccddddeeeeffff\",k = 4) == 21\n assert candidate(word = \"aaaabbbbccccdddd\",k = 4) == 10\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 3) == 55\n assert candidate(word = \"abacabadabacaba\",k = 3) == 0\n assert candidate(word = \"mississippi\",k = 2) == 3\n assert candidate(word = \"aaa\",k = 1) == 3\n assert candidate(word = \"aabbbcccaabb\",k = 2) == 12\n assert candidate(word = \"abcdefghi\",k = 1) == 45\n assert candidate(word = \"ababababababababababababababababababababab\",k = 2) == 39\n assert candidate(word = \"zzzyyyxxxwwwwvvvuuutttsssrrrqqqpppoonnmmmlllkkkjjjiii\",k = 3) == 61\n assert candidate(word = \"aabbcc\",k = 2) == 6\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzzz\",k = 1) == 354\n assert candidate(word = \"xyzyxzyzxzyx\",k = 2) == 3\n assert candidate(word = \"zzzzz\",k = 5) == 1\n assert candidate(word = \"abacaba\",k = 1) == 15\n assert candidate(word = \"aabbaabbaabbaabb\",k = 2) == 21\n assert candidate(word = \"abacabadabacaba\",k = 2) == 0\n assert candidate(word = \"abcdabcdeabcdabcde\",k = 2) == 0\n assert candidate(word = \"abcabcabc\",k = 1) == 24\n assert candidate(word = \"zzzzz\",k = 1) == 5\n assert candidate(word = \"mnopqr\",k = 1) == 21\n assert candidate(word = \"xyxxyxyxyx\",k = 2) == 6\n assert candidate(word = \"mnopqrsmnopqrsmnopqrsmnopqrs\",k = 5) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 5) == 47\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\",k = 1) == 51\n assert candidate(word = \"abcdefghij\",k = 1) == 55\n assert candidate(word = \"zzzaaa\",k = 3) == 2\n assert candidate(word = \"qqwweerrtt\",k = 2) == 6\n assert candidate(word = \"abcdefghijk\",k = 1) == 66\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 2) == 351\n assert candidate(word = \"abcdabcdabcd\",k = 2) == 0\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabc\",k = 3) == 22\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzaaa\",k = 1) == 354\n assert candidate(word = \"aaaabbbbccccaaaabbbbcccc\",k = 4) == 24\n assert candidate(word = \"zzzzzz\",k = 1) == 6\n assert candidate(word = \"abcabcabcabcabcabc\",k = 3) == 10\n assert candidate(word = \"abababababababababab\",k = 2) == 17\n assert candidate(word = \"abcdef\",k = 1) == 21\n assert candidate(word = \"aabbccddeeaabbccddeeaabbccddeeddeeaabbcc\",k = 2) == 57\n assert candidate(word = \"abcdabc\",k = 2) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 43\n assert candidate(word = \"zzzyyyxxx\",k = 3) == 6\n assert candidate(word = \"xyzzzzzyxxyzzzzzyx\",k = 3) == 6\n", "comparison": "exact"}, "public_tests": ["\"igigee\"\n2", "\"aaabbbccc\"\n3"], "hints": ["There are at most 26 different lengths of the complete substrings: k *1, k * 2, … k * 26.****", "For each length, we can use sliding window to count the frequency of each letter in the window.", "We still need to check for all characters in the window that abs(word[i] - word[i - 1]) <= 2. We do this by maintaining the values of abs(word[i] - word[i - 1]) in the sliding window dynamically in an ordered multiset or priority queue, so that we know the maximum value at each iteration."], "metadata": {"canonical_parameter_names": ["word", "k"], "leetcode_dataset_entry_point": "Solution().countCompleteSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:22+00:00", "tests_total": 91, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def count_complete_substrings(word, k)", "container": null, "callable": "count_complete_substrings", "parameters": [{"name": "word", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2956, "task_id": "find-common-elements-between-two-arrays", "difficulty": "Easy", "problem_description": "You are given two integer arrays nums1 and nums2 of sizes n and m, respectively. Calculate the following values:\n\n- answer1 : the number of indices i such that nums1[i] exists in nums2.\n- answer2 : the number of indices i such that nums2[i] exists in nums1.\n\nReturn [answer1,answer2].\n\nExample 1:\n\nInput: nums1 = [2,3,2], nums2 = [1,2]\nOutput: [2,1]\nExplanation:\n\nExample 2:\n\nInput: nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]\nOutput: [3,4]\nExplanation:\nThe elements at indices 1, 2, and 3 in nums1 exist in nums2 as well. So answer1 is 3.\nThe elements at indices 0, 1, 3, and 4 in nums2 exist in nums1. So answer2 is 4.\n\nExample 3:\n\nInput: nums1 = [3,4,2,3], nums2 = [1,5]\nOutput: [0,0]\nExplanation:\nNo numbers are common between nums1 and nums2, so answer is [0,0].\n\nConstraints:\n\n- n == nums1.length\n- m == nums2.length\n- 1 <= n, m <= 100\n- 1 <= nums1[i], nums2[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25, 35]) == [0, 0]\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 20, 10]) == [3, 3]\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == [4, 4]\n assert candidate(nums1 = [2, 3, 2],nums2 = [1, 2]) == [2, 1]\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25, 35, 45]) == [0, 0]\n assert candidate(nums1 = [100, 99, 98],nums2 = [97, 96, 95]) == [0, 0]\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == [0, 0]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == [5, 5]\n assert candidate(nums1 = [50, 60, 70],nums2 = [50, 60, 70, 80, 90]) == [3, 3]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == [0, 0]\n assert candidate(nums1 = [50, 51, 52],nums2 = [49, 50, 51]) == [2, 2]\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 4, 5]) == [1, 1]\n assert candidate(nums1 = [1],nums2 = [2]) == [0, 0]\n assert candidate(nums1 = [50, 50, 50],nums2 = [50, 50]) == [3, 2]\n assert candidate(nums1 = [4, 3, 2, 3, 1],nums2 = [2, 2, 5, 2, 3, 6]) == [3, 4]\n assert candidate(nums1 = [3, 4, 2, 3],nums2 = [1, 5]) == [0, 0]\n assert candidate(nums1 = [100, 100, 100],nums2 = [100]) == [3, 1]\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == [0, 0]\n assert candidate(nums1 = [10],nums2 = [10]) == [1, 1]\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1]) == [4, 3]\n assert candidate(nums1 = [1],nums2 = [1]) == [1, 1]\n assert candidate(nums1 = [1, 2, 3],nums2 = [1, 2, 3, 4, 5]) == [3, 3]\n assert candidate(nums1 = [100],nums2 = [100]) == [1, 1]\n assert candidate(nums1 = [50],nums2 = [50]) == [1, 1]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == [5, 5]\n assert candidate(nums1 = [99, 98, 97, 96, 95],nums2 = [50, 40, 30, 20, 10]) == [0, 0]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [10, 15, 20, 25, 30]) == [3, 3]\n assert candidate(nums1 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [3, 3]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [5, 10]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [6, 6]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [10, 10]\n assert candidate(nums1 = [99, 98, 97, 96, 95],nums2 = [95, 96, 97, 98, 99]) == [5, 5]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60],nums2 = [5, 15, 25, 35, 45, 55, 65]) == [0, 0]\n assert candidate(nums1 = [23, 45, 67, 89, 12, 34, 56],nums2 = [12, 23, 34, 45, 56, 67, 78, 89, 90]) == [7, 7]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 10]\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6, 1, 2, 3, 4, 5, 6]) == [3, 3]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [10, 10]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5]) == [5, 5]\n assert candidate(nums1 = [100, 99, 98, 97, 96],nums2 = [95, 96, 97, 98, 99]) == [4, 4]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 3, 5, 7, 9]) == [5, 5]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [0, 0]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [3, 3, 3, 3, 2, 2, 1, 1]) == [6, 8]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [10, 10]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5]) == [5, 5]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [5, 5]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0]\n assert candidate(nums1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [0, 0]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == [10, 15]\n assert candidate(nums1 = [50],nums2 = [50, 50, 50, 50, 50, 50]) == [1, 6]\n assert candidate(nums1 = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0]\n assert candidate(nums1 = [7, 14, 21, 28, 35, 42, 49],nums2 = [7, 21, 35, 49, 56, 63, 70]) == [4, 4]\n assert candidate(nums1 = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],nums2 = [91, 92, 93, 94, 95]) == [5, 5]\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30],nums2 = [15, 25, 35, 45, 55]) == [2, 2]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == [0, 0]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5]) == [0, 0]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [5, 5]\n assert candidate(nums1 = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5]) == [7, 5]\n assert candidate(nums1 = [99, 98, 97, 96, 95],nums2 = [95, 94, 93, 92, 91]) == [1, 1]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [40, 50, 60, 70, 80]) == [2, 2]\n assert candidate(nums1 = [99, 98, 97, 96, 95],nums2 = [94, 93, 92, 91, 90]) == [0, 0]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 5]\n assert candidate(nums1 = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],nums2 = [1, 2, 3, 4, 5, 90, 91, 92, 93, 94]) == [5, 5]\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == [10, 10]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == [5, 5]\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55],nums2 = [10, 20, 30, 40, 50]) == [0, 0]\n assert candidate(nums1 = [7, 8, 9, 10, 11, 12],nums2 = [5, 6, 7, 8, 9, 10]) == [4, 4]\n assert candidate(nums1 = [42],nums2 = [42, 42, 42, 42, 42]) == [1, 5]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [0, 0]\n assert candidate(nums1 = [42],nums2 = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == [1, 10]\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5, 5]) == [7, 7]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [3, 3, 2, 2, 1, 1]) == [6, 6]\n assert candidate(nums1 = [9, 18, 27, 36, 45],nums2 = [8, 17, 26, 35, 44, 53]) == [0, 0]\n assert candidate(nums1 = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0]\n assert candidate(nums1 = [7, 8, 9, 10],nums2 = [5, 6, 7, 8, 9]) == [3, 3]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [10, 10]\n assert candidate(nums1 = [2, 4, 6, 8, 10, 2, 4, 6, 8, 10],nums2 = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9]) == [0, 0]\n assert candidate(nums1 = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 100]) == [10, 10]\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [5, 5]\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1]\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == [0, 0]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5, 5, 5]) == [5, 8]\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [25, 20, 15, 10, 5]) == [5, 5]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == [5, 10]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 6, 7, 8, 9, 10]) == [1, 1]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [5, 5]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [10, 10]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [10, 10]\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [10, 20, 30, 40, 50]) == [2, 2]\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == [5, 5]\n assert candidate(nums1 = [100, 1, 50, 75],nums2 = [50, 75, 100, 1, 50, 75, 100, 1]) == [4, 8]\n assert candidate(nums1 = [100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 100]) == [1, 1]\n assert candidate(nums1 = [1, 10, 20, 30, 40],nums2 = [1, 10, 20, 30, 40]) == [5, 5]\n assert candidate(nums1 = [1, 2, 2, 3, 4],nums2 = [2, 3, 3, 4, 5]) == [4, 4]\n assert candidate(nums1 = [23, 45, 67, 89, 23],nums2 = [23, 45, 99, 23, 67, 100]) == [4, 4]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50]) == [5, 5]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [15, 25, 35, 45, 55]) == [0, 0]\n assert candidate(nums1 = [100, 99, 98, 97, 96],nums2 = [95, 94, 93, 92, 91]) == [0, 0]\n assert candidate(nums1 = [50, 50, 50, 50, 50],nums2 = [50, 50, 50, 50, 50]) == [5, 5]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10]) == [5, 5]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [11, 22, 33, 44, 55]) == [0, 0]\n assert candidate(nums1 = [100, 99, 98, 97, 96, 95],nums2 = [96, 97, 98, 99, 100]) == [5, 5]\n", "comparison": "exact"}, "public_tests": ["[2,3,2]\n[1,2]", "[4,3,2,3,1]\n[2,2,5,2,3,6]", "[3,4,2,3]\n[1,5]"], "hints": ["Since the constraints are small, you can use brute force to solve the problem.", "For each element i in nums1, iterate over all elements of nums2 to find if it occurs."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().findIntersectionValues", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:27+00:00", "tests_total": 102, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def find_intersection_values(nums1, nums2)", "container": null, "callable": "find_intersection_values", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2957, "task_id": "remove-adjacent-almost-equal-characters", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string word.\n\nIn one operation, you can pick any index i of word and change word[i] to any lowercase English letter.\n\nReturn the minimum number of operations needed to remove all adjacent almost-equal characters from word.\n\nTwo characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.\n\nExample 1:\n\nInput: word = \"aaaaa\"\nOutput: 2\nExplanation: We can change word into \"acaca\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\n\nExample 2:\n\nInput: word = \"abddez\"\nOutput: 2\nExplanation: We can change word into \"ybdoez\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\n\nExample 3:\n\nInput: word = \"zyxyxyz\"\nOutput: 3\nExplanation: We can change word into \"zaxaxaz\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.\n\nConstraints:\n\n- 1 <= word.length <= 100\n- word consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"abddez\") == 2\n assert candidate(word = \"qrstuvwpqrstuvwxyz\") == 8\n assert candidate(word = \"abecidof\") == 1\n assert candidate(word = \"zzz\") == 1\n assert candidate(word = \"abacaba\") == 2\n assert candidate(word = \"abababab\") == 4\n assert candidate(word = \"acacacac\") == 0\n assert candidate(word = \"xyz\") == 1\n assert candidate(word = \"abcde\") == 2\n assert candidate(word = \"aabbcc\") == 3\n assert candidate(word = \"zzzzz\") == 2\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 26\n assert candidate(word = \"abcdefg\") == 3\n assert candidate(word = \"a\") == 0\n assert candidate(word = \"mnonmo\") == 2\n assert candidate(word = \"abc\") == 1\n assert candidate(word = \"acxz\") == 0\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\") == 13\n assert candidate(word = \"aaaaa\") == 2\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 13\n assert candidate(word = \"qwert\") == 0\n assert candidate(word = \"zyxyxyz\") == 3\n assert candidate(word = \"aabbaabbaabbaabbaabbaabb\") == 12\n assert candidate(word = \"aaabbbccc\") == 4\n assert candidate(word = \"aaaaabbbbbaaaa\") == 7\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 39\n assert candidate(word = \"zzzyyxxwwvvuuttrrssqqppoonnllkkjjiihhggffeeddccbbaa\") == 25\n assert candidate(word = \"abbbccddeeefffggghhhhiiiiijjjjkkkkllllmmmmmnnnnnooooo\") == 26\n assert candidate(word = \"mississippi\") == 3\n assert candidate(word = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmnnnooopppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 50\n assert candidate(word = \"aazzbbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 27\n assert candidate(word = \"zzzzyyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbbaaaa\") == 30\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(word = \"aaaabbbbcccc\") == 6\n assert candidate(word = \"qwerttyuiiooppllkkiijjhhggffeedcvvbbnnaassddffgghhjjiikkllppoouuyyttrewqq\") == 32\n assert candidate(word = \"aaaabbbbccccaaaabbbbcccc\") == 12\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 39\n assert candidate(word = \"aabbaaabbbaaa\") == 6\n assert candidate(word = \"banana\") == 1\n assert candidate(word = \"abcabcabcabcabcabc\") == 6\n assert candidate(word = \"abcdeedcba\") == 5\n assert candidate(word = \"zyxzyxzyx\") == 3\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 50\n assert candidate(word = \"ababababababababababc\") == 10\n assert candidate(word = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\") == 18\n assert candidate(word = \"aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxxyyyzzz\") == 40\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(word = \"aabbccddeeaabbccddee\") == 10\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 27\n assert candidate(word = \"ababababababababababababababababababababab\") == 21\n assert candidate(word = \"zyxzyxzyxzyxzyxzyxzyxzyx\") == 8\n assert candidate(word = \"mnopqrspqrstmnopqrspqrstmnopqrspqrst\") == 15\n assert candidate(word = \"aaaaabbbbbaaaaabbbbbaaaa\") == 12\n assert candidate(word = \"aaaabbbbccccdddd\") == 8\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 26\n assert candidate(word = \"abzycxyxbwaxavauatassarapaoanamaalakajaiagafae\") == 5\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyxwvutsrqponmlkjihgfedcba\") == 39\n assert candidate(word = \"ababababab\") == 5\n assert candidate(word = \"abzabzabzabzabz\") == 5\n assert candidate(word = \"aabbaabbccddeeffaabbccddeeff\") == 14\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzz\") == 10\n assert candidate(word = \"abacabcabacabcabacabcabacabcabacabcabacabc\") == 12\n assert candidate(word = \"abacabadabacabadaba\") == 5\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcbaaaaaaaaaaaaa\") == 19\n assert candidate(word = \"aaaaabbbbbccccc\") == 7\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcb\") == 25\n assert candidate(word = \"zzzyyyxxxwwwwvvvuuuuttttssssrrrrqqqqppppllllooooiiiihhhhhgggggffffffeeeeeeeedddddccccbbbbaaa\") == 46\n assert candidate(word = \"abcabcabc\") == 3\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 25\n assert candidate(word = \"acxzacxzacxzacxzacxzacxz\") == 0\n assert candidate(word = \"zzzyyxxwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbbaaa\") == 27\n assert candidate(word = \"zazazazazazazazazaza\") == 0\n assert candidate(word = \"ababababababababababababababababababababababababababababababab\") == 31\n assert candidate(word = \"bookkeeper\") == 3\n assert candidate(word = \"abababababababababababababababababab\") == 18\n assert candidate(word = \"abababababababababababababab\") == 14\n assert candidate(word = \"zazazazazazazazazaabc\") == 2\n assert candidate(word = \"abczyxabczyxabczyx\") == 6\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 41\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 21\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaa\") == 27\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(word = \"abzabzabz\") == 3\n assert candidate(word = \"abacabadabacabadabacabad\") == 6\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 22\n assert candidate(word = \"abcdabcdabcdabcdabcdabcd\") == 12\n assert candidate(word = \"abcabcabcabc\") == 4\n assert candidate(word = \"abacabadabacabadabacabadabacabad\") == 8\n assert candidate(word = \"abacabadabacaba\") == 4\n assert candidate(word = \"abababababababababab\") == 10\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 26\n", "comparison": "exact"}, "public_tests": ["\"aaaaa\"", "\"abddez\"", "\"zyxyxyz\""], "hints": ["For i > 0, if word[i] and word[i - 1] are adjacent, we will change word[i] to another character. Which character should we change it to?", "We will change word[i] to some character that is not adjacent to word[i - 1] nor word[i + 1] (if it exists). Such a character always exists. However, since the problem does not ask for the final state of the string, It is enough to prove that the character exists and we do not need to find it."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().removeAlmostEqualCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:29+00:00", "tests_total": 95, "tests_dropped": 4, "flags": [], "topic_tags": ["string", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def remove_almost_equal_characters(word)", "container": null, "callable": "remove_almost_equal_characters", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2958, "task_id": "length-of-longest-subarray-with-at-most-k-frequency", "difficulty": "Medium", "problem_description": "You are given an integer array nums and an integer k.\n\nThe frequency of an element x is the number of times it occurs in an array.\n\nAn array is called good if the frequency of each element in this array is less than or equal to k.\n\nReturn the length of the longest good subarray of nums.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,1,2,3,1,2], k = 2\nOutput: 6\nExplanation: The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good.\nIt can be shown that there are no good subarrays with length more than 6.\n\nExample 2:\n\nInput: nums = [1,2,1,2,1,2,1,2], k = 1\nOutput: 2\nExplanation: The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good.\nIt can be shown that there are no good subarrays with length more than 2.\n\nExample 3:\n\nInput: nums = [5,5,5,5,5,5,5], k = 4\nOutput: 4\nExplanation: The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray.\nIt can be shown that there are no good subarrays with length more than 4.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 2) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 3) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 4) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 2) == 2\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2],k = 1) == 2\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1],k = 2) == 5\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 2) == 6\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 3) == 19\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],k = 3) == 30\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 = 1) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 2) == 6\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) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5],k = 1) == 15\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],k = 4) == 4\n assert candidate(nums = [1, 1, 1, 2, 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, 6, 6, 6, 6],k = 3) == 6\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 2, 3, 4, 5, 6],k = 4) == 9\n assert candidate(nums = [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],k = 1) == 9\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],k = 4) == 4\n assert candidate(nums = [100, 200, 100, 300, 200, 100, 400, 300, 200, 100],k = 2) == 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],k = 3) == 9\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 = 1) == 10\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 = 1) == 1\n assert candidate(nums = [1, 1, 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, 7],k = 2) == 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],k = 2) == 20\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 7, 8, 9, 7, 8, 9, 7, 8, 9, 10, 10, 10, 10, 10],k = 2) == 12\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 = 1) == 10\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 5) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 18\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],k = 3) == 6\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3],k = 2) == 4\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 3) == 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],k = 1) == 20\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],k = 2) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 10\n assert candidate(nums = [100, 200, 100, 300, 100, 200, 400, 200, 100, 200, 100, 300, 100, 400, 100],k = 3) == 9\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 8, 9, 8, 9, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 2) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 4) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 2) == 10\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 10\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],k = 5) == 5\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9],k = 3) == 9\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],k = 1) == 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, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 1) == 5\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1) == 20\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5],k = 2) == 8\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) == 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, 1, 2, 3],k = 2) == 6\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],k = 20) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == 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],k = 1) == 2\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 999999999, 999999999, 999999999, 888888888, 888888888, 888888888, 777777777, 777777777, 777777777],k = 3) == 12\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 18\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],k = 5) == 5\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],k = 2) == 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],k = 2) == 20\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 30\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 3) == 15\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3],k = 3) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 3) == 15\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500],k = 4) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6],k = 4) == 20\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 40\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 = 10) == 30\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 3) == 9\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],k = 2) == 6\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 5) == 5\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],k = 5) == 30\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],k = 2) == 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, 6],k = 2) == 5\n assert candidate(nums = [9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5],k = 3) == 6\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 16\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2],k = 2) == 4\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 3) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3],k = 1) == 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, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],k = 3) == 30\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300],k = 3) == 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, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 2) == 20\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 = 10) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10],k = 4) == 24\n assert candidate(nums = [7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 5) == 10\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],k = 2) == 2\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],k = 5) == 5\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 40\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],k = 3) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 20\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 40\n assert candidate(nums = [5, 7, 7, 7, 7, 3, 3, 5, 5, 5, 7, 7, 5, 5, 7, 7, 5, 5, 5, 5],k = 3) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 18\n assert candidate(nums = [7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10],k = 3) == 8\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],k = 2) == 4\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],k = 5) == 25\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],k = 3) == 30\n", "comparison": "exact"}, "public_tests": ["[1,2,3,1,2,3,1,2]\n2", "[1,2,1,2,1,2,1,2]\n1", "[5,5,5,5,5,5,5]\n4"], "hints": ["For each index i, find the rightmost index j >= i such that the frequency of each element in the subarray [i, j] is at most k.", "We can use 2 pointers / sliding window to achieve it."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxSubarrayLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:31+00:00", "tests_total": 107, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def max_subarray_length(nums, k)", "container": null, "callable": "max_subarray_length", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2959, "task_id": "number-of-possible-sets-of-closing-branches", "difficulty": "Hard", "problem_description": "There is a company with n branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.\n\nThe company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most maxDistance from each other.\n\nThe distance between two branches is the minimum total traveled length needed to reach one branch from another.\n\nYou are given integers n, maxDistance, and a 0-indexed 2D array roads, where roads[i] = [u_i, v_i, w_i] represents the undirected road between branches u_i and v_i with length w_i.\n\nReturn the number of possible sets of closing branches, so that any branch has a distance of at most maxDistance from any other.\n\nNote that, after closing a branch, the company will no longer have access to any roads connected to it.\n\nNote that, multiple roads are allowed.\n\nExample 1:\n\nInput: n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]\nOutput: 5\nExplanation: The possible sets of closing branches are:\n- The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.\n- The set [0,1], after closing, the active branch is [2].\n- The set [1,2], after closing, the active branch is [0].\n- The set [0,2], after closing, the active branch is [1].\n- The set [0,1,2], after closing, there are no active branches.\nIt can be proven, that there are only 5 possible sets of closing branches.\n\nExample 2:\n\nInput: n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]\nOutput: 7\nExplanation: The possible sets of closing branches are:\n- The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.\n- The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.\n- The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.\n- The set [0,1], after closing, the active branch is [2].\n- The set [1,2], after closing, the active branch is [0].\n- The set [0,2], after closing, the active branch is [1].\n- The set [0,1,2], after closing, there are no active branches.\nIt can be proven, that there are only 7 possible sets of closing branches.\n\nExample 3:\n\nInput: n = 1, maxDistance = 10, roads = []\nOutput: 2\nExplanation: The possible sets of closing branches are:\n- The set [], after closing, the active branch is [0].\n- The set [0], after closing, there are no active branches.\nIt can be proven, that there are only 2 possible sets of closing branches.\n\nConstraints:\n\n- 1 <= n <= 10\n- 1 <= maxDistance <= 10^5\n- 0 <= roads.length <= 1000\n- roads[i].length == 3\n- 0 <= u_i, v_i <= n - 1\n- u_i != v_i\n- 1 <= w_i <= 1000\n- All branches are reachable from each other by traveling some roads.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,maxDistance = 5,roads = [[0, 1, 2], [1, 2, 10], [0, 2, 10]]) == 5\n assert candidate(n = 5,maxDistance = 10,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 0, 5]]) == 20\n assert candidate(n = 1,maxDistance = 10,roads = []) == 2\n assert candidate(n = 2,maxDistance = 1,roads = [[0, 1, 1]]) == 4\n assert candidate(n = 4,maxDistance = 6,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1]]) == 14\n assert candidate(n = 6,maxDistance = 15,roads = [[0, 1, 3], [1, 2, 3], [2, 3, 3], [3, 4, 3], [4, 5, 3], [5, 0, 3]]) == 32\n assert candidate(n = 3,maxDistance = 5,roads = [[0, 1, 20], [0, 1, 10], [1, 2, 2], [0, 2, 2]]) == 7\n assert candidate(n = 5,maxDistance = 6,roads = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [3, 4, 4]]) == 11\n assert candidate(n = 4,maxDistance = 4,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4]]) == 10\n assert candidate(n = 4,maxDistance = 15,roads = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [0, 3, 15]]) == 12\n assert candidate(n = 4,maxDistance = 3,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 0, 2]]) == 9\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 0, 1], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 0, 1], [4, 1, 1]]) == 32\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 0, 5], [0, 2, 6], [1, 3, 7], [2, 4, 8]]) == 13\n assert candidate(n = 9,maxDistance = 15,roads = [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 4, 2], [1, 5, 3], [2, 4, 4], [2, 6, 5], [3, 5, 1], [3, 7, 2], [4, 6, 3], [4, 8, 4], [5, 7, 6], [6, 8, 7], [7, 8, 1]]) == 198\n assert candidate(n = 8,maxDistance = 10,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 0, 1]]) == 58\n assert candidate(n = 5,maxDistance = 10,roads = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [0, 4, 4], [1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 1, 3]]) == 30\n assert candidate(n = 6,maxDistance = 12,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [0, 3, 6], [1, 4, 7], [2, 5, 8], [3, 0, 9], [4, 1, 10], [5, 2, 11]]) == 43\n assert candidate(n = 5,maxDistance = 8,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 0, 6], [0, 2, 1], [1, 3, 1], [2, 4, 1]]) == 29\n assert candidate(n = 7,maxDistance = 12,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 0, 7], [0, 3, 3], [1, 4, 4], [2, 5, 5], [3, 6, 6], [4, 0, 1], [5, 1, 2], [6, 2, 3]]) == 109\n assert candidate(n = 4,maxDistance = 4,roads = [[0, 1, 1], [0, 2, 3], [1, 2, 2], [1, 3, 2], [2, 3, 3]]) == 14\n assert candidate(n = 10,maxDistance = 30,roads = [[0, 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, 0, 10], [0, 3, 2], [1, 4, 2], [2, 5, 2], [3, 6, 2], [4, 7, 2], [5, 8, 2], [6, 9, 2], [7, 0, 2], [8, 1, 2], [9, 2, 2]]) == 807\n assert candidate(n = 9,maxDistance = 25,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 0, 9], [0, 5, 10], [1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 0, 14], [5, 1, 15], [6, 2, 16], [7, 3, 17], [8, 4, 18]]) == 252\n assert candidate(n = 8,maxDistance = 20,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8], [0, 4, 9], [1, 5, 10], [2, 6, 11], [3, 7, 12], [4, 0, 13], [5, 1, 14], [6, 2, 15], [7, 3, 16]]) == 137\n assert candidate(n = 7,maxDistance = 12,roads = [[0, 1, 3], [1, 2, 2], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 2], [6, 0, 1], [0, 3, 2], [2, 4, 3], [1, 5, 2]]) == 87\n assert candidate(n = 6,maxDistance = 10,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 0, 6], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 5, 1], [4, 0, 1], [5, 1, 1]]) == 61\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 5], [1, 2, 3], [2, 3, 2], [3, 4, 4], [4, 0, 3], [1, 4, 1], [2, 4, 2], [0, 3, 2]]) == 28\n assert candidate(n = 5,maxDistance = 10,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 0, 6]]) == 17\n assert candidate(n = 5,maxDistance = 7,roads = [[0, 1, 3], [1, 2, 2], [2, 3, 4], [3, 4, 5], [4, 0, 6], [1, 3, 1]]) == 18\n assert candidate(n = 6,maxDistance = 10,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 0, 7], [0, 3, 1], [1, 4, 2], [2, 5, 3]]) == 52\n assert candidate(n = 6,maxDistance = 10,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 0, 1]]) == 23\n assert candidate(n = 4,maxDistance = 2,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4]]) == 7\n assert candidate(n = 6,maxDistance = 8,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 2], [3, 4, 3], [4, 5, 2], [5, 0, 1], [0, 3, 4], [2, 4, 1], [1, 3, 2]]) == 50\n assert candidate(n = 6,maxDistance = 7,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 2], [3, 4, 3], [4, 5, 2], [5, 0, 3]]) == 23\n assert candidate(n = 8,maxDistance = 8,roads = [[0, 1, 2], [0, 3, 5], [0, 4, 8], [1, 2, 3], [1, 5, 6], [2, 6, 4], [3, 4, 2], [3, 5, 1], [4, 6, 7], [5, 7, 2], [6, 7, 3]]) == 41\n assert candidate(n = 4,maxDistance = 4,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1], [0, 2, 1], [1, 3, 1], [0, 3, 1], [2, 1, 1]]) == 16\n assert candidate(n = 5,maxDistance = 7,roads = [[0, 1, 10], [0, 2, 15], [0, 3, 20], [0, 4, 25], [1, 2, 5], [1, 3, 10], [1, 4, 15], [2, 3, 5], [2, 4, 10], [3, 4, 5]]) == 9\n assert candidate(n = 6,maxDistance = 10,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 4], [4, 5, 2], [5, 0, 5], [0, 3, 3], [1, 4, 2], [2, 5, 4]]) == 56\n assert candidate(n = 5,maxDistance = 10,roads = [[0, 1, 5], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 0, 1], [0, 2, 1], [1, 3, 2], [2, 4, 3]]) == 30\n assert candidate(n = 7,maxDistance = 8,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 0, 7]]) == 20\n assert candidate(n = 5,maxDistance = 15,roads = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 0, 50]]) == 7\n assert candidate(n = 7,maxDistance = 15,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 0, 7], [0, 3, 8], [1, 4, 9], [2, 5, 10], [3, 6, 11], [4, 0, 12], [5, 1, 13], [6, 2, 14]]) == 85\n assert candidate(n = 10,maxDistance = 30,roads = [[0, 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, 0, 10], [0, 6, 11], [1, 7, 12], [2, 8, 13], [3, 9, 14], [4, 0, 15], [5, 1, 16], [6, 2, 17], [7, 3, 18], [8, 4, 19], [9, 5, 20]]) == 573\n assert candidate(n = 9,maxDistance = 15,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 0, 9], [0, 2, 1], [1, 3, 2], [2, 4, 3], [3, 5, 4], [4, 6, 5], [5, 7, 6], [6, 8, 7], [7, 1, 8], [8, 2, 9]]) == 245\n assert candidate(n = 5,maxDistance = 10,roads = [[0, 1, 3], [1, 2, 1], [2, 3, 4], [3, 4, 2], [4, 0, 5]]) == 21\n assert candidate(n = 6,maxDistance = 7,roads = [[0, 1, 2], [0, 2, 3], [1, 3, 1], [2, 4, 2], [3, 4, 2], [3, 5, 1], [4, 5, 3]]) == 35\n assert candidate(n = 5,maxDistance = 3,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 0, 2], [0, 3, 1], [1, 4, 1], [2, 0, 1], [3, 1, 1], [4, 2, 1]]) == 32\n assert candidate(n = 5,maxDistance = 20,roads = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 0, 25], [0, 3, 1], [1, 4, 6]]) == 21\n assert candidate(n = 6,maxDistance = 15,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 0, 6], [0, 3, 1], [1, 4, 1], [2, 5, 1]]) == 56\n assert candidate(n = 4,maxDistance = 4,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 0, 5], [0, 2, 1], [1, 3, 1], [2, 0, 1], [3, 1, 1]]) == 14\n assert candidate(n = 5,maxDistance = 6,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 0, 1], [0, 2, 2], [1, 3, 2], [2, 4, 2], [3, 0, 2], [4, 1, 2]]) == 32\n assert candidate(n = 4,maxDistance = 5,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4], [0, 2, 2], [1, 3, 3], [2, 0, 3], [3, 1, 4]]) == 16\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 0, 5]]) == 11\n assert candidate(n = 8,maxDistance = 15,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 0, 9]]) == 29\n assert candidate(n = 10,maxDistance = 20,roads = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [1, 5, 6], [1, 6, 7], [2, 6, 8], [2, 7, 9], [3, 7, 10], [3, 8, 11], [4, 8, 12], [4, 9, 13], [5, 9, 14], [6, 9, 15], [7, 9, 16], [8, 9, 17]]) == 120\n assert candidate(n = 5,maxDistance = 10,roads = [[0, 1, 3], [0, 2, 5], [1, 3, 2], [2, 3, 4], [3, 4, 1]]) == 22\n assert candidate(n = 7,maxDistance = 20,roads = [[0, 1, 5], [1, 2, 6], [2, 3, 7], [3, 4, 8], [4, 5, 9], [5, 6, 10], [6, 0, 11], [0, 4, 3], [1, 5, 4], [2, 6, 5]]) == 75\n assert candidate(n = 6,maxDistance = 8,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 0, 1], [0, 3, 1], [1, 4, 1], [2, 5, 1], [3, 0, 1], [4, 1, 1], [5, 2, 1]]) == 56\n assert candidate(n = 6,maxDistance = 4,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 5, 2], [5, 0, 2], [0, 3, 1], [1, 4, 1], [2, 5, 1], [3, 0, 1], [4, 1, 1], [5, 2, 1]]) == 56\n assert candidate(n = 8,maxDistance = 25,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 5, 1], [4, 6, 1], [5, 7, 1], [6, 0, 1], [7, 1, 1]]) == 208\n assert candidate(n = 6,maxDistance = 5,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 0, 6], [0, 3, 2], [1, 4, 2], [2, 5, 2], [3, 0, 2], [4, 1, 2], [5, 2, 2]]) == 35\n assert candidate(n = 5,maxDistance = 3,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 0, 1], [0, 2, 2], [1, 3, 2], [2, 4, 2], [3, 0, 2], [4, 1, 2]]) == 32\n assert candidate(n = 10,maxDistance = 20,roads = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 6], [2, 5, 4], [2, 6, 1], [3, 7, 2], [4, 8, 5], [5, 9, 3], [6, 9, 6], [7, 8, 1], [8, 9, 2], [0, 3, 2], [1, 5, 1], [2, 4, 5]]) == 474\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 2], [1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 0, 3]]) == 19\n assert candidate(n = 6,maxDistance = 10,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 0, 7], [0, 3, 8], [1, 4, 9], [2, 5, 10]]) == 24\n assert candidate(n = 7,maxDistance = 12,roads = [[0, 1, 4], [0, 2, 3], [1, 2, 1], [1, 3, 2], [2, 4, 5], [3, 4, 2], [3, 5, 6], [4, 6, 3], [5, 6, 1]]) == 65\n assert candidate(n = 9,maxDistance = 25,roads = [[0, 1, 3], [1, 2, 4], [2, 3, 5], [3, 4, 6], [4, 5, 7], [5, 6, 8], [6, 7, 9], [7, 8, 10], [8, 0, 11], [0, 4, 2], [1, 5, 3], [2, 6, 4], [3, 7, 5], [4, 8, 6], [5, 0, 7], [6, 1, 8], [7, 2, 9], [8, 3, 10]]) == 329\n assert candidate(n = 6,maxDistance = 5,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 0, 6]]) == 14\n assert candidate(n = 5,maxDistance = 20,roads = [[0, 1, 5], [0, 2, 5], [1, 3, 5], [2, 4, 5], [3, 4, 5]]) == 22\n assert candidate(n = 5,maxDistance = 4,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 1], [3, 4, 2], [4, 0, 3]]) == 17\n assert candidate(n = 8,maxDistance = 12,roads = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 0, 9]]) == 24\n assert candidate(n = 6,maxDistance = 5,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 3], [3, 4, 3], [4, 5, 4], [5, 0, 4]]) == 15\n assert candidate(n = 7,maxDistance = 8,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 0, 7], [0, 3, 1], [1, 4, 2], [2, 5, 3], [3, 6, 4], [4, 0, 5], [5, 1, 6], [6, 2, 7]]) == 71\n assert candidate(n = 5,maxDistance = 7,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 0, 5], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 0, 1], [4, 1, 1]]) == 32\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 0, 2], [0, 2, 2], [1, 3, 2], [2, 4, 2], [3, 0, 2], [4, 1, 2]]) == 32\n assert candidate(n = 8,maxDistance = 20,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8], [0, 2, 2], [1, 3, 3], [2, 4, 4], [3, 5, 5], [4, 6, 6], [5, 7, 7]]) == 167\n assert candidate(n = 5,maxDistance = 7,roads = [[0, 1, 2], [1, 2, 2], [2, 3, 3], [3, 4, 1], [4, 0, 1]]) == 22\n assert candidate(n = 7,maxDistance = 15,roads = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 0, 10], [4, 5, 5], [5, 6, 5], [6, 4, 5], [4, 6, 3], [5, 4, 4]]) == 16\n assert candidate(n = 5,maxDistance = 8,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 0, 5], [0, 2, 3], [1, 3, 4], [2, 4, 5], [3, 0, 6], [4, 1, 7]]) == 32\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 3], [1, 2, 3], [2, 3, 3], [3, 4, 3], [4, 0, 3], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 0, 1], [4, 1, 1]]) == 32\n assert candidate(n = 6,maxDistance = 7,roads = [[0, 1, 2], [0, 2, 3], [1, 3, 2], [1, 4, 5], [2, 5, 1], [3, 4, 2], [4, 5, 3]]) == 29\n assert candidate(n = 7,maxDistance = 8,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 2], [4, 5, 3], [5, 6, 3], [6, 0, 4]]) == 32\n assert candidate(n = 6,maxDistance = 9,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [0, 5, 6]]) == 21\n assert candidate(n = 5,maxDistance = 5,roads = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 0, 5], [0, 2, 6], [1, 3, 7], [2, 4, 8], [3, 0, 9], [4, 1, 10]]) == 13\n assert candidate(n = 5,maxDistance = 7,roads = [[0, 1, 3], [1, 2, 1], [2, 3, 2], [3, 4, 2], [4, 0, 5]]) == 18\n assert candidate(n = 6,maxDistance = 10,roads = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 0, 1], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 5, 1], [4, 0, 1], [5, 1, 1]]) == 61\n", "comparison": "exact"}, "public_tests": ["3\n5\n[[0,1,2],[1,2,10],[0,2,10]]", "3\n5\n[[0,1,20],[0,1,10],[1,2,2],[0,2,2]]", "1\n10\n[]"], "hints": ["Try all the possibilities of closing branches.", "On the vertices that are not closed, use Floyd-Warshall algorithm to find the shortest paths."], "metadata": {"canonical_parameter_names": ["n", "maxDistance", "roads"], "leetcode_dataset_entry_point": "Solution().numberOfSets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:33+00:00", "tests_total": 86, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["bit-manipulation", "graph", "heap-priority-queue", "enumeration", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_sets(n, max_distance, roads)", "container": null, "callable": "number_of_sets", "parameters": [{"name": "n", "type": "Integer"}, {"name": "max_distance", "type": "Integer"}, {"name": "roads", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2960, "task_id": "count-tested-devices-after-test-operations", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.\n\nYour task is to test each device i in order from 0 to n - 1, by performing the following test operations:\n\n- If batteryPercentages[i] is greater than 0:\n - Increment the count of tested devices.\n - Decrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1).\n - Move to the next device.\n- Otherwise, move to the next device without performing any test.\n\nReturn an integer denoting the number of devices that will be tested after performing the test operations in order.\n\nExample 1:\n\nInput: batteryPercentages = [1,1,2,1,3]\nOutput: 3\nExplanation: Performing the test operations in order starting from device 0:\nAt device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].\nAt device 1, batteryPercentages[1] == 0, so we move to the next device without testing.\nAt device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].\nAt device 3, batteryPercentages[3] == 0, so we move to the next device without testing.\nAt device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.\nSo, the answer is 3.\n\nExample 2:\n\nInput: batteryPercentages = [0,1,2]\nOutput: 2\nExplanation: Performing the test operations in order starting from device 0:\nAt device 0, batteryPercentages[0] == 0, so we move to the next device without testing.\nAt device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].\nAt device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.\nSo, the answer is 2.\n\nConstraints:\n\n- 1 <= n == batteryPercentages.length <= 100\n- 0 <= batteryPercentages[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(batteryPercentages = [100, 99, 98, 97, 96]) == 5\n assert candidate(batteryPercentages = [50, 49, 48, 47, 46]) == 5\n assert candidate(batteryPercentages = [100, 100, 100]) == 3\n assert candidate(batteryPercentages = [100, 0, 100, 0, 100]) == 3\n assert candidate(batteryPercentages = [3, 2, 1, 0, 4, 3, 2, 1]) == 3\n assert candidate(batteryPercentages = [3, 0, 2, 0, 1]) == 2\n assert candidate(batteryPercentages = [1, 1, 2, 1, 3]) == 3\n assert candidate(batteryPercentages = [0, 1, 0, 1, 0]) == 1\n assert candidate(batteryPercentages = [1]) == 1\n assert candidate(batteryPercentages = [1, 2, 3, 4, 5]) == 5\n assert candidate(batteryPercentages = [0, 0, 0]) == 0\n assert candidate(batteryPercentages = [3, 2, 1, 0, 4, 3, 2, 1, 0]) == 3\n assert candidate(batteryPercentages = [50, 40, 30, 20, 10]) == 5\n assert candidate(batteryPercentages = [50, 0, 50, 0, 50]) == 3\n assert candidate(batteryPercentages = [0, 1, 2]) == 2\n assert candidate(batteryPercentages = [100]) == 1\n assert candidate(batteryPercentages = [0, 0, 0, 0, 0]) == 0\n assert candidate(batteryPercentages = [100, 99, 98, 97]) == 4\n assert candidate(batteryPercentages = [50, 50, 50, 50, 50]) == 5\n assert candidate(batteryPercentages = [1, 0, 1, 0, 1]) == 1\n assert candidate(batteryPercentages = [0, 0, 0, 0]) == 0\n assert candidate(batteryPercentages = [1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(batteryPercentages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(batteryPercentages = [0]) == 0\n assert candidate(batteryPercentages = [10, 20, 30, 40, 50]) == 5\n assert candidate(batteryPercentages = [5, 5, 5, 5, 5]) == 5\n assert candidate(batteryPercentages = [1, 0, 2, 0, 3, 0, 4]) == 4\n assert candidate(batteryPercentages = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == 5\n assert candidate(batteryPercentages = [5, 3, 0, 2, 1, 0, 4, 0, 3]) == 3\n assert candidate(batteryPercentages = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(batteryPercentages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(batteryPercentages = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(batteryPercentages = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(batteryPercentages = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(batteryPercentages = [3, 0, 3, 0, 3, 0, 3, 0, 3, 0]) == 3\n assert candidate(batteryPercentages = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(batteryPercentages = [5, 0, 5, 0, 5, 0, 5, 0]) == 4\n assert candidate(batteryPercentages = [0, 1, 0, 2, 0, 3, 0, 4]) == 4\n assert candidate(batteryPercentages = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(batteryPercentages = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(batteryPercentages = [100, 0, 99, 1, 98, 2, 97, 3, 96, 4]) == 5\n assert candidate(batteryPercentages = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 2\n assert candidate(batteryPercentages = [3, 2, 1, 0, 5, 4, 3, 2, 1]) == 4\n assert candidate(batteryPercentages = [0, 10, 0, 20, 0, 30, 0, 40, 0, 50]) == 5\n assert candidate(batteryPercentages = [20, 20, 19, 19, 18, 18, 17, 17, 16, 16]) == 10\n assert candidate(batteryPercentages = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 10\n assert candidate(batteryPercentages = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10]) == 8\n assert candidate(batteryPercentages = [10, 0, 10, 0, 10, 0, 10]) == 4\n assert candidate(batteryPercentages = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == 10\n assert candidate(batteryPercentages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0]) == 5\n assert candidate(batteryPercentages = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(batteryPercentages = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5]) == 5\n assert candidate(batteryPercentages = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 20\n assert candidate(batteryPercentages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(batteryPercentages = [3, 0, 5, 2, 8, 0, 6]) == 4\n assert candidate(batteryPercentages = [3, 2, 1, 0, 4, 5]) == 4\n assert candidate(batteryPercentages = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(batteryPercentages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(batteryPercentages = [100, 0, 100, 0, 100, 0, 100]) == 4\n assert candidate(batteryPercentages = [20, 0, 15, 5, 0, 10, 0, 0, 0, 5]) == 5\n assert candidate(batteryPercentages = [50, 25, 0, 75, 100, 0, 0, 25, 50, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 7\n assert candidate(batteryPercentages = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0]) == 10\n assert candidate(batteryPercentages = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(batteryPercentages = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 10\n assert candidate(batteryPercentages = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(batteryPercentages = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(batteryPercentages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(batteryPercentages = [3, 2, 2, 1, 1, 0, 0, 1, 1, 0]) == 2\n assert candidate(batteryPercentages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 5\n assert candidate(batteryPercentages = [100, 99, 98, 97, 96, 95, 94]) == 7\n assert candidate(batteryPercentages = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(batteryPercentages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(batteryPercentages = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5]) == 5\n assert candidate(batteryPercentages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(batteryPercentages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 5\n assert candidate(batteryPercentages = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(batteryPercentages = [0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0]) == 3\n assert candidate(batteryPercentages = [0, 100, 0, 100, 0, 100, 0, 100]) == 4\n assert candidate(batteryPercentages = [1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 7\n assert candidate(batteryPercentages = [50, 25, 0, 75, 50, 25, 0, 75, 50, 25]) == 8\n assert candidate(batteryPercentages = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10]) == 10\n assert candidate(batteryPercentages = [50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100]) == 20\n assert candidate(batteryPercentages = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == 5\n assert candidate(batteryPercentages = [90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0, 90, 0]) == 15\n assert candidate(batteryPercentages = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(batteryPercentages = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6]) == 6\n assert candidate(batteryPercentages = [100, 0, 99, 0, 98, 0, 97, 0, 96, 0]) == 5\n assert candidate(batteryPercentages = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 3\n assert candidate(batteryPercentages = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(batteryPercentages = [2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1]) == 2\n assert candidate(batteryPercentages = [100, 99, 98, 97, 96, 95]) == 6\n assert candidate(batteryPercentages = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100]) == 5\n assert candidate(batteryPercentages = [0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0]) == 6\n assert candidate(batteryPercentages = [3, 2, 1, 0, 4, 5, 0, 6]) == 5\n assert candidate(batteryPercentages = [5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0]) == 5\n assert candidate(batteryPercentages = [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]) == 31\n assert candidate(batteryPercentages = [3, 2, 1, 0, 1, 2, 3]) == 3\n assert candidate(batteryPercentages = [100, 100, 0, 0, 50, 50, 0, 0, 25, 25]) == 6\n assert candidate(batteryPercentages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 10\n assert candidate(batteryPercentages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(batteryPercentages = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]) == 5\n assert candidate(batteryPercentages = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(batteryPercentages = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]) == 1\n assert candidate(batteryPercentages = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 29\n assert candidate(batteryPercentages = [1, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 1]) == 10\n assert candidate(batteryPercentages = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(batteryPercentages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n", "comparison": "exact"}, "public_tests": ["[1,1,2,1,3]", "[0,1,2]"], "hints": ["One solution is simulating the operations as explained in the problem statement, and it works in O(n^2) time.", "While going through the devices, you can maintain the number of previously tested devices, and the current device can be tested if batteryPercentages[i] is greater than the number of tested devices."], "metadata": {"canonical_parameter_names": ["batteryPercentages"], "leetcode_dataset_entry_point": "Solution().countTestedDevices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:36+00:00", "tests_total": 107, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "simulation", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def count_tested_devices(battery_percentages)", "container": null, "callable": "count_tested_devices", "parameters": [{"name": "battery_percentages", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2962, "task_id": "count-subarrays-where-max-element-appears-at-least-k-times", "difficulty": "Medium", "problem_description": "You are given an integer array nums and a positive integer k.\n\nReturn the number of subarrays where the maximum element of nums appears at least k times in that subarray.\n\nA subarray is a contiguous sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,2,3,3], k = 2\nOutput: 6\nExplanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].\n\nExample 2:\n\nInput: nums = [1,4,2,1], k = 3\nOutput: 0\nExplanation: No subarray contains the element 4 at least 3 times.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n- 1 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 1, 10, 10],k = 4) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 5) == 21\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 4) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 10\n assert candidate(nums = [1, 3, 2, 3, 3],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 5\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],k = 3) == 6\n assert candidate(nums = [1, 4, 2, 1],k = 3) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 3) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == 55\n assert candidate(nums = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 2) == 29\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 5) == 136\n assert candidate(nums = [3, 1, 4, 3, 3, 2, 3, 3, 3],k = 4) == 0\n assert candidate(nums = [1000000, 999999, 1000000, 999999, 1000000, 999999, 1000000, 999999, 1000000, 999999],k = 5) == 2\n assert candidate(nums = [5, 5, 1, 5, 5, 1, 5, 5, 1, 5, 5, 1, 5, 5],k = 3) == 63\n assert candidate(nums = [1000000, 999999, 999999, 1000000, 999999, 1000000, 1000000, 999999, 1000000, 1000000],k = 4) == 12\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],k = 10) == 903\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 10) == 66\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 9\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],k = 15) == 171\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],k = 2) == 96\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, 9],k = 20) == 66\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 8) == 6\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 66\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1],k = 3) == 0\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 5) == 6\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6],k = 2) == 72\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 = 1) == 20\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10, 90, 10, 100],k = 5) == 0\n assert candidate(nums = [1000000, 999999, 1000000, 999999, 1000000, 999999, 1000000, 999999, 1000000, 999999],k = 3) == 18\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1],k = 3) == 0\n assert candidate(nums = [100, 200, 300, 100, 400, 100, 500, 100, 600, 100, 700, 100, 800, 100, 900, 100, 100, 100, 100],k = 4) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 100],k = 2) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1],k = 3) == 36\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1],k = 5) == 48\n assert candidate(nums = [3, 3, 3, 2, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3],k = 5) == 630\n assert candidate(nums = [9, 9, 8, 9, 8, 9, 8, 9, 8, 9, 9, 9, 9, 9],k = 5) == 32\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],k = 20) == 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 = 2) == 10\n assert candidate(nums = [7, 3, 7, 7, 2, 7, 7, 7, 7, 7],k = 6) == 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],k = 5) == 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 = 2) == 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],k = 5) == 0\n assert candidate(nums = [7, 5, 7, 8, 7, 9, 7, 7, 6, 7],k = 3) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 5) == 36\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 100\n assert candidate(nums = [7, 7, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1],k = 4) == 102\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 = 10) == 66\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 5) == 200\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5],k = 3) == 5\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 = 5) == 72\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 2) == 27\n assert candidate(nums = [1, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3],k = 10) == 3826\n assert candidate(nums = [1000000, 999999, 1000000, 999999, 1000000, 999999, 1000000],k = 4) == 1\n assert candidate(nums = [7, 7, 7, 1, 7, 1, 7, 7, 7, 7],k = 3) == 29\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300, 100, 200, 300],k = 2) == 36\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 = 1) == 120\n assert candidate(nums = [1000000, 1000000, 1000000, 999999, 999999, 1000000, 999999, 1000000, 1000000, 999999],k = 4) == 10\n assert candidate(nums = [5, 6, 7, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6],k = 4) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 21\n assert candidate(nums = [1, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3],k = 6) == 1150\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1],k = 2) == 156\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 3) == 5\n assert candidate(nums = [7, 1, 5, 3, 6, 4, 7, 7, 7, 2, 7],k = 3) == 23\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5],k = 4) == 105\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1],k = 3) == 138\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 = 10) == 231\n assert candidate(nums = [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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 15) == 496\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 7) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 100\n assert candidate(nums = [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],k = 5) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 20) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3) == 19\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6],k = 4) == 0\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],k = 20) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 6) == 28\n assert candidate(nums = [1, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 15) == 111\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],k = 25) == 231\n assert candidate(nums = [3, 3, 3, 1, 1, 1, 3, 3, 1, 1, 1, 3, 3, 3, 1, 1, 1, 3, 3, 3, 1, 1, 1],k = 4) == 132\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 10\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],k = 15) == 171\n", "comparison": "exact"}, "public_tests": ["[1,3,2,3,3]\n2", "[1,4,2,1]\n3"], "hints": [], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:38+00:00", "tests_total": 90, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def count_subarrays(nums, k)", "container": null, "callable": "count_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2965, "task_id": "find-missing-and-repeated-values", "difficulty": "Easy", "problem_description": "You are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n^2]. Each integer appears exactly once except a which appears twice and b which is missing. The task is to find the repeating and missing numbers a and b.\n\nReturn a 0-indexed integer array ans of size 2 where ans[0] equals to a and ans[1] equals to b.\n\nExample 1:\n\nInput: grid = [[1,3],[2,2]]\nOutput: [2,4]\nExplanation: Number 2 is repeated and number 4 is missing so the answer is [2,4].\n\nExample 2:\n\nInput: grid = [[9,1,7],[8,9,2],[3,4,6]]\nOutput: [9,5]\nExplanation: Number 9 is repeated and number 5 is missing so the answer is [9,5].\n\nConstraints:\n\n- 2 <= n == grid.length == grid[i].length <= 50\n- 1 <= grid[i][j] <= n * n\n- For all x that 1 <= x <= n * n there is exactly one x that is not equal to any of the grid members.\n- For all x that 1 <= x <= n * n there is exactly one x that is equal to exactly two of the grid members.\n- For all x that 1 <= x <= n * n except two of them there is exactly one pair of i, j that 0 <= i, j <= n - 1 and grid[i][j] == x.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1], [2, 3]]) == [1, 4]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 8]]) == [8, 9]\n assert candidate(grid = [[1, 3], [2, 2]]) == [2, 4]\n assert candidate(grid = [[4, 5, 6], [7, 8, 9], [1, 2, 1]]) == [1, 3]\n assert candidate(grid = [[1, 2], [2, 3]]) == [2, 4]\n assert candidate(grid = [[4, 3, 2], [1, 5, 2], [6, 7, 8]]) == [2, 9]\n assert candidate(grid = [[9, 1, 7], [8, 9, 2], [3, 4, 6]]) == [9, 5]\n assert candidate(grid = [[16, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 13]]) == [13, 1]\n assert candidate(grid = [[16, 2, 3, 4], [5, 13, 6, 7], [8, 9, 12, 10], [11, 15, 14, 13]]) == [13, 1]\n assert candidate(grid = [[4, 1, 3], [3, 2, 5], [6, 5, 7]]) == [5, 9]\n assert candidate(grid = [[4, 3, 2], [1, 5, 1], [6, 7, 8]]) == [1, 9]\n assert candidate(grid = [[25, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [25, 21, 22, 23, 24]]) == [25, 1]\n assert candidate(grid = [[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], [61, 62, 63, 64, 65, 66, 67, 68, 69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 99]]) == [99, 100]\n assert candidate(grid = [[36, 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, 31, 32, 33, 34, 35]]) == [0, 0]\n assert candidate(grid = [[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]]) == [0, 0]\n assert candidate(grid = [[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, 42]]) == [42, 49]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 1]]) == [1, 25]\n assert candidate(grid = [[25, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 24, 24]]) == [24, 23]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 23, 25]]) == [23, 24]\n assert candidate(grid = [[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, 30]]) == [30, 36]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 24]]) == [24, 25]\n assert candidate(grid = [[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, 48]]) == [48, 49]\n assert candidate(grid = [[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, 36, 36]]) == [36, 35]\n assert candidate(grid = [[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, 49, 49]]) == [49, 48]\n assert candidate(grid = [[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, 40]]) == [40, 49]\n assert candidate(grid = [[36, 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]]) == [36, 1]\n assert candidate(grid = [[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, 61, 62, 63, 63]]) == [63, 64]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 10], [21, 22, 23, 24, 25]]) == [10, 20]\n assert candidate(grid = [[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, 44]]) == [44, 49]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 25, 25]]) == [25, 24]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 25, 24, 25]]) == [25, 23]\n assert candidate(grid = [[25, 24, 23, 22, 21], [20, 19, 18, 17, 16], [15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 3]]) == [3, 1]\n assert candidate(grid = [[25, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]]) == [25, 1]\n assert candidate(grid = [[25, 1, 3, 5, 7], [9, 11, 13, 15, 17], [19, 21, 23, 25, 2], [4, 6, 8, 10, 12], [14, 16, 18, 20, 22]]) == [25, 24]\n assert candidate(grid = [[25, 1, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 24]]) == [24, 2]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 25, 25]]) == [25, 24]\n assert candidate(grid = [[49, 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, 61, 62], [63, 64, 65, 66, 67, 68, 69, 70, 71], [72, 73, 74, 75, 76, 77, 78, 79, 80]]) == [49, 81]\n assert candidate(grid = [[4, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]]) == [4, 1]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [25, 22, 23, 24, 25]]) == [25, 21]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 24]]) == [24, 25]\n assert candidate(grid = [[25, 24, 23, 22, 21], [20, 19, 18, 17, 16], [15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 3, 1]]) == [3, 2]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 25], [21, 22, 23, 24, 25]]) == [25, 20]\n assert candidate(grid = [[36, 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, 35]]) == [35, 1]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 16]]) == [16, 25]\n assert candidate(grid = [[16, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 24]]) == [24, 25]\n assert candidate(grid = [[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, 2]]) == [2, 1]\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19], [12, 14, 16, 18, 20], [21, 22, 23, 24, 24]]) == [24, 25]\n assert candidate(grid = [[1, 3, 4, 5, 6], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16], [17, 18, 19, 20, 21], [22, 23, 24, 25, 22]]) == [22, 2]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 25], [21, 22, 25, 24, 25]]) == [0, 23]\n assert candidate(grid = [[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, 29]]) == [29, 36]\n assert candidate(grid = [[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, 0]\n assert candidate(grid = [[2, 3, 4, 5, 6], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16], [17, 18, 19, 20, 21], [22, 23, 24, 25, 25]]) == [25, 1]\n assert candidate(grid = [[4, 2, 3, 1, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 24]]) == [24, 25]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 10]]) == [10, 25]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 23]]) == [23, 25]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [22, 23, 24, 25, 22]]) == [22, 21]\n assert candidate(grid = [[25, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [1, 21, 22, 23, 24]]) == [0, 0]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 20, 20], [21, 22, 23, 24, 19]]) == [20, 25]\n assert candidate(grid = [[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, 61, 62, 63], [64, 65, 66, 67, 68, 69, 70, 71, 72], [73, 74, 75, 76, 77, 78, 79, 80, 80]]) == [80, 81]\n assert candidate(grid = [[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, 35]]) == [35, 36]\n assert candidate(grid = [[49, 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, 61, 62], [63, 64, 65, 66, 67, 68, 69, 70, 71], [72, 73, 74, 75, 76, 77, 78, 80, 80]]) == [80, 81]\n assert candidate(grid = [[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]]) == [0, 0]\n assert candidate(grid = [[25, 22, 23, 24, 20], [18, 17, 16, 15, 14], [13, 12, 11, 10, 9], [8, 7, 6, 5, 4], [3, 2, 1, 1, 19]]) == [1, 21]\n assert candidate(grid = [[25, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 24]]) == [24, 1]\n assert candidate(grid = [[25, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [25, 22, 23, 24, 21]]) == [25, 1]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 21]]) == [21, 25]\n", "comparison": "exact"}, "public_tests": ["[[1,3],[2,2]]", "[[9,1,7],[8,9,2],[3,4,6]]"], "hints": [], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().findMissingAndRepeatedValues", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:43+00:00", "tests_total": 69, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "math", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def find_missing_and_repeated_values(grid)", "container": null, "callable": "find_missing_and_repeated_values", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2966, "task_id": "divide-array-into-arrays-with-max-difference", "difficulty": "Medium", "problem_description": "You are given an integer array nums of size n where n is a multiple of 3 and a positive integer k.\n\nDivide the array nums into n / 3 arrays of size 3 satisfying the following condition:\n\n- The difference between any two elements in one array is less than or equal to k.\n\nReturn a 2D array containing the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return any of them.\n\nExample 1:\n\nInput: nums = [1,3,4,8,7,9,3,5,1], k = 2\nOutput: [[1,1,3],[3,4,5],[7,8,9]]\nExplanation:\nThe difference between any two elements in each array is less than or equal to 2.\n\nExample 2:\n\nInput: nums = [2,4,2,2,5,2], k = 2\nOutput: []\nExplanation:\nDifferent ways to divide nums into 2 arrays of size 3 are:\n- [[2,2,2],[2,4,5]] (and its permutations)\n- [[2,2,4],[2,2,5]] (and its permutations)\n\nBecause there are four 2s there will be an array with the elements 2 and 5 no matter how we divide it. since 5 - 2 = 3 > k, the condition is not satisfied and so there is no valid division.\n\nExample 3:\n\nInput: nums = [4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11], k = 14\nOutput: [[2,2,2],[4,5,5],[5,5,7],[7,8,8],[9,9,10],[11,12,12]]\nExplanation:\nThe difference between any two elements in each array is less than or equal to 14.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- n is a multiple of 3\n- 1 <= nums[i] <= 10^5\n- 1 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 4, 2, 2, 5, 2],k = 2) == []\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 3) == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n assert candidate(nums = [1, 3, 4, 8, 7, 9, 3, 5, 1],k = 2) == [[1, 1, 3], [3, 4, 5], [7, 8, 9]]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == [[5, 5, 5], [5, 5, 5], [5, 5, 5]]\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 2) == [[1, 2, 3], [4, 5, 6]]\n assert candidate(nums = [4, 2, 9, 8, 2, 12, 7, 12, 10, 5, 8, 5, 5, 7, 9, 2, 5, 11],k = 14) == [[2, 2, 2], [4, 5, 5], [5, 5, 7], [7, 8, 8], [9, 9, 10], [11, 12, 12]]\n assert candidate(nums = [5, 5, 5, 10, 10, 10, 15, 15, 15, 20, 20, 20, 25, 25, 25, 30, 30, 30],k = 4) == [[5, 5, 5], [10, 10, 10], [15, 15, 15], [20, 20, 20], [25, 25, 25], [30, 30, 30]]\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 9) == []\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41],k = 2) == [[30, 31, 32], [33, 34, 35], [36, 37, 38], [39, 40, 41]]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 15) == []\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 300, 300, 300],k = 100) == [[100, 100, 100], [200, 200, 200], [300, 300, 300]]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 5) == []\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 20) == [[10, 20, 30], [40, 50, 60], [70, 80, 90], [100, 110, 120]]\n assert candidate(nums = [3, 3, 3, 6, 6, 6, 9, 9, 9, 12, 12, 12],k = 3) == [[3, 3, 3], [6, 6, 6], [9, 9, 9], [12, 12, 12]]\n assert candidate(nums = [1, 3, 6, 10, 15, 18, 20, 25, 30, 33, 36, 40],k = 5) == []\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 2) == []\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 2) == []\n assert candidate(nums = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 3) == [[9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20]]\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],k = 50) == [[1, 10, 20], [30, 40, 50], [60, 70, 80], [90, 100, 110]]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 9) == []\n assert candidate(nums = [15, 15, 15, 25, 25, 25, 35, 35, 35, 45, 45, 45, 55, 55, 55, 65, 65, 65],k = 9) == [[15, 15, 15], [25, 25, 25], [35, 35, 35], [45, 45, 45], [55, 55, 55], [65, 65, 65]]\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 = 3) == [[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]]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995],k = 2) == [[99995, 99996, 99997], [99998, 99999, 100000]]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 4) == [[1, 3, 5], [7, 9, 11], [13, 15, 17], [19, 21, 23]]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 3) == [[1, 1, 2], [2, 3, 3], [4, 4, 5], [5, 6, 6], [7, 8, 9], [10, 11, 12]]\n assert candidate(nums = [1, 100, 200, 101, 201, 300, 102, 202, 301],k = 100) == [[1, 100, 101], [102, 200, 201], [202, 300, 301]]\n assert candidate(nums = [3, 3, 3, 6, 6, 6, 9, 9, 9, 12, 12, 12, 15, 15, 15],k = 3) == [[3, 3, 3], [6, 6, 6], [9, 9, 9], [12, 12, 12], [15, 15, 15]]\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 7, 9, 11, 8, 10, 12],k = 3) == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 250) == [[100, 200, 300], [400, 500, 600], [700, 800, 900], [1000, 1100, 1200]]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 1) == []\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 1) == [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]\n assert candidate(nums = [1, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010],k = 10) == []\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91, 11, 90, 12, 89, 13, 88, 14, 87, 15, 86],k = 99) == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [86, 87, 88], [89, 90, 91], [92, 93, 94], [95, 96, 97], [98, 99, 100]]\n assert candidate(nums = [1, 6, 8, 10, 12, 14, 16, 20, 22, 24, 26, 28],k = 4) == []\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 100) == []\n assert candidate(nums = [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],k = 90) == [[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]]\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],k = 2) == [[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]]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115],k = 10) == []\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12],k = 1) == [[7, 7, 8], [8, 9, 9], [10, 10, 11], [11, 12, 12]]\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 10, 11, 12, 15, 16, 17],k = 2) == [[1, 2, 3], [6, 7, 8], [10, 11, 12], [15, 16, 17]]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],k = 5) == [[2, 4, 6], [8, 10, 12], [14, 16, 18], [20, 22, 24]]\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 21, 22, 23, 26, 27, 28, 31, 32, 33, 36, 37, 38, 41, 42, 43, 46, 47, 48],k = 2) == [[1, 2, 3], [6, 7, 8], [11, 12, 13], [16, 17, 18], [21, 22, 23], [26, 27, 28], [31, 32, 33], [36, 37, 38], [41, 42, 43], [46, 47, 48]]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],k = 3) == []\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7],k = 1) == [[1, 2, 2], [3, 3, 4], [4, 5, 5], [6, 6, 7]]\n assert candidate(nums = [100, 200, 300, 101, 201, 301, 102, 202, 302, 103, 203, 303],k = 3) == []\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 10) == []\n assert candidate(nums = [100, 101, 102, 200, 201, 202, 300, 301, 302, 400, 401, 402, 500, 501, 502],k = 2) == [[100, 101, 102], [200, 201, 202], [300, 301, 302], [400, 401, 402], [500, 501, 502]]\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9],k = 1) == [[1, 1, 2], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9]]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 1) == [[1, 2, 2], [3, 3, 3], [4, 4, 4], [4, 5, 5], [5, 5, 5]]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17],k = 4) == [[1, 3, 5], [7, 9, 11], [13, 15, 17]]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 11, 10, 12],k = 2) == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]\n assert candidate(nums = [1, 6, 7, 8, 10, 11, 15, 16, 17],k = 2) == []\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],k = 1) == []\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18],k = 2) == [[1, 2, 3], [6, 7, 8], [11, 12, 13], [16, 17, 18]]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54],k = 3) == []\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 2) == [[5, 6, 7], [8, 9, 10], [11, 12, 13], [14, 15, 16]]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108],k = 2) == [[100, 101, 102], [103, 104, 105], [106, 107, 108]]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],k = 12) == [[3, 6, 9], [12, 15, 18], [21, 24, 27], [30, 33, 36]]\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],k = 5) == [[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]]\n assert candidate(nums = [3, 3, 3, 6, 6, 6, 9, 9, 9, 12, 12, 12],k = 2) == [[3, 3, 3], [6, 6, 6], [9, 9, 9], [12, 12, 12]]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],k = 2) == []\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9],k = 2) == [[1, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9]]\n assert candidate(nums = [10, 15, 10, 20, 25, 15, 30, 35, 30],k = 5) == []\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],k = 2) == [[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]]\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 = 10) == [[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]]\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170],k = 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, 11, 11, 11],k = 2) == [[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]]\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 25, 30, 35],k = 5) == []\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],k = 1) == [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6]]\n assert candidate(nums = [10, 20, 20, 20, 30, 30, 30, 40, 40, 50, 50, 50],k = 15) == [[10, 20, 20], [20, 30, 30], [30, 40, 40], [50, 50, 50]]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992],k = 3) == [[99992, 99993, 99994], [99995, 99996, 99997], [99998, 99999, 100000]]\n assert candidate(nums = [100, 101, 102, 200, 201, 202, 300, 301, 302, 400, 401, 402],k = 2) == [[100, 101, 102], [200, 201, 202], [300, 301, 302], [400, 401, 402]]\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 = 2) == [[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]]\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],k = 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]]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27],k = 9) == [[3, 6, 9], [12, 15, 18], [21, 24, 27]]\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 = 4) == [[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]]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 9) == []\n assert candidate(nums = [100000, 100000, 100000, 99999, 99999, 99999, 99998, 99998, 99998, 99997, 99997, 99997],k = 1) == [[99997, 99997, 99997], [99998, 99998, 99998], [99999, 99999, 99999], [100000, 100000, 100000]]\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 21, 22, 23],k = 2) == [[1, 2, 3], [6, 7, 8], [11, 12, 13], [16, 17, 18], [21, 22, 23]]\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],k = 1) == [[1, 1, 2], [2, 3, 3], [4, 4, 5], [5, 6, 6], [7, 7, 8], [8, 9, 9], [10, 10, 11], [11, 12, 12]]\n assert candidate(nums = [10, 20, 30, 11, 21, 31, 12, 22, 32, 13, 23, 33],k = 1) == []\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50],k = 10) == [[10, 15, 20], [25, 30, 35], [40, 45, 50]]\n", "comparison": "exact"}, "public_tests": ["[1,3,4,8,7,9,3,5,1]\n2", "[2,4,2,2,5,2]\n2", "[4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11]\n14"], "hints": ["Try to use a greedy approach.", "Sort the array and try to group each 3 consecutive elements."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().divideArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:46+00:00", "tests_total": 95, "tests_dropped": 13, "flags": ["multiple_answers"], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def divide_array(nums, k)", "container": null, "callable": "divide_array", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2967, "task_id": "minimum-cost-to-make-array-equalindromic", "difficulty": "Medium", "problem_description": "You are given an integer array nums.\n\nIn one operation, you may choose an index i and either increment or decrement nums[i] by 1.\n\nReturn the minimum number of operations required to make every element in nums equal to the same positive palindromic integer.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 6\nExplanation: Increment nums[0] twice and nums[1] once, then decrement nums[3] once and nums[4] twice. After 6 operations, nums becomes [3,3,3,3,3], and 3 is a positive palindromic integer.\nIt can be shown that this is the minimum number of operations required.\n\nExample 2:\n\nInput: nums = [10,12,13,14,15]\nOutput: 11\nExplanation: Increment nums[0] once, then decrement nums[1], nums[2], nums[3], and nums[4] by 1, 2, 3, and 4, respectively. After 11 operations, nums becomes [11,11,11,11,11], and 11 is a positive palindromic integer.\nIt can be shown that this is the minimum number of operations required.\n\nExample 3:\n\nInput: nums = [22,33,22,33,22]\nOutput: 22\nExplanation: Decrement nums[1] and nums[3] by 11 each. After 22 operations, nums becomes [22,22,22,22,22], and 22 is a positive palindromic integer.\nIt can be shown that this is the minimum number of operations required.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [123, 121, 131, 141, 151]) == 48\n assert candidate(nums = [100000001, 200000002, 300000003, 400000004, 500000005]) == 600000006\n assert candidate(nums = [123456789, 987654321, 12345678, 87654321, 1234567, 7654321]) == 1177530865\n assert candidate(nums = [12321, 23432, 34543, 45654, 56765]) == 66666\n assert candidate(nums = [101, 202, 303, 404, 505]) == 606\n assert candidate(nums = [123, 456, 789, 101, 202]) == 1021\n assert candidate(nums = [100000000, 100000001, 100000002, 100000003, 100000004]) == 7\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555]) == 666666666\n assert candidate(nums = [8, 88, 888, 8888, 88888]) == 97680\n assert candidate(nums = [1, 2, 3, 4, 5]) == 6\n assert candidate(nums = [12321, 45654, 78987, 101101, 23432]) == 144335\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500]) == 603\n assert candidate(nums = [123, 456, 789, 101112, 131415]) == 231950\n assert candidate(nums = [123, 321, 132, 213, 231, 312]) == 396\n assert candidate(nums = [12321, 45654, 78987, 1011101, 1213121]) == 2166247\n assert candidate(nums = [9, 11, 22, 33, 44]) == 57\n assert candidate(nums = [9, 9, 9, 9, 9]) == 0\n assert candidate(nums = [12321, 45654, 78987, 10101, 11111]) == 103429\n assert candidate(nums = [100000000, 99999999, 10000000, 9999999, 1000000]) == 189000001\n assert candidate(nums = [10, 12, 13, 14, 15]) == 11\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000]) == 600000003\n assert candidate(nums = [22, 33, 22, 33, 22]) == 22\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995]) == 10\n assert candidate(nums = [9, 99, 999, 9999, 99999]) == 109890\n assert candidate(nums = [123456789, 987654321, 123456789, 987654321, 123456789]) == 1728402596\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 222, 333, 444, 555, 666, 777, 888, 999]) == 5005\n assert candidate(nums = [1221, 2332, 3443, 4554, 5665, 6776, 7887, 8998, 9119]) == 21230\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1012, 1213, 1314, 1415, 1516, 1617, 1718, 1819, 1920]) == 8561\n assert candidate(nums = [11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999, 111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999, 1000001, 1111111]) == 6388890\n assert candidate(nums = [100000000, 100000001, 100000002, 100000003, 100000004, 100000005]) == 11\n assert candidate(nums = [12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321]) == 419760\n assert candidate(nums = [100000001, 200000002, 300000003, 400000004, 500000005, 600000006, 700000007, 800000008, 900000009]) == 2000000020\n assert candidate(nums = [100000000, 100000001, 100000002, 100000003, 100000004, 100000005, 100000006]) == 16\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000]) == 2000000005\n assert candidate(nums = [123456789, 987654321, 876543210, 765432109, 654321098, 543210987]) == 1308640766\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 10001]) == 25016\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 100001]) == 116666\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000]) == 600000003\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 10101, 11111, 12212, 13331, 14441, 15551, 16661, 17771, 18881, 19991]) == 94905\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1001]) == 2666\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 1010, 1111, 2222, 3333]) == 6320\n assert candidate(nums = [100000001, 200000002, 300000003, 400000004, 500000005, 600000006, 700000007, 800000008, 900000009, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 4277777790\n assert candidate(nums = [123321, 213312, 321123, 432234, 543345, 654456, 765567, 876678, 987789, 110011]) == 2627834\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1012, 2123, 3234, 4345, 5456, 6567, 7678, 8789, 9890]) == 44111\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 2222222220\n assert candidate(nums = [123456789, 123456788, 123456790, 123456791, 123456787, 123456779, 123456786, 123456792, 123456785, 123456793]) == 24670\n assert candidate(nums = [111111111, 111111112, 111111113, 111111114, 111111115, 111111116, 111111117, 111111118, 111111119, 111111120]) == 45\n assert candidate(nums = [121, 222, 333, 444, 555, 666, 777, 888, 999, 1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 40040\n assert candidate(nums = [1234321, 4321234, 5678765, 8765678, 9876789, 123454321, 432151234, 567898765]) == 1113381111\n assert candidate(nums = [123321, 124421, 125521, 126621, 127721, 128821, 129921, 130031, 131131, 132231, 133331]) == 29040\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 100000000, 99999999, 88888888, 77777777, 66666666, 55555555]) == 4066666666\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 45\n assert candidate(nums = [22, 33, 22, 33, 22, 22, 33, 22, 33, 22, 22, 33, 22, 33, 22, 22, 33, 22, 33, 22]) == 88\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 10001]) == 25016\n assert candidate(nums = [1234321, 2345432, 3456543, 4567654, 5678765, 6789876, 7891098, 8910198, 9101109]) == 21088331\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888]) == 2641975308\n assert candidate(nums = [10001, 20002, 30003, 40004, 50005, 60006, 70007, 80008, 90009, 10101, 11111, 12212, 13331, 14441, 15551, 16661, 17771, 18881, 19991, 20002, 21112, 22222, 23332, 24442, 25552]) == 356648\n assert candidate(nums = [987654321, 987654320, 987654319, 987654318, 987654317, 987654316, 987654315]) == 17297\n assert candidate(nums = [12321, 12321, 12321, 12321, 12321, 12321, 12321, 12321, 12321, 12321]) == 0\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999, 1111111]) == 2777776\n assert candidate(nums = [123, 321, 231, 132, 111, 222, 333, 444, 555, 666]) == 1500\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 100\n assert candidate(nums = [98789, 87678, 76567, 65456, 54345, 43234, 32123, 21012, 10901, 98789]) == 265664\n assert candidate(nums = [123456789, 987654321, 123456789, 987654321, 123456789, 987654321, 123456789, 987654321]) == 3456790128\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1001]) == 2516\n assert candidate(nums = [100000000, 100000001, 100000002, 100000003, 100000004, 100000005, 100000006, 100000007, 100000008, 100000009]) == 37\n assert candidate(nums = [987654321, 876543218, 765432187, 654321876, 543218765, 432187654, 321876543, 218765432, 187654321]) == 2123471232\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == 45000\n assert candidate(nums = [100001, 101001, 110111, 111111, 121212, 131313, 141414, 151515, 161616, 171717]) == 214139\n assert candidate(nums = [123210, 213210, 321230, 432340, 543450, 654560, 765670, 876780, 987890, 1098901]) == 2750361\n assert candidate(nums = [88888888, 77777777, 66666666, 55555555, 44444444, 33333333, 22222222, 11111111]) == 177777776\n assert candidate(nums = [999, 1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 10001]) == 29022\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 50\n assert candidate(nums = [1221, 1331, 1441, 1551, 1661, 1771, 1881, 1991, 2002, 2112]) == 2552\n assert candidate(nums = [123, 132, 213, 231, 312, 321, 432, 423, 342, 324, 243, 234, 543, 534, 453, 435, 354, 345, 654, 645]) == 2343\n assert candidate(nums = [121, 131, 141, 151, 161, 171, 181, 191, 202, 212]) == 252\n assert candidate(nums = [987654321, 987654320, 987654319, 987654318, 987654317, 987654316, 987654315]) == 17297\n assert candidate(nums = [12321, 21321, 32123, 43234, 54345, 65456, 76567]) == 130603\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 56\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 1000\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215, 225, 235, 245, 255, 265, 275, 285, 295, 305, 315, 325, 335, 345, 355, 365, 375, 385, 395]) == 4000\n assert candidate(nums = [12345, 54321, 67890, 90876, 12345, 54321, 67890, 90876]) == 184200\n assert candidate(nums = [12321, 45654, 78987, 10101, 11111, 98789, 1234321, 4567654, 112211]) == 5933788\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777]) == 1333333332\n assert candidate(nums = [11111111, 22222222, 33333333, 44444444, 55555555, 66666666, 77777777, 88888888, 99999999, 100000000]) == 266666665\n assert candidate(nums = [123456789, 123456788, 123456787, 123456786, 123456785, 123456784, 123456783, 123456782, 123456781, 123456780]) == 24635\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 100\n assert candidate(nums = [10001, 20002, 30003, 40004, 50005, 60006, 70007, 80008, 90009, 110011]) == 260026\n assert candidate(nums = [12321, 23432, 34543, 45654, 56765, 67876, 78987, 89098, 90109, 10101]) == 256784\n assert candidate(nums = [123456789, 987654321, 111222333, 333222111, 555555555]) == 1308530976\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 20020\n assert candidate(nums = [1221, 2332, 3443, 4554, 5665, 6776, 7887, 8998, 10101, 20202, 30303, 40404, 50505, 60606, 70707, 80808, 90909, 111111, 222222, 333333]) == 1019729\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1010]) == 2675\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 100000000, 99999999, 88888888, 77777777, 66666666, 55555555, 44444444, 33333333, 22222222, 11111111]) == 5400000000\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1001, 1111, 1221, 1331, 1441, 1551, 1661, 1771, 1881, 1991]) == 9414\n assert candidate(nums = [12345, 54321, 11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999, 10101, 20202, 30303, 40404, 50505, 60606, 70707, 80808, 90909]) == 471266\n assert candidate(nums = [100000001, 200000002, 300000003, 400000004, 500000005, 600000006]) == 900000009\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999, 1000001, 1100011, 1200021, 1300031, 1400041, 1500051]) == 5389047\n assert candidate(nums = [101010101, 202020202, 303030303, 404040404, 505050505, 606060606, 707070707, 808080808, 909090909]) == 2020202020\n assert candidate(nums = [999, 1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 24026\n assert candidate(nums = [10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001]) == 0\n assert candidate(nums = [12321, 23432, 34543, 45654, 56765, 67876, 78987]) == 133332\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 222, 333, 444, 555, 666, 777, 888, 999, 1001, 1111]) == 5292\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 2222222220\n assert candidate(nums = [121, 131, 141, 151, 161, 171, 181, 191, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292, 303]) == 909\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543, 98765432]) == 2654323455\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990]) == 45\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 1000000000]) == 2666666665\n assert candidate(nums = [123, 321, 231, 132, 312, 213, 456, 654, 564, 465]) == 1449\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 11001]) == 26016\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 10101]) == 10979\n assert candidate(nums = [99999999, 88888888, 77777777, 66666666, 55555555, 44444444, 33333333, 22222222, 11111111, 10101010]) == 267676765\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1001, 2002, 3003, 4004, 5005]) == 13794\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 2666666665\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[10,12,13,14,15]", "[22,33,22,33,22]"], "hints": ["Find the median of nums after sorting it (if the length is even, we can select any number from the two in the middle). Let’s call it m.", "Try the smallest palindromic number that is larger than or equal to m (if any) and the largest palindromic number that is smaller than or equal to m (if any). These two values are the candidate palindromic numbers for values of all indices.", "We can use math constructions to construct the two palindromic numbers in O(log(m) / 2) time or we can do it using brute-force by starting from m and checking smaller and larger values in O(sqrt(10^{log(m)})).", "It is also possible to just generate all palindromic numbers using recursion in O(sqrt(10^9log(10^9))."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:48+00:00", "tests_total": 117, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "binary-search", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(nums)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2968, "task_id": "apply-operations-to-maximize-frequency-score", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums and an integer k.\n\nYou can perform the following operation on the array at most k times:\n\n- Choose any index i from the array and increase or decrease nums[i] by 1.\n\nThe score of the final array is the frequency of the most frequent element in the array.\n\nReturn the maximum score you can achieve.\n\nThe frequency of an element is the number of occurences of that element in the array.\n\nExample 1:\n\nInput: nums = [1,2,6,4], k = 3\nOutput: 3\nExplanation: We can do the following operations on the array:\n- Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4].\n- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3].\n- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2].\nThe element 2 is the most frequent in the final array so our score is 3.\nIt can be shown that we cannot achieve a better score.\n\nExample 2:\n\nInput: nums = [1,4,4,2,4], k = 0\nOutput: 3\nExplanation: We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 0 <= k <= 10^14\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],k = 1000000000000) == 1\n assert candidate(nums = [1, 3, 3, 3, 7, 8, 9],k = 4) == 4\n assert candidate(nums = [1, 3, 5, 7, 9],k = 10) == 4\n assert candidate(nums = [1, 4, 4, 2, 4],k = 0) == 3\n assert candidate(nums = [5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [1, 1000000000],k = 1000000000) == 2\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 1000000000) == 3\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3],k = 4) == 7\n assert candidate(nums = [1, 2, 3],k = 2) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 10\n assert candidate(nums = [1, 2, 6, 4],k = 3) == 3\n assert candidate(nums = [1, 1000000000, 1, 1000000000],k = 1000000000) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],k = 10) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 0) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 7\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 0) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 9\n assert candidate(nums = [1, 2, 3, 4, 5],k = 10) == 5\n assert candidate(nums = [1, 1000000000],k = 500000000) == 1\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 0) == 10\n assert candidate(nums = [1000000000, 1, 1000000000, 1],k = 1000000000) == 3\n assert candidate(nums = [1, 3, 5, 7, 9],k = 25) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4],k = 5) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 50) == 15\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],k = 250) == 10\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 = 1000) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 150) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 25) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 100) == 14\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 20) == 15\n assert candidate(nums = [5, 5, 5, 10, 10, 15, 15, 15, 20, 20, 25],k = 30) == 8\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5],k = 5) == 8\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],k = 20) == 20\n assert candidate(nums = [1, 2, 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],k = 50) == 32\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 = 0) == 20\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 20) == 15\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],k = 100) == 21\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 1000) == 91\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 6\n assert candidate(nums = [1, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5],k = 20) == 11\n assert candidate(nums = [10, 10, 10, 20, 20, 30, 30, 30, 40, 40, 40, 50, 50, 50, 50],k = 200) == 15\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],k = 25) == 17\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 30) == 15\n assert candidate(nums = [1, 1000000000, 1000000000, 1000000000, 1],k = 1000000000) == 4\n assert candidate(nums = [1, 3, 3, 3, 3, 5, 5, 7, 9, 9, 11, 11, 13, 13, 15],k = 30) == 11\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 = 500) == 20\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5],k = 15) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 500) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],k = 10) == 15\n assert candidate(nums = [1, 1000000000, 2, 999999998, 3, 999999996, 4, 999999994],k = 1000000000) == 5\n assert candidate(nums = [1, 3, 3, 5, 5, 5, 7, 9, 11, 11],k = 15) == 8\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],k = 50) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],k = 15) == 14\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 = 1000) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000) == 10\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 10000) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 50) == 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],k = 50) == 20\n assert candidate(nums = [1, 1000000000, 500000000, 750000000, 250000000],k = 100000000000) == 5\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 = 100) == 20\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 0) == 15\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 = 1000) == 20\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 = 150) == 20\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 = 0) == 20\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6],k = 30) == 24\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],k = 100) == 9\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 0) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 30) == 15\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 0) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 50) == 10\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 = 500) == 20\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\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],k = 100) == 36\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 25) == 23\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8],k = 50) == 30\n assert candidate(nums = [1, 2, 6, 4, 8, 10, 3, 5, 7, 9],k = 15) == 7\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, 7, 7, 7, 8, 8, 8, 9, 9, 10],k = 50) == 29\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],k = 100) == 30\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 0) == 15\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 10000000000) == 6\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000000) == 10\n assert candidate(nums = [1, 1000000000],k = 1000000000) == 2\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],k = 100) == 21\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],k = 10) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 100) == 15\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000],k = 1500000000) == 4\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3],k = 5) == 9\n assert candidate(nums = [5, 5, 5, 1, 1, 1, 1, 1, 1, 1],k = 10) == 9\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000) == 5\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],k = 100000000000) == 4\n", "comparison": "exact"}, "public_tests": ["[1,2,6,4]\n3", "[1,4,4,2,4]\n0"], "hints": ["If you sort the original array, it is optimal to apply the operations on one subarray such that all the elements of that subarray become equal.", "You can use binary search to find the longest subarray where we can make the elements equal in at most k operations."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxFrequencyScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:51+00:00", "tests_total": 96, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "sliding-window", "sorting", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def max_frequency_score(nums, k)", "container": null, "callable": "max_frequency_score", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2970, "task_id": "count-the-number-of-incremovable-subarrays-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array of positive integers nums.\n\nA subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\n\nReturn the total number of incremovable subarrays of nums.\n\nNote that an empty array is considered strictly increasing.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 10\nExplanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n\nExample 2:\n\nInput: nums = [6,5,7,8]\nOutput: 7\nExplanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\nIt can be shown that there are only 7 incremovable subarrays in nums.\n\nExample 3:\n\nInput: nums = [8,7,6,6]\nOutput: 3\nExplanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [6, 5, 7, 8]) == 7\n assert candidate(nums = [1, 3, 2, 4, 5]) == 11\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 4]) == 11\n assert candidate(nums = [1, 2, 2, 3]) == 8\n assert candidate(nums = [1, 2, 3, 4]) == 10\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7]) == 19\n assert candidate(nums = [10, 20, 15, 25, 30]) == 11\n assert candidate(nums = [1, 2, 3, 2, 3, 4]) == 13\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 3]) == 8\n assert candidate(nums = [8, 7, 6, 6]) == 3\n assert candidate(nums = [1, 2, 3, 3, 4]) == 11\n assert candidate(nums = [10, 20, 15, 30, 25, 40]) == 9\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 8, 9, 10]) == 22\n assert candidate(nums = [5, 3, 4, 6, 7, 2, 3, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 17\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10]) == 22\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 25\n assert candidate(nums = [3, 5, 2, 8, 7, 10, 9, 11, 13, 12]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9]) == 26\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 12\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7]) == 9\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 9]) == 29\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, 7, 8, 9, 10]) == 71\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [5, 10, 15, 20, 18, 25, 30, 35, 40]) == 29\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1]) == 13\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == 11\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]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 14, 16, 18, 20, 19, 21, 23, 25, 24, 26, 28, 30]) == 45\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12]) == 6\n assert candidate(nums = [3, 1, 2, 1, 3, 4, 5, 6, 7]) == 12\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 10]) == 12\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 11\n assert candidate(nums = [1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 9\n assert candidate(nums = [1, 5, 3, 7, 9, 2, 11, 13, 12, 14]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 6, 7, 8, 9, 10, 11]) == 46\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 26\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 51\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 12\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13]) == 9\n assert candidate(nums = [30, 20, 10, 20, 30, 40, 30, 20, 10]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 55\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 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]) == 4\n assert candidate(nums = [5, 6, 2, 7, 8, 10]) == 13\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6]) == 9\n assert candidate(nums = [3, 5, 6, 7, 8, 2, 3, 4, 5, 6]) == 15\n assert candidate(nums = [1, 2, 3, 6, 5, 4, 7, 8, 9, 10]) == 29\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 10, 20, 30]) == 9\n assert candidate(nums = [3, 4, 3, 5, 6, 7, 8, 9, 10, 11, 12]) == 28\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 10, 9, 11]) == 15\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 6]) == 22\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 30, 45]) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2]) == 3\n assert candidate(nums = [10, 20, 30, 25, 40, 50, 15, 25, 35, 45]) == 17\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 38, 45]) == 12\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 38\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 6, 7, 8, 9, 10, 11]) == 43\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 4\n assert candidate(nums = [1, 3, 5, 4, 6, 7, 8, 9]) == 23\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 17\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4]) == 10\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 41\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == 3\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10]) == 38\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 7, 8, 9]) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 9]) == 42\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 21]) == 5\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 5, 7, 8, 7, 9]) == 9\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 9\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 21\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 7, 8, 9, 10]) == 29\n assert candidate(nums = [5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 81\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 7\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 35, 50]) == 9\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 92\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [1, 2, 3, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9]) == 11\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10]) == 28\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 5, 8, 9, 7, 10, 11, 8]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 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]) == 36\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 10, 12, 14, 16]) == 34\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5]) == 18\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5]) == 18\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 26\n assert candidate(nums = [1, 3, 5, 7, 9, 10, 8, 11, 12]) == 26\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 4, 5, 6, 7]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2]) == 9\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 29\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 4, 5]) == 18\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1]) == 7\n assert candidate(nums = [8, 9, 7, 10, 11, 12, 13, 6]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[6,5,7,8]", "[8,7,6,6]"], "hints": ["Use two loops to check all the subarrays."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().incremovableSubarrayCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:56+00:00", "tests_total": 123, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def incremovable_subarray_count(nums)", "container": null, "callable": "incremovable_subarray_count", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2971, "task_id": "find-polygon-with-the-largest-perimeter", "difficulty": "Medium", "problem_description": "You are given an array of positive integers nums of length n.\n\nA polygon is a closed plane figure that has at least 3 sides. The longest side of a polygon is smaller than the sum of its other sides.\n\nConversely, if you have k (k >= 3) positive real numbers a_1, a_2, a_3, ..., a_k where a_1 <= a_2 <= a_3 <= ... <= a_k and a_1 + a_2 + a_3 + ... + a_{k-1} > a_k, then there always exists a polygon with k sides whose lengths are a_1, a_2, a_3, ..., a_k.\n\nThe perimeter of a polygon is the sum of lengths of its sides.\n\nReturn the largest possible perimeter of a polygon whose sides can be formed from nums, or -1 if it is not possible to create a polygon.\n\nExample 1:\n\nInput: nums = [5,5,5]\nOutput: 15\nExplanation: The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.\n\nExample 2:\n\nInput: nums = [1,12,1,2,5,50,3]\nOutput: 12\nExplanation: The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12.\nWe cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them.\nIt can be shown that the largest possible perimeter is 12.\n\nExample 3:\n\nInput: nums = [5,5,50]\nOutput: -1\nExplanation: There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 > 5 + 5.\n\nConstraints:\n\n- 3 <= n <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 5, 1, 12, 3, 7]) == 38\n assert candidate(nums = [5, 5, 50]) == -1\n assert candidate(nums = [5, 5, 5]) == 15\n assert candidate(nums = [10, 5, 25, 25, 10]) == 75\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(nums = [3, 6, 2, 3, 5, 4, 1]) == 24\n assert candidate(nums = [3, 6, 2, 3, 5, 10]) == 29\n assert candidate(nums = [10, 20, 30, 40, 50]) == 150\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 30\n assert candidate(nums = [1, 12, 1, 2, 5, 50, 3]) == 12\n assert candidate(nums = [3, 6, 2, 3, 5, 4]) == 23\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [10, 5, 1, 1, 1, 1]) == 4\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]) == 31\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1050\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 5500\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 211\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 21000\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]) == 376\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864]) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(nums = [1000000000, 900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000]) == 5500000000\n assert candidate(nums = [1000000000, 500000000, 300000000, 200000000, 100000000]) == 2100000000\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]) == 84\n assert candidate(nums = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [7, 10, 5, 8, 9, 6, 4, 2, 3, 1]) == 55\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]) == 150\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 1810\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]) == 465\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 42\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]) == 165\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == -1\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]) == 625\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [1, 2, 3, 6, 11, 20, 37, 68, 125, 230]) == 503\n assert candidate(nums = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 21000\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) == 143\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1]) == 3000000001\n assert candidate(nums = [100, 200, 300, 400, 500]) == 1500\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 209\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 275\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 165\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 60\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 225\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]) == 240\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 9999999955\n assert candidate(nums = [3, 6, 2, 3, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 33\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [50, 60, 70, 80, 90, 100, 110]) == 560\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 180\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]) == 465\n assert candidate(nums = [2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) == 247\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 10500\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 110\n assert candidate(nums = [3, 6, 2, 3, 5, 4, 1, 8, 7, 9]) == 48\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 100\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]) == 2325\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == -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, 2]) == 32\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 7000000000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 12000\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == 2100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [1, 1000000000, 1000000000, 1000000000]) == 3000000001\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 209\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 780\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 4999999990\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 1200\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]) == 17710\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 100, 200, 300, 400, 500]) == 1515\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 225\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1050\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 3, 1]) == 159\n assert candidate(nums = [1, 2, 3, 6, 10, 18, 33, 59, 107, 198, 374, 699, 1302, 2441, 4537, 8380, 15619, 29036, 54256, 100901]) == 217982\n assert candidate(nums = [33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33]) == 660\n assert candidate(nums = [7, 10, 5, 8, 6, 9, 3, 4, 2, 1]) == 55\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 1050\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(nums = [1, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 6000000001\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 1000\n assert candidate(nums = [7, 10, 14, 21, 28, 35, 42, 49, 56, 63]) == 325\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 5500\n assert candidate(nums = [1, 3, 2, 4, 5, 9, 7, 8, 6, 10]) == 55\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 1000000000]) == 5500000000\n assert candidate(nums = [1, 1000000000, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n", "comparison": "exact"}, "public_tests": ["[5,5,5]", "[1,12,1,2,5,50,3]", "[5,5,50]"], "hints": ["Sort the array.", "Use greedy algorithm. If we select an edge as the longest side, it is always better to pick up all the edges with length no longer than this longest edge.", "Note that the number of edges should not be less than 3."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().largestPerimeter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:08:58+00:00", "tests_total": 95, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting", "prefix-sum", "polygons"]}, "language": "ruby", "interface": {"raw_signature": "def largest_perimeter(nums)", "container": null, "callable": "largest_perimeter", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2972, "task_id": "count-the-number-of-incremovable-subarrays-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array of positive integers nums.\n\nA subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\n\nReturn the total number of incremovable subarrays of nums.\n\nNote that an empty array is considered strictly increasing.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 10\nExplanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n\nExample 2:\n\nInput: nums = [6,5,7,8]\nOutput: 7\nExplanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\nIt can be shown that there are only 7 incremovable subarrays in nums.\n\nExample 3:\n\nInput: nums = [8,7,6,6]\nOutput: 3\nExplanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 11\n assert candidate(nums = [6, 5, 7, 8]) == 7\n assert candidate(nums = [1, 3, 5, 4, 6, 7, 8]) == 19\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 8, 9, 10]) == 22\n assert candidate(nums = [1, 2, 2, 3]) == 8\n assert candidate(nums = [1, 1, 1, 1]) == 3\n assert candidate(nums = [2, 1]) == 3\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 3, 4]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5]) == 3\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 9, 10]) == 34\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 55\n assert candidate(nums = [1, 3, 2]) == 5\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 9]) == 29\n assert candidate(nums = [1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [10, 20, 15, 25, 30]) == 11\n assert candidate(nums = [8, 7, 6, 6]) == 3\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 15, 25, 35, 45, 55, 60, 65, 70]) == 44\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]) == 1275\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10]) == 12\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]) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 11\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 88\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12]) == 27\n assert candidate(nums = [10, 20, 30, 40, 35, 50, 60, 70, 80, 90, 100]) == 39\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 176\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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, 1, 2, 3, 4, 5]) == 21\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 91\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 32\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, 7, 8, 9, 10]) == 71\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 140\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 6, 7, 8, 9, 10]) == 39\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 21\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]) == 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]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 210\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]) == 41\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 111\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, 25]) == 56\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2]) == 23\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]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2, 3, 4, 5]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 465\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 76\n assert candidate(nums = [1, 2, 3, 4, 5, 100, 3, 4, 5, 6, 7, 8, 9, 10]) == 49\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15]) == 13\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 63\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 37\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]) == 66\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 12\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]) == 820\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14]) == 44\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 19]) == 39\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 69\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3, 4, 5]) == 35\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 21\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 7, 8, 10, 9]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7]) == 38\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 12\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == 22\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 122\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6, 70, 7, 80, 8, 90, 9, 100, 10]) == 3\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4]) == 11\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, 1]) == 42\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 26\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 23\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]) == 12\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, 10, 20, 30, 40, 50]) == 115\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 3, 5, 7, 9, 11]) == 47\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10]) == 12\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 17\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 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]) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15]) == 67\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 3\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]) == 76\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10]) == 56\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == 36\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 10, 9]) == 19\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]) == 496\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 41\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 86\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 6, 7, 8, 9, 10, 11, 12]) == 49\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]) == 325\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 10, 12, 14, 16, 18, 17]) == 12\n assert candidate(nums = [20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58]) == 210\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 82\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 88\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 29\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, 26, 27, 28, 29, 30]) == 86\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 26\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\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]) == 31\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 5, 6, 7, 8, 9, 10]) == 19\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 32\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]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 175\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]) == 27\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, 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]) == 32\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 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]) == 11\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]) == 36\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 66\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]) == 1275\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 121\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 8\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 56\n assert candidate(nums = [5, 7, 9, 10, 6, 8, 11, 12, 13, 14]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 11]) == 31\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 102\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1]) == 17\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 25, 35, 45, 55, 65, 75, 85, 95]) == 116\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10, 12, 13, 15, 14, 16, 17, 19, 18, 20]) == 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, 26, 27, 28, 29, 30, 1]) == 32\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 83\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4]) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 26\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 12\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]) == 22\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]) == 21\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9]) == 23\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[6,5,7,8]", "[8,7,6,6]"], "hints": ["Calculate the largest x such that nums[0..x] is strictly increasing.", "Calculate the smallest y such that nums[y..nums.length-1] is strictly increasing.", "For each i in [0, x], select the smallest j in [y, nums.length - 1]. Then we can keep the prefix with any suffix of [j, nums.length - 1] (including the empty one).", "Note that when i increases, j won’t decrease. Use two-pointers.", "Note that we cannot delete an empty array, but we can delete the whole array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().incremovableSubarrayCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:01+00:00", "tests_total": 153, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search"]}, "language": "ruby", "interface": {"raw_signature": "def incremovable_subarray_count(nums)", "container": null, "callable": "incremovable_subarray_count", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2973, "task_id": "find-number-of-coins-to-place-in-tree-nodes", "difficulty": "Hard", "problem_description": "You are given an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree.\n\nYou are also given a 0-indexed integer array cost of length n, where cost[i] is the cost assigned to the i^th node.\n\nYou need to place some coins on every node of the tree. The number of coins to be placed at node i can be calculated as:\n\n- If size of the subtree of node i is less than 3, place 1 coin.\n- Otherwise, place an amount of coins equal to the maximum product of cost values assigned to 3 distinct nodes in the subtree of node i. If this product is negative, place 0 coins.\n\nReturn an array coin of size n such that coin[i] is the number of coins placed at node i.\n\nExample 1:\n\nInput: edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]\nOutput: [120,1,1,1,1,1]\nExplanation: For node 0 place 6 * 5 * 4 = 120 coins. All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n\nExample 2:\n\nInput: edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]\nOutput: [280,140,32,1,1,1,1,1,1]\nExplanation: The coins placed on each node are:\n- Place 8 * 7 * 5 = 280 coins on node 0.\n- Place 7 * 5 * 4 = 140 coins on node 1.\n- Place 8 * 2 * 2 = 32 coins on node 2.\n- All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n\nExample 3:\n\nInput: edges = [[0,1],[0,2]], cost = [1,2,-2]\nOutput: [0,1,1]\nExplanation: Node 1 and 2 are leaves with subtree of size 1, place 1 coin on each of them. For node 0 the only possible product of cost is 2 * 1 * -2 = -4. Hence place 0 coins on node 0.\n\nConstraints:\n\n- 2 <= n <= 2 * 10^4\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= a_i, b_i < n\n- cost.length == n\n- 1 <= |cost[i]| <= 10^4\n- The input is generated such that edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],cost = [3, 2, 1, -1, -2, -3, -4, -5]) == [60, 40, 6, 0, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [2, 6]],cost = [1, 2, 3, 4, 5, -1, 6]) == [120, 120, 1, 0, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 7]],cost = [1, -2, 3, -4, 5, -6, 7, -8]) == [336, 60, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3]],cost = [1, -2, -3, -4]) == [12, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2]],cost = [1, 2, -2]) == [0, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]],cost = [1, 2, 3, 4, 5, 6]) == [120, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],cost = [1, 2, 3, 4, 5, 6, 7, 8]) == [336, 336, 90, 224, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],cost = [3, 2, -1, 4, -5, 6, -7, 8]) == [280, 280, 30, 0, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8]],cost = [1, 4, 2, 3, 5, 7, 8, -4, 2]) == [280, 140, 32, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 7]],cost = [10, 20, 30, 40, 50, 60, 70, 80]) == [336000, 60000, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [10, 23], [11, 24], [11, 25]],cost = [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]) == [15600, 15600, 4896, 9240, 15600, 1092, 1680, 2448, 3420, 4620, 6072, 7800, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],cost = [100, -100, 200, 300, -300, 400, 500, -500, 600, 700, 800]) == [336000000, 336000000, 40000000, 0, 0, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) == [9240, 2184, 4896, 9240, 660, 1092, 1680, 2448, 3420, 4620, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15]],cost = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16]) == [3120, 2002, 1680, 0, 660, 0, 1680, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],cost = [10000, -9999, 9998, -9997, 9996, -9995, 9994, -9993, 9992, -9991, 9990, -9989, 9988, -9987, 9986]) == [999600030000, 999200189988, 998200869890, 998201009832, 0, 997202469340, 0, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [990, 990, 126, 288, 550, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],cost = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7], [2, 8], [2, 9]],cost = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25]) == [12500, 12500, 0, 6000, 1, 6000, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],cost = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80]) == [336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 0, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12]],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == [1716, 210, 720, 1716, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220]) == [9240000, 2184000, 4896000, 9240000, 660000, 1092000, 1680000, 2448000, 3420000, 4620000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17]],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == [4896, 2184, 4896, 360, 660, 1092, 1680, 2448, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13]],cost = [5, -3, 2, 8, -7, 1, 4, -6, 9, 2, -8, 5, 3, -4]) == [504, 378, 160, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [5, 9], [5, 10]],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [990, 360, 770, 288, 1, 660, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],cost = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11]],cost = [100, 50, 200, -10, -20, 300, 150, -5, -30, 25, 40, 60]) == [9000000, 9000000, 3600000, 7500, 15000, 720000, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],cost = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == [100, 100, 100, 100, 100, 100, 100, 100, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15]],cost = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16]) == [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12], [5, 13], [5, 14], [6, 15], [6, 16], [7, 17], [7, 18], [8, 19], [8, 20], [9, 21], [9, 22], [10, 23], [10, 24]],cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500]) == [13800000000, 4080000000, 7980000000, 13800000000, 780000000, 1260000000, 1904000000, 2736000000, 3780000000, 5060000000, 6600000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],cost = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 0, -1, -2, -4, -8]) == [125000000, 3875000, 116250, 2625, 0, 62, 480, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [10, 23], [11, 24], [11, 25]],cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600]) == [15600000000, 15600000000, 4896000000, 9240000000, 15600000000, 1092000000, 1680000000, 2448000000, 3420000000, 4620000000, 6072000000, 7800000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],cost = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11]) == [880, 880, 0, 288, 0, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23]],cost = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11]],cost = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == [9177, 4845, 6279, 1785, 1, 5313, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],cost = [3, 1, 2, 5, -1, -2, -3, 7, 8, 6, 4]) == [336, 336, 12, 280, 0, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15]],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == [3360, 2184, 1920, 360, 660, 1092, 1680, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15]],cost = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16]) == [3360, 2184, 1920, 360, 0, 1092, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7], [2, 8], [2, 9]],cost = [1, 2, 3, 4, -5, 6, -7, 8, 9, 10]) == [720, 720, 270, 280, 1, 0, 1, 1, 1, 1]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],cost = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20, 21]) == [7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 0, 1, 1]\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,2],[0,3],[0,4],[0,5]]\n[1,2,3,4,5,6]", "[[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]]\n[1,4,2,3,5,7,8,-4,2]", "[[0,1],[0,2]]\n[1,2,-2]"], "hints": ["Use DFS on the whole tree, for each subtree, save the largest three positive costs and the smallest three non-positive costs. This can be done by using two Heaps with the size of at most three.", "You need to store at most six values at each subtree.", "If there are more than three values in total, we can sort them. Let’s call the resultant array A, the maximum product of three is max(A[0] * A[1] * A[n - 1], A[n - 1] * A[n - 2] * A[n - 3]). Don’t forget to set the result to 0 if the value is negative.", "If there are less than three values for a subtree, set its result to 1."], "metadata": {"canonical_parameter_names": ["edges", "cost"], "leetcode_dataset_entry_point": "Solution().placedCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:04+00:00", "tests_total": 47, "tests_dropped": 6, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "tree", "depth-first-search", "sorting", "heap-priority-queue", "dp-on-trees"]}, "language": "ruby", "interface": {"raw_signature": "def placed_coins(edges, cost)", "container": null, "callable": "placed_coins", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "cost", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2974, "task_id": "minimum-number-game", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:\n\n- Every round, first Alice will remove the minimum element from nums, and then Bob does the same.\n- Now, first Bob will append the removed element in the array arr, and then Alice does the same.\n- The game continues until nums becomes empty.\n\nReturn the resulting array arr.\n\nExample 1:\n\nInput: nums = [5,4,2,3]\nOutput: [3,2,5,4]\nExplanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].\nAt the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].\n\nExample 2:\n\nInput: nums = [2,5]\nOutput: [5,2]\nExplanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n- nums.length % 2 == 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [90, 100, 80, 70, 60, 50]) == [60, 50, 80, 70, 100, 90]\n assert candidate(nums = [100, 1, 99, 2, 98, 3]) == [2, 1, 98, 3, 100, 99]\n assert candidate(nums = [6, 2, 8, 4]) == [4, 2, 8, 6]\n assert candidate(nums = [10, 1, 3, 8, 7, 2]) == [2, 1, 7, 3, 10, 8]\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == [2, 1, 4, 3, 6, 5]\n assert candidate(nums = [10, 9, 8, 7, 6, 5]) == [6, 5, 8, 7, 10, 9]\n assert candidate(nums = [5, 4, 2, 3]) == [3, 2, 5, 4]\n assert candidate(nums = [4, 3, 2, 1, 6, 5]) == [2, 1, 4, 3, 6, 5]\n assert candidate(nums = [100, 1, 99, 2]) == [2, 1, 100, 99]\n assert candidate(nums = [2, 5]) == [5, 2]\n assert candidate(nums = [6, 4, 3, 2]) == [3, 2, 6, 4]\n assert candidate(nums = [1, 3, 2, 4]) == [2, 1, 4, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [50, 40, 30, 20, 10, 1, 2, 3, 4, 5]) == [2, 1, 4, 3, 10, 5, 30, 20, 50, 40]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56]) == [14, 7, 28, 21, 42, 35, 56, 49]\n assert candidate(nums = [41, 39, 37, 35, 33, 31, 29, 27]) == [29, 27, 33, 31, 37, 35, 41, 39]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\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]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30, 29, 32, 31, 34, 33, 36, 35, 38, 37, 40, 39, 42, 41, 44, 43, 46, 45, 48, 47, 50, 49]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == [92, 91, 94, 93, 96, 95, 98, 97, 100, 99]\n assert candidate(nums = [60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == [42, 41, 44, 43, 46, 45, 48, 47, 50, 49, 52, 51, 54, 53, 56, 55, 58, 57, 60, 59]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, 9]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]\n assert candidate(nums = [42, 31, 25, 14, 19, 28, 37, 46, 5, 13]) == [13, 5, 19, 14, 28, 25, 37, 31, 46, 42]\n assert candidate(nums = [45, 67, 23, 89, 34, 12, 6, 8, 33, 55]) == [8, 6, 23, 12, 34, 33, 55, 45, 89, 67]\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]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30, 29]\n assert candidate(nums = [23, 17, 5, 19, 11, 3, 29, 21, 7, 13, 25, 15]) == [5, 3, 11, 7, 15, 13, 19, 17, 23, 21, 29, 25]\n assert candidate(nums = [50, 20, 40, 30, 10, 60, 70, 80]) == [20, 10, 40, 30, 60, 50, 80, 70]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6]) == [7, 6, 9, 8, 11, 10, 13, 12, 15, 14]\n assert candidate(nums = [50, 25, 75, 5, 100, 2, 70, 10, 80, 30, 60, 40]) == [5, 2, 25, 10, 40, 30, 60, 50, 75, 70, 100, 80]\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == [22, 21, 24, 23, 26, 25, 28, 27, 30, 29, 32, 31]\n assert candidate(nums = [8, 6, 4, 2, 10, 12, 14, 16]) == [4, 2, 8, 6, 12, 10, 16, 14]\n assert candidate(nums = [8, 6, 10, 12, 4, 2, 14, 16]) == [4, 2, 8, 6, 12, 10, 16, 14]\n assert candidate(nums = [33, 32, 31, 30, 29, 28, 27, 26]) == [27, 26, 29, 28, 31, 30, 33, 32]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(nums = [1, 100, 50, 51, 99, 2, 49, 52, 48, 53]) == [2, 1, 49, 48, 51, 50, 53, 52, 100, 99]\n assert candidate(nums = [50, 25, 75, 100, 2, 52, 77, 74, 51, 76, 53, 78, 54, 79, 55, 80, 56, 81, 57, 82]) == [25, 2, 51, 50, 53, 52, 55, 54, 57, 56, 75, 74, 77, 76, 79, 78, 81, 80, 100, 82]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40]) == [10, 5, 20, 15, 30, 25, 40, 35]\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 92, 91, 94, 93, 96, 95, 98, 97, 100, 99]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4]) == [2, 1, 4, 3, 98, 97, 100, 99]\n assert candidate(nums = [9, 1, 6, 8, 3, 7, 4, 5]) == [3, 1, 5, 4, 7, 6, 9, 8]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == [92, 91, 94, 93, 96, 95, 98, 97, 100, 99]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == [32, 31, 34, 33, 36, 35, 38, 37, 40, 39, 42, 41, 44, 43, 46, 45, 48, 47, 50, 49]\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15]) == [16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30, 29]\n assert candidate(nums = [50, 20, 10, 30, 40, 60]) == [20, 10, 40, 30, 60, 50]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]\n assert candidate(nums = [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95]) == [81, 80, 83, 82, 85, 84, 87, 86, 89, 88, 91, 90, 93, 92, 95, 94]\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43]) == [44, 43, 46, 45, 48, 47, 50, 49]\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]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30, 29]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == [4, 2, 8, 6, 12, 10, 16, 14, 20, 18]\n assert candidate(nums = [3, 3, 2, 2, 1, 1, 6, 6, 5, 5, 4, 4]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 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]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [50, 40, 30, 20, 10, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60]) == [10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 80, 70, 100, 90]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 92, 91, 94, 93, 96, 95, 98, 97, 100, 99]\n assert candidate(nums = [30, 25, 22, 20, 21, 23, 24, 26]) == [21, 20, 23, 22, 25, 24, 30, 26]\n assert candidate(nums = [50, 50, 40, 40, 30, 30, 20, 20, 10, 10]) == [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]\n assert candidate(nums = [45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26]) == [27, 26, 29, 28, 31, 30, 33, 32, 35, 34, 37, 36, 39, 38, 41, 40, 43, 42, 45, 44]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, 9]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6]) == [2, 1, 4, 3, 6, 5, 96, 95, 98, 97, 100, 99]\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [6, 1, 9, 4, 3, 8, 7, 2]) == [2, 1, 4, 3, 7, 6, 9, 8]\n assert candidate(nums = [23, 45, 67, 12, 34, 56, 78, 89, 90, 10]) == [12, 10, 34, 23, 56, 45, 78, 67, 90, 89]\n assert candidate(nums = [9, 4, 1, 7, 3, 8, 2, 6, 5, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15]) == [16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30, 29, 32, 31, 34, 33]\n assert candidate(nums = [45, 23, 67, 89, 12, 34, 56, 78]) == [23, 12, 45, 34, 67, 56, 89, 78]\n assert candidate(nums = [34, 12, 78, 56, 32, 89, 21, 67]) == [21, 12, 34, 32, 67, 56, 89, 78]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == [11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == [2, 1, 4, 3, 6, 5]\n assert candidate(nums = [9, 1, 6, 3, 8, 4, 7, 2, 5, 10]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 12, 11, 10, 9, 8, 7]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11]\n assert candidate(nums = [6, 1, 10, 3, 8, 5, 7, 2]) == [2, 1, 5, 3, 7, 6, 10, 8]\n assert candidate(nums = [9, 1, 6, 8, 3, 4, 7, 2]) == [2, 1, 4, 3, 7, 6, 9, 8]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8]) == [2, 1, 4, 3, 6, 5, 8, 7, 94, 93, 96, 95, 98, 97, 100, 99]\n assert candidate(nums = [21, 17, 19, 15, 16, 20, 18, 14]) == [15, 14, 17, 16, 19, 18, 21, 20]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == [4, 2, 8, 6, 12, 10, 16, 14, 20, 18, 24, 22]\n assert candidate(nums = [15, 10, 20, 5, 18, 13, 12, 8]) == [8, 5, 12, 10, 15, 13, 20, 18]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25, 28, 27, 30, 29]\n assert candidate(nums = [20, 15, 30, 10, 25, 5, 35, 50, 40, 45]) == [10, 5, 20, 15, 30, 25, 40, 35, 50, 45]\n assert candidate(nums = [50, 25, 75, 100, 12, 88, 63, 45, 37, 71, 19, 94]) == [19, 12, 37, 25, 50, 45, 71, 63, 88, 75, 100, 94]\n assert candidate(nums = [33, 66, 99, 22, 55, 88, 11, 44, 77, 100]) == [22, 11, 44, 33, 66, 55, 88, 77, 100, 99]\n", "comparison": "exact"}, "public_tests": ["[5,4,2,3]", "[2,5]"], "hints": ["Sort the array in increasing order and then swap the adjacent elements."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().numberGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:07+00:00", "tests_total": 91, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "sorting", "heap-priority-queue", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def number_game(nums)", "container": null, "callable": "number_game", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2975, "task_id": "maximum-square-area-by-removing-fences-from-a-field", "difficulty": "Medium", "problem_description": "There is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.\n\nHorizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).\n\nReturn the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.\n\nSince the answer may be large, return it modulo 10^9+ 7.\n\nNote: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.\n\nExample 1:\n\nInput: m = 4, n = 3, hFences = [2,3], vFences = [2]\nOutput: 4\nExplanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.\n\nExample 2:\n\nInput: m = 6, n = 7, hFences = [2], vFences = [4]\nOutput: -1\nExplanation: It can be proved that there is no way to create a square field by removing fences.\n\nConstraints:\n\n- 3 <= m, n <= 10^9\n- 1 <= hFences.length, vFences.length <= 600\n- 1 < hFences[i] < m\n- 1 < vFences[i] < n\n- hFences and vFences are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 4,n = 3,hFences = [2, 3],vFences = [2]) == 4\n assert candidate(m = 10,n = 10,hFences = [3, 7],vFences = [2, 8]) == 81\n assert candidate(m = 15,n = 12,hFences = [5, 10],vFences = [4, 8]) == 16\n assert candidate(m = 50,n = 50,hFences = [10, 20, 30],vFences = [10, 20, 30]) == 2401\n assert candidate(m = 20,n = 15,hFences = [4, 12],vFences = [5, 10]) == -1\n assert candidate(m = 10,n = 10,hFences = [3, 7],vFences = [3, 7]) == 81\n assert candidate(m = 8,n = 5,hFences = [2, 6],vFences = [2]) == 16\n assert candidate(m = 15,n = 15,hFences = [4, 6, 10],vFences = [4, 6, 10]) == 196\n assert candidate(m = 7,n = 8,hFences = [3],vFences = [3, 5]) == 16\n assert candidate(m = 9,n = 5,hFences = [2, 5, 8],vFences = [2, 3]) == 16\n assert candidate(m = 100,n = 100,hFences = [20, 40, 60, 80],vFences = [20, 40, 60, 80]) == 9801\n assert candidate(m = 12,n = 12,hFences = [3, 9],vFences = [3, 9]) == 121\n assert candidate(m = 9,n = 9,hFences = [5],vFences = [5]) == 64\n assert candidate(m = 15,n = 12,hFences = [5, 10],vFences = [3, 9]) == 81\n assert candidate(m = 8,n = 5,hFences = [2, 5],vFences = [2, 3]) == 16\n assert candidate(m = 6,n = 7,hFences = [2],vFences = [4]) == -1\n assert candidate(m = 1000000000,n = 1000000000,hFences = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000],vFences = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000]) == 64\n assert candidate(m = 100,n = 100,hFences = [20, 30, 40, 50],vFences = [15, 25, 35, 45]) == 9801\n assert candidate(m = 999999999,n = 999999999,hFences = [333333333, 666666666],vFences = [333333333, 666666666]) == 81\n assert candidate(m = 1000,n = 1000,hFences = [250, 500, 750],vFences = [250, 500, 750]) == 998001\n assert candidate(m = 200,n = 200,hFences = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],vFences = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]) == 39601\n assert candidate(m = 500,n = 500,hFences = [50, 150, 250, 350, 450],vFences = [75, 125, 175, 225, 275, 325, 375, 425, 475]) == 249001\n assert candidate(m = 8,n = 12,hFences = [2, 4, 6, 7],vFences = [3, 5, 9, 11]) == 49\n assert candidate(m = 100,n = 100,hFences = [10, 20, 30, 40, 50],vFences = [15, 25, 35, 45, 55]) == 9801\n assert candidate(m = 800,n = 600,hFences = [100, 300, 500, 700],vFences = [120, 240, 360, 480]) == -1\n assert candidate(m = 10000,n = 10000,hFences = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000],vFences = [500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 8500, 9500]) == 99980001\n assert candidate(m = 1000000000,n = 1000000000,hFences = [100000, 200000, 300000],vFences = [150000, 250000, 350000]) == 64\n assert candidate(m = 1200,n = 800,hFences = [240, 480, 720, 960],vFences = [160, 320, 480, 640]) == 230400\n assert candidate(m = 3000,n = 2000,hFences = [750, 1500, 2250],vFences = [500, 1000, 1500]) == 2250000\n assert candidate(m = 50,n = 30,hFences = [5, 10, 15, 20, 25, 30, 35, 40, 45],vFences = [3, 6, 9, 12, 15, 18, 21, 24, 27]) == 841\n assert candidate(m = 999,n = 999,hFences = [100, 200, 300, 400, 500, 600, 700, 800, 900],vFences = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 996004\n assert candidate(m = 1200,n = 900,hFences = [150, 300, 450, 600, 750, 900],vFences = [200, 400, 600, 800]) == 808201\n assert candidate(m = 2000,n = 3000,hFences = [500, 1000, 1500],vFences = [750, 1500, 2250]) == 2250000\n assert candidate(m = 1000,n = 1000,hFences = [150, 350, 550, 750, 950],vFences = [150, 350, 550, 750, 950]) == 998001\n assert candidate(m = 150,n = 150,hFences = [10, 20, 30, 40, 50],vFences = [15, 30, 45, 60, 75]) == 22201\n assert candidate(m = 10,n = 20,hFences = [2, 3, 5, 7],vFences = [4, 8, 12, 16]) == 64\n assert candidate(m = 1000,n = 1000,hFences = [200, 300, 400, 500, 600, 700, 800, 900],vFences = [100, 200, 300, 400, 500, 600, 700, 800]) == 998001\n assert candidate(m = 600,n = 400,hFences = [100, 200, 300, 400, 500],vFences = [150, 250, 350]) == 159201\n assert candidate(m = 1000000,n = 1000000,hFences = [100000, 200000, 300000, 400000, 500000],vFences = [100000, 200000, 300000, 400000, 500000]) == 997993008\n assert candidate(m = 750,n = 1000,hFences = [10, 20, 30, 40, 50, 60, 70, 80, 90],vFences = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 7921\n assert candidate(m = 20,n = 15,hFences = [3, 6, 12, 18],vFences = [4, 8, 14]) == 196\n assert candidate(m = 5000,n = 5000,hFences = [1000, 2000, 3000, 4000],vFences = [1200, 2200, 3200, 4200]) == 24990001\n assert candidate(m = 10000,n = 10000,hFences = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000],vFences = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == 99980001\n assert candidate(m = 999,n = 999,hFences = [100, 200, 300, 400, 500, 600, 700, 800],vFences = [100, 200, 300, 400, 500, 600, 700, 800]) == 996004\n assert candidate(m = 800,n = 600,hFences = [50, 100, 150, 200, 250],vFences = [75, 125, 175, 225, 275]) == 40000\n assert candidate(m = 200,n = 150,hFences = [50, 100, 150],vFences = [30, 60, 90, 120]) == 22201\n assert candidate(m = 1000,n = 1000,hFences = [200, 400, 600, 800],vFences = [250, 500, 750]) == 998001\n assert candidate(m = 500,n = 300,hFences = [100, 200, 300, 400],vFences = [50, 150, 250, 290]) == 89401\n assert candidate(m = 2000,n = 3000,hFences = [200, 600, 1000, 1400, 1800],vFences = [300, 900, 1500, 2100, 2700]) == 3240000\n assert candidate(m = 999,n = 999,hFences = [333, 666],vFences = [333, 666]) == 996004\n assert candidate(m = 123456789,n = 987654321,hFences = [12345678, 24691356, 37037034],vFences = [9876543, 19753086, 29629629]) == -1\n assert candidate(m = 1000,n = 1000,hFences = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950],vFences = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 998001\n assert candidate(m = 500,n = 500,hFences = [100, 150, 200, 250, 300],vFences = [50, 100, 150, 200, 250]) == 249001\n assert candidate(m = 800,n = 900,hFences = [50, 150, 250, 350, 450],vFences = [60, 160, 260, 360, 460]) == 160000\n assert candidate(m = 700,n = 500,hFences = [70, 140, 210, 280, 350, 420, 490, 560, 630],vFences = [50, 100, 150, 200, 250, 300, 350, 400, 450]) == 122500\n assert candidate(m = 1000000000,n = 1000000000,hFences = [200, 300, 400],vFences = [200, 300, 400]) == 64\n assert candidate(m = 500,n = 500,hFences = [100, 200, 300, 400],vFences = [100, 200, 300, 400]) == 249001\n assert candidate(m = 500000000,n = 500000000,hFences = [250000000],vFences = [250000000]) == 250000022\n assert candidate(m = 100,n = 100,hFences = [10, 30, 50, 70, 90],vFences = [10, 30, 50, 70, 90]) == 9801\n assert candidate(m = 123456789,n = 987654321,hFences = [12345678, 24691356, 37037034, 49382712, 61728390, 74074068, 86419746, 98765424],vFences = [9876543, 19753086, 29629629, 39506172, 49382715, 59259258, 69135801, 79012344, 88888887]) == -1\n assert candidate(m = 100,n = 100,hFences = [15, 25, 35, 45, 55, 65, 75, 85, 95],vFences = [15, 25, 35, 45, 55, 65, 75, 85, 95]) == 9801\n assert candidate(m = 100,n = 100,hFences = [10, 20, 30, 40, 50, 60, 70, 80, 90],vFences = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 9801\n assert candidate(m = 123456,n = 654321,hFences = [23456, 45678, 67890],vFences = [34567, 56789, 78901]) == 493817284\n assert candidate(m = 800,n = 400,hFences = [100, 300, 500, 700],vFences = [100, 200, 300]) == 90000\n assert candidate(m = 100,n = 100,hFences = [20, 40, 60, 80],vFences = [20, 40, 60, 80]) == 9801\n assert candidate(m = 999999999,n = 999999999,hFences = [100000001, 200000001, 300000001, 400000001, 500000001],vFences = [100000002, 200000002, 300000002, 400000002, 500000002]) == 81\n assert candidate(m = 1000000000,n = 1000000000,hFences = [500000000],vFences = [500000000]) == 64\n assert candidate(m = 1000,n = 1000,hFences = [200, 300, 400, 500, 600, 700, 800, 900],vFences = [150, 250, 350, 450, 550, 650, 750, 850]) == 998001\n assert candidate(m = 100,n = 200,hFences = [10, 20, 30, 40],vFences = [15, 25, 35, 45]) == 900\n assert candidate(m = 500,n = 500,hFences = [25, 50, 75, 100, 125, 150, 175, 200],vFences = [25, 50, 75, 100, 125, 150, 175, 200]) == 249001\n assert candidate(m = 500,n = 600,hFences = [150, 250, 350],vFences = [200, 300, 400, 500]) == 249001\n assert candidate(m = 120,n = 120,hFences = [24, 48, 72, 96],vFences = [24, 48, 72, 96]) == 14161\n assert candidate(m = 80,n = 80,hFences = [20, 40, 60],vFences = [20, 40, 60]) == 6241\n assert candidate(m = 20,n = 20,hFences = [4, 8, 12, 16],vFences = [4, 8, 12, 16]) == 361\n assert candidate(m = 20,n = 20,hFences = [4, 8, 12, 16],vFences = [5, 10, 15]) == 361\n assert candidate(m = 100,n = 100,hFences = [20, 40, 60, 80],vFences = [25, 50, 75]) == 9801\n assert candidate(m = 897,n = 789,hFences = [123, 234, 345, 456, 567, 678, 789],vFences = [87, 174, 261, 348, 435, 522, 609]) == 620944\n assert candidate(m = 99,n = 99,hFences = [33, 66],vFences = [33, 66]) == 9604\n assert candidate(m = 500,n = 500,hFences = [100, 200, 300],vFences = [150, 250, 350]) == 249001\n assert candidate(m = 100,n = 100,hFences = [20, 30, 40, 50, 60, 70, 80, 90],vFences = [15, 25, 35, 45, 55, 65, 75, 85, 95]) == 9801\n assert candidate(m = 20,n = 20,hFences = [3, 7, 13, 17],vFences = [4, 8, 12, 16]) == 361\n assert candidate(m = 777,n = 777,hFences = [259, 518],vFences = [259, 518]) == 602176\n assert candidate(m = 50,n = 50,hFences = [10, 20, 30, 40],vFences = [10, 20, 30, 40]) == 2401\n assert candidate(m = 1024,n = 1024,hFences = [256, 512, 768],vFences = [256, 512, 768]) == 1046529\n assert candidate(m = 1000,n = 1000,hFences = [100, 200, 300, 400, 500, 600, 700, 800, 900],vFences = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 998001\n assert candidate(m = 1000,n = 1000,hFences = [100, 200, 300, 400, 500, 600, 700, 800, 900],vFences = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 998001\n assert candidate(m = 500000000,n = 500000000,hFences = [50000000, 100000000, 150000000, 200000000, 250000000, 300000000, 350000000, 400000000, 450000000, 499999990],vFences = [50000000, 100000000, 150000000, 200000000, 250000000, 300000000, 350000000, 400000000, 450000000, 499999990]) == 250000022\n assert candidate(m = 75,n = 60,hFences = [15, 30, 45],vFences = [10, 20, 30, 40]) == 900\n assert candidate(m = 20,n = 15,hFences = [3, 7, 12],vFences = [4, 8, 11]) == 121\n assert candidate(m = 50,n = 40,hFences = [10, 20, 30, 40],vFences = [5, 15, 25, 35]) == 1521\n", "comparison": "exact"}, "public_tests": ["4\n3\n[2,3]\n[2]", "6\n7\n[2]\n[4]"], "hints": ["Put 1 and m into hFences. The differences of any two values in the new hFences can be a horizontal edge of a rectangle.", "Similarly put 1 and n into vFences. The differences of any two values in the new vFences can be a vertical edge of a rectangle.", "Our goal is to find the maximum common value in both parts."], "metadata": {"canonical_parameter_names": ["m", "n", "hFences", "vFences"], "leetcode_dataset_entry_point": "Solution().maximizeSquareArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:09+00:00", "tests_total": 101, "tests_dropped": 11, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def maximize_square_area(m, n, h_fences, v_fences)", "container": null, "callable": "maximize_square_area", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "h_fences", "type": "Integer[]"}, {"name": "v_fences", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2976, "task_id": "minimum-cost-to-convert-string-i", "difficulty": "Medium", "problem_description": "You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].\n\nYou start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y.\n\nReturn the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\n\nNote that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n\nExample 1:\n\nInput: source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\nOutput: 28\nExplanation: To convert the string \"abcd\" to string \"acbe\":\n- Change value at index 1 from 'b' to 'c' at a cost of 5.\n- Change value at index 2 from 'c' to 'e' at a cost of 1.\n- Change value at index 2 from 'e' to 'b' at a cost of 2.\n- Change value at index 3 from 'd' to 'e' at a cost of 20.\nThe total cost incurred is 5 + 1 + 2 + 20 = 28.\nIt can be shown that this is the minimum possible cost.\n\nExample 2:\n\nInput: source = \"aaaa\", target = \"bbbb\", original = [\"a\",\"c\"], changed = [\"c\",\"b\"], cost = [1,2]\nOutput: 12\nExplanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.\n\nExample 3:\n\nInput: source = \"abcd\", target = \"abce\", original = [\"a\"], changed = [\"e\"], cost = [10000]\nOutput: -1\nExplanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.\n\nConstraints:\n\n- 1 <= source.length == target.length <= 10^5\n- source, target consist of lowercase English letters.\n- 1 <= cost.length == original.length == changed.length <= 2000\n- original[i], changed[i] are lowercase English letters.\n- 1 <= cost[i] <= 10^6\n- original[i] != changed[i]\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(source = \"abcd\",target = \"abce\",original = ['a'],changed = ['e'],cost = [10000]) == -1\n assert candidate(source = \"aaaa\",target = \"bbbb\",original = ['a', 'c'],changed = ['c', 'b'],cost = [1, 2]) == 12\n assert candidate(source = \"abc\",target = \"def\",original = ['a', 'b', 'c'],changed = ['d', 'e', 'f'],cost = [1, 1, 1]) == 3\n assert candidate(source = \"abcd\",target = \"acbe\",original = ['a', 'b', 'c', 'c', 'e', 'd'],changed = ['b', 'c', 'b', 'e', 'b', 'e'],cost = [2, 5, 5, 1, 2, 20]) == 28\n assert candidate(source = \"zzz\",target = \"aaa\",original = ['z', 'z', 'z'],changed = ['a', 'b', 'a'],cost = [2, 3, 1]) == 3\n assert candidate(source = \"hello\",target = \"ohell\",original = ['h', 'e', 'l', 'o'],changed = ['o', 'l', 'e', 'h'],cost = [10, 20, 30, 40]) == -1\n assert candidate(source = \"aaaaabbbbbcccc\",target = \"bbbbbccccddddd\",original = ['a', 'b', 'c', 'd'],changed = ['b', 'c', 'd', 'a'],cost = [1, 1, 1, 1]) == 15\n assert candidate(source = \"aaaaaaaaaa\",target = \"bbbbbbbbbb\",original = ['a', 'b'],changed = ['b', 'a'],cost = [1000000, 1000000]) == 10000000\n assert candidate(source = \"abcabcabc\",target = \"defdefdef\",original = ['a', 'b', 'c'],changed = ['d', 'e', 'f'],cost = [100, 200, 300]) == 1800\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"zyxwvutsrqponmlkjihgfedcba\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],changed = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],cost = [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]) == 351\n assert candidate(source = \"abcabcabcabc\",target = \"abcabcabcabc\",original = ['a', 'b', 'c'],changed = ['b', 'c', 'a'],cost = [10, 20, 30]) == 0\n assert candidate(source = \"aaaaaa\",target = \"bbbbbb\",original = ['a', 'a', 'a', 'a', 'a', 'a'],changed = ['b', 'c', 'd', 'e', 'f', 'g'],cost = [1, 10, 100, 1000, 10000, 100000]) == 6\n assert candidate(source = \"aaaaaaaaaa\",target = \"bbbbbbbbbb\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a'],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(source = \"aaabbbccc\",target = \"bbbaaaccb\",original = ['a', 'b', 'c'],changed = ['b', 'a', 'b'],cost = [1, 2, 3]) == 12\n assert candidate(source = \"abcdefghij\",target = \"abcdefghij\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a'],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(source = \"zzzzzzzzzz\",target = \"aaaaaaaaaa\",original = ['z', 'a'],changed = ['a', 'z'],cost = [1000000, 1]) == 10000000\n assert candidate(source = \"abacabadabacaba\",target = \"zyxzyxzyxzyxzyx\",original = ['a', 'b', 'c'],changed = ['z', 'y', 'x'],cost = [1, 2, 3]) == -1\n assert candidate(source = \"abcdabcdabcd\",target = \"dcbaabcddcba\",original = ['a', 'b', 'c', 'd'],changed = ['d', 'c', 'b', 'a'],cost = [1, 2, 3, 4]) == 20\n assert candidate(source = \"conversion\",target = \"converting\",original = ['v', 's', 'i'],changed = ['r', 't', 'n'],cost = [15, 25, 35]) == -1\n assert candidate(source = \"aabbcc\",target = \"bbccdd\",original = ['a', 'b', 'c'],changed = ['b', 'c', 'd'],cost = [1, 1, 1]) == 6\n assert candidate(source = \"abababab\",target = \"babababa\",original = ['a', 'b'],changed = ['b', 'a'],cost = [1, 1]) == 8\n assert candidate(source = \"aaaaaaaaaa\",target = \"bbbbbbbbbb\",original = ['a', 'b'],changed = ['b', 'a'],cost = [1, 10]) == 10\n assert candidate(source = \"abcdefghij\",target = \"ghijklmnop\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f'],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(source = \"mmmmmmmmmmmmmmmmmmmm\",target = \"nnnnnnnnnnnnnnnnnnnn\",original = ['m', 'n'],changed = ['n', 'm'],cost = [10, 1]) == 200\n assert candidate(source = \"abacabadabacaba\",target = \"xyzxyzxyzxyzxyz\",original = ['a', 'b', 'c'],changed = ['x', 'y', 'z'],cost = [3, 4, 5]) == -1\n assert candidate(source = \"aaaaa\",target = \"bbbbb\",original = ['a', 'a', 'a', 'a', 'a'],changed = ['b', 'b', 'b', 'b', 'b'],cost = [1, 2, 3, 4, 5]) == 5\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyza\",target = \"abcdefghijklmnopqrstuvwxyzb\",original = ['a', 'z'],changed = ['b', 'a'],cost = [10, 20]) == 10\n assert candidate(source = \"testing\",target = \"success\",original = ['t', 'e', 's', 'i', 'n', 'c'],changed = ['s', 's', 'c', 's', 'c', 's'],cost = [10, 20, 30, 40, 50, 60]) == -1\n assert candidate(source = \"zzzzzzzzzzzzzzzzzzzz\",target = \"aaaaaaaaaaaaaaaaaaaa\",original = ['z'],changed = ['a'],cost = [1]) == 20\n assert candidate(source = \"abcdef\",target = \"fedcba\",original = ['a', 'b', 'c', 'd', 'e', 'f'],changed = ['f', 'e', 'd', 'c', 'b', 'a'],cost = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(source = \"abcdefg\",target = \"hijklmn\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],changed = ['h', 'i', 'j', 'k', 'l', 'm', 'n'],cost = [1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(source = \"abcdabcdabcd\",target = \"zzzzzzzzzzzz\",original = ['a', 'b', 'c', 'd'],changed = ['z', 'z', 'z', 'z'],cost = [1, 2, 3, 4]) == 30\n assert candidate(source = \"xyxzy\",target = \"yxyzx\",original = ['x', 'y', 'z'],changed = ['y', 'z', 'x'],cost = [1, 1, 1]) == 6\n assert candidate(source = \"xyxyxy\",target = \"yzyzyz\",original = ['x', 'y'],changed = ['y', 'z'],cost = [10, 20]) == 90\n assert candidate(source = \"aaaaaaaaaa\",target = \"zzzzzzzzzz\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q'],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(source = \"abacabadabacaba\",target = \"xyzxyzyxzyzyxzy\",original = ['a', 'b', 'c'],changed = ['x', 'y', 'z'],cost = [10, 20, 30]) == -1\n assert candidate(source = \"abcdefghij\",target = \"jihgfedcba\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(source = \"abcabcabcabc\",target = \"xyzxyzxyzxyz\",original = ['a', 'b', 'c', 'x', 'y', 'z'],changed = ['x', 'y', 'z', 'a', 'b', 'c'],cost = [10, 20, 30, 40, 50, 60]) == 240\n assert candidate(source = \"abcdefghij\",target = \"jihgfedcba\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(source = \"hello\",target = \"world\",original = ['h', 'e', 'l', 'o', 'w', 'r', 'd'],changed = ['w', 'r', 'd', 'r', 'o', 'l', 'l'],cost = [1, 2, 3, 4, 5, 6, 7]) == -1\n assert candidate(source = \"aabbcc\",target = \"bbccdd\",original = ['a', 'b', 'c', 'd'],changed = ['b', 'c', 'd', 'e'],cost = [1, 2, 3, 4]) == 12\n assert candidate(source = \"mississippi\",target = \"hississippi\",original = ['m'],changed = ['h'],cost = [5]) == 5\n assert candidate(source = \"xyxyxyxyxyxyxyxyxy\",target = \"yzyzyzyzyzyzyzyzyz\",original = ['x', 'y', 'z'],changed = ['y', 'z', 'x'],cost = [5, 4, 3]) == 81\n assert candidate(source = \"abcabcabcabcabcabc\",target = \"defdefdefdefdefdef\",original = ['a', 'b', 'c'],changed = ['d', 'e', 'f'],cost = [1, 2, 3]) == 36\n assert candidate(source = \"algorithm\",target = \"algorithm\",original = ['a', 'l', 'g', 'o', 'r', 'i', 't', 'h', 'm'],changed = ['m', 'a', 'l', 'g', 'o', 'r', 'i', 't', 'h'],cost = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(source = \"repeated\",target = \"rotating\",original = ['e', 'p', 't', 'a', 'd'],changed = ['o', 'a', 'i', 't', 'n'],cost = [5, 7, 3, 9, 12]) == -1\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"zyxwvutsrqponmlkjihgfedcba\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],changed = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],cost = [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]) == 3510\n assert candidate(source = \"abababababababababab\",target = \"bcbcbcbcbcbcbcbcbcbc\",original = ['a', 'b', 'c'],changed = ['b', 'c', 'a'],cost = [1, 2, 3]) == 30\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"bcdefghijklmnopqrstuvwxyza\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],changed = ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a'],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 26\n assert candidate(source = \"aaaabbbbcccc\",target = \"bbccccddddee\",original = ['a', 'b', 'c'],changed = ['b', 'c', 'd'],cost = [1, 2, 3]) == -1\n assert candidate(source = \"aaaaaaaaaaaaaaaaaa\",target = \"bbbbbbbbbbbbbbbbbb\",original = ['a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'],changed = ['b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a'],cost = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 36\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyza\",target = \"zyxwvutsrqponmlkjihgfedcbaa\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],changed = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],cost = [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]) == 351\n assert candidate(source = \"abcabcabcabcabcabcabcabcabcabc\",target = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\",original = ['a', 'b', 'c', 'x', 'y', 'z'],changed = ['x', 'y', 'z', 'a', 'b', 'c'],cost = [10, 20, 30, 40, 50, 60]) == 600\n assert candidate(source = \"abcabcabcabcabc\",target = \"defdefdefdefdef\",original = ['a', 'b', 'c'],changed = ['d', 'e', 'f'],cost = [100, 200, 300]) == 3000\n assert candidate(source = \"abcabcabcabc\",target = \"xyzxyzxyzxyz\",original = ['a', 'b', 'c', 'x', 'y', 'z'],changed = ['x', 'y', 'z', 'a', 'b', 'c'],cost = [10, 20, 30, 5, 15, 25]) == 240\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"zyxwvutsrqponmlkjihgfedcba\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],changed = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],cost = [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]) == 351\n assert candidate(source = \"aaaaaaaaaaaaaaaaaaaa\",target = \"bbbbbbbbbbbbbbbbbbbb\",original = ['a', 'b', 'c'],changed = ['b', 'c', 'a'],cost = [100, 200, 300]) == 2000\n assert candidate(source = \"abacabadabacaba\",target = \"xyzxyzxyzxyzxyz\",original = ['a', 'b', 'c'],changed = ['x', 'y', 'z'],cost = [100, 200, 300]) == -1\n assert candidate(source = \"abcdefghij\",target = \"klmnopqrst\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(source = \"abcde\",target = \"fghij\",original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],changed = ['f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e'],cost = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1500\n assert candidate(source = \"aaaaabbbbbaaaaa\",target = \"bbbbbbaaaaabbbb\",original = ['a', 'b'],changed = ['b', 'a'],cost = [100, 150]) == 1500\n", "comparison": "exact"}, "public_tests": ["\"abcd\"\n\"acbe\"\n[\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"]\n[\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"]\n[2,5,5,1,2,20]", "\"aaaa\"\n\"bbbb\"\n[\"a\",\"c\"]\n[\"c\",\"b\"]\n[1,2]", "\"abcd\"\n\"abce\"\n[\"a\"]\n[\"e\"]\n[10000]"], "hints": ["Construct a graph with each letter as a node, and construct an edge (a, b) with weight c if we can change from character a to letter b with cost c. (Keep the one with the smallest cost in case there are multiple edges between a and b).", "Calculate the shortest path for each pair of characters (source[i], target[i]). The sum of cost over all i in the range [0, source.length - 1]. If there is no path between source[i] and target[i], the answer is -1.", "Any shortest path algorithms will work since we only have 26 nodes. Since we only have at most 26 * 26 pairs, we can save the result to avoid re-calculation.", "We can also use Floyd Warshall's algorithm to precompute all the results."], "metadata": {"canonical_parameter_names": ["source", "target", "original", "changed", "cost"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:11+00:00", "tests_total": 94, "tests_dropped": 33, "flags": [], "topic_tags": ["array", "string", "graph", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(source, target, original, changed, cost)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "source", "type": "String"}, {"name": "target", "type": "String"}, {"name": "original", "type": "Character[]"}, {"name": "changed", "type": "Character[]"}, {"name": "cost", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2977, "task_id": "minimum-cost-to-convert-string-ii", "difficulty": "Hard", "problem_description": "You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters. You are also given two 0-indexed string arrays original and changed, and an integer array cost, where cost[i] represents the cost of converting the string original[i] to the string changed[i].\n\nYou start with the string source. In one operation, you can pick a substring x from the string, and change it to y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:\n\n- The substrings picked in the operations are source[a..b] and source[c..d] with either b < c or d < a. In other words, the indices picked in both operations are disjoint.\n- The substrings picked in the operations are source[a..b] and source[c..d] with a == c and b == d. In other words, the indices picked in both operations are identical.\n\nReturn the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\n\nNote that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n\nExample 1:\n\nInput: source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\nOutput: 28\nExplanation: To convert \"abcd\" to \"acbe\", do the following operations:\n- Change substring source[1..1] from \"b\" to \"c\" at a cost of 5.\n- Change substring source[2..2] from \"c\" to \"e\" at a cost of 1.\n- Change substring source[2..2] from \"e\" to \"b\" at a cost of 2.\n- Change substring source[3..3] from \"d\" to \"e\" at a cost of 20.\nThe total cost incurred is 5 + 1 + 2 + 20 = 28.\nIt can be shown that this is the minimum possible cost.\n\nExample 2:\n\nInput: source = \"abcdefgh\", target = \"acdeeghh\", original = [\"bcd\",\"fgh\",\"thh\"], changed = [\"cde\",\"thh\",\"ghh\"], cost = [1,3,5]\nOutput: 9\nExplanation: To convert \"abcdefgh\" to \"acdeeghh\", do the following operations:\n- Change substring source[1..3] from \"bcd\" to \"cde\" at a cost of 1.\n- Change substring source[5..7] from \"fgh\" to \"thh\" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.\n- Change substring source[5..7] from \"thh\" to \"ghh\" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.\nThe total cost incurred is 1 + 3 + 5 = 9.\nIt can be shown that this is the minimum possible cost.\n\nExample 3:\n\nInput: source = \"abcdefgh\", target = \"addddddd\", original = [\"bcd\",\"defgh\"], changed = [\"ddd\",\"ddddd\"], cost = [100,1578]\nOutput: -1\nExplanation: It is impossible to convert \"abcdefgh\" to \"addddddd\".\nIf you select substring source[1..3] as the first operation to change \"abcdefgh\" to \"adddefgh\", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.\nIf you select substring source[3..7] as the first operation to change \"abcdefgh\" to \"abcddddd\", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.\n\nConstraints:\n\n- 1 <= source.length == target.length <= 1000\n- source, target consist only of lowercase English characters.\n- 1 <= cost.length == original.length == changed.length <= 100\n- 1 <= original[i].length == changed[i].length <= source.length\n- original[i], changed[i] consist only of lowercase English characters.\n- original[i] != changed[i]\n- 1 <= cost[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(source = \"abcdefgh\",target = \"acdeeghh\",original = ['bcd', 'fgh', 'thh'],changed = ['cde', 'thh', 'ghh'],cost = [1, 3, 5]) == 9\n assert candidate(source = \"abcd\",target = \"acbe\",original = ['a', 'b', 'c', 'c', 'e', 'd'],changed = ['b', 'c', 'b', 'e', 'b', 'e'],cost = [2, 5, 5, 1, 2, 20]) == 28\n assert candidate(source = \"abcdefgh\",target = \"addddddd\",original = ['bcd', 'defgh'],changed = ['ddd', 'ddddd'],cost = [100, 1578]) == -1\n assert candidate(source = \"mississippi\",target = \"massissippi\",original = ['issi', 'miss'],changed = ['assi', 'mass'],cost = [20, 30]) == 20\n assert candidate(source = \"xyzxyzxyz\",target = \"zyxzyxzyx\",original = ['xyz', 'zyx'],changed = ['zyx', 'xyz'],cost = [500, 500]) == 1500\n assert candidate(source = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",target = \"zzxxwwvvuuttrrssqqppoonnmmllkkjjiihhggffeeeeddccbbaa\",original = ['ab', 'bc', 'cd', 'de', 'ef', 'fg', 'gh', 'hi', 'ij', 'jk', 'kl', 'lm', 'mn', 'no', 'op', 'pq', 'qr', 'rs', 'st', 'tu', 'uv', 'vw', 'wx', 'xy', 'yz'],changed = ['yx', 'xw', 'wg', 'vf', 'fu', 'et', 'ts', 'sr', 'rq', 'qp', 'po', 'on', 'nm', 'ml', 'lk', 'kj', 'ji', 'ih', 'hg', 'gf', 'fe', 'ed', 'dc', 'cb', 'ba'],cost = [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]) == -1\n assert candidate(source = \"mnopqr\",target = \"rqpomn\",original = ['mnop', 'opqr', 'pqro', 'qrop', 'rpoq', 'poqm'],changed = ['rpoq', 'poqm', 'mnop', 'opqr', 'pqro', 'qrop'],cost = [100, 200, 300, 400, 500, 600]) == -1\n assert candidate(source = \"abcdefgabcdefgabcdefg\",target = \"zyxwvutzyxwvutzyxwvut\",original = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],changed = ['zyx', 'wvu', 'tsr', 'pon', 'mlk', 'jih', 'fed', 'cba', 'ba'],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(source = \"mnopqrst\",target = \"nopqrstu\",original = ['mnop', 'qrst', 'rstu'],changed = ['nopq', 'mnop', 'rstv'],cost = [100, 200, 300]) == -1\n assert candidate(source = \"abracadabra\",target = \"abracabadaa\",original = ['ra'],changed = ['aa'],cost = [3]) == -1\n assert candidate(source = \"abcabcabcabc\",target = \"defdefdefdef\",original = ['abc', 'def'],changed = ['def', 'abc'],cost = [1000, 1000]) == 4000\n assert candidate(source = \"aaaaabbbbb\",target = \"bbbbbbaaaa\",original = ['aaaaa', 'bbbbb'],changed = ['bbbbb', 'aaaaa'],cost = [2000, 1000]) == -1\n assert candidate(source = \"aaaaabbbbb\",target = \"bbbbbbaaaa\",original = ['aaaaa', 'bbbbb'],changed = ['bbbbb', 'aaaaa'],cost = [1000, 1000]) == -1\n assert candidate(source = \"abcdefabcdefabcdef\",target = \"ghijklghijklghijkl\",original = ['abc', 'def', 'ghi', 'jkl'],changed = ['ghi', 'jkl', 'abc', 'def'],cost = [10, 20, 30, 40]) == 90\n assert candidate(source = \"ababababab\",target = \"bababababa\",original = ['aba', 'bab'],changed = ['bab', 'aba'],cost = [5, 10]) == -1\n assert candidate(source = \"ababababab\",target = \"cdcdcdcdcd\",original = ['ab', 'ba'],changed = ['cd', 'dc'],cost = [1, 2]) == 5\n assert candidate(source = \"abababababababababababab\",target = \"babababababababababababa\",original = ['ab', 'ba'],changed = ['ba', 'ab'],cost = [1, 2]) == 12\n assert candidate(source = \"abcdefgabcdefg\",target = \"gfedcbagfedcba\",original = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],changed = ['cba', 'fed', 'ihg', 'lkj', 'onm', 'rqp', 'uts', 'xwv', 'zy'],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -1\n assert candidate(source = \"abcabcabcabcabcabc\",target = \"defdefdefdefdefdef\",original = ['abc', 'def'],changed = ['def', 'abc'],cost = [1, 2]) == 6\n assert candidate(source = \"abcdef\",target = \"fedcba\",original = ['abc', 'def', 'fed'],changed = ['def', 'fed', 'abc'],cost = [100, 200, 300]) == -1\n assert candidate(source = \"abcabcabcabc\",target = \"cbacbacbacba\",original = ['abc', 'cba'],changed = ['cba', 'abc'],cost = [25, 35]) == 100\n assert candidate(source = \"abababab\",target = \"cdcdcdcd\",original = ['ab', 'ba', 'abcd', 'cd', 'dc'],changed = ['cd', 'cd', 'cdcd', 'ab', 'ab'],cost = [10, 20, 30, 40, 50]) == 40\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"zyxwvutsrqponmlkjihgfedcba\",original = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],changed = ['xyz', 'wvu', 'tsr', 'qpo', 'nml', 'kji', 'hgf', 'edc', 'ba'],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -1\n assert candidate(source = \"abcdefgabcdefg\",target = \"ghijklmghijklm\",original = ['abc', 'def', 'ghi', 'jkl'],changed = ['ghi', 'jkl', 'mno', 'pqr'],cost = [50, 75, 100, 125]) == -1\n assert candidate(source = \"aaaaaaaaaaaaaaaaaaaa\",target = \"bbbbbbbbbbbbbbbbbbbb\",original = ['aaa', 'bbb', 'aab', 'abb'],changed = ['bbb', 'aaa', 'abb', 'aab'],cost = [10, 5, 20, 15]) == -1\n assert candidate(source = \"mississippi\",target = \"maddessippi\",original = ['issi', 'ippi', 'ippi', 'issi'],changed = ['addi', 'essi', 'ppii', 'ppii'],cost = [100, 200, 50, 300]) == -1\n assert candidate(source = \"abcdefg\",target = \"abcdefg\",original = ['abc', 'def', 'ghi'],changed = ['bcd', 'efg', 'hij'],cost = [10, 20, 30]) == 0\n assert candidate(source = \"ababababab\",target = \"bababababa\",original = ['aba', 'bab'],changed = ['bab', 'aba'],cost = [5, 7]) == -1\n assert candidate(source = \"abcdabcdabcd\",target = \"zzzzzzzzzzzz\",original = ['abcd', 'abc', 'bcd', 'cd', 'd', 'ab'],changed = ['zzzz', 'zzz', 'zzz', 'zz', 'z', 'zz'],cost = [100, 110, 120, 130, 140, 150]) == 300\n assert candidate(source = \"abcde\",target = \"edcba\",original = ['abc', 'cde', 'edc', 'cba'],changed = ['cde', 'edc', 'cba', 'abc'],cost = [10, 20, 30, 40]) == -1\n assert candidate(source = \"abababab\",target = \"babababa\",original = ['aba', 'bab', 'aab'],changed = ['bab', 'aba', 'bab'],cost = [2, 3, 1]) == -1\n assert candidate(source = \"abcdefabcdef\",target = \"fedcbafedcba\",original = ['abc', 'def'],changed = ['def', 'abc'],cost = [50, 60]) == -1\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"zyxwvutsrqponmlkjihgfedcba\",original = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yza'],changed = ['uvw', 'rst', 'opq', 'lmn', 'fed', 'cba', 'zyx', 'wvu', 'tsr'],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -1\n assert candidate(source = \"hellohellohello\",target = \"worldworldworld\",original = ['hello', 'world'],changed = ['world', 'hello'],cost = [500, 300]) == 1500\n assert candidate(source = \"abcabcabcabc\",target = \"xyzxyzxyzxyz\",original = ['abc', 'ab', 'bc'],changed = ['xyz', 'yx', 'zx'],cost = [100, 50, 30]) == 400\n assert candidate(source = \"abcdefghij\",target = \"jihgfedcba\",original = ['abc', 'def', 'ghi', 'jkl'],changed = ['cba', 'fed', 'ihg', 'lkj'],cost = [10, 20, 30, 40]) == -1\n assert candidate(source = \"abcdef\",target = \"fedcba\",original = ['abc', 'def'],changed = ['def', 'abc'],cost = [10, 20]) == -1\n assert candidate(source = \"abacabadabacaba\",target = \"xyzxyzxyzxyzxyz\",original = ['aba', 'bac', 'cab', 'abc'],changed = ['xyz', 'zyx', 'yxz', 'yzx'],cost = [1000, 2000, 3000, 4000]) == -1\n assert candidate(source = \"abcdefghijklmnopqrstuvwxyz\",target = \"zyxwvutsrqponmlkjihgfedcba\",original = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],changed = ['zyx', 'wvu', 'tsr', 'pon', 'mlk', 'jih', 'fed', 'cba', 'ba'],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -1\n assert candidate(source = \"xyxyxyxyxy\",target = \"yxyxyxyxyx\",original = ['xy', 'yx'],changed = ['yx', 'xy'],cost = [10, 5]) == 50\n assert candidate(source = \"xyzxyzxyz\",target = \"zyxzyxzyx\",original = ['xyz', 'zyx'],changed = ['zyx', 'xyz'],cost = [1, 2]) == 3\n assert candidate(source = \"aabbccddeeff\",target = \"ffeeddccbbaa\",original = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff'],changed = ['ff', 'ee', 'dd', 'cc', 'bb', 'aa'],cost = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(source = \"zzzzzzzz\",target = \"yyyyyyyy\",original = ['zzz', 'zyz', 'yzy'],changed = ['yyy', 'yyy', 'yyy'],cost = [10, 20, 5]) == -1\n assert candidate(source = \"aabbccddeeff\",target = \"ffeeddccbbaa\",original = ['ab', 'bc', 'cd', 'de', 'ef'],changed = ['fe', 'ed', 'dc', 'cb', 'ba'],cost = [1, 2, 3, 4, 5]) == -1\n assert candidate(source = \"aabbccddeeff\",target = \"zzzzzzzzzzzz\",original = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'abcdef'],changed = ['zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zzzzzz'],cost = [10, 10, 10, 10, 10, 10, 50]) == 60\n assert candidate(source = \"abcdefghij\",target = \"jihgfedcba\",original = ['abc', 'def', 'ghi', 'jih', 'fed', 'cba'],changed = ['jih', 'fed', 'cba', 'abc', 'def', 'ghi'],cost = [100, 200, 300, 400, 500, 600]) == -1\n assert candidate(source = \"abcabcabcabcabcabcabcabcabcabc\",target = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\",original = ['abc', 'bc', 'c', 'a', 'b', 'ab', 'bc', 'ca'],changed = ['xyz', 'yz', 'z', 'x', 'y', 'xy', 'yz', 'zx'],cost = [10, 20, 30, 40, 50, 60, 70, 80]) == 100\n assert candidate(source = \"abacabadabacaba\",target = \"zzzzzzzzzzzzzzz\",original = ['aba', 'abc', 'aca', 'bca', 'cab'],changed = ['zzz', 'zzz', 'zzz', 'zzz', 'zzz'],cost = [10, 20, 30, 40, 50]) == -1\n assert candidate(source = \"xyzxyzxyz\",target = \"uvwuvwuvw\",original = ['xyz', 'yzx', 'zxy', 'xy', 'yz', 'zx', 'x', 'y', 'z'],changed = ['uvw', 'uvw', 'uvw', 'uv', 'uw', 'vw', 'u', 'v', 'w'],cost = [100, 150, 200, 10, 20, 30, 1, 2, 3]) == 18\n assert candidate(source = \"aaaaabbbbb\",target = \"bbbbbbaaaa\",original = ['aaaa', 'bbbb'],changed = ['bbbb', 'aaaa'],cost = [1000, 2000]) == -1\n assert candidate(source = \"aabbccddeeff\",target = \"aabbccddeeff\",original = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff'],changed = ['bb', 'cc', 'dd', 'ee', 'ff', 'aa'],cost = [10, 20, 30, 40, 50, 60]) == 0\n assert candidate(source = \"abababababababababab\",target = \"babababababababababa\",original = ['ab', 'ba'],changed = ['ba', 'ab'],cost = [3, 2]) == 30\n assert candidate(source = \"mississippi\",target = \"mississippa\",original = ['ippi'],changed = ['appa'],cost = [5]) == -1\n assert candidate(source = \"aaaaabbbbbaaaaabbbbbaaaaabbbbbaaaaa\",target = \"zzzzzxxxxxzzzzzxxxxxzzzzzxxxxxzzzzz\",original = ['aaaaa', 'bbbbb', 'xxxxx', 'zzzzz'],changed = ['zzzzz', 'aaaaa', 'zzzzz', 'xxxxx'],cost = [100, 200, 300, 400]) == 2500\n assert candidate(source = \"xyxyxyxyxyxyxyxyxy\",target = \"yxyxyxyxyxyxyxyxyx\",original = ['xy', 'yx'],changed = ['yx', 'xy'],cost = [1, 2]) == 9\n", "comparison": "exact"}, "public_tests": ["\"abcd\"\n\"acbe\"\n[\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"]\n[\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"]\n[2,5,5,1,2,20]", "\"abcdefgh\"\n\"acdeeghh\"\n[\"bcd\",\"fgh\",\"thh\"]\n[\"cde\",\"thh\",\"ghh\"]\n[1,3,5]", "\"abcdefgh\"\n\"addddddd\"\n[\"bcd\",\"defgh\"]\n[\"ddd\",\"ddddd\"]\n[100,1578]"], "hints": ["Give each unique string in original and changed arrays a unique id. There are at most 2 * m unique strings in total where m is the length of the arrays. We can put them into a hash map to assign ids.", "We can pre-compute the smallest costs between all pairs of unique strings using Floyd Warshall algorithm in O(m ^ 3) time complexity.", "Let dp[i] be the smallest cost to change the first i characters (prefix) of source into target, leaving the suffix untouched. We have dp[0] = 0. dp[i] = min( dp[i - 1] if (source[i - 1] == target[i - 1]), dp[j-1] + cost[x][y] where x is the id of source[j..(i - 1)] and y is the id of target e[j..(i - 1)]) ). If neither of the two conditions is satisfied, dp[i] = infinity.", "We can use Trie to check for the second condition in O(1).", "The answer is dp[n] where n is source.length."], "metadata": {"canonical_parameter_names": ["source", "target", "original", "changed", "cost"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:14+00:00", "tests_total": 91, "tests_dropped": 36, "flags": [], "topic_tags": ["array", "string", "dynamic-programming", "graph", "trie", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(source, target, original, changed, cost)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "source", "type": "String"}, {"name": "target", "type": "String"}, {"name": "original", "type": "String[]"}, {"name": "changed", "type": "String[]"}, {"name": "cost", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2980, "task_id": "check-if-bitwise-or-has-trailing-zeros", "difficulty": "Easy", "problem_description": "You are given an array of positive integers nums.\n\nYou have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.\n\nFor example, the binary representation of 5, which is \"101\", does not have any trailing zeros, whereas the binary representation of 4, which is \"100\", has two trailing zeros.\n\nReturn true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\n\nExample 2:\n\nInput: nums = [2,4,8,16]\nOutput: true\nExplanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\nOther possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).\n\nExample 3:\n\nInput: nums = [1,3,5,7,9]\nOutput: false\nExplanation: There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1]) == False\n assert candidate(nums = [1, 3, 5, 7, 9]) == False\n assert candidate(nums = [5, 7, 9, 11]) == False\n assert candidate(nums = [7, 11, 13, 14]) == False\n assert candidate(nums = [3, 6, 9, 12, 15]) == True\n assert candidate(nums = [11, 13, 15, 17]) == False\n assert candidate(nums = [1, 2, 3, 4, 5]) == True\n assert candidate(nums = [2, 4, 8, 16]) == True\n assert candidate(nums = [6, 12, 18, 24, 30]) == True\n assert candidate(nums = [5, 7, 11, 13]) == False\n assert candidate(nums = [9, 18, 27, 36]) == True\n assert candidate(nums = [2, 2, 2, 2]) == True\n assert candidate(nums = [8, 16, 32]) == True\n assert candidate(nums = [6, 12, 18, 24]) == True\n assert candidate(nums = [3, 5]) == False\n assert candidate(nums = [5, 10, 15, 20]) == True\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == True\n assert candidate(nums = [1, 2]) == False\n assert candidate(nums = [5, 7, 9, 11, 13]) == False\n assert candidate(nums = [7, 14, 21, 28]) == True\n assert candidate(nums = [10, 20, 30, 40]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == False\n assert candidate(nums = [10, 18, 22, 34, 50, 62]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == True\n assert candidate(nums = [7, 15, 23, 31, 39, 47, 55, 63, 71, 79]) == False\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == False\n assert candidate(nums = [2, 3, 4, 6, 8, 10]) == True\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64]) == True\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]) == True\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80]) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [3, 6, 9, 12, 15]) == True\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39]) == False\n assert candidate(nums = [7, 14, 21, 28, 35]) == True\n assert candidate(nums = [2, 3, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72]) == True\n assert candidate(nums = [11, 14, 19, 22, 27, 30, 35, 38, 43]) == True\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == True\n assert candidate(nums = [10, 14, 18, 22, 26]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == True\n assert candidate(nums = [10, 12, 14, 16, 18, 20, 22]) == True\n assert candidate(nums = [50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78]) == True\n assert candidate(nums = [17, 34, 51, 68, 85]) == True\n assert candidate(nums = [63, 62, 61, 60, 59, 58, 57, 56, 55, 54]) == True\n assert candidate(nums = [17, 19, 21, 23, 25, 27, 29, 31]) == False\n assert candidate(nums = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == False\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21]) == True\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16]) == True\n assert candidate(nums = [2, 3, 6, 12, 24, 48]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == False\n assert candidate(nums = [10, 20, 30, 40, 50]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == True\n assert candidate(nums = [4, 12, 20, 28, 36, 44, 52]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == True\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(nums = [33, 35, 37, 39, 41, 43, 45, 47, 49, 51]) == False\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42]) == True\n assert candidate(nums = [1, 3, 5, 7, 8, 9, 11]) == False\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38]) == True\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]) == True\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == False\n assert candidate(nums = [10, 12, 14, 16, 18, 20]) == True\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15]) == True\n assert candidate(nums = [25, 30, 40, 50, 60, 70]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == False\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34]) == True\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61]) == False\n assert candidate(nums = [30, 42, 54, 66, 78, 90]) == True\n assert candidate(nums = [10, 12, 14, 16, 18, 20, 22, 24]) == True\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == True\n assert candidate(nums = [51, 53, 57, 61, 65, 69, 73, 77]) == False\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[2,4,8,16]", "[1,3,5,7,9]"], "hints": ["Bitwise OR can never unset a bit. If there is a solution, there must be a solution with only a pair of elements.", "We can brute force the solution: enumerate all the pairs.", "As the least significant bit must stay unset, the question is whether the array has at least two even elements."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().hasTrailingZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:19+00:00", "tests_total": 119, "tests_dropped": 41, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def has_trailing_zeros(nums)", "container": null, "callable": "has_trailing_zeros", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2981, "task_id": "find-longest-special-substring-that-occurs-thrice-i", "difficulty": "Medium", "problem_description": "You are given a string s that consists of lowercase English letters.\n\nA string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\n\nReturn the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\n\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\nIt can be shown that the maximum length achievable is 2.\n\nExample 2:\n\nInput: s = \"abcdef\"\nOutput: -1\nExplanation: There exists no special substring which occurs at least thrice. Hence return -1.\n\nExample 3:\n\nInput: s = \"abcaba\"\nOutput: 1\nExplanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\nIt can be shown that the maximum length achievable is 1.\n\nConstraints:\n\n- 3 <= s.length <= 50\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 7\n assert candidate(s = \"abcabcabc\") == 1\n assert candidate(s = \"aaabbbccc\") == 1\n assert candidate(s = \"aabbcc\") == -1\n assert candidate(s = \"aaaabbbbcccc\") == 2\n assert candidate(s = \"abcabcabcabc\") == 1\n assert candidate(s = \"aaaaaa\") == 4\n assert candidate(s = \"ababab\") == 1\n assert candidate(s = \"zzzzzz\") == 4\n assert candidate(s = \"abcaba\") == 1\n assert candidate(s = \"zzzzyzzzz\") == 3\n assert candidate(s = \"abcdef\") == -1\n assert candidate(s = \"aabbaabbaa\") == 2\n assert candidate(s = \"abcabc\") == -1\n assert candidate(s = \"aaaabb\") == 2\n assert candidate(s = \"aaabbb\") == 1\n assert candidate(s = \"aaaa\") == 2\n assert candidate(s = \"aaaabaaa\") == 3\n assert candidate(s = \"mnopmnopmnopmnop\") == 1\n assert candidate(s = \"aaaaaaaabbaaaaaaabbaaaaaaa\") == 7\n assert candidate(s = \"aaabbbcccdddaaaabbbcccddd\") == 3\n assert candidate(s = \"aabbaaabaabb\") == 2\n assert candidate(s = \"abcdefabcdefabcdef\") == 1\n assert candidate(s = \"abacabadabacabadabacabadabacabad\") == 1\n assert candidate(s = \"aabbccddeeefffgggaaaabbbcccddd\") == 2\n assert candidate(s = \"zzzzzzzzzzzzzzz\") == 13\n assert candidate(s = \"aabbbcccaabbcccaa\") == 2\n assert candidate(s = \"aaaaaaaabbaaaaaaa\") == 7\n assert candidate(s = \"hhhhhhhhhhhhhhhhhiiiiiiiihhhhiiiiiii\") == 15\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 30\n assert candidate(s = \"abcddcbaabcddcba\") == 1\n assert candidate(s = \"cccccccccccccccccccc\") == 18\n assert candidate(s = \"ccccaaaabbbccc\") == 3\n assert candidate(s = \"aaabbbcccddd\") == 1\n assert candidate(s = \"abacabadabacab\") == 1\n assert candidate(s = \"aabbaabbaabbaabb\") == 2\n assert candidate(s = \"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\") == 44\n assert candidate(s = \"aaabbbaaabbbaaabb\") == 3\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 1\n assert candidate(s = \"xxyyxxyyxxyy\") == 2\n assert candidate(s = \"ababababababababababababababab\") == 1\n assert candidate(s = \"zzzzzzyzzzzz\") == 5\n assert candidate(s = \"zzzzzzzzzzzz\") == 10\n assert candidate(s = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 44\n assert candidate(s = \"abababababab\") == 1\n assert candidate(s = \"abcabcabcabcabcabc\") == 1\n assert candidate(s = \"xyzxyzzxyzyzyx\") == 1\n assert candidate(s = \"aabbbcccbbbccccccbbbaabbcc\") == 4\n assert candidate(s = \"aaaaaabaaaaabaaaaa\") == 5\n assert candidate(s = \"mnopqrstuvwxyzaaa\") == 1\n assert candidate(s = \"abcdabcdabcdabcd\") == 1\n assert candidate(s = \"aaaaaaa\") == 5\n assert candidate(s = \"ppppqqppqqqqqqpp\") == 4\n assert candidate(s = \"abcdabcdabcdabcdabcd\") == 1\n assert candidate(s = \"abababababababababab\") == 1\n assert candidate(s = \"abababab\") == 1\n assert candidate(s = \"nnnmmmnnnmmmnnnmmmm\") == 3\n assert candidate(s = \"aaaaaaaabbbbbbbbbb\") == 8\n assert candidate(s = \"abacabadabacaba\") == 1\n assert candidate(s = \"aabbaaabbbaaaabbb\") == 3\n assert candidate(s = \"aabbccddeeefffggg\") == 1\n assert candidate(s = \"aaaaaabbbcccaabb\") == 4\n assert candidate(s = \"aaaabbbbccccddddeeeeffff\") == 2\n assert candidate(s = \"aaabbbcccaaaabbb\") == 3\n assert candidate(s = \"xyxyxyxyxyxyxyx\") == 1\n assert candidate(s = \"zzzzzzzzzzzzz\") == 11\n assert candidate(s = \"aaabbbaaabbbbaaabbbbaaabbb\") == 3\n assert candidate(s = \"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\") == 48\n assert candidate(s = \"aaaaabbbaaaaaaaaabbbaaaa\") == 7\n assert candidate(s = \"pppppqqqqqrrrrrppqqrr\") == 3\n assert candidate(s = \"aaabbaaabbaa\") == 2\n assert candidate(s = \"kkkkkllllllmmmmm\") == 4\n assert candidate(s = \"lkllkkkklllllllllllkkk\") == 9\n assert candidate(s = \"ppppqpppqqqpppp\") == 3\n assert candidate(s = \"aaabbbcccdddcccbbbcccbbbcccaaacccaaa\") == 3\n assert candidate(s = \"aaabbbcccdddeeefffgggaaaabbbcccddd\") == 3\n assert candidate(s = \"abcddcba\") == -1\n assert candidate(s = \"cccccbbbbbbaaaaa\") == 4\n assert candidate(s = \"mmmmmnnnnooooo\") == 3\n assert candidate(s = \"abcabcabcabcabcab\") == 1\n assert candidate(s = \"tttttttttttttttttttttttttt\") == 24\n assert candidate(s = \"aaaaaaaabaaaaaa\") == 6\n assert candidate(s = \"aaaaabbbbcccc\") == 3\n assert candidate(s = \"xzyxzyxzyxzyxzyxzy\") == 1\n assert candidate(s = \"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\") == 46\n assert candidate(s = \"abcabcabcabcabc\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 48\n", "comparison": "exact"}, "public_tests": ["\"aaaa\"", "\"abcdef\"", "\"abcaba\""], "hints": ["The constraints are small.", "Brute force checking all substrings."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:21+00:00", "tests_total": 95, "tests_dropped": 8, "flags": [], "topic_tags": ["hash-table", "string", "binary-search", "sliding-window", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(s)", "container": null, "callable": "maximum_length", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2982, "task_id": "find-longest-special-substring-that-occurs-thrice-ii", "difficulty": "Medium", "problem_description": "You are given a string s that consists of lowercase English letters.\n\nA string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\n\nReturn the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\n\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\nIt can be shown that the maximum length achievable is 2.\n\nExample 2:\n\nInput: s = \"abcdef\"\nOutput: -1\nExplanation: There exists no special substring which occurs at least thrice. Hence return -1.\n\nExample 3:\n\nInput: s = \"abcaba\"\nOutput: 1\nExplanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\nIt can be shown that the maximum length achievable is 1.\n\nConstraints:\n\n- 3 <= s.length <= 5 * 10^5\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 7\n assert candidate(s = \"aaabbbccc\") == 1\n assert candidate(s = \"aabbbcccaaa\") == 2\n assert candidate(s = \"abcdef\") == -1\n assert candidate(s = \"abacabadabacaba\") == 1\n assert candidate(s = \"abcabcabc\") == 1\n assert candidate(s = \"abcaba\") == 1\n assert candidate(s = \"aaaaabbbbccccc\") == 3\n assert candidate(s = \"aabbaabbcc\") == 1\n assert candidate(s = \"aaaaaaaaaa\") == 8\n assert candidate(s = \"aaaabbbbcccc\") == 2\n assert candidate(s = \"abababababa\") == 1\n assert candidate(s = \"abcdabcabcd\") == 1\n assert candidate(s = \"aabbccddeeefff\") == 1\n assert candidate(s = \"aabbccddeeffgg\") == -1\n assert candidate(s = \"aaaa\") == 2\n assert candidate(s = \"aaabaaa\") == 2\n assert candidate(s = \"aaaaabbbbbaaaa\") == 4\n assert candidate(s = \"nnnhaaaannn\") == 2\n assert candidate(s = \"zzzzz\") == 3\n assert candidate(s = \"aabbaabbccddccddc\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == -1\n", "comparison": "exact"}, "public_tests": ["\"aaaa\"", "\"abcdef\"", "\"abcaba\""], "hints": ["Let len[i] be the length of the longest special string ending with s[i].", "If i > 0 and s[i] == s[i - 1], len[i] = len[i - 1] + 1. Otherwise len[i] == 1.", "Group all the len[i] by s[i]. We have at most 26 groups.", "The maximum value of the third largest len[i] in each group is the answer.", "We only need to maintain the top three values for each group. You can use sorting, heap, or brute-force comparison to find the third largest value in each group."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:23+00:00", "tests_total": 22, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "binary-search", "sliding-window", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(s)", "container": null, "callable": "maximum_length", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2983, "task_id": "palindrome-rearrangement-queries", "difficulty": "Hard", "problem_description": "You are given a 0-indexed string s having an even length n.\n\nYou are also given a 0-indexed 2D integer array, queries, where queries[i] = [a_i, b_i, c_i, d_i].\n\nFor each query i, you are allowed to perform the following operations:\n\n- Rearrange the characters within the substring s[a_i:b_i], where 0 <= a_i <= b_i < n / 2.\n- Rearrange the characters within the substring s[c_i:d_i], where n / 2 <= c_i <= d_i < n.\n\nFor each query, your task is to determine whether it is possible to make s a palindrome by performing the operations.\n\nEach query is answered independently of the others.\n\nReturn a 0-indexed array answer, where answer[i] == true if it is possible to make s a palindrome by performing operations specified by the i^th query, and false otherwise.\n\n- A substring is a contiguous sequence of characters within a string.\n- s[x:y] represents the substring consisting of characters from the index x to index y in s, both inclusive.\n\nExample 1:\n\nInput: s = \"abcabc\", queries = [[1,1,3,5],[0,2,5,5]]\nOutput: [true,true]\nExplanation: In this example, there are two queries:\nIn the first query:\n- a_0 = 1, b_0 = 1, c_0 = 3, d_0 = 5.\n- So, you are allowed to rearrange s[1:1] => abcabc and s[3:5] => abcabc.\n- To make s a palindrome, s[3:5] can be rearranged to become => abccba.\n- Now, s is a palindrome. So, answer[0] = true.\nIn the second query:\n- a_1 = 0, b_1 = 2, c_1 = 5, d_1 = 5.\n- So, you are allowed to rearrange s[0:2] => abcabc and s[5:5] => abcabc.\n- To make s a palindrome, s[0:2] can be rearranged to become => cbaabc.\n- Now, s is a palindrome. So, answer[1] = true.\n\nExample 2:\n\nInput: s = \"abbcdecbba\", queries = [[0,2,7,9]]\nOutput: [false]\nExplanation: In this example, there is only one query.\na_0 = 0, b_0 = 2, c_0 = 7, d_0 = 9.\nSo, you are allowed to rearrange s[0:2] => abbcdecbba and s[7:9] => abbcdecbba.\nIt is not possible to make s a palindrome by rearranging these substrings because s[3:6] is not a palindrome.\nSo, answer[0] = false.\n\nExample 3:\n\nInput: s = \"acbcab\", queries = [[1,2,4,5]]\nOutput: [true]\nExplanation: In this example, there is only one query.\na_0 = 1, b_0 = 2, c_0 = 4, d_0 = 5.\nSo, you are allowed to rearrange s[1:2] => acbcab and s[4:5] => acbcab.\nTo make s a palindrome s[1:2] can be rearranged to become abccab.\nThen, s[4:5] can be rearranged to become abccba.\nNow, s is a palindrome. So, answer[0] = true.\n\nConstraints:\n\n- 2 <= n == s.length <= 10^5\n- 1 <= queries.length <= 10^5\n- queries[i].length == 4\n- a_i == queries[i][0], b_i == queries[i][1]\n- c_i == queries[i][2], d_i == queries[i][3]\n- 0 <= a_i <= b_i < n / 2\n- n / 2 <= c_i <= d_i < n\n- n is even.\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abbcdecbba\",queries = [[0, 2, 7, 9]]) == [False]\n assert candidate(s = \"abcabc\",queries = [[1, 1, 3, 5], [0, 2, 5, 5]]) == [True, True]\n assert candidate(s = \"acbcab\",queries = [[1, 2, 4, 5]]) == [True]\n assert candidate(s = \"aabbaa\",queries = [[0, 2, 3, 5]]) == [True]\n assert candidate(s = \"aabbccdd\",queries = [[0, 1, 6, 7], [2, 3, 4, 5]]) == [False, False]\n assert candidate(s = \"racecaracercar\",queries = [[0, 2, 10, 12], [3, 5, 8, 10], [1, 4, 7, 9]]) == [False, False, False]\n assert candidate(s = \"aabbccddeeffgg\",queries = [[0, 5, 7, 12], [2, 3, 10, 11]]) == [False, False]\n assert candidate(s = \"mississippiissippi\",queries = [[0, 4, 10, 14], [1, 3, 11, 13]]) == [False, False]\n assert candidate(s = \"aaaabbbbccccdddd\",queries = [[0, 3, 12, 15], [1, 2, 13, 14], [2, 3, 14, 15]]) == [False, False, False]\n assert candidate(s = \"racecarannakayak\",queries = [[0, 6, 8, 13], [1, 5, 9, 12]]) == [False, False]\n assert candidate(s = \"noonnoon\",queries = [[0, 2, 5, 7], [1, 3, 4, 6]]) == [True, True]\n assert candidate(s = \"abcdeedcba\",queries = [[0, 4, 5, 9], [1, 3, 6, 8], [2, 2, 7, 7]]) == [True, True, True]\n assert candidate(s = \"rotorrotorrotorrotor\",queries = [[0, 4, 12, 16], [2, 5, 10, 14], [3, 6, 11, 15]]) == [True, True, True]\n assert candidate(s = \"abacabadabacabad\",queries = [[0, 7, 8, 15], [1, 6, 9, 14], [2, 5, 10, 13], [3, 4, 11, 12]]) == [True, False, False, False]\n assert candidate(s = \"abcdefghijzyxwvutsrqponmlkjihgfedcba\",queries = [[0, 9, 20, 29], [1, 8, 21, 28], [2, 7, 22, 27], [3, 6, 23, 26], [4, 5, 24, 25]]) == [False, False, False, False, False]\n assert candidate(s = \"rotorrotor\",queries = [[0, 2, 6, 8], [1, 4, 5, 7]]) == [True, True]\n assert candidate(s = \"aabbccddeeff\",queries = [[0, 2, 9, 11], [1, 3, 8, 10], [2, 4, 7, 9]]) == [False, False, False]\n assert candidate(s = \"mississippiissim\",queries = [[0, 3, 11, 14], [2, 4, 9, 12], [1, 5, 8, 11]]) == [False, False, False]\n assert candidate(s = \"abcdedcbaa\",queries = [[0, 1, 8, 9], [2, 3, 6, 7], [1, 4, 5, 8]]) == [False, False, False]\n assert candidate(s = \"zzzzzzzzzz\",queries = [[0, 4, 5, 9], [1, 3, 6, 8], [2, 2, 7, 7]]) == [True, True, True]\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",queries = [[0, 1, 28, 29], [1, 2, 27, 28], [2, 3, 26, 27], [3, 4, 25, 26], [4, 5, 24, 25], [5, 6, 23, 24]]) == [False, False, False, False, False, False]\n assert candidate(s = \"abacabadabacabad\",queries = [[0, 3, 8, 11], [1, 4, 9, 12], [2, 5, 10, 13]]) == [False, False, False]\n assert candidate(s = \"noonnoon\",queries = [[0, 1, 5, 6], [2, 3, 4, 5]]) == [True, True]\n assert candidate(s = \"zyxzyxzyxzyx\",queries = [[0, 2, 9, 11], [3, 5, 6, 8]]) == [False, False]\n assert candidate(s = \"noonnoonnoon\",queries = [[1, 3, 9, 11], [2, 4, 8, 10], [0, 2, 6, 8]]) == [True, True, True]\n assert candidate(s = \"abacaxabacax\",queries = [[0, 2, 8, 10], [1, 3, 6, 8]]) == [False, False]\n assert candidate(s = \"abcdefghijkzyxwvutsrqponml\",queries = [[0, 4, 19, 23], [2, 3, 17, 18]]) == [False, False]\n assert candidate(s = \"noonnoonnoonnoon\",queries = [[0, 3, 12, 15], [1, 2, 13, 14]]) == [True, True]\n assert candidate(s = \"xyzzyxzyxzyx\",queries = [[0, 1, 10, 11], [2, 3, 8, 9], [4, 5, 6, 7]]) == [False, False, False]\n", "comparison": "exact"}, "public_tests": ["\"abcabc\"\n[[1,1,3,5],[0,2,5,5]]", "\"abbcdecbba\"\n[[0,2,7,9]]", "\"acbcab\"\n[[1,2,4,5]]"], "hints": ["Consider two indices, x on the left side and its symmetrical index y on the right side.", "Store the frequencies of all of the letters in both intervals [a_i, b_i] and [c_i, d_i] in a query.", "If x is not in [a_i, b_i] and y is not in [c_i, d_i], they must be the same.", "If x is in [a_i, b_i] and y is not in [c_i, d_i], remove one occurrence of the character at index y from the frequency array on the left side.", "Similarly, if x is not in [a_i, b_i] and y is in [c_i, d_i], remove one occurrence of the character at index x from the frequency array on the right side.", "Finally, check whether the two frequency arrays are the same, and the indices that don't fall into any of the intervals are the same as well.", "Use prefix-sum + hashing to improve the time complexity."], "metadata": {"canonical_parameter_names": ["s", "queries"], "leetcode_dataset_entry_point": "Solution().canMakePalindromeQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:26+00:00", "tests_total": 51, "tests_dropped": 22, "flags": [], "topic_tags": ["array", "hash-table", "string", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def can_make_palindrome_queries(s, queries)", "container": null, "callable": "can_make_palindrome_queries", "parameters": [{"name": "s", "type": "String"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2996, "task_id": "smallest-missing-integer-greater-than-sequential-prefix-sum", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array of integers nums.\n\nA prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.\n\nReturn the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.\n\nExample 1:\n\nInput: nums = [1,2,3,2,5]\nOutput: 6\nExplanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n\nExample 2:\n\nInput: nums = [3,4,5,1,12,14,13]\nOutput: 15\nExplanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == 6\n assert candidate(nums = [10, 11, 12, 8, 9, 13]) == 33\n assert candidate(nums = [10, 11, 12, 13, 14]) == 60\n assert candidate(nums = [1, 3, 5, 7, 9]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [50, 49, 48, 47, 46]) == 51\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 95\n assert candidate(nums = [2, 3, 4, 5, 6]) == 20\n assert candidate(nums = [1, 2, 4, 3, 5]) == 6\n assert candidate(nums = [5, 6, 7, 8, 9]) == 35\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 110\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 54\n assert candidate(nums = [1, 2, 3, 2, 5]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [3, 4, 5, 1, 12, 14, 13]) == 15\n assert candidate(nums = [1, 2, 2, 3, 4]) == 5\n assert candidate(nums = [1, 2, 3, 5, 6]) == 7\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 204\n assert candidate(nums = [1, 2, 4, 5, 6]) == 3\n assert candidate(nums = [7, 8, 9, 10, 12, 13, 14, 15, 16, 17]) == 34\n assert candidate(nums = [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]) == 1265\n assert candidate(nums = [5, 6, 7, 8, 10, 11, 12]) == 26\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 54\n assert candidate(nums = [1, 2, 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\n assert candidate(nums = [1, 2, 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]) == 3\n assert candidate(nums = [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, 1]) == 1274\n assert candidate(nums = [3, 5, 4, 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]) == 31\n assert candidate(nums = [5, 6, 7, 8, 10, 11, 12, 13, 14]) == 26\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [10, 11, 12, 13, 10, 9, 8]) == 46\n assert candidate(nums = [1, 2, 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]) == 3\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]) == 51\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 104\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, 50]) == 1176\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]) == 465\n assert candidate(nums = [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]) == 609\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15]) == 65\n assert candidate(nums = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 21\n assert candidate(nums = [1, 2, 4, 5, 6, 3, 7, 8, 9, 10]) == 11\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 45\n assert candidate(nums = [10, 11, 12, 13, 15, 14, 16, 17, 18, 19]) == 46\n assert candidate(nums = [2, 3, 5, 4, 6, 7, 8, 9, 10, 11]) == 12\n assert candidate(nums = [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]) == 975\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]) == 2\n assert candidate(nums = [1, 2, 3, 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]) == 6\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 315\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 925\n assert candidate(nums = [10, 11, 12, 13, 15, 16, 17, 18, 19, 20]) == 46\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 3, 2, 1]) == 45\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 54\n assert candidate(nums = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12]) == 13\n assert candidate(nums = [2, 3, 4, 1, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1]) == 114\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 14\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15]) == 31\n assert candidate(nums = [10, 11, 12, 13, 14, 20, 21, 22, 23]) == 60\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]) == 4\n assert candidate(nums = [3, 5, 4, 6, 7, 8, 9, 10, 11, 12]) == 13\n assert candidate(nums = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 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]) == 11\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14]) == 3\n assert candidate(nums = [10, 11, 12, 13, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 46\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11, 12, 13]) == 54\n assert candidate(nums = [10, 11, 12, 13, 7, 8, 9]) == 46\n assert candidate(nums = [5, 6, 7, 8, 9, 3, 2, 1]) == 35\n assert candidate(nums = [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]) == 775\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 3, 4, 2, 1]) == 45\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == 52\n assert candidate(nums = [2, 3, 4, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 14\n assert candidate(nums = [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 3\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2]) == 85\n assert candidate(nums = [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]) == 50\n assert candidate(nums = [5, 6, 7, 8, 10, 11, 12, 13, 14, 15]) == 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]) == 210\n assert candidate(nums = [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]) == 275\n assert candidate(nums = [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, 1, 2, 3, 4]) == 1265\n assert candidate(nums = [30, 31, 32, 33, 30, 31, 32, 33]) == 126\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 115\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 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]) == 54\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 165\n assert candidate(nums = [3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 4\n assert candidate(nums = [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 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]) == 495\n assert candidate(nums = [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 1, 2, 3]) == 495\n assert candidate(nums = [49, 50, 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]) == 99\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]) == 325\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 55\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]) == 330\n assert candidate(nums = [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]) == 425\n assert candidate(nums = [5, 6, 7, 8, 3, 4, 2, 1]) == 26\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 1, 2, 3]) == 285\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 55\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 319\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 285\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 209\n assert candidate(nums = [49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 99\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 16\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]) == 1275\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 840\n assert candidate(nums = [20, 21, 22, 23, 24, 15, 16, 17, 18, 19]) == 110\n assert candidate(nums = [3, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13]) == 14\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\n assert candidate(nums = [5, 6, 7, 8, 9, 3, 4, 2, 1]) == 35\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5]) == 840\n assert candidate(nums = [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, 1, 2, 3]) == 1269\n assert candidate(nums = [10, 11, 12, 15, 16, 17, 18]) == 33\n assert candidate(nums = [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]) == 165\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]) == 465\n assert candidate(nums = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 360\n assert candidate(nums = [30, 31, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 61\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, 50]) == 435\n assert candidate(nums = [15, 16, 17, 18, 19, 20, 1, 2, 3, 4]) == 105\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16]) == 17\n", "comparison": "exact"}, "public_tests": ["[1,2,3,2,5]", "[3,4,5,1,12,14,13]"], "hints": ["To find the longest sequential prefix, iterate from left to right. For a fixed i, if nums[i] != nums[i - 1] + 1 then the longest sequential prefix ends at i - 1."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().missingInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:39+00:00", "tests_total": 123, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def missing_integer(nums)", "container": null, "callable": "missing_integer", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2997, "task_id": "minimum-number-of-operations-to-make-array-xor-equal-to-k", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and a positive integer k.\n\nYou can apply the following operation on the array any number of times:\n\n- Choose any element of the array and flip a bit in its binary representation. Flipping a bit means changing a 0 to 1 or vice versa.\n\nReturn the minimum number of operations required to make the bitwise XOR of all elements of the final array equal to k.\n\nNote that you can flip leading zero bits in the binary representation of elements. For example, for the number (101)_2 you can flip the fourth bit and obtain (1101)_2.\n\nExample 1:\n\nInput: nums = [2,1,3,4], k = 1\nOutput: 2\nExplanation: We can do the following operations:\n- Choose element 2 which is 3 == (011)_2, we flip the first bit and we obtain (010)_2 == 2. nums becomes [2,1,2,4].\n- Choose element 0 which is 2 == (010)_2, we flip the third bit and we obtain (110)_2 = 6. nums becomes [6,1,2,4].\nThe XOR of elements of the final array is (6 XOR 1 XOR 2 XOR 4) == 1 == k.\nIt can be shown that we cannot make the XOR equal to k in less than 2 operations.\n\nExample 2:\n\nInput: nums = [2,0,2,0], k = 0\nOutput: 0\nExplanation: The XOR of elements of the array is (2 XOR 0 XOR 2 XOR 0) == 0 == k. So no operation is needed.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^6\n- 0 <= k <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0],k = 2) == 1\n assert candidate(nums = [1, 1, 1, 1],k = 0) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1],k = 63) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 1\n assert candidate(nums = [2, 1, 3, 4],k = 1) == 2\n assert candidate(nums = [1000000, 500000, 250000],k = 125000) == 12\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],k = 15) == 2\n assert candidate(nums = [3, 3, 3, 3],k = 3) == 2\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64],k = 127) == 0\n assert candidate(nums = [1000000],k = 1000000) == 0\n assert candidate(nums = [0, 0, 0, 0],k = 1) == 1\n assert candidate(nums = [0, 0, 0, 0],k = 15) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],k = 7) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [2, 0, 2, 0],k = 0) == 0\n assert candidate(nums = [0, 0, 0, 0],k = 0) == 0\n assert candidate(nums = [15, 27, 33, 45],k = 58) == 2\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 100000],k = 999998) == 8\n assert candidate(nums = [7, 14, 28, 56, 112, 224],k = 112) == 5\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 1022) == 4\n assert candidate(nums = [17, 34, 51, 68, 85],k = 255) == 6\n assert candidate(nums = [123456, 789012, 345678, 901234],k = 67890) == 10\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 1023) == 5\n assert candidate(nums = [7, 13, 15, 21],k = 10) == 3\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1023) == 0\n assert candidate(nums = [15, 7, 3, 1],k = 14) == 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],k = 1) == 1\n assert candidate(nums = [1023, 2047, 4095, 8191],k = 16383) == 12\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 2047) == 0\n assert candidate(nums = [1, 3, 5, 7, 9],k = 15) == 2\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 8) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [1023, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 2047) == 11\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 = 1) == 1\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 0) == 0\n assert candidate(nums = [123456, 654321, 111111, 222222, 333333, 444444],k = 555555) == 9\n assert candidate(nums = [3, 5, 6, 12],k = 7) == 3\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 100000],k = 555555) == 12\n assert candidate(nums = [13, 7, 15, 8, 2],k = 31) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 0) == 5\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 28) == 2\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],k = 112) == 4\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],k = 16383) == 3\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 255) == 8\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 8) == 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],k = 1) == 0\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 10) == 6\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210, 432109, 321098, 210987, 109876, 98765],k = 1000000) == 12\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],k = 1000000) == 8\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930],k = 123456) == 13\n assert candidate(nums = [63, 31, 15, 7, 3, 1],k = 64) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 990) == 7\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 254) == 7\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 2047) == 6\n assert candidate(nums = [15, 15, 15, 15],k = 15) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 31) == 5\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 2048) == 12\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 256) == 1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],k = 1000000) == 0\n assert candidate(nums = [3, 5, 7, 9, 11],k = 15) == 2\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 254) == 3\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],k = 2048) == 10\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20],k = 14) == 3\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 1023) == 1\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111],k = 123456) == 13\n assert candidate(nums = [64, 32, 16, 8, 4, 2, 1],k = 127) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 2047) == 0\n assert candidate(nums = [1, 3, 7, 15, 31],k = 63) == 3\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 65534) == 7\n assert candidate(nums = [3, 5, 7, 9],k = 15) == 3\n assert candidate(nums = [5, 3, 15, 8],k = 10) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 0) == 0\n assert candidate(nums = [15, 31, 63, 127, 255],k = 255) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 31) == 5\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 1024) == 6\n assert candidate(nums = [8, 4, 2, 1, 8, 4, 2, 1, 8, 4, 2, 1, 8, 4, 2, 1],k = 15) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 23) == 0\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],k = 0) == 0\n assert candidate(nums = [500, 501, 502, 503, 504, 505, 506, 507, 508, 509],k = 512) == 2\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000],k = 1000000) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1023) == 10\n assert candidate(nums = [123456, 654321, 789012, 345678, 901234, 234567, 876543, 456789, 543210, 123456],k = 999999) == 10\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 1023) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 4095) == 12\n assert candidate(nums = [7, 7, 7, 7, 7],k = 7) == 0\n", "comparison": "exact"}, "public_tests": ["[2,1,3,4]\n1", "[2,0,2,0]\n0"], "hints": ["Calculate the bitwise XOR of all elements of the original array and compare it to k in their binary representation.", "For each different bit between the bitwise XOR of elements of the original array and k we have to flip exactly one bit of an element in nums to make that bit equal."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:41+00:00", "tests_total": 115, "tests_dropped": 28, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums, k)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2998, "task_id": "minimum-number-of-operations-to-make-x-and-y-equal", "difficulty": "Medium", "problem_description": "You are given two positive integers x and y.\n\nIn one operation, you can do one of the four following operations:\n\n1. Divide x by 11 if x is a multiple of 11.\n2. Divide x by 5 if x is a multiple of 5.\n3. Decrement x by 1.\n4. Increment x by 1.\n\nReturn the minimum number of operations required to make x and y equal.\n\nExample 1:\n\nInput: x = 26, y = 1\nOutput: 3\nExplanation: We can make 26 equal to 1 by applying the following operations:\n1. Decrement x by 1\n2. Divide x by 5\n3. Divide x by 5\nIt can be shown that 3 is the minimum number of operations required to make 26 equal to 1.\n\nExample 2:\n\nInput: x = 54, y = 2\nOutput: 4\nExplanation: We can make 54 equal to 2 by applying the following operations:\n1. Increment x by 1\n2. Divide x by 11\n3. Divide x by 5\n4. Increment x by 1\nIt can be shown that 4 is the minimum number of operations required to make 54 equal to 2.\n\nExample 3:\n\nInput: x = 25, y = 30\nOutput: 5\nExplanation: We can make 25 equal to 30 by applying the following operations:\n1. Increment x by 1\n2. Increment x by 1\n3. Increment x by 1\n4. Increment x by 1\n5. Increment x by 1\nIt can be shown that 5 is the minimum number of operations required to make 25 equal to 30.\n\nConstraints:\n\n- 1 <= x, y <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(x = 1,y = 10000) == 9999\n assert candidate(x = 11,y = 5) == 5\n assert candidate(x = 10000,y = 1) == 8\n assert candidate(x = 111,y = 11) == 3\n assert candidate(x = 77,y = 7) == 1\n assert candidate(x = 500,y = 20) == 2\n assert candidate(x = 25,y = 30) == 5\n assert candidate(x = 11,y = 1) == 1\n assert candidate(x = 55,y = 11) == 1\n assert candidate(x = 2,y = 20) == 18\n assert candidate(x = 1234,y = 4321) == 3087\n assert candidate(x = 100,y = 1) == 4\n assert candidate(x = 26,y = 1) == 3\n assert candidate(x = 54,y = 2) == 4\n assert candidate(x = 99,y = 9) == 1\n assert candidate(x = 9999,y = 9999) == 0\n assert candidate(x = 55,y = 10) == 2\n assert candidate(x = 10,y = 10) == 0\n assert candidate(x = 55,y = 5) == 1\n assert candidate(x = 100,y = 10) == 3\n assert candidate(x = 5,y = 1) == 1\n assert candidate(x = 15,y = 6) == 4\n assert candidate(x = 1,y = 100) == 99\n assert candidate(x = 1111,y = 5555) == 4444\n assert candidate(x = 6666,y = 3333) == 2002\n assert candidate(x = 9876,y = 5432) == 3459\n assert candidate(x = 8888,y = 111) == 45\n assert candidate(x = 3000,y = 2500) == 500\n assert candidate(x = 1111,y = 100) == 2\n assert candidate(x = 7777,y = 6666) == 1111\n assert candidate(x = 100,y = 2500) == 2400\n assert candidate(x = 5555,y = 22) == 6\n assert candidate(x = 1234,y = 8765) == 7531\n assert candidate(x = 7000,y = 3500) == 2101\n assert candidate(x = 9876,y = 1234) == 339\n assert candidate(x = 55,y = 15) == 5\n assert candidate(x = 3333,y = 6666) == 3333\n assert candidate(x = 3333,y = 33) == 12\n assert candidate(x = 1010,y = 10) == 7\n assert candidate(x = 550,y = 10) == 2\n assert candidate(x = 100,y = 10000) == 9900\n assert candidate(x = 6666,y = 66) == 14\n assert candidate(x = 5000,y = 5005) == 5\n assert candidate(x = 5000,y = 50) == 13\n assert candidate(x = 441,y = 121) == 35\n assert candidate(x = 5000,y = 2500) == 1501\n assert candidate(x = 330,y = 3) == 5\n assert candidate(x = 9999,y = 10000) == 1\n assert candidate(x = 5000,y = 6000) == 1000\n assert candidate(x = 9999,y = 1000) == 92\n assert candidate(x = 500,y = 1000) == 500\n assert candidate(x = 2222,y = 2222) == 0\n assert candidate(x = 9000,y = 9009) == 9\n assert candidate(x = 1000,y = 345) == 146\n assert candidate(x = 4444,y = 4445) == 1\n assert candidate(x = 220,y = 385) == 165\n assert candidate(x = 300,y = 105) == 46\n assert candidate(x = 9999,y = 1) == 9\n assert candidate(x = 1234,y = 654) == 409\n assert candidate(x = 5000,y = 5) == 7\n assert candidate(x = 55,y = 77) == 22\n assert candidate(x = 4999,y = 5001) == 2\n assert candidate(x = 1000,y = 10000) == 9000\n assert candidate(x = 3000,y = 2990) == 10\n assert candidate(x = 300,y = 150) == 91\n assert candidate(x = 220,y = 20) == 1\n assert candidate(x = 4567,y = 890) == 26\n assert candidate(x = 1111,y = 1000) == 111\n assert candidate(x = 1000,y = 995) == 5\n assert candidate(x = 4444,y = 44) == 12\n assert candidate(x = 123,y = 321) == 198\n assert candidate(x = 1000,y = 999) == 1\n assert candidate(x = 6000,y = 1000) == 201\n assert candidate(x = 880,y = 15) == 3\n assert candidate(x = 880,y = 55) == 23\n assert candidate(x = 1100,y = 50) == 8\n assert candidate(x = 1331,y = 110) == 12\n assert candidate(x = 1000,y = 990) == 10\n assert candidate(x = 7777,y = 2222) == 670\n assert candidate(x = 1100,y = 10) == 4\n assert candidate(x = 4000,y = 2000) == 1201\n assert candidate(x = 9876,y = 4321) == 2348\n assert candidate(x = 9876,y = 4567) == 2594\n assert candidate(x = 1234,y = 5678) == 4444\n assert candidate(x = 495,y = 660) == 165\n assert candidate(x = 6110,y = 55) == 12\n assert candidate(x = 1111,y = 222) == 2\n assert candidate(x = 45,y = 33) == 12\n assert candidate(x = 9876,y = 11) == 11\n assert candidate(x = 5500,y = 220) == 2\n assert candidate(x = 1024,y = 128) == 37\n assert candidate(x = 24,y = 29) == 5\n assert candidate(x = 8000,y = 8008) == 8\n assert candidate(x = 88,y = 22) == 7\n assert candidate(x = 495,y = 4) == 3\n assert candidate(x = 7000,y = 7000) == 0\n assert candidate(x = 825,y = 17) == 4\n assert candidate(x = 5555,y = 5) == 6\n assert candidate(x = 1234,y = 88) == 27\n assert candidate(x = 1024,y = 512) == 309\n assert candidate(x = 9999,y = 8888) == 1111\n assert candidate(x = 8000,y = 2000) == 401\n assert candidate(x = 5432,y = 6789) == 1357\n assert candidate(x = 111,y = 55) == 35\n assert candidate(x = 7500,y = 7400) == 100\n assert candidate(x = 242,y = 11) == 7\n assert candidate(x = 121,y = 1) == 2\n assert candidate(x = 6105,y = 1221) == 1\n assert candidate(x = 3333,y = 999) == 335\n assert candidate(x = 2020,y = 202) == 23\n assert candidate(x = 121,y = 110) == 11\n assert candidate(x = 4321,y = 9876) == 5555\n assert candidate(x = 4444,y = 8888) == 4444\n assert candidate(x = 2222,y = 222) == 21\n assert candidate(x = 1234,y = 890) == 344\n assert candidate(x = 7,y = 143) == 136\n assert candidate(x = 7777,y = 77) == 18\n assert candidate(x = 5555,y = 1111) == 1\n assert candidate(x = 8888,y = 7777) == 1111\n assert candidate(x = 9876,y = 123) == 48\n assert candidate(x = 2000,y = 10000) == 8000\n assert candidate(x = 8000,y = 8010) == 10\n assert candidate(x = 88,y = 13) == 6\n assert candidate(x = 7777,y = 1111) == 405\n assert candidate(x = 3333,y = 4444) == 1111\n assert candidate(x = 6000,y = 6005) == 5\n assert candidate(x = 9999,y = 9990) == 9\n assert candidate(x = 2222,y = 7777) == 5555\n assert candidate(x = 77,y = 22) == 10\n assert candidate(x = 2000,y = 10) == 9\n assert candidate(x = 1111,y = 9999) == 8888\n assert candidate(x = 1234,y = 987) == 247\n assert candidate(x = 8888,y = 1111) == 304\n", "comparison": "exact"}, "public_tests": ["26\n1", "54\n2", "25\n30"], "hints": ["The only way to make x larger is to increase it by 1 so if y >= x the answer is y - x.", "For y < x, x - y is always a candidate answer since we can repeatedly decrease x by one to reach y.", "We can also increase x and then use the division operations. For example, if x = 10 and y = 1, we can increment x by 1 then divide it by 11.", "Find an upper bound U on the maximum value of x we will reach an optimal solution. Since all values of x will be in the range [1, U], we can use BFS to find the answer.", "One possible upper bound on x is U = x + (x - y) . To reach any number strictly greater than U from x, we will need more than x - y operations which is not optimal since we can always reach y in x - y operations."], "metadata": {"canonical_parameter_names": ["x", "y"], "leetcode_dataset_entry_point": "Solution().minimumOperationsToMakeEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:43+00:00", "tests_total": 133, "tests_dropped": 0, "flags": [], "topic_tags": ["dynamic-programming", "breadth-first-search", "memoization"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations_to_make_equal(x, y)", "container": null, "callable": "minimum_operations_to_make_equal", "parameters": [{"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2999, "task_id": "count-the-number-of-powerful-integers", "difficulty": "Hard", "problem_description": "You are given three integers start, finish, and limit. You are also given a 0-indexed string s representing a positive integer.\n\nA positive integer x is called powerful if it ends with s (in other words, s is a suffix of x) and each digit in x is at most limit.\n\nReturn the total number of powerful integers in the range [start..finish].\n\nA string x is a suffix of a string y if and only if x is a substring of y that starts from some index (including 0) in y and extends to the index y.length - 1. For example, 25 is a suffix of 5125 whereas 512 is not.\n\nExample 1:\n\nInput: start = 1, finish = 6000, limit = 4, s = \"124\"\nOutput: 5\nExplanation: The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit <= 4, and \"124\" as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.\nIt can be shown that there are only 5 powerful integers in this range.\n\nExample 2:\n\nInput: start = 15, finish = 215, limit = 6, s = \"10\"\nOutput: 2\nExplanation: The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit <= 6, and \"10\" as a suffix.\nIt can be shown that there are only 2 powerful integers in this range.\n\nExample 3:\n\nInput: start = 1000, finish = 2000, limit = 4, s = \"3000\"\nOutput: 0\nExplanation: All integers in the range [1000..2000] are smaller than 3000, hence \"3000\" cannot be a suffix of any integer in this range.\n\nConstraints:\n\n- 1 <= start <= finish <= 10^15\n- 1 <= limit <= 9\n- 1 <= s.length <= floor(log_10(finish)) + 1\n- s only consists of numeric digits which are at most limit.\n- s does not have leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(start = 100,finish = 1000,limit = 1,s = \"00\") == 2\n assert candidate(start = 1111,finish = 2222,limit = 2,s = \"11\") == 5\n assert candidate(start = 500,finish = 5000,limit = 7,s = \"50\") == 35\n assert candidate(start = 10000,finish = 99999,limit = 8,s = \"8888\") == 8\n assert candidate(start = 1,finish = 6000,limit = 4,s = \"124\") == 5\n assert candidate(start = 111,finish = 999,limit = 9,s = \"11\") == 9\n assert candidate(start = 1234,finish = 98765,limit = 8,s = \"4321\") == 9\n assert candidate(start = 100,finish = 1000,limit = 5,s = \"00\") == 6\n assert candidate(start = 1234,finish = 98765,limit = 9,s = \"567\") == 98\n assert candidate(start = 5,finish = 55,limit = 5,s = \"5\") == 6\n assert candidate(start = 1,finish = 1000000000000000,limit = 9,s = \"999\") == 1000000000000\n assert candidate(start = 500,finish = 1500,limit = 5,s = \"50\") == 6\n assert candidate(start = 1,finish = 999999999999999,limit = 9,s = \"999\") == 1000000000000\n assert candidate(start = 5,finish = 500,limit = 3,s = \"1\") == 15\n assert candidate(start = 100,finish = 1000,limit = 7,s = \"00\") == 8\n assert candidate(start = 15,finish = 215,limit = 6,s = \"10\") == 2\n assert candidate(start = 123,finish = 456,limit = 5,s = \"34\") == 4\n assert candidate(start = 1000,finish = 2000,limit = 4,s = \"3000\") == 0\n assert candidate(start = 5,finish = 5,limit = 5,s = \"5\") == 1\n assert candidate(start = 1,finish = 10,limit = 1,s = \"1\") == 1\n assert candidate(start = 200,finish = 800,limit = 2,s = \"2\") == 3\n assert candidate(start = 1234,finish = 4321,limit = 7,s = \"34\") == 25\n assert candidate(start = 10,finish = 100,limit = 1,s = \"0\") == 2\n assert candidate(start = 1234,finish = 123456,limit = 7,s = \"34\") == 659\n assert candidate(start = 1,finish = 1000000000000000,limit = 1,s = \"1\") == 16384\n assert candidate(start = 10,finish = 100,limit = 3,s = \"0\") == 4\n assert candidate(start = 10,finish = 100,limit = 3,s = \"1\") == 3\n assert candidate(start = 100,finish = 200,limit = 2,s = \"00\") == 2\n assert candidate(start = 10000,finish = 100000,limit = 1,s = \"0000\") == 2\n assert candidate(start = 999,finish = 9999,limit = 9,s = \"999\") == 10\n assert candidate(start = 10,finish = 100,limit = 3,s = \"2\") == 3\n assert candidate(start = 500,finish = 5000,limit = 5,s = \"50\") == 25\n assert candidate(start = 123456789,finish = 987654321,limit = 8,s = \"123\") == 456707\n assert candidate(start = 1000000000000,finish = 10000000000000,limit = 6,s = \"6666\") == 34588806\n assert candidate(start = 1000000000,finish = 1000000000,limit = 9,s = \"0\") == 1\n assert candidate(start = 123,finish = 321,limit = 1,s = \"1\") == 0\n assert candidate(start = 1,finish = 1000000000000000,limit = 7,s = \"777777777777777\") == 1\n assert candidate(start = 10000000000,finish = 99999999999,limit = 4,s = \"44444\") == 12500\n assert candidate(start = 500000000,finish = 5000000000,limit = 4,s = \"444444\") == 500\n assert candidate(start = 1234567890,finish = 2345678901,limit = 7,s = \"789\") == 299592\n assert candidate(start = 555555555555555,finish = 666666666666666,limit = 5,s = \"555\") == 1\n assert candidate(start = 1000000000,finish = 9000000000,limit = 4,s = \"4444\") == 12500\n assert candidate(start = 1111111111,finish = 2222222222,limit = 2,s = \"222\") == 1094\n assert candidate(start = 123456789,finish = 987654321,limit = 8,s = \"876\") == 456708\n assert candidate(start = 123456789,finish = 9876543210,limit = 8,s = \"8765\") == 523138\n assert candidate(start = 111111111111111,finish = 222222222222222,limit = 2,s = \"2222222222\") == 122\n assert candidate(start = 100000000000000,finish = 200000000000000,limit = 6,s = \"666666\") == 5764801\n assert candidate(start = 5000,finish = 50000,limit = 5,s = \"25\") == 150\n assert candidate(start = 1000000000,finish = 2000000000,limit = 9,s = \"999999\") == 1000\n assert candidate(start = 123456789,finish = 123456789,limit = 9,s = \"999\") == 0\n assert candidate(start = 123456789,finish = 987654321,limit = 4,s = \"789\") == 10750\n assert candidate(start = 1000000000,finish = 2000000000,limit = 6,s = \"12345\") == 2401\n assert candidate(start = 123456789,finish = 9876543210,limit = 4,s = \"4321\") == 14650\n assert candidate(start = 123,finish = 456789,limit = 6,s = \"678\") == 238\n assert candidate(start = 500000000,finish = 600000000,limit = 4,s = \"40000\") == 0\n assert candidate(start = 1000000000,finish = 1500000000,limit = 3,s = \"321\") == 4096\n assert candidate(start = 100000000,finish = 200000000,limit = 9,s = \"90000000\") == 1\n assert candidate(start = 10000,finish = 999999999,limit = 5,s = \"5555\") == 7775\n assert candidate(start = 1000000000,finish = 10000000000,limit = 6,s = \"6000000\") == 294\n assert candidate(start = 123456789,finish = 987654321,limit = 8,s = \"456\") == 456707\n assert candidate(start = 100000,finish = 9999999999,limit = 5,s = \"2500\") == 46650\n assert candidate(start = 100,finish = 999,limit = 1,s = \"1\") == 2\n assert candidate(start = 1000000000,finish = 2000000000,limit = 3,s = \"123\") == 4096\n assert candidate(start = 1000000000,finish = 9999999999,limit = 5,s = \"4444\") == 38880\n assert candidate(start = 1,finish = 1000000000000,limit = 1,s = \"1\") == 2048\n assert candidate(start = 1,finish = 10000000000,limit = 2,s = \"12\") == 6561\n assert candidate(start = 99999999,finish = 1000000000,limit = 9,s = \"999\") == 900001\n assert candidate(start = 1000000,finish = 10000000,limit = 3,s = \"333\") == 192\n assert candidate(start = 1000000000000,finish = 9999999999999,limit = 8,s = \"8888\") == 344373768\n assert candidate(start = 100000,finish = 999999,limit = 5,s = \"2500\") == 30\n assert candidate(start = 10000,finish = 15000,limit = 3,s = \"3000\") == 1\n assert candidate(start = 500000000,finish = 800000000,limit = 6,s = \"567\") == 33614\n assert candidate(start = 111111111,finish = 222222222,limit = 2,s = \"222\") == 365\n assert candidate(start = 100000,finish = 999999,limit = 4,s = \"4444\") == 20\n assert candidate(start = 123456789012345,finish = 987654321098765,limit = 7,s = \"789\") == 57499975680\n assert candidate(start = 1111,finish = 2222,limit = 1,s = \"11\") == 1\n assert candidate(start = 100000000000,finish = 900000000000,limit = 3,s = \"333\") == 196608\n assert candidate(start = 111111111111111,finish = 222222222222222,limit = 2,s = \"21\") == 797162\n assert candidate(start = 100000000000000,finish = 200000000000000,limit = 1,s = \"1\") == 8192\n assert candidate(start = 500000000000000,finish = 600000000000000,limit = 5,s = \"500\") == 362797056\n assert candidate(start = 10000000000000,finish = 50000000000000,limit = 4,s = \"4444444\") == 62500\n assert candidate(start = 5000000,finish = 5500000,limit = 5,s = \"5000\") == 30\n assert candidate(start = 123456789012345,finish = 234567890123456,limit = 2,s = \"222\") == 177147\n assert candidate(start = 100000000000000,finish = 200000000000000,limit = 7,s = \"7654321\") == 2097152\n assert candidate(start = 123123123,finish = 987987987,limit = 8,s = \"876\") == 456981\n assert candidate(start = 222222222222222,finish = 333333333333333,limit = 3,s = \"3333333333\") == 342\n assert candidate(start = 1000000000,finish = 9000000000,limit = 6,s = \"666\") == 705894\n assert candidate(start = 100000000000000,finish = 300000000000000,limit = 5,s = \"55555555555555\") == 2\n assert candidate(start = 10000,finish = 99999,limit = 2,s = \"22\") == 18\n assert candidate(start = 1000000000,finish = 10000000000,limit = 1,s = \"1\") == 256\n assert candidate(start = 10000,finish = 20000,limit = 3,s = \"111\") == 4\n assert candidate(start = 1000000000000,finish = 1000000000000,limit = 9,s = \"999999999999\") == 0\n assert candidate(start = 50000,finish = 150000,limit = 5,s = \"2500\") == 6\n assert candidate(start = 1000000000000000,finish = 1000000000000000,limit = 9,s = \"999999999999999\") == 0\n assert candidate(start = 123456789,finish = 2100000000,limit = 6,s = \"6789\") == 32748\n assert candidate(start = 1000000000000,finish = 9999999999999,limit = 2,s = \"21\") == 118098\n assert candidate(start = 123456789012345,finish = 987654321098765,limit = 7,s = \"765\") == 57499975680\n assert candidate(start = 123456789012345,finish = 987654321098765,limit = 6,s = \"654321\") == 32507139\n assert candidate(start = 100000000000000,finish = 200000000000000,limit = 3,s = \"100\") == 4194304\n assert candidate(start = 50000,finish = 60000,limit = 5,s = \"500\") == 6\n assert candidate(start = 123456789123,finish = 987654321987,limit = 9,s = \"987\") == 864197533\n assert candidate(start = 123456789012,finish = 987654321012,limit = 5,s = \"5555\") == 1276560\n assert candidate(start = 500,finish = 5000,limit = 3,s = \"300\") == 3\n assert candidate(start = 12345,finish = 67890,limit = 7,s = \"789\") == 46\n assert candidate(start = 555555555,finish = 666666666,limit = 9,s = \"555\") == 111112\n assert candidate(start = 1000000,finish = 2000000,limit = 2,s = \"222\") == 27\n assert candidate(start = 9000000000,finish = 9999999999,limit = 9,s = \"9999\") == 100000\n assert candidate(start = 1234567890,finish = 1234567890123,limit = 6,s = \"6789\") == 7823592\n assert candidate(start = 1111,finish = 3333,limit = 1,s = \"11\") == 1\n assert candidate(start = 123456789012345,finish = 987654321098765,limit = 7,s = \"7654321\") == 14038080\n assert candidate(start = 5000,finish = 15000,limit = 3,s = \"300\") == 4\n assert candidate(start = 1,finish = 1000000000000000,limit = 4,s = \"444444444444444\") == 1\n assert candidate(start = 100000,finish = 500000,limit = 7,s = \"7777\") == 32\n assert candidate(start = 100000000000000,finish = 200000000000000,limit = 8,s = \"8888888888\") == 6561\n assert candidate(start = 5000,finish = 80000,limit = 5,s = \"250\") == 31\n assert candidate(start = 5000000000,finish = 6000000000,limit = 6,s = \"5555\") == 16807\n assert candidate(start = 123456789,finish = 987654321,limit = 6,s = \"666\") == 94773\n assert candidate(start = 1000000,finish = 2000000,limit = 2,s = \"200\") == 27\n assert candidate(start = 500,finish = 2500,limit = 4,s = \"444\") == 2\n assert candidate(start = 100000000000000,finish = 1000000000000000,limit = 4,s = \"43210\") == 7812500\n assert candidate(start = 123456789012345,finish = 123456789012345,limit = 9,s = \"123456789\") == 0\n assert candidate(start = 1000000000000,finish = 4000000000000,limit = 3,s = \"333333333333\") == 3\n assert candidate(start = 5000000,finish = 6000000,limit = 4,s = \"4000\") == 0\n assert candidate(start = 111111111111111,finish = 222222222222222,limit = 1,s = \"1\") == 1\n assert candidate(start = 100000000,finish = 600000000,limit = 2,s = \"222222222\") == 1\n assert candidate(start = 500000000000,finish = 5000000000000,limit = 7,s = \"777\") == 587202560\n assert candidate(start = 10000000000,finish = 50000000000,limit = 4,s = \"4444444444\") == 4\n assert candidate(start = 10000000000,finish = 11000000000,limit = 3,s = \"3000\") == 1024\n assert candidate(start = 123456789,finish = 987654321,limit = 4,s = \"3456\") == 2150\n assert candidate(start = 1000000000000000,finish = 1000000000000000,limit = 9,s = \"1\") == 0\n assert candidate(start = 111111111111111,finish = 999999999999999,limit = 9,s = \"999999999999999\") == 1\n assert candidate(start = 111111111,finish = 222222222,limit = 2,s = \"123\") == 365\n assert candidate(start = 123456789012345,finish = 987654321098765,limit = 7,s = \"765432\") == 112304640\n assert candidate(start = 222222222222222,finish = 333333333333333,limit = 3,s = \"333\") == 5592406\n", "comparison": "exact"}, "public_tests": ["1\n6000\n4\n\"124\"", "15\n215\n6\n\"10\"", "1000\n2000\n4\n\"3000\""], "hints": ["We can use digit DP to count powerful integers in the range [1, x].", "Let dp[i][j] be the number of integers that have i digits (with allowed leading 0s) and j refers to the comparison between the current number and the prefix of x, j == 0 if the i-digit number formed currently is identical to the leftmost i digits of x, else if j ==1 it means the i-digit number is smaller than the leftmost i digits of x.", "The answer is count[finish] - count[start - 1], where count[i] refers to the number of powerful integers in the range [1..i]."], "metadata": {"canonical_parameter_names": ["start", "finish", "limit", "s"], "leetcode_dataset_entry_point": "Solution().numberOfPowerfulInt", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:46+00:00", "tests_total": 147, "tests_dropped": 13, "flags": [], "topic_tags": ["math", "string", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_powerful_int(start, finish, limit, s)", "container": null, "callable": "number_of_powerful_int", "parameters": [{"name": "start", "type": "Integer"}, {"name": "finish", "type": "Integer"}, {"name": "limit", "type": "Integer"}, {"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3000, "task_id": "maximum-area-of-longest-diagonal-rectangle", "difficulty": "Easy", "problem_description": "You are given a 2D 0-indexed integer array dimensions.\n\nFor all indices i, 0 <= i < dimensions.length, dimensions[i][0] represents the length and dimensions[i][1] represents the width of the rectangle i.\n\nReturn the area of the rectangle having the longest diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the maximum area.\n\nExample 1:\n\nInput: dimensions = [[9,3],[8,6]]\nOutput: 48\nExplanation:\nFor index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈ 9.487.\nFor index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10.\nSo, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 * 6 = 48.\n\nExample 2:\n\nInput: dimensions = [[3,4],[4,3]]\nOutput: 12\nExplanation: Length of diagonal is the same for both which is 5, so maximum area = 12.\n\nConstraints:\n\n- 1 <= dimensions.length <= 100\n- dimensions[i].length == 2\n- 1 <= dimensions[i][0], dimensions[i][1] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(dimensions = [[5, 12], [13, 88], [20, 21]]) == 1144\n assert candidate(dimensions = [[6, 8], [8, 6], [10, 24]]) == 240\n assert candidate(dimensions = [[9, 3], [8, 6]]) == 48\n assert candidate(dimensions = [[7, 24], [24, 7], [10, 10]]) == 168\n assert candidate(dimensions = [[1, 1], [1, 1], [1, 1]]) == 1\n assert candidate(dimensions = [[100, 1], [1, 100]]) == 100\n assert candidate(dimensions = [[1, 2], [2, 1], [3, 4], [4, 3]]) == 12\n assert candidate(dimensions = [[5, 12], [12, 5], [8, 8]]) == 60\n assert candidate(dimensions = [[10, 10], [15, 15], [20, 20]]) == 400\n assert candidate(dimensions = [[10, 24], [24, 10], [15, 20]]) == 240\n assert candidate(dimensions = [[1, 1], [2, 2], [3, 3]]) == 9\n assert candidate(dimensions = [[5, 12], [12, 5], [8, 15]]) == 120\n assert candidate(dimensions = [[10, 10], [10, 10], [10, 10]]) == 100\n assert candidate(dimensions = [[5, 12], [12, 5], [8, 6]]) == 60\n assert candidate(dimensions = [[3, 4], [4, 3]]) == 12\n assert candidate(dimensions = [[5, 12], [12, 5], [8, 15], [15, 8], [7, 24], [24, 7], [9, 40], [40, 9], [11, 60], [60, 11]]) == 660\n assert candidate(dimensions = [[9, 40], [40, 9], [12, 35], [35, 12], [15, 36], [36, 15]]) == 360\n assert candidate(dimensions = [[20, 21], [19, 22], [21, 20], [22, 19]]) == 418\n assert candidate(dimensions = [[48, 55], [60, 80], [33, 56], [77, 36]]) == 4800\n assert candidate(dimensions = [[99, 1], [1, 99], [45, 55]]) == 99\n assert candidate(dimensions = [[10, 24], [24, 10], [7, 24], [24, 7]]) == 240\n assert candidate(dimensions = [[12, 5], [7, 24], [9, 40]]) == 360\n assert candidate(dimensions = [[99, 1], [1, 99], [49, 51], [51, 49], [50, 50], [33, 66], [66, 33]]) == 99\n assert candidate(dimensions = [[10, 10], [15, 20], [20, 15], [10, 25], [25, 10]]) == 250\n assert candidate(dimensions = [[60, 80], [80, 60], [48, 55], [55, 48]]) == 4800\n assert candidate(dimensions = [[20, 21], [21, 20], [15, 20], [20, 15], [18, 24], [24, 18]]) == 432\n assert candidate(dimensions = [[10, 24], [7, 24], [24, 10]]) == 240\n assert candidate(dimensions = [[4, 1], [1, 4], [3, 5], [5, 3], [2, 6], [6, 2], [7, 1], [1, 7], [8, 2], [2, 8]]) == 16\n assert candidate(dimensions = [[50, 50], [40, 60], [60, 40], [30, 70], [70, 30]]) == 2100\n assert candidate(dimensions = [[12, 16], [15, 20], [7, 24], [8, 15]]) == 300\n assert candidate(dimensions = [[66, 68], [67, 67], [65, 69], [68, 66], [69, 65]]) == 4485\n assert candidate(dimensions = [[99, 1], [1, 99], [50, 50], [45, 45], [55, 55]]) == 99\n assert candidate(dimensions = [[1, 100], [100, 1], [50, 50], [25, 75], [75, 25], [60, 80], [80, 60]]) == 100\n assert candidate(dimensions = [[45, 55], [55, 45], [30, 70], [70, 30], [60, 60], [20, 80], [80, 20], [10, 90], [90, 10]]) == 900\n assert candidate(dimensions = [[3, 4], [4, 3], [5, 12], [12, 5], [8, 15], [15, 8]]) == 120\n assert candidate(dimensions = [[7, 24], [24, 7], [3, 4], [4, 3]]) == 168\n assert candidate(dimensions = [[50, 50], [51, 49], [49, 51], [30, 40], [40, 30], [25, 60], [60, 25]]) == 2499\n assert candidate(dimensions = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90]]) == 8100\n assert candidate(dimensions = [[20, 21], [21, 20], [19, 22], [22, 19], [18, 23], [23, 18]]) == 414\n assert candidate(dimensions = [[10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15]]) == 225\n assert candidate(dimensions = [[80, 15], [15, 80], [75, 20], [20, 75], [70, 25], [25, 70]]) == 1200\n assert candidate(dimensions = [[99, 1], [1, 99], [45, 45], [23, 77]]) == 99\n assert candidate(dimensions = [[50, 50], [51, 51], [49, 49], [48, 48], [52, 52], [53, 53], [54, 54]]) == 2916\n assert candidate(dimensions = [[10, 1], [9, 12], [12, 9], [8, 15], [15, 8], [7, 18], [18, 7]]) == 126\n assert candidate(dimensions = [[10, 6], [6, 10], [8, 15], [15, 8], [12, 5], [5, 12]]) == 120\n assert candidate(dimensions = [[99, 1], [1, 99], [45, 45], [50, 50]]) == 99\n assert candidate(dimensions = [[33, 56], [56, 33], [45, 60], [60, 45], [28, 96], [96, 28], [55, 72], [72, 55]]) == 2688\n assert candidate(dimensions = [[50, 50], [40, 60], [30, 70], [20, 80]]) == 1600\n assert candidate(dimensions = [[50, 50], [60, 80], [80, 60], [45, 45], [70, 70]]) == 4800\n assert candidate(dimensions = [[10, 24], [24, 10], [15, 20], [20, 15], [12, 35], [35, 12], [16, 30], [30, 16], [18, 24], [24, 18]]) == 420\n assert candidate(dimensions = [[8, 6], [6, 8], [5, 5], [7, 7], [9, 9]]) == 81\n assert candidate(dimensions = [[1, 100], [100, 1], [50, 50], [75, 25], [25, 75]]) == 100\n assert candidate(dimensions = [[7, 24], [24, 7], [8, 15], [15, 8], [3, 4], [4, 3], [10, 24], [24, 10]]) == 240\n assert candidate(dimensions = [[1, 100], [100, 1], [50, 50], [30, 70], [70, 30], [20, 80], [80, 20], [10, 90], [90, 10], [45, 55], [55, 45], [60, 60], [25, 60], [60, 25]]) == 100\n assert candidate(dimensions = [[33, 56], [56, 33], [40, 42], [42, 40], [48, 55], [55, 48]]) == 2640\n assert candidate(dimensions = [[8, 15], [15, 8], [7, 24], [24, 7], [5, 12], [12, 5], [9, 40], [40, 9]]) == 360\n assert candidate(dimensions = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 100\n assert candidate(dimensions = [[99, 1], [1, 99], [50, 50], [60, 80], [80, 60]]) == 4800\n assert candidate(dimensions = [[5, 12], [12, 5], [8, 15], [15, 8]]) == 120\n assert candidate(dimensions = [[8, 15], [15, 8], [7, 24], [24, 7], [12, 16], [16, 12], [9, 40], [40, 9], [6, 72], [72, 6]]) == 432\n assert candidate(dimensions = [[97, 1], [1, 97], [98, 2], [2, 98], [50, 50]]) == 196\n assert candidate(dimensions = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]]) == 240\n assert candidate(dimensions = [[15, 20], [20, 15], [25, 25]]) == 625\n assert candidate(dimensions = [[48, 55], [55, 48], [60, 80], [80, 60]]) == 4800\n assert candidate(dimensions = [[45, 55], [55, 45], [40, 60], [60, 40], [35, 65], [65, 35]]) == 2275\n assert candidate(dimensions = [[6, 8], [8, 6], [10, 24], [24, 10], [15, 20], [20, 15]]) == 240\n assert candidate(dimensions = [[6, 8], [8, 6], [5, 12], [12, 5], [9, 40], [40, 9], [35, 12], [12, 35], [7, 24], [24, 7]]) == 360\n assert candidate(dimensions = [[99, 1], [1, 99], [90, 40], [40, 90], [50, 50], [60, 60]]) == 99\n assert candidate(dimensions = [[33, 56], [56, 33], [48, 55], [55, 48], [60, 80], [80, 60], [77, 36], [36, 77]]) == 4800\n assert candidate(dimensions = [[30, 40], [40, 30], [25, 50], [50, 25], [20, 60], [60, 20]]) == 1200\n assert candidate(dimensions = [[1, 100], [100, 1], [50, 50], [40, 60], [60, 40], [30, 70], [70, 30]]) == 100\n assert candidate(dimensions = [[10, 24], [24, 10], [15, 20], [20, 15], [7, 24], [24, 7]]) == 240\n assert candidate(dimensions = [[3, 4], [6, 8], [5, 12], [8, 15]]) == 120\n assert candidate(dimensions = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60]]) == 3600\n assert candidate(dimensions = [[33, 56], [56, 33], [28, 45], [45, 28], [60, 80], [80, 60]]) == 4800\n assert candidate(dimensions = [[33, 56], [56, 33], [40, 40], [30, 40], [40, 30]]) == 1848\n assert candidate(dimensions = [[10, 24], [7, 24], [24, 10], [15, 20], [30, 40], [25, 60], [60, 25]]) == 1500\n assert candidate(dimensions = [[50, 50], [40, 80], [60, 40], [30, 70]]) == 3200\n assert candidate(dimensions = [[99, 1], [1, 99], [50, 50], [40, 70], [70, 40]]) == 99\n assert candidate(dimensions = [[12, 16], [16, 12], [10, 10], [20, 20]]) == 400\n assert candidate(dimensions = [[10, 10], [15, 15], [20, 20], [25, 25], [30, 30]]) == 900\n assert candidate(dimensions = [[30, 40], [40, 30], [35, 35], [25, 25], [45, 45]]) == 2025\n assert candidate(dimensions = [[1, 100], [100, 1], [50, 50], [25, 75], [75, 25], [20, 80], [80, 20], [30, 70], [70, 30]]) == 100\n assert candidate(dimensions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]]) == 144\n assert candidate(dimensions = [[6, 8], [8, 6], [7, 24], [24, 7], [15, 20], [20, 15], [12, 16], [16, 12]]) == 300\n assert candidate(dimensions = [[8, 15], [15, 8], [7, 24], [24, 7], [6, 8], [8, 6]]) == 168\n assert candidate(dimensions = [[99, 1], [98, 2], [97, 3], [96, 4], [95, 5]]) == 99\n assert candidate(dimensions = [[3, 4], [4, 3], [6, 8], [8, 6], [5, 12], [12, 5], [7, 24], [24, 7]]) == 168\n assert candidate(dimensions = [[15, 20], [20, 15], [10, 25], [25, 10]]) == 250\n assert candidate(dimensions = [[5, 12], [12, 5], [9, 40], [40, 9], [35, 12], [12, 35]]) == 360\n assert candidate(dimensions = [[60, 80], [80, 60], [70, 70], [50, 90], [90, 50], [65, 75], [75, 65]]) == 4500\n assert candidate(dimensions = [[10, 24], [20, 21], [15, 36], [30, 40], [12, 16], [8, 15]]) == 1200\n assert candidate(dimensions = [[33, 56], [56, 33], [22, 88], [88, 22], [44, 44]]) == 1936\n assert candidate(dimensions = [[25, 60], [30, 40], [50, 50], [45, 55], [35, 65]]) == 2275\n assert candidate(dimensions = [[60, 80], [80, 60], [48, 55], [55, 48], [5, 12], [12, 5], [8, 15], [15, 8]]) == 4800\n assert candidate(dimensions = [[20, 21], [21, 20], [15, 25], [25, 15]]) == 375\n assert candidate(dimensions = [[50, 50], [70, 30], [60, 40]]) == 2100\n assert candidate(dimensions = [[50, 50], [49, 51], [51, 49], [60, 8], [8, 60]]) == 2499\n assert candidate(dimensions = [[1, 100], [100, 1], [50, 50], [70, 70], [60, 80], [80, 60]]) == 100\n assert candidate(dimensions = [[25, 60], [60, 25], [40, 40], [30, 70], [70, 30], [10, 90], [90, 10]]) == 900\n assert candidate(dimensions = [[10, 24], [24, 10], [15, 36], [36, 15], [20, 21], [21, 20], [25, 60], [60, 25], [30, 40], [40, 30]]) == 1500\n assert candidate(dimensions = [[33, 56], [56, 33], [44, 48], [48, 44], [29, 71], [71, 29], [17, 84], [84, 17]]) == 1428\n assert candidate(dimensions = [[13, 84], [84, 13], [16, 82], [82, 16], [20, 79], [79, 20], [24, 76], [76, 24], [28, 73], [73, 28]]) == 1092\n assert candidate(dimensions = [[15, 20], [30, 40], [25, 60], [60, 25]]) == 1500\n assert candidate(dimensions = [[5, 12], [12, 5], [8, 15], [15, 8], [10, 24], [24, 10]]) == 240\n assert candidate(dimensions = [[20, 21], [21, 20], [19, 22], [22, 19], [18, 23], [23, 18], [17, 24], [24, 17]]) == 408\n", "comparison": "exact"}, "public_tests": ["[[9,3],[8,6]]", "[[3,4],[4,3]]"], "hints": ["Diagonal of rectangle is sqrt(length^2 + width^2)."], "metadata": {"canonical_parameter_names": ["dimensions"], "leetcode_dataset_entry_point": "Solution().areaOfMaxDiagonal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:48+00:00", "tests_total": 107, "tests_dropped": 1, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def area_of_max_diagonal(dimensions)", "container": null, "callable": "area_of_max_diagonal", "parameters": [{"name": "dimensions", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3001, "task_id": "minimum-moves-to-capture-the-queen", "difficulty": "Medium", "problem_description": "There is a 1-indexed 8 x 8 chessboard containing 3 pieces.\n\nYou are given 6 integers a, b, c, d, e, and f where:\n\n- (a, b) denotes the position of the white rook.\n- (c, d) denotes the position of the white bishop.\n- (e, f) denotes the position of the black queen.\n\nGiven that you can only move the white pieces, return the minimum number of moves required to capture the black queen.\n\nNote that:\n\n- Rooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.\n- Bishops can move any number of squares diagonally, but cannot jump over other pieces.\n- A rook or a bishop can capture the queen if it is located in a square that they can move to.\n- The queen does not move.\n\nExample 1:\n\nInput: a = 1, b = 1, c = 8, d = 8, e = 2, f = 3\nOutput: 2\nExplanation: We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).\nIt is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.\n\nExample 2:\n\nInput: a = 5, b = 3, c = 3, d = 4, e = 5, f = 2\nOutput: 1\nExplanation: We can capture the black queen in a single move by doing one of the following:\n- Move the white rook to (5, 2).\n- Move the white bishop to (5, 2).\n\nConstraints:\n\n- 1 <= a, b, c, d, e, f <= 8\n- No two pieces are on the same square.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(a = 4,b = 4,c = 7,d = 7,e = 3,f = 3) == 2\n assert candidate(a = 3,b = 3,c = 6,d = 6,e = 7,f = 7) == 1\n assert candidate(a = 7,b = 2,c = 2,d = 7,e = 4,f = 4) == 2\n assert candidate(a = 1,b = 8,c = 2,d = 7,e = 3,f = 6) == 1\n assert candidate(a = 8,b = 8,c = 1,d = 1,e = 3,f = 3) == 1\n assert candidate(a = 8,b = 8,c = 1,d = 1,e = 4,f = 4) == 1\n assert candidate(a = 8,b = 1,c = 5,d = 4,e = 7,f = 7) == 2\n assert candidate(a = 4,b = 4,c = 7,d = 7,e = 6,f = 6) == 1\n assert candidate(a = 5,b = 3,c = 3,d = 4,e = 5,f = 2) == 1\n assert candidate(a = 1,b = 1,c = 8,d = 8,e = 2,f = 3) == 2\n assert candidate(a = 4,b = 4,c = 6,d = 6,e = 7,f = 7) == 1\n assert candidate(a = 6,b = 6,c = 2,d = 2,e = 4,f = 4) == 1\n assert candidate(a = 2,b = 2,c = 4,d = 4,e = 6,f = 6) == 1\n assert candidate(a = 4,b = 4,c = 1,d = 4,e = 8,f = 4) == 1\n assert candidate(a = 2,b = 3,c = 5,d = 6,e = 3,f = 4) == 1\n assert candidate(a = 4,b = 4,c = 4,d = 1,e = 4,f = 8) == 1\n assert candidate(a = 3,b = 3,c = 5,d = 5,e = 6,f = 6) == 1\n assert candidate(a = 8,b = 8,c = 7,d = 7,e = 6,f = 6) == 1\n assert candidate(a = 3,b = 3,c = 6,d = 6,e = 5,f = 5) == 1\n assert candidate(a = 1,b = 1,c = 2,d = 2,e = 8,f = 8) == 1\n assert candidate(a = 4,b = 4,c = 5,d = 5,e = 6,f = 6) == 1\n assert candidate(a = 1,b = 1,c = 2,d = 2,e = 3,f = 3) == 1\n assert candidate(a = 1,b = 8,c = 8,d = 1,e = 4,f = 4) == 2\n assert candidate(a = 3,b = 3,c = 5,d = 5,e = 2,f = 2) == 2\n assert candidate(a = 2,b = 4,c = 7,d = 1,e = 4,f = 7) == 2\n assert candidate(a = 6,b = 2,c = 3,d = 5,e = 5,f = 2) == 1\n assert candidate(a = 5,b = 1,c = 2,d = 6,e = 5,f = 8) == 1\n assert candidate(a = 5,b = 5,c = 2,d = 8,e = 2,f = 3) == 2\n assert candidate(a = 3,b = 6,c = 6,d = 3,e = 7,f = 7) == 2\n assert candidate(a = 2,b = 2,c = 5,d = 5,e = 3,f = 3) == 1\n assert candidate(a = 5,b = 5,c = 1,d = 1,e = 8,f = 8) == 2\n assert candidate(a = 5,b = 5,c = 3,d = 3,e = 5,f = 1) == 1\n assert candidate(a = 6,b = 3,c = 3,d = 6,e = 8,f = 1) == 2\n assert candidate(a = 8,b = 8,c = 1,d = 1,e = 5,f = 5) == 1\n assert candidate(a = 3,b = 3,c = 6,d = 6,e = 4,f = 7) == 2\n assert candidate(a = 1,b = 1,c = 7,d = 7,e = 4,f = 4) == 1\n assert candidate(a = 4,b = 8,c = 8,d = 4,e = 1,f = 1) == 2\n assert candidate(a = 1,b = 4,c = 8,d = 4,e = 5,f = 4) == 1\n assert candidate(a = 2,b = 5,c = 5,d = 2,e = 7,f = 7) == 2\n assert candidate(a = 1,b = 1,c = 3,d = 5,e = 7,f = 7) == 2\n assert candidate(a = 7,b = 2,c = 3,d = 6,e = 5,f = 4) == 1\n assert candidate(a = 4,b = 4,c = 1,d = 8,e = 8,f = 1) == 1\n assert candidate(a = 2,b = 5,c = 5,d = 2,e = 7,f = 5) == 1\n assert candidate(a = 5,b = 8,c = 3,d = 3,e = 1,f = 1) == 1\n assert candidate(a = 1,b = 5,c = 8,d = 5,e = 6,f = 5) == 1\n assert candidate(a = 8,b = 8,c = 1,d = 8,e = 1,f = 1) == 2\n assert candidate(a = 7,b = 7,c = 2,d = 2,e = 5,f = 5) == 1\n assert candidate(a = 3,b = 5,c = 1,d = 1,e = 8,f = 8) == 1\n assert candidate(a = 3,b = 3,c = 6,d = 3,e = 5,f = 3) == 1\n assert candidate(a = 5,b = 1,c = 1,d = 5,e = 6,f = 6) == 2\n assert candidate(a = 4,b = 4,c = 3,d = 5,e = 5,f = 3) == 2\n assert candidate(a = 8,b = 8,c = 3,d = 3,e = 6,f = 6) == 1\n assert candidate(a = 8,b = 1,c = 5,d = 4,e = 4,f = 4) == 2\n assert candidate(a = 4,b = 4,c = 1,d = 8,e = 7,f = 2) == 1\n assert candidate(a = 6,b = 2,c = 2,d = 6,e = 3,f = 3) == 2\n assert candidate(a = 3,b = 6,c = 6,d = 3,e = 8,f = 8) == 2\n assert candidate(a = 2,b = 2,c = 5,d = 5,e = 7,f = 7) == 1\n assert candidate(a = 8,b = 1,c = 1,d = 8,e = 5,f = 5) == 2\n assert candidate(a = 4,b = 4,c = 7,d = 1,e = 1,f = 8) == 2\n assert candidate(a = 4,b = 4,c = 1,d = 8,e = 7,f = 7) == 2\n assert candidate(a = 1,b = 8,c = 7,d = 1,e = 4,f = 4) == 1\n assert candidate(a = 7,b = 3,c = 4,d = 6,e = 1,f = 1) == 2\n assert candidate(a = 1,b = 1,c = 7,d = 7,e = 8,f = 8) == 1\n assert candidate(a = 4,b = 4,c = 8,d = 1,e = 2,f = 2) == 2\n assert candidate(a = 3,b = 8,c = 6,d = 3,e = 8,f = 1) == 1\n assert candidate(a = 3,b = 6,c = 6,d = 3,e = 5,f = 5) == 2\n assert candidate(a = 5,b = 5,c = 2,d = 2,e = 8,f = 1) == 2\n assert candidate(a = 4,b = 4,c = 5,d = 5,e = 7,f = 2) == 2\n assert candidate(a = 1,b = 8,c = 8,d = 1,e = 5,f = 5) == 2\n assert candidate(a = 6,b = 3,c = 2,d = 7,e = 5,f = 5) == 2\n assert candidate(a = 4,b = 4,c = 1,d = 1,e = 8,f = 8) == 2\n assert candidate(a = 7,b = 2,c = 2,d = 7,e = 5,f = 5) == 2\n assert candidate(a = 8,b = 1,c = 1,d = 8,e = 4,f = 4) == 2\n assert candidate(a = 1,b = 1,c = 7,d = 2,e = 8,f = 8) == 2\n assert candidate(a = 1,b = 8,c = 3,d = 6,e = 4,f = 4) == 2\n assert candidate(a = 2,b = 2,c = 5,d = 5,e = 8,f = 8) == 1\n assert candidate(a = 1,b = 1,c = 7,d = 7,e = 5,f = 5) == 1\n assert candidate(a = 2,b = 3,c = 4,d = 6,e = 3,f = 6) == 2\n assert candidate(a = 4,b = 4,c = 7,d = 1,e = 1,f = 7) == 2\n assert candidate(a = 1,b = 8,c = 5,d = 5,e = 3,f = 3) == 1\n assert candidate(a = 1,b = 8,c = 4,d = 4,e = 8,f = 1) == 2\n assert candidate(a = 7,b = 7,c = 3,d = 3,e = 4,f = 4) == 1\n assert candidate(a = 5,b = 5,c = 8,d = 1,e = 1,f = 8) == 1\n assert candidate(a = 2,b = 2,c = 7,d = 7,e = 4,f = 4) == 1\n assert candidate(a = 8,b = 8,c = 5,d = 5,e = 2,f = 2) == 1\n assert candidate(a = 1,b = 1,c = 8,d = 8,e = 4,f = 4) == 1\n assert candidate(a = 1,b = 5,c = 5,d = 1,e = 8,f = 8) == 2\n assert candidate(a = 8,b = 1,c = 4,d = 4,e = 5,f = 5) == 1\n", "comparison": "exact"}, "public_tests": ["1\n1\n8\n8\n2\n3", "5\n3\n3\n4\n5\n2"], "hints": ["The minimum number of moves can be either 1 or 2.", "The answer will be 1 if the queen is on the path of the rook or bishop and none of them is in between."], "metadata": {"canonical_parameter_names": ["a", "b", "c", "d", "e", "f"], "leetcode_dataset_entry_point": "Solution().minMovesToCaptureTheQueen", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:50+00:00", "tests_total": 89, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["math", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def min_moves_to_capture_the_queen(a, b, c, d, e, f)", "container": null, "callable": "min_moves_to_capture_the_queen", "parameters": [{"name": "a", "type": "Integer"}, {"name": "b", "type": "Integer"}, {"name": "c", "type": "Integer"}, {"name": "d", "type": "Integer"}, {"name": "e", "type": "Integer"}, {"name": "f", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3002, "task_id": "maximum-size-of-a-set-after-removals", "difficulty": "Medium", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2 of even length n.\n\nYou must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.\n\nReturn the maximum possible size of the set s.\n\nExample 1:\n\nInput: nums1 = [1,2,1,2], nums2 = [1,1,1,1]\nOutput: 2\nExplanation: We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.\nIt can be shown that 2 is the maximum possible size of the set s after the removals.\n\nExample 2:\n\nInput: nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]\nOutput: 5\nExplanation: We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.\nIt can be shown that 5 is the maximum possible size of the set s after the removals.\n\nExample 3:\n\nInput: nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]\nOutput: 6\nExplanation: We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.\nIt can be shown that 6 is the maximum possible size of the set s after the removals.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 1 <= n <= 2 * 10^4\n- n is even.\n- 1 <= nums1[i], nums2[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [4, 4, 5, 5, 6, 6]) == 6\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8],nums2 = [5, 6, 7, 8, 9, 10, 11, 12]) == 8\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60],nums2 = [40, 50, 60, 70, 80, 90]) == 6\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [2, 4, 6, 8, 10, 12]) == 6\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [2, 2, 2, 2]) == 2\n assert candidate(nums1 = [1, 2, 1, 2],nums2 = [1, 1, 1, 1]) == 2\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [3, 3, 4, 4, 5, 5]) == 5\n assert candidate(nums1 = [9, 9, 9, 9, 9, 9],nums2 = [9, 9, 9, 9, 9, 9]) == 1\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60],nums2 = [10, 20, 10, 20, 10, 20]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [2, 3, 2, 3, 2, 3]) == 5\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [5, 6, 7, 8]) == 4\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 20\n assert candidate(nums1 = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 14\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000, 1000000000],nums2 = [1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4],nums2 = [2, 2, 3, 3, 5, 5, 6, 6]) == 6\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 16\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4],nums2 = [4, 4, 5, 5, 6, 6, 7, 7]) == 7\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums1 = [10, 20, 20, 30, 30, 30, 40, 50],nums2 = [10, 20, 20, 30, 40, 40, 50, 60]) == 6\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20]) == 16\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11],nums2 = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == 16\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],nums2 = [6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 11\n assert candidate(nums1 = [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],nums2 = [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]) == 30\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 10\n assert candidate(nums1 = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4],nums2 = [2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5]) == 5\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11],nums2 = [2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12]) == 12\n assert candidate(nums1 = [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],nums2 = [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, 61, 62]) == 32\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 9\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160],nums2 = [10, 20, 30, 40, 50, 60, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 16\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == 8\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],nums2 = [1, 1, 2, 2, 3, 3, 7, 8, 9, 10, 11, 12]) == 12\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 20\n assert candidate(nums1 = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7],nums2 = [2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8]) == 8\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4],nums2 = [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5]) == 5\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9]) == 9\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],nums2 = [6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 11\n assert candidate(nums1 = [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],nums2 = [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]) == 30\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],nums2 = [4, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 6\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],nums2 = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10],nums2 = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 14\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 20\n assert candidate(nums1 = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9],nums2 = [5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9]) == 5\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 7\n assert candidate(nums1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],nums2 = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 6\n assert candidate(nums1 = [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],nums2 = [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]) == 30\n assert candidate(nums1 = [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],nums2 = [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]) == 16\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 9\n assert candidate(nums1 = [1, 2, 2, 3, 4, 4, 5, 5],nums2 = [2, 3, 3, 4, 5, 5, 6, 7]) == 7\n assert candidate(nums1 = [10, 10, 20, 20, 30, 30, 40, 40],nums2 = [40, 40, 50, 50, 60, 60, 70, 70]) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 14\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 16\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],nums2 = [2, 2, 3, 3, 4, 4, 5, 5, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7],nums2 = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 6\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 16\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 24\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 16\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],nums2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 12\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 16\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 16\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [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, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 16\n assert candidate(nums1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],nums2 = [4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7]) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 20\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 11\n assert candidate(nums1 = [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6],nums2 = [6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10]) == 10\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 20\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 2, 2, 3, 3],nums2 = [4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 8\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == 18\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],nums2 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 15\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],nums2 = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == 18\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums1 = [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],nums2 = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 9\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],nums2 = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 9\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4],nums2 = [4, 4, 5, 5, 6, 6, 7, 7]) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8, 9, 10, 10, 10, 11],nums2 = [5, 5, 6, 6, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums1 = [1000000000, 1000000000, 1000000000, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],nums2 = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == 18\n assert candidate(nums1 = [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],nums2 = [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]) == 30\n", "comparison": "exact"}, "public_tests": ["[1,2,1,2]\n[1,1,1,1]", "[1,2,3,4,5,6]\n[2,3,2,3,2,3]", "[1,1,2,2,3,3]\n[4,4,5,5,6,6]"], "hints": ["Removing n / 2 elements from each array is the same as keeping n / 2 elements in each array.", "Think of a greedy algorithm.", "For each array, we will greedily keep the elements that are only in that array. Once we run out of such elements, we will keep the elements that are common to both arrays."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().maximumSetSize", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:52+00:00", "tests_total": 103, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_set_size(nums1, nums2)", "container": null, "callable": "maximum_set_size", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3003, "task_id": "maximize-the-number-of-partitions-after-operations", "difficulty": "Hard", "problem_description": "You are given a string s and an integer k.\n\nFirst, you are allowed to change at most one index in s to another lowercase English letter.\n\nAfter that, do the following partitioning operation until s is empty:\n\n- Choose the longest prefix of s containing at most k distinct characters.\n- Delete the prefix from s and increase the number of partitions by one. The remaining characters (if any) in s maintain their initial order.\n\nReturn an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.\n\nExample 1:\n\nInput: s = \"accca\", k = 2\nOutput: 3\nExplanation:\nThe optimal way is to change s[2] to something other than a and c, for example, b. then it becomes \"acbca\".\nThen we perform the operations:\n1. The longest prefix containing at most 2 distinct characters is \"ac\", we remove it and s becomes \"bca\".\n2. Now The longest prefix containing at most 2 distinct characters is \"bc\", so we remove it and s becomes \"a\".\n3. Finally, we remove \"a\" and s becomes empty, so the procedure ends.\n\nDoing the operations, the string is divided into 3 partitions, so the answer is 3.\n\nExample 2:\n\nInput: s = \"aabaab\", k = 3\nOutput: 1\nExplanation:\nInitially s contains 2 distinct characters, so whichever character we change, it will contain at most 3 distinct characters, so the longest prefix with at most 3 distinct characters would always be all of it, therefore the answer is 1.\n\nExample 3:\n\nInput: s = \"xxyz\", k = 1\nOutput: 4\nExplanation:\nThe optimal way is to change s[0] or s[1] to something other than characters in s, for example, to change s[0] to w.\nThen s becomes \"wxyz\", which consists of 4 distinct characters, so as k is 1, it will divide into 4 partitions.\n\nConstraints:\n\n- 1 <= s.length <= 10^4\n- s consists only of lowercase English letters.\n- 1 <= k <= 26\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzz\",k = 1) == 3\n assert candidate(s = \"abcdef\",k = 6) == 1\n assert candidate(s = \"aaaaaaa\",k = 1) == 3\n assert candidate(s = \"abcdefghijklmnop\",k = 5) == 4\n assert candidate(s = \"aabacbebebe\",k = 3) == 2\n assert candidate(s = \"aaaabbbbcccc\",k = 3) == 2\n assert candidate(s = \"zzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"abcd\",k = 2) == 2\n assert candidate(s = \"abacabadabacaba\",k = 3) == 4\n assert candidate(s = \"aabaab\",k = 3) == 1\n assert candidate(s = \"aabbccddeeffgg\",k = 2) == 4\n assert candidate(s = \"accca\",k = 2) == 3\n assert candidate(s = \"aabbaa\",k = 2) == 2\n assert candidate(s = \"zzzzz\",k = 1) == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 10) == 3\n assert candidate(s = \"aabbccddeeff\",k = 3) == 3\n assert candidate(s = \"xxyz\",k = 1) == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 26) == 1\n assert candidate(s = \"abcdabcd\",k = 4) == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"abcdefg\",k = 7) == 1\n assert candidate(s = \"aabbaabb\",k = 2) == 3\n assert candidate(s = \"zzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"abacabadabacaba\",k = 2) == 7\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 26) == 1\n assert candidate(s = \"abcdefabcdef\",k = 4) == 3\n assert candidate(s = \"aabbccddeeff\",k = 2) == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 2) == 15\n assert candidate(s = \"abcdefg\",k = 3) == 3\n assert candidate(s = \"abcabcabc\",k = 3) == 3\n assert candidate(s = \"abacabad\",k = 2) == 4\n assert candidate(s = \"aaaa\",k = 1) == 3\n assert candidate(s = \"abcabcabcabc\",k = 3) == 3\n assert candidate(s = \"aabcccccaabaab\",k = 2) == 4\n assert candidate(s = \"mnopqrstuvw\",k = 6) == 2\n assert candidate(s = \"abcdabcdabcdabcd\",k = 4) == 3\n assert candidate(s = \"xyzxyzxyzxyzxyz\",k = 3) == 3\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 5) == 1\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",k = 10) == 3\n assert candidate(s = \"ababababababab\",k = 2) == 3\n assert candidate(s = \"banana\",k = 2) == 3\n assert candidate(s = \"aaaaabbbbbaaaaabbbbb\",k = 2) == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 1) == 27\n assert candidate(s = \"aaabbbcccdddeeefffggghhh\",k = 2) == 5\n assert candidate(s = \"abcdefghijklaaaa\",k = 4) == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"zzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"ababababababababab\",k = 2) == 3\n assert candidate(s = \"abcdefgabcdefg\",k = 4) == 4\n assert candidate(s = \"mississippi\",k = 2) == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"llllllllllllllllllllllllll\",k = 1) == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 5) == 6\n assert candidate(s = \"abcabcabcabcabc\",k = 2) == 8\n assert candidate(s = \"xyxyxyxyxyxyxyxy\",k = 2) == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",k = 10) == 3\n assert candidate(s = \"abcabcabcabcabcabc\",k = 3) == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"xyzzzzxyzzzz\",k = 2) == 4\n assert candidate(s = \"abcabcaabbccbbaccc\",k = 2) == 7\n assert candidate(s = \"abcdeabcdeabcde\",k = 5) == 3\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",k = 5) == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabc\",k = 2) == 12\n assert candidate(s = \"abcdefabcdefabcdef\",k = 5) == 4\n assert candidate(s = \"aabbaabbaabbaabbaabbaabb\",k = 2) == 3\n assert candidate(s = \"abcdabcdabcd\",k = 3) == 4\n assert candidate(s = \"abcdefghij\",k = 5) == 2\n assert candidate(s = \"aaabbbcccddd\",k = 3) == 2\n assert candidate(s = \"aabbccddeeffgghhii\",k = 26) == 1\n assert candidate(s = \"abcabcabcabc\",k = 2) == 6\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",k = 25) == 2\n assert candidate(s = \"abababababababababababababababababababababababababababababab\",k = 2) == 3\n assert candidate(s = \"ababababababababababababababab\",k = 2) == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 3) == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"abcdefghij\",k = 1) == 10\n assert candidate(s = \"aabbbcccccdddd\",k = 3) == 2\n assert candidate(s = \"aaaaaaaaabbbbbbb\",k = 2) == 2\n assert candidate(s = \"aabbaabbaabbaabb\",k = 2) == 3\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcd\",k = 4) == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 10) == 3\n assert candidate(s = \"aabccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 5) == 6\n assert candidate(s = \"abcdefg\",k = 1) == 7\n assert candidate(s = \"abbaabbaabba\",k = 2) == 3\n assert candidate(s = \"abracadabra\",k = 4) == 3\n assert candidate(s = \"aabbaabbccddeeffgg\",k = 3) == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 3\n assert candidate(s = \"abcabcabc\",k = 2) == 5\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzz\",k = 2) == 16\n assert candidate(s = \"aabbccddeeffgghhii\",k = 5) == 2\n assert candidate(s = \"abababababab\",k = 2) == 3\n assert candidate(s = \"ababababababababababababab\",k = 2) == 3\n assert candidate(s = \"xyzzxyzzxyzz\",k = 3) == 3\n assert candidate(s = \"aaaaaaaaaabbbbbbbbccccccccdddddddd\",k = 4) == 2\n assert candidate(s = \"mississippi\",k = 3) == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 1) == 26\n assert candidate(s = \"lalalalalala\",k = 2) == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 3) == 9\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxxyyyyzzzz\",k = 4) == 7\n assert candidate(s = \"aaaaaabbbbbbbccc\",k = 2) == 3\n assert candidate(s = \"xyzxyzxyzxyzxyzxyz\",k = 3) == 3\n assert candidate(s = \"xyzzzxyzzzxyzzz\",k = 3) == 3\n assert candidate(s = \"abracadabra\",k = 2) == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 3) == 3\n assert candidate(s = \"abacbacbacbacba\",k = 4) == 1\n assert candidate(s = \"abcdefg\",k = 2) == 4\n assert candidate(s = \"abababababababab\",k = 2) == 3\n assert candidate(s = \"xyzzzxyzzzxyzzz\",k = 2) == 6\n assert candidate(s = \"abracadabraabracadabraabracadabra\",k = 3) == 8\n assert candidate(s = \"abcdabcdbca\",k = 3) == 4\n assert candidate(s = \"zzzzzabczzzzzdefzzzzzghizzzzzjklzzzzzmnopzzzzzqrstzzzzzuvwxyz\",k = 26) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 13) == 4\n", "comparison": "exact"}, "public_tests": ["\"accca\"\n2", "\"aabaab\"\n3", "\"xxyz\"\n1"], "hints": ["For each position, try to brute-force the replacements.", "To speed up the brute-force solution, we can precompute the following (without changing any index) using prefix sums and binary search:\n- pref[i]: The number of resulting partitions from the operations by performing the operations on s[0:i].\n- suff[i]: The number of resulting partitions from the operations by performing the operations on s[i:n - 1], where n == s.length.\n- partition_start[i]: The start index of the partition containing the i^th index after performing the operations.", "Now, for a position i, we can try all possible 25 replacements:\nFor a replacement, using prefix sums and binary search, we need to find the rightmost index, r, such that the number of distinct characters in the range [partition_start[i], r] is at most k.\nThere are 2 cases:\n- r >= i: the number of resulting partitions in this case is 1 + pref[partition_start[i] - 1] + suff[r + 1].\n- Otherwise, we need to find the rightmost index r_2 such that the number of distinct characters in the range [r:r_2] is at most k. The answer in this case is 2 + pref[partition_start[i] - 1] + suff[r_2 + 1]", "The answer is the maximum among all replacements."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().maxPartitionsAfterOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:09:55+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "bit-manipulation", "bitmask"]}, "language": "ruby", "interface": {"raw_signature": "def max_partitions_after_operations(s, k)", "container": null, "callable": "max_partitions_after_operations", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3005, "task_id": "count-elements-with-maximum-frequency", "difficulty": "Easy", "problem_description": "You are given an array nums consisting of positive integers.\n\nReturn the total frequencies of elements in nums such that those elements all have the maximum frequency.\n\nThe frequency of an element is the number of occurrences of that element in the array.\n\nExample 1:\n\nInput: nums = [1,2,2,3,1,4]\nOutput: 4\nExplanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.\nSo the number of elements in the array with maximum frequency is 4.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: 5\nExplanation: All elements of the array have a frequency of 1 which is the maximum.\nSo the number of elements in the array with maximum frequency is 5.\n\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 = [3, 3, 3, 2, 2, 1]) == 3\n assert candidate(nums = [10, 20, 10, 20, 10, 30, 30, 30, 30]) == 4\n assert candidate(nums = [10, 20, 10, 20, 10, 30, 20, 40, 50, 20]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 8\n assert candidate(nums = [1, 2, 2, 3, 1, 4]) == 4\n assert candidate(nums = [5, 5, 5, 5, 1, 1, 2, 2, 3, 3]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 3]) == 3\n assert candidate(nums = [10, 20, 20, 10, 30, 30, 30]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [7, 7, 7, 7, 7]) == 5\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [1, 1]) == 2\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9]) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 9\n assert candidate(nums = [31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 34, 34, 34, 35, 35, 35, 35]) == 12\n assert candidate(nums = [2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7]) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [32, 32, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35]) == 9\n assert candidate(nums = [7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10]) == 5\n assert candidate(nums = [7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10]) == 4\n assert candidate(nums = [11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 19]) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4]) == 8\n assert candidate(nums = [99, 99, 99, 99, 98, 98, 98, 97, 97, 96, 96, 95, 95, 95, 95, 95, 95, 95, 95, 95]) == 9\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 8\n assert candidate(nums = [2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6]) == 8\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 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]) == 30\n assert candidate(nums = [17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 20, 20, 20]) == 6\n assert candidate(nums = [6, 6, 6, 6, 7, 7, 7, 8, 8, 9]) == 4\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5]) == 5\n assert candidate(nums = [3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 18\n assert candidate(nums = [21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\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]) == 27\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 9, 9, 10]) == 4\n assert candidate(nums = [6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10]) == 4\n assert candidate(nums = [1, 1, 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\n assert candidate(nums = [6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10]) == 5\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [6, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 11]) == 5\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6]) == 8\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10]) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4]) == 4\n assert candidate(nums = [6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10]) == 6\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9]) == 5\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 92, 91, 91]) == 6\n assert candidate(nums = [25, 26, 27, 28, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31]) == 7\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40]) == 4\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 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]) == 25\n assert candidate(nums = [1, 1, 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, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 20\n assert candidate(nums = [36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39]) == 9\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 2, 2, 2, 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]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 21\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10]) == 5\n assert candidate(nums = [2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 12\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 6\n assert candidate(nums = [6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 12\n assert candidate(nums = [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 36, 37, 38, 39]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 15\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 12\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 20\n assert candidate(nums = [6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]) == 10\n assert candidate(nums = [30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 37, 38, 38, 39]) == 4\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60]) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 6\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]) == 28\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 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]) == 41\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7]) == 6\n assert candidate(nums = [50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 60, 60]) == 4\n assert candidate(nums = [7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9]) == 5\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(nums = [21, 21, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24]) == 7\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, 10]) == 16\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, 70, 70, 70, 70, 70, 70, 70]) == 7\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]) == 9\n assert candidate(nums = [11, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15]) == 5\n assert candidate(nums = [6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10]) == 4\n assert candidate(nums = [10, 10, 20, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40, 40]) == 5\n assert candidate(nums = [14, 15, 14, 15, 14, 15, 16, 16, 16, 17, 18, 18, 18, 19, 19, 19, 19]) == 4\n assert candidate(nums = [31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10]) == 12\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 7, 8, 8, 8, 8]) == 8\n assert candidate(nums = [9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40]) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8]) == 6\n assert candidate(nums = [7, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5]) == 4\n assert candidate(nums = [21, 21, 21, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 25]) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9]) == 8\n assert candidate(nums = [41, 41, 41, 42, 42, 42, 42, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 45]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 10]) == 12\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5]) == 8\n assert candidate(nums = [40, 40, 40, 41, 41, 41, 42, 42, 42, 42, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 47, 47, 47, 47]) == 8\n assert candidate(nums = [11, 12, 13, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16]) == 5\n assert candidate(nums = [7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 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, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 10\n assert candidate(nums = [6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 12, 12, 12, 13, 13, 13, 13]) == 8\n assert candidate(nums = [10, 10, 10, 20, 20, 30, 30, 30, 40, 40, 40, 40]) == 4\n assert candidate(nums = [26, 27, 28, 29, 30, 26, 27, 28, 29, 30, 26, 27, 28, 29, 30, 26, 27, 28, 29]) == 16\n assert candidate(nums = [51, 51, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55]) == 6\n assert candidate(nums = [40, 41, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [61, 61, 61, 61, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64]) == 7\n", "comparison": "exact"}, "public_tests": ["[1,2,2,3,1,4]", "[1,2,3,4,5]"], "hints": ["Find frequencies of all elements of the array.", "Find the elements that have the maximum frequencies and count their total occurrences."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxFrequencyElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:00+00:00", "tests_total": 116, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def max_frequency_elements(nums)", "container": null, "callable": "max_frequency_elements", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3006, "task_id": "find-beautiful-indices-in-the-given-array-i", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string s, a string a, a string b, and an integer k.\n\nAn index i is beautiful if:\n\n- 0 <= i <= s.length - a.length\n- s[i..(i + a.length - 1)] == a\n- There exists an index j such that:\n - 0 <= j <= s.length - b.length\n - s[j..(j + b.length - 1)] == b\n - |j - i| <= k\n\nReturn the array that contains beautiful indices in sorted order from smallest to largest.\n\nExample 1:\n\nInput: s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\nOutput: [16,33]\nExplanation: There are 2 beautiful indices: [16,33].\n- The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n- The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\nThus we return [16,33] as the result.\n\nExample 2:\n\nInput: s = \"abcd\", a = \"a\", b = \"a\", k = 4\nOutput: [0]\nExplanation: There is 1 beautiful index: [0].\n- The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\nThus we return [0] as the result.\n\nConstraints:\n\n- 1 <= k <= s.length <= 10^5\n- 1 <= a.length, b.length <= 10\n- s, a, and b contain only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"beautifulbeautifulbeautiful\",a = \"ful\",b = \"aut\",k = 5) == [6, 15, 24]\n assert candidate(s = \"hellobeautifulworld\",a = \"be\",b = \"autiful\",k = 5) == [5]\n assert candidate(s = \"beautifulbeautifulbeautiful\",a = \"ful\",b = \"uti\",k = 5) == [6, 15, 24]\n assert candidate(s = \"hellohellohello\",a = \"he\",b = \"lo\",k = 3) == [0, 5, 10]\n assert candidate(s = \"beautifulday\",a = \"day\",b = \"beat\",k = 10) == []\n assert candidate(s = \"abababab\",a = \"ab\",b = \"ba\",k = 2) == [0, 2, 4, 6]\n assert candidate(s = \"abcabcabcabc\",a = \"ab\",b = \"bc\",k = 3) == [0, 3, 6, 9]\n assert candidate(s = \"hellohellohello\",a = \"he\",b = \"lo\",k = 2) == [5, 10]\n assert candidate(s = \"abcd\",a = \"a\",b = \"a\",k = 4) == [0]\n assert candidate(s = \"aaaaaa\",a = \"aa\",b = \"aaa\",k = 2) == [0, 1, 2, 3, 4]\n assert candidate(s = \"isawsquirrelnearmysquirrelhouseohmy\",a = \"my\",b = \"squirrel\",k = 15) == [16, 33]\n assert candidate(s = \"abababab\",a = \"ab\",b = \"ba\",k = 1) == [0, 2, 4, 6]\n assert candidate(s = \"hellotherehello\",a = \"he\",b = \"lo\",k = 5) == [0, 6, 10]\n assert candidate(s = \"teststringteststring\",a = \"test\",b = \"ing\",k = 10) == [0, 10]\n assert candidate(s = \"abcabcabcabc\",a = \"abc\",b = \"cab\",k = 3) == [0, 3, 6, 9]\n assert candidate(s = \"beautifulbeautiful\",a = \"ful\",b = \"uti\",k = 5) == [6, 15]\n assert candidate(s = \"hellobeautifulworld\",a = \"bea\",b = \"ful\",k = 7) == [5]\n assert candidate(s = \"overlappingoverlappingoverlapping\",a = \"over\",b = \"lapping\",k = 10) == [0, 11, 22]\n assert candidate(s = \"overlappingoverlappingoverlapping\",a = \"over\",b = \"lap\",k = 5) == [0, 11, 22]\n assert candidate(s = \"randomstringwithrandomstringinside\",a = \"random\",b = \"inside\",k = 25) == [16]\n assert candidate(s = \"qwertyuiopqwertyuiop\",a = \"erty\",b = \"rtyu\",k = 8) == [2, 12]\n assert candidate(s = \"abababababab\",a = \"aba\",b = \"bab\",k = 2) == [0, 2, 4, 6, 8]\n assert candidate(s = \"repeatedwordrepeatedwordrepeated\",a = \"word\",b = \"repeated\",k = 10) == [8, 20]\n assert candidate(s = \"xyxxyxyxyxyxxyxyxyxy\",a = \"xy\",b = \"yx\",k = 4) == [0, 3, 5, 7, 9, 12, 14, 16, 18]\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"sis\",k = 3) == [1, 4]\n assert candidate(s = \"uniquestringswithvariouslengthsandcharacters\",a = \"strings\",b = \"length\",k = 25) == [6]\n assert candidate(s = \"longestsubstringhereandthere\",a = \"long\",b = \"here\",k = 12) == []\n assert candidate(s = \"bananaananabanana\",a = \"ana\",b = \"nan\",k = 4) == [1, 3, 6, 8, 12, 14]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"sip\",k = 4) == [4]\n assert candidate(s = \"aaaaaabaaaaaabaaaaaabaaaaaabaaaaaabaaaaaabaaaaaab\",a = \"aa\",b = \"bb\",k = 5) == []\n assert candidate(s = \"xylophonexylophonexylophone\",a = \"xylo\",b = \"phone\",k = 7) == [0, 9, 18]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"issi\",k = 3) == [1, 4]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"issi\",k = 2) == [1, 4]\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyz\",a = \"xyz\",b = \"zyx\",k = 2) == []\n assert candidate(s = \"racecaracecaracecar\",a = \"ace\",b = \"cec\",k = 7) == [1, 7, 13]\n assert candidate(s = \"abababababababa\",a = \"aba\",b = \"bab\",k = 3) == [0, 2, 4, 6, 8, 10, 12]\n assert candidate(s = \"overlappingoverlappingoverlapping\",a = \"lapping\",b = \"over\",k = 10) == [4, 15, 26]\n assert candidate(s = \"thelongestwordinenglishdictionary\",a = \"word\",b = \"english\",k = 15) == [10]\n assert candidate(s = \"repeatthisstringmanytimesrepeatthisstringmanytimes\",a = \"this\",b = \"many\",k = 25) == [6, 31]\n assert candidate(s = \"bananaananabanana\",a = \"ana\",b = \"nana\",k = 6) == [1, 3, 6, 8, 12, 14]\n assert candidate(s = \"alibabaibabaibaba\",a = \"ali\",b = \"iba\",k = 5) == [0]\n assert candidate(s = \"bananaananabananananabanana\",a = \"ana\",b = \"nana\",k = 5) == [1, 3, 6, 8, 12, 14, 16, 18, 22, 24]\n assert candidate(s = \"overlappingstringsoverlapping\",a = \"lap\",b = \"ing\",k = 10) == [4, 22]\n assert candidate(s = \"squirrelmysquirrelhouseohmysquirrel\",a = \"squirrel\",b = \"house\",k = 20) == [0, 10, 27]\n assert candidate(s = \"thisisaverylongstringthatcontainsmultipleinstancesofthesamepattern\",a = \"this\",b = \"that\",k = 25) == [0]\n assert candidate(s = \"abcdefgabcdefgabcdefg\",a = \"abc\",b = \"defg\",k = 15) == [0, 7, 14]\n assert candidate(s = \"abababababababababab\",a = \"aba\",b = \"bab\",k = 5) == [0, 2, 4, 6, 8, 10, 12, 14, 16]\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\",a = \"xy\",b = \"yx\",k = 2) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]\n assert candidate(s = \"abababababababababababababababababab\",a = \"aba\",b = \"bab\",k = 2) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",a = \"abc\",b = \"xyz\",k = 20) == []\n assert candidate(s = \"complexexamplecomplexexample\",a = \"complex\",b = \"exam\",k = 15) == [0, 14]\n assert candidate(s = \"fuzzywuzzy\",a = \"fuz\",b = \"uzz\",k = 3) == [0]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zzz\",k = 2) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]\n assert candidate(s = \"findingbeautifulindices\",a = \"find\",b = \"ind\",k = 7) == [0]\n assert candidate(s = \"aaaaaaabaaaaaa\",a = \"aa\",b = \"aaa\",k = 5) == [0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12]\n assert candidate(s = \"repeatedsubstringsarecool\",a = \"are\",b = \"cool\",k = 10) == [18]\n assert candidate(s = \"overlappingoverlapping\",a = \"over\",b = \"lap\",k = 8) == [0, 11]\n assert candidate(s = \"repeatedpatternsrepeatedpatternsrepeatedpatterns\",a = \"repeated\",b = \"patterns\",k = 20) == [0, 16, 32]\n assert candidate(s = \"mississippiissiisipiissipississippi\",a = \"issi\",b = \"ippi\",k = 10) == [1, 4, 11, 25, 28]\n assert candidate(s = \"ababababababababababababababababa\",a = \"aba\",b = \"bab\",k = 4) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(s = \"mississippiississippiississippi\",a = \"issi\",b = \"miss\",k = 12) == [1, 4, 11]\n assert candidate(s = \"xyxyxyxyxyxy\",a = \"xyx\",b = \"yxy\",k = 4) == [0, 2, 4, 6, 8]\n assert candidate(s = \"abcdefghijabcdefghij\",a = \"def\",b = \"ghi\",k = 10) == [3, 13]\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"issi\",k = 4) == [1, 4]\n assert candidate(s = \"onetwothreefourfivesixseveneightnine\",a = \"one\",b = \"two\",k = 5) == [0]\n assert candidate(s = \"aaaaaaaaaabaaaaaaaaaabaaaaaaaaaab\",a = \"aaaaaa\",b = \"aaab\",k = 15) == [0, 1, 2, 3, 4, 11, 12, 13, 14, 15, 22, 23, 24, 25, 26]\n assert candidate(s = \"programmingisfun\",a = \"fun\",b = \"ing\",k = 10) == [13]\n assert candidate(s = \"abracadabra\",a = \"abr\",b = \"cad\",k = 8) == [0, 7]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"cdef\",b = \"ghij\",k = 5) == [2, 12, 22]\n assert candidate(s = \"repeatedrepeatedrepeated\",a = \"peat\",b = \"peat\",k = 3) == [2, 10, 18]\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdef\",a = \"cdef\",b = \"ab\",k = 8) == [2, 8, 14, 20, 26]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zz\",k = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"abc\",b = \"efg\",k = 15) == [0, 10, 20]\n assert candidate(s = \"abcdefghijabcdefghij\",a = \"abc\",b = \"efg\",k = 12) == [0, 10]\n assert candidate(s = \"thisisaverylongstringwithaverylongsubstring\",a = \"very\",b = \"long\",k = 20) == [7, 26]\n assert candidate(s = \"squirrelmysquirrelhouse\",a = \"my\",b = \"squirrel\",k = 10) == [8]\n assert candidate(s = \"bananaananabananananana\",a = \"ana\",b = \"nan\",k = 5) == [1, 3, 6, 8, 12, 14, 16, 18, 20]\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"sip\",k = 4) == [4]\n assert candidate(s = \"abababababab\",a = \"aba\",b = \"bab\",k = 3) == [0, 2, 4, 6, 8]\n assert candidate(s = \"beautifulbeautifulbeautifulbeautiful\",a = \"bea\",b = \"ful\",k = 15) == [0, 9, 18, 27]\n assert candidate(s = \"thisisaverylongstringwithrepeatedsubstringsandlongoccurrencesofpatterns\",a = \"long\",b = \"pattern\",k = 30) == [46]\n assert candidate(s = \"beautifuldaybeautifulday\",a = \"day\",b = \"beau\",k = 12) == [9, 21]\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\",a = \"xyz\",b = \"yzx\",k = 2) == [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]\n assert candidate(s = \"thisisaverylongstringwithmultiplesubstrings\",a = \"very\",b = \"string\",k = 20) == [7]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",a = \"zz\",b = \"zzz\",k = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxy\",a = \"xy\",b = \"yx\",k = 3) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n assert candidate(s = \"aaaaabaaaabaaaaaaaba\",a = \"aa\",b = \"aaa\",k = 5) == [0, 1, 2, 3, 6, 7, 8, 11, 12, 13, 14, 15, 16]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"abc\",b = \"efg\",k = 8) == [0, 10, 20]\n assert candidate(s = \"repeatedrepeatedrepeated\",a = \"repe\",b = \"ated\",k = 6) == [0, 8, 16]\n assert candidate(s = \"racecar\",a = \"race\",b = \"car\",k = 5) == [0]\n assert candidate(s = \"thisissomereallylongstringwithsomerepetitions\",a = \"some\",b = \"long\",k = 15) == [6, 30]\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",a = \"abc\",b = \"xyz\",k = 10) == []\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\",a = \"ghi\",b = \"def\",k = 8) == [6, 16, 26, 36]\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",a = \"quick\",b = \"lazy\",k = 20) == []\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",a = \"mnop\",b = \"qrst\",k = 10) == [12]\n assert candidate(s = \"onetwothreefourfivesixseveneightnine\",a = \"two\",b = \"nine\",k = 20) == []\n assert candidate(s = \"thisisaverylongstringwithmultiplesubstrings\",a = \"very\",b = \"string\",k = 10) == [7]\n assert candidate(s = \"patternmatchingexamplepatternmatchingexamplepatternmatchingexample\",a = \"example\",b = \"pattern\",k = 50) == [15, 37, 59]\n assert candidate(s = \"aaabbbcccaaa\",a = \"aaa\",b = \"bbb\",k = 5) == [0]\n assert candidate(s = \"thisisaverylongstringfortesting\",a = \"very\",b = \"long\",k = 12) == [7]\n assert candidate(s = \"bananaananabay\",a = \"ana\",b = \"nana\",k = 4) == [1, 3, 6, 8]\n assert candidate(s = \"abababababababababab\",a = \"aba\",b = \"bab\",k = 2) == [0, 2, 4, 6, 8, 10, 12, 14, 16]\n assert candidate(s = \"bananaananabananananabanana\",a = \"ana\",b = \"nan\",k = 5) == [1, 3, 6, 8, 12, 14, 16, 18, 22, 24]\n assert candidate(s = \"thisissomethingreallylongthatshouldtestthelimits\",a = \"test\",b = \"limits\",k = 25) == [35]\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\",a = \"qwerty\",b = \"poi\",k = 15) == []\n assert candidate(s = \"bananaananabanana\",a = \"ana\",b = \"na\",k = 5) == [1, 3, 6, 8, 12, 14]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"def\",b = \"ghi\",k = 10) == [3, 13, 23]\n assert candidate(s = \"thisisaverylongstringwithmultiplesubstrings\",a = \"long\",b = \"string\",k = 10) == [11]\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiop\",a = \"qwerty\",b = \"uiop\",k = 6) == [0, 10, 20]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"iss\",k = 5) == [1, 4]\n assert candidate(s = \"aabbccddeeffgghhiijjkk\",a = \"abc\",b = \"def\",k = 10) == []\n assert candidate(s = \"abababababababababab\",a = \"aba\",b = \"bab\",k = 4) == [0, 2, 4, 6, 8, 10, 12, 14, 16]\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\",a = \"micro\",b = \"scopic\",k = 30) == [13]\n", "comparison": "exact"}, "public_tests": ["\"isawsquirrelnearmysquirrelhouseohmy\"\n\"my\"\n\"squirrel\"\n15", "\"abcd\"\n\"a\"\n\"a\"\n4"], "hints": ["For each i, you can iterate over all js and determine if i is beautiful or not."], "metadata": {"canonical_parameter_names": ["s", "a", "b", "k"], "leetcode_dataset_entry_point": "Solution().beautifulIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:02+00:00", "tests_total": 115, "tests_dropped": 2, "flags": [], "topic_tags": ["two-pointers", "string", "binary-search", "rolling-hash", "string-matching", "hash-function", "z-algorithm", "knuth-morris-pratt-algorithm", "boyer-moore-string-search-algorithm"]}, "language": "ruby", "interface": {"raw_signature": "def beautiful_indices(s, a, b, k)", "container": null, "callable": "beautiful_indices", "parameters": [{"name": "s", "type": "String"}, {"name": "a", "type": "String"}, {"name": "b", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3007, "task_id": "maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "difficulty": "Medium", "problem_description": "You are given an integer k and an integer x. The price of a number num is calculated by the count of set bits at positions x, 2x, 3x, etc., in its binary representation, starting from the least significant bit. The following table contains examples of how price is calculated.\n\nx | num | Binary Representation | Price\n1 | 13 | 000001101 | 3\n2 | 13 | 000001101 | 1\n2 | 233 | 011101001 | 3\n3 | 13 | 000001101 | 1\n3 | 362 | 101101010 | 2\n\nThe accumulated price of num is the total price of numbers from 1 to num. num is considered cheap if its accumulated price is less than or equal to k.\n\nReturn the greatest cheap number.\n\nExample 1:\n\nInput: k = 9, x = 1\nOutput: 6\nExplanation:\nAs shown in the table below, 6 is the greatest cheap number.\n\nx | num | Binary Representation | Price | Accumulated Price\n1 | 1 | 001 | 1 | 1\n1 | 2 | 010 | 1 | 2\n1 | 3 | 011 | 2 | 4\n1 | 4 | 100 | 1 | 5\n1 | 5 | 101 | 2 | 7\n1 | 6 | 110 | 2 | 9\n1 | 7 | 111 | 3 | 12\n\nExample 2:\n\nInput: k = 7, x = 2\nOutput: 9\nExplanation:\nAs shown in the table below, 9 is the greatest cheap number.\n\nx | num | Binary Representation | Price | Accumulated Price\n2 | 1 | 0001 | 0 | 0\n2 | 2 | 0010 | 1 | 1\n2 | 3 | 0011 | 1 | 2\n2 | 4 | 0100 | 0 | 2\n2 | 5 | 0101 | 0 | 2\n2 | 6 | 0110 | 1 | 3\n2 | 7 | 0111 | 1 | 4\n2 | 8 | 1000 | 1 | 5\n2 | 9 | 1001 | 1 | 6\n2 | 10 | 1010 | 2 | 8\n\nConstraints:\n\n- 1 <= k <= 10^15\n- 1 <= x <= 8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(k = 15,x = 1) == 9\n assert candidate(k = 5,x = 2) == 8\n assert candidate(k = 100000000000000,x = 8) == 40104798005951\n assert candidate(k = 500,x = 6) == 1011\n assert candidate(k = 20,x = 2) == 23\n assert candidate(k = 5,x = 1) == 4\n assert candidate(k = 15,x = 4) == 30\n assert candidate(k = 7,x = 2) == 9\n assert candidate(k = 100,x = 4) == 153\n assert candidate(k = 15,x = 3) == 30\n assert candidate(k = 10,x = 3) == 21\n assert candidate(k = 9,x = 1) == 6\n assert candidate(k = 1000,x = 7) == 2023\n assert candidate(k = 1000,x = 6) == 2023\n assert candidate(k = 1000000000000000,x = 8) == 343778878348159\n assert candidate(k = 100,x = 5) == 211\n assert candidate(k = 1000000,x = 8) == 1016223\n assert candidate(k = 9876543210,x = 2) == 1335770905\n assert candidate(k = 75000000000000,x = 5) == 18535653792058\n assert candidate(k = 1000000,x = 2) == 229535\n assert candidate(k = 37500000000000,x = 6) == 11028437048759\n assert candidate(k = 8,x = 8) == 135\n assert candidate(k = 200000000000000,x = 4) == 36505448274943\n assert candidate(k = 1000,x = 8) == 2023\n assert candidate(k = 987654321,x = 5) == 396332511\n assert candidate(k = 65536,x = 2) == 19343\n assert candidate(k = 123456789,x = 7) == 82565716\n assert candidate(k = 987654321,x = 3) == 225159917\n assert candidate(k = 500,x = 4) == 505\n assert candidate(k = 876543210,x = 4) == 252864144\n assert candidate(k = 300,x = 2) == 174\n assert candidate(k = 75,x = 7) == 202\n assert candidate(k = 987654321,x = 7) == 502583375\n assert candidate(k = 10000,x = 5) == 10079\n assert candidate(k = 67890,x = 4) == 40389\n assert candidate(k = 888888888,x = 1) == 68597981\n assert candidate(k = 750,x = 6) == 1517\n assert candidate(k = 89,x = 4) == 144\n assert candidate(k = 512,x = 5) == 687\n assert candidate(k = 25000,x = 4) == 16839\n assert candidate(k = 100000000000000,x = 1) == 4779296144709\n assert candidate(k = 1000000000000,x = 2) == 112964310932\n assert candidate(k = 50,x = 5) == 113\n assert candidate(k = 999999999999999,x = 6) == 253657567778409\n assert candidate(k = 150000000000000,x = 4) == 27972811528487\n assert candidate(k = 500000000,x = 5) == 200231279\n assert candidate(k = 3000000000,x = 7) == 1522191359\n assert candidate(k = 1000000,x = 4) == 505131\n assert candidate(k = 1000,x = 3) == 751\n assert candidate(k = 1023,x = 1) == 254\n assert candidate(k = 456789123456789,x = 5) == 101944274868895\n assert candidate(k = 111111111111111,x = 7) == 37402810498266\n assert candidate(k = 500000000000000,x = 2) == 44975429102831\n assert candidate(k = 123456789012345,x = 7) == 41467248081098\n assert candidate(k = 35791,x = 6) == 36150\n assert candidate(k = 99999999999999,x = 8) == 40104798005950\n assert candidate(k = 50000000000000,x = 7) == 16799267244329\n assert candidate(k = 50,x = 1) == 22\n assert candidate(k = 1000000000000000,x = 7) == 320446066360319\n assert candidate(k = 500,x = 5) == 675\n assert candidate(k = 100000000000000,x = 5) == 23566547569891\n assert candidate(k = 86420,x = 1) == 12978\n assert candidate(k = 1000000,x = 1) == 120205\n assert candidate(k = 9375000000000,x = 8) == 3858234249087\n assert candidate(k = 125,x = 8) == 252\n assert candidate(k = 5000,x = 6) == 5927\n assert candidate(k = 200,x = 5) == 407\n assert candidate(k = 12345678912345,x = 7) == 4155872352796\n assert candidate(k = 50,x = 2) == 41\n assert candidate(k = 500000000000000,x = 6) == 142592321015807\n assert candidate(k = 1000000000,x = 6) == 500668855\n assert candidate(k = 2,x = 1) == 2\n assert candidate(k = 897654321000,x = 3) == 151072975789\n assert candidate(k = 123456789,x = 2) == 20934568\n assert candidate(k = 87654321098765,x = 5) == 21067518135670\n assert candidate(k = 150,x = 5) == 309\n assert candidate(k = 1000000000,x = 5) == 400458607\n assert candidate(k = 7777777777777,x = 8) == 3142572550626\n assert candidate(k = 1024,x = 6) == 2047\n assert candidate(k = 100000000,x = 7) == 66778015\n assert candidate(k = 500,x = 3) == 379\n assert candidate(k = 500000000000000,x = 8) == 183136759108959\n assert candidate(k = 999999999999999,x = 8) == 343778878348158\n assert candidate(k = 8000000000000,x = 6) == 2550830257769\n assert candidate(k = 1000,x = 2) == 504\n assert candidate(k = 500,x = 7) == 1011\n assert candidate(k = 1000000,x = 7) == 1000639\n assert candidate(k = 64,x = 4) == 127\n assert candidate(k = 999999999999999,x = 7) == 320446066360318\n assert candidate(k = 987654321,x = 2) == 150736664\n assert candidate(k = 300000000000000,x = 3) == 40423774188390\n assert candidate(k = 25,x = 6) == 56\n assert candidate(k = 99999999999999,x = 1) == 4779296144709\n assert candidate(k = 256,x = 3) == 255\n assert candidate(k = 1000000,x = 3) == 350061\n assert candidate(k = 128,x = 2) == 95\n assert candidate(k = 333333333333333,x = 5) == 74563043705932\n assert candidate(k = 200,x = 6) == 423\n assert candidate(k = 1000000000000000,x = 1) == 44470852534271\n assert candidate(k = 123456789012345,x = 2) == 11594690512161\n assert candidate(k = 10000000000000,x = 2) == 1010190497191\n assert candidate(k = 97531,x = 7) == 97788\n assert candidate(k = 2048,x = 7) == 4159\n assert candidate(k = 800000000000000,x = 1) == 35598682963967\n assert candidate(k = 987654321,x = 4) == 284658738\n assert candidate(k = 75319,x = 8) == 85174\n assert candidate(k = 43210,x = 2) == 12987\n assert candidate(k = 250000000,x = 8) == 166950655\n assert candidate(k = 24680,x = 5) == 20551\n assert candidate(k = 1,x = 1) == 1\n assert candidate(k = 123456789,x = 5) == 52351833\n assert candidate(k = 4096,x = 8) == 8319\n assert candidate(k = 1000000,x = 5) == 611931\n assert candidate(k = 1000000,x = 6) == 696703\n assert candidate(k = 100,x = 3) == 109\n assert candidate(k = 10,x = 8) == 137\n assert candidate(k = 12345,x = 3) == 6589\n assert candidate(k = 123456789,x = 3) == 31193134\n assert candidate(k = 1,x = 8) == 128\n assert candidate(k = 123456789,x = 6) == 62823067\n assert candidate(k = 2000000000,x = 6) == 846978196\n assert candidate(k = 23,x = 3) == 36\n assert candidate(k = 2147483647,x = 7) == 1073741822\n assert candidate(k = 30,x = 3) == 41\n assert candidate(k = 18750000000000,x = 7) == 6615951850383\n assert candidate(k = 75,x = 1) == 30\n", "comparison": "exact"}, "public_tests": ["9\n1", "7\n2"], "hints": ["Binary search the answer.", "In each step of the binary search you should calculate the number of the set bits in the i^th position. Then calculate the sum of them."], "metadata": {"canonical_parameter_names": ["k", "x"], "leetcode_dataset_entry_point": "Solution().findMaximumNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:04+00:00", "tests_total": 126, "tests_dropped": 0, "flags": ["figure_reference"], "topic_tags": ["math", "binary-search", "dynamic-programming", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_maximum_number(k, x)", "container": null, "callable": "find_maximum_number", "parameters": [{"name": "k", "type": "Integer"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3008, "task_id": "find-beautiful-indices-in-the-given-array-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed string s, a string a, a string b, and an integer k.\n\nAn index i is beautiful if:\n\n- 0 <= i <= s.length - a.length\n- s[i..(i + a.length - 1)] == a\n- There exists an index j such that:\n - 0 <= j <= s.length - b.length\n - s[j..(j + b.length - 1)] == b\n - |j - i| <= k\n\nReturn the array that contains beautiful indices in sorted order from smallest to largest.\n\nExample 1:\n\nInput: s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\nOutput: [16,33]\nExplanation: There are 2 beautiful indices: [16,33].\n- The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n- The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\nThus we return [16,33] as the result.\n\nExample 2:\n\nInput: s = \"abcd\", a = \"a\", b = \"a\", k = 4\nOutput: [0]\nExplanation: There is 1 beautiful index: [0].\n- The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\nThus we return [0] as the result.\n\nConstraints:\n\n- 1 <= k <= s.length <= 5 * 10^5\n- 1 <= a.length, b.length <= 5 * 10^5\n- s, a, and b contain only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"beautifulbeautifulbeautiful\",a = \"ful\",b = \"uti\",k = 5) == [6, 15, 24]\n assert candidate(s = \"abcabcabcabcabc\",a = \"abc\",b = \"bca\",k = 3) == [0, 3, 6, 9, 12]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"ippi\",k = 4) == [4]\n assert candidate(s = \"abcabcabc\",a = \"abc\",b = \"cab\",k = 3) == [0, 3, 6]\n assert candidate(s = \"abcabcabc\",a = \"abc\",b = \"cab\",k = 2) == [0, 3, 6]\n assert candidate(s = \"aaaaaaa\",a = \"aa\",b = \"aa\",k = 2) == [0, 1, 2, 3, 4, 5]\n assert candidate(s = \"beautifuldayinbeautifultown\",a = \"day\",b = \"town\",k = 10) == []\n assert candidate(s = \"hellohellohello\",a = \"he\",b = \"lo\",k = 2) == [5, 10]\n assert candidate(s = \"abcd\",a = \"a\",b = \"a\",k = 4) == [0]\n assert candidate(s = \"isawsquirrelnearmysquirrelhouseohmy\",a = \"my\",b = \"squirrel\",k = 15) == [16, 33]\n assert candidate(s = \"hellobeautifulworld\",a = \"bea\",b = \"ful\",k = 5) == []\n assert candidate(s = \"ababababa\",a = \"aba\",b = \"bab\",k = 2) == [0, 2, 4, 6]\n assert candidate(s = \"hellohellohello\",a = \"he\",b = \"lo\",k = 5) == [0, 5, 10]\n assert candidate(s = \"bananaananabananaba\",a = \"ana\",b = \"nana\",k = 3) == [1, 3, 6, 8, 12, 14]\n assert candidate(s = \"babababababababababa\",a = \"aba\",b = \"bab\",k = 2) == [1, 3, 5, 7, 9, 11, 13, 15, 17]\n assert candidate(s = \"sequenceofcharacters\",a = \"que\",b = \"nce\",k = 4) == [2]\n assert candidate(s = \"abababababab\",a = \"aba\",b = \"bab\",k = 2) == [0, 2, 4, 6, 8]\n assert candidate(s = \"mississippimississippi\",a = \"issi\",b = \"ippi\",k = 6) == [1, 4, 12, 15]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"issip\",k = 5) == [1, 4]\n assert candidate(s = \"zzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zzz\",k = 3) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(s = \"qwertyuiopqwertyuiop\",a = \"qwerty\",b = \"uiop\",k = 4) == [10]\n assert candidate(s = \"xyxxyxyxyxyxyxyxyx\",a = \"xy\",b = \"yx\",k = 4) == [0, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zzzz\",k = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefgabcdefg\",a = \"abc\",b = \"def\",k = 12) == [0, 7, 14, 21, 28]\n assert candidate(s = \"repeatedrepeatedrepeated\",a = \"pea\",b = \"eat\",k = 6) == [2, 10, 18]\n assert candidate(s = \"ababababababababab\",a = \"aba\",b = \"bab\",k = 1) == [0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiop\",a = \"qwerty\",b = \"uiop\",k = 15) == [0, 10, 20]\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\",a = \"erty\",b = \"ghjk\",k = 10) == []\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"def\",b = \"jabcdefghi\",k = 12) == [3, 13, 23]\n assert candidate(s = \"bananaananabayana\",a = \"ana\",b = \"anaba\",k = 6) == [3, 6, 8, 14]\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",a = \"mnop\",b = \"qrst\",k = 10) == []\n assert candidate(s = \"longstringwithrepeatedpatternsandpatterns\",a = \"pattern\",b = \"patterns\",k = 10) == [22, 33]\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"sis\",k = 4) == [1, 4]\n assert candidate(s = \"bananaananabananabanana\",a = \"ana\",b = \"anana\",k = 5) == [1, 3, 6, 8, 12, 14, 18, 20]\n assert candidate(s = \"qwertyuiopqwertyuiop\",a = \"rty\",b = \"tyu\",k = 6) == [3, 13]\n assert candidate(s = \"xyzyzyzyzyzyzyz\",a = \"zyz\",b = \"yzy\",k = 4) == [2, 4, 6, 8, 10, 12]\n assert candidate(s = \"thisisaverylongstringwithvariouswords\",a = \"word\",b = \"words\",k = 20) == [32]\n assert candidate(s = \"zzzzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zzz\",k = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\",a = \"xyxy\",b = \"yxyx\",k = 6) == [0, 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]\n assert candidate(s = \"xyzzxyzzxyzzxyzz\",a = \"zz\",b = \"xy\",k = 4) == [2, 6, 10, 14]\n assert candidate(s = \"abababababababa\",a = \"aba\",b = \"bab\",k = 5) == [0, 2, 4, 6, 8, 10, 12]\n assert candidate(s = \"abcdabcdabcdabcd\",a = \"abcd\",b = \"dcba\",k = 8) == []\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\",a = \"asdf\",b = \"ghjk\",k = 10) == [10]\n assert candidate(s = \"lkjsdhflksjdhflksjdhflksjdhf\",a = \"ksj\",b = \"jdh\",k = 10) == [8, 15, 22]\n assert candidate(s = \"thisisaverylongstringwithmultiplesubstrings\",a = \"string\",b = \"multiplesubstrings\",k = 20) == [15, 36]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"ghi\",b = \"def\",k = 3) == [6, 16, 26]\n assert candidate(s = \"abababababababababababababababababababababababababab\",a = \"abab\",b = \"baba\",k = 5) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiop\",a = \"qwe\",b = \"rty\",k = 5) == [0, 10, 20]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"ippi\",k = 5) == [4]\n assert candidate(s = \"bananaananabananana\",a = \"ana\",b = \"nana\",k = 7) == [1, 3, 6, 8, 12, 14, 16]\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",a = \"abc\",b = \"xyz\",k = 20) == []\n assert candidate(s = \"hellohellohellohello\",a = \"llo\",b = \"hel\",k = 7) == [2, 7, 12, 17]\n assert candidate(s = \"bananaananabananabanana\",a = \"ana\",b = \"nan\",k = 5) == [1, 3, 6, 8, 12, 14, 18, 20]\n assert candidate(s = \"repeatedrepeatedrepeated\",a = \"repeated\",b = \"atedrepe\",k = 9) == [0, 8, 16]\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"sip\",k = 5) == [1, 4]\n assert candidate(s = \"aabbccddeeffgghhiijj\",a = \"abcd\",b = \"bcde\",k = 4) == []\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"sis\",k = 2) == [1, 4]\n assert candidate(s = \"patternpatternpatternpattern\",a = \"pattern\",b = \"ternpat\",k = 15) == [0, 7, 14, 21]\n assert candidate(s = \"abcdefghijabcdefghij\",a = \"abc\",b = \"def\",k = 10) == [0, 10]\n assert candidate(s = \"mississippiississipi\",a = \"iss\",b = \"issi\",k = 4) == [1, 4, 11, 14]\n assert candidate(s = \"abacabadabacaba\",a = \"aba\",b = \"aca\",k = 8) == [0, 4, 8, 12]\n assert candidate(s = \"ababababababababab\",a = \"aba\",b = \"bab\",k = 6) == [0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(s = \"xyzxyzxyzxyzxyzxyz\",a = \"xyz\",b = \"zyx\",k = 5) == []\n assert candidate(s = \"ababababababababab\",a = \"aba\",b = \"bab\",k = 5) == [0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(s = \"bananaananabanananananabanana\",a = \"ana\",b = \"nana\",k = 8) == [1, 3, 6, 8, 12, 14, 16, 18, 20, 24, 26]\n assert candidate(s = \"overlappingoverlapping\",a = \"over\",b = \"lap\",k = 5) == [0, 11]\n assert candidate(s = \"banana\",a = \"ana\",b = \"nan\",k = 2) == [1, 3]\n assert candidate(s = \"longstringwithsubstring\",a = \"with\",b = \"subs\",k = 10) == [10]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",a = \"xyz\",b = \"uvw\",k = 3) == [23]\n assert candidate(s = \"mississippi\",a = \"iss\",b = \"issi\",k = 3) == [1, 4]\n assert candidate(s = \"aaaaabbbbbbbcccccc\",a = \"bbbb\",b = \"cccc\",k = 6) == [6, 7, 8]\n assert candidate(s = \"abcdefghijabcdefghij\",a = \"efgh\",b = \"ghij\",k = 5) == [4, 14]\n assert candidate(s = \"repeatedpatternrepeatedpattern\",a = \"repe\",b = \"atte\",k = 8) == [15]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",a = \"mnopqr\",b = \"ghijkl\",k = 15) == [12, 38]\n assert candidate(s = \"abracadabraabracadabra\",a = \"abra\",b = \"cad\",k = 5) == [0, 7, 11, 18]\n assert candidate(s = \"foobarfoobarfoobar\",a = \"foo\",b = \"bar\",k = 6) == [0, 6, 12]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",a = \"def\",b = \"xyz\",k = 15) == []\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",a = \"zz\",b = \"zz\",k = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]\n assert candidate(s = \"hellohellohellohello\",a = \"hel\",b = \"ell\",k = 4) == [0, 5, 10, 15]\n assert candidate(s = \"complexstringwithmultipleoverlaps\",a = \"over\",b = \"overlap\",k = 12) == [25]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zzzz\",k = 3) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]\n assert candidate(s = \"abracadabraabracadabra\",a = \"cad\",b = \"bra\",k = 8) == [4, 15]\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxy\",a = \"xyx\",b = \"yxy\",k = 3) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n assert candidate(s = \"abcdefghijabcdefghij\",a = \"def\",b = \"ghi\",k = 8) == [3, 13]\n assert candidate(s = \"bananaananabanana\",a = \"ana\",b = \"naa\",k = 7) == [1, 3, 6, 8]\n assert candidate(s = \"racecaracecaracecaracecar\",a = \"ace\",b = \"cec\",k = 4) == [1, 7, 13, 19]\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\",a = \"qwerty\",b = \"zxcvbn\",k = 10) == [26]\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcd\",a = \"abc\",b = \"bcd\",k = 1) == [0, 4, 8, 12, 16, 20, 24]\n assert candidate(s = \"abcdefghijabcdefghij\",a = \"abc\",b = \"cde\",k = 10) == [0, 10]\n assert candidate(s = \"mississippi\",a = \"issi\",b = \"issip\",k = 2) == [4]\n assert candidate(s = \"xyzxyzxyzxyzxyzxyz\",a = \"xyz\",b = \"zyx\",k = 4) == []\n assert candidate(s = \"repeatedrepeatedrepeatedrepeated\",a = \"repeated\",b = \"eatedr\",k = 18) == [0, 8, 16, 24]\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",a = \"abcabc\",b = \"bcabca\",k = 12) == [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]\n assert candidate(s = \"xyxyxyxyxyxyxyxyxy\",a = \"xyxy\",b = \"xyxyxy\",k = 8) == [0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(s = \"abababababababab\",a = \"ab\",b = \"ba\",k = 2) == [0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(s = \"abababababab\",a = \"aba\",b = \"bab\",k = 5) == [0, 2, 4, 6, 8]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\",a = \"cde\",b = \"efg\",k = 5) == [2, 12, 22, 32]\n assert candidate(s = \"abcdefgabcdefgabcdefg\",a = \"def\",b = \"abc\",k = 10) == [3, 10, 17]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",a = \"ghij\",b = \"efgh\",k = 20) == [6, 16, 26, 36, 46]\n assert candidate(s = \"hellohellohello\",a = \"hello\",b = \"ohell\",k = 6) == [0, 5, 10]\n assert candidate(s = \"aabbccddeeffaabbccddeeff\",a = \"abb\",b = \"bbc\",k = 2) == [1, 13]\n assert candidate(s = \"ababababababababab\",a = \"aba\",b = \"bab\",k = 4) == [0, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"def\",b = \"ghi\",k = 3) == [3, 13, 23]\n assert candidate(s = \"repeatedsubstringrepeatedsubstring\",a = \"substring\",b = \"substr\",k = 15) == [8, 25]\n assert candidate(s = \"abcabcabcabcabcabc\",a = \"abc\",b = \"abcabc\",k = 5) == [0, 3, 6, 9, 12, 15]\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwerty\",a = \"erty\",b = \"asdf\",k = 10) == [2]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"abc\",b = \"efg\",k = 10) == [0, 10, 20]\n assert candidate(s = \"abacabadabacaba\",a = \"aba\",b = \"aca\",k = 5) == [0, 4, 8, 12]\n assert candidate(s = \"hellohellohellohellohellohellohello\",a = \"hello\",b = \"elloh\",k = 20) == [0, 5, 10, 15, 20, 25, 30]\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",a = \"abc\",b = \"cab\",k = 2) == [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]\n assert candidate(s = \"mississippiississippiississippiississippiississippi\",a = \"issi\",b = \"issip\",k = 15) == [1, 4, 11, 14, 21, 24, 31, 34, 41, 44]\n assert candidate(s = \"hellohellohellohello\",a = \"hello\",b = \"lohel\",k = 7) == [0, 5, 10, 15]\n assert candidate(s = \"hellohellohellohello\",a = \"ell\",b = \"ell\",k = 2) == [1, 6, 11, 16]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"abc\",b = \"ghi\",k = 7) == [0, 10, 20]\n assert candidate(s = \"thisisaverylongstringwithmanywords\",a = \"very\",b = \"with\",k = 15) == [7]\n assert candidate(s = \"mississippiississippi\",a = \"issi\",b = \"ippi\",k = 10) == [1, 4, 11, 14]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",a = \"zzz\",b = \"zzzz\",k = 8) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]\n assert candidate(s = \"bananaanananabanananabanananabanananabananana\",a = \"anan\",b = \"nana\",k = 8) == [1, 6, 8, 14, 16, 22, 24, 30, 32, 38, 40]\n assert candidate(s = \"xyxxyxyxyxxyxyxyxyxyxy\",a = \"xyx\",b = \"xyxy\",k = 4) == [0, 3, 5, 7, 10, 12, 14, 16, 18]\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",a = \"abc\",b = \"ghi\",k = 5) == [10, 20]\n", "comparison": "exact"}, "public_tests": ["\"isawsquirrelnearmysquirrelhouseohmy\"\n\"my\"\n\"squirrel\"\n15", "\"abcd\"\n\"a\"\n\"a\"\n4"], "hints": ["Use KMP or string hashing."], "metadata": {"canonical_parameter_names": ["s", "a", "b", "k"], "leetcode_dataset_entry_point": "Solution().beautifulIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:07+00:00", "tests_total": 122, "tests_dropped": 2, "flags": [], "topic_tags": ["two-pointers", "string", "binary-search", "rolling-hash", "string-matching", "hash-function", "z-algorithm", "knuth-morris-pratt-algorithm", "boyer-moore-string-search-algorithm"]}, "language": "ruby", "interface": {"raw_signature": "def beautiful_indices(s, a, b, k)", "container": null, "callable": "beautiful_indices", "parameters": [{"name": "s", "type": "String"}, {"name": "a", "type": "String"}, {"name": "b", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3010, "task_id": "divide-an-array-into-subarrays-with-minimum-cost-i", "difficulty": "Easy", "problem_description": "You are given an array of integers nums of length n.\n\nThe cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\n\nYou need to divide nums into 3 disjoint contiguous subarrays.\n\nReturn the minimum possible sum of the cost of these subarrays.\n\nExample 1:\n\nInput: nums = [1,2,3,12]\nOutput: 6\nExplanation: The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6.\nThe other possible ways to form 3 subarrays are:\n- [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.\n- [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.\n\nExample 2:\n\nInput: nums = [5,4,3]\nOutput: 12\nExplanation: The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.\nIt can be shown that 12 is the minimum cost achievable.\n\nExample 3:\n\nInput: nums = [10,3,1,1]\nOutput: 12\nExplanation: The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.\nIt can be shown that 12 is the minimum cost achievable.\n\nConstraints:\n\n- 3 <= n <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [30, 20, 10, 40, 50]) == 60\n assert candidate(nums = [50, 49, 48, 47, 46, 45]) == 141\n assert candidate(nums = [5, 4, 3]) == 12\n assert candidate(nums = [40, 30, 20, 10, 5]) == 55\n assert candidate(nums = [50, 1, 50, 1, 50]) == 52\n assert candidate(nums = [4, 5, 2, 3, 1, 6]) == 7\n assert candidate(nums = [3, 1, 2, 4, 5]) == 6\n assert candidate(nums = [1, 5, 2, 4, 3]) == 6\n assert candidate(nums = [10, 3, 1, 1]) == 12\n assert candidate(nums = [10, 20, 30, 40, 50]) == 60\n assert candidate(nums = [5, 1, 4, 2, 3]) == 8\n assert candidate(nums = [2, 1, 4, 3, 5]) == 6\n assert candidate(nums = [40, 30, 20, 10, 50]) == 70\n assert candidate(nums = [30, 20, 10, 50, 40]) == 60\n assert candidate(nums = [1, 2, 3, 12]) == 6\n assert candidate(nums = [1, 3, 2, 5, 4]) == 6\n assert candidate(nums = [15, 20, 10, 25, 30]) == 45\n assert candidate(nums = [3, 1, 2, 2, 5]) == 6\n assert candidate(nums = [20, 10, 30, 5, 45]) == 35\n assert candidate(nums = [3, 3, 3, 3, 3]) == 9\n assert candidate(nums = [1, 50, 2, 49, 3]) == 6\n assert candidate(nums = [15, 25, 35, 5, 10]) == 30\n assert candidate(nums = [30, 10, 20, 5, 25, 40, 15]) == 45\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]) == 6\n assert candidate(nums = [50, 25, 10, 5, 1, 2, 3, 4]) == 53\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6]) == 8\n assert candidate(nums = [30, 20, 10, 5, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 33\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 53\n assert candidate(nums = [4, 3, 2, 1, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40]) == 7\n assert candidate(nums = [20, 15, 10, 5, 1, 2, 3, 4]) == 23\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 18\n assert candidate(nums = [5, 1, 4, 2, 8, 3]) == 8\n assert candidate(nums = [30, 20, 10, 5, 15, 25, 35, 40, 45, 50]) == 45\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == 13\n assert candidate(nums = [45, 40, 35, 30, 25, 20, 15, 10, 5]) == 60\n assert candidate(nums = [15, 10, 5, 3, 8, 2, 7]) == 20\n assert candidate(nums = [15, 3, 18, 6, 7, 9, 2]) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 13, 14]) == 13\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 30\n assert candidate(nums = [4, 2, 9, 1, 7, 3, 5]) == 7\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 6\n assert candidate(nums = [1, 49, 2, 48, 3, 47, 4, 46, 5, 45, 6, 44, 7, 43, 8, 42, 9, 41, 10, 40, 11, 39, 12, 38, 13, 37, 14, 36, 15, 35]) == 6\n assert candidate(nums = [45, 30, 15, 5, 1, 50, 40, 35, 25, 20]) == 51\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]) == 3\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40]) == 131\n assert candidate(nums = [50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 53\n assert candidate(nums = [3, 2, 1, 50, 49, 48, 47, 46, 45]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [30, 10, 20, 5, 25, 40, 15, 50, 2, 1]) == 33\n assert candidate(nums = [23, 12, 7, 3, 1, 8, 4, 9, 5, 10, 6, 11]) == 27\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 43, 36, 29, 22]) == 42\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]) == 53\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 6\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 8, 7, 9, 11]) == 8\n assert candidate(nums = [45, 21, 32, 18, 9, 40, 35]) == 72\n assert candidate(nums = [45, 20, 10, 5, 15, 25, 35, 40]) == 60\n assert candidate(nums = [1, 50, 2, 49, 3, 48, 4, 47, 5, 46, 6, 45, 7, 44, 8]) == 6\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11]) == 8\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 3\n assert candidate(nums = [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]) == 52\n assert candidate(nums = [42, 28, 36, 12, 45, 50, 10, 20, 30]) == 64\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 50]) == 13\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15]) == 61\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]) == 15\n assert candidate(nums = [5, 2, 1, 3, 8, 7, 6]) == 8\n assert candidate(nums = [30, 10, 20, 30, 10, 20, 30]) == 50\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]) == 28\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]) == 6\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]) == 30\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 6\n assert candidate(nums = [34, 12, 45, 37, 26, 48, 22, 39, 14, 47]) == 60\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 13\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 9\n assert candidate(nums = [20, 30, 10, 40, 50, 15, 25, 35, 45, 5]) == 35\n assert candidate(nums = [42, 15, 22, 7, 31, 19, 9]) == 58\n assert candidate(nums = [20, 15, 10, 5, 1, 6, 11, 16, 21]) == 26\n assert candidate(nums = [50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 53\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [50, 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]) == 53\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 5\n assert candidate(nums = [7, 3, 1, 6, 2, 5, 4, 8, 9, 10]) == 10\n assert candidate(nums = [25, 10, 5, 20, 15, 30, 25, 10, 5, 20, 15]) == 35\n assert candidate(nums = [42, 31, 23, 17, 8, 4, 5, 13, 29, 38, 11]) == 51\n assert candidate(nums = [25, 50, 15, 40, 10, 30, 20, 25, 35]) == 50\n assert candidate(nums = [23, 19, 17, 29, 25, 31, 13, 11, 15, 21]) == 47\n assert candidate(nums = [15, 10, 20, 5, 30, 25]) == 30\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 12\n assert candidate(nums = [1, 10, 3, 8, 2, 5, 4]) == 6\n assert candidate(nums = [47, 42, 37, 32, 27, 22, 17, 12, 7, 2, 49, 44, 39, 34, 29, 24, 19, 14, 9, 4, 1, 3, 8, 13, 18, 23, 28, 33, 38, 43, 48]) == 50\n assert candidate(nums = [8, 2, 6, 4, 7, 1, 3, 5]) == 11\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == 12\n assert candidate(nums = [15, 25, 35, 10, 5, 45, 40, 30, 20]) == 30\n assert candidate(nums = [45, 1, 42, 2, 44, 3, 43]) == 48\n assert candidate(nums = [25, 10, 5, 1, 9, 3, 8, 12]) == 29\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 50, 49, 48]) == 18\n assert candidate(nums = [25, 5, 15, 10, 30, 20, 40, 50, 35]) == 40\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == 13\n assert candidate(nums = [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]) == 90\n assert candidate(nums = [23, 15, 34, 10, 5, 40, 30, 20, 1, 2, 3]) == 26\n assert candidate(nums = [49, 1, 48, 2, 47, 3, 46, 4, 45, 5]) == 52\n assert candidate(nums = [5, 9, 12, 1, 6, 3, 7, 8, 4, 10, 2, 11]) == 8\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49]) == 15\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 50]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 6\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == 24\n assert candidate(nums = [5, 4, 3, 2, 1, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == 8\n", "comparison": "exact"}, "public_tests": ["[1,2,3,12]", "[5,4,3]", "[10,3,1,1]"], "hints": [], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:12+00:00", "tests_total": 116, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "sorting", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(nums)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3011, "task_id": "find-if-array-can-be-sorted", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of positive integers nums.\n\nIn one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).\n\nReturn true if you can sort the array in ascending order, else return false.\n\nExample 1:\n\nInput: nums = [8,4,2,30,15]\nOutput: true\nExplanation: Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation \"10\", \"100\", and \"1000\" respectively. The numbers 15 and 30 have four set bits each with binary representation \"1111\" and \"11110\".\nWe can sort the array using 4 operations:\n- Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].\n- Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].\n- Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].\n- Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].\nThe array has become sorted, hence we return true.\nNote that there may be other sequences of operations which also sort the array.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: The array is already sorted, hence we return true.\n\nExample 3:\n\nInput: nums = [3,16,8,4,2]\nOutput: false\nExplanation: It can be shown that it is not possible to sort the input array using any number of operations.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 2^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 7, 6, 5, 4, 8]) == False\n assert candidate(nums = [31, 14, 7, 3, 1]) == False\n assert candidate(nums = [5, 3, 1, 4, 2]) == False\n assert candidate(nums = [5, 3, 9, 6, 12]) == True\n assert candidate(nums = [4, 4, 4, 4, 4]) == True\n assert candidate(nums = [8, 4, 2, 30, 15]) == True\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == False\n assert candidate(nums = [30, 30, 30, 30, 30]) == True\n assert candidate(nums = [8, 8, 8, 8, 8]) == True\n assert candidate(nums = [16, 8, 4, 2, 32, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5]) == True\n assert candidate(nums = [2, 1, 4, 3, 8, 6]) == False\n assert candidate(nums = [28, 14, 7, 3, 1, 2, 4, 8, 16]) == False\n assert candidate(nums = [2, 1, 4, 3, 8, 7, 6, 5]) == False\n assert candidate(nums = [16, 8, 4, 2, 1]) == True\n assert candidate(nums = [5, 3, 9, 6, 12, 4, 8]) == False\n assert candidate(nums = [7, 14, 28, 21, 18]) == False\n assert candidate(nums = [15, 30, 60, 120, 240]) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 1, 1, 1, 1]) == True\n assert candidate(nums = [5, 3, 6, 8, 2]) == False\n assert candidate(nums = [2, 4, 8, 16, 32]) == True\n assert candidate(nums = [10, 12, 15, 7, 3]) == False\n assert candidate(nums = [31, 29, 28, 27, 26]) == False\n assert candidate(nums = [3, 16, 8, 4, 2]) == False\n assert candidate(nums = [4, 2, 1, 3, 8, 6]) == False\n assert candidate(nums = [31, 15, 7, 3, 1]) == False\n assert candidate(nums = [31, 15, 7, 3, 1, 2, 4, 8, 16]) == False\n assert candidate(nums = [16, 8, 4, 2, 30, 15]) == False\n assert candidate(nums = [28, 14, 7, 3, 1, 14, 28]) == False\n assert candidate(nums = [2, 2, 2, 2, 2]) == True\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7]) == False\n assert candidate(nums = [15, 15, 15, 15, 15]) == True\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == False\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]) == True\n assert candidate(nums = [5, 3, 9, 6, 12, 10, 14, 7, 11]) == False\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == True\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 3, 5, 7, 14, 28, 56, 112]) == False\n assert candidate(nums = [10, 13, 11, 14, 15, 7, 8, 12]) == False\n assert candidate(nums = [31, 23, 15, 7, 3, 1, 127, 63, 31, 15, 7, 3, 1]) == False\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256]) == False\n assert candidate(nums = [15, 30, 21, 28, 7, 14, 3, 6, 12, 24]) == False\n assert candidate(nums = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246]) == False\n assert candidate(nums = [17, 25, 29, 31, 30, 14, 6, 3, 1, 2]) == False\n assert candidate(nums = [255, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == False\n assert candidate(nums = [1, 3, 7, 15, 31, 30, 14, 7, 3, 1, 2, 4, 8, 16, 32]) == False\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == False\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == True\n assert candidate(nums = [3, 6, 12, 9, 15, 30, 60, 5, 10]) == False\n assert candidate(nums = [127, 63, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128]) == False\n assert candidate(nums = [10, 9, 5, 6, 2, 3, 1]) == False\n assert candidate(nums = [32, 16, 8, 4, 2, 1, 30, 15, 7, 14, 28, 12, 6, 3]) == False\n assert candidate(nums = [5, 3, 6, 12, 24, 48, 96, 192, 3, 6, 12]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [24, 12, 6, 3, 1, 48, 24, 12, 6, 3, 1, 96, 48, 24, 12, 6, 3, 1]) == False\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == True\n assert candidate(nums = [3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 24, 25, 30, 33, 36, 40, 45, 48, 50, 60, 66, 72, 75, 80, 90, 100]) == True\n assert candidate(nums = [5, 3, 9, 6, 10, 12, 15]) == True\n assert candidate(nums = [25, 10, 5, 3, 1, 2, 4, 8, 16, 32, 64]) == False\n assert candidate(nums = [21, 21, 14, 14, 7, 7, 3, 3, 15, 15, 30, 30, 60, 60, 120, 120, 240, 240]) == False\n assert candidate(nums = [18, 9, 4, 2, 1, 3, 6, 12, 24, 48, 96, 192]) == False\n assert candidate(nums = [15, 30, 18, 21, 7, 14, 28]) == False\n assert candidate(nums = [31, 15, 7, 3, 1, 2, 4, 8, 16, 32]) == False\n assert candidate(nums = [13, 10, 9, 6, 3, 2, 4, 8, 16]) == False\n assert candidate(nums = [30, 15, 8, 4, 2, 1]) == False\n assert candidate(nums = [64, 32, 16, 8, 4, 2, 1]) == True\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112]) == True\n assert candidate(nums = [127, 125, 123, 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99, 97, 95, 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == False\n assert candidate(nums = [15, 30, 1, 2, 4, 8]) == False\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]) == True\n assert candidate(nums = [255, 254, 252, 248, 240, 224, 192, 128, 64, 32, 16, 8, 4, 2, 1]) == False\n assert candidate(nums = [31, 15, 7, 3, 1, 30, 28, 14, 6, 2]) == False\n assert candidate(nums = [5, 3, 9, 12, 6, 15, 7]) == False\n assert candidate(nums = [16, 32, 8, 4, 2, 1, 128, 64, 15, 30, 21, 28, 7, 14, 3, 6, 12, 24]) == False\n assert candidate(nums = [12, 5, 6, 3, 9, 18, 36, 45]) == True\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144]) == True\n assert candidate(nums = [31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64]) == False\n assert candidate(nums = [5, 3, 1, 12, 4, 6, 18, 9, 15, 30]) == False\n assert candidate(nums = [8, 4, 2, 30, 15, 7, 14, 28, 21, 18]) == False\n assert candidate(nums = [5, 3, 11, 7, 13, 9, 14, 10, 6, 2]) == False\n assert candidate(nums = [31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256]) == False\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15]) == False\n assert candidate(nums = [18, 28, 21, 7, 14, 3, 6, 12, 24, 48]) == False\n assert candidate(nums = [8, 4, 2, 16, 8, 4, 2, 1, 32, 16]) == True\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1]) == True\n assert candidate(nums = [5, 2, 9, 6, 17, 12, 34, 21, 27]) == False\n assert candidate(nums = [3, 19, 11, 5, 13, 7, 15, 31, 29, 27, 23, 19, 15, 7, 3]) == False\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 1]) == True\n assert candidate(nums = [31, 29, 27, 23, 19, 17, 13, 11, 7, 5, 3]) == False\n assert candidate(nums = [28, 24, 20, 16, 12, 8, 4, 2, 14, 10, 6, 30, 26, 22, 18, 31, 15, 7, 11, 19, 27, 23, 3, 1, 5, 9, 13]) == False\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128]) == False\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 255, 127, 63, 31, 15, 7, 3, 1]) == False\n assert candidate(nums = [6, 3, 5, 9, 12, 10, 15, 30, 1, 2]) == False\n assert candidate(nums = [31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256]) == False\n assert candidate(nums = [2, 8, 4, 16, 32, 64, 128, 1, 3]) == False\n assert candidate(nums = [15, 7, 14, 28, 21, 3, 6, 12]) == False\n assert candidate(nums = [5, 3, 9, 6, 12, 18, 24, 30, 31, 15, 7, 14]) == False\n assert candidate(nums = [135, 144, 117, 126, 99, 108, 90, 81, 72, 63, 54, 45, 36, 27, 18, 9]) == False\n assert candidate(nums = [10, 6, 5, 3, 2, 4, 8, 16, 32]) == False\n assert candidate(nums = [11, 7, 13, 5, 3, 9, 1, 2, 4]) == False\n assert candidate(nums = [5, 3, 12, 9, 18, 30, 24]) == False\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]) == True\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1]) == True\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 31, 30, 29, 27, 25, 23, 21, 19]) == False\n assert candidate(nums = [1, 8, 4, 2, 16, 32, 64, 128, 256]) == True\n assert candidate(nums = [5, 3, 12, 15, 30, 60, 240]) == True\n assert candidate(nums = [63, 55, 47, 39, 31, 23, 15, 7, 3, 1]) == False\n assert candidate(nums = [32, 16, 8, 4, 2, 1, 128, 64, 32, 16, 8, 4, 2, 1]) == True\n assert candidate(nums = [15, 30, 15, 30, 15, 30, 15, 30, 15, 30, 15, 30, 15, 30, 15, 30]) == True\n", "comparison": "exact"}, "public_tests": ["[8,4,2,30,15]", "[1,2,3,4,5]", "[3,16,8,4,2]"], "hints": ["Split the array into segments. Each segment contains consecutive elements with the same number of set bits.", "From left to right, the previous segment’s largest element should be smaller than the current segment’s smallest element."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().canSortArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:14+00:00", "tests_total": 135, "tests_dropped": 26, "flags": [], "topic_tags": ["array", "bit-manipulation", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def can_sort_array(nums)", "container": null, "callable": "can_sort_array", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3012, "task_id": "minimize-length-of-array-using-operations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums containing positive integers.\n\nYour task is to minimize the length of nums by performing the following operations any number of times (including zero):\n\n- Select two distinct indices i and j from nums, such that nums[i] > 0 and nums[j] > 0.\n- Insert the result of nums[i] % nums[j] at the end of nums.\n- Delete the elements at indices i and j from nums.\n\nReturn an integer denoting the minimum length of nums after performing the operation any number of times.\n\nExample 1:\n\nInput: nums = [1,4,3,1]\nOutput: 1\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1.\nnums becomes [1,1,3].\nOperation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2.\nnums becomes [1,1].\nOperation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0.\nnums becomes [0].\nThe length of nums cannot be reduced further. Hence, the answer is 1.\nIt can be shown that 1 is the minimum achievable length.\n\nExample 2:\n\nInput: nums = [5,5,5,10,5]\nOutput: 2\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3.\nnums becomes [5,5,5,5].\nOperation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3.\nnums becomes [5,5,0].\nOperation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1.\nnums becomes [0,0].\nThe length of nums cannot be reduced further. Hence, the answer is 2.\nIt can be shown that 2 is the minimum achievable length.\n\nExample 3:\n\nInput: nums = [2,3,4]\nOutput: 1\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2.\nnums becomes [2,3].\nOperation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0.\nnums becomes [1].\nThe length of nums cannot be reduced further. Hence, the answer is 1.\nIt can be shown that 1 is the minimum achievable length.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [5, 5, 5, 10, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 6\n assert candidate(nums = [3, 9, 27, 81, 243]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7]) == 3\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 1\n assert candidate(nums = [1, 4, 3, 1]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500]) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [7, 14, 28, 35]) == 1\n assert candidate(nums = [2, 3, 4]) == 1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 3\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]) == 1\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17]) == 10\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65]) == 1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1000]) == 1\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 1\n assert candidate(nums = [13, 13, 13, 26, 26, 26, 39, 39, 39, 52, 52, 52, 65, 65, 65]) == 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]) == 10\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 1\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17]) == 15\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]) == 1\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]) == 2\n assert candidate(nums = [7, 21, 35, 49, 63, 77, 91, 105, 119, 133, 147, 161, 175, 189, 203]) == 1\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]) == 1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160]) == 1\n assert candidate(nums = [17, 17, 34, 34, 51, 51, 68, 68, 85, 85, 102, 102, 119, 119, 136, 136, 153, 153, 170, 170]) == 1\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210, 231, 252, 273, 294, 315, 336, 357, 378, 399, 420]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220]) == 1\n assert candidate(nums = [71, 142, 213, 284, 355, 426, 497, 568, 639, 710]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3]) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == 1\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220]) == 1\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000]) == 1\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 1\n assert candidate(nums = [29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 15\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500]) == 1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515]) == 1\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 1\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266, 285, 304, 323, 342, 361, 380]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65]) == 1\n assert candidate(nums = [12, 15, 18, 21, 24, 27, 30, 33, 36, 39]) == 1\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190]) == 1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220, 231, 242, 253, 264, 275]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165]) == 1\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100]) == 1\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) == 1\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230]) == 1\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\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448]) == 1\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == 1\n assert candidate(nums = [23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25]) == 1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170]) == 1\n assert candidate(nums = [12, 12, 12, 24, 24, 24, 36, 36, 36, 48, 48, 48, 60, 60, 60, 72, 72, 72, 84, 84, 84]) == 2\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156]) == 1\n assert candidate(nums = [7, 14, 28, 56, 112]) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143]) == 1\n assert candidate(nums = [7, 7, 7, 7, 14, 14, 14, 14, 28, 28, 28, 28]) == 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, 21, 22, 23, 24, 25]) == 1\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 1\n assert candidate(nums = [21, 21, 21, 42, 42, 42, 63, 63, 63, 84, 84, 84, 105, 105, 105, 126, 126, 126]) == 2\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == 1\n assert candidate(nums = [11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260]) == 1\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]) == 1\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\n assert candidate(nums = [13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]) == 1\n assert candidate(nums = [101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1\n assert candidate(nums = [29, 58, 87, 116, 145, 174, 203, 232, 261, 290]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42]) == 1\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300]) == 1\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135]) == 1\n assert candidate(nums = [41, 82, 123, 164, 205, 246, 287, 328, 369, 410]) == 1\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162]) == 1\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1]) == 2\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13]) == 8\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205]) == 1\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230, 253, 276, 299, 322, 345, 368, 391, 414, 437, 460]) == 1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323]) == 1\n assert candidate(nums = [17, 17, 17, 34, 34, 34, 51, 51, 51, 68, 68, 68, 85, 85, 85, 102, 102, 102]) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96]) == 1\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266, 285]) == 1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153]) == 1\n assert candidate(nums = [15, 15, 15, 30, 30, 30, 60, 60, 60, 120, 120, 120]) == 2\n assert candidate(nums = [7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97]) == 1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 1\n assert candidate(nums = [53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55]) == 1\n assert candidate(nums = [89, 178, 267, 356, 445, 534, 623, 712, 801, 890]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,4,3,1]", "[5,5,5,10,5]", "[2,3,4]"], "hints": ["The problem can be solved by considering different cases.", "Let the minimum value in nums be x; we can consider the following cases:", "If x occurs once: The minimum length of nums achievable in this case is 1, since every other value, y, can be paired with x, resulting in deleting x and y, and inserting x % y == x, since x < y. So, only x remains after the operations.", "If there is a value y in nums such that y % x is not equal to 0: The minimum achievable length in this case is 1 as well, because inserting y % x creates a new minimum, since y % x < x, returning to the first case.", "If neither of the previous cases holds, and x occurs cnt times: The minimum length of nums achievable in this case is ceil(cnt / 2)."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumArrayLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:17+00:00", "tests_total": 136, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "math", "greedy", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_array_length(nums)", "container": null, "callable": "minimum_array_length", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3013, "task_id": "divide-an-array-into-subarrays-with-minimum-cost-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array of integers nums of length n, and two positive integers k and dist.\n\nThe cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\n\nYou need to divide nums into k disjoint contiguous subarrays, such that the difference between the starting index of the second subarray and the starting index of the kth subarray should be less than or equal to dist. In other words, if you divide nums into the subarrays nums[0..(i_1 - 1)], nums[i_1..(i_2 - 1)], ..., nums[i_{k-1}..(n - 1)], then i_{k-1} - i_1 <= dist.\n\nReturn the minimum possible sum of the cost of these subarrays.\n\nExample 1:\n\nInput: nums = [1,3,2,6,4,2], k = 3, dist = 3\nOutput: 5\nExplanation: The best possible way to divide nums into 3 subarrays is: [1,3], [2,6,4], and [2]. This choice is valid because i_{k-1} - i_1 is 5 - 2 = 3 which is equal to dist. The total cost is nums[0] + nums[2] + nums[5] which is 1 + 2 + 2 = 5.\nIt can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 5.\n\nExample 2:\n\nInput: nums = [10,1,2,2,2,1], k = 4, dist = 3\nOutput: 15\nExplanation: The best possible way to divide nums into 4 subarrays is: [10], [1], [2], and [2,2,1]. This choice is valid because i_{k-1} - i_1 is 3 - 1 = 2 which is less than dist. The total cost is nums[0] + nums[1] + nums[2] + nums[3] which is 10 + 1 + 2 + 2 = 15.\nThe division [10], [1], [2,2,2], and [1] is not valid, because the difference between i_{k-1} and i_1 is 5 - 1 = 4, which is greater than dist.\nIt can be shown that there is no possible way to divide nums into 4 subarrays at a cost lower than 15.\n\nExample 3:\n\nInput: nums = [10,8,18,9], k = 3, dist = 1\nOutput: 36\nExplanation: The best possible way to divide nums into 3 subarrays is: [10], [8], and [18,9]. This choice is valid because i_{k-1} - i_1 is 2 - 1 = 1 which is equal to dist.The total cost is nums[0] + nums[1] + nums[2] which is 10 + 8 + 18 = 36.\nThe division [10], [8,18], and [9] is not valid, because the difference between i_{k-1} and i_1 is 3 - 1 = 2, which is greater than dist.\nIt can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 36.\n\nConstraints:\n\n- 3 <= n <= 10^5\n- 1 <= nums[i] <= 10^9\n- 3 <= k <= n\n- k - 2 <= dist <= n - 2\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 8, 9, 10, 5, 6],k = 3,dist = 4) == 18\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2,dist = 2) == 6\n assert candidate(nums = [1, 3, 2, 6, 4, 2],k = 3,dist = 3) == 5\n assert candidate(nums = [10, 8, 18, 9],k = 3,dist = 1) == 36\n assert candidate(nums = [5, 1, 4, 3, 2],k = 3,dist = 2) == 9\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4,dist = 4) == 15\n assert candidate(nums = [7, 8, 9, 10, 11, 12],k = 3,dist = 4) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5,dist = 4) == 15\n assert candidate(nums = [10, 1, 2, 2, 2, 1],k = 4,dist = 3) == 15\n assert candidate(nums = [5, 1, 4, 2, 8, 7, 3, 6, 9, 10],k = 4,dist = 5) == 11\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5,dist = 4) == 50\n assert candidate(nums = [100, 200, 10, 20, 30, 40, 50, 5, 15, 25, 35, 45],k = 5,dist = 6) == 150\n assert candidate(nums = [100, 101, 102, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88],k = 7,dist = 9) == 643\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,dist = 4) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,dist = 5) == 5\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 3,dist = 5) == 6\n assert candidate(nums = [100, 200, 300, 400, 500, 1, 2, 3, 4, 5],k = 3,dist = 9) == 103\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 8,dist = 8) == 36\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],k = 10,dist = 10) == 855\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 1, 2, 3, 4, 5],k = 6,dist = 9) == 1000000015\n assert candidate(nums = [31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59],k = 7,dist = 6) == 259\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 = 10,dist = 10) == 65\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 = 15,dist = 15) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8,dist = 6) == 36\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 6, 4, 10, 11, 12],k = 5,dist = 6) == 17\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7,dist = 7) == 28\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 = 10,dist = 10) == 65\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 8,dist = 6) == 360\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 3) == 19\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100],k = 10,dist = 15) == 145\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9, 10],k = 4,dist = 5) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 4,dist = 3) == 100\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10,dist = 15) == 550\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10, 11, 12, 13, 14, 15],k = 7,dist = 8) == 28\n assert candidate(nums = [1, 3, 2, 6, 4, 2, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 6,dist = 5) == 17\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10,dist = 12) == 550\n assert candidate(nums = [5, 3, 8, 1, 4, 9, 2, 6, 7],k = 4,dist = 5) == 11\n assert candidate(nums = [1, 1000000000, 2, 1000000000, 3, 1000000000, 4, 1000000000, 5],k = 5,dist = 4) == 1000000010\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 6,dist = 7) == 36\n assert candidate(nums = [100, 200, 300, 400, 500, 1, 2, 3, 4, 5],k = 6,dist = 9) == 115\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 = 10,dist = 10) == 55\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7,dist = 10) == 280\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],k = 5,dist = 5) == 11\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 = 10,dist = 10) == 55\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 6,dist = 7) == 2100\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10],k = 5,dist = 4) == 17\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,dist = 10) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8,dist = 7) == 36\n assert candidate(nums = [1, 3, 5, 2, 8, 7, 4, 6, 9, 10],k = 4,dist = 5) == 10\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,dist = 10) == 1000000045\n assert candidate(nums = [100, 200, 150, 10, 50, 300, 400, 250, 350, 100, 500],k = 6,dist = 8) == 610\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16],k = 8,dist = 7) == 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],k = 10,dist = 10) == 10\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,dist = 10) == 1000000045\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],k = 15,dist = 15) == 15\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,dist = 10) == 15\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 5) == 25\n assert candidate(nums = [100, 200, 10, 20, 30, 40, 50, 60, 70, 80, 90],k = 6,dist = 6) == 250\n assert candidate(nums = [15, 3, 8, 7, 5, 2, 9, 1, 10, 4, 6, 11, 13, 12],k = 5,dist = 5) == 27\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],k = 20,dist = 20) == 100\n assert candidate(nums = [3, 1, 2, 1, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2],k = 7,dist = 6) == 13\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],k = 10,dist = 10) == 35\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 6,dist = 5) == 24\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 8,dist = 10) == 72\n assert candidate(nums = [100, 99, 98, 97, 96, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 7,dist = 7) == 121\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 = 10,dist = 9) == 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],k = 5,dist = 5) == 11\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10, 11, 12, 13, 14, 15],k = 7,dist = 8) == 28\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 6,dist = 7) == 105\n assert candidate(nums = [3, 1, 2, 1, 3, 2, 1, 3, 2, 1],k = 4,dist = 4) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10,dist = 10) == 550\n assert candidate(nums = [100, 1, 50, 2, 99, 3, 49, 4, 98, 5],k = 5,dist = 5) == 155\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 3) == 19\n assert candidate(nums = [5, 1, 3, 8, 12, 7, 9, 2, 6, 4],k = 4,dist = 5) == 16\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 5,dist = 5) == 7\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 = 10,dist = 10) == 70\n assert candidate(nums = [9, 3, 7, 2, 8, 6, 5, 1, 4, 10],k = 4,dist = 5) == 16\n assert candidate(nums = [10, 20, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 6,dist = 5) == 25\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 7,dist = 10) == 49\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 = 10,dist = 15) == 55\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5,dist = 5) == 15\n assert candidate(nums = [15, 20, 25, 10, 30, 35, 5, 40, 45, 4, 50],k = 6,dist = 7) == 89\n assert candidate(nums = [200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 10,dist = 10) == 650\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,dist = 20) == 34\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 = 15,dist = 15) == 135\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 15) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 6,dist = 7) == 210\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3],k = 7,dist = 10) == 19\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5,dist = 3) == 200\n assert candidate(nums = [9, 3, 1, 5, 2, 8, 6, 7, 4, 10],k = 5,dist = 5) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 5,dist = 12) == 30\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15,dist = 25) == 76\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 5) == 25\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6,dist = 8) == 30\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 8, 7, 9, 10],k = 4,dist = 6) == 11\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5,dist = 8) == 101\n assert candidate(nums = [5, 3, 8, 12, 4, 6, 7, 10, 2, 9],k = 4,dist = 6) == 17\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 9,dist = 10) == 25\n assert candidate(nums = [200, 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 5,dist = 10) == 1500\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5,dist = 4) == 15\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000],k = 3,dist = 3) == 1000000002\n assert candidate(nums = [5, 1, 4, 2, 8, 7, 3],k = 4,dist = 5) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 6,dist = 7) == 21\n assert candidate(nums = [7, 8, 9, 10, 5, 6, 2, 3, 4, 1],k = 5,dist = 5) == 17\n assert candidate(nums = [5, 4, 3, 2, 1],k = 3,dist = 4) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3,dist = 5) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5,dist = 5) == 15\n assert candidate(nums = [5, 3, 8, 1, 4, 7, 9, 2],k = 4,dist = 4) == 12\n assert candidate(nums = [5, 1, 3, 7, 9, 2, 6, 8, 4],k = 4,dist = 5) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4,dist = 2) == 20\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 5) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3,dist = 7) == 6\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 7, 8, 9],k = 4,dist = 5) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3,dist = 2) == 15\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10],k = 4,dist = 5) == 10\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],k = 6,dist = 5) == 16\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3,dist = 4) == 12\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3,dist = 6) == 12\n assert candidate(nums = [50, 40, 30, 20, 10, 1, 2, 3, 4, 5],k = 4,dist = 5) == 56\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5,dist = 5) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 6,dist = 10) == 21\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3,dist = 7) == 3\n assert candidate(nums = [5, 2, 3, 1, 4, 6, 7, 8, 9],k = 5,dist = 4) == 15\n assert candidate(nums = [100, 200, 300, 400, 500],k = 3,dist = 2) == 600\n assert candidate(nums = [7, 3, 5, 10, 6, 9],k = 4,dist = 5) == 21\n assert candidate(nums = [9, 7, 5, 3, 1],k = 4,dist = 3) == 18\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3],k = 5,dist = 5) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 6,dist = 7) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3,dist = 5) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3,dist = 2) == 3\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5,dist = 5) == 11\n assert candidate(nums = [7, 9, 3, 1, 5, 6, 2],k = 5,dist = 5) == 18\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9],k = 3,dist = 4) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,dist = 4) == 19\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 5,dist = 5) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4,dist = 6) == 100\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000],k = 3,dist = 4) == 111\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 6,dist = 5) == 2100\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1],k = 3,dist = 2) == 3\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],k = 3,dist = 4) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3,dist = 5) == 9\n assert candidate(nums = [5, 1, 4, 3, 2],k = 3,dist = 2) == 9\n assert candidate(nums = [10, 8, 18, 9],k = 3,dist = 1) == 36\n assert candidate(nums = [7, 8, 9, 10, 2, 1, 3, 4, 5, 6],k = 4,dist = 4) == 13\n assert candidate(nums = [5, 1, 4, 2, 8, 3, 7, 6],k = 4,dist = 4) == 11\n assert candidate(nums = [5, 1, 4, 3, 2, 6, 7],k = 3,dist = 4) == 8\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3,dist = 7) == 9\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5,dist = 6) == 1500\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900],k = 4,dist = 7) == 1000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5,dist = 6) == 15\n assert candidate(nums = [7, 8, 9, 10, 2, 1, 3, 4, 5, 6],k = 4,dist = 5) == 13\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,dist = 10) == 15\n assert candidate(nums = [1, 3, 2, 6, 4, 2],k = 3,dist = 3) == 5\n assert candidate(nums = [3, 1, 5, 2, 4, 6, 8, 7],k = 3,dist = 4) == 6\n assert candidate(nums = [7, 8, 9, 10, 11, 12],k = 4,dist = 5) == 34\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,dist = 10) == 5\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3,dist = 4) == 9\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],k = 5,dist = 5) == 107\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7],k = 5,dist = 5) == 15\n assert candidate(nums = [7, 1, 5, 3, 6, 4, 8, 2],k = 5,dist = 5) == 20\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],k = 5,dist = 5) == 19\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5,dist = 4) == 25\n assert candidate(nums = [5, 4, 3, 2, 1],k = 3,dist = 2) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3,dist = 7) == 600\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4,dist = 6) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900],k = 4,dist = 4) == 1000\n assert candidate(nums = [5, 1, 3, 8, 6, 7, 4, 2],k = 4,dist = 4) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5,dist = 6) == 150\n assert candidate(nums = [7, 8, 9, 1, 2, 3, 4, 5, 6],k = 5,dist = 5) == 17\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3,dist = 8) == 600\n assert candidate(nums = [7, 8, 9, 10, 2, 1],k = 4,dist = 4) == 18\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 3,dist = 2) == 3000000000\n assert candidate(nums = [5, 1, 4, 2, 3],k = 3,dist = 4) == 8\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],k = 4,dist = 4) == 9\n assert candidate(nums = [5, 1, 3, 7, 9, 2, 6, 4, 8],k = 4,dist = 5) == 11\n assert candidate(nums = [9, 3, 7, 6, 2, 5, 8, 4],k = 5,dist = 4) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4,dist = 4) == 10\n assert candidate(nums = [5, 1, 3, 7, 9, 2, 6, 8, 4, 10],k = 5,dist = 4) == 18\n assert candidate(nums = [10, 1, 2, 2, 2, 1],k = 4,dist = 3) == 15\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5,dist = 5) == 25\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10],k = 4,dist = 5) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4,dist = 5) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600],k = 3,dist = 2) == 600\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63],k = 4,dist = 6) == 70\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4,dist = 5) == 15\n assert candidate(nums = [5, 1, 4, 2, 3],k = 3,dist = 4) == 8\n assert candidate(nums = [5, 1, 4, 2, 8, 3],k = 4,dist = 4) == 11\n assert candidate(nums = [5, 1, 4, 2, 8, 3],k = 3,dist = 4) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 3,dist = 6) == 6\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7],k = 7,dist = 6) == 19\n", "comparison": "exact"}, "public_tests": ["[1,3,2,6,4,2]\n3\n3", "[10,1,2,2,2,1]\n4\n3", "[10,8,18,9]\n3\n1"], "hints": ["For each i > 0, try each nums[i] as the first element of the second subarray. We need to find the sum of k - 2 smallest values in the index range [i + 1, min(i + dist, n - 1)].", "Typically, we use a max heap to maintain the top k - 2 smallest values dynamically. Here we also have a sliding window, which is the index range [i + 1, min(i + dist, n - 1)]. We can use another min heap to put unselected values for future use.", "Update the two heaps when iteration over i. Ordered/Tree sets are also a good choice since we have to delete elements.", "If the max heap’s size is less than k - 2, use the min heap’s value to fill it. If the maximum value in the max heap is larger than the smallest value in the min heap, swap them in the two heaps."], "metadata": {"canonical_parameter_names": ["nums", "k", "dist"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:19+00:00", "tests_total": 193, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(nums, k, dist)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}, {"name": "dist", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3014, "task_id": "minimum-number-of-pushes-to-type-word-i", "difficulty": "Easy", "problem_description": "You are given a string word containing distinct lowercase English letters.\n\nTelephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\n\nIt is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\n\nReturn the minimum number of pushes needed to type word after remapping the keys.\n\nAn example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n\nExample 1:\n\nInput: word = \"abcde\"\nOutput: 5\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\nTotal cost is 1 + 1 + 1 + 1 + 1 = 5.\nIt can be shown that no other mapping can provide a lower cost.\n\nExample 2:\n\nInput: word = \"xycdefghij\"\nOutput: 12\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"x\" -> one push on key 2\n\"y\" -> two pushes on key 2\n\"c\" -> one push on key 3\n\"d\" -> two pushes on key 3\n\"e\" -> one push on key 4\n\"f\" -> one push on key 5\n\"g\" -> one push on key 6\n\"h\" -> one push on key 7\n\"i\" -> one push on key 8\n\"j\" -> one push on key 9\nTotal cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.\nIt can be shown that no other mapping can provide a lower cost.\n\nConstraints:\n\n- 1 <= word.length <= 26\n- word consists of lowercase English letters.\n- All letters in word are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"ghijkl\") == 6\n assert candidate(word = \"npqrstvwxy\") == 12\n assert candidate(word = \"abcdefghi\") == 10\n assert candidate(word = \"vwxyz\") == 5\n assert candidate(word = \"abcdefghijklmnopq\") == 27\n assert candidate(word = \"abcdefghijklmnopqrs\") == 33\n assert candidate(word = \"abcdefghijklmnopqrstu\") == 39\n assert candidate(word = \"pqrstu\") == 6\n assert candidate(word = \"abcdefghijkl\") == 16\n assert candidate(word = \"abcdefghijk\") == 14\n assert candidate(word = \"pqrstuvw\") == 8\n assert candidate(word = \"defghi\") == 6\n assert candidate(word = \"abcdefghijklm\") == 18\n assert candidate(word = \"efghijkl\") == 8\n assert candidate(word = \"abcdef\") == 6\n assert candidate(word = \"abcdefghijklmn\") == 20\n assert candidate(word = \"qrstuvw\") == 7\n assert candidate(word = \"uvwxyza\") == 7\n assert candidate(word = \"bcdefg\") == 6\n assert candidate(word = \"tuvwxy\") == 6\n assert candidate(word = \"qrstuv\") == 6\n assert candidate(word = \"tuvwxyz\") == 7\n assert candidate(word = \"wxyzabc\") == 7\n assert candidate(word = \"abcdefghij\") == 12\n assert candidate(word = \"nopqrs\") == 6\n assert candidate(word = \"nopqrst\") == 7\n assert candidate(word = \"xycdefghij\") == 12\n assert candidate(word = \"hijklmno\") == 8\n assert candidate(word = \"mnopqrstu\") == 10\n assert candidate(word = \"vwxyza\") == 6\n assert candidate(word = \"abcdefghijklmnopqr\") == 30\n assert candidate(word = \"rstvwxy\") == 7\n assert candidate(word = \"zabcdef\") == 7\n assert candidate(word = \"abcdefghijklmnop\") == 24\n assert candidate(word = \"klmnopq\") == 7\n assert candidate(word = \"stuvwx\") == 6\n assert candidate(word = \"mnop\") == 4\n assert candidate(word = \"xyz\") == 3\n assert candidate(word = \"qrstuvwx\") == 8\n assert candidate(word = \"abcdefghijlkmnopqrstuvwxyz\") == 56\n assert candidate(word = \"yz\") == 2\n assert candidate(word = \"lmnopqrs\") == 8\n assert candidate(word = \"ab\") == 2\n assert candidate(word = \"abcde\") == 5\n assert candidate(word = \"abcd\") == 4\n assert candidate(word = \"abcdefg\") == 7\n assert candidate(word = \"a\") == 1\n assert candidate(word = \"ijklmn\") == 6\n assert candidate(word = \"klmnop\") == 6\n assert candidate(word = \"mnopqr\") == 6\n assert candidate(word = \"ghijklm\") == 7\n assert candidate(word = \"ijklmnop\") == 8\n assert candidate(word = \"zabcde\") == 6\n assert candidate(word = \"abcdefghijklmnopqrst\") == 36\n assert candidate(word = \"abc\") == 3\n assert candidate(word = \"opqrstuv\") == 8\n assert candidate(word = \"hijklm\") == 6\n assert candidate(word = \"abcdefghijklmnopqrstuv\") == 42\n assert candidate(word = \"abcdefghijkmnopqrstuvwx\") == 45\n assert candidate(word = \"defghij\") == 7\n assert candidate(word = \"efghij\") == 6\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 56\n assert candidate(word = \"mnopqrstuvwxyz\") == 20\n assert candidate(word = \"yzabcdef\") == 8\n assert candidate(word = \"defghijkl\") == 10\n assert candidate(word = \"jklmno\") == 6\n assert candidate(word = \"abcdefgh\") == 8\n assert candidate(word = \"bcdfghjkl\") == 10\n assert candidate(word = \"abcdefghijklmnopqrstuvwx\") == 48\n assert candidate(word = \"nopqrstuvwxyz\") == 18\n assert candidate(word = \"stuvwxyzabcdefghij\") == 30\n assert candidate(word = \"wxyzabcdefghijklmnopqrstuv\") == 56\n assert candidate(word = \"xyzmnopqrstuabc\") == 22\n assert candidate(word = \"stuvwxyzabcdefghijkl\") == 36\n assert candidate(word = \"qrstuvwxyzabcdefghij\") == 36\n assert candidate(word = \"nopqrstuvwxyzabcdefghijk\") == 48\n assert candidate(word = \"lmnopqrstuvwxyzabc\") == 30\n assert candidate(word = \"opqrstuvwxyzabcde\") == 27\n assert candidate(word = \"lmnopqrstuvwxyzabcdefghijk\") == 56\n assert candidate(word = \"zxcvbnmlkjhgfedcba\") == 30\n assert candidate(word = \"xyzabcdefghijklmnop\") == 33\n assert candidate(word = \"qrstuvwxyzzzzz\") == 20\n assert candidate(word = \"abcdefghijlmnopqrstuvwxyz\") == 52\n assert candidate(word = \"jklmnopqrstuvwx\") == 22\n assert candidate(word = \"klmnopqrstuvwxyzabcdefghij\") == 56\n assert candidate(word = \"zxcvbnmlkjhgfdsapoiuytrewq\") == 56\n assert candidate(word = \"nopqrstuvwxyzabcdefghijklm\") == 56\n assert candidate(word = \"pqrstuvwxy\") == 12\n assert candidate(word = \"efghijklmnop\") == 16\n assert candidate(word = \"yzabcdefghijklmnopqrstuvwx\") == 56\n assert candidate(word = \"tuvxyzabcdefghijklmnopqrs\") == 52\n assert candidate(word = \"mnopqrstuvwxzyabc\") == 27\n assert candidate(word = \"lmnopqrstu\") == 12\n assert candidate(word = \"bdfhjlnprtvxz\") == 18\n assert candidate(word = \"mnopqrstuvwxyzabc\") == 27\n assert candidate(word = \"mnopqrst\") == 8\n assert candidate(word = \"mnopqrstuvwxzy\") == 20\n assert candidate(word = \"abcdpqrs\") == 8\n assert candidate(word = \"abcdefghijklmnopqrstuvwxzy\") == 56\n assert candidate(word = \"aeiouaeiou\") == 12\n assert candidate(word = \"abcdefgxyz\") == 12\n assert candidate(word = \"defghijklmnopqrstuvwxyzabc\") == 56\n assert candidate(word = \"klmnopqrstuabcdefghij\") == 39\n assert candidate(word = \"abcdefghijkmnop\") == 22\n assert candidate(word = \"abcdefgxyzijklmnop\") == 30\n assert candidate(word = \"stuvxyzabcdefghijklmnopqr\") == 52\n assert candidate(word = \"ghijklmnopqrstuvwxyzabcde\") == 52\n assert candidate(word = \"zyxcvbnm\") == 8\n assert candidate(word = \"nopqrstuvwxyzabcdefghijkl\") == 52\n assert candidate(word = \"abcdefghjklmno\") == 20\n assert candidate(word = \"hijklmnopqrstuvwxyz\") == 33\n assert candidate(word = \"vwxyzabcd\") == 10\n assert candidate(word = \"pqrstuvwlmnoefghij\") == 30\n assert candidate(word = \"zabcdefghijklmnopq\") == 30\n assert candidate(word = \"defghijklmnopqrstuvwxyza\") == 48\n assert candidate(word = \"opqrstuvwxyzabcdefghijklmn\") == 56\n assert candidate(word = \"mnopqrstuvwxyzaefghijkl\") == 45\n assert candidate(word = \"abcdefghijmnopqrstuvwxyz\") == 48\n assert candidate(word = \"bcdefghijklmnopqrstuvwxyza\") == 56\n assert candidate(word = \"xyzabc\") == 6\n assert candidate(word = \"poiuytrewq\") == 12\n assert candidate(word = \"bcdfghjklmnpqrstvwxyz\") == 39\n assert candidate(word = \"qwertyuiop\") == 12\n assert candidate(word = \"abcdefhijklmno\") == 20\n assert candidate(word = \"qrstuvwxyz\") == 12\n assert candidate(word = \"uvwxyzaeiou\") == 14\n assert candidate(word = \"abcdefghilmnopqrstuvwxyz\") == 48\n assert candidate(word = \"abcdefghijxyzklmnopqr\") == 39\n assert candidate(word = \"xyzdefghijklmnopqrstuvw\") == 45\n assert candidate(word = \"abcdefghijkmnopqrst\") == 33\n assert candidate(word = \"wxyzabcdefghijklmnopqrst\") == 48\n assert candidate(word = \"tuvwxyzabcdefghijklmnopqrs\") == 56\n assert candidate(word = \"qrstuvwxyzabcdefghijklmnop\") == 56\n assert candidate(word = \"ghijklmnopqrstuvwxyzab\") == 42\n assert candidate(word = \"nopqrstuvwxyzabc\") == 24\n assert candidate(word = \"abcdefghiklmnopqrstuvwxyz\") == 52\n assert candidate(word = \"yzabcd\") == 6\n assert candidate(word = \"ghijklmnopqrstu\") == 22\n assert candidate(word = \"vwxyzabcdefghijklmnopqrstu\") == 56\n assert candidate(word = \"vwxyzabcdefghijklmnopq\") == 42\n assert candidate(word = \"zabcdefghijklmnop\") == 27\n assert candidate(word = \"ijklmnopqrstuvwxyzabcdefgh\") == 56\n assert candidate(word = \"lkjihgfedcba\") == 16\n assert candidate(word = \"klmno\") == 5\n assert candidate(word = \"pqrstuvwxyzabcdefghijklmno\") == 56\n assert candidate(word = \"stuvwxyzabcdefghijklmnopqr\") == 56\n assert candidate(word = \"lmnopqrstuvwxyz\") == 22\n assert candidate(word = \"qrstuvwxyza\") == 14\n assert candidate(word = \"abcdefghilmnopqr\") == 24\n assert candidate(word = \"yzabcdefghijklmnopqrstuvw\") == 52\n assert candidate(word = \"xyzabcdefghijklmnopq\") == 36\n assert candidate(word = \"bcdefghijklmnopqrstuvwx\") == 45\n assert candidate(word = \"abcdefghijklmnopqrstuvmnop\") == 56\n assert candidate(word = \"zxcvbnm\") == 7\n assert candidate(word = \"xyzabcdefghijklmnopqrstuvw\") == 56\n assert candidate(word = \"qrstuvwxyzabcdefg\") == 27\n assert candidate(word = \"abcdefghijkmnopqrstuvwxy\") == 48\n assert candidate(word = \"abcdefghilmnopqrstuvwxyzz\") == 52\n assert candidate(word = \"defghijklmnopqrstu\") == 30\n assert candidate(word = \"vwxyzabcdefghijklmno\") == 36\n assert candidate(word = \"zxcvbnmasdfghjklqwertyuiop\") == 56\n assert candidate(word = \"mnopqrstuv\") == 12\n assert candidate(word = \"zabcdefghijklmnopqrstuvwxy\") == 56\n assert candidate(word = \"defghijklmnopqrstuabcdefgh\") == 56\n assert candidate(word = \"asdfghjkl\") == 10\n assert candidate(word = \"abcdefghijklmno\") == 22\n assert candidate(word = \"ghijklmnopqrstuvwxyzabcdef\") == 56\n assert candidate(word = \"yzabcdefghijklmnop\") == 30\n assert candidate(word = \"rstuvwxyzabcdefghijklmnopq\") == 56\n assert candidate(word = \"zabcdefghijklmnopqrstuvwx\") == 52\n assert candidate(word = \"nopqrstuvwxyzabcd\") == 27\n assert candidate(word = \"bcdefghijkl\") == 14\n assert candidate(word = \"nopqrstuvwxyzabcde\") == 30\n assert candidate(word = \"abcdefhijklmnopqrstuvwxyz\") == 52\n assert candidate(word = \"abcdefghijkmnopqrstuv\") == 39\n assert candidate(word = \"tuvwx\") == 5\n assert candidate(word = \"pqrstuvwxyzabcdef\") == 27\n assert candidate(word = \"jklmnopqrst\") == 14\n assert candidate(word = \"bcdefghijklmnopqrstvwxyz\") == 48\n assert candidate(word = \"lkjhgfdsa\") == 10\n assert candidate(word = \"pqrstuvwxyzabc\") == 20\n assert candidate(word = \"jklmnopqr\") == 10\n assert candidate(word = \"uvwxyzabcdefghijklmnopqrst\") == 56\n assert candidate(word = \"qrstuvwlmnop\") == 16\n assert candidate(word = \"acdegikmoqsuwy\") == 20\n assert candidate(word = \"pqrstuvwxyza\") == 16\n assert candidate(word = \"qrstuabcdefghijk\") == 24\n assert candidate(word = \"mnopqrstuvwx\") == 16\n assert candidate(word = \"hgfedcba\") == 8\n", "comparison": "exact"}, "public_tests": ["\"abcde\"", "\"xycdefghij\""], "hints": ["We have 8 keys in total. We can type 8 characters with one push each, 8 different characters with two pushes each, and so on.", "The optimal way is to map letters to keys evenly."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().minimumPushes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:21+00:00", "tests_total": 202, "tests_dropped": 13, "flags": ["figure_reference", "has_images"], "topic_tags": ["math", "string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_pushes(word)", "container": null, "callable": "minimum_pushes", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3015, "task_id": "count-the-number-of-houses-at-a-certain-distance-i", "difficulty": "Medium", "problem_description": "You are given three positive integers n, x, and y.\n\nIn a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\n\nFor each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house_1, house_2) such that the minimum number of streets that need to be traveled to reach house_2 from house_1 is k.\n\nReturn a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\n\nNote that x and y can be equal.\n\nExample 1:\n\nInput: n = 3, x = 1, y = 3\nOutput: [6,0,0]\nExplanation: Let's look at each pair of houses:\n- For the pair (1, 2), we can go from house 1 to house 2 directly.\n- For the pair (2, 1), we can go from house 2 to house 1 directly.\n- For the pair (1, 3), we can go from house 1 to house 3 directly.\n- For the pair (3, 1), we can go from house 3 to house 1 directly.\n- For the pair (2, 3), we can go from house 2 to house 3 directly.\n- For the pair (3, 2), we can go from house 3 to house 2 directly.\n\nExample 2:\n\nInput: n = 5, x = 2, y = 4\nOutput: [10,8,2,0,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n- For k == 3, the pairs are (1, 5), and (5, 1).\n- For k == 4 and k == 5, there are no pairs.\n\nExample 3:\n\nInput: n = 4, x = 1, y = 1\nOutput: [6,4,2,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n- For k == 3, the pairs are (1, 4), and (4, 1).\n- For k == 4, there are no pairs.\n\nConstraints:\n\n- 2 <= n <= 100\n- 1 <= x, y <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,x = 4,y = 9) == [20, 24, 22, 14, 8, 2, 0, 0, 0, 0]\n assert candidate(n = 10,x = 4,y = 6) == [20, 18, 16, 14, 10, 6, 4, 2, 0, 0]\n assert candidate(n = 10,x = 3,y = 7) == [20, 24, 20, 16, 8, 2, 0, 0, 0, 0]\n assert candidate(n = 10,x = 3,y = 8) == [20, 24, 24, 16, 6, 0, 0, 0, 0, 0]\n assert candidate(n = 4,x = 1,y = 1) == [6, 4, 2, 0]\n assert candidate(n = 100,x = 1,y = 100) == [200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 5,x = 2,y = 4) == [10, 8, 2, 0, 0]\n assert candidate(n = 8,x = 1,y = 8) == [16, 16, 16, 8, 0, 0, 0, 0]\n assert candidate(n = 9,x = 5,y = 5) == [16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 6,x = 2,y = 5) == [12, 12, 6, 0, 0, 0]\n assert candidate(n = 3,x = 1,y = 3) == [6, 0, 0]\n assert candidate(n = 100,x = 50,y = 51) == [198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 10,x = 4,y = 7) == [20, 20, 18, 16, 10, 4, 2, 0, 0, 0]\n assert candidate(n = 2,x = 1,y = 2) == [2, 0]\n assert candidate(n = 7,x = 3,y = 7) == [14, 16, 8, 4, 0, 0, 0]\n assert candidate(n = 100,x = 50,y = 50) == [198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 12,x = 1,y = 12) == [24, 24, 24, 24, 24, 12, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 30,x = 10,y = 25) == [60, 64, 70, 76, 82, 88, 92, 78, 60, 54, 46, 36, 26, 18, 12, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 65,x = 2,y = 3) == [128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 90,x = 15,y = 85) == [180, 184, 190, 196, 202, 208, 212, 214, 216, 218, 220, 222, 224, 226, 228, 228, 226, 224, 222, 220, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 76, 68, 60, 52, 44, 36, 32, 28, 24, 20, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 70,x = 20,y = 60) == [140, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 202, 204, 206, 208, 210, 212, 214, 216, 218, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 36, 32, 28, 24, 20, 16, 12, 8, 4, 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]\n assert candidate(n = 100,x = 50,y = 90) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 262, 264, 266, 268, 270, 272, 274, 276, 278, 198, 192, 186, 180, 174, 168, 162, 156, 150, 144, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 96, 90, 84, 78, 72, 66, 60, 54, 48, 42, 36, 32, 28, 24, 20, 16, 12, 8, 4, 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]\n assert candidate(n = 35,x = 17,y = 28) == [70, 74, 80, 86, 92, 86, 76, 74, 70, 64, 58, 52, 46, 42, 40, 38, 36, 32, 26, 20, 14, 8, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 25,x = 10,y = 15) == [50, 54, 54, 50, 48, 46, 44, 42, 40, 38, 34, 26, 18, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 20,y = 40) == [100, 104, 110, 116, 122, 128, 134, 140, 146, 152, 116, 112, 106, 100, 94, 88, 82, 76, 70, 64, 56, 50, 44, 38, 32, 26, 20, 14, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 70,x = 68,y = 69) == [138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 35,x = 17,y = 21) == [70, 74, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 42, 36, 32, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0]\n assert candidate(n = 30,x = 1,y = 29) == [60, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 95,x = 5,y = 90) == [190, 194, 200, 206, 212, 216, 216, 214, 212, 210, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 122, 32, 24, 16, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 7,x = 3,y = 3) == [12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 22,x = 3,y = 19) == [44, 48, 54, 58, 58, 56, 54, 54, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 32,x = 5,y = 27) == [64, 68, 74, 80, 86, 90, 90, 88, 86, 84, 82, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 18,x = 9,y = 5) == [36, 40, 36, 34, 32, 28, 22, 20, 18, 16, 12, 6, 4, 2, 0, 0, 0, 0]\n assert candidate(n = 40,x = 1,y = 40) == [80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 8,x = 2,y = 7) == [16, 20, 16, 4, 0, 0, 0, 0]\n assert candidate(n = 18,x = 5,y = 9) == [36, 40, 36, 34, 32, 28, 22, 20, 18, 16, 12, 6, 4, 2, 0, 0, 0, 0]\n assert candidate(n = 100,x = 40,y = 60) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 154, 146, 136, 126, 116, 106, 96, 86, 76, 66, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 99,x = 50,y = 99) == [198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 196, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 94, 90, 86, 82, 78, 74, 70, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 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]\n assert candidate(n = 70,x = 18,y = 50) == [140, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 204, 210, 216, 222, 228, 168, 166, 162, 156, 150, 142, 132, 122, 112, 102, 92, 82, 72, 62, 52, 42, 32, 22, 16, 10, 4, 2, 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]\n assert candidate(n = 50,x = 1,y = 50) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 50, 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]\n assert candidate(n = 100,x = 35,y = 95) == [200, 204, 210, 216, 222, 228, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 158, 152, 146, 140, 134, 126, 120, 114, 108, 102, 96, 92, 88, 84, 80, 76, 72, 68, 64, 60, 56, 52, 48, 44, 40, 36, 32, 28, 24, 20, 16, 12, 8, 4, 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]\n assert candidate(n = 25,x = 1,y = 25) == [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 30,x = 15,y = 15) == [58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 25,x = 7,y = 18) == [50, 54, 60, 66, 72, 66, 56, 52, 44, 34, 24, 14, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 60,x = 20,y = 55) == [120, 124, 130, 136, 142, 148, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 138, 100, 94, 86, 76, 66, 58, 52, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 25,y = 25) == [98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 24,x = 12,y = 12) == [46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 60,x = 35,y = 45) == [120, 124, 130, 136, 142, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 102, 96, 90, 84, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 46, 40, 34, 28, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 70,x = 30,y = 65) == [140, 144, 150, 156, 162, 168, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 158, 120, 114, 108, 102, 96, 92, 90, 88, 86, 84, 82, 80, 76, 70, 64, 58, 52, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 48,x = 6,y = 43) == [96, 100, 106, 112, 118, 124, 126, 124, 122, 120, 118, 116, 116, 116, 116, 116, 116, 116, 78, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 25,x = 7,y = 20) == [50, 54, 60, 66, 72, 78, 68, 50, 40, 30, 20, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 40,x = 30,y = 30) == [78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 100,x = 30,y = 80) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312, 318, 322, 324, 326, 328, 228, 222, 216, 210, 204, 196, 186, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 40, 34, 28, 22, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 20,y = 35) == [100, 104, 110, 116, 122, 128, 134, 124, 110, 108, 106, 104, 102, 100, 98, 96, 92, 86, 80, 74, 66, 56, 46, 38, 32, 26, 20, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 45,x = 10,y = 40) == [90, 94, 100, 106, 112, 118, 122, 124, 126, 128, 128, 126, 124, 122, 120, 56, 48, 40, 32, 24, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 75,x = 15,y = 60) == [150, 154, 160, 166, 172, 178, 184, 190, 196, 202, 208, 214, 220, 226, 232, 236, 236, 234, 232, 230, 228, 226, 178, 126, 116, 106, 96, 86, 76, 66, 56, 48, 40, 32, 24, 16, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 12,y = 35) == [100, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 140, 116, 110, 104, 98, 90, 80, 70, 60, 50, 40, 30, 22, 16, 10, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 30,x = 10,y = 20) == [60, 64, 70, 76, 82, 66, 64, 62, 60, 58, 54, 46, 36, 26, 16, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 60,x = 10,y = 55) == [120, 124, 130, 136, 142, 148, 152, 154, 156, 158, 158, 156, 154, 152, 150, 148, 148, 148, 148, 148, 148, 148, 102, 52, 44, 36, 28, 20, 14, 10, 6, 2, 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]\n assert candidate(n = 18,x = 8,y = 15) == [36, 40, 46, 44, 36, 30, 24, 20, 16, 10, 4, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 15,x = 3,y = 13) == [30, 34, 40, 42, 40, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 5,y = 45) == [100, 104, 110, 116, 122, 126, 126, 124, 122, 120, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 36, 28, 20, 12, 4, 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]\n assert candidate(n = 20,x = 7,y = 15) == [40, 44, 50, 56, 44, 42, 38, 30, 20, 10, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 30,y = 95) == [200, 204, 210, 216, 222, 228, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 278, 276, 208, 136, 126, 116, 108, 100, 94, 90, 86, 82, 78, 74, 70, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 40,x = 15,y = 35) == [80, 84, 90, 96, 102, 108, 112, 114, 116, 118, 78, 72, 66, 60, 54, 46, 40, 34, 28, 22, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 85,x = 25,y = 80) == [170, 174, 180, 186, 192, 198, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 238, 236, 178, 116, 106, 96, 88, 80, 74, 70, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 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]\n assert candidate(n = 35,x = 15,y = 25) == [70, 74, 80, 86, 92, 76, 74, 72, 70, 68, 66, 62, 56, 50, 44, 36, 30, 24, 18, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 90,x = 40,y = 80) == [180, 184, 190, 196, 202, 208, 214, 220, 226, 232, 238, 242, 244, 246, 248, 250, 252, 254, 256, 258, 178, 172, 166, 160, 154, 148, 142, 136, 130, 124, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 96, 90, 84, 78, 72, 66, 60, 54, 48, 42, 36, 32, 28, 24, 20, 16, 12, 8, 4, 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]\n assert candidate(n = 55,x = 10,y = 45) == [110, 114, 120, 126, 132, 138, 144, 150, 156, 162, 166, 166, 164, 162, 160, 158, 156, 118, 76, 66, 56, 48, 40, 32, 24, 16, 8, 2, 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]\n assert candidate(n = 80,x = 25,y = 75) == [160, 164, 170, 176, 182, 188, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 126, 116, 106, 96, 86, 76, 72, 68, 64, 60, 56, 52, 48, 44, 40, 36, 32, 28, 24, 20, 16, 12, 8, 4, 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]\n assert candidate(n = 40,x = 15,y = 25) == [80, 84, 90, 96, 102, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 64, 56, 46, 36, 26, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 70,x = 30,y = 50) == [140, 144, 150, 156, 162, 168, 174, 180, 186, 192, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 132, 126, 120, 114, 108, 102, 96, 90, 84, 76, 70, 64, 58, 52, 46, 40, 34, 28, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 40,y = 50) == [160, 164, 170, 176, 182, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 112, 106, 100, 94, 88, 86, 84, 82, 80, 76, 70, 64, 58, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 20,x = 10,y = 10) == [38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 65,x = 5,y = 60) == [130, 134, 140, 146, 152, 156, 156, 154, 152, 150, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 92, 32, 24, 16, 8, 2, 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]\n assert candidate(n = 70,x = 25,y = 55) == [140, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 204, 210, 216, 222, 166, 162, 156, 150, 144, 138, 132, 126, 120, 114, 106, 96, 86, 76, 66, 56, 50, 44, 38, 32, 26, 20, 14, 8, 2, 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]\n assert candidate(n = 30,x = 15,y = 20) == [60, 64, 64, 60, 58, 56, 54, 52, 50, 48, 46, 42, 36, 32, 30, 26, 20, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(n = 20,x = 7,y = 14) == [40, 44, 50, 48, 42, 40, 38, 32, 22, 12, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 24,x = 4,y = 21) == [48, 52, 58, 64, 66, 64, 62, 60, 42, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 25,y = 26) == [98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 15,x = 7,y = 8) == [28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 80,x = 40,y = 60) == [160, 164, 170, 176, 182, 188, 194, 200, 206, 212, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 152, 146, 140, 134, 128, 122, 116, 110, 104, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 76, 70, 64, 58, 52, 46, 40, 34, 28, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 55,x = 15,y = 50) == [110, 114, 120, 126, 132, 138, 142, 144, 146, 148, 150, 152, 154, 156, 158, 158, 156, 118, 76, 66, 56, 48, 40, 34, 30, 26, 22, 18, 14, 10, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 15,x = 3,y = 12) == [30, 34, 40, 44, 34, 18, 8, 2, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 20,y = 30) == [100, 104, 110, 116, 122, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 74, 66, 56, 46, 36, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 50,y = 95) == [200, 204, 210, 216, 222, 228, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 218, 170, 164, 158, 152, 146, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 96, 90, 84, 78, 72, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 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]\n assert candidate(n = 100,x = 50,y = 75) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 244, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 192, 186, 180, 174, 168, 162, 156, 150, 144, 138, 132, 126, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 96, 90, 84, 78, 72, 66, 60, 54, 48, 42, 36, 30, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 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]\n assert candidate(n = 64,x = 7,y = 57) == [128, 132, 138, 144, 150, 156, 162, 166, 166, 164, 162, 160, 158, 156, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 52, 44, 36, 28, 20, 12, 4, 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]\n assert candidate(n = 12,x = 2,y = 11) == [24, 28, 30, 28, 18, 4, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 25,y = 45) == [100, 104, 110, 116, 122, 128, 132, 134, 136, 138, 98, 92, 86, 80, 74, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 46, 40, 34, 28, 22, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 25,x = 10,y = 20) == [50, 54, 60, 66, 72, 56, 52, 46, 40, 34, 26, 20, 14, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 90,x = 40,y = 85) == [180, 184, 190, 196, 202, 208, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 198, 150, 144, 138, 132, 126, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 96, 90, 84, 78, 72, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 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]\n assert candidate(n = 20,x = 5,y = 15) == [40, 44, 50, 56, 62, 44, 36, 26, 16, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 45,x = 23,y = 23) == [88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 100,x = 10,y = 90) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 256, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 30,y = 65) == [160, 164, 170, 176, 182, 188, 194, 200, 206, 212, 218, 224, 230, 236, 242, 248, 252, 218, 180, 174, 168, 162, 156, 150, 144, 138, 132, 126, 120, 114, 106, 96, 86, 78, 72, 66, 60, 54, 48, 42, 36, 30, 24, 18, 12, 6, 2, 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]\n assert candidate(n = 25,x = 5,y = 20) == [50, 54, 60, 66, 72, 76, 76, 58, 36, 26, 16, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 75,x = 25,y = 60) == [150, 154, 160, 166, 172, 178, 184, 190, 196, 202, 208, 214, 220, 226, 232, 238, 242, 208, 170, 164, 158, 152, 146, 140, 134, 126, 116, 106, 96, 86, 76, 66, 56, 48, 42, 36, 30, 24, 18, 12, 6, 2, 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]\n assert candidate(n = 30,x = 15,y = 25) == [60, 64, 70, 76, 82, 66, 62, 56, 50, 44, 38, 36, 34, 32, 30, 26, 20, 14, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 96,x = 9,y = 85) == [192, 196, 202, 208, 214, 220, 226, 232, 238, 242, 244, 246, 246, 244, 242, 240, 238, 236, 234, 232, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 76, 68, 60, 52, 44, 36, 28, 20, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 60,x = 15,y = 15) == [118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 60,x = 10,y = 50) == [120, 124, 130, 136, 142, 148, 154, 160, 166, 172, 176, 176, 174, 172, 170, 168, 166, 164, 162, 160, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4, 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]\n assert candidate(n = 40,x = 20,y = 30) == [80, 84, 90, 96, 102, 86, 84, 82, 80, 78, 76, 72, 66, 60, 54, 48, 46, 44, 42, 40, 36, 30, 24, 18, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 8,y = 73) == [160, 164, 170, 176, 182, 188, 194, 200, 202, 200, 198, 196, 194, 192, 190, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 122, 52, 44, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 40,y = 75) == [160, 164, 170, 176, 182, 188, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 178, 140, 134, 128, 122, 116, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 76, 70, 64, 58, 52, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 18,x = 1,y = 18) == [36, 36, 36, 36, 36, 36, 36, 36, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 40,x = 5,y = 35) == [80, 84, 90, 96, 102, 106, 106, 104, 102, 100, 98, 98, 98, 98, 98, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 20,y = 75) == [160, 164, 170, 176, 182, 188, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 218, 216, 214, 212, 210, 208, 208, 152, 92, 84, 76, 68, 60, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 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]\n assert candidate(n = 50,x = 1,y = 49) == [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 4, 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]\n assert candidate(n = 90,x = 30,y = 85) == [180, 184, 190, 196, 202, 208, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 198, 140, 134, 126, 116, 106, 98, 92, 86, 82, 78, 74, 70, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2, 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]\n assert candidate(n = 60,x = 20,y = 40) == [120, 124, 130, 136, 142, 148, 154, 160, 166, 172, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 114, 106, 96, 86, 76, 66, 56, 46, 36, 26, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 18,x = 3,y = 16) == [36, 40, 46, 48, 46, 44, 30, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 30,x = 5,y = 25) == [60, 64, 70, 76, 82, 86, 86, 84, 82, 80, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 75,x = 10,y = 70) == [150, 154, 160, 166, 172, 178, 182, 184, 186, 188, 188, 186, 184, 182, 180, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 56, 48, 40, 32, 24, 16, 12, 8, 4, 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]\n", "comparison": "exact"}, "public_tests": ["3\n1\n3", "5\n2\n4", "4\n1\n1"], "hints": ["Start from each house, run a BFS to get all the distances from this house to all the other houses."], "metadata": {"canonical_parameter_names": ["n", "x", "y"], "leetcode_dataset_entry_point": "Solution().countOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:23+00:00", "tests_total": 114, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["breadth-first-search", "graph", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def count_of_pairs(n, x, y)", "container": null, "callable": "count_of_pairs", "parameters": [{"name": "n", "type": "Integer"}, {"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3016, "task_id": "minimum-number-of-pushes-to-type-word-ii", "difficulty": "Medium", "problem_description": "You are given a string word containing lowercase English letters.\n\nTelephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\n\nIt is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\n\nReturn the minimum number of pushes needed to type word after remapping the keys.\n\nAn example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n\nExample 1:\n\nInput: word = \"abcde\"\nOutput: 5\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\nTotal cost is 1 + 1 + 1 + 1 + 1 = 5.\nIt can be shown that no other mapping can provide a lower cost.\n\nExample 2:\n\nInput: word = \"xyzxyzxyzxyz\"\nOutput: 12\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"x\" -> one push on key 2\n\"y\" -> one push on key 3\n\"z\" -> one push on key 4\nTotal cost is 1 * 4 + 1 * 4 + 1 * 4 = 12\nIt can be shown that no other mapping can provide a lower cost.\nNote that the key 9 is not mapped to any letter: it is not necessary to map letters to every key, but to map all the letters.\n\nExample 3:\n\nInput: word = \"aabbccddeeffgghhiiiiii\"\nOutput: 24\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\n\"f\" -> one push on key 7\n\"g\" -> one push on key 8\n\"h\" -> two pushes on key 9\n\"i\" -> one push on key 9\nTotal cost is 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24.\nIt can be shown that no other mapping can provide a lower cost.\n\nConstraints:\n\n- 1 <= word.length <= 10^5\n- word consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 52\n assert candidate(word = \"abcde\") == 5\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\") == 56\n assert candidate(word = \"mississippi\") == 11\n assert candidate(word = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 52\n assert candidate(word = \"aaaabbbbccccddddeeeeffffgggghhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkkllllllllllllmmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnoooooooppppppppppppppppqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrsssssssssssssssstttttttttttttttttuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwxxxxxxxxxyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzz\") == 499\n assert candidate(word = \"hellohellohellohellohellohellohellohellohellohello\") == 50\n assert candidate(word = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 88\n assert candidate(word = \"xyzxyzxyzxyz\") == 12\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 56\n assert candidate(word = \"a\") == 1\n assert candidate(word = \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 198\n assert candidate(word = \"ababababababababababababababababababababab\") == 42\n assert candidate(word = \"aabbccddeeffgghhiiiiii\") == 24\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 98\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 168\n assert candidate(word = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 104\n assert candidate(word = \"ppppppppppppppppppppppppppppppppppppppppppppppppppppqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 104\n assert candidate(word = \"mississippimississippimississippimississippi\") == 44\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 162\n assert candidate(word = \"loremipsumdolorsitametconsecteturadipiscingelitloremipsumdolorsitametconsecteturadipiscingelitloremipsumdolorsitametconsecteturadipiscingelit\") == 183\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzz\") == 79\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 143\n assert candidate(word = \"onelongwordwithoutrepetitionsonelongwordwithoutrepetitions\") == 70\n assert candidate(word = \"thequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydog\") == 130\n assert candidate(word = \"uniquelettersabcdefghijklmnopqrstuvwxyzuniqueletters\") == 84\n assert candidate(word = \"aaaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeffffffffggggggghhhhhhhh\") == 64\n assert candidate(word = \"nnnnneeeeffffddddeeeeffffddddddddddddeeeeeeeeeeeeeeeeffffffddddddddddddddeeeeeeeeeeeeeeeeffffffdddddddddddddeeeeeeeeeeeeee\") == 122\n assert candidate(word = \"equalprobabilityabcdefghijklmnopqrstuvwxyz\") == 76\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 136\n assert candidate(word = \"ppppoooolllliiiihhhhggggffffeeeeeeeedddddccccbbbaaa\") == 65\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 114\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 112\n assert candidate(word = \"mnbvcxzvbnmzxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnmxcvbnm\") == 102\n assert candidate(word = \"aaaabbbbccccddddeeeeffffgggghhhhiiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 225\n assert candidate(word = \"repeatedrepeatedrepeatedrepeatedrepeatedrepeated\") == 48\n assert candidate(word = \"aabbcdeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 104\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 112\n assert candidate(word = \"frequencydistributionfrequencydistribution\") == 54\n assert candidate(word = \"programmingproblemsolvingprogramming\") == 42\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop\") == 132\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 56\n assert candidate(word = \"mississippiissippiissippi\") == 25\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 170\n assert candidate(word = \"abcdefghijklnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 108\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzz\") == 120\n assert candidate(word = \"frequentfrequentfrequentfrequentfrequentfrequentfrequentfrequentfrequentfrequent\") == 80\n", "comparison": "exact"}, "public_tests": ["\"abcde\"", "\"xyzxyzxyzxyz\"", "\"aabbccddeeffgghhiiiiii\""], "hints": ["We have 8 keys in total. We can type 8 characters with one push each, 8 different characters with two pushes each, and so on.", "The optimal way is to map letters to keys evenly.", "Sort the letters by frequencies in the word in non-increasing order."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().minimumPushes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:26+00:00", "tests_total": 47, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["hash-table", "string", "greedy", "sorting", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_pushes(word)", "container": null, "callable": "minimum_pushes", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3017, "task_id": "count-the-number-of-houses-at-a-certain-distance-ii", "difficulty": "Hard", "problem_description": "You are given three positive integers n, x, and y.\n\nIn a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\n\nFor each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house_1, house_2) such that the minimum number of streets that need to be traveled to reach house_2 from house_1 is k.\n\nReturn a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\n\nNote that x and y can be equal.\n\nExample 1:\n\nInput: n = 3, x = 1, y = 3\nOutput: [6,0,0]\nExplanation: Let's look at each pair of houses:\n- For the pair (1, 2), we can go from house 1 to house 2 directly.\n- For the pair (2, 1), we can go from house 2 to house 1 directly.\n- For the pair (1, 3), we can go from house 1 to house 3 directly.\n- For the pair (3, 1), we can go from house 3 to house 1 directly.\n- For the pair (2, 3), we can go from house 2 to house 3 directly.\n- For the pair (3, 2), we can go from house 3 to house 2 directly.\n\nExample 2:\n\nInput: n = 5, x = 2, y = 4\nOutput: [10,8,2,0,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n- For k == 3, the pairs are (1, 5), and (5, 1).\n- For k == 4 and k == 5, there are no pairs.\n\nExample 3:\n\nInput: n = 4, x = 1, y = 1\nOutput: [6,4,2,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n- For k == 3, the pairs are (1, 4), and (4, 1).\n- For k == 4, there are no pairs.\n\nConstraints:\n\n- 2 <= n <= 10^5\n- 1 <= x, y <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,x = 3,y = 7) == [20, 24, 20, 16, 8, 2, 0, 0, 0, 0]\n assert candidate(n = 10,x = 3,y = 8) == [20, 24, 24, 16, 6, 0, 0, 0, 0, 0]\n assert candidate(n = 4,x = 1,y = 1) == [6, 4, 2, 0]\n assert candidate(n = 5,x = 2,y = 4) == [10, 8, 2, 0, 0]\n assert candidate(n = 6,x = 2,y = 5) == [12, 12, 6, 0, 0, 0]\n assert candidate(n = 3,x = 1,y = 3) == [6, 0, 0]\n assert candidate(n = 7,x = 1,y = 7) == [14, 14, 14, 0, 0, 0, 0]\n assert candidate(n = 9,x = 2,y = 8) == [18, 22, 24, 8, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 50,y = 50) == [198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 50,x = 10,y = 40) == [100, 104, 110, 116, 122, 128, 134, 140, 146, 152, 156, 156, 154, 152, 150, 86, 76, 66, 56, 46, 36, 28, 20, 12, 4, 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]\n assert candidate(n = 30,x = 2,y = 29) == [60, 64, 66, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 36, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 40,y = 41) == [158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 25,x = 10,y = 12) == [50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 28, 26, 24, 22, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0]\n assert candidate(n = 1000,x = 300,y = 700) == [2000, 2004, 2010, 2016, 2022, 2028, 2034, 2040, 2046, 2052, 2058, 2064, 2070, 2076, 2082, 2088, 2094, 2100, 2106, 2112, 2118, 2124, 2130, 2136, 2142, 2148, 2154, 2160, 2166, 2172, 2178, 2184, 2190, 2196, 2202, 2208, 2214, 2220, 2226, 2232, 2238, 2244, 2250, 2256, 2262, 2268, 2274, 2280, 2286, 2292, 2298, 2304, 2310, 2316, 2322, 2328, 2334, 2340, 2346, 2352, 2358, 2364, 2370, 2376, 2382, 2388, 2394, 2400, 2406, 2412, 2418, 2424, 2430, 2436, 2442, 2448, 2454, 2460, 2466, 2472, 2478, 2484, 2490, 2496, 2502, 2508, 2514, 2520, 2526, 2532, 2538, 2544, 2550, 2556, 2562, 2568, 2574, 2580, 2586, 2592, 2598, 2604, 2610, 2616, 2622, 2628, 2634, 2640, 2646, 2652, 2658, 2664, 2670, 2676, 2682, 2688, 2694, 2700, 2706, 2712, 2718, 2724, 2730, 2736, 2742, 2748, 2754, 2760, 2766, 2772, 2778, 2784, 2790, 2796, 2802, 2808, 2814, 2820, 2826, 2832, 2838, 2844, 2850, 2856, 2862, 2868, 2874, 2880, 2886, 2892, 2898, 2904, 2910, 2916, 2922, 2928, 2934, 2940, 2946, 2952, 2958, 2964, 2970, 2976, 2982, 2988, 2994, 3000, 3006, 3012, 3018, 3024, 3030, 3036, 3042, 3048, 3054, 3060, 3066, 3072, 3078, 3084, 3090, 3096, 3102, 3108, 3114, 3120, 3126, 3132, 3138, 3144, 3150, 3156, 3162, 3168, 3174, 3180, 3186, 3192, 2396, 2394, 2392, 2390, 2388, 2386, 2384, 2382, 2380, 2378, 2376, 2374, 2372, 2370, 2368, 2366, 2364, 2362, 2360, 2358, 2356, 2354, 2352, 2350, 2348, 2346, 2344, 2342, 2340, 2338, 2336, 2334, 2332, 2330, 2328, 2326, 2324, 2322, 2320, 2318, 2316, 2314, 2312, 2310, 2308, 2306, 2304, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288, 2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268, 2266, 2264, 2262, 2260, 2258, 2256, 2254, 2252, 2250, 2248, 2246, 2244, 2242, 2240, 2238, 2236, 2234, 2232, 2230, 2228, 2226, 2224, 2222, 2220, 2218, 2216, 2214, 2212, 2210, 2208, 2206, 2204, 2202, 2200, 2198, 2194, 2186, 2176, 2166, 2156, 2146, 2136, 2126, 2116, 2106, 2096, 2086, 2076, 2066, 2056, 2046, 2036, 2026, 2016, 2006, 1996, 1986, 1976, 1966, 1956, 1946, 1936, 1926, 1916, 1906, 1896, 1886, 1876, 1866, 1856, 1846, 1836, 1826, 1816, 1806, 1796, 1786, 1776, 1766, 1756, 1746, 1736, 1726, 1716, 1706, 1696, 1686, 1676, 1666, 1656, 1646, 1636, 1626, 1616, 1606, 1596, 1586, 1576, 1566, 1556, 1546, 1536, 1526, 1516, 1506, 1496, 1486, 1476, 1466, 1456, 1446, 1436, 1426, 1416, 1406, 1396, 1386, 1376, 1366, 1356, 1346, 1336, 1326, 1316, 1306, 1296, 1286, 1276, 1266, 1256, 1246, 1236, 1226, 1216, 1206, 1196, 1186, 1176, 1166, 1156, 1146, 1136, 1126, 1116, 1106, 1096, 1086, 1076, 1066, 1056, 1046, 1036, 1026, 1016, 1006, 996, 986, 976, 966, 956, 946, 936, 926, 916, 906, 896, 886, 876, 866, 856, 846, 836, 826, 816, 806, 796, 786, 776, 766, 756, 746, 736, 726, 716, 706, 696, 686, 676, 666, 656, 646, 636, 626, 616, 606, 596, 586, 576, 566, 556, 546, 536, 526, 516, 506, 496, 486, 476, 466, 456, 446, 436, 426, 416, 406, 396, 386, 376, 366, 356, 346, 336, 326, 316, 306, 296, 286, 276, 266, 256, 246, 236, 226, 216, 206, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 2,y = 99) == [200, 204, 206, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 106, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 200,x = 100,y = 100) == [398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 500,x = 1,y = 500) == [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 25,x = 10,y = 15) == [50, 54, 54, 50, 48, 46, 44, 42, 40, 38, 34, 26, 18, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(n = 500,x = 100,y = 400) == [1000, 1004, 1010, 1016, 1022, 1028, 1034, 1040, 1046, 1052, 1058, 1064, 1070, 1076, 1082, 1088, 1094, 1100, 1106, 1112, 1118, 1124, 1130, 1136, 1142, 1148, 1154, 1160, 1166, 1172, 1178, 1184, 1190, 1196, 1202, 1208, 1214, 1220, 1226, 1232, 1238, 1244, 1250, 1256, 1262, 1268, 1274, 1280, 1286, 1292, 1298, 1304, 1310, 1316, 1322, 1328, 1334, 1340, 1346, 1352, 1358, 1364, 1370, 1376, 1382, 1388, 1394, 1400, 1406, 1412, 1418, 1424, 1430, 1436, 1442, 1448, 1454, 1460, 1466, 1472, 1478, 1484, 1490, 1496, 1502, 1508, 1514, 1520, 1526, 1532, 1538, 1544, 1550, 1556, 1562, 1568, 1574, 1580, 1586, 1592, 1596, 1596, 1594, 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 1512, 1510, 1508, 1506, 1504, 1502, 1500, 896, 886, 876, 866, 856, 846, 836, 826, 816, 806, 796, 786, 776, 766, 756, 746, 736, 726, 716, 706, 696, 686, 676, 666, 656, 646, 636, 626, 616, 606, 596, 586, 576, 566, 556, 546, 536, 526, 516, 506, 496, 486, 476, 466, 456, 446, 436, 426, 416, 406, 396, 388, 380, 372, 364, 356, 348, 340, 332, 324, 316, 308, 300, 292, 284, 276, 268, 260, 252, 244, 236, 228, 220, 212, 204, 196, 188, 180, 172, 164, 156, 148, 140, 132, 124, 116, 108, 100, 92, 84, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 5,y = 95) == [200, 204, 210, 216, 222, 226, 226, 224, 222, 220, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 75,x = 30,y = 45) == [150, 154, 160, 166, 172, 178, 184, 174, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 114, 106, 96, 86, 76, 66, 56, 48, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 500,x = 250,y = 251) == [998, 996, 994, 992, 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, 830, 828, 826, 824, 822, 820, 818, 816, 814, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762, 760, 758, 756, 754, 752, 750, 748, 746, 744, 742, 740, 738, 736, 734, 732, 730, 728, 726, 724, 722, 720, 718, 716, 714, 712, 710, 708, 706, 704, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 75,x = 25,y = 75) == [150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 96, 92, 88, 84, 80, 76, 72, 68, 64, 60, 56, 52, 48, 44, 40, 36, 32, 28, 24, 20, 16, 12, 8, 4, 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]\n assert candidate(n = 100,x = 25,y = 75) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312, 318, 324, 330, 336, 342, 244, 236, 226, 216, 206, 196, 186, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 36, 26, 16, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 15,x = 5,y = 12) == [30, 34, 40, 38, 30, 22, 12, 4, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 150,x = 75,y = 76) == [298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 80,x = 5,y = 75) == [160, 164, 170, 176, 182, 186, 186, 184, 182, 180, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 40,y = 60) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 154, 146, 136, 126, 116, 106, 96, 86, 76, 66, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 1,y = 50) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 50, 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]\n assert candidate(n = 500,x = 250,y = 250) == [998, 996, 994, 992, 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, 830, 828, 826, 824, 822, 820, 818, 816, 814, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762, 760, 758, 756, 754, 752, 750, 748, 746, 744, 742, 740, 738, 736, 734, 732, 730, 728, 726, 724, 722, 720, 718, 716, 714, 712, 710, 708, 706, 704, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 30,x = 15,y = 15) == [58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 50,x = 25,y = 25) == [98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 20,x = 4,y = 18) == [40, 44, 50, 54, 54, 52, 50, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 50,y = 51) == [198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 300,x = 150,y = 151) == [598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 1000,x = 500,y = 500) == [1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982, 1980, 1978, 1976, 1974, 1972, 1970, 1968, 1966, 1964, 1962, 1960, 1958, 1956, 1954, 1952, 1950, 1948, 1946, 1944, 1942, 1940, 1938, 1936, 1934, 1932, 1930, 1928, 1926, 1924, 1922, 1920, 1918, 1916, 1914, 1912, 1910, 1908, 1906, 1904, 1902, 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 1884, 1882, 1880, 1878, 1876, 1874, 1872, 1870, 1868, 1866, 1864, 1862, 1860, 1858, 1856, 1854, 1852, 1850, 1848, 1846, 1844, 1842, 1840, 1838, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778, 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746, 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1720, 1718, 1716, 1714, 1712, 1710, 1708, 1706, 1704, 1702, 1700, 1698, 1696, 1694, 1692, 1690, 1688, 1686, 1684, 1682, 1680, 1678, 1676, 1674, 1672, 1670, 1668, 1666, 1664, 1662, 1660, 1658, 1656, 1654, 1652, 1650, 1648, 1646, 1644, 1642, 1640, 1638, 1636, 1634, 1632, 1630, 1628, 1626, 1624, 1622, 1620, 1618, 1616, 1614, 1612, 1610, 1608, 1606, 1604, 1602, 1600, 1598, 1596, 1594, 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 1512, 1510, 1508, 1506, 1504, 1502, 1500, 1498, 1496, 1494, 1492, 1490, 1488, 1486, 1484, 1482, 1480, 1478, 1476, 1474, 1472, 1470, 1468, 1466, 1464, 1462, 1460, 1458, 1456, 1454, 1452, 1450, 1448, 1446, 1444, 1442, 1440, 1438, 1436, 1434, 1432, 1430, 1428, 1426, 1424, 1422, 1420, 1418, 1416, 1414, 1412, 1410, 1408, 1406, 1404, 1402, 1400, 1398, 1396, 1394, 1392, 1390, 1388, 1386, 1384, 1382, 1380, 1378, 1376, 1374, 1372, 1370, 1368, 1366, 1364, 1362, 1360, 1358, 1356, 1354, 1352, 1350, 1348, 1346, 1344, 1342, 1340, 1338, 1336, 1334, 1332, 1330, 1328, 1326, 1324, 1322, 1320, 1318, 1316, 1314, 1312, 1310, 1308, 1306, 1304, 1302, 1300, 1298, 1296, 1294, 1292, 1290, 1288, 1286, 1284, 1282, 1280, 1278, 1276, 1274, 1272, 1270, 1268, 1266, 1264, 1262, 1260, 1258, 1256, 1254, 1252, 1250, 1248, 1246, 1244, 1242, 1240, 1238, 1236, 1234, 1232, 1230, 1228, 1226, 1224, 1222, 1220, 1218, 1216, 1214, 1212, 1210, 1208, 1206, 1204, 1202, 1200, 1198, 1196, 1194, 1192, 1190, 1188, 1186, 1184, 1182, 1180, 1178, 1176, 1174, 1172, 1170, 1168, 1166, 1164, 1162, 1160, 1158, 1156, 1154, 1152, 1150, 1148, 1146, 1144, 1142, 1140, 1138, 1136, 1134, 1132, 1130, 1128, 1126, 1124, 1122, 1120, 1118, 1116, 1114, 1112, 1110, 1108, 1106, 1104, 1102, 1100, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 998, 996, 994, 992, 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, 830, 828, 826, 824, 822, 820, 818, 816, 814, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762, 760, 758, 756, 754, 752, 750, 748, 746, 744, 742, 740, 738, 736, 734, 732, 730, 728, 726, 724, 722, 720, 718, 716, 714, 712, 710, 708, 706, 704, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 1000,x = 500,y = 700) == [2000, 2004, 2010, 2016, 2022, 2028, 2034, 2040, 2046, 2052, 2058, 2064, 2070, 2076, 2082, 2088, 2094, 2100, 2106, 2112, 2118, 2124, 2130, 2136, 2142, 2148, 2154, 2160, 2166, 2172, 2178, 2184, 2190, 2196, 2202, 2208, 2214, 2220, 2226, 2232, 2238, 2244, 2250, 2256, 2262, 2268, 2274, 2280, 2286, 2292, 2298, 2304, 2310, 2316, 2322, 2328, 2334, 2340, 2346, 2352, 2358, 2364, 2370, 2376, 2382, 2388, 2394, 2400, 2406, 2412, 2418, 2424, 2430, 2436, 2442, 2448, 2454, 2460, 2466, 2472, 2478, 2484, 2490, 2496, 2502, 2508, 2514, 2520, 2526, 2532, 2538, 2544, 2550, 2556, 2562, 2568, 2574, 2580, 2586, 2592, 2196, 2194, 2192, 2190, 2188, 2186, 2184, 2182, 2180, 2178, 2176, 2174, 2172, 2170, 2168, 2166, 2164, 2162, 2160, 2158, 2156, 2154, 2152, 2150, 2148, 2146, 2144, 2142, 2140, 2138, 2136, 2134, 2132, 2130, 2128, 2126, 2124, 2122, 2120, 2118, 2116, 2114, 2112, 2110, 2108, 2106, 2104, 2102, 2100, 2098, 2096, 2094, 2092, 2090, 2088, 2086, 2084, 2082, 2080, 2078, 2076, 2074, 2072, 2070, 2068, 2066, 2064, 2062, 2060, 2058, 2056, 2054, 2052, 2050, 2048, 2046, 2044, 2042, 2040, 2038, 2036, 2034, 2032, 2030, 2028, 2026, 2024, 2022, 2020, 2018, 2016, 2014, 2012, 2010, 2008, 2006, 2004, 2002, 2000, 1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982, 1980, 1978, 1976, 1974, 1972, 1970, 1968, 1966, 1964, 1962, 1960, 1958, 1956, 1954, 1952, 1950, 1948, 1946, 1944, 1942, 1940, 1938, 1936, 1934, 1932, 1930, 1928, 1926, 1924, 1922, 1920, 1918, 1916, 1914, 1912, 1910, 1908, 1906, 1904, 1902, 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 1884, 1882, 1880, 1878, 1876, 1874, 1872, 1870, 1868, 1866, 1864, 1862, 1860, 1858, 1856, 1854, 1852, 1850, 1848, 1846, 1844, 1842, 1840, 1838, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1792, 1786, 1780, 1774, 1768, 1762, 1756, 1750, 1744, 1738, 1732, 1726, 1720, 1714, 1708, 1702, 1696, 1690, 1684, 1678, 1672, 1666, 1660, 1654, 1648, 1642, 1636, 1630, 1624, 1618, 1612, 1606, 1600, 1594, 1588, 1582, 1576, 1570, 1564, 1558, 1552, 1546, 1540, 1534, 1528, 1522, 1516, 1510, 1504, 1498, 1492, 1486, 1480, 1474, 1468, 1462, 1456, 1450, 1444, 1438, 1432, 1426, 1420, 1414, 1408, 1402, 1396, 1390, 1384, 1378, 1372, 1366, 1360, 1354, 1348, 1342, 1336, 1330, 1324, 1318, 1312, 1306, 1300, 1294, 1288, 1282, 1276, 1270, 1264, 1258, 1252, 1246, 1240, 1234, 1228, 1222, 1216, 1210, 1204, 1198, 1196, 1194, 1192, 1190, 1188, 1186, 1184, 1182, 1180, 1178, 1176, 1174, 1172, 1170, 1168, 1166, 1164, 1162, 1160, 1158, 1156, 1154, 1152, 1150, 1148, 1146, 1144, 1142, 1140, 1138, 1136, 1134, 1132, 1130, 1128, 1126, 1124, 1122, 1120, 1118, 1116, 1114, 1112, 1110, 1108, 1106, 1104, 1102, 1100, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 996, 990, 984, 978, 972, 966, 960, 954, 948, 942, 936, 930, 924, 918, 912, 906, 900, 894, 888, 882, 876, 870, 864, 858, 852, 846, 840, 834, 828, 822, 816, 810, 804, 798, 792, 786, 780, 774, 768, 762, 756, 750, 744, 738, 732, 726, 720, 714, 708, 702, 696, 690, 684, 678, 672, 666, 660, 654, 648, 642, 636, 630, 624, 618, 612, 606, 600, 594, 588, 582, 576, 570, 564, 558, 552, 546, 540, 534, 528, 522, 516, 510, 504, 498, 492, 486, 480, 474, 468, 462, 456, 450, 444, 438, 432, 426, 420, 414, 408, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 250,x = 100,y = 150) == [500, 504, 510, 516, 522, 528, 534, 540, 546, 552, 558, 564, 570, 576, 582, 588, 594, 600, 606, 612, 618, 624, 630, 636, 642, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 394, 386, 376, 366, 356, 346, 336, 326, 316, 306, 296, 286, 276, 266, 256, 246, 236, 226, 216, 206, 196, 186, 176, 166, 156, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 20,x = 10,y = 11) == [38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 30,x = 10,y = 20) == [60, 64, 70, 76, 82, 66, 64, 62, 60, 58, 54, 46, 36, 26, 16, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 18,x = 5,y = 13) == [36, 40, 46, 52, 40, 36, 28, 18, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 1000,x = 500,y = 501) == [1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982, 1980, 1978, 1976, 1974, 1972, 1970, 1968, 1966, 1964, 1962, 1960, 1958, 1956, 1954, 1952, 1950, 1948, 1946, 1944, 1942, 1940, 1938, 1936, 1934, 1932, 1930, 1928, 1926, 1924, 1922, 1920, 1918, 1916, 1914, 1912, 1910, 1908, 1906, 1904, 1902, 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 1884, 1882, 1880, 1878, 1876, 1874, 1872, 1870, 1868, 1866, 1864, 1862, 1860, 1858, 1856, 1854, 1852, 1850, 1848, 1846, 1844, 1842, 1840, 1838, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778, 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746, 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1720, 1718, 1716, 1714, 1712, 1710, 1708, 1706, 1704, 1702, 1700, 1698, 1696, 1694, 1692, 1690, 1688, 1686, 1684, 1682, 1680, 1678, 1676, 1674, 1672, 1670, 1668, 1666, 1664, 1662, 1660, 1658, 1656, 1654, 1652, 1650, 1648, 1646, 1644, 1642, 1640, 1638, 1636, 1634, 1632, 1630, 1628, 1626, 1624, 1622, 1620, 1618, 1616, 1614, 1612, 1610, 1608, 1606, 1604, 1602, 1600, 1598, 1596, 1594, 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 1512, 1510, 1508, 1506, 1504, 1502, 1500, 1498, 1496, 1494, 1492, 1490, 1488, 1486, 1484, 1482, 1480, 1478, 1476, 1474, 1472, 1470, 1468, 1466, 1464, 1462, 1460, 1458, 1456, 1454, 1452, 1450, 1448, 1446, 1444, 1442, 1440, 1438, 1436, 1434, 1432, 1430, 1428, 1426, 1424, 1422, 1420, 1418, 1416, 1414, 1412, 1410, 1408, 1406, 1404, 1402, 1400, 1398, 1396, 1394, 1392, 1390, 1388, 1386, 1384, 1382, 1380, 1378, 1376, 1374, 1372, 1370, 1368, 1366, 1364, 1362, 1360, 1358, 1356, 1354, 1352, 1350, 1348, 1346, 1344, 1342, 1340, 1338, 1336, 1334, 1332, 1330, 1328, 1326, 1324, 1322, 1320, 1318, 1316, 1314, 1312, 1310, 1308, 1306, 1304, 1302, 1300, 1298, 1296, 1294, 1292, 1290, 1288, 1286, 1284, 1282, 1280, 1278, 1276, 1274, 1272, 1270, 1268, 1266, 1264, 1262, 1260, 1258, 1256, 1254, 1252, 1250, 1248, 1246, 1244, 1242, 1240, 1238, 1236, 1234, 1232, 1230, 1228, 1226, 1224, 1222, 1220, 1218, 1216, 1214, 1212, 1210, 1208, 1206, 1204, 1202, 1200, 1198, 1196, 1194, 1192, 1190, 1188, 1186, 1184, 1182, 1180, 1178, 1176, 1174, 1172, 1170, 1168, 1166, 1164, 1162, 1160, 1158, 1156, 1154, 1152, 1150, 1148, 1146, 1144, 1142, 1140, 1138, 1136, 1134, 1132, 1130, 1128, 1126, 1124, 1122, 1120, 1118, 1116, 1114, 1112, 1110, 1108, 1106, 1104, 1102, 1100, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 998, 996, 994, 992, 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, 830, 828, 826, 824, 822, 820, 818, 816, 814, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762, 760, 758, 756, 754, 752, 750, 748, 746, 744, 742, 740, 738, 736, 734, 732, 730, 728, 726, 724, 722, 720, 718, 716, 714, 712, 710, 708, 706, 704, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 60,x = 10,y = 55) == [120, 124, 130, 136, 142, 148, 152, 154, 156, 158, 158, 156, 154, 152, 150, 148, 148, 148, 148, 148, 148, 148, 102, 52, 44, 36, 28, 20, 14, 10, 6, 2, 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]\n assert candidate(n = 5,x = 1,y = 5) == [10, 10, 0, 0, 0]\n assert candidate(n = 50,x = 25,y = 30) == [100, 104, 104, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 62, 56, 52, 50, 46, 40, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(n = 300,x = 150,y = 250) == [600, 604, 610, 616, 622, 628, 634, 640, 646, 652, 658, 664, 670, 676, 682, 688, 694, 700, 706, 712, 718, 724, 730, 736, 742, 748, 754, 760, 766, 772, 778, 784, 790, 796, 802, 808, 814, 820, 826, 832, 838, 844, 850, 856, 862, 868, 874, 880, 886, 892, 696, 692, 686, 680, 674, 668, 662, 656, 650, 644, 638, 632, 626, 620, 614, 608, 602, 596, 590, 584, 578, 572, 566, 560, 554, 548, 542, 536, 530, 524, 518, 512, 506, 500, 494, 488, 482, 476, 470, 464, 458, 452, 446, 440, 434, 428, 422, 416, 410, 404, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 296, 290, 284, 278, 272, 266, 260, 254, 248, 242, 236, 230, 224, 218, 212, 206, 200, 194, 188, 182, 176, 170, 164, 158, 152, 146, 140, 134, 128, 122, 116, 110, 104, 98, 92, 86, 80, 74, 68, 62, 56, 50, 44, 38, 32, 26, 20, 14, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 30,x = 1,y = 30) == [60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 20,y = 80) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312, 316, 316, 314, 312, 310, 308, 306, 304, 302, 300, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 90,x = 30,y = 60) == [180, 184, 190, 196, 202, 208, 214, 220, 226, 232, 238, 244, 250, 256, 262, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 174, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 36, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 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]\n assert candidate(n = 20,x = 5,y = 16) == [40, 44, 50, 56, 62, 52, 34, 24, 14, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 80,x = 20,y = 60) == [160, 164, 170, 176, 182, 188, 194, 200, 206, 212, 218, 224, 230, 236, 242, 248, 254, 260, 266, 272, 194, 186, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 36, 26, 16, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 1,y = 1) == [198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 25,x = 3,y = 22) == [50, 54, 60, 64, 64, 62, 60, 60, 60, 40, 16, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 1000,x = 1,y = 1000) == [2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 50,y = 55) == [200, 204, 204, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 112, 106, 102, 100, 96, 90, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 15,y = 40) == [100, 104, 110, 116, 122, 128, 134, 140, 146, 152, 158, 162, 138, 110, 104, 96, 86, 76, 66, 56, 46, 36, 26, 18, 12, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 300,x = 200,y = 250) == [600, 604, 610, 616, 622, 628, 634, 640, 646, 652, 658, 664, 670, 676, 682, 688, 694, 700, 706, 712, 718, 724, 730, 736, 742, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 592, 586, 580, 574, 568, 562, 556, 550, 544, 538, 532, 526, 520, 514, 508, 502, 496, 490, 484, 478, 472, 466, 460, 454, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 196, 190, 184, 178, 172, 166, 160, 154, 148, 142, 136, 130, 124, 118, 112, 106, 100, 94, 88, 82, 76, 70, 64, 58, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 200,x = 100,y = 101) == [398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 25,x = 5,y = 5) == [48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 5000,x = 1,y = 5000) == [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 5000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 20,x = 7,y = 14) == [40, 44, 50, 48, 42, 40, 38, 32, 22, 12, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 25,y = 26) == [98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 100,x = 3,y = 4) == [198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 150,x = 75,y = 75) == [298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 180,x = 60,y = 120) == [360, 364, 370, 376, 382, 388, 394, 400, 406, 412, 418, 424, 430, 436, 442, 448, 454, 460, 466, 472, 478, 484, 490, 496, 502, 508, 514, 520, 526, 532, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 354, 346, 336, 326, 316, 306, 296, 286, 276, 266, 256, 246, 236, 226, 216, 206, 196, 186, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 75,x = 10,y = 65) == [150, 154, 160, 166, 172, 178, 184, 190, 196, 202, 206, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 188, 188, 188, 188, 188, 188, 132, 72, 64, 56, 48, 40, 32, 24, 16, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 20,y = 30) == [100, 104, 110, 116, 122, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 74, 66, 56, 46, 36, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 25,y = 35) == [100, 104, 110, 116, 122, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 82, 76, 70, 64, 58, 56, 54, 52, 50, 46, 40, 34, 28, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 50,y = 75) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 244, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 192, 186, 180, 174, 168, 162, 156, 150, 144, 138, 132, 126, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 96, 90, 84, 78, 72, 66, 60, 54, 48, 42, 36, 30, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 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]\n assert candidate(n = 150,x = 1,y = 150) == [300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 150, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]\n assert candidate(n = 20,x = 5,y = 15) == [40, 44, 50, 56, 62, 44, 36, 26, 16, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 10,y = 90) == [200, 204, 210, 216, 222, 228, 234, 240, 246, 252, 256, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 200,x = 50,y = 150) == [400, 404, 410, 416, 422, 428, 434, 440, 446, 452, 458, 464, 470, 476, 482, 488, 494, 500, 506, 512, 518, 524, 530, 536, 542, 548, 554, 560, 566, 572, 578, 584, 590, 596, 602, 608, 614, 620, 626, 632, 638, 644, 650, 656, 662, 668, 674, 680, 686, 692, 494, 486, 476, 466, 456, 446, 436, 426, 416, 406, 396, 386, 376, 366, 356, 346, 336, 326, 316, 306, 296, 286, 276, 266, 256, 246, 236, 226, 216, 206, 196, 186, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 36, 26, 16, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 999,x = 333,y = 666) == [1998, 2002, 2008, 2014, 2020, 2026, 2032, 2038, 2044, 2050, 2056, 2062, 2068, 2074, 2080, 2086, 2092, 2098, 2104, 2110, 2116, 2122, 2128, 2134, 2140, 2146, 2152, 2158, 2164, 2170, 2176, 2182, 2188, 2194, 2200, 2206, 2212, 2218, 2224, 2230, 2236, 2242, 2248, 2254, 2260, 2266, 2272, 2278, 2284, 2290, 2296, 2302, 2308, 2314, 2320, 2326, 2332, 2338, 2344, 2350, 2356, 2362, 2368, 2374, 2380, 2386, 2392, 2398, 2404, 2410, 2416, 2422, 2428, 2434, 2440, 2446, 2452, 2458, 2464, 2470, 2476, 2482, 2488, 2494, 2500, 2506, 2512, 2518, 2524, 2530, 2536, 2542, 2548, 2554, 2560, 2566, 2572, 2578, 2584, 2590, 2596, 2602, 2608, 2614, 2620, 2626, 2632, 2638, 2644, 2650, 2656, 2662, 2668, 2674, 2680, 2686, 2692, 2698, 2704, 2710, 2716, 2722, 2728, 2734, 2740, 2746, 2752, 2758, 2764, 2770, 2776, 2782, 2788, 2794, 2800, 2806, 2812, 2818, 2824, 2830, 2836, 2842, 2848, 2854, 2860, 2866, 2872, 2878, 2884, 2890, 2896, 2902, 2908, 2914, 2920, 2926, 2932, 2938, 2944, 2950, 2956, 2962, 2968, 2974, 2980, 2986, 2658, 2326, 2324, 2322, 2320, 2318, 2316, 2314, 2312, 2310, 2308, 2306, 2304, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288, 2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268, 2266, 2264, 2262, 2260, 2258, 2256, 2254, 2252, 2250, 2248, 2246, 2244, 2242, 2240, 2238, 2236, 2234, 2232, 2230, 2228, 2226, 2224, 2222, 2220, 2218, 2216, 2214, 2212, 2210, 2208, 2206, 2204, 2202, 2200, 2198, 2196, 2194, 2192, 2190, 2188, 2186, 2184, 2182, 2180, 2178, 2176, 2174, 2172, 2170, 2168, 2166, 2164, 2162, 2160, 2158, 2156, 2154, 2152, 2150, 2148, 2146, 2144, 2142, 2140, 2138, 2136, 2134, 2132, 2130, 2128, 2126, 2124, 2122, 2120, 2118, 2116, 2114, 2112, 2110, 2108, 2106, 2104, 2102, 2100, 2098, 2096, 2094, 2092, 2090, 2088, 2086, 2084, 2082, 2080, 2078, 2076, 2074, 2072, 2070, 2068, 2066, 2064, 2062, 2060, 2058, 2056, 2054, 2052, 2050, 2048, 2046, 2044, 2042, 2040, 2038, 2036, 2034, 2032, 2030, 2028, 2026, 2024, 2022, 2020, 2018, 2016, 2014, 2012, 2010, 2008, 2006, 2004, 2002, 2000, 1998, 1996, 1992, 1984, 1974, 1964, 1954, 1944, 1934, 1924, 1914, 1904, 1894, 1884, 1874, 1864, 1854, 1844, 1834, 1824, 1814, 1804, 1794, 1784, 1774, 1764, 1754, 1744, 1734, 1724, 1714, 1704, 1694, 1684, 1674, 1664, 1654, 1644, 1634, 1624, 1614, 1604, 1594, 1584, 1574, 1564, 1554, 1544, 1534, 1524, 1514, 1504, 1494, 1484, 1474, 1464, 1454, 1444, 1434, 1424, 1414, 1404, 1394, 1384, 1374, 1364, 1354, 1344, 1334, 1324, 1314, 1304, 1294, 1284, 1274, 1264, 1254, 1244, 1234, 1224, 1214, 1204, 1194, 1184, 1174, 1164, 1154, 1144, 1134, 1124, 1114, 1104, 1094, 1084, 1074, 1064, 1054, 1044, 1034, 1024, 1014, 1004, 994, 984, 974, 964, 954, 944, 934, 924, 914, 904, 894, 884, 874, 864, 854, 844, 834, 824, 814, 804, 794, 784, 774, 764, 754, 744, 734, 724, 714, 704, 694, 684, 674, 664, 654, 644, 634, 624, 614, 604, 594, 584, 574, 564, 554, 544, 534, 524, 514, 504, 494, 484, 474, 464, 454, 444, 434, 424, 414, 404, 394, 384, 374, 364, 354, 344, 336, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 50,x = 15,y = 35) == [100, 104, 110, 116, 122, 128, 134, 140, 146, 152, 116, 114, 112, 110, 108, 104, 96, 86, 76, 66, 56, 46, 36, 26, 16, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 15,x = 1,y = 15) == [30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 2000,x = 1000,y = 1001) == [3998, 3996, 3994, 3992, 3990, 3988, 3986, 3984, 3982, 3980, 3978, 3976, 3974, 3972, 3970, 3968, 3966, 3964, 3962, 3960, 3958, 3956, 3954, 3952, 3950, 3948, 3946, 3944, 3942, 3940, 3938, 3936, 3934, 3932, 3930, 3928, 3926, 3924, 3922, 3920, 3918, 3916, 3914, 3912, 3910, 3908, 3906, 3904, 3902, 3900, 3898, 3896, 3894, 3892, 3890, 3888, 3886, 3884, 3882, 3880, 3878, 3876, 3874, 3872, 3870, 3868, 3866, 3864, 3862, 3860, 3858, 3856, 3854, 3852, 3850, 3848, 3846, 3844, 3842, 3840, 3838, 3836, 3834, 3832, 3830, 3828, 3826, 3824, 3822, 3820, 3818, 3816, 3814, 3812, 3810, 3808, 3806, 3804, 3802, 3800, 3798, 3796, 3794, 3792, 3790, 3788, 3786, 3784, 3782, 3780, 3778, 3776, 3774, 3772, 3770, 3768, 3766, 3764, 3762, 3760, 3758, 3756, 3754, 3752, 3750, 3748, 3746, 3744, 3742, 3740, 3738, 3736, 3734, 3732, 3730, 3728, 3726, 3724, 3722, 3720, 3718, 3716, 3714, 3712, 3710, 3708, 3706, 3704, 3702, 3700, 3698, 3696, 3694, 3692, 3690, 3688, 3686, 3684, 3682, 3680, 3678, 3676, 3674, 3672, 3670, 3668, 3666, 3664, 3662, 3660, 3658, 3656, 3654, 3652, 3650, 3648, 3646, 3644, 3642, 3640, 3638, 3636, 3634, 3632, 3630, 3628, 3626, 3624, 3622, 3620, 3618, 3616, 3614, 3612, 3610, 3608, 3606, 3604, 3602, 3600, 3598, 3596, 3594, 3592, 3590, 3588, 3586, 3584, 3582, 3580, 3578, 3576, 3574, 3572, 3570, 3568, 3566, 3564, 3562, 3560, 3558, 3556, 3554, 3552, 3550, 3548, 3546, 3544, 3542, 3540, 3538, 3536, 3534, 3532, 3530, 3528, 3526, 3524, 3522, 3520, 3518, 3516, 3514, 3512, 3510, 3508, 3506, 3504, 3502, 3500, 3498, 3496, 3494, 3492, 3490, 3488, 3486, 3484, 3482, 3480, 3478, 3476, 3474, 3472, 3470, 3468, 3466, 3464, 3462, 3460, 3458, 3456, 3454, 3452, 3450, 3448, 3446, 3444, 3442, 3440, 3438, 3436, 3434, 3432, 3430, 3428, 3426, 3424, 3422, 3420, 3418, 3416, 3414, 3412, 3410, 3408, 3406, 3404, 3402, 3400, 3398, 3396, 3394, 3392, 3390, 3388, 3386, 3384, 3382, 3380, 3378, 3376, 3374, 3372, 3370, 3368, 3366, 3364, 3362, 3360, 3358, 3356, 3354, 3352, 3350, 3348, 3346, 3344, 3342, 3340, 3338, 3336, 3334, 3332, 3330, 3328, 3326, 3324, 3322, 3320, 3318, 3316, 3314, 3312, 3310, 3308, 3306, 3304, 3302, 3300, 3298, 3296, 3294, 3292, 3290, 3288, 3286, 3284, 3282, 3280, 3278, 3276, 3274, 3272, 3270, 3268, 3266, 3264, 3262, 3260, 3258, 3256, 3254, 3252, 3250, 3248, 3246, 3244, 3242, 3240, 3238, 3236, 3234, 3232, 3230, 3228, 3226, 3224, 3222, 3220, 3218, 3216, 3214, 3212, 3210, 3208, 3206, 3204, 3202, 3200, 3198, 3196, 3194, 3192, 3190, 3188, 3186, 3184, 3182, 3180, 3178, 3176, 3174, 3172, 3170, 3168, 3166, 3164, 3162, 3160, 3158, 3156, 3154, 3152, 3150, 3148, 3146, 3144, 3142, 3140, 3138, 3136, 3134, 3132, 3130, 3128, 3126, 3124, 3122, 3120, 3118, 3116, 3114, 3112, 3110, 3108, 3106, 3104, 3102, 3100, 3098, 3096, 3094, 3092, 3090, 3088, 3086, 3084, 3082, 3080, 3078, 3076, 3074, 3072, 3070, 3068, 3066, 3064, 3062, 3060, 3058, 3056, 3054, 3052, 3050, 3048, 3046, 3044, 3042, 3040, 3038, 3036, 3034, 3032, 3030, 3028, 3026, 3024, 3022, 3020, 3018, 3016, 3014, 3012, 3010, 3008, 3006, 3004, 3002, 3000, 2998, 2996, 2994, 2992, 2990, 2988, 2986, 2984, 2982, 2980, 2978, 2976, 2974, 2972, 2970, 2968, 2966, 2964, 2962, 2960, 2958, 2956, 2954, 2952, 2950, 2948, 2946, 2944, 2942, 2940, 2938, 2936, 2934, 2932, 2930, 2928, 2926, 2924, 2922, 2920, 2918, 2916, 2914, 2912, 2910, 2908, 2906, 2904, 2902, 2900, 2898, 2896, 2894, 2892, 2890, 2888, 2886, 2884, 2882, 2880, 2878, 2876, 2874, 2872, 2870, 2868, 2866, 2864, 2862, 2860, 2858, 2856, 2854, 2852, 2850, 2848, 2846, 2844, 2842, 2840, 2838, 2836, 2834, 2832, 2830, 2828, 2826, 2824, 2822, 2820, 2818, 2816, 2814, 2812, 2810, 2808, 2806, 2804, 2802, 2800, 2798, 2796, 2794, 2792, 2790, 2788, 2786, 2784, 2782, 2780, 2778, 2776, 2774, 2772, 2770, 2768, 2766, 2764, 2762, 2760, 2758, 2756, 2754, 2752, 2750, 2748, 2746, 2744, 2742, 2740, 2738, 2736, 2734, 2732, 2730, 2728, 2726, 2724, 2722, 2720, 2718, 2716, 2714, 2712, 2710, 2708, 2706, 2704, 2702, 2700, 2698, 2696, 2694, 2692, 2690, 2688, 2686, 2684, 2682, 2680, 2678, 2676, 2674, 2672, 2670, 2668, 2666, 2664, 2662, 2660, 2658, 2656, 2654, 2652, 2650, 2648, 2646, 2644, 2642, 2640, 2638, 2636, 2634, 2632, 2630, 2628, 2626, 2624, 2622, 2620, 2618, 2616, 2614, 2612, 2610, 2608, 2606, 2604, 2602, 2600, 2598, 2596, 2594, 2592, 2590, 2588, 2586, 2584, 2582, 2580, 2578, 2576, 2574, 2572, 2570, 2568, 2566, 2564, 2562, 2560, 2558, 2556, 2554, 2552, 2550, 2548, 2546, 2544, 2542, 2540, 2538, 2536, 2534, 2532, 2530, 2528, 2526, 2524, 2522, 2520, 2518, 2516, 2514, 2512, 2510, 2508, 2506, 2504, 2502, 2500, 2498, 2496, 2494, 2492, 2490, 2488, 2486, 2484, 2482, 2480, 2478, 2476, 2474, 2472, 2470, 2468, 2466, 2464, 2462, 2460, 2458, 2456, 2454, 2452, 2450, 2448, 2446, 2444, 2442, 2440, 2438, 2436, 2434, 2432, 2430, 2428, 2426, 2424, 2422, 2420, 2418, 2416, 2414, 2412, 2410, 2408, 2406, 2404, 2402, 2400, 2398, 2396, 2394, 2392, 2390, 2388, 2386, 2384, 2382, 2380, 2378, 2376, 2374, 2372, 2370, 2368, 2366, 2364, 2362, 2360, 2358, 2356, 2354, 2352, 2350, 2348, 2346, 2344, 2342, 2340, 2338, 2336, 2334, 2332, 2330, 2328, 2326, 2324, 2322, 2320, 2318, 2316, 2314, 2312, 2310, 2308, 2306, 2304, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288, 2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268, 2266, 2264, 2262, 2260, 2258, 2256, 2254, 2252, 2250, 2248, 2246, 2244, 2242, 2240, 2238, 2236, 2234, 2232, 2230, 2228, 2226, 2224, 2222, 2220, 2218, 2216, 2214, 2212, 2210, 2208, 2206, 2204, 2202, 2200, 2198, 2196, 2194, 2192, 2190, 2188, 2186, 2184, 2182, 2180, 2178, 2176, 2174, 2172, 2170, 2168, 2166, 2164, 2162, 2160, 2158, 2156, 2154, 2152, 2150, 2148, 2146, 2144, 2142, 2140, 2138, 2136, 2134, 2132, 2130, 2128, 2126, 2124, 2122, 2120, 2118, 2116, 2114, 2112, 2110, 2108, 2106, 2104, 2102, 2100, 2098, 2096, 2094, 2092, 2090, 2088, 2086, 2084, 2082, 2080, 2078, 2076, 2074, 2072, 2070, 2068, 2066, 2064, 2062, 2060, 2058, 2056, 2054, 2052, 2050, 2048, 2046, 2044, 2042, 2040, 2038, 2036, 2034, 2032, 2030, 2028, 2026, 2024, 2022, 2020, 2018, 2016, 2014, 2012, 2010, 2008, 2006, 2004, 2002, 2000, 1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982, 1980, 1978, 1976, 1974, 1972, 1970, 1968, 1966, 1964, 1962, 1960, 1958, 1956, 1954, 1952, 1950, 1948, 1946, 1944, 1942, 1940, 1938, 1936, 1934, 1932, 1930, 1928, 1926, 1924, 1922, 1920, 1918, 1916, 1914, 1912, 1910, 1908, 1906, 1904, 1902, 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 1884, 1882, 1880, 1878, 1876, 1874, 1872, 1870, 1868, 1866, 1864, 1862, 1860, 1858, 1856, 1854, 1852, 1850, 1848, 1846, 1844, 1842, 1840, 1838, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778, 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746, 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1720, 1718, 1716, 1714, 1712, 1710, 1708, 1706, 1704, 1702, 1700, 1698, 1696, 1694, 1692, 1690, 1688, 1686, 1684, 1682, 1680, 1678, 1676, 1674, 1672, 1670, 1668, 1666, 1664, 1662, 1660, 1658, 1656, 1654, 1652, 1650, 1648, 1646, 1644, 1642, 1640, 1638, 1636, 1634, 1632, 1630, 1628, 1626, 1624, 1622, 1620, 1618, 1616, 1614, 1612, 1610, 1608, 1606, 1604, 1602, 1600, 1598, 1596, 1594, 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 1512, 1510, 1508, 1506, 1504, 1502, 1500, 1498, 1496, 1494, 1492, 1490, 1488, 1486, 1484, 1482, 1480, 1478, 1476, 1474, 1472, 1470, 1468, 1466, 1464, 1462, 1460, 1458, 1456, 1454, 1452, 1450, 1448, 1446, 1444, 1442, 1440, 1438, 1436, 1434, 1432, 1430, 1428, 1426, 1424, 1422, 1420, 1418, 1416, 1414, 1412, 1410, 1408, 1406, 1404, 1402, 1400, 1398, 1396, 1394, 1392, 1390, 1388, 1386, 1384, 1382, 1380, 1378, 1376, 1374, 1372, 1370, 1368, 1366, 1364, 1362, 1360, 1358, 1356, 1354, 1352, 1350, 1348, 1346, 1344, 1342, 1340, 1338, 1336, 1334, 1332, 1330, 1328, 1326, 1324, 1322, 1320, 1318, 1316, 1314, 1312, 1310, 1308, 1306, 1304, 1302, 1300, 1298, 1296, 1294, 1292, 1290, 1288, 1286, 1284, 1282, 1280, 1278, 1276, 1274, 1272, 1270, 1268, 1266, 1264, 1262, 1260, 1258, 1256, 1254, 1252, 1250, 1248, 1246, 1244, 1242, 1240, 1238, 1236, 1234, 1232, 1230, 1228, 1226, 1224, 1222, 1220, 1218, 1216, 1214, 1212, 1210, 1208, 1206, 1204, 1202, 1200, 1198, 1196, 1194, 1192, 1190, 1188, 1186, 1184, 1182, 1180, 1178, 1176, 1174, 1172, 1170, 1168, 1166, 1164, 1162, 1160, 1158, 1156, 1154, 1152, 1150, 1148, 1146, 1144, 1142, 1140, 1138, 1136, 1134, 1132, 1130, 1128, 1126, 1124, 1122, 1120, 1118, 1116, 1114, 1112, 1110, 1108, 1106, 1104, 1102, 1100, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 998, 996, 994, 992, 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, 830, 828, 826, 824, 822, 820, 818, 816, 814, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762, 760, 758, 756, 754, 752, 750, 748, 746, 744, 742, 740, 738, 736, 734, 732, 730, 728, 726, 724, 722, 720, 718, 716, 714, 712, 710, 708, 706, 704, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n assert candidate(n = 5000,x = 2500,y = 3000) == [10000, 10004, 10010, 10016, 10022, 10028, 10034, 10040, 10046, 10052, 10058, 10064, 10070, 10076, 10082, 10088, 10094, 10100, 10106, 10112, 10118, 10124, 10130, 10136, 10142, 10148, 10154, 10160, 10166, 10172, 10178, 10184, 10190, 10196, 10202, 10208, 10214, 10220, 10226, 10232, 10238, 10244, 10250, 10256, 10262, 10268, 10274, 10280, 10286, 10292, 10298, 10304, 10310, 10316, 10322, 10328, 10334, 10340, 10346, 10352, 10358, 10364, 10370, 10376, 10382, 10388, 10394, 10400, 10406, 10412, 10418, 10424, 10430, 10436, 10442, 10448, 10454, 10460, 10466, 10472, 10478, 10484, 10490, 10496, 10502, 10508, 10514, 10520, 10526, 10532, 10538, 10544, 10550, 10556, 10562, 10568, 10574, 10580, 10586, 10592, 10598, 10604, 10610, 10616, 10622, 10628, 10634, 10640, 10646, 10652, 10658, 10664, 10670, 10676, 10682, 10688, 10694, 10700, 10706, 10712, 10718, 10724, 10730, 10736, 10742, 10748, 10754, 10760, 10766, 10772, 10778, 10784, 10790, 10796, 10802, 10808, 10814, 10820, 10826, 10832, 10838, 10844, 10850, 10856, 10862, 10868, 10874, 10880, 10886, 10892, 10898, 10904, 10910, 10916, 10922, 10928, 10934, 10940, 10946, 10952, 10958, 10964, 10970, 10976, 10982, 10988, 10994, 11000, 11006, 11012, 11018, 11024, 11030, 11036, 11042, 11048, 11054, 11060, 11066, 11072, 11078, 11084, 11090, 11096, 11102, 11108, 11114, 11120, 11126, 11132, 11138, 11144, 11150, 11156, 11162, 11168, 11174, 11180, 11186, 11192, 11198, 11204, 11210, 11216, 11222, 11228, 11234, 11240, 11246, 11252, 11258, 11264, 11270, 11276, 11282, 11288, 11294, 11300, 11306, 11312, 11318, 11324, 11330, 11336, 11342, 11348, 11354, 11360, 11366, 11372, 11378, 11384, 11390, 11396, 11402, 11408, 11414, 11420, 11426, 11432, 11438, 11444, 11450, 11456, 11462, 11468, 11474, 11480, 11486, 11492, 10496, 10494, 10492, 10490, 10488, 10486, 10484, 10482, 10480, 10478, 10476, 10474, 10472, 10470, 10468, 10466, 10464, 10462, 10460, 10458, 10456, 10454, 10452, 10450, 10448, 10446, 10444, 10442, 10440, 10438, 10436, 10434, 10432, 10430, 10428, 10426, 10424, 10422, 10420, 10418, 10416, 10414, 10412, 10410, 10408, 10406, 10404, 10402, 10400, 10398, 10396, 10394, 10392, 10390, 10388, 10386, 10384, 10382, 10380, 10378, 10376, 10374, 10372, 10370, 10368, 10366, 10364, 10362, 10360, 10358, 10356, 10354, 10352, 10350, 10348, 10346, 10344, 10342, 10340, 10338, 10336, 10334, 10332, 10330, 10328, 10326, 10324, 10322, 10320, 10318, 10316, 10314, 10312, 10310, 10308, 10306, 10304, 10302, 10300, 10298, 10296, 10294, 10292, 10290, 10288, 10286, 10284, 10282, 10280, 10278, 10276, 10274, 10272, 10270, 10268, 10266, 10264, 10262, 10260, 10258, 10256, 10254, 10252, 10250, 10248, 10246, 10244, 10242, 10240, 10238, 10236, 10234, 10232, 10230, 10228, 10226, 10224, 10222, 10220, 10218, 10216, 10214, 10212, 10210, 10208, 10206, 10204, 10202, 10200, 10198, 10196, 10194, 10192, 10190, 10188, 10186, 10184, 10182, 10180, 10178, 10176, 10174, 10172, 10170, 10168, 10166, 10164, 10162, 10160, 10158, 10156, 10154, 10152, 10150, 10148, 10146, 10144, 10142, 10140, 10138, 10136, 10134, 10132, 10130, 10128, 10126, 10124, 10122, 10120, 10118, 10116, 10114, 10112, 10110, 10108, 10106, 10104, 10102, 10100, 10098, 10096, 10094, 10092, 10090, 10088, 10086, 10084, 10082, 10080, 10078, 10076, 10074, 10072, 10070, 10068, 10066, 10064, 10062, 10060, 10058, 10056, 10054, 10052, 10050, 10048, 10046, 10044, 10042, 10040, 10038, 10036, 10034, 10032, 10030, 10028, 10026, 10024, 10022, 10020, 10018, 10016, 10014, 10012, 10010, 10008, 10006, 10004, 10002, 10000, 9998, 9996, 9994, 9992, 9990, 9988, 9986, 9984, 9982, 9980, 9978, 9976, 9974, 9972, 9970, 9968, 9966, 9964, 9962, 9960, 9958, 9956, 9954, 9952, 9950, 9948, 9946, 9944, 9942, 9940, 9938, 9936, 9934, 9932, 9930, 9928, 9926, 9924, 9922, 9920, 9918, 9916, 9914, 9912, 9910, 9908, 9906, 9904, 9902, 9900, 9898, 9896, 9894, 9892, 9890, 9888, 9886, 9884, 9882, 9880, 9878, 9876, 9874, 9872, 9870, 9868, 9866, 9864, 9862, 9860, 9858, 9856, 9854, 9852, 9850, 9848, 9846, 9844, 9842, 9840, 9838, 9836, 9834, 9832, 9830, 9828, 9826, 9824, 9822, 9820, 9818, 9816, 9814, 9812, 9810, 9808, 9806, 9804, 9802, 9800, 9798, 9796, 9794, 9792, 9790, 9788, 9786, 9784, 9782, 9780, 9778, 9776, 9774, 9772, 9770, 9768, 9766, 9764, 9762, 9760, 9758, 9756, 9754, 9752, 9750, 9748, 9746, 9744, 9742, 9740, 9738, 9736, 9734, 9732, 9730, 9728, 9726, 9724, 9722, 9720, 9718, 9716, 9714, 9712, 9710, 9708, 9706, 9704, 9702, 9700, 9698, 9696, 9694, 9692, 9690, 9688, 9686, 9684, 9682, 9680, 9678, 9676, 9674, 9672, 9670, 9668, 9666, 9664, 9662, 9660, 9658, 9656, 9654, 9652, 9650, 9648, 9646, 9644, 9642, 9640, 9638, 9636, 9634, 9632, 9630, 9628, 9626, 9624, 9622, 9620, 9618, 9616, 9614, 9612, 9610, 9608, 9606, 9604, 9602, 9600, 9598, 9596, 9594, 9592, 9590, 9588, 9586, 9584, 9582, 9580, 9578, 9576, 9574, 9572, 9570, 9568, 9566, 9564, 9562, 9560, 9558, 9556, 9554, 9552, 9550, 9548, 9546, 9544, 9542, 9540, 9538, 9536, 9534, 9532, 9530, 9528, 9526, 9524, 9522, 9520, 9518, 9516, 9514, 9512, 9510, 9508, 9506, 9504, 9502, 9500, 9498, 9496, 9494, 9492, 9490, 9488, 9486, 9484, 9482, 9480, 9478, 9476, 9474, 9472, 9470, 9468, 9466, 9464, 9462, 9460, 9458, 9456, 9454, 9452, 9450, 9448, 9446, 9444, 9442, 9440, 9438, 9436, 9434, 9432, 9430, 9428, 9426, 9424, 9422, 9420, 9418, 9416, 9414, 9412, 9410, 9408, 9406, 9404, 9402, 9400, 9398, 9396, 9394, 9392, 9390, 9388, 9386, 9384, 9382, 9380, 9378, 9376, 9374, 9372, 9370, 9368, 9366, 9364, 9362, 9360, 9358, 9356, 9354, 9352, 9350, 9348, 9346, 9344, 9342, 9340, 9338, 9336, 9334, 9332, 9330, 9328, 9326, 9324, 9322, 9320, 9318, 9316, 9314, 9312, 9310, 9308, 9306, 9304, 9302, 9300, 9298, 9296, 9294, 9292, 9290, 9288, 9286, 9284, 9282, 9280, 9278, 9276, 9274, 9272, 9270, 9268, 9266, 9264, 9262, 9260, 9258, 9256, 9254, 9252, 9250, 9248, 9246, 9244, 9242, 9240, 9238, 9236, 9234, 9232, 9230, 9228, 9226, 9224, 9222, 9220, 9218, 9216, 9214, 9212, 9210, 9208, 9206, 9204, 9202, 9200, 9198, 9196, 9194, 9192, 9190, 9188, 9186, 9184, 9182, 9180, 9178, 9176, 9174, 9172, 9170, 9168, 9166, 9164, 9162, 9160, 9158, 9156, 9154, 9152, 9150, 9148, 9146, 9144, 9142, 9140, 9138, 9136, 9134, 9132, 9130, 9128, 9126, 9124, 9122, 9120, 9118, 9116, 9114, 9112, 9110, 9108, 9106, 9104, 9102, 9100, 9098, 9096, 9094, 9092, 9090, 9088, 9086, 9084, 9082, 9080, 9078, 9076, 9074, 9072, 9070, 9068, 9066, 9064, 9062, 9060, 9058, 9056, 9054, 9052, 9050, 9048, 9046, 9044, 9042, 9040, 9038, 9036, 9034, 9032, 9030, 9028, 9026, 9024, 9022, 9020, 9018, 9016, 9014, 9012, 9010, 9008, 9006, 9004, 9002, 9000, 8998, 8996, 8994, 8992, 8990, 8988, 8986, 8984, 8982, 8980, 8978, 8976, 8974, 8972, 8970, 8968, 8966, 8964, 8962, 8960, 8958, 8956, 8954, 8952, 8950, 8948, 8946, 8944, 8942, 8940, 8938, 8936, 8934, 8932, 8930, 8928, 8926, 8924, 8922, 8920, 8918, 8916, 8914, 8912, 8910, 8908, 8906, 8904, 8902, 8900, 8898, 8896, 8894, 8892, 8890, 8888, 8886, 8884, 8882, 8880, 8878, 8876, 8874, 8872, 8870, 8868, 8866, 8864, 8862, 8860, 8858, 8856, 8854, 8852, 8850, 8848, 8846, 8844, 8842, 8840, 8838, 8836, 8834, 8832, 8830, 8828, 8826, 8824, 8822, 8820, 8818, 8816, 8814, 8812, 8810, 8808, 8806, 8804, 8802, 8800, 8798, 8796, 8794, 8792, 8790, 8788, 8786, 8784, 8782, 8780, 8778, 8776, 8774, 8772, 8770, 8768, 8766, 8764, 8762, 8760, 8758, 8756, 8754, 8752, 8750, 8748, 8746, 8744, 8742, 8740, 8738, 8736, 8734, 8732, 8730, 8728, 8726, 8724, 8722, 8720, 8718, 8716, 8714, 8712, 8710, 8708, 8706, 8704, 8702, 8700, 8698, 8696, 8694, 8692, 8690, 8688, 8686, 8684, 8682, 8680, 8678, 8676, 8674, 8672, 8670, 8668, 8666, 8664, 8662, 8660, 8658, 8656, 8654, 8652, 8650, 8648, 8646, 8644, 8642, 8640, 8638, 8636, 8634, 8632, 8630, 8628, 8626, 8624, 8622, 8620, 8618, 8616, 8614, 8612, 8610, 8608, 8606, 8604, 8602, 8600, 8598, 8596, 8594, 8592, 8590, 8588, 8586, 8584, 8582, 8580, 8578, 8576, 8574, 8572, 8570, 8568, 8566, 8564, 8562, 8560, 8558, 8556, 8554, 8552, 8550, 8548, 8546, 8544, 8542, 8540, 8538, 8536, 8534, 8532, 8530, 8528, 8526, 8524, 8522, 8520, 8518, 8516, 8514, 8512, 8510, 8508, 8506, 8504, 8502, 8500, 8498, 8496, 8494, 8492, 8490, 8488, 8486, 8484, 8482, 8480, 8478, 8476, 8474, 8472, 8470, 8468, 8466, 8464, 8462, 8460, 8458, 8456, 8454, 8452, 8450, 8448, 8446, 8444, 8442, 8440, 8438, 8436, 8434, 8432, 8430, 8428, 8426, 8424, 8422, 8420, 8418, 8416, 8414, 8412, 8410, 8408, 8406, 8404, 8402, 8400, 8398, 8396, 8394, 8392, 8390, 8388, 8386, 8384, 8382, 8380, 8378, 8376, 8374, 8372, 8370, 8368, 8366, 8364, 8362, 8360, 8358, 8356, 8354, 8352, 8350, 8348, 8346, 8344, 8342, 8340, 8338, 8336, 8334, 8332, 8330, 8328, 8326, 8324, 8322, 8320, 8318, 8316, 8314, 8312, 8310, 8308, 8306, 8304, 8302, 8300, 8298, 8296, 8294, 8292, 8290, 8288, 8286, 8284, 8282, 8280, 8278, 8276, 8274, 8272, 8270, 8268, 8266, 8264, 8262, 8260, 8258, 8256, 8254, 8252, 8250, 8248, 8246, 8244, 8242, 8240, 8238, 8236, 8234, 8232, 8230, 8228, 8226, 8224, 8222, 8220, 8218, 8216, 8214, 8212, 8210, 8208, 8206, 8204, 8202, 8200, 8198, 8196, 8194, 8192, 8190, 8188, 8186, 8184, 8182, 8180, 8178, 8176, 8174, 8172, 8170, 8168, 8166, 8164, 8162, 8160, 8158, 8156, 8154, 8152, 8150, 8148, 8146, 8144, 8142, 8140, 8138, 8136, 8134, 8132, 8130, 8128, 8126, 8124, 8122, 8120, 8118, 8116, 8114, 8112, 8110, 8108, 8106, 8104, 8102, 8100, 8098, 8096, 8094, 8092, 8090, 8088, 8086, 8084, 8082, 8080, 8078, 8076, 8074, 8072, 8070, 8068, 8066, 8064, 8062, 8060, 8058, 8056, 8054, 8052, 8050, 8048, 8046, 8044, 8042, 8040, 8038, 8036, 8034, 8032, 8030, 8028, 8026, 8024, 8022, 8020, 8018, 8016, 8014, 8012, 8010, 8008, 8006, 8004, 8002, 8000, 7998, 7996, 7994, 7992, 7990, 7988, 7986, 7984, 7982, 7980, 7978, 7976, 7974, 7972, 7970, 7968, 7966, 7964, 7962, 7960, 7958, 7956, 7954, 7952, 7950, 7948, 7946, 7944, 7942, 7940, 7938, 7936, 7934, 7932, 7930, 7928, 7926, 7924, 7922, 7920, 7918, 7916, 7914, 7912, 7910, 7908, 7906, 7904, 7902, 7900, 7898, 7896, 7894, 7892, 7890, 7888, 7886, 7884, 7882, 7880, 7878, 7876, 7874, 7872, 7870, 7868, 7866, 7864, 7862, 7860, 7858, 7856, 7854, 7852, 7850, 7848, 7846, 7844, 7842, 7840, 7838, 7836, 7834, 7832, 7830, 7828, 7826, 7824, 7822, 7820, 7818, 7816, 7814, 7812, 7810, 7808, 7806, 7804, 7802, 7800, 7798, 7796, 7794, 7792, 7790, 7788, 7786, 7784, 7782, 7780, 7778, 7776, 7774, 7772, 7770, 7768, 7766, 7764, 7762, 7760, 7758, 7756, 7754, 7752, 7750, 7748, 7746, 7744, 7742, 7740, 7738, 7736, 7734, 7732, 7730, 7728, 7726, 7724, 7722, 7720, 7718, 7716, 7714, 7712, 7710, 7708, 7706, 7704, 7702, 7700, 7698, 7696, 7694, 7692, 7690, 7688, 7686, 7684, 7682, 7680, 7678, 7676, 7674, 7672, 7670, 7668, 7666, 7664, 7662, 7660, 7658, 7656, 7654, 7652, 7650, 7648, 7646, 7644, 7642, 7640, 7638, 7636, 7634, 7632, 7630, 7628, 7626, 7624, 7622, 7620, 7618, 7616, 7614, 7612, 7610, 7608, 7606, 7604, 7602, 7600, 7598, 7596, 7594, 7592, 7590, 7588, 7586, 7584, 7582, 7580, 7578, 7576, 7574, 7572, 7570, 7568, 7566, 7564, 7562, 7560, 7558, 7556, 7554, 7552, 7550, 7548, 7546, 7544, 7542, 7540, 7538, 7536, 7534, 7532, 7530, 7528, 7526, 7524, 7522, 7520, 7518, 7516, 7514, 7512, 7510, 7508, 7506, 7504, 7502, 7500, 7498, 7496, 7494, 7492, 7490, 7488, 7486, 7484, 7482, 7480, 7478, 7476, 7474, 7472, 7470, 7468, 7466, 7464, 7462, 7460, 7458, 7456, 7454, 7452, 7450, 7448, 7446, 7444, 7442, 7440, 7438, 7436, 7434, 7432, 7430, 7428, 7426, 7424, 7422, 7420, 7418, 7416, 7414, 7412, 7410, 7408, 7406, 7404, 7402, 7400, 7398, 7396, 7394, 7392, 7390, 7388, 7386, 7384, 7382, 7380, 7378, 7376, 7374, 7372, 7370, 7368, 7366, 7364, 7362, 7360, 7358, 7356, 7354, 7352, 7350, 7348, 7346, 7344, 7342, 7340, 7338, 7336, 7334, 7332, 7330, 7328, 7326, 7324, 7322, 7320, 7318, 7316, 7314, 7312, 7310, 7308, 7306, 7304, 7302, 7300, 7298, 7296, 7294, 7292, 7290, 7288, 7286, 7284, 7282, 7280, 7278, 7276, 7274, 7272, 7270, 7268, 7266, 7264, 7262, 7260, 7258, 7256, 7254, 7252, 7250, 7248, 7246, 7244, 7242, 7240, 7238, 7236, 7234, 7232, 7230, 7228, 7226, 7224, 7222, 7220, 7218, 7216, 7214, 7212, 7210, 7208, 7206, 7204, 7202, 7200, 7198, 7196, 7194, 7192, 7190, 7188, 7186, 7184, 7182, 7180, 7178, 7176, 7174, 7172, 7170, 7168, 7166, 7164, 7162, 7160, 7158, 7156, 7154, 7152, 7150, 7148, 7146, 7144, 7142, 7140, 7138, 7136, 7134, 7132, 7130, 7128, 7126, 7124, 7122, 7120, 7118, 7116, 7114, 7112, 7110, 7108, 7106, 7104, 7102, 7100, 7098, 7096, 7094, 7092, 7090, 7088, 7086, 7084, 7082, 7080, 7078, 7076, 7074, 7072, 7070, 7068, 7066, 7064, 7062, 7060, 7058, 7056, 7054, 7052, 7050, 7048, 7046, 7044, 7042, 7040, 7038, 7036, 7034, 7032, 7030, 7028, 7026, 7024, 7022, 7020, 7018, 7016, 7014, 7012, 7010, 7008, 7006, 7004, 7002, 7000, 6998, 6996, 6992, 6986, 6980, 6974, 6968, 6962, 6956, 6950, 6944, 6938, 6932, 6926, 6920, 6914, 6908, 6902, 6896, 6890, 6884, 6878, 6872, 6866, 6860, 6854, 6848, 6842, 6836, 6830, 6824, 6818, 6812, 6806, 6800, 6794, 6788, 6782, 6776, 6770, 6764, 6758, 6752, 6746, 6740, 6734, 6728, 6722, 6716, 6710, 6704, 6698, 6692, 6686, 6680, 6674, 6668, 6662, 6656, 6650, 6644, 6638, 6632, 6626, 6620, 6614, 6608, 6602, 6596, 6590, 6584, 6578, 6572, 6566, 6560, 6554, 6548, 6542, 6536, 6530, 6524, 6518, 6512, 6506, 6500, 6494, 6488, 6482, 6476, 6470, 6464, 6458, 6452, 6446, 6440, 6434, 6428, 6422, 6416, 6410, 6404, 6398, 6392, 6386, 6380, 6374, 6368, 6362, 6356, 6350, 6344, 6338, 6332, 6326, 6320, 6314, 6308, 6302, 6296, 6290, 6284, 6278, 6272, 6266, 6260, 6254, 6248, 6242, 6236, 6230, 6224, 6218, 6212, 6206, 6200, 6194, 6188, 6182, 6176, 6170, 6164, 6158, 6152, 6146, 6140, 6134, 6128, 6122, 6116, 6110, 6104, 6098, 6092, 6086, 6080, 6074, 6068, 6062, 6056, 6050, 6044, 6038, 6032, 6026, 6020, 6014, 6008, 6002, 5996, 5990, 5984, 5978, 5972, 5966, 5960, 5954, 5948, 5942, 5936, 5930, 5924, 5918, 5912, 5906, 5900, 5894, 5888, 5882, 5876, 5870, 5864, 5858, 5852, 5846, 5840, 5834, 5828, 5822, 5816, 5810, 5804, 5798, 5792, 5786, 5780, 5774, 5768, 5762, 5756, 5750, 5744, 5738, 5732, 5726, 5720, 5714, 5708, 5702, 5696, 5690, 5684, 5678, 5672, 5666, 5660, 5654, 5648, 5642, 5636, 5630, 5624, 5618, 5612, 5606, 5600, 5594, 5588, 5582, 5576, 5570, 5564, 5558, 5552, 5546, 5540, 5534, 5528, 5522, 5516, 5510, 5504, 5498, 5496, 5494, 5492, 5490, 5488, 5486, 5484, 5482, 5480, 5478, 5476, 5474, 5472, 5470, 5468, 5466, 5464, 5462, 5460, 5458, 5456, 5454, 5452, 5450, 5448, 5446, 5444, 5442, 5440, 5438, 5436, 5434, 5432, 5430, 5428, 5426, 5424, 5422, 5420, 5418, 5416, 5414, 5412, 5410, 5408, 5406, 5404, 5402, 5400, 5398, 5396, 5394, 5392, 5390, 5388, 5386, 5384, 5382, 5380, 5378, 5376, 5374, 5372, 5370, 5368, 5366, 5364, 5362, 5360, 5358, 5356, 5354, 5352, 5350, 5348, 5346, 5344, 5342, 5340, 5338, 5336, 5334, 5332, 5330, 5328, 5326, 5324, 5322, 5320, 5318, 5316, 5314, 5312, 5310, 5308, 5306, 5304, 5302, 5300, 5298, 5296, 5294, 5292, 5290, 5288, 5286, 5284, 5282, 5280, 5278, 5276, 5274, 5272, 5270, 5268, 5266, 5264, 5262, 5260, 5258, 5256, 5254, 5252, 5250, 5248, 5246, 5244, 5242, 5240, 5238, 5236, 5234, 5232, 5230, 5228, 5226, 5224, 5222, 5220, 5218, 5216, 5214, 5212, 5210, 5208, 5206, 5204, 5202, 5200, 5198, 5196, 5194, 5192, 5190, 5188, 5186, 5184, 5182, 5180, 5178, 5176, 5174, 5172, 5170, 5168, 5166, 5164, 5162, 5160, 5158, 5156, 5154, 5152, 5150, 5148, 5146, 5144, 5142, 5140, 5138, 5136, 5134, 5132, 5130, 5128, 5126, 5124, 5122, 5120, 5118, 5116, 5114, 5112, 5110, 5108, 5106, 5104, 5102, 5100, 5098, 5096, 5094, 5092, 5090, 5088, 5086, 5084, 5082, 5080, 5078, 5076, 5074, 5072, 5070, 5068, 5066, 5064, 5062, 5060, 5058, 5056, 5054, 5052, 5050, 5048, 5046, 5044, 5042, 5040, 5038, 5036, 5034, 5032, 5030, 5028, 5026, 5024, 5022, 5020, 5018, 5016, 5014, 5012, 5010, 5008, 5006, 5004, 5002, 5000, 4996, 4990, 4984, 4978, 4972, 4966, 4960, 4954, 4948, 4942, 4936, 4930, 4924, 4918, 4912, 4906, 4900, 4894, 4888, 4882, 4876, 4870, 4864, 4858, 4852, 4846, 4840, 4834, 4828, 4822, 4816, 4810, 4804, 4798, 4792, 4786, 4780, 4774, 4768, 4762, 4756, 4750, 4744, 4738, 4732, 4726, 4720, 4714, 4708, 4702, 4696, 4690, 4684, 4678, 4672, 4666, 4660, 4654, 4648, 4642, 4636, 4630, 4624, 4618, 4612, 4606, 4600, 4594, 4588, 4582, 4576, 4570, 4564, 4558, 4552, 4546, 4540, 4534, 4528, 4522, 4516, 4510, 4504, 4498, 4492, 4486, 4480, 4474, 4468, 4462, 4456, 4450, 4444, 4438, 4432, 4426, 4420, 4414, 4408, 4402, 4396, 4390, 4384, 4378, 4372, 4366, 4360, 4354, 4348, 4342, 4336, 4330, 4324, 4318, 4312, 4306, 4300, 4294, 4288, 4282, 4276, 4270, 4264, 4258, 4252, 4246, 4240, 4234, 4228, 4222, 4216, 4210, 4204, 4198, 4192, 4186, 4180, 4174, 4168, 4162, 4156, 4150, 4144, 4138, 4132, 4126, 4120, 4114, 4108, 4102, 4096, 4090, 4084, 4078, 4072, 4066, 4060, 4054, 4048, 4042, 4036, 4030, 4024, 4018, 4012, 4006, 4000, 3994, 3988, 3982, 3976, 3970, 3964, 3958, 3952, 3946, 3940, 3934, 3928, 3922, 3916, 3910, 3904, 3898, 3892, 3886, 3880, 3874, 3868, 3862, 3856, 3850, 3844, 3838, 3832, 3826, 3820, 3814, 3808, 3802, 3796, 3790, 3784, 3778, 3772, 3766, 3760, 3754, 3748, 3742, 3736, 3730, 3724, 3718, 3712, 3706, 3700, 3694, 3688, 3682, 3676, 3670, 3664, 3658, 3652, 3646, 3640, 3634, 3628, 3622, 3616, 3610, 3604, 3598, 3592, 3586, 3580, 3574, 3568, 3562, 3556, 3550, 3544, 3538, 3532, 3526, 3520, 3514, 3508, 3502, 3500, 3498, 3496, 3494, 3492, 3490, 3488, 3486, 3484, 3482, 3480, 3478, 3476, 3474, 3472, 3470, 3468, 3466, 3464, 3462, 3460, 3458, 3456, 3454, 3452, 3450, 3448, 3446, 3444, 3442, 3440, 3438, 3436, 3434, 3432, 3430, 3428, 3426, 3424, 3422, 3420, 3418, 3416, 3414, 3412, 3410, 3408, 3406, 3404, 3402, 3400, 3398, 3396, 3394, 3392, 3390, 3388, 3386, 3384, 3382, 3380, 3378, 3376, 3374, 3372, 3370, 3368, 3366, 3364, 3362, 3360, 3358, 3356, 3354, 3352, 3350, 3348, 3346, 3344, 3342, 3340, 3338, 3336, 3334, 3332, 3330, 3328, 3326, 3324, 3322, 3320, 3318, 3316, 3314, 3312, 3310, 3308, 3306, 3304, 3302, 3300, 3298, 3296, 3294, 3292, 3290, 3288, 3286, 3284, 3282, 3280, 3278, 3276, 3274, 3272, 3270, 3268, 3266, 3264, 3262, 3260, 3258, 3256, 3254, 3252, 3250, 3248, 3246, 3244, 3242, 3240, 3238, 3236, 3234, 3232, 3230, 3228, 3226, 3224, 3222, 3220, 3218, 3216, 3214, 3212, 3210, 3208, 3206, 3204, 3202, 3200, 3198, 3196, 3194, 3192, 3190, 3188, 3186, 3184, 3182, 3180, 3178, 3176, 3174, 3172, 3170, 3168, 3166, 3164, 3162, 3160, 3158, 3156, 3154, 3152, 3150, 3148, 3146, 3144, 3142, 3140, 3138, 3136, 3134, 3132, 3130, 3128, 3126, 3124, 3122, 3120, 3118, 3116, 3114, 3112, 3110, 3108, 3106, 3104, 3102, 3100, 3098, 3096, 3094, 3092, 3090, 3088, 3086, 3084, 3082, 3080, 3078, 3076, 3074, 3072, 3070, 3068, 3066, 3064, 3062, 3060, 3058, 3056, 3054, 3052, 3050, 3048, 3046, 3044, 3042, 3040, 3038, 3036, 3034, 3032, 3030, 3028, 3026, 3024, 3022, 3020, 3018, 3016, 3014, 3012, 3010, 3008, 3006, 3004, 3002, 3000, 2998, 2996, 2994, 2992, 2990, 2988, 2986, 2984, 2982, 2980, 2978, 2976, 2974, 2972, 2970, 2968, 2966, 2964, 2962, 2960, 2958, 2956, 2954, 2952, 2950, 2948, 2946, 2944, 2942, 2940, 2938, 2936, 2934, 2932, 2930, 2928, 2926, 2924, 2922, 2920, 2918, 2916, 2914, 2912, 2910, 2908, 2906, 2904, 2902, 2900, 2898, 2896, 2894, 2892, 2890, 2888, 2886, 2884, 2882, 2880, 2878, 2876, 2874, 2872, 2870, 2868, 2866, 2864, 2862, 2860, 2858, 2856, 2854, 2852, 2850, 2848, 2846, 2844, 2842, 2840, 2838, 2836, 2834, 2832, 2830, 2828, 2826, 2824, 2822, 2820, 2818, 2816, 2814, 2812, 2810, 2808, 2806, 2804, 2802, 2800, 2798, 2796, 2794, 2792, 2790, 2788, 2786, 2784, 2782, 2780, 2778, 2776, 2774, 2772, 2770, 2768, 2766, 2764, 2762, 2760, 2758, 2756, 2754, 2752, 2750, 2748, 2746, 2744, 2742, 2740, 2738, 2736, 2734, 2732, 2730, 2728, 2726, 2724, 2722, 2720, 2718, 2716, 2714, 2712, 2710, 2708, 2706, 2704, 2702, 2700, 2698, 2696, 2694, 2692, 2690, 2688, 2686, 2684, 2682, 2680, 2678, 2676, 2674, 2672, 2670, 2668, 2666, 2664, 2662, 2660, 2658, 2656, 2654, 2652, 2650, 2648, 2646, 2644, 2642, 2640, 2638, 2636, 2634, 2632, 2630, 2628, 2626, 2624, 2622, 2620, 2618, 2616, 2614, 2612, 2610, 2608, 2606, 2604, 2602, 2600, 2598, 2596, 2594, 2592, 2590, 2588, 2586, 2584, 2582, 2580, 2578, 2576, 2574, 2572, 2570, 2568, 2566, 2564, 2562, 2560, 2558, 2556, 2554, 2552, 2550, 2548, 2546, 2544, 2542, 2540, 2538, 2536, 2534, 2532, 2530, 2528, 2526, 2524, 2522, 2520, 2518, 2516, 2514, 2512, 2510, 2508, 2506, 2504, 2502, 2500, 2498, 2496, 2494, 2492, 2490, 2488, 2486, 2484, 2482, 2480, 2478, 2476, 2474, 2472, 2470, 2468, 2466, 2464, 2462, 2460, 2458, 2456, 2454, 2452, 2450, 2448, 2446, 2444, 2442, 2440, 2438, 2436, 2434, 2432, 2430, 2428, 2426, 2424, 2422, 2420, 2418, 2416, 2414, 2412, 2410, 2408, 2406, 2404, 2402, 2400, 2398, 2396, 2394, 2392, 2390, 2388, 2386, 2384, 2382, 2380, 2378, 2376, 2374, 2372, 2370, 2368, 2366, 2364, 2362, 2360, 2358, 2356, 2354, 2352, 2350, 2348, 2346, 2344, 2342, 2340, 2338, 2336, 2334, 2332, 2330, 2328, 2326, 2324, 2322, 2320, 2318, 2316, 2314, 2312, 2310, 2308, 2306, 2304, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288, 2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268, 2266, 2264, 2262, 2260, 2258, 2256, 2254, 2252, 2250, 2248, 2246, 2244, 2242, 2240, 2238, 2236, 2234, 2232, 2230, 2228, 2226, 2224, 2222, 2220, 2218, 2216, 2214, 2212, 2210, 2208, 2206, 2204, 2202, 2200, 2198, 2196, 2194, 2192, 2190, 2188, 2186, 2184, 2182, 2180, 2178, 2176, 2174, 2172, 2170, 2168, 2166, 2164, 2162, 2160, 2158, 2156, 2154, 2152, 2150, 2148, 2146, 2144, 2142, 2140, 2138, 2136, 2134, 2132, 2130, 2128, 2126, 2124, 2122, 2120, 2118, 2116, 2114, 2112, 2110, 2108, 2106, 2104, 2102, 2100, 2098, 2096, 2094, 2092, 2090, 2088, 2086, 2084, 2082, 2080, 2078, 2076, 2074, 2072, 2070, 2068, 2066, 2064, 2062, 2060, 2058, 2056, 2054, 2052, 2050, 2048, 2046, 2044, 2042, 2040, 2038, 2036, 2034, 2032, 2030, 2028, 2026, 2024, 2022, 2020, 2018, 2016, 2014, 2012, 2010, 2008, 2006, 2004, 2002, 2000, 1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982, 1980, 1978, 1976, 1974, 1972, 1970, 1968, 1966, 1964, 1962, 1960, 1958, 1956, 1954, 1952, 1950, 1948, 1946, 1944, 1942, 1940, 1938, 1936, 1934, 1932, 1930, 1928, 1926, 1924, 1922, 1920, 1918, 1916, 1914, 1912, 1910, 1908, 1906, 1904, 1902, 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 1884, 1882, 1880, 1878, 1876, 1874, 1872, 1870, 1868, 1866, 1864, 1862, 1860, 1858, 1856, 1854, 1852, 1850, 1848, 1846, 1844, 1842, 1840, 1838, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778, 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746, 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1720, 1718, 1716, 1714, 1712, 1710, 1708, 1706, 1704, 1702, 1700, 1698, 1696, 1694, 1692, 1690, 1688, 1686, 1684, 1682, 1680, 1678, 1676, 1674, 1672, 1670, 1668, 1666, 1664, 1662, 1660, 1658, 1656, 1654, 1652, 1650, 1648, 1646, 1644, 1642, 1640, 1638, 1636, 1634, 1632, 1630, 1628, 1626, 1624, 1622, 1620, 1618, 1616, 1614, 1612, 1610, 1608, 1606, 1604, 1602, 1600, 1598, 1596, 1594, 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 1512, 1510, 1508, 1506, 1504, 1502, 1500, 1498, 1496, 1494, 1492, 1490, 1488, 1486, 1484, 1482, 1480, 1478, 1476, 1474, 1472, 1470, 1468, 1466, 1464, 1462, 1460, 1458, 1456, 1454, 1452, 1450, 1448, 1446, 1444, 1442, 1440, 1438, 1436, 1434, 1432, 1430, 1428, 1426, 1424, 1422, 1420, 1418, 1416, 1414, 1412, 1410, 1408, 1406, 1404, 1402, 1400, 1398, 1396, 1394, 1392, 1390, 1388, 1386, 1384, 1382, 1380, 1378, 1376, 1374, 1372, 1370, 1368, 1366, 1364, 1362, 1360, 1358, 1356, 1354, 1352, 1350, 1348, 1346, 1344, 1342, 1340, 1338, 1336, 1334, 1332, 1330, 1328, 1326, 1324, 1322, 1320, 1318, 1316, 1314, 1312, 1310, 1308, 1306, 1304, 1302, 1300, 1298, 1296, 1294, 1292, 1290, 1288, 1286, 1284, 1282, 1280, 1278, 1276, 1274, 1272, 1270, 1268, 1266, 1264, 1262, 1260, 1258, 1256, 1254, 1252, 1250, 1248, 1246, 1244, 1242, 1240, 1238, 1236, 1234, 1232, 1230, 1228, 1226, 1224, 1222, 1220, 1218, 1216, 1214, 1212, 1210, 1208, 1206, 1204, 1202, 1200, 1198, 1196, 1194, 1192, 1190, 1188, 1186, 1184, 1182, 1180, 1178, 1176, 1174, 1172, 1170, 1168, 1166, 1164, 1162, 1160, 1158, 1156, 1154, 1152, 1150, 1148, 1146, 1144, 1142, 1140, 1138, 1136, 1134, 1132, 1130, 1128, 1126, 1124, 1122, 1120, 1118, 1116, 1114, 1112, 1110, 1108, 1106, 1104, 1102, 1100, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 998, 996, 994, 992, 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, 830, 828, 826, 824, 822, 820, 818, 816, 814, 812, 810, 808, 806, 804, 802, 800, 798, 796, 794, 792, 790, 788, 786, 784, 782, 780, 778, 776, 774, 772, 770, 768, 766, 764, 762, 760, 758, 756, 754, 752, 750, 748, 746, 744, 742, 740, 738, 736, 734, 732, 730, 728, 726, 724, 722, 720, 718, 716, 714, 712, 710, 708, 706, 704, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 1000,x = 500,y = 750) == [2000, 2004, 2010, 2016, 2022, 2028, 2034, 2040, 2046, 2052, 2058, 2064, 2070, 2076, 2082, 2088, 2094, 2100, 2106, 2112, 2118, 2124, 2130, 2136, 2142, 2148, 2154, 2160, 2166, 2172, 2178, 2184, 2190, 2196, 2202, 2208, 2214, 2220, 2226, 2232, 2238, 2244, 2250, 2256, 2262, 2268, 2274, 2280, 2286, 2292, 2298, 2304, 2310, 2316, 2322, 2328, 2334, 2340, 2346, 2352, 2358, 2364, 2370, 2376, 2382, 2388, 2394, 2400, 2406, 2412, 2418, 2424, 2430, 2436, 2442, 2448, 2454, 2460, 2466, 2472, 2478, 2484, 2490, 2496, 2502, 2508, 2514, 2520, 2526, 2532, 2538, 2544, 2550, 2556, 2562, 2568, 2574, 2580, 2586, 2592, 2598, 2604, 2610, 2616, 2622, 2628, 2634, 2640, 2646, 2652, 2658, 2664, 2670, 2676, 2682, 2688, 2694, 2700, 2706, 2712, 2718, 2724, 2730, 2736, 2742, 2246, 2244, 2242, 2240, 2238, 2236, 2234, 2232, 2230, 2228, 2226, 2224, 2222, 2220, 2218, 2216, 2214, 2212, 2210, 2208, 2206, 2204, 2202, 2200, 2198, 2196, 2194, 2192, 2190, 2188, 2186, 2184, 2182, 2180, 2178, 2176, 2174, 2172, 2170, 2168, 2166, 2164, 2162, 2160, 2158, 2156, 2154, 2152, 2150, 2148, 2146, 2144, 2142, 2140, 2138, 2136, 2134, 2132, 2130, 2128, 2126, 2124, 2122, 2120, 2118, 2116, 2114, 2112, 2110, 2108, 2106, 2104, 2102, 2100, 2098, 2096, 2094, 2092, 2090, 2088, 2086, 2084, 2082, 2080, 2078, 2076, 2074, 2072, 2070, 2068, 2066, 2064, 2062, 2060, 2058, 2056, 2054, 2052, 2050, 2048, 2046, 2044, 2042, 2040, 2038, 2036, 2034, 2032, 2030, 2028, 2026, 2024, 2022, 2020, 2018, 2016, 2014, 2012, 2010, 2008, 2006, 2004, 2002, 2000, 1998, 1996, 1992, 1986, 1980, 1974, 1968, 1962, 1956, 1950, 1944, 1938, 1932, 1926, 1920, 1914, 1908, 1902, 1896, 1890, 1884, 1878, 1872, 1866, 1860, 1854, 1848, 1842, 1836, 1830, 1824, 1818, 1812, 1806, 1800, 1794, 1788, 1782, 1776, 1770, 1764, 1758, 1752, 1746, 1740, 1734, 1728, 1722, 1716, 1710, 1704, 1698, 1692, 1686, 1680, 1674, 1668, 1662, 1656, 1650, 1644, 1638, 1632, 1626, 1620, 1614, 1608, 1602, 1596, 1590, 1584, 1578, 1572, 1566, 1560, 1554, 1548, 1542, 1536, 1530, 1524, 1518, 1512, 1506, 1500, 1494, 1488, 1482, 1476, 1470, 1464, 1458, 1452, 1446, 1440, 1434, 1428, 1422, 1416, 1410, 1404, 1398, 1392, 1386, 1380, 1374, 1368, 1362, 1356, 1350, 1344, 1338, 1332, 1326, 1320, 1314, 1308, 1302, 1296, 1290, 1284, 1278, 1272, 1266, 1260, 1254, 1248, 1246, 1244, 1242, 1240, 1238, 1236, 1234, 1232, 1230, 1228, 1226, 1224, 1222, 1220, 1218, 1216, 1214, 1212, 1210, 1208, 1206, 1204, 1202, 1200, 1198, 1196, 1194, 1192, 1190, 1188, 1186, 1184, 1182, 1180, 1178, 1176, 1174, 1172, 1170, 1168, 1166, 1164, 1162, 1160, 1158, 1156, 1154, 1152, 1150, 1148, 1146, 1144, 1142, 1140, 1138, 1136, 1134, 1132, 1130, 1128, 1126, 1124, 1122, 1120, 1118, 1116, 1114, 1112, 1110, 1108, 1106, 1104, 1102, 1100, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 996, 990, 984, 978, 972, 966, 960, 954, 948, 942, 936, 930, 924, 918, 912, 906, 900, 894, 888, 882, 876, 870, 864, 858, 852, 846, 840, 834, 828, 822, 816, 810, 804, 798, 792, 786, 780, 774, 768, 762, 756, 750, 744, 738, 732, 726, 720, 714, 708, 702, 696, 690, 684, 678, 672, 666, 660, 654, 648, 642, 636, 630, 624, 618, 612, 606, 600, 594, 588, 582, 576, 570, 564, 558, 552, 546, 540, 534, 528, 522, 516, 510, 504, 498, 492, 486, 480, 474, 468, 462, 456, 450, 444, 438, 432, 426, 420, 414, 408, 402, 396, 390, 384, 378, 372, 366, 360, 354, 348, 342, 336, 330, 324, 318, 312, 306, 300, 294, 288, 282, 276, 270, 264, 258, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 120,x = 40,y = 80) == [240, 244, 250, 256, 262, 268, 274, 280, 286, 292, 298, 304, 310, 316, 322, 328, 334, 340, 346, 352, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 234, 226, 216, 206, 196, 186, 176, 166, 156, 146, 136, 126, 116, 106, 96, 86, 76, 66, 56, 46, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 1000,x = 500,y = 600) == [2000, 2004, 2010, 2016, 2022, 2028, 2034, 2040, 2046, 2052, 2058, 2064, 2070, 2076, 2082, 2088, 2094, 2100, 2106, 2112, 2118, 2124, 2130, 2136, 2142, 2148, 2154, 2160, 2166, 2172, 2178, 2184, 2190, 2196, 2202, 2208, 2214, 2220, 2226, 2232, 2238, 2244, 2250, 2256, 2262, 2268, 2274, 2280, 2286, 2292, 2096, 2094, 2092, 2090, 2088, 2086, 2084, 2082, 2080, 2078, 2076, 2074, 2072, 2070, 2068, 2066, 2064, 2062, 2060, 2058, 2056, 2054, 2052, 2050, 2048, 2046, 2044, 2042, 2040, 2038, 2036, 2034, 2032, 2030, 2028, 2026, 2024, 2022, 2020, 2018, 2016, 2014, 2012, 2010, 2008, 2006, 2004, 2002, 2000, 1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982, 1980, 1978, 1976, 1974, 1972, 1970, 1968, 1966, 1964, 1962, 1960, 1958, 1956, 1954, 1952, 1950, 1948, 1946, 1944, 1942, 1940, 1938, 1936, 1934, 1932, 1930, 1928, 1926, 1924, 1922, 1920, 1918, 1916, 1914, 1912, 1910, 1908, 1906, 1904, 1902, 1900, 1898, 1896, 1894, 1892, 1890, 1888, 1886, 1884, 1882, 1880, 1878, 1876, 1874, 1872, 1870, 1868, 1866, 1864, 1862, 1860, 1858, 1856, 1854, 1852, 1850, 1848, 1846, 1844, 1842, 1840, 1838, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778, 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746, 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1720, 1718, 1716, 1714, 1712, 1710, 1708, 1706, 1704, 1702, 1700, 1698, 1696, 1694, 1692, 1690, 1688, 1686, 1684, 1682, 1680, 1678, 1676, 1674, 1672, 1670, 1668, 1666, 1664, 1662, 1660, 1658, 1656, 1654, 1652, 1650, 1648, 1646, 1644, 1642, 1640, 1638, 1636, 1634, 1632, 1630, 1628, 1626, 1624, 1622, 1620, 1618, 1616, 1614, 1612, 1610, 1608, 1606, 1604, 1602, 1600, 1598, 1596, 1594, 1592, 1590, 1588, 1586, 1584, 1582, 1580, 1578, 1576, 1574, 1572, 1570, 1568, 1566, 1564, 1562, 1560, 1558, 1556, 1554, 1552, 1550, 1548, 1546, 1544, 1542, 1540, 1538, 1536, 1534, 1532, 1530, 1528, 1526, 1524, 1522, 1520, 1518, 1516, 1514, 1512, 1510, 1508, 1506, 1504, 1502, 1500, 1498, 1496, 1494, 1492, 1490, 1488, 1486, 1484, 1482, 1480, 1478, 1476, 1474, 1472, 1470, 1468, 1466, 1464, 1462, 1460, 1458, 1456, 1454, 1452, 1450, 1448, 1446, 1444, 1442, 1440, 1438, 1436, 1434, 1432, 1430, 1428, 1426, 1424, 1422, 1420, 1418, 1416, 1414, 1412, 1410, 1408, 1406, 1404, 1402, 1400, 1398, 1396, 1392, 1386, 1380, 1374, 1368, 1362, 1356, 1350, 1344, 1338, 1332, 1326, 1320, 1314, 1308, 1302, 1296, 1290, 1284, 1278, 1272, 1266, 1260, 1254, 1248, 1242, 1236, 1230, 1224, 1218, 1212, 1206, 1200, 1194, 1188, 1182, 1176, 1170, 1164, 1158, 1152, 1146, 1140, 1134, 1128, 1122, 1116, 1110, 1104, 1098, 1096, 1094, 1092, 1090, 1088, 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1068, 1066, 1064, 1062, 1060, 1058, 1056, 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 996, 990, 984, 978, 972, 966, 960, 954, 948, 942, 936, 930, 924, 918, 912, 906, 900, 894, 888, 882, 876, 870, 864, 858, 852, 846, 840, 834, 828, 822, 816, 810, 804, 798, 792, 786, 780, 774, 768, 762, 756, 750, 744, 738, 732, 726, 720, 714, 708, 702, 700, 698, 696, 694, 692, 690, 688, 686, 684, 682, 680, 678, 676, 674, 672, 670, 668, 666, 664, 662, 660, 658, 656, 654, 652, 650, 648, 646, 644, 642, 640, 638, 636, 634, 632, 630, 628, 626, 624, 622, 620, 618, 616, 614, 612, 610, 608, 606, 604, 602, 600, 598, 596, 594, 592, 590, 588, 586, 584, 582, 580, 578, 576, 574, 572, 570, 568, 566, 564, 562, 560, 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 498, 496, 494, 492, 490, 488, 486, 484, 482, 480, 478, 476, 474, 472, 470, 468, 466, 464, 462, 460, 458, 456, 454, 452, 450, 448, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380, 378, 376, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 324, 322, 320, 318, 316, 314, 312, 310, 308, 306, 304, 302, 300, 298, 296, 294, 292, 290, 288, 286, 284, 282, 280, 278, 276, 274, 272, 270, 268, 266, 264, 262, 260, 258, 256, 254, 252, 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, 146, 144, 142, 140, 138, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 200,x = 100,y = 150) == [400, 404, 410, 416, 422, 428, 434, 440, 446, 452, 458, 464, 470, 476, 482, 488, 494, 500, 506, 512, 518, 524, 530, 536, 542, 446, 444, 442, 440, 438, 436, 434, 432, 430, 428, 426, 424, 422, 420, 418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 392, 386, 380, 374, 368, 362, 356, 350, 344, 338, 332, 326, 320, 314, 308, 302, 296, 290, 284, 278, 272, 266, 260, 254, 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 196, 190, 184, 178, 172, 166, 160, 154, 148, 142, 136, 130, 124, 118, 112, 106, 100, 94, 88, 82, 76, 70, 64, 58, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 150,x = 75,y = 125) == [300, 304, 310, 316, 322, 328, 334, 340, 346, 352, 358, 364, 370, 376, 382, 388, 394, 400, 406, 412, 418, 424, 430, 436, 442, 346, 342, 336, 330, 324, 318, 312, 306, 300, 294, 288, 282, 276, 270, 264, 258, 252, 246, 240, 234, 228, 222, 216, 210, 204, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 146, 140, 134, 128, 122, 116, 110, 104, 98, 92, 86, 80, 74, 68, 62, 56, 50, 44, 38, 32, 26, 20, 14, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 60,x = 20,y = 40) == [120, 124, 130, 136, 142, 148, 154, 160, 166, 172, 136, 134, 132, 130, 128, 126, 124, 122, 120, 118, 114, 106, 96, 86, 76, 66, 56, 46, 36, 26, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 2000,x = 1,y = 2000) == [4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 100,x = 3,y = 98) == [200, 204, 210, 212, 210, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 112, 12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 12,x = 6,y = 6) == [22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]\n", "comparison": "exact"}, "public_tests": ["3\n1\n3", "5\n2\n4", "4\n1\n1"], "hints": ["If there were no additional street connecting house x to house y, there would be 2 * (n - i) pairs of houses at distance i.", "The shortest distance between house i and house j (j < i) is along one of these paths: - i -> j - i -> y---x -> j", "Try to change the distances calculated by path i ->j to the other path.", "Can we use prefix sums to compute the answer?"], "metadata": {"canonical_parameter_names": ["n", "x", "y"], "leetcode_dataset_entry_point": "Solution().countOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:28+00:00", "tests_total": 87, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["graph", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def count_of_pairs(n, x, y)", "container": null, "callable": "count_of_pairs", "parameters": [{"name": "n", "type": "Integer"}, {"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3019, "task_id": "number-of-changing-keys", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = \"ab\" has a change of a key while s = \"bBBb\" does not have any.\n\nReturn the number of times the user had to change the key.\n\nNote: Modifiers like shift or caps lock won't be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.\n\nExample 1:\n\nInput: s = \"aAbBcC\"\nOutput: 2\nExplanation:\nFrom s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.\nFrom s[1] = 'A' to s[2] = 'b', there is a change of key.\nFrom s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.\nFrom s[3] = 'B' to s[4] = 'c', there is a change of key.\nFrom s[4] = 'c' to s[5] = 'C', there is no change of key as caps lock or shift is not counted.\n\nExample 2:\n\nInput: s = \"AaAaAaaA\"\nOutput: 0\nExplanation: There is no change of key since only the letters 'a' and 'A' are pressed which does not require change of key.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists of only upper case and lower case English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"ZzZzZzZ\") == 0\n assert candidate(s = \"QwErTyUiOpAsDfGhJkLzXcVbNm\") == 25\n assert candidate(s = \"ABCDEFG\") == 6\n assert candidate(s = \"A\") == 0\n assert candidate(s = \"AaAaAaaA\") == 0\n assert candidate(s = \"zZyYxXwW\") == 3\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == 25\n assert candidate(s = \"aAbBcC\") == 2\n assert candidate(s = \"aBcDeFg\") == 6\n assert candidate(s = \"aBAcB\") == 4\n assert candidate(s = \"AbCdEfGhIjK\") == 10\n assert candidate(s = \"zzzzzzzz\") == 0\n assert candidate(s = \"aAaAaAaAaA\") == 0\n assert candidate(s = \"AAAAaaaAAA\") == 0\n assert candidate(s = \"AAaaaAA\") == 0\n assert candidate(s = \"a\") == 0\n assert candidate(s = \"abcdefg\") == 6\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == 25\n assert candidate(s = \"abcABCdefDEFghiGHIjklJKLmnoMNOpqrPQRstuSTUvwxVWXyzYZ\") == 51\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 51\n assert candidate(s = \"AbCdEfGhIjKlMnoPqRsTuVwXyZ\") == 25\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(s = \"aBCdeFGhIJKlmNoPQRstUVwXYz\") == 25\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzA\") == 26\n assert candidate(s = \"aBcDefGhIjKlMnOpQrStUvWxYz\") == 25\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(s = \"abcDefGhIjKlMnOpQrStUvWxYzABC\") == 28\n assert candidate(s = \"AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == 0\n assert candidate(s = \"abABcdCDefEFghGHijIJklKLmnMNopOPqrQRstSTuvUVwxWXyzYZ\") == 51\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 25\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 51\n assert candidate(s = \"bAcAdAeAfAgAhAiAjAkAlAmAnAoApAqArAsAtAuAvAwAxAyAz\") == 48\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\") == 77\n assert candidate(s = \"mNbvCxZlkJhGfDsApOiUrYtWeQ\") == 25\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 77\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 25\n assert candidate(s = \"abcdEFGHijklMNOPqrstUVWXyz\") == 25\n assert candidate(s = \"zYxWvUtSrQpOnMlKjIhGfEdCbA\") == 25\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAb\") == 1\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == 25\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 77\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAa\") == 26\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBc\") == 28\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCcDdEeFf\") == 31\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcde\") == 30\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 51\n assert candidate(s = \"abcdefGHIJKLmnopQRstuvwxyzAbCdEfGHIJKLmnopQRstuvwxyz\") == 51\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\") == 51\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 51\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDaA\") == 23\n assert candidate(s = \"aBcDabcdEFGHefghIJKLijklMNOpQRmnopqrSTUVstuvWXYZwxyz\") == 51\n assert candidate(s = \"aBcDabcdEFGHefghIJKLijklMNOpQRmnopqrSTUVstuvWXYZwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 77\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzBb\") == 26\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkJiIhHgGfFeEdDcCbBaA\") == 25\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 77\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(s = \"AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcDEFdef\") == 34\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 51\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCc\") == 28\n assert candidate(s = \"abcdEFGHijklMNOpQRstUVWXyz\") == 25\n assert candidate(s = \"aBcDefGhIjKlMnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUvWxYz\") == 51\n assert candidate(s = \"AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 25\n assert candidate(s = \"ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba\") == 51\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUvWxYz\") == 51\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(s = \"mNbVcXzLkJhGfDsApoIuYtReWq\") == 25\n", "comparison": "exact"}, "public_tests": ["\"aAbBcC\"", "\"AaAaAaaA\""], "hints": ["Change all the characters to lowercase and then return the number of indices where the character does not match with the last index character."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countKeyChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:33+00:00", "tests_total": 78, "tests_dropped": 6, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def count_key_changes(s)", "container": null, "callable": "count_key_changes", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3020, "task_id": "find-the-maximum-number-of-elements-in-subset", "difficulty": "Medium", "problem_description": "You are given an array of positive integers nums.\n\nYou need to select a subset of nums which satisfies the following condition:\n\n- You can place the selected elements in a 0-indexed array such that it follows the pattern: [x, x^2, x^4, ..., x^{k/2}, x^k, x^{k/2}, ..., x^4, x^2, x] (Note that k can be any non-negative power of 2). For example, [2, 4, 16, 4, 2] and [3, 9, 3] follow the pattern while [2, 4, 8, 4, 2] does not.\n\nReturn the maximum number of elements in a subset that satisfies these conditions.\n\nExample 1:\n\nInput: nums = [5,4,1,2,2]\nOutput: 3\nExplanation: We can select the subset {4,2,2}, which can be placed in the array as [2,4,2] which follows the pattern and 2^2 == 4. Hence the answer is 3.\n\nExample 2:\n\nInput: nums = [1,3,2,4]\nOutput: 1\nExplanation: We can select the subset {1}, which can be placed in the array as [1] which follows the pattern. Hence the answer is 1. Note that we could have also selected the subsets {2}, {3}, or {4}, there may be multiple subsets which provide the same answer.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 81, 729, 6561, 729, 81, 9]) == 5\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 16, 8, 4, 2]) == 5\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [5, 5, 25, 25, 625, 625, 390625, 390625]) == 7\n assert candidate(nums = [2, 4, 8, 4, 2]) == 3\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(nums = [16, 4, 2, 8, 1, 32, 64, 128, 256, 512]) == 1\n assert candidate(nums = [5, 4, 1, 2, 2]) == 3\n assert candidate(nums = [2, 2, 2, 2, 2, 4, 4, 4, 16, 16, 256]) == 7\n assert candidate(nums = [3, 9, 27, 81, 27, 9, 3]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums = [2, 2, 4, 4, 16, 16, 256, 256]) == 7\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 3125, 625, 125, 25, 5]) == 5\n assert candidate(nums = [3, 9, 3]) == 3\n assert candidate(nums = [6, 36, 216, 1296, 7776, 46656, 279936, 1679616, 10077696, 60466176, 362797056]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [9, 3, 1, 3, 9, 27, 27, 9, 3, 1]) == 3\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == 1\n assert candidate(nums = [10, 100, 1000, 100, 10]) == 3\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(nums = [7, 49, 343, 2401, 343, 49, 7]) == 5\n assert candidate(nums = [5, 5, 25, 625, 390625]) == 3\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 1\n assert candidate(nums = [2, 4, 16, 4, 2]) == 5\n assert candidate(nums = [3, 9, 3, 27, 9, 3]) == 3\n assert candidate(nums = [1, 3, 2, 4]) == 1\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 10000, 1000, 100, 10]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 31\n assert candidate(nums = [7, 49, 343, 2401, 16807, 117649, 823543, 5764801, 40353607, 282475249, 40353607, 5764801, 823543, 117649, 16807, 2401, 343, 49, 7]) == 7\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]) == 25\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 7\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 7\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums = [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]) == 1\n assert candidate(nums = [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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]) == 1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 2187, 729, 243, 81, 27, 9, 3]) == 7\n assert candidate(nums = [1, 4, 16, 64, 4096, 262144, 65536, 4096, 64, 16, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(nums = [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 = [5, 25, 125, 625, 3125, 15625, 3125, 625, 125, 25, 5, 4, 16, 2, 8, 32, 64, 128, 256, 512]) == 5\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 3125, 625, 125, 25, 5, 10, 100, 1000, 10000, 10000, 1000, 100, 10, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 7\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 1\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10]) == 7\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 27\n assert candidate(nums = [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 = [4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 4194304, 1048576, 262144, 65536, 16384, 4096, 1024, 256, 64, 16, 4]) == 7\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 32, 32, 32, 32, 64, 64, 64, 64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512]) == 7\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 3125, 625, 125, 25, 5, 4, 16, 2, 8, 32, 64, 128, 256, 512, 3, 9, 27, 81, 243, 729, 2187, 6561, 2187, 729, 243, 81, 27, 9, 3]) == 7\n assert candidate(nums = [2, 8, 32, 128, 512, 2048, 8192, 32768, 131072, 524288, 131072, 32768, 8192, 2048, 512, 128, 32, 8, 2]) == 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]) == 47\n", "comparison": "exact"}, "public_tests": ["[5,4,1,2,2]", "[1,3,2,4]"], "hints": ["We can select an odd number of 1’s.", "Put all the values into a HashSet. We can start from each x > 1 as the smallest chosen value and we can find the longest subset by checking the new values (which are the square of the previous value) in the set by brute force.", "Note when x > 1, x^2, x^4, x^8, … increases very fast, the longest subset with smallest value x cannot be very long. (The length is O(log(log(10^9))).", "Hence we can directly check all lengths less than 10 for all values of x."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:35+00:00", "tests_total": 86, "tests_dropped": 30, "flags": [], "topic_tags": ["array", "hash-table", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(nums)", "container": null, "callable": "maximum_length", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3021, "task_id": "alice-and-bob-playing-flower-game", "difficulty": "Medium", "problem_description": "Alice and Bob are playing a turn-based game on a field, with two lanes of flowers between them. There are x flowers in the first lane between Alice and Bob, and y flowers in the second lane between them.\n\nThe game proceeds as follows:\n\n1. Alice takes the first turn.\n2. In each turn, a player must choose either one of the lane and pick one flower from that side.\n3. At the end of the turn, if there are no flowers left at all in either lane, the current player captures their opponent and wins the game.\n\nGiven two integers, n and m, the task is to compute the number of possible pairs (x, y) that satisfy the conditions:\n\n- Alice must win the game according to the described rules.\n- The number of flowers x in the first lane must be in the range [1,n].\n- The number of flowers y in the second lane must be in the range [1,m].\n\nReturn the number of possible pairs (x, y) that satisfy the conditions mentioned in the statement.\n\nExample 1:\n\nInput: n = 3, m = 2\nOutput: 3\nExplanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).\n\nExample 2:\n\nInput: n = 1, m = 1\nOutput: 0\nExplanation: No pairs satisfy the conditions described in the statement.\n\nConstraints:\n\n- 1 <= n, m <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,m = 7) == 17\n assert candidate(n = 5,m = 4) == 10\n assert candidate(n = 1,m = 1) == 0\n assert candidate(n = 100,m = 200) == 10000\n assert candidate(n = 4,m = 3) == 6\n assert candidate(n = 100000,m = 100000) == 5000000000\n assert candidate(n = 3,m = 2) == 3\n assert candidate(n = 10,m = 10) == 50\n assert candidate(n = 5,m = 5) == 12\n assert candidate(n = 2,m = 2) == 2\n assert candidate(n = 75000,m = 25000) == 937500000\n assert candidate(n = 7,m = 11) == 38\n assert candidate(n = 25000,m = 75000) == 937500000\n assert candidate(n = 99,m = 101) == 4999\n assert candidate(n = 30000,m = 40000) == 600000000\n assert candidate(n = 99999,m = 2) == 99999\n assert candidate(n = 50000,m = 100000) == 2500000000\n assert candidate(n = 10,m = 1) == 5\n assert candidate(n = 1000,m = 1000) == 500000\n assert candidate(n = 33333,m = 66667) == 1111105555\n assert candidate(n = 7,m = 8) == 28\n assert candidate(n = 33333,m = 66666) == 1111088889\n assert candidate(n = 75000,m = 85000) == 3187500000\n assert candidate(n = 99999,m = 99999) == 4999900000\n assert candidate(n = 10000,m = 5000) == 25000000\n assert candidate(n = 99999,m = 100000) == 4999950000\n assert candidate(n = 3,m = 3) == 4\n assert candidate(n = 500,m = 500) == 125000\n assert candidate(n = 100,m = 100) == 5000\n assert candidate(n = 15,m = 25) == 187\n assert candidate(n = 50000,m = 50000) == 1250000000\n assert candidate(n = 60000,m = 40000) == 1200000000\n assert candidate(n = 20000,m = 10000) == 100000000\n assert candidate(n = 5000,m = 5000) == 12500000\n assert candidate(n = 1,m = 99999) == 49999\n assert candidate(n = 55,m = 88) == 2420\n assert candidate(n = 1,m = 10) == 5\n assert candidate(n = 20,m = 15) == 150\n assert candidate(n = 50,m = 60) == 1500\n assert candidate(n = 2,m = 99999) == 99999\n assert candidate(n = 1,m = 100000) == 50000\n assert candidate(n = 300,m = 200) == 30000\n assert candidate(n = 20000,m = 20000) == 200000000\n assert candidate(n = 50000,m = 1) == 25000\n assert candidate(n = 10,m = 15) == 75\n assert candidate(n = 50,m = 50) == 1250\n assert candidate(n = 7,m = 5) == 17\n assert candidate(n = 1000,m = 500) == 250000\n assert candidate(n = 20000,m = 30000) == 300000000\n assert candidate(n = 200,m = 300) == 30000\n assert candidate(n = 150,m = 150) == 11250\n assert candidate(n = 23456,m = 65432) == 767386496\n assert candidate(n = 30000,m = 20000) == 300000000\n assert candidate(n = 1000,m = 1500) == 750000\n assert candidate(n = 49999,m = 50001) == 1249999999\n assert candidate(n = 2,m = 3) == 3\n assert candidate(n = 80000,m = 20000) == 800000000\n assert candidate(n = 25,m = 30) == 375\n assert candidate(n = 99999,m = 1) == 49999\n assert candidate(n = 10000,m = 10000) == 50000000\n assert candidate(n = 12345,m = 67890) == 419051025\n assert candidate(n = 15,m = 15) == 112\n assert candidate(n = 66667,m = 33333) == 1111105555\n assert candidate(n = 100000,m = 1) == 50000\n", "comparison": "exact"}, "public_tests": ["3\n2", "1\n1"], "hints": ["(x, y) is valid if and only if they have different parities."], "metadata": {"canonical_parameter_names": ["n", "m"], "leetcode_dataset_entry_point": "Solution().flowerGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:37+00:00", "tests_total": 66, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def flower_game(n, m)", "container": null, "callable": "flower_game", "parameters": [{"name": "n", "type": "Integer"}, {"name": "m", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3022, "task_id": "minimize-or-of-remaining-elements-using-operations", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums and an integer k.\n\nIn one operation, you can pick any index i of nums such that 0 <= i < nums.length - 1 and replace nums[i] and nums[i + 1] with a single occurrence of nums[i] & nums[i + 1], where & represents the bitwise AND operator.\n\nReturn the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n\nExample 1:\n\nInput: nums = [3,5,3,2,7], k = 2\nOutput: 3\nExplanation: Let's do the following operations:\n1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [1,3,2,7].\n2. Replace nums[2] and nums[3] with (nums[2] & nums[3]) so that nums becomes equal to [1,3,2].\nThe bitwise-or of the final array is 3.\nIt can be shown that 3 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n\nExample 2:\n\nInput: nums = [7,3,15,14,2,8], k = 4\nOutput: 2\nExplanation: Let's do the following operations:\n1. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,15,14,2,8].\n2. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [3,14,2,8].\n3. Replace nums[0] and nums[1] with (nums[0] & nums[1]) so that nums becomes equal to [2,2,8].\n4. Replace nums[1] and nums[2] with (nums[1] & nums[2]) so that nums becomes equal to [2,0].\nThe bitwise-or of the final array is 2.\nIt can be shown that 2 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n\nExample 3:\n\nInput: nums = [10,7,10,3,9,14,9,4], k = 1\nOutput: 15\nExplanation: Without applying any operations, the bitwise-or of nums is 15.\nIt can be shown that 15 is the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] < 2^30\n- 0 <= k < nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [30, 20, 10, 0],k = 2) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [0, 0, 0, 0, 0],k = 0) == 0\n assert candidate(nums = [1, 0, 1, 0, 1],k = 2) == 1\n assert candidate(nums = [31, 31, 31, 31, 31],k = 3) == 31\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 0\n assert candidate(nums = [0, 0, 0, 0, 0],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 7\n assert candidate(nums = [8, 8, 8, 8, 8],k = 2) == 8\n assert candidate(nums = [29, 29, 29, 29, 29],k = 4) == 29\n assert candidate(nums = [25, 15, 5, 1, 0],k = 3) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 3) == 1\n assert candidate(nums = [30, 29, 28, 27, 26, 25],k = 5) == 24\n assert candidate(nums = [10, 7, 10, 3, 9, 14, 9, 4],k = 1) == 15\n assert candidate(nums = [1, 2, 4, 8, 16],k = 2) == 1\n assert candidate(nums = [8, 12, 4, 6, 10],k = 2) == 12\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 9) == 1\n assert candidate(nums = [7, 3, 15, 14, 2, 8],k = 4) == 2\n assert candidate(nums = [31, 15, 7, 3, 1],k = 4) == 1\n assert candidate(nums = [16, 16, 16, 16, 16],k = 0) == 16\n assert candidate(nums = [31, 31, 31, 31, 31],k = 4) == 31\n assert candidate(nums = [3, 5, 3, 2, 7],k = 2) == 3\n assert candidate(nums = [1, 1, 1, 1, 1],k = 4) == 1\n assert candidate(nums = [31, 15, 7, 3, 1],k = 3) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],k = 6) == 7\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 3) == 31\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 9) == 31\n assert candidate(nums = [15, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 4) == 7\n assert candidate(nums = [16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1],k = 7) == 0\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 9) == 1\n assert candidate(nums = [30, 21, 45, 12, 8, 16, 32, 64, 128, 256],k = 7) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 10) == 7\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 31\n assert candidate(nums = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246],k = 5) == 254\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 10) == 3\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 5) == 31\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 0],k = 7) == 0\n assert candidate(nums = [18, 5, 12, 9, 3, 14, 7, 11, 6, 4, 10, 8, 2, 13, 1],k = 10) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575],k = 19) == 1\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 19) == 1\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],k = 25) == 15\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 18) == 31\n assert candidate(nums = [31, 14, 7, 3, 1, 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 = 28) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 62\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],k = 5) == 15\n assert candidate(nums = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 19) == 0\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 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],k = 25) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 8) == 7\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047],k = 9) == 2047\n assert candidate(nums = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120],k = 9) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 9) == 1\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],k = 29) == 3\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 9) == 1\n assert candidate(nums = [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],k = 29) == 0\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023],k = 9) == 1023\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 = 15) == 15\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 = 19) == 1\n assert candidate(nums = [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],k = 20) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 25) == 7\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],k = 9) == 255\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0, 255, 128],k = 10) == 0\n assert candidate(nums = [30, 15, 7, 3, 1, 15, 7, 3, 1, 15, 7, 3, 1, 15, 7, 3, 1, 15, 7, 3],k = 15) == 3\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21],k = 5) == 28\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 5) == 15\n assert candidate(nums = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015, 1014, 1013, 1012, 1011, 1010, 1009],k = 13) == 1008\n assert candidate(nums = [29, 21, 13, 5, 1],k = 3) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 29) == 1\n assert candidate(nums = [29, 31, 28, 27, 26, 25, 24, 23, 22, 21],k = 8) == 20\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],k = 5) == 4088\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 13) == 0\n assert candidate(nums = [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, 101, 103, 107, 109, 113],k = 15) == 63\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 9) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0],k = 9) == 1\n assert candidate(nums = [4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0],k = 13) == 0\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 3, 1],k = 6) == 0\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 255, 127, 63],k = 10) == 1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 10) == 0\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 15) == 31\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 7) == 5\n assert candidate(nums = [30, 14, 7, 3, 1, 0, 15, 8, 4, 2],k = 6) == 2\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095],k = 11) == 1\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1],k = 7) == 0\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 255, 128, 64, 32, 16, 8, 4, 2, 1],k = 17) == 0\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984, 3968, 7936, 15872],k = 8) == 24\n assert candidate(nums = [30, 28, 24, 16, 8, 4, 2, 1],k = 6) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 8) == 3\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 14) == 0\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0],k = 14) == 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],k = 10) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 31\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 7) == 5\n assert candidate(nums = [29, 21, 14, 7, 3, 1, 0],k = 6) == 0\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 255, 127, 63, 31, 15, 7, 3, 1, 255, 127, 63, 31],k = 18) == 1\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047],k = 8) == 4095\n assert candidate(nums = [29, 17, 3, 15, 8, 12, 7],k = 3) == 15\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 5) == 16777215\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576],k = 19) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 9) == 3\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 = 25) == 3\n assert candidate(nums = [17, 34, 68, 136, 272, 544, 1088, 2176, 4352, 8704],k = 5) == 0\n", "comparison": "exact"}, "public_tests": ["[3,5,3,2,7]\n2", "[7,3,15,14,2,8]\n4", "[10,7,10,3,9,14,9,4]\n1"], "hints": ["From the most significant bit to the least significant bit, maintain the bits that will not be included in the final answer in a variable mask.", "For a fixed bit, add it to mask then check if there exists some sequence of k operations such that mask & answer == 0 where answer is the bitwise-or of the remaining elements of nums. If there is no such sequence of operations, remove the current bit from mask. How can we perform this check?", "Let x be the bitwise-and of all elements of nums. If x AND mask != 0, there is no sequence of operations that satisfies the condition in the previous hint. This is because even if we perform this operation n - 1 times on the array, we will end up with x as the final element.", "Otherwise, there exists at least one such sequence. It is sufficient to check if the number of operations in such a sequence is less than k. Let’s calculate the minimum number of operations in such a sequence.", "Iterate over the array from left to right, if nums[i] & mask != 0, apply the operation on index i.", "After iterating over all elements, let x be the bitwise-and of all elements of nums. If x == 0, then we have found the minimum number of operations. Otherwise, It can be proven that we need exactly one more operation so that x == 0.", "The condition in the second hint is satisfied if and only if the minimum number of operations is less than or equal to k."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minOrAfterOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:40+00:00", "tests_total": 109, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "greedy", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_or_after_operations(nums, k)", "container": null, "callable": "min_or_after_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3024, "task_id": "type-of-triangle", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.\n\n- A triangle is called equilateral if it has all sides of equal length.\n- A triangle is called isosceles if it has exactly two sides of equal length.\n- A triangle is called scalene if all its sides are of different lengths.\n\nReturn a string representing the type of triangle that can be formed or \"none\" if it cannot form a triangle.\n\nExample 1:\n\nInput: nums = [3,3,3]\nOutput: \"equilateral\"\nExplanation: Since all the sides are of equal length, therefore, it will form an equilateral triangle.\n\nExample 2:\n\nInput: nums = [3,4,5]\nOutput: \"scalene\"\nExplanation:\nnums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.\nnums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.\nnums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.\nSince the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.\nAs all the sides are of different lengths, it will form a scalene triangle.\n\nConstraints:\n\n- nums.length == 3\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 3]) == \"isosceles\"\n assert candidate(nums = [10, 10, 10]) == \"equilateral\"\n assert candidate(nums = [1, 1, 2]) == \"none\"\n assert candidate(nums = [6, 6, 10]) == \"isosceles\"\n assert candidate(nums = [6, 6, 12]) == \"none\"\n assert candidate(nums = [3, 4, 5]) == \"scalene\"\n assert candidate(nums = [8, 15, 17]) == \"scalene\"\n assert candidate(nums = [1, 2, 3]) == \"none\"\n assert candidate(nums = [5, 7, 10]) == \"scalene\"\n assert candidate(nums = [6, 6, 6]) == \"equilateral\"\n assert candidate(nums = [50, 50, 50]) == \"equilateral\"\n assert candidate(nums = [5, 5, 8]) == \"isosceles\"\n assert candidate(nums = [5, 7, 5]) == \"isosceles\"\n assert candidate(nums = [3, 3, 3]) == \"equilateral\"\n assert candidate(nums = [7, 10, 5]) == \"scalene\"\n assert candidate(nums = [4, 4, 7]) == \"isosceles\"\n assert candidate(nums = [99, 99, 98]) == \"isosceles\"\n assert candidate(nums = [5, 5, 5]) == \"equilateral\"\n assert candidate(nums = [25, 25, 40]) == \"isosceles\"\n assert candidate(nums = [30, 40, 50]) == \"scalene\"\n assert candidate(nums = [12, 16, 20]) == \"scalene\"\n assert candidate(nums = [10, 15, 25]) == \"none\"\n assert candidate(nums = [99, 99, 1]) == \"isosceles\"\n assert candidate(nums = [5, 5, 8]) == \"isosceles\"\n assert candidate(nums = [7, 7, 14]) == \"none\"\n assert candidate(nums = [45, 45, 89]) == \"isosceles\"\n assert candidate(nums = [20, 21, 21]) == \"isosceles\"\n assert candidate(nums = [20, 25, 30]) == \"scalene\"\n assert candidate(nums = [45, 45, 45]) == \"equilateral\"\n assert candidate(nums = [3, 4, 6]) == \"scalene\"\n assert candidate(nums = [50, 60, 60]) == \"isosceles\"\n assert candidate(nums = [50, 50, 80]) == \"isosceles\"\n assert candidate(nums = [99, 99, 99]) == \"equilateral\"\n assert candidate(nums = [3, 5, 5]) == \"isosceles\"\n assert candidate(nums = [13, 14, 15]) == \"scalene\"\n assert candidate(nums = [9, 12, 15]) == \"scalene\"\n assert candidate(nums = [6, 6, 10]) == \"isosceles\"\n assert candidate(nums = [23, 23, 23]) == \"equilateral\"\n assert candidate(nums = [7, 10, 5]) == \"scalene\"\n assert candidate(nums = [5, 5, 5]) == \"equilateral\"\n assert candidate(nums = [9, 9, 9]) == \"equilateral\"\n assert candidate(nums = [100, 100, 1]) == \"isosceles\"\n assert candidate(nums = [6, 6, 11]) == \"isosceles\"\n assert candidate(nums = [45, 45, 45]) == \"equilateral\"\n assert candidate(nums = [9, 4, 6]) == \"scalene\"\n assert candidate(nums = [1, 2, 2]) == \"isosceles\"\n assert candidate(nums = [6, 8, 10]) == \"scalene\"\n assert candidate(nums = [9, 12, 15]) == \"scalene\"\n assert candidate(nums = [99, 1, 1]) == \"none\"\n assert candidate(nums = [45, 45, 90]) == \"none\"\n assert candidate(nums = [40, 40, 41]) == \"isosceles\"\n assert candidate(nums = [50, 51, 100]) == \"scalene\"\n assert candidate(nums = [5, 12, 13]) == \"scalene\"\n assert candidate(nums = [50, 51, 100]) == \"scalene\"\n assert candidate(nums = [2, 2, 4]) == \"none\"\n assert candidate(nums = [5, 12, 13]) == \"scalene\"\n assert candidate(nums = [100, 100, 1]) == \"isosceles\"\n assert candidate(nums = [10, 10, 15]) == \"isosceles\"\n assert candidate(nums = [5, 5, 9]) == \"isosceles\"\n assert candidate(nums = [10, 10, 20]) == \"none\"\n assert candidate(nums = [30, 30, 59]) == \"isosceles\"\n assert candidate(nums = [10, 10, 10]) == \"equilateral\"\n assert candidate(nums = [2, 2, 4]) == \"none\"\n assert candidate(nums = [15, 15, 29]) == \"isosceles\"\n assert candidate(nums = [10, 10, 15]) == \"isosceles\"\n assert candidate(nums = [100, 100, 100]) == \"equilateral\"\n assert candidate(nums = [25, 25, 30]) == \"isosceles\"\n assert candidate(nums = [7, 24, 25]) == \"scalene\"\n assert candidate(nums = [9, 40, 41]) == \"scalene\"\n assert candidate(nums = [17, 17, 34]) == \"none\"\n assert candidate(nums = [33, 44, 55]) == \"scalene\"\n assert candidate(nums = [50, 50, 80]) == \"isosceles\"\n assert candidate(nums = [3, 4, 4]) == \"isosceles\"\n assert candidate(nums = [25, 25, 49]) == \"isosceles\"\n assert candidate(nums = [10, 15, 25]) == \"none\"\n assert candidate(nums = [10, 14, 14]) == \"isosceles\"\n assert candidate(nums = [5, 7, 12]) == \"none\"\n assert candidate(nums = [12, 16, 20]) == \"scalene\"\n assert candidate(nums = [1, 1, 1]) == \"equilateral\"\n assert candidate(nums = [7, 24, 25]) == \"scalene\"\n assert candidate(nums = [51, 51, 100]) == \"isosceles\"\n assert candidate(nums = [6, 8, 10]) == \"scalene\"\n assert candidate(nums = [45, 45, 89]) == \"isosceles\"\n assert candidate(nums = [7, 7, 10]) == \"isosceles\"\n assert candidate(nums = [50, 50, 100]) == \"none\"\n assert candidate(nums = [1, 1, 2]) == \"none\"\n assert candidate(nums = [2, 2, 3]) == \"isosceles\"\n assert candidate(nums = [30, 40, 50]) == \"scalene\"\n assert candidate(nums = [33, 33, 34]) == \"isosceles\"\n assert candidate(nums = [50, 50, 70]) == \"isosceles\"\n assert candidate(nums = [1, 100, 100]) == \"isosceles\"\n assert candidate(nums = [1, 100, 1]) == \"none\"\n assert candidate(nums = [15, 15, 25]) == \"isosceles\"\n assert candidate(nums = [9, 9, 12]) == \"isosceles\"\n assert candidate(nums = [100, 100, 100]) == \"equilateral\"\n", "comparison": "exact"}, "public_tests": ["[3,3,3]", "[3,4,5]"], "hints": ["The condition for a valid triangle is that for any two sides, the sum of their lengths must be greater than the third side.", "Simply count the number of unique edge lengths after checking it’s a valid triangle."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().triangleType", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:42+00:00", "tests_total": 96, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "sorting", "polygons"]}, "language": "ruby", "interface": {"raw_signature": "def triangle_type(nums)", "container": null, "callable": "triangle_type", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3025, "task_id": "find-the-number-of-ways-to-place-people-i", "difficulty": "Medium", "problem_description": "You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D plane, where points[i] = [x_i, y_i].\n\nCount the number of pairs of points (A, B), where\n\n- A is on the upper left side of B, and\n- there are no other points in the rectangle (or line) they make (including the border), except for the points A and B.\n\nReturn the count.\n\nExample 1:\n\nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 0\nExplanation:\nThere is no way to choose A and B such that A is on the upper left side of B.\n\nExample 2:\n\nInput: points = [[6,2],[4,4],[2,6]]\nOutput: 2\nExplanation:\n- The left one is the pair (points[1], points[0]), where points[1] is on the upper left side of points[0] and the rectangle is empty.\n- The middle one is the pair (points[2], points[1]), same as the left one it is a valid pair.\n- The right one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0], but points[1] is inside the rectangle so it's not a valid pair.\n\nExample 3:\n\nInput: points = [[3,1],[1,3],[1,1]]\nOutput: 2\nExplanation:\n- The left one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0] and there are no other points on the line they form. Note that it is a valid state when the two points form a line.\n- The middle one is the pair (points[1], points[2]), it is a valid pair same as the left one.\n- The right one is the pair (points[1], points[0]), it is not a valid pair as points[2] is on the border of the rectangle.\n\nConstraints:\n\n- 2 <= n <= 50\n- points[i].length == 2\n- 0 <= points[i][0], points[i][1] <= 50\n- All points[i] are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[3, 1], [1, 3], [1, 1]]) == 2\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2], [1, 3], [2, 3], [3, 3]]) == 12\n assert candidate(points = [[2, 4], [4, 2], [1, 3], [3, 1], [5, 0], [0, 5]]) == 8\n assert candidate(points = [[50, 50], [49, 49], [48, 48], [47, 47], [46, 46]]) == 0\n assert candidate(points = [[1, 1], [2, 2], [3, 3]]) == 0\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(points = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 0\n assert candidate(points = [[10, 10], [10, 9], [9, 10], [9, 9]]) == 4\n assert candidate(points = [[10, 10], [10, 20], [20, 10], [20, 20]]) == 4\n assert candidate(points = [[0, 0], [50, 50], [25, 25], [25, 50], [50, 25]]) == 4\n assert candidate(points = [[0, 50], [50, 0], [25, 25], [20, 30]]) == 3\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30]]) == 0\n assert candidate(points = [[6, 2], [4, 4], [2, 6]]) == 2\n assert candidate(points = [[50, 50], [0, 0], [25, 25], [10, 10], [40, 40], [30, 30]]) == 0\n assert candidate(points = [[30, 20], [20, 30], [10, 40], [40, 10], [25, 25]]) == 4\n assert candidate(points = [[0, 0], [50, 50], [25, 25], [30, 30]]) == 0\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 0\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == 0\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 0\n assert candidate(points = [[5, 5], [4, 6], [3, 7], [2, 8], [1, 9]]) == 4\n assert candidate(points = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == 4\n assert candidate(points = [[0, 50], [50, 0], [25, 25], [10, 40], [40, 10]]) == 4\n assert candidate(points = [[0, 1], [1, 0], [2, 3], [3, 2]]) == 2\n assert candidate(points = [[10, 5], [3, 7], [2, 8], [5, 3], [9, 4]]) == 4\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]) == 0\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5]]) == 3\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40]]) == 0\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [1, 4], [3, 6], [1, 6]]) == 6\n assert candidate(points = [[10, 20], [10, 10], [20, 20], [20, 10], [15, 15], [15, 10], [10, 15]]) == 8\n assert candidate(points = [[50, 50], [49, 49], [48, 48], [47, 47], [46, 46], [45, 45], [44, 44], [43, 43], [42, 42], [41, 41]]) == 0\n assert candidate(points = [[2, 3], [4, 5], [1, 1], [5, 2], [3, 4], [4, 4], [5, 5], [1, 5], [5, 1], [3, 2]]) == 14\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == 13\n assert candidate(points = [[25, 25], [24, 26], [26, 24], [23, 27], [27, 23], [22, 28], [28, 22], [21, 29], [29, 21], [30, 30]]) == 8\n assert candidate(points = [[20, 20], [18, 18], [16, 16], [14, 14], [12, 12], [10, 10], [8, 8], [6, 6], [4, 4], [2, 2]]) == 0\n assert candidate(points = [[1, 50], [2, 49], [3, 48], [4, 47], [5, 46], [6, 45], [7, 44], [8, 43], [9, 42], [10, 41], [11, 40], [12, 39], [13, 38], [14, 37]]) == 13\n assert candidate(points = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [5, 2], [4, 3], [3, 4], [2, 5]]) == 8\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3], [1, 3], [3, 1], [2, 4], [4, 2]]) == 10\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]]) == 0\n assert candidate(points = [[1, 1], [50, 50], [25, 25], [10, 10], [40, 40], [30, 30]]) == 0\n assert candidate(points = [[25, 25], [20, 30], [30, 20], [15, 35], [35, 15], [10, 40], [40, 10], [5, 45], [45, 5]]) == 8\n assert candidate(points = [[1, 1], [1, 5], [5, 1], [5, 5], [2, 2], [2, 4], [4, 2], [4, 4], [3, 3], [3, 5]]) == 15\n assert candidate(points = [[1, 49], [2, 48], [3, 47], [4, 46], [5, 45], [6, 44], [7, 43], [8, 42], [9, 41], [10, 40], [11, 39], [12, 38], [13, 37], [14, 36], [15, 35], [16, 34], [17, 33], [18, 32], [19, 31], [20, 30], [21, 29], [22, 28], [23, 27], [24, 26], [25, 25], [26, 24], [27, 23], [28, 22], [29, 21], [30, 20], [31, 19], [32, 18], [33, 17], [34, 16], [35, 15], [36, 14], [37, 13], [38, 12], [39, 11], [40, 10], [41, 9], [42, 8], [43, 7], [44, 6], [45, 5], [46, 4], [47, 3], [48, 2], [49, 1]]) == 48\n assert candidate(points = [[5, 5], [5, 4], [5, 3], [5, 2], [5, 1], [4, 5], [3, 5], [2, 5], [1, 5], [4, 4]]) == 10\n assert candidate(points = [[5, 5], [10, 5], [15, 5], [20, 5], [25, 5], [30, 5], [35, 5], [40, 5], [45, 5], [50, 5], [5, 10], [10, 10], [15, 10], [20, 10], [25, 10], [30, 10], [35, 10], [40, 10], [45, 10], [50, 10]]) == 28\n assert candidate(points = [[5, 5], [3, 3], [4, 4], [2, 2], [1, 1], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 0\n assert candidate(points = [[10, 40], [20, 30], [30, 20], [40, 10], [10, 10], [20, 20], [30, 30], [40, 40]]) == 10\n assert candidate(points = [[1, 1], [2, 3], [3, 2], [4, 4], [5, 5], [6, 7], [7, 6], [8, 8], [9, 9], [10, 10], [1, 10], [10, 1], [5, 1], [5, 10], [1, 5], [10, 5]]) == 24\n assert candidate(points = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 9\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]]) == 22\n assert candidate(points = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1], [10, 0]]) == 9\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3]]) == 22\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4]]) == 8\n assert candidate(points = [[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]]) == 0\n assert candidate(points = [[5, 10], [10, 5], [3, 8], [8, 3], [2, 2], [7, 7], [4, 6], [6, 4]]) == 9\n assert candidate(points = [[2, 3], [4, 1], [5, 7], [3, 6], [7, 2], [6, 4], [8, 8], [1, 5], [5, 1], [7, 6]]) == 13\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == 8\n assert candidate(points = [[30, 10], [10, 30], [20, 20], [15, 15], [25, 25], [5, 5], [35, 35], [40, 40], [5, 40], [40, 5]]) == 14\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45], [50, 50], [2, 2], [4, 4], [6, 6], [8, 8], [12, 12], [14, 14], [16, 16], [18, 18], [22, 22], [24, 24], [26, 26], [28, 28], [32, 32], [34, 34], [36, 36], [38, 38], [42, 42], [44, 44], [46, 46], [48, 48]]) == 0\n assert candidate(points = [[1, 5], [3, 4], [2, 3], [5, 2], [4, 1], [6, 0]]) == 8\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [10, 20], [20, 30], [30, 40], [40, 50], [50, 10]]) == 13\n assert candidate(points = [[1, 49], [2, 48], [3, 47], [4, 46], [5, 45], [6, 44], [7, 43], [8, 42], [9, 41], [10, 40], [11, 39], [12, 38], [13, 37], [14, 36]]) == 13\n assert candidate(points = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6], [1, 1], [2, 2], [3, 1], [4, 0]]) == 14\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5]]) == 13\n assert candidate(points = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [5, 4], [4, 3], [3, 2], [2, 1]]) == 8\n assert candidate(points = [[1, 5], [2, 5], [1, 4], [2, 4], [1, 3], [2, 3], [1, 2], [2, 2], [1, 1], [2, 1]]) == 13\n assert candidate(points = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == 8\n assert candidate(points = [[50, 50], [49, 49], [48, 48], [47, 47], [46, 46], [45, 45], [44, 44], [43, 43], [42, 42], [41, 41], [40, 40], [39, 39], [38, 38], [37, 37], [36, 36], [35, 35], [34, 34], [33, 33], [32, 32], [31, 31], [30, 30], [29, 29], [28, 28], [27, 27], [26, 26], [25, 25], [24, 24], [23, 23], [22, 22], [21, 21], [20, 20], [19, 19], [18, 18], [17, 17], [16, 16], [15, 15], [14, 14], [13, 13], [12, 12], [11, 11], [10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 0\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 0\n assert candidate(points = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8], [45, 9], [50, 10], [4, 2], [9, 3], [14, 4], [19, 5], [24, 6], [29, 7], [34, 8], [39, 9], [44, 10], [49, 11]]) == 19\n assert candidate(points = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0]]) == 0\n assert candidate(points = [[5, 5], [10, 5], [15, 5], [5, 10], [10, 10], [15, 10], [5, 15], [10, 15], [15, 15]]) == 12\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 9\n assert candidate(points = [[1, 5], [2, 3], [2, 4], [4, 2], [4, 3], [4, 4], [5, 1], [5, 2], [5, 3]]) == 10\n assert candidate(points = [[5, 10], [10, 5], [15, 0], [20, 5], [25, 10], [30, 15], [35, 10], [40, 5], [45, 0]]) == 10\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 0\n assert candidate(points = [[1, 5], [5, 1], [2, 4], [4, 2], [3, 3], [6, 6], [6, 1], [1, 6], [7, 7], [7, 2], [2, 7], [8, 8], [8, 3], [3, 8], [9, 9], [9, 4], [4, 9], [10, 10], [10, 5], [5, 10]]) == 44\n assert candidate(points = [[50, 50], [25, 25], [0, 0], [25, 50], [50, 25]]) == 4\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [1, 1], [6, 6], [11, 11], [16, 16], [2, 2], [7, 7], [12, 12], [17, 17], [3, 3], [8, 8], [13, 13], [18, 18], [4, 4], [9, 9], [14, 14], [19, 19]]) == 0\n assert candidate(points = [[1, 3], [3, 3], [5, 3], [2, 2], [4, 2], [6, 2], [1, 1], [3, 1], [5, 1]]) == 14\n assert candidate(points = [[30, 30], [25, 25], [20, 20], [15, 15], [10, 10], [5, 5], [0, 0], [35, 35], [40, 40], [45, 45], [50, 50], [2, 2], [7, 7], [12, 12], [17, 17], [22, 22], [27, 27], [32, 32], [37, 37], [42, 42], [47, 47], [3, 3], [8, 8], [13, 13], [18, 18], [23, 23], [28, 28], [33, 33], [38, 38], [43, 43], [48, 48], [4, 4], [9, 9], [14, 14], [19, 19], [24, 24], [29, 29], [34, 34], [39, 39], [44, 44], [49, 49]]) == 0\n assert candidate(points = [[30, 20], [15, 25], [10, 30], [5, 35], [40, 10], [35, 15], [45, 5], [5, 5]]) == 8\n assert candidate(points = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0], [6, 6], [7, 7], [8, 8], [9, 9]]) == 0\n assert candidate(points = [[1, 1], [5, 5], [2, 4], [3, 3], [4, 2], [1, 5], [5, 1], [2, 3], [3, 2], [4, 4]]) == 12\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 10], [3, 10], [4, 10], [5, 10]]) == 13\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1]]) == 13\n assert candidate(points = [[1, 2], [2, 1], [1, 3], [3, 1], [2, 3], [3, 2], [1, 4], [4, 1], [2, 4], [4, 2], [3, 3]]) == 15\n assert candidate(points = [[2, 3], [4, 3], [1, 2], [1, 1], [3, 2], [3, 1], [5, 1], [5, 2], [4, 1]]) == 12\n assert candidate(points = [[1, 1], [2, 1], [1, 2], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 4\n assert candidate(points = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]]) == 9\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [1, 3], [2, 1], [3, 1], [1, 2], [2, 3], [3, 2], [2, 4]]) == 13\n assert candidate(points = [[5, 5], [3, 3], [1, 1], [2, 2], [4, 4], [6, 6], [7, 7]]) == 0\n assert candidate(points = [[1, 1], [5, 5], [3, 3], [2, 2], [4, 4], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 0\n assert candidate(points = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 1]]) == 0\n assert candidate(points = [[1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]) == 8\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(points = [[1, 50], [2, 49], [3, 48], [4, 47], [5, 46], [6, 45], [7, 44], [8, 43], [9, 42], [10, 41], [40, 40], [39, 39], [38, 38], [37, 37]]) == 13\n assert candidate(points = [[30, 30], [29, 29], [28, 28], [27, 27], [26, 26], [25, 25], [24, 24], [23, 23], [22, 22], [21, 21], [20, 20]]) == 0\n assert candidate(points = [[3, 1], [1, 3], [1, 1], [4, 4], [2, 2], [5, 5]]) == 4\n assert candidate(points = [[4, 4], [3, 3], [2, 2], [1, 1], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 0\n assert candidate(points = [[10, 10], [10, 9], [9, 10], [9, 9], [8, 8], [8, 7], [7, 8], [7, 7], [6, 6], [6, 5]]) == 9\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 40\n assert candidate(points = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 0], [7, 1], [8, 2], [9, 3], [10, 4]]) == 9\n assert candidate(points = [[1, 49], [3, 48], [5, 47], [7, 46], [9, 45], [11, 44], [13, 43], [15, 42], [17, 41], [19, 40]]) == 9\n assert candidate(points = [[5, 5], [4, 5], [3, 5], [2, 5], [1, 5], [5, 4], [5, 3], [5, 2], [5, 1], [4, 4], [3, 3], [2, 2], [1, 1]]) == 16\n assert candidate(points = [[2, 4], [4, 2], [3, 5], [5, 3], [1, 6], [6, 1], [7, 7], [8, 8], [9, 9], [10, 10]]) == 8\n", "comparison": "exact"}, "public_tests": ["[[1,1],[2,2],[3,3]]", "[[6,2],[4,4],[2,6]]", "[[3,1],[1,3],[1,1]]"], "hints": ["We can enumerate all the upper-left and lower-right corners.", "If the upper-left corner is (x1, y1) and lower-right corner is (x2, y2), check that there is no point (x, y) such that x1 <= x <= x2 and y2 <= y <= y1."], "metadata": {"canonical_parameter_names": ["points"], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:45+00:00", "tests_total": 111, "tests_dropped": 6, "flags": ["has_images"], "topic_tags": ["array", "math", "geometry", "sorting", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_pairs(points)", "container": null, "callable": "number_of_pairs", "parameters": [{"name": "points", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3026, "task_id": "maximum-good-subarray-sum", "difficulty": "Medium", "problem_description": "You are given an array nums of length n and a positive integer k.\n\nA subarray of nums is called good if the absolute difference between its first and last element is exactly k, in other words, the subarray nums[i..j] is good if |nums[i] - nums[j]| == k.\n\nReturn the maximum sum of a good subarray of nums. If there are no good subarrays, return 0.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5,6], k = 1\nOutput: 11\nExplanation: The absolute difference between the first and last element must be 1 for a good subarray. All the good subarrays are: [1,2], [2,3], [3,4], [4,5], and [5,6]. The maximum subarray sum is 11 for the subarray [5,6].\n\nExample 2:\n\nInput: nums = [-1,3,2,4,5], k = 3\nOutput: 11\nExplanation: The absolute difference between the first and last element must be 3 for a good subarray. All the good subarrays are: [-1,3,2], and [2,4,5]. The maximum subarray sum is 11 for the subarray [2,4,5].\n\nExample 3:\n\nInput: nums = [-1,-2,-3,-4], k = 2\nOutput: -6\nExplanation: The absolute difference between the first and last element must be 2 for a good subarray. All the good subarrays are: [-1,-2,-3], and [-2,-3,-4]. The maximum subarray sum is -6 for the subarray [-1,-2,-3].\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- -10^9 <= nums[i] <= 10^9\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 3, 2, 4, 5],k = 3) == 11\n assert candidate(nums = [10, 20, 30, 40, 50],k = 20) == 120\n assert candidate(nums = [1, 3, 5, 7, 9],k = 8) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 55\n assert candidate(nums = [10, 20, 30, 40, 50],k = 40) == 150\n assert candidate(nums = [-1, -2, -3, -4],k = 2) == -6\n assert candidate(nums = [1, -1, 1, -1, 1],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 1) == 11\n assert candidate(nums = [1, 3, 1, 5, 4, 1, 3, 5],k = 2) == 22\n assert candidate(nums = [1, 3, 1, 5, 4, 1],k = 4) == 10\n assert candidate(nums = [5, 4, 3, 2, 1],k = 4) == 15\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 55\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 90\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 = 19) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5],k = 14) == 120\n assert candidate(nums = [1, 3, 1, 5, 1, 7, 1, 9, 1, 11],k = 8) == 39\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],k = 19) == 210\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5],k = 5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 55\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -10, -20, -30, -40, -50],k = 90) == -110\n assert candidate(nums = [-5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19],k = 9) == -95\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 = 19) == -35\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1],k = 999) == 1001\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1],k = 5) == 45\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40],k = 20) == 40\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9],k = 18) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 1) == -3\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11],k = 1) == 51\n assert candidate(nums = [-1, 0, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9],k = 1) == 8\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9],k = 8) == 1\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 90) == -550\n assert candidate(nums = [-5, -10, 0, -15, 5, 10, 20, -5],k = 15) == 35\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],k = 4) == 15\n assert candidate(nums = [5, 6, 7, 8, 9, 5, 6, 7, 8, 9],k = 3) == 65\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20],k = 19) == 210\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 18) == 300\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 190\n assert candidate(nums = [5, 3, 8, 5, 12, 7, 5],k = 7) == 33\n assert candidate(nums = [1, 5, 3, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 18) == 300\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 450\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 5) == 5999999985\n assert candidate(nums = [5, 1, 9, 10, 3, 8, 7, 6, 4, 2],k = 5) == 47\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 5) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 190) == 2100\n assert candidate(nums = [-1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000],k = 2000) == 0\n assert candidate(nums = [5, 3, 1, 4, 7, 9, 2, 5],k = 4) == 29\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 = 9) == 110\n assert candidate(nums = [500000000, 500000001, 500000002, 500000003, 500000004, 500000005, 500000000],k = 5) == 3000000015\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5],k = 5) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 14) == 120\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2],k = 2) == 36\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],k = 1) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 14) == 120\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],k = 18) == 589\n assert candidate(nums = [5, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 8) == 20\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 = 1) == 39\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45],k = 10) == 45\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],k = 1) == 49\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 19) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 50) == 850\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 2) == 10\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400],k = 100) == 400\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10],k = 1) == 45\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 1) == 38\n assert candidate(nums = [2, 4, 2, 6, 2, 8, 2, 10, 2, 12],k = 10) == 50\n assert candidate(nums = [-5, -3, -1, 0, 2, 4, 6, 8, 10, 12],k = 10) == 42\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],k = 1) == 21\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],k = 19) == 210\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 = 19) == 210\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40],k = 10) == 40\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 8) == 90\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],k = 90) == 650\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 999999999) == 9999999956\n assert candidate(nums = [5, 1, 3, 5, 7, 9, 3, 5],k = 2) == 33\n assert candidate(nums = [100, 200, 300, 400, 500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500, -400, -300, -200, -100],k = 200) == 2400\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 6) == 4\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1) == 29\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40],k = 100) == 550\n assert candidate(nums = [1, 3, 1, 5, 1, 7, 1, 9, 1, 11, 1, 13, 1, 15, 1, 17, 1, 19],k = 18) == 108\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 55\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],k = 5) == 15\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],k = 1) == 27\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 14) == -120\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 = 19) == 210\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 5) == 5999999985\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 110\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 90) == 550\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 20) == -60\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1) == 29\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 4) == 5\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],k = 9) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 38) == 400\n assert candidate(nums = [5, 3, 8, 6, 7, 2, 9, 1, 4, 10],k = 7) == 50\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 9) == 55\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50],k = 90) == 550\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 55\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 50) == 450\n assert candidate(nums = [1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 90\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 900) == 5500\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],k = 10) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 400, 300, 200, 100, 500, 400, 300, 200, 100],k = 400) == 3000\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,6]\n1", "[-1,3,2,4,5]\n3", "[-1,-2,-3,-4]\n2"], "hints": ["Save all the prefix sums into a HashMap.", "For the index i store the element at index i + 1 as the key and the prefix sum till i as the value.", "For each prefix sum ending at nums[i], try finding nums[i] - k and nums[i] + k in the HashMap and update the answer."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumSubarraySum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:47+00:00", "tests_total": 116, "tests_dropped": 15, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_subarray_sum(nums, k)", "container": null, "callable": "maximum_subarray_sum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3027, "task_id": "find-the-number-of-ways-to-place-people-ii", "difficulty": "Hard", "problem_description": "You are given a 2D array points of size n x 2 representing integer coordinates of some points on a 2D-plane, where points[i] = [x_i, y_i].\n\nWe define the right direction as positive x-axis (increasing x-coordinate) and the left direction as negative x-axis (decreasing x-coordinate). Similarly, we define the up direction as positive y-axis (increasing y-coordinate) and the down direction as negative y-axis (decreasing y-coordinate)\n\nYou have to place n people, including Alice and Bob, at these points such that there is exactly one person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the upper left corner and Bob's position as the lower right corner of the fence (Note that the fence might not enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either inside the fence or on the fence, Alice will be sad.\n\nReturn the number of pairs of points where you can place Alice and Bob, such that Alice does not become sad on building the fence.\n\nNote that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners (1, 1), (1, 3), (3, 1), and (3, 3), because:\n\n- With Alice at (3, 3) and Bob at (1, 1), Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence.\n- With Alice at (1, 3) and Bob at (1, 1) (as the rectangle shown in the image instead of a line), Bob's position is not the lower right corner of the fence.\n\nExample 1:\n\nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 0\nExplanation: There is no way to place Alice and Bob such that Alice can build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. Hence we return 0.\n\nExample 2:\n\nInput: points = [[6,2],[4,4],[2,6]]\nOutput: 2\nExplanation: There are two ways to place Alice and Bob such that Alice will not be sad:\n- Place Alice at (4, 4) and Bob at (6, 2).\n- Place Alice at (2, 6) and Bob at (4, 4).\nYou cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence.\n\nExample 3:\n\nInput: points = [[3,1],[1,3],[1,1]]\nOutput: 2\nExplanation: There are two ways to place Alice and Bob such that Alice will not be sad:\n- Place Alice at (1, 1) and Bob at (3, 1).\n- Place Alice at (1, 3) and Bob at (1, 1).\nYou cannot place Alice at (1, 3) and Bob at (3, 1) because the person at (1, 1) will be on the fence.\nNote that it does not matter if the fence encloses any area, the first and second fences in the image are valid.\n\nConstraints:\n\n- 2 <= n <= 1000\n- points[i].length == 2\n- -10^9 <= points[i][0], points[i][1] <= 10^9\n- All points[i] are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[3, 1], [1, 3], [1, 1]]) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 1], [1, 3], [2, 1], [1, 2]]) == 6\n assert candidate(points = [[1, 1], [2, 2], [1, 2], [2, 1]]) == 4\n assert candidate(points = [[-1, 5], [0, 0], [2, 4], [4, -2]]) == 4\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]) == 4\n assert candidate(points = [[0, 0], [1, 1], [2, 0], [2, 2], [3, 1]]) == 5\n assert candidate(points = [[-1, 1], [1, -1], [-2, 2], [2, -2]]) == 3\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-4, -4], [-5, -5]]) == 0\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7]]) == 3\n assert candidate(points = [[1, 1], [2, 2], [3, 3]]) == 0\n assert candidate(points = [[5, 5], [5, 4], [5, 3], [5, 2], [5, 1]]) == 4\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(points = [[-10, 10], [10, -10], [0, 0], [5, 5], [-5, -5]]) == 6\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2]]) == 4\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3]]) == 0\n assert candidate(points = [[-1, 1], [1, -1], [0, 0]]) == 2\n assert candidate(points = [[-1, -1], [0, 0], [1, 1], [2, 2]]) == 0\n assert candidate(points = [[6, 2], [4, 4], [2, 6]]) == 2\n assert candidate(points = [[10, 1], [9, 2], [8, 3], [7, 4]]) == 3\n assert candidate(points = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == 4\n assert candidate(points = [[0, 0], [1, 1], [2, 0], [2, 2]]) == 3\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 0\n assert candidate(points = [[1, 1], [2, 3], [3, 2], [4, 4]]) == 1\n assert candidate(points = [[0, 10], [10, 0], [5, 5], [15, 15]]) == 2\n assert candidate(points = [[-1, 1], [-2, 2], [-3, 3], [-4, 4], [-5, 5]]) == 4\n assert candidate(points = [[1, 5], [2, 3], [3, 2], [4, 1]]) == 3\n assert candidate(points = [[-1, -1], [1, 1], [-2, -2], [2, 2]]) == 0\n assert candidate(points = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == 4\n assert candidate(points = [[10, 10], [5, 5], [0, 0], [-5, -5], [-10, -10]]) == 0\n assert candidate(points = [[1, -1], [2, -2], [3, -3], [4, -4], [5, -5]]) == 4\n assert candidate(points = [[10, 10], [20, 20], [15, 15], [5, 5]]) == 0\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5]]) == 3\n assert candidate(points = [[-1000000000, 1000000000], [1000000000, -1000000000], [0, 0], [1, 1], [2, 2], [3, 3]]) == 8\n assert candidate(points = [[-2, 3], [1, 1], [0, 0], [-1, -1], [2, 2], [3, -3], [4, 4], [-4, -4], [5, 5]]) == 8\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-1, -3], [-2, -1], [-3, -2]]) == 7\n assert candidate(points = [[5, 5], [5, 6], [5, 7], [6, 5], [6, 6], [6, 7], [7, 5], [7, 6], [7, 7], [8, 5], [8, 6], [8, 7]]) == 17\n assert candidate(points = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 0\n assert candidate(points = [[10, 10], [10, 9], [10, 8], [10, 7], [10, 6], [9, 10], [9, 9], [9, 8], [9, 7], [9, 6], [8, 10], [8, 9], [8, 8], [8, 7], [8, 6], [7, 10], [7, 9], [7, 8], [7, 7], [7, 6], [6, 10], [6, 9], [6, 8], [6, 7], [6, 6]]) == 40\n assert candidate(points = [[0, 0], [100, 100], [50, 50], [75, 25], [25, 75], [125, 125], [25, 25], [75, 75], [100, 50], [50, 100]]) == 12\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == 13\n assert candidate(points = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == 9\n assert candidate(points = [[-1, 1], [0, 0], [1, -1], [1, 1], [-1, -1]]) == 6\n assert candidate(points = [[5, 1], [1, 5], [3, 3], [4, 2], [2, 4], [6, 0], [0, 6], [7, 1], [1, 7]]) == 8\n assert candidate(points = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9], [3, 1], [3, 3], [3, 5], [3, 7], [3, 9]]) == 13\n assert candidate(points = [[1000000000, 1000000000], [500000000, 500000000], [0, 0], [-500000000, -500000000], [-1000000000, -1000000000]]) == 0\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [1, 4], [2, 4], [3, 4], [4, 4], [5, 4]]) == 31\n assert candidate(points = [[5, 5], [5, 6], [6, 5], [6, 6], [5, 4], [4, 5], [4, 4], [7, 7], [7, 6], [6, 7]]) == 12\n assert candidate(points = [[-1, -1], [1, 1], [2, 2], [-2, -2], [0, 0]]) == 0\n assert candidate(points = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [1, 4]]) == 13\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [1, 3], [2, 3], [3, 1], [3, 2], [3, 3], [4, 4]]) == 12\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-1, -2], [-2, -3], [-1, -3], [-3, -1], [-3, -2], [0, 0], [0, -1], [0, -2], [0, -3]]) == 16\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 0\n assert candidate(points = [[1000000000, 1000000000], [1, 1], [500000000, 500000000], [2, 2], [999999999, 999999999]]) == 0\n assert candidate(points = [[10, 10], [10, 9], [10, 8], [9, 9], [8, 8], [9, 8], [8, 9]]) == 8\n assert candidate(points = [[100, 100], [90, 90], [80, 80], [70, 70], [60, 60], [50, 50], [40, 40], [30, 30], [20, 20], [10, 10]]) == 0\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 9\n assert candidate(points = [[-10, 10], [-9, 9], [-8, 8], [-7, 7], [-6, 6], [-5, 5], [-4, 4], [-3, 3], [-2, 2], [-1, 1]]) == 9\n assert candidate(points = [[1, 5], [2, 3], [3, 2], [4, 1], [5, 4]]) == 4\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]) == 12\n assert candidate(points = [[-1, 1], [-1, -1], [1, -1], [1, 1], [0, 0], [0, 1], [0, -1], [1, 0], [-1, 0], [2, 2], [-2, -2], [2, -2], [-2, 2], [3, 3], [-3, -3], [3, -3], [-3, 3]]) == 24\n assert candidate(points = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [10, 0], [0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == 31\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1], [2, 10], [3, 9], [4, 8], [5, 7], [6, 6], [7, 5], [8, 4], [9, 3], [10, 2], [3, 10], [4, 9], [5, 8], [6, 7], [7, 6], [8, 5], [9, 4], [10, 3], [4, 10], [5, 9], [6, 8], [7, 7], [8, 6], [9, 5], [10, 4], [5, 10], [6, 9], [7, 8], [8, 7], [9, 6], [10, 5], [6, 10], [7, 9], [8, 8], [9, 7], [10, 6], [7, 10], [8, 9], [9, 8], [10, 7], [8, 10], [9, 9], [10, 8], [9, 10], [10, 9], [10, 10]]) == 108\n assert candidate(points = [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], [3, 0], [3, 1], [3, 2]]) == 17\n assert candidate(points = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [1, 8], [2, 8], [3, 8], [4, 8], [5, 8]]) == 22\n assert candidate(points = [[-5, -5], [-4, -4], [-3, -3], [-2, -2], [-1, -1], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 0\n assert candidate(points = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 26\n assert candidate(points = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 9\n assert candidate(points = [[-100, 100], [0, 0], [100, -100], [50, 50], [-50, -50], [75, 25], [25, 75], [25, 25], [75, 75], [-25, -25], [-75, -75]]) == 16\n assert candidate(points = [[5, 5], [6, 4], [7, 3], [8, 2], [9, 1], [10, 0], [9, 0], [8, 0], [7, 0], [6, 0], [5, 0], [4, 1], [3, 2], [2, 3], [1, 4]]) == 22\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5]]) == 31\n assert candidate(points = [[0, 1], [1, 0], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6], [8, 9], [9, 8]]) == 5\n assert candidate(points = [[5, 5], [5, 4], [5, 3], [5, 2], [5, 1], [4, 5], [3, 5], [2, 5], [1, 5], [5, 0]]) == 9\n assert candidate(points = [[-5, -5], [5, 5], [0, 0], [3, 3], [2, 2], [1, 1]]) == 0\n assert candidate(points = [[1000000000, -1000000000], [-1000000000, 1000000000], [0, 0], [500000000, 500000000], [-500000000, -500000000]]) == 6\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-4, -4], [-5, -5], [-6, -6], [-7, -7], [-8, -8], [-9, -9]]) == 0\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 0\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-1, -2], [-2, -1], [-1, -3], [-3, -1]]) == 8\n assert candidate(points = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3]]) == 8\n assert candidate(points = [[1, 5], [2, 5], [3, 5], [1, 4], [2, 4], [3, 4], [1, 3], [2, 3], [3, 3], [1, 2], [2, 2], [3, 2], [1, 1], [2, 1], [3, 1]]) == 22\n assert candidate(points = [[1, 10], [10, 1], [3, 3], [5, 5], [2, 8], [8, 2]]) == 6\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [4, 1], [4, 2], [4, 3], [4, 4]]) == 24\n assert candidate(points = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == 8\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900]]) == 0\n assert candidate(points = [[10, 20], [10, 19], [10, 18], [9, 20], [9, 19], [9, 18], [8, 20], [8, 19], [8, 18], [7, 20], [7, 19], [7, 18]]) == 17\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == 0\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 0\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 9\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == 9\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == 13\n assert candidate(points = [[1, 1], [2, 2], [2, 1], [3, 3], [3, 2], [3, 1], [4, 4], [4, 3], [4, 2], [4, 1]]) == 12\n assert candidate(points = [[1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [2, 5], [2, 4], [2, 3], [2, 2], [2, 1]]) == 13\n assert candidate(points = [[1000000000, 1000000000], [999999999, 999999999], [999999998, 999999998], [999999997, 999999997], [999999996, 999999996], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 0\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-4, -4], [-5, -5], [-6, -6], [-7, -7], [-8, -8], [-9, -9], [-10, -10]]) == 0\n assert candidate(points = [[1, 1], [2, 1], [1, 2], [2, 2], [3, 1], [3, 2], [3, 3], [2, 3], [1, 3], [1, 4], [2, 4], [3, 4]]) == 17\n assert candidate(points = [[1, 5], [5, 1], [3, 3], [2, 4], [4, 2], [1, 3], [3, 1], [2, 3], [3, 2], [4, 1], [5, 2], [2, 5]]) == 14\n assert candidate(points = [[1, 5], [5, 1], [3, 3], [2, 4], [4, 2]]) == 4\n assert candidate(points = [[1, 5], [3, 7], [5, 9], [2, 3], [4, 6], [6, 8]]) == 3\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 0\n assert candidate(points = [[-10, 10], [10, -10], [0, 0], [5, 5], [-5, -5], [7, 3], [3, 7]]) == 8\n assert candidate(points = [[10, 10], [10, 9], [10, 8], [10, 7], [10, 6], [10, 5], [10, 4], [10, 3], [10, 2], [10, 1]]) == 9\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 9\n assert candidate(points = [[1, 2], [2, 1], [1, 3], [3, 1], [2, 3], [3, 2], [1, 4], [4, 1], [2, 4], [4, 2], [3, 3]]) == 15\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9]]) == 5\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 9\n assert candidate(points = [[1, 10], [3, 9], [5, 8], [7, 7], [9, 6], [11, 5], [13, 4], [15, 3], [17, 2], [19, 1]]) == 9\n assert candidate(points = [[-10, 10], [10, -10], [0, 0], [5, 5], [-5, -5], [3, 3], [-3, -3]]) == 10\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == 0\n assert candidate(points = [[5, 5], [5, 10], [10, 5], [10, 10], [7, 7], [8, 8], [3, 3], [3, 8], [8, 3]]) == 16\n assert candidate(points = [[-5, 5], [0, 0], [5, -5], [10, -10], [5, 0], [0, 5]]) == 5\n assert candidate(points = [[-5, 5], [-4, 4], [-3, 3], [-2, 2], [-1, 1], [1, -1], [2, -2], [3, -3], [4, -4], [5, -5]]) == 9\n assert candidate(points = [[1000000000, 1000000000], [-1000000000, -1000000000], [0, 0], [500000000, 500000000], [-500000000, -500000000]]) == 0\n assert candidate(points = [[-10, -10], [10, 10], [0, 0], [5, 5], [-5, -5], [5, -5], [-5, 5]]) == 6\n assert candidate(points = [[5, 10], [10, 5], [15, 0], [20, 5], [25, 10], [30, 5], [35, 0], [40, 5], [45, 10]]) == 10\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 40\n assert candidate(points = [[-100, -100], [-200, -200], [-300, -300], [-400, -400], [-500, -500], [-600, -600], [-700, -700], [-800, -800], [-900, -900]]) == 0\n assert candidate(points = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == 27\n assert candidate(points = [[10, 10], [11, 11], [12, 12], [9, 12], [8, 13], [7, 14], [6, 15], [5, 16], [4, 17], [3, 18], [2, 19], [1, 20]]) == 11\n assert candidate(points = [[5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [6, 5], [6, 6], [6, 7], [6, 8], [6, 9], [7, 5], [7, 6], [7, 7], [7, 8], [7, 9], [8, 5], [8, 6], [8, 7], [8, 8], [8, 9], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9]]) == 40\n", "comparison": "exact"}, "public_tests": ["[[1,1],[2,2],[3,3]]", "[[6,2],[4,4],[2,6]]", "[[3,1],[1,3],[1,1]]"], "hints": ["Sort the points by x-coordinate in non-decreasing order and break the tie by sorting the y-coordinate in non-increasing order.", "Now consider two points upper-left corner points[i] and lower-right corner points[j], such that i < j and points[i][0] <= points[j][0] and points[i][1] >= points[j][1].", "Instead of brute force looping, we can save the largest y-coordinate that is no larger than points[i][1] when looping on j, say the value is m. And if m < points[j][1], the upper-left and lower-right corner pair is valid.", "The actual values don’t matter, we can compress all x-coordinates and y-coordinates to the range [1, n]. Can we use prefix sum now?"], "metadata": {"canonical_parameter_names": ["points"], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:49+00:00", "tests_total": 120, "tests_dropped": 2, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "math", "geometry", "sorting", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_pairs(points)", "container": null, "callable": "number_of_pairs", "parameters": [{"name": "points", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3028, "task_id": "ant-on-the-boundary", "difficulty": "Easy", "problem_description": "An ant is on a boundary. It sometimes goes left and sometimes right.\n\nYou are given an array of non-zero integers nums. The ant starts reading nums from the first element of it to its end. At each step, it moves according to the value of the current element:\n\n- If nums[i] < 0, it moves left by -nums[i] units.\n- If nums[i] > 0, it moves right by nums[i] units.\n\nReturn the number of times the ant returns to the boundary.\n\nNotes:\n\n- There is an infinite space on both sides of the boundary.\n- We check whether the ant is on the boundary only after it has moved |nums[i]| units. In other words, if the ant crosses the boundary during its movement, it does not count.\n\nExample 1:\n\nInput: nums = [2,3,-5]\nOutput: 1\nExplanation: After the first step, the ant is 2 steps to the right of the boundary.\nAfter the second step, the ant is 5 steps to the right of the boundary.\nAfter the third step, the ant is on the boundary.\nSo the answer is 1.\n\nExample 2:\n\nInput: nums = [3,2,-3,-4]\nOutput: 0\nExplanation: After the first step, the ant is 3 steps to the right of the boundary.\nAfter the second step, the ant is 5 steps to the right of the boundary.\nAfter the third step, the ant is 2 steps to the right of the boundary.\nAfter the fourth step, the ant is 2 steps to the left of the boundary.\nThe ant never returned to the boundary, so the answer is 0.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- -10 <= nums[i] <= 10\n- nums[i] != 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 1, -1, 1]) == 2\n assert candidate(nums = [10]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [-2, 2, -2, 2]) == 2\n assert candidate(nums = [1, -1, 1, -1]) == 2\n assert candidate(nums = [2, 3, -5]) == 1\n assert candidate(nums = [5, 5, -10]) == 1\n assert candidate(nums = [1, 2, 3, -6]) == 1\n assert candidate(nums = [10, -5, -5]) == 1\n assert candidate(nums = [10, -10, 10, -10]) == 2\n assert candidate(nums = [1, 1, 1, 1, -4]) == 1\n assert candidate(nums = [-5, 5, -5, 5]) == 2\n assert candidate(nums = [-10]) == 0\n assert candidate(nums = [-1, -2, -3, 6]) == 1\n assert candidate(nums = [3, 2, -3, -4]) == 0\n assert candidate(nums = [5, -2, -3, 1, 4, -4]) == 1\n assert candidate(nums = [-5, -5, 10]) == 1\n assert candidate(nums = [7, -3, 2, -4, 1, -1, 3, -3, 2, -2]) == 0\n assert candidate(nums = [5, -2, -3, 1, 4, -4, -6, 6]) == 1\n assert candidate(nums = [-1, -1, -1, -1, -1, 5, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2]) == 6\n assert candidate(nums = [5, -2, 3, -3, 2, -5, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, -10, 1, 2, 3, 4, -10]) == 2\n assert candidate(nums = [-2, -2, -2, 6, -2, -2, -2, 6, -2, -2, -2]) == 2\n assert candidate(nums = [2, -1, 2, -1, 2, -1, 2, -1, 2, -1]) == 0\n assert candidate(nums = [5, 5, -10, 1, -1, 1]) == 2\n assert candidate(nums = [5, -2, 3, -6, 4, -1, -6]) == 1\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4]) == 4\n assert candidate(nums = [10, -10, 10, -10, 10, -10]) == 3\n assert candidate(nums = [-3, 3, -3, 3, -3, 3]) == 3\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, -4, 1, 1, 1, 1, -4, 1, 1, 1, 1, -4]) == 3\n assert candidate(nums = [7, -3, 2, -6, 1, 1, 1, -1, 1]) == 1\n assert candidate(nums = [5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5]) == 8\n assert candidate(nums = [5, -5, 5, -5, 5, -5, 5, -5, 5, -5]) == 5\n assert candidate(nums = [2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2]) == 11\n assert candidate(nums = [4, -1, -3, 2, 2, -4]) == 2\n assert candidate(nums = [7, -3, 3, -7, 4, -2, 2, -4]) == 2\n assert candidate(nums = [-7, 3, 4, -1, -2, 2, 1, -4, 6, -2]) == 3\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, 9]) == 1\n assert candidate(nums = [-2, 4, -2, -2, 4, -2, -2, 4]) == 2\n assert candidate(nums = [-1, -1, 2, 2, -4, 4, -5, 5, -6, 6]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, -9]) == 1\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 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]) == 10\n assert candidate(nums = [5, 5, -10, 5, -5, 5, -5]) == 3\n assert candidate(nums = [-3, -2, 5, -1, 4, -6, 2, 3]) == 1\n assert candidate(nums = [-3, 1, 2, -4, 1, 1, 1, -1]) == 1\n assert candidate(nums = [-10, 5, 5, -5, 5, -5, 5, -5, 5]) == 4\n assert candidate(nums = [-1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6]) == 0\n assert candidate(nums = [1, 2, 3, -3, -2, -1, 4, -4, 5, -5]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, -5, 1, 1, 1, -4, 1, 1, 1]) == 2\n assert candidate(nums = [2, 2, 2, -6, 1, -1, 1, -1, 1]) == 3\n assert candidate(nums = [5, -3, 2, -2, 2, -2, -2, 2]) == 1\n assert candidate(nums = [-2, 2, -2, 2, -2, 2]) == 3\n assert candidate(nums = [10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [-5, 5, -5, 5, -5, 5, -5]) == 3\n assert candidate(nums = [-10, 5, 5, -3, 3, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [7, -2, -2, -2, -1, 8, -1, -2, -2, -2]) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 1\n assert candidate(nums = [5, -2, -2, -1, 10, -5, 5]) == 1\n assert candidate(nums = [3, -1, -2, 3, -1, -2, 3, -1, -2, 3, -1, -2]) == 4\n assert candidate(nums = [7, -3, -1, -2, 3, -4, 1, 1, 1, -3, 5, -2, -1, 1, -1, -1, -1, -1, -1, 1]) == 3\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == 3\n assert candidate(nums = [-10, 10, -5, 5, -3, 3, -2, 2]) == 4\n assert candidate(nums = [4, -3, 2, -1, 4, -3, 2, -1]) == 0\n assert candidate(nums = [5, -2, 3, -6, 4, -1, -2, 3]) == 1\n assert candidate(nums = [10, -5, 3, -8, 2, -2, 4, -4, 6, -6, 5, -5]) == 5\n assert candidate(nums = [2, 2, 2, 2, -8, 2, 2, 2, 2, -8]) == 2\n assert candidate(nums = [2, 3, -5, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 9\n assert candidate(nums = [-10, 5, 3, -8, 2, 1, -2, 2, 1, -1]) == 0\n assert candidate(nums = [3, -3, 3, -3, 3, -3, 3, -3, 3, -3]) == 5\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\n assert candidate(nums = [10, -10, 10, -10, 10, -10, 10, -10]) == 4\n assert candidate(nums = [1, 1, -2, 1, -1, 3, -3, 2, -1, -1]) == 4\n assert candidate(nums = [2, 3, -5, 4, -4, -3, 3, 2, -2, 1, -1]) == 5\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == 0\n assert candidate(nums = [10, -10, 5, -5, 3, -3, 2, -2, 1, -1]) == 5\n assert candidate(nums = [-10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, -5, 5, -5, 5, -5]) == 3\n assert candidate(nums = [7, -3, -4, 1, 2, -2, -1, 4, -6, 2]) == 3\n assert candidate(nums = [2, -2, 3, -3, 4, -4]) == 3\n assert candidate(nums = [5, -2, -2, -1, 1, 5, -5, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2, -2, 2]) == 1\n assert candidate(nums = [5, -2, 3, -6, 1, 2, -3]) == 2\n assert candidate(nums = [7, -3, -2, 1, 2, -1, 2, -2]) == 0\n assert candidate(nums = [10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [2, -1, -1, 2, -2, 2, -1, 1, -2, 2]) == 3\n assert candidate(nums = [10, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1]) == 0\n assert candidate(nums = [4, -1, -3, 2, 1, -3]) == 2\n assert candidate(nums = [-1, -1, -1, -1, 4, -1, -1, -1, -1, 4, -1, -1, -1, -1, 4]) == 3\n assert candidate(nums = [1, 2, 3, 4, -1, -2, -3, -4]) == 1\n assert candidate(nums = [2, -2, 2, -2, 2, -2, 2, -2, 2, -2]) == 5\n assert candidate(nums = [5, -2, -3, 1, 2, -1, 3, -3, 2, -2, 5, -5]) == 1\n assert candidate(nums = [3, -1, -2, -1, 4, -4, 1, 1, 1, -3]) == 2\n assert candidate(nums = [-10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [7, -3, 2, -2, 2, -2, 3, -7]) == 1\n assert candidate(nums = [7, 2, -9, 4, -5, 3, -2, 1]) == 2\n assert candidate(nums = [-1, -2, -3, -4, 5, 5, 6, 6, -7, 7]) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1]) == 4\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 3\n assert candidate(nums = [5, -10, 5, 5, -10, 5]) == 2\n assert candidate(nums = [10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, -5, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 8\n assert candidate(nums = [3, 3, 3, -9, 3, -3, 3, -3, 3, -3]) == 4\n assert candidate(nums = [-1, 2, -2, 1, -1, 3, -3, 2, -2]) == 1\n assert candidate(nums = [2, 3, -1, -2, 1, -3, 4, -4, 5, -5, 6, -6, 7, -7]) == 5\n assert candidate(nums = [4, -1, 2, -5, 6, -3, 2, -1, 5, -10]) == 1\n", "comparison": "exact"}, "public_tests": ["[2,3,-5]", "[3,2,-3,-4]"], "hints": ["Define a variable and add nums[i] to it in each step."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().returnToBoundaryCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:51+00:00", "tests_total": 123, "tests_dropped": 14, "flags": [], "topic_tags": ["array", "simulation", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def return_to_boundary_count(nums)", "container": null, "callable": "return_to_boundary_count", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3029, "task_id": "minimum-time-to-revert-word-to-initial-state-i", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string word and an integer k.\n\nAt every second, you must perform the following operations:\n\n- Remove the first k characters of word.\n- Add any k characters to the end of word.\n\nNote that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.\n\nReturn the minimum time greater than zero required for word to revert to its initial state.\n\nExample 1:\n\nInput: word = \"abacaba\", k = 3\nOutput: 2\nExplanation: At the 1st second, we remove characters \"aba\" from the prefix of word, and add characters \"bac\" to the end of word. Thus, word becomes equal to \"cababac\".\nAt the 2nd second, we remove characters \"cab\" from the prefix of word, and add \"aba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\nIt can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.\n\nExample 2:\n\nInput: word = \"abacaba\", k = 4\nOutput: 1\nExplanation: At the 1st second, we remove characters \"abac\" from the prefix of word, and add characters \"caba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\nIt can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.\n\nExample 3:\n\nInput: word = \"abcbabcd\", k = 2\nOutput: 4\nExplanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.\nAfter 4 seconds, word becomes equal to \"abcbabcd\" and reverts to its initial state.\nIt can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.\n\nConstraints:\n\n- 1 <= word.length <= 50\n- 1 <= k <= word.length\n- word consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aabbcc\",k = 2) == 3\n assert candidate(word = \"hello\",k = 5) == 1\n assert candidate(word = \"xyzxyzxyz\",k = 4) == 3\n assert candidate(word = \"abcdef\",k = 1) == 6\n assert candidate(word = \"ababab\",k = 2) == 1\n assert candidate(word = \"pattern\",k = 1) == 7\n assert candidate(word = \"abcdefg\",k = 2) == 4\n assert candidate(word = \"abacaba\",k = 3) == 2\n assert candidate(word = \"abacaba\",k = 4) == 1\n assert candidate(word = \"xyzxyz\",k = 2) == 3\n assert candidate(word = \"banana\",k = 3) == 2\n assert candidate(word = \"abcabcabc\",k = 3) == 1\n assert candidate(word = \"hellohello\",k = 5) == 1\n assert candidate(word = \"racecar\",k = 2) == 3\n assert candidate(word = \"abcd\",k = 1) == 4\n assert candidate(word = \"aaaa\",k = 1) == 1\n assert candidate(word = \"aaaa\",k = 2) == 1\n assert candidate(word = \"abcbabcd\",k = 2) == 4\n assert candidate(word = \"abcdef\",k = 6) == 1\n assert candidate(word = \"rotate\",k = 3) == 2\n assert candidate(word = \"abcdefghiabcdefghiabcdefghi\",k = 9) == 1\n assert candidate(word = \"abcabcabcabcabcabcabcabc\",k = 7) == 3\n assert candidate(word = \"abcdefabcdef\",k = 2) == 3\n assert candidate(word = \"mississippi\",k = 2) == 6\n assert candidate(word = \"abcdefghabcdefgh\",k = 5) == 4\n assert candidate(word = \"abacabadabacabadabacabad\",k = 5) == 5\n assert candidate(word = \"abacabadabacabad\",k = 2) == 4\n assert candidate(word = \"abacabacabacabacabacaba\",k = 5) == 4\n assert candidate(word = \"racecar\",k = 1) == 6\n assert candidate(word = \"abcabcabcabcabcabcabcabc\",k = 6) == 1\n assert candidate(word = \"aaaaaa\",k = 1) == 1\n assert candidate(word = \"cascadecascade\",k = 2) == 7\n assert candidate(word = \"aaabbbcccdddaa\",k = 3) == 4\n assert candidate(word = \"zzzzzzzzzzzzzzzz\",k = 3) == 1\n assert candidate(word = \"aaaabbbbcccc\",k = 4) == 3\n assert candidate(word = \"abcabcabcabc\",k = 3) == 1\n assert candidate(word = \"abcdefabcdefabcdefabcdef\",k = 6) == 1\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiop\",k = 8) == 4\n assert candidate(word = \"abcabcabcabcabc\",k = 5) == 3\n assert candidate(word = \"abcdefgabcdefg\",k = 3) == 5\n assert candidate(word = \"abcdefgabcdefg\",k = 5) == 3\n assert candidate(word = \"aabbccddeeff\",k = 6) == 2\n assert candidate(word = \"abcdefghabcdefghabcdefgh\",k = 8) == 1\n assert candidate(word = \"aaaaabbbbbccccdddd\",k = 4) == 5\n assert candidate(word = \"abcdefghabcdefgh\",k = 8) == 1\n assert candidate(word = \"abcdeabcdeabcdeabcdeabcdeabcde\",k = 9) == 4\n assert candidate(word = \"xyzxyzxyzxyz\",k = 3) == 1\n assert candidate(word = \"qwertyuiopqwertyuiopqwerty\",k = 11) == 3\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcd\",k = 8) == 1\n assert candidate(word = \"mnopqrstmnopqrstmnopqr\",k = 7) == 4\n assert candidate(word = \"hellohellohello\",k = 5) == 1\n assert candidate(word = \"deeddeed\",k = 4) == 1\n assert candidate(word = \"abababababababab\",k = 3) == 2\n assert candidate(word = \"repetitionrepetition\",k = 7) == 3\n assert candidate(word = \"civiccivicciviccivic\",k = 4) == 5\n assert candidate(word = \"aabbccddeeaabbccddee\",k = 5) == 2\n assert candidate(word = \"mnopmnopmnopmnop\",k = 2) == 2\n assert candidate(word = \"abcabcabcabcabcabc\",k = 5) == 3\n assert candidate(word = \"aabbccddeeffgghhiijj\",k = 10) == 2\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 1\n assert candidate(word = \"qqwweerrttyy\",k = 2) == 6\n assert candidate(word = \"abcdabcdabcdabcd\",k = 4) == 1\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 1\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 1\n assert candidate(word = \"abababababababababababab\",k = 9) == 2\n assert candidate(word = \"pneumonoultramicroscopicsilicovolcanoconiosis\",k = 10) == 5\n assert candidate(word = \"abcdefabcdefabcdef\",k = 6) == 1\n assert candidate(word = \"banana\",k = 1) == 6\n assert candidate(word = \"abracadabraabracadabra\",k = 5) == 5\n assert candidate(word = \"repeatedrepeated\",k = 8) == 1\n assert candidate(word = \"repeatedstringrepeatedstring\",k = 9) == 4\n assert candidate(word = \"abcdefgabcdefgabcdefg\",k = 6) == 4\n assert candidate(word = \"banana\",k = 2) == 3\n assert candidate(word = \"abcdefabcdef\",k = 3) == 2\n assert candidate(word = \"abababababababababababab\",k = 3) == 2\n assert candidate(word = \"aabbccddeeff\",k = 2) == 6\n assert candidate(word = \"abcabcabcabc\",k = 4) == 3\n assert candidate(word = \"abcdefghijabcdefghijabcdefghij\",k = 10) == 1\n assert candidate(word = \"xyxxyxyxxyxyxy\",k = 3) == 4\n assert candidate(word = \"abcdabcdabcd\",k = 5) == 3\n assert candidate(word = \"aaaabbbbccccddddeeeeffff\",k = 5) == 5\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",k = 1) == 26\n assert candidate(word = \"mississippi\",k = 3) == 4\n assert candidate(word = \"repetitionrepetitionrepetition\",k = 6) == 5\n assert candidate(word = \"aabbccddeeff\",k = 3) == 4\n assert candidate(word = \"abcdabcdabcdabcd\",k = 7) == 3\n assert candidate(word = \"abacabadabacaba\",k = 4) == 2\n assert candidate(word = \"aaaaabbbbbccccc\",k = 5) == 3\n assert candidate(word = \"aaaaaaaaaa\",k = 1) == 1\n assert candidate(word = \"abracadabra\",k = 5) == 2\n assert candidate(word = \"abcdabcdabcd\",k = 3) == 4\n assert candidate(word = \"hellohellohello\",k = 6) == 3\n assert candidate(word = \"aaaaabbbbb\",k = 5) == 2\n assert candidate(word = \"abacabadabacaba\",k = 5) == 3\n assert candidate(word = \"bananaananabayananabanana\",k = 5) == 5\n assert candidate(word = \"palindromemordnilap\",k = 8) == 3\n assert candidate(word = \"abracadabraabracadabra\",k = 7) == 3\n assert candidate(word = \"abcdefghijkabcdefghijk\",k = 7) == 4\n assert candidate(word = \"abcdabcdabcdabcd\",k = 5) == 4\n assert candidate(word = \"mississippi\",k = 4) == 3\n assert candidate(word = \"xyxzyzyzxzyzyzxzyz\",k = 3) == 6\n assert candidate(word = \"aabbccddeeffgghhiijj\",k = 6) == 4\n assert candidate(word = \"xyzxyzxyzxyzxyzxyzxyzxyz\",k = 8) == 3\n assert candidate(word = \"abcabcabcabcabcabc\",k = 4) == 3\n assert candidate(word = \"mnopqrnopqrmon\",k = 6) == 3\n assert candidate(word = \"abcdefghabcdefghabcdefghabcdefgh\",k = 7) == 5\n assert candidate(word = \"abcdabcdabcd\",k = 4) == 1\n assert candidate(word = \"qwertyqwertyqwerty\",k = 6) == 1\n", "comparison": "exact"}, "public_tests": ["\"abacaba\"\n3", "\"abacaba\"\n4", "\"abcbabcd\"\n2"], "hints": ["Find the longest suffix which is also a prefix and the length is multiple of k."], "metadata": {"canonical_parameter_names": ["word", "k"], "leetcode_dataset_entry_point": "Solution().minimumTimeToInitialState", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:53+00:00", "tests_total": 108, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "rolling-hash", "string-matching", "hash-function"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_time_to_initial_state(word, k)", "container": null, "callable": "minimum_time_to_initial_state", "parameters": [{"name": "word", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3030, "task_id": "find-the-grid-of-region-average", "difficulty": "Medium", "problem_description": "You are given m x n grid image which represents a grayscale image, where image[i][j] represents a pixel with intensity in the range [0..255]. You are also given a non-negative integer threshold.\n\nTwo pixels are adjacent if they share an edge.\n\nA region is a 3 x 3 subgrid where the absolute difference in intensity between any two adjacent pixels is less than or equal to threshold.\n\nAll pixels in a region belong to that region, note that a pixel can belong to multiple regions.\n\nYou need to calculate a m x n grid result, where result[i][j] is the average intensity of the regions to which image[i][j] belongs, rounded down to the nearest integer. If image[i][j] belongs to multiple regions, result[i][j] is the average of the rounded-down average intensities of these regions, rounded down to the nearest integer. If image[i][j] does not belong to any region, result[i][j] is equal to image[i][j].\n\nReturn the grid result.\n\nExample 1:\n\nInput: image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3\nOutput: [[9,9,9,9],[9,9,9,9],[9,9,9,9]]\nExplanation:\nThere are two regions as illustrated above. The average intensity of the first region is 9, while the average intensity of the second region is 9.67 which is rounded down to 9. The average intensity of both of the regions is (9 + 9) / 2 = 9. As all the pixels belong to either region 1, region 2, or both of them, the intensity of every pixel in the result is 9.\nPlease note that the rounded-down values are used when calculating the average of multiple regions, hence the calculation is done using 9 as the average intensity of region 2, not 9.67.\n\nExample 2:\n\nInput: image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12\nOutput: [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]\nExplanation:\nThere are two regions as illustrated above. The average intensity of the first region is 25, while the average intensity of the second region is 30. The average intensity of both of the regions is (25 + 30) / 2 = 27.5 which is rounded down to 27.\nAll the pixels in row 0 of the image belong to region 1, hence all the pixels in row 0 in the result are 25. Similarly, all the pixels in row 3 in the result are 30. The pixels in rows 1 and 2 of the image belong to region 1 and region 2, hence their assigned value is 27 in the result.\n\nExample 3:\n\nInput: image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1\nOutput: [[5,6,7],[8,9,10],[11,12,13]]\nExplanation:\nThere is only one 3 x 3 subgrid, while it does not have the condition on difference of adjacent pixels, for example, the difference between image[0][0] and image[1][0] is |5 - 8| = 3 > threshold = 1. None of them belong to any valid regions, so the result should be the same as image.\n\nConstraints:\n\n- 3 <= n, m <= 500\n- 0 <= image[i][j] <= 255\n- 0 <= threshold <= 255\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(image = [[5, 6, 7], [8, 9, 10], [11, 12, 13]],threshold = 1) == [[5, 6, 7], [8, 9, 10], [11, 12, 13]]\n assert candidate(image = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65]],threshold = 15) == [[25, 30, 35, 40, 45], [27, 32, 37, 42, 47], [27, 32, 37, 42, 47], [30, 35, 40, 45, 50]]\n assert candidate(image = [[100, 101, 102], [101, 102, 103], [102, 103, 104]],threshold = 2) == [[102, 102, 102], [102, 102, 102], [102, 102, 102]]\n assert candidate(image = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],threshold = 255) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(image = [[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]],threshold = 0) == [[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]]\n assert candidate(image = [[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]],threshold = 2) == [[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]]\n assert candidate(image = [[255, 255, 255], [255, 255, 255], [255, 255, 255]],threshold = 0) == [[255, 255, 255], [255, 255, 255], [255, 255, 255]]\n assert candidate(image = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]],threshold = 1) == [[3, 3, 4, 4, 5], [3, 4, 4, 5, 5], [4, 4, 5, 5, 6], [4, 5, 5, 6, 6], [5, 5, 6, 6, 7]]\n assert candidate(image = [[10, 20, 30], [15, 25, 35], [20, 30, 40], [25, 35, 45]],threshold = 12) == [[25, 25, 25], [27, 27, 27], [27, 27, 27], [30, 30, 30]]\n assert candidate(image = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]],threshold = 2) == [[3, 3, 4, 4, 5], [3, 4, 4, 5, 5], [4, 4, 5, 5, 6], [4, 5, 5, 6, 6], [5, 5, 6, 6, 7]]\n assert candidate(image = [[5, 6, 7, 10], [8, 9, 10, 10], [11, 12, 13, 10]],threshold = 3) == [[9, 9, 9, 9], [9, 9, 9, 9], [9, 9, 9, 9]]\n assert candidate(image = [[255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255]],threshold = 127) == [[255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255]]\n assert candidate(image = [[255, 254, 253, 252, 251], [254, 253, 252, 251, 250], [253, 252, 251, 250, 249], [252, 251, 250, 249, 248], [251, 250, 249, 248, 247]],threshold = 2) == [[253, 252, 252, 251, 251], [252, 252, 251, 251, 250], [252, 251, 251, 250, 250], [251, 251, 250, 250, 249], [251, 250, 250, 249, 249]]\n assert candidate(image = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],threshold = 0) == [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]\n assert candidate(image = [[255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255]],threshold = 0) == [[255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255]]\n assert candidate(image = [[1, 3, 5, 7, 9, 11], [3, 5, 7, 9, 11, 13], [5, 7, 9, 11, 13, 15], [7, 9, 11, 13, 15, 17], [9, 11, 13, 15, 17, 19], [11, 13, 15, 17, 19, 21]],threshold = 2) == [[5, 6, 7, 9, 10, 11], [6, 7, 8, 10, 11, 12], [7, 8, 9, 11, 12, 13], [9, 10, 11, 13, 14, 15], [10, 11, 12, 14, 15, 16], [11, 12, 13, 15, 16, 17]]\n assert candidate(image = [[255, 254, 253, 252, 251], [254, 253, 252, 251, 250], [253, 252, 251, 250, 249], [252, 251, 250, 249, 248], [251, 250, 249, 248, 247]],threshold = 2) == [[253, 252, 252, 251, 251], [252, 252, 251, 251, 250], [252, 251, 251, 250, 250], [251, 251, 250, 250, 249], [251, 250, 250, 249, 249]]\n assert candidate(image = [[10, 20, 10, 20, 10], [20, 10, 20, 10, 20], [10, 20, 10, 20, 10], [20, 10, 20, 10, 20], [10, 20, 10, 20, 10]],threshold = 10) == [[14, 14, 14, 14, 14], [14, 14, 14, 14, 14], [14, 14, 14, 14, 14], [14, 14, 14, 14, 14], [14, 14, 14, 14, 14]]\n assert candidate(image = [[5, 10, 15, 20, 25, 30, 35], [10, 15, 20, 25, 30, 35, 40], [15, 20, 25, 30, 35, 40, 45], [20, 25, 30, 35, 40, 45, 50], [25, 30, 35, 40, 45, 50, 55], [30, 35, 40, 45, 50, 55, 60]],threshold = 20) == [[15, 17, 20, 25, 30, 32, 35], [17, 20, 22, 27, 32, 35, 37], [20, 22, 25, 30, 35, 37, 40], [25, 27, 30, 35, 40, 42, 45], [27, 30, 32, 37, 42, 45, 47], [30, 32, 35, 40, 45, 47, 50]]\n assert candidate(image = [[255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255]],threshold = 254) == [[255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255], [0, 255, 0, 255, 0], [255, 0, 255, 0, 255]]\n assert candidate(image = [[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]],threshold = 1) == [[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]]\n assert candidate(image = [[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]],threshold = 15) == [[20, 25, 30, 35, 40], [20, 25, 30, 35, 40], [20, 25, 30, 35, 40], [20, 25, 30, 35, 40], [20, 25, 30, 35, 40], [20, 25, 30, 35, 40]]\n assert candidate(image = [[10, 20, 30, 40], [15, 25, 35, 45], [20, 30, 40, 50], [25, 35, 45, 55]],threshold = 15) == [[25, 30, 30, 35], [27, 32, 32, 37], [27, 32, 32, 37], [30, 35, 35, 40]]\n assert candidate(image = [[50, 50, 50, 50, 50, 50, 50], [50, 60, 60, 60, 60, 60, 50], [50, 60, 70, 70, 70, 60, 50], [50, 60, 70, 80, 70, 60, 50], [50, 60, 70, 70, 70, 60, 50], [50, 60, 60, 60, 60, 60, 50], [50, 50, 50, 50, 50, 50, 50]],threshold = 10) == [[55, 56, 57, 58, 57, 56, 55], [56, 59, 60, 62, 60, 59, 56], [57, 60, 62, 64, 62, 60, 57], [58, 62, 64, 66, 64, 62, 58], [57, 60, 62, 64, 62, 60, 57], [56, 59, 60, 62, 60, 59, 56], [55, 56, 57, 58, 57, 56, 55]]\n assert candidate(image = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65], [30, 40, 50, 60, 70]],threshold = 15) == [[25, 30, 35, 40, 45], [27, 32, 37, 42, 47], [30, 35, 40, 45, 50], [32, 37, 42, 47, 52], [35, 40, 45, 50, 55]]\n assert candidate(image = [[255, 255, 255, 255], [255, 254, 253, 252], [254, 253, 252, 251], [253, 252, 251, 250]],threshold = 1) == [[255, 255, 255, 255], [253, 252, 252, 252], [253, 252, 252, 252], [253, 252, 252, 252]]\n assert candidate(image = [[1, 5, 9, 13, 17], [2, 6, 10, 14, 18], [3, 7, 11, 15, 19], [4, 8, 12, 16, 20]],threshold = 4) == [[6, 8, 10, 12, 14], [6, 8, 10, 12, 14], [6, 8, 10, 12, 14], [7, 9, 11, 13, 15]]\n assert candidate(image = [[1, 255, 1, 255, 1], [255, 1, 255, 1, 255], [1, 255, 1, 255, 1], [255, 1, 255, 1, 255], [1, 255, 1, 255, 1]],threshold = 128) == [[1, 255, 1, 255, 1], [255, 1, 255, 1, 255], [1, 255, 1, 255, 1], [255, 1, 255, 1, 255], [1, 255, 1, 255, 1]]\n assert candidate(image = [[50, 51, 52, 53, 54, 55], [51, 52, 53, 54, 55, 56], [52, 53, 54, 55, 56, 57], [53, 54, 55, 56, 57, 58], [54, 55, 56, 57, 58, 59], [55, 56, 57, 58, 59, 60]],threshold = 2) == [[52, 52, 53, 54, 54, 55], [52, 53, 53, 54, 55, 55], [53, 53, 54, 55, 55, 56], [54, 54, 55, 56, 56, 57], [54, 55, 55, 56, 57, 57], [55, 55, 56, 57, 57, 58]]\n assert candidate(image = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],threshold = 1) == [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]\n assert candidate(image = [[50, 50, 50, 50, 50, 50], [50, 55, 55, 55, 55, 50], [50, 55, 60, 60, 55, 50], [50, 55, 60, 65, 55, 50], [50, 55, 60, 60, 55, 50], [50, 55, 55, 55, 55, 50], [50, 50, 50, 50, 50, 50]],threshold = 5) == [[52, 53, 53, 53, 53, 52], [53, 54, 54, 54, 53, 52], [53, 55, 54, 55, 53, 52], [54, 55, 55, 57, 55, 50], [53, 55, 54, 55, 53, 52], [53, 54, 54, 54, 53, 52], [52, 53, 53, 53, 53, 52]]\n assert candidate(image = [[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]],threshold = 1) == [[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]]\n assert candidate(image = [[255, 0, 255, 0, 255, 0], [0, 255, 0, 255, 0, 255], [255, 0, 255, 0, 255, 0], [0, 255, 0, 255, 0, 255], [255, 0, 255, 0, 255, 0], [0, 255, 0, 255, 0, 255]],threshold = 0) == [[255, 0, 255, 0, 255, 0], [0, 255, 0, 255, 0, 255], [255, 0, 255, 0, 255, 0], [0, 255, 0, 255, 0, 255], [255, 0, 255, 0, 255, 0], [0, 255, 0, 255, 0, 255]]\n assert candidate(image = [[10, 15, 20, 25, 30], [15, 20, 25, 30, 35], [20, 25, 30, 35, 40], [25, 30, 35, 40, 45], [30, 35, 40, 45, 50]],threshold = 5) == [[20, 22, 25, 27, 30], [22, 25, 27, 30, 32], [25, 27, 30, 32, 35], [27, 30, 32, 35, 37], [30, 32, 35, 37, 40]]\n assert candidate(image = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 4, 5, 6, 7, 8, 9, 10, 11], [4, 5, 6, 7, 8, 9, 10, 11, 12], [5, 6, 7, 8, 9, 10, 11, 12, 13], [6, 7, 8, 9, 10, 11, 12, 13, 14], [7, 8, 9, 10, 11, 12, 13, 14, 15]],threshold = 1) == [[3, 3, 4, 5, 6, 7, 8, 8, 9], [3, 4, 4, 5, 6, 7, 8, 9, 9], [4, 4, 5, 6, 7, 8, 9, 9, 10], [5, 5, 6, 7, 8, 9, 10, 10, 11], [6, 6, 7, 8, 9, 10, 11, 11, 12], [6, 7, 7, 8, 9, 10, 11, 12, 12], [7, 7, 8, 9, 10, 11, 12, 12, 13]]\n assert candidate(image = [[0, 10, 20, 30, 40, 50], [10, 20, 30, 40, 50, 60], [20, 30, 40, 50, 60, 70], [30, 40, 50, 60, 70, 80], [40, 50, 60, 70, 80, 90], [50, 60, 70, 80, 90, 100]],threshold = 15) == [[20, 25, 30, 40, 45, 50], [25, 30, 35, 45, 50, 55], [30, 35, 40, 50, 55, 60], [40, 45, 50, 60, 65, 70], [45, 50, 55, 65, 70, 75], [50, 55, 60, 70, 75, 80]]\n assert candidate(image = [[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]],threshold = 10) == [[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]]\n assert candidate(image = [[50, 51, 52, 53, 54, 55, 56], [51, 52, 53, 54, 55, 56, 57], [52, 53, 54, 55, 56, 57, 58], [53, 54, 55, 56, 57, 58, 59], [54, 55, 56, 57, 58, 59, 60]],threshold = 2) == [[52, 52, 53, 54, 55, 55, 56], [52, 53, 53, 54, 55, 56, 56], [53, 53, 54, 55, 56, 56, 57], [53, 54, 54, 55, 56, 57, 57], [54, 54, 55, 56, 57, 57, 58]]\n assert candidate(image = [[50, 51, 52, 53, 54], [51, 52, 53, 54, 55], [52, 53, 54, 55, 56], [53, 54, 55, 56, 57], [54, 55, 56, 57, 58]],threshold = 3) == [[52, 52, 53, 53, 54], [52, 53, 53, 54, 54], [53, 53, 54, 54, 55], [53, 54, 54, 55, 55], [54, 54, 55, 55, 56]]\n assert candidate(image = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 4, 5, 6, 7, 8, 9, 10, 11], [4, 5, 6, 7, 8, 9, 10, 11, 12]],threshold = 1) == [[3, 3, 4, 5, 6, 7, 8, 8, 9], [3, 4, 4, 5, 6, 7, 8, 9, 9], [3, 4, 4, 5, 6, 7, 8, 9, 9], [4, 4, 5, 6, 7, 8, 9, 9, 10]]\n assert candidate(image = [[10, 20, 30, 40, 50, 60, 70], [20, 30, 40, 50, 60, 70, 80], [30, 40, 50, 60, 70, 80, 90], [40, 50, 60, 70, 80, 90, 100], [50, 60, 70, 80, 90, 100, 110], [60, 70, 80, 90, 100, 110, 120]],threshold = 10) == [[30, 35, 40, 50, 60, 65, 70], [35, 40, 45, 55, 65, 70, 75], [40, 45, 50, 60, 70, 75, 80], [50, 55, 60, 70, 80, 85, 90], [55, 60, 65, 75, 85, 90, 95], [60, 65, 70, 80, 90, 95, 100]]\n assert candidate(image = [[10, 15, 20, 25, 30], [12, 17, 22, 27, 32], [14, 19, 24, 29, 34], [16, 21, 26, 31, 36], [18, 23, 28, 33, 38]],threshold = 5) == [[17, 19, 22, 24, 27], [18, 20, 23, 25, 28], [19, 21, 24, 26, 29], [20, 22, 25, 27, 30], [21, 23, 26, 28, 31]]\n assert candidate(image = [[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, 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, 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, 10, 10, 10, 10, 10, 10, 10]],threshold = 100) == [[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, 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, 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, 10, 10, 10, 10, 10, 10, 10]]\n assert candidate(image = [[20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20]],threshold = 0) == [[20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20], [20, 20, 20, 20, 20, 20, 20, 20, 20]]\n assert candidate(image = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]],threshold = 1) == [[3, 3, 3], [3, 3, 3], [4, 4, 4], [4, 4, 4], [5, 5, 5]]\n assert candidate(image = [[10, 10, 10, 10, 10], [10, 20, 20, 20, 10], [10, 20, 30, 20, 10], [10, 20, 20, 20, 10], [10, 10, 10, 10, 10]],threshold = 10) == [[15, 16, 15, 16, 15], [16, 17, 17, 17, 16], [15, 17, 16, 17, 15], [16, 17, 17, 17, 16], [15, 16, 15, 16, 15]]\n assert candidate(image = [[5, 15, 25, 35, 45, 55], [10, 20, 30, 40, 50, 60], [15, 25, 35, 45, 55, 65], [20, 30, 40, 50, 60, 70], [25, 35, 45, 55, 65, 75]],threshold = 5) == [[5, 15, 25, 35, 45, 55], [10, 20, 30, 40, 50, 60], [15, 25, 35, 45, 55, 65], [20, 30, 40, 50, 60, 70], [25, 35, 45, 55, 65, 75]]\n assert candidate(image = [[128, 129, 130, 131, 132], [129, 130, 131, 132, 133], [130, 131, 132, 133, 134], [131, 132, 133, 134, 135], [132, 133, 134, 135, 136]],threshold = 3) == [[130, 130, 131, 131, 132], [130, 131, 131, 132, 132], [131, 131, 132, 132, 133], [131, 132, 132, 133, 133], [132, 132, 133, 133, 134]]\n assert candidate(image = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70]],threshold = 5) == [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70]]\n assert candidate(image = [[50, 55, 60, 65, 70], [55, 60, 65, 70, 75], [60, 65, 70, 75, 80], [65, 70, 75, 80, 85], [70, 75, 80, 85, 90]],threshold = 5) == [[60, 62, 65, 67, 70], [62, 65, 67, 70, 72], [65, 67, 70, 72, 75], [67, 70, 72, 75, 77], [70, 72, 75, 77, 80]]\n assert candidate(image = [[50, 60, 70, 80, 90], [60, 70, 80, 90, 100], [70, 80, 90, 100, 110], [80, 90, 100, 110, 120], [90, 100, 110, 120, 130]],threshold = 10) == [[70, 75, 80, 85, 90], [75, 80, 85, 90, 95], [80, 85, 90, 95, 100], [85, 90, 95, 100, 105], [90, 95, 100, 105, 110]]\n assert candidate(image = [[50, 51, 52, 53, 54, 55], [51, 52, 53, 54, 55, 56], [52, 53, 54, 55, 56, 57], [53, 54, 55, 56, 57, 58], [54, 55, 56, 57, 58, 59], [55, 56, 57, 58, 59, 60]],threshold = 2) == [[52, 52, 53, 54, 54, 55], [52, 53, 53, 54, 55, 55], [53, 53, 54, 55, 55, 56], [54, 54, 55, 56, 56, 57], [54, 55, 55, 56, 57, 57], [55, 55, 56, 57, 57, 58]]\n assert candidate(image = [[50, 50, 50, 100, 100, 100], [50, 50, 50, 100, 100, 100], [50, 50, 50, 100, 100, 100], [100, 100, 100, 150, 150, 150], [100, 100, 100, 150, 150, 150], [100, 100, 100, 150, 150, 150]],threshold = 50) == [[50, 58, 66, 83, 91, 100], [58, 66, 74, 91, 99, 108], [66, 74, 83, 99, 108, 116], [83, 91, 99, 116, 124, 133], [91, 99, 108, 124, 133, 141], [100, 108, 116, 133, 141, 150]]\n assert candidate(image = [[1, 2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 7, 8], [3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 10], [5, 6, 7, 8, 9, 10, 11]],threshold = 1) == [[3, 3, 4, 5, 6, 6, 7], [3, 4, 4, 5, 6, 7, 7], [4, 4, 5, 6, 7, 7, 8], [4, 5, 5, 6, 7, 8, 8], [5, 5, 6, 7, 8, 8, 9]]\n assert candidate(image = [[255, 255, 255, 0, 0, 0], [255, 255, 255, 0, 0, 0], [255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255], [0, 0, 0, 255, 255, 255], [0, 0, 0, 255, 255, 255]],threshold = 255) == [[255, 212, 170, 85, 42, 0], [212, 184, 155, 99, 70, 42], [170, 155, 141, 113, 99, 85], [85, 99, 113, 141, 155, 170], [42, 70, 99, 155, 184, 212], [0, 42, 85, 170, 212, 255]]\n assert candidate(image = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65], [30, 40, 50, 60, 70]],threshold = 10) == [[25, 30, 35, 40, 45], [27, 32, 37, 42, 47], [30, 35, 40, 45, 50], [32, 37, 42, 47, 52], [35, 40, 45, 50, 55]]\n assert candidate(image = [[100, 200, 100, 200], [200, 100, 200, 100], [100, 200, 100, 200], [200, 100, 200, 100]],threshold = 50) == [[100, 200, 100, 200], [200, 100, 200, 100], [100, 200, 100, 200], [200, 100, 200, 100]]\n assert candidate(image = [[10, 20, 30], [15, 25, 35], [20, 30, 40], [25, 35, 45], [30, 40, 50], [35, 45, 55]],threshold = 15) == [[25, 25, 25], [27, 27, 27], [30, 30, 30], [35, 35, 35], [37, 37, 37], [40, 40, 40]]\n assert candidate(image = [[255, 254, 253, 252, 251], [254, 253, 252, 251, 250], [253, 252, 251, 250, 249], [252, 251, 250, 249, 248], [251, 250, 249, 248, 247]],threshold = 5) == [[253, 252, 252, 251, 251], [252, 252, 251, 251, 250], [252, 251, 251, 250, 250], [251, 251, 250, 250, 249], [251, 250, 250, 249, 249]]\n assert candidate(image = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 4, 5, 6, 7, 8, 9, 10, 11], [4, 5, 6, 7, 8, 9, 10, 11, 12], [5, 6, 7, 8, 9, 10, 11, 12, 13]],threshold = 2) == [[3, 3, 4, 5, 6, 7, 8, 8, 9], [3, 4, 4, 5, 6, 7, 8, 9, 9], [4, 4, 5, 6, 7, 8, 9, 9, 10], [4, 5, 5, 6, 7, 8, 9, 10, 10], [5, 5, 6, 7, 8, 9, 10, 10, 11]]\n assert candidate(image = [[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]],threshold = 0) == [[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]]\n assert candidate(image = [[128, 130, 128, 130, 128], [130, 132, 130, 132, 130], [128, 130, 128, 130, 128], [130, 132, 130, 132, 130], [128, 130, 128, 130, 128]],threshold = 2) == [[129, 129, 129, 129, 129], [129, 129, 129, 129, 129], [129, 129, 129, 129, 129], [129, 129, 129, 129, 129], [129, 129, 129, 129, 129]]\n assert candidate(image = [[255, 255, 255, 255, 255], [255, 250, 245, 240, 235], [255, 245, 240, 235, 230], [255, 240, 235, 230, 225], [255, 235, 230, 225, 220]],threshold = 10) == [[250, 250, 250, 255, 255], [250, 245, 241, 237, 235], [250, 241, 238, 235, 232], [255, 237, 235, 235, 232], [255, 235, 232, 232, 230]]\n assert candidate(image = [[200, 201, 202, 203], [201, 202, 203, 204], [202, 203, 204, 205], [203, 204, 205, 206], [204, 205, 206, 207], [205, 206, 207, 208]],threshold = 5) == [[202, 202, 202, 203], [202, 203, 203, 203], [203, 203, 203, 204], [204, 204, 204, 205], [204, 205, 205, 205], [205, 205, 205, 206]]\n assert candidate(image = [[255, 255, 255, 0, 0, 0], [255, 255, 255, 0, 0, 0], [255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255], [0, 0, 0, 255, 255, 255], [0, 0, 0, 255, 255, 255]],threshold = 254) == [[255, 255, 255, 0, 0, 0], [255, 255, 255, 0, 0, 0], [255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255], [0, 0, 0, 255, 255, 255], [0, 0, 0, 255, 255, 255]]\n assert candidate(image = [[100, 100, 100, 100, 100], [100, 200, 200, 200, 100], [100, 200, 255, 200, 100], [100, 200, 200, 200, 100], [100, 100, 100, 100, 100]],threshold = 100) == [[150, 161, 157, 161, 150], [161, 175, 170, 175, 161], [157, 170, 166, 170, 157], [161, 175, 170, 175, 161], [150, 161, 157, 161, 150]]\n assert candidate(image = [[0, 127, 255, 127, 0], [127, 255, 127, 0, 127], [255, 127, 0, 127, 255], [127, 0, 127, 255, 127], [0, 127, 255, 127, 0]],threshold = 127) == [[0, 127, 255, 127, 0], [127, 255, 127, 0, 127], [255, 127, 0, 127, 255], [127, 0, 127, 255, 127], [0, 127, 255, 127, 0]]\n assert candidate(image = [[128, 128, 128, 128, 128], [128, 128, 128, 128, 128], [128, 128, 128, 128, 128], [128, 128, 128, 128, 128], [128, 128, 128, 128, 128]],threshold = 0) == [[128, 128, 128, 128, 128], [128, 128, 128, 128, 128], [128, 128, 128, 128, 128], [128, 128, 128, 128, 128], [128, 128, 128, 128, 128]]\n assert candidate(image = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65], [30, 40, 50, 60, 70]],threshold = 25) == [[25, 30, 35, 40, 45], [27, 32, 37, 42, 47], [30, 35, 40, 45, 50], [32, 37, 42, 47, 52], [35, 40, 45, 50, 55]]\n assert candidate(image = [[10, 20, 30, 40, 50], [20, 30, 40, 50, 60], [30, 40, 50, 60, 70], [40, 50, 60, 70, 80], [50, 60, 70, 80, 90]],threshold = 10) == [[30, 35, 40, 45, 50], [35, 40, 45, 50, 55], [40, 45, 50, 55, 60], [45, 50, 55, 60, 65], [50, 55, 60, 65, 70]]\n assert candidate(image = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 4, 5, 6, 7, 8, 9, 10, 11], [4, 5, 6, 7, 8, 9, 10, 11, 12], [5, 6, 7, 8, 9, 10, 11, 12, 13], [6, 7, 8, 9, 10, 11, 12, 13, 14], [7, 8, 9, 10, 11, 12, 13, 14, 15], [8, 9, 10, 11, 12, 13, 14, 15, 16], [9, 10, 11, 12, 13, 14, 15, 16, 17]],threshold = 1) == [[3, 3, 4, 5, 6, 7, 8, 8, 9], [3, 4, 4, 5, 6, 7, 8, 9, 9], [4, 4, 5, 6, 7, 8, 9, 9, 10], [5, 5, 6, 7, 8, 9, 10, 10, 11], [6, 6, 7, 8, 9, 10, 11, 11, 12], [7, 7, 8, 9, 10, 11, 12, 12, 13], [8, 8, 9, 10, 11, 12, 13, 13, 14], [8, 9, 9, 10, 11, 12, 13, 14, 14], [9, 9, 10, 11, 12, 13, 14, 14, 15]]\n assert candidate(image = [[255, 254, 253, 252, 251], [254, 253, 252, 251, 250], [253, 252, 251, 250, 249], [252, 251, 250, 249, 248], [251, 250, 249, 248, 247]],threshold = 1) == [[253, 252, 252, 251, 251], [252, 252, 251, 251, 250], [252, 251, 251, 250, 250], [251, 251, 250, 250, 249], [251, 250, 250, 249, 249]]\n assert candidate(image = [[30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30]],threshold = 0) == [[30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30]]\n assert candidate(image = [[255, 255, 255], [255, 0, 255], [255, 255, 255]],threshold = 100) == [[255, 255, 255], [255, 0, 255], [255, 255, 255]]\n assert candidate(image = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]],threshold = 0) == [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]\n assert candidate(image = [[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, 61, 62, 63], [64, 65, 66, 67, 68, 69, 70, 71, 72], [73, 74, 75, 76, 77, 78, 79, 80, 81]],threshold = 5) == [[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, 61, 62, 63], [64, 65, 66, 67, 68, 69, 70, 71, 72], [73, 74, 75, 76, 77, 78, 79, 80, 81]]\n assert candidate(image = [[100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100]],threshold = 0) == [[100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100], [100, 100, 100, 100, 100]]\n assert candidate(image = [[255, 254, 253, 252, 251, 250, 249, 248, 247], [254, 253, 252, 251, 250, 249, 248, 247, 246], [253, 252, 251, 250, 249, 248, 247, 246, 245], [252, 251, 250, 249, 248, 247, 246, 245, 244], [251, 250, 249, 248, 247, 246, 245, 244, 243], [250, 249, 248, 247, 246, 245, 244, 243, 242], [249, 248, 247, 246, 245, 244, 243, 242, 241], [248, 247, 246, 245, 244, 243, 242, 241, 240], [247, 246, 245, 244, 243, 242, 241, 240, 239]],threshold = 2) == [[253, 252, 252, 251, 250, 249, 248, 247, 247], [252, 252, 251, 250, 249, 248, 247, 247, 246], [252, 251, 251, 250, 249, 248, 247, 246, 246], [251, 250, 250, 249, 248, 247, 246, 245, 245], [250, 249, 249, 248, 247, 246, 245, 244, 244], [249, 248, 248, 247, 246, 245, 244, 243, 243], [248, 247, 247, 246, 245, 244, 243, 242, 242], [247, 247, 246, 245, 244, 243, 242, 242, 241], [247, 246, 246, 245, 244, 243, 242, 241, 241]]\n assert candidate(image = [[5, 10, 15, 20, 25], [10, 15, 20, 25, 30], [15, 20, 25, 30, 35], [20, 25, 30, 35, 40], [25, 30, 35, 40, 45]],threshold = 10) == [[15, 17, 20, 22, 25], [17, 20, 22, 25, 27], [20, 22, 25, 27, 30], [22, 25, 27, 30, 32], [25, 27, 30, 32, 35]]\n assert candidate(image = [[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]],threshold = 0) == [[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]]\n assert candidate(image = [[50, 50, 50, 50, 50], [50, 55, 60, 65, 70], [50, 60, 70, 80, 90], [50, 65, 80, 95, 110], [50, 70, 90, 110, 130]],threshold = 10) == [[55, 55, 55, 50, 50], [55, 55, 55, 65, 70], [55, 55, 55, 80, 90], [50, 65, 80, 95, 110], [50, 70, 90, 110, 130]]\n assert candidate(image = [[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]],threshold = 1) == [[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]]\n assert candidate(image = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70]],threshold = 10) == [[30, 35, 35, 40], [35, 40, 40, 45], [35, 40, 40, 45], [40, 45, 45, 50]]\n assert candidate(image = [[10, 11, 12, 13, 14, 15], [11, 12, 13, 14, 15, 16], [12, 13, 14, 15, 16, 17], [13, 14, 15, 16, 17, 18], [14, 15, 16, 17, 18, 19], [15, 16, 17, 18, 19, 20]],threshold = 3) == [[12, 12, 13, 14, 14, 15], [12, 13, 13, 14, 15, 15], [13, 13, 14, 15, 15, 16], [14, 14, 15, 16, 16, 17], [14, 15, 15, 16, 17, 17], [15, 15, 16, 17, 17, 18]]\n assert candidate(image = [[200, 205, 210, 215, 220], [205, 210, 215, 220, 225], [210, 215, 220, 225, 230], [215, 220, 225, 230, 235], [220, 225, 230, 235, 240]],threshold = 5) == [[210, 212, 215, 217, 220], [212, 215, 217, 220, 222], [215, 217, 220, 222, 225], [217, 220, 222, 225, 227], [220, 222, 225, 227, 230]]\n assert candidate(image = [[10, 10, 10], [10, 10, 10], [10, 10, 10], [10, 10, 10]],threshold = 0) == [[10, 10, 10], [10, 10, 10], [10, 10, 10], [10, 10, 10]]\n assert candidate(image = [[5, 10, 15, 20, 25, 30], [10, 15, 20, 25, 30, 35], [15, 20, 25, 30, 35, 40], [20, 25, 30, 35, 40, 45], [25, 30, 35, 40, 45, 50], [30, 35, 40, 45, 50, 55]],threshold = 5) == [[15, 17, 20, 25, 27, 30], [17, 20, 22, 27, 30, 32], [20, 22, 25, 30, 32, 35], [25, 27, 30, 35, 37, 40], [27, 30, 32, 37, 40, 42], [30, 32, 35, 40, 42, 45]]\n assert candidate(image = [[5, 10, 15, 20, 25], [10, 15, 20, 25, 30], [15, 20, 25, 30, 35], [20, 25, 30, 35, 40], [25, 30, 35, 40, 45]],threshold = 5) == [[15, 17, 20, 22, 25], [17, 20, 22, 25, 27], [20, 22, 25, 27, 30], [22, 25, 27, 30, 32], [25, 27, 30, 32, 35]]\n assert candidate(image = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 2, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]],threshold = 1) == [[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]]\n assert candidate(image = [[1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8], [4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 10], [6, 7, 8, 9, 10, 11]],threshold = 2) == [[3, 3, 4, 5, 5, 6], [3, 4, 4, 5, 6, 6], [4, 4, 5, 6, 6, 7], [5, 5, 6, 7, 7, 8], [5, 6, 6, 7, 8, 8], [6, 6, 7, 8, 8, 9]]\n", "comparison": "exact"}, "public_tests": ["[[5,6,7,10],[8,9,10,10],[11,12,13,10]]\n3", "[[10,20,30],[15,25,35],[20,30,40],[25,35,45]]\n12", "[[5,6,7],[8,9,10],[11,12,13]]\n1"], "hints": ["Try all the 3 * 3 sub-grids to find all the regions.", "Keep two 2-D arrays sum and num, for each position (x, y) in a region, increase sum[x][y] by the average sum of the region and increase num[x][y] by 1.", "For each position (x, y), sum[x][y] / num[x][y] is the answer. Note when num[x][y] == 0, we use the original value in image instead."], "metadata": {"canonical_parameter_names": ["image", "threshold"], "leetcode_dataset_entry_point": "Solution().resultGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:57+00:00", "tests_total": 90, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def result_grid(image, threshold)", "container": null, "callable": "result_grid", "parameters": [{"name": "image", "type": "Integer[][]"}, {"name": "threshold", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3031, "task_id": "minimum-time-to-revert-word-to-initial-state-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed string word and an integer k.\n\nAt every second, you must perform the following operations:\n\n- Remove the first k characters of word.\n- Add any k characters to the end of word.\n\nNote that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.\n\nReturn the minimum time greater than zero required for word to revert to its initial state.\n\nExample 1:\n\nInput: word = \"abacaba\", k = 3\nOutput: 2\nExplanation: At the 1st second, we remove characters \"aba\" from the prefix of word, and add characters \"bac\" to the end of word. Thus, word becomes equal to \"cababac\".\nAt the 2nd second, we remove characters \"cab\" from the prefix of word, and add \"aba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\nIt can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.\n\nExample 2:\n\nInput: word = \"abacaba\", k = 4\nOutput: 1\nExplanation: At the 1st second, we remove characters \"abac\" from the prefix of word, and add characters \"caba\" to the end of word. Thus, word becomes equal to \"abacaba\" and reverts to its initial state.\nIt can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.\n\nExample 3:\n\nInput: word = \"abcbabcd\", k = 2\nOutput: 4\nExplanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.\nAfter 4 seconds, word becomes equal to \"abcbabcd\" and reverts to its initial state.\nIt can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.\n\nConstraints:\n\n- 1 <= word.length <= 10^6\n- 1 <= k <= word.length\n- word consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"abcdefgh\",k = 2) == 4\n assert candidate(word = \"xyz\",k = 1) == 3\n assert candidate(word = \"zzzzzz\",k = 2) == 1\n assert candidate(word = \"abcdabcd\",k = 4) == 1\n assert candidate(word = \"abacaba\",k = 3) == 2\n assert candidate(word = \"abcabcabc\",k = 1) == 3\n assert candidate(word = \"abcdefg\",k = 7) == 1\n assert candidate(word = \"abacaba\",k = 4) == 1\n assert candidate(word = \"aabbccddeeff\",k = 2) == 6\n assert candidate(word = \"zzzzzzzzzzzz\",k = 5) == 1\n assert candidate(word = \"a\",k = 1) == 1\n assert candidate(word = \"repeatrepeat\",k = 6) == 1\n assert candidate(word = \"abcabcabcabc\",k = 3) == 1\n assert candidate(word = \"abcabcabc\",k = 3) == 1\n assert candidate(word = \"abcdabcd\",k = 2) == 2\n assert candidate(word = \"hellohello\",k = 5) == 1\n assert candidate(word = \"aaaa\",k = 1) == 1\n assert candidate(word = \"abcdabcdabcd\",k = 4) == 1\n assert candidate(word = \"aaaa\",k = 2) == 1\n assert candidate(word = \"abcbabcd\",k = 2) == 4\n assert candidate(word = \"abcdef\",k = 6) == 1\n assert candidate(word = \"aaaaabbbbbccccddddaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 15) == 5\n assert candidate(word = \"abcabcabcabcabcabcabcabc\",k = 7) == 3\n assert candidate(word = \"abcdefgabcdefg\",k = 7) == 1\n assert candidate(word = \"aaaabbbbccccddddeeeeffff\",k = 4) == 6\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiopqwerty\",k = 11) == 4\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",k = 10) == 1\n assert candidate(word = \"abacabadabacabadabacabad\",k = 5) == 5\n assert candidate(word = \"abacabadabacabad\",k = 3) == 6\n assert candidate(word = \"abcdeabcdeabcdeabcdeabcde\",k = 6) == 5\n assert candidate(word = \"ababababababababababababababababababababababababab\",k = 3) == 2\n assert candidate(word = \"ababababababab\",k = 4) == 1\n assert candidate(word = \"abcdefgabcdefgabcdefg\",k = 7) == 1\n assert candidate(word = \"samepatterneverywhereeverywhereeverywhere\",k = 11) == 4\n assert candidate(word = \"hellohellohellohellohellohello\",k = 6) == 5\n assert candidate(word = \"abababababababababababababab\",k = 10) == 1\n assert candidate(word = \"abababababababab\",k = 4) == 1\n assert candidate(word = \"aaaaaabaaaaa\",k = 3) == 3\n assert candidate(word = \"abacabadabacabad\",k = 6) == 3\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 13) == 4\n assert candidate(word = \"zzzzzzzzzzzzzzzzzz\",k = 7) == 1\n assert candidate(word = \"hellohellohellohellohello\",k = 7) == 4\n assert candidate(word = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\",k = 9) == 8\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabc\",k = 10) == 3\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcd\",k = 8) == 1\n assert candidate(word = \"xyzxyzxyzxyz\",k = 5) == 3\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 26) == 1\n assert candidate(word = \"hellohellohellohellohello\",k = 5) == 1\n assert candidate(word = \"aaaaaabbbbbbcccccc\",k = 3) == 6\n assert candidate(word = \"aaaaabbbbbcccc\",k = 5) == 3\n assert candidate(word = \"abacabadabacabadabacabadabacabadaba\",k = 7) == 5\n assert candidate(word = \"xyzxyzxyzxyzxyzxyzxyzxyz\",k = 7) == 3\n assert candidate(word = \"abcabcabcabcabcabc\",k = 5) == 3\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzz\",k = 2) == 1\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",k = 2) == 1\n assert candidate(word = \"abababababab\",k = 4) == 1\n assert candidate(word = \"abcdefgabcdefgabcdefgabcdefgabcdefg\",k = 9) == 4\n assert candidate(word = \"ababababababababababab\",k = 5) == 2\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabc\",k = 7) == 3\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiop\",k = 9) == 4\n assert candidate(word = \"zyxzyxzyxzyxzyxzyxzyxzyx\",k = 6) == 1\n assert candidate(word = \"xyzxyzxyzxyzxyzxyz\",k = 6) == 1\n assert candidate(word = \"abcdefabcdefabcdef\",k = 6) == 1\n assert candidate(word = \"ababababababababababababababababababa\",k = 1) == 2\n assert candidate(word = \"abcdefabcdefabcdefabcdefabcdefabcdef\",k = 3) == 2\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 10) == 6\n assert candidate(word = \"abcabcabcabcabc\",k = 6) == 1\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabc\",k = 9) == 1\n assert candidate(word = \"banana\",k = 2) == 3\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 13) == 2\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",k = 13) == 2\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 12) == 1\n assert candidate(word = \"abcdefgabcdefgabcdefgabcdefg\",k = 5) == 6\n assert candidate(word = \"xyzxyzxyzxyz\",k = 2) == 3\n assert candidate(word = \"zzzzzzzzzzzzzzzzzz\",k = 9) == 1\n assert candidate(word = \"abacabadabacabadabacabadabacabadaba\",k = 8) == 1\n assert candidate(word = \"ababababababababababababababababababa\",k = 6) == 1\n assert candidate(word = \"abacabadabacabadabacabadabacabadabacabadabacabad\",k = 6) == 4\n assert candidate(word = \"aaaaaaa\",k = 2) == 1\n assert candidate(word = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\",k = 4) == 3\n assert candidate(word = \"aabbaabbaabbaabbaabbaabb\",k = 3) == 4\n assert candidate(word = \"abcdefghijabcdefghijabcdefghij\",k = 10) == 1\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 26) == 2\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghij\",k = 10) == 1\n assert candidate(word = \"abacabadabacabadabacabad\",k = 4) == 2\n assert candidate(word = \"xyzxyzxyzxyzxyzxyz\",k = 5) == 3\n assert candidate(word = \"repeatrepeatrepeatrepeatrepeat\",k = 3) == 2\n assert candidate(word = \"abababababab\",k = 1) == 2\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabc\",k = 5) == 3\n assert candidate(word = \"abracadabraabracadabraabracadabra\",k = 7) == 5\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 12) == 1\n assert candidate(word = \"repeatedrepeatedrepeated\",k = 7) == 4\n assert candidate(word = \"abcdabcdabcdabcdabcd\",k = 8) == 1\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",k = 25) == 2\n assert candidate(word = \"abababababababab\",k = 5) == 2\n assert candidate(word = \"aabbccddeeffgghhiijjkkll\",k = 11) == 3\n assert candidate(word = \"mississippimississippimississippi\",k = 4) == 9\n assert candidate(word = \"abacabadabacaba\",k = 3) == 4\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",k = 13) == 6\n assert candidate(word = \"abcdabcdabcdabcd\",k = 5) == 4\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 15) == 1\n assert candidate(word = \"mississippi\",k = 4) == 3\n assert candidate(word = \"abacabadabacabadabacabadabacabadaba\",k = 10) == 4\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 15) == 4\n assert candidate(word = \"abcabcabcabcabcabcabcabc\",k = 8) == 3\n assert candidate(word = \"abcabcabcabcabcabcabcabc\",k = 9) == 1\n assert candidate(word = \"abababababab\",k = 2) == 1\n assert candidate(word = \"abcabcabcabcabcabcabcabc\",k = 4) == 3\n", "comparison": "exact"}, "public_tests": ["\"abacaba\"\n3", "\"abacaba\"\n4", "\"abcbabcd\"\n2"], "hints": ["Find the longest suffix which is also a prefix and whose length is a multiple of K in O(N).", "Use Z-function."], "metadata": {"canonical_parameter_names": ["word", "k"], "leetcode_dataset_entry_point": "Solution().minimumTimeToInitialState", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:10:59+00:00", "tests_total": 108, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "rolling-hash", "string-matching", "hash-function"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_time_to_initial_state(word, k)", "container": null, "callable": "minimum_time_to_initial_state", "parameters": [{"name": "word", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3033, "task_id": "modify-the-matrix", "difficulty": "Easy", "problem_description": "Given a 0-indexed m x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column.\n\nReturn the matrix answer.\n\nExample 1:\n\nInput: matrix = [[1,2,-1],[4,-1,6],[7,8,9]]\nOutput: [[1,2,9],[4,8,6],[7,8,9]]\nExplanation: The diagram above shows the elements that are changed (in blue).\n- We replace the value in the cell [1][1] with the maximum value in the column 1, that is 8.\n- We replace the value in the cell [0][2] with the maximum value in the column 2, that is 9.\n\nExample 2:\n\nInput: matrix = [[3,-1],[5,2]]\nOutput: [[3,2],[5,2]]\nExplanation: The diagram above shows the elements that are changed (in blue).\n\nConstraints:\n\n- m == matrix.length\n- n == matrix[i].length\n- 2 <= m, n <= 50\n- -1 <= matrix[i][j] <= 100\n- The input is generated such that each column contains at least one non-negative integer.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[3, -1], [5, 2]]) == [[3, 2], [5, 2]]\n assert candidate(matrix = [[1, 2, -1], [4, -1, 6], [7, 8, 9]]) == [[1, 2, 9], [4, 8, 6], [7, 8, 9]]\n assert candidate(matrix = [[-1, -1], [-1, -1], [-1, -1], [2, 2]]) == [[2, 2], [2, 2], [2, 2], [2, 2]]\n assert candidate(matrix = [[10, -1, 10], [-1, -1, -1], [10, 10, 10]]) == [[10, 10, 10], [10, 10, 10], [10, 10, 10]]\n assert candidate(matrix = [[10, 20, -1], [30, -1, 40], [50, 60, 70]]) == [[10, 20, 70], [30, 60, 40], [50, 60, 70]]\n assert candidate(matrix = [[100, -1, -1], [-1, -1, -1], [-1, -1, -1]]) == [[100, -1, -1], [100, -1, -1], [100, -1, -1]]\n assert candidate(matrix = [[-1, 4, 5], [-1, 6, 7], [8, 9, -1]]) == [[8, 4, 5], [8, 6, 7], [8, 9, 7]]\n assert candidate(matrix = [[-1, 0, -1], [2, 3, -1], [4, -1, 5]]) == [[4, 0, 5], [2, 3, 5], [4, 3, 5]]\n assert candidate(matrix = [[5, 6, 7], [8, 9, -1], [-1, -1, -1]]) == [[5, 6, 7], [8, 9, 7], [8, 9, 7]]\n assert candidate(matrix = [[1, 2, 3], [4, 5, 6], [-1, -1, -1]]) == [[1, 2, 3], [4, 5, 6], [4, 5, 6]]\n assert candidate(matrix = [[0, -1, 2], [-1, 1, -1], [3, -1, 4]]) == [[0, 1, 2], [3, 1, 4], [3, 1, 4]]\n assert candidate(matrix = [[-1, 1], [-1, 2], [-1, 3]]) == [[-1, 1], [-1, 2], [-1, 3]]\n assert candidate(matrix = [[0, -1, -1], [-1, -1, 0], [-1, 0, -1]]) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n assert candidate(matrix = [[0, -1, 0], [-1, -1, -1], [0, -1, 0]]) == [[0, -1, 0], [0, -1, 0], [0, -1, 0]]\n assert candidate(matrix = [[1, -1, -1], [2, -1, 3], [-1, 4, -1]]) == [[1, 4, 3], [2, 4, 3], [2, 4, 3]]\n assert candidate(matrix = [[-1, -1, -1], [1, 2, 3], [4, 5, 6]]) == [[4, 5, 6], [1, 2, 3], [4, 5, 6]]\n assert candidate(matrix = [[-1, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, -1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, -1, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, -1, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, -1, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, -1, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, -1, 7, 8, 9]]) == [[10, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 6, 7, 8, 9]]\n assert candidate(matrix = [[-1, -1, -1, -1, -1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [9, 8, 7, 6, 5]]) == [[9, 8, 7, 6, 5], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [9, 8, 7, 6, 5]]\n assert candidate(matrix = [[-1, 3, -1, 4], [-1, -1, -1, 8], [7, 6, -1, 9]]) == [[7, 3, -1, 4], [7, 6, -1, 8], [7, 6, -1, 9]]\n assert candidate(matrix = [[-1, 10, -1, -1], [12, -1, 14, -1], [-1, 16, -1, 18], [20, -1, -1, -1]]) == [[20, 10, 14, 18], [12, 16, 14, 18], [20, 16, 14, 18], [20, 16, 14, 18]]\n assert candidate(matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, -1, -1, -1]]) == [[1, 2, 3, 4], [5, 6, 7, 8], [9, 6, 7, 8]]\n assert candidate(matrix = [[-1, -1, -1, -1], [-1, -1, -1, -1], [1, 2, 3, 4], [5, 6, 7, 8]]) == [[5, 6, 7, 8], [5, 6, 7, 8], [1, 2, 3, 4], [5, 6, 7, 8]]\n assert candidate(matrix = [[-1, 3, -1, 5, -1, 7, -1, 9], [-1, 11, -1, 13, -1, 15, -1, 17], [19, -1, 21, -1, 23, -1, 25, -1], [27, -1, 29, -1, 31, -1, 33, -1]]) == [[27, 3, 29, 5, 31, 7, 33, 9], [27, 11, 29, 13, 31, 15, 33, 17], [19, 11, 21, 13, 23, 15, 25, 17], [27, 11, 29, 13, 31, 15, 33, 17]]\n assert candidate(matrix = [[-1, 3, -1, 7], [2, -1, 6, -1], [1, 5, -1, 8], [4, -1, -1, 9]]) == [[4, 3, 6, 7], [2, 5, 6, 9], [1, 5, 6, 8], [4, 5, 6, 9]]\n assert candidate(matrix = [[-1, -1, 3, -1], [-1, -1, -1, -1], [1, 2, -1, 4]]) == [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]\n assert candidate(matrix = [[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], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]) == [[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], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]]\n assert candidate(matrix = [[-1, -1, 100, -1, -1], [-1, 50, -1, -1, -1], [-1, -1, -1, 90, -1], [20, -1, -1, -1, -1]]) == [[20, 50, 100, 90, -1], [20, 50, 100, 90, -1], [20, 50, 100, 90, -1], [20, 50, 100, 90, -1]]\n assert candidate(matrix = [[-1, 10, 20], [30, 40, -1], [50, -1, 60], [-1, 70, 80]]) == [[50, 10, 20], [30, 40, 80], [50, 70, 60], [50, 70, 80]]\n assert candidate(matrix = [[10, -1, 20, -1, 30], [-1, 40, -1, 50, -1], [60, -1, 70, -1, 80], [-1, 90, -1, 100, -1]]) == [[10, 90, 20, 100, 30], [60, 40, 70, 50, 80], [60, 90, 70, 100, 80], [60, 90, 70, 100, 80]]\n assert candidate(matrix = [[-1, 5, 3, -1, 7], [-1, -1, 6, 8, 2], [0, 9, 1, -1, 4]]) == [[0, 5, 3, 8, 7], [0, 9, 6, 8, 2], [0, 9, 1, 8, 4]]\n assert candidate(matrix = [[-1, 0, 0, 0, 0], [0, -1, 0, 0, 0], [0, 0, -1, 0, 0], [0, 0, 0, -1, 0], [0, 0, 0, 0, -1]]) == [[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]]\n assert candidate(matrix = [[10, 15, -1], [20, -1, 25], [30, -1, 35]]) == [[10, 15, 35], [20, 15, 25], [30, 15, 35]]\n assert candidate(matrix = [[1, 2, 3, 4, 5], [-1, -1, -1, -1, -1], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == [[1, 2, 3, 4, 5], [16, 17, 18, 19, 20], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]\n assert candidate(matrix = [[-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]) == [[11, 12, 13, 14, 15], [11, 12, 13, 14, 15], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]\n assert candidate(matrix = [[0, 1, -1, -1], [10, 11, -1, -1], [-1, -1, 12, 13], [20, 21, 22, 23]]) == [[0, 1, 22, 23], [10, 11, 22, 23], [20, 21, 12, 13], [20, 21, 22, 23]]\n assert candidate(matrix = [[-1, -1, -1, -1, 5], [-1, 0, -1, 0, 5], [-1, 2, -1, 2, 5], [-1, 3, -1, 3, 5]]) == [[-1, 3, -1, 3, 5], [-1, 0, -1, 0, 5], [-1, 2, -1, 2, 5], [-1, 3, -1, 3, 5]]\n assert candidate(matrix = [[1, 2, 3], [4, -1, 6], [7, 8, -1], [-1, -1, 9], [10, 11, 12]]) == [[1, 2, 3], [4, 11, 6], [7, 8, 12], [10, 11, 9], [10, 11, 12]]\n assert candidate(matrix = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [-1, -1, -1, -1, -1]]) == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [11, 12, 13, 14, 15]]\n assert candidate(matrix = [[10, -1, 20, -1, 30], [20, -1, 30, -1, 40], [30, -1, 40, -1, 50], [40, -1, 50, -1, 60]]) == [[10, -1, 20, -1, 30], [20, -1, 30, -1, 40], [30, -1, 40, -1, 50], [40, -1, 50, -1, 60]]\n assert candidate(matrix = [[-1, 2, -1, 4, -1, 6], [-1, 8, -1, 10, -1, 12], [14, -1, 16, -1, 18, -1], [20, -1, 22, -1, 24, -1]]) == [[20, 2, 22, 4, 24, 6], [20, 8, 22, 10, 24, 12], [14, 8, 16, 10, 18, 12], [20, 8, 22, 10, 24, 12]]\n assert candidate(matrix = [[-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) == [[20, 21, 22, 23, 24], [20, 21, 22, 23, 24], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]\n assert candidate(matrix = [[5, 6, 7, -1, -1], [8, 9, 10, -1, -1], [-1, -1, -1, 12, 13], [-1, 15, 16, -1, -1]]) == [[5, 6, 7, 12, 13], [8, 9, 10, 12, 13], [8, 15, 16, 12, 13], [8, 15, 16, 12, 13]]\n assert candidate(matrix = [[15, -1, 13, -1, 11], [-1, 14, -1, 12, -1], [17, 16, 18, -1, 19], [-1, -1, -1, 20, -1]]) == [[15, 16, 13, 20, 11], [17, 14, 18, 12, 19], [17, 16, 18, 20, 19], [17, 16, 18, 20, 19]]\n assert candidate(matrix = [[-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) == [[6, 7, 8, 9, 10], [6, 7, 8, 9, 10], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]\n assert candidate(matrix = [[-1, 100, -1], [-1, -1, -1], [-1, 100, 100], [50, -1, -1]]) == [[50, 100, 100], [50, 100, 100], [50, 100, 100], [50, 100, 100]]\n assert candidate(matrix = [[15, -1, 17, -1], [20, -1, -1, 23], [-1, 26, 27, -1], [29, -1, 31, -1]]) == [[15, 26, 17, 23], [20, 26, 31, 23], [29, 26, 27, 23], [29, 26, 31, 23]]\n assert candidate(matrix = [[1, -1, 3, -1], [5, 6, 7, 8], [-1, -1, -1, 9], [10, 11, 12, -1]]) == [[1, 11, 3, 9], [5, 6, 7, 8], [10, 11, 12, 9], [10, 11, 12, 9]]\n assert candidate(matrix = [[-1, 0, 1], [-1, 2, 3], [-1, 4, 5], [-1, 6, 7], [-1, 8, 9]]) == [[-1, 0, 1], [-1, 2, 3], [-1, 4, 5], [-1, 6, 7], [-1, 8, 9]]\n assert candidate(matrix = [[-1, -1, -1, 0, 1], [2, -1, 4, 5, 6], [7, 8, 9, -1, 10], [-1, 11, -1, 12, -1]]) == [[7, 11, 9, 0, 1], [2, 11, 4, 5, 6], [7, 8, 9, 12, 10], [7, 11, 9, 12, 10]]\n assert candidate(matrix = [[-1, 3, -1, 2, 5], [-1, 4, 6, 3, 1], [7, 2, -1, -1, 8], [5, 6, 0, 1, 3]]) == [[7, 3, 6, 2, 5], [7, 4, 6, 3, 1], [7, 2, 6, 3, 8], [5, 6, 0, 1, 3]]\n assert candidate(matrix = [[1, 2, -1, 4, 5], [-1, -1, -1, -1, 6], [-1, 3, 7, -1, -1]]) == [[1, 2, 7, 4, 5], [1, 3, 7, 4, 6], [1, 3, 7, 4, 6]]\n assert candidate(matrix = [[1, -1, 3, 4], [5, 6, 7, 8], [-1, 10, 11, 12], [13, 14, 15, -1]]) == [[1, 14, 3, 4], [5, 6, 7, 8], [13, 10, 11, 12], [13, 14, 15, 12]]\n assert candidate(matrix = [[-1, -1, 9], [-1, 8, -1], [-1, -1, 7]]) == [[-1, 8, 9], [-1, 8, 9], [-1, 8, 7]]\n assert candidate(matrix = [[-1, 1, 2, 3, 4], [1, -1, 2, 3, 4], [1, 2, -1, 3, 4], [1, 2, 3, -1, 4], [1, 2, 3, 4, -1]]) == [[1, 1, 2, 3, 4], [1, 2, 2, 3, 4], [1, 2, 3, 3, 4], [1, 2, 3, 4, 4], [1, 2, 3, 4, 4]]\n assert candidate(matrix = [[-1, -1, -1, -1], [-1, 0, 1, -1], [2, -1, -1, 3], [4, -1, 5, -1]]) == [[4, 0, 5, 3], [4, 0, 1, 3], [2, 0, 5, 3], [4, 0, 5, 3]]\n assert candidate(matrix = [[10, 20, -1, 40], [50, 60, 70, 80], [90, -1, -1, -1]]) == [[10, 20, 70, 40], [50, 60, 70, 80], [90, 60, 70, 80]]\n assert candidate(matrix = [[-1, 8, 10, -1, 12], [-1, 7, 14, -1, 13], [-1, 6, 15, -1, 11], [9, 5, 16, -1, 14], [10, 4, 17, -1, 15]]) == [[10, 8, 10, -1, 12], [10, 7, 14, -1, 13], [10, 6, 15, -1, 11], [9, 5, 16, -1, 14], [10, 4, 17, -1, 15]]\n assert candidate(matrix = [[-1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1], [25, 26, 27, 28, 29, 30]]) == [[25, 26, 27, 28, 29, 30], [25, 26, 27, 28, 29, 30], [25, 26, 27, 28, 29, 30], [25, 26, 27, 28, 29, 30]]\n assert candidate(matrix = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]\n assert candidate(matrix = [[-1, -1, -1, 40], [-1, 25, -1, 50], [-1, -1, 35, -1], [-1, 45, -1, 60]]) == [[-1, 45, 35, 40], [-1, 25, 35, 50], [-1, 45, 35, 60], [-1, 45, 35, 60]]\n assert candidate(matrix = [[1, -1, 1, -1, 1], [-1, 2, -1, 2, -1], [3, -1, 3, -1, 3], [4, -1, 4, -1, 4]]) == [[1, 2, 1, 2, 1], [4, 2, 4, 2, 4], [3, 2, 3, 2, 3], [4, 2, 4, 2, 4]]\n assert candidate(matrix = [[-1, 2, 3, -1], [4, 5, 6, 7], [8, 9, 10, -1], [11, 12, -1, 14]]) == [[11, 2, 3, 14], [4, 5, 6, 7], [8, 9, 10, 14], [11, 12, 10, 14]]\n assert candidate(matrix = [[-1, 3, -1, -1], [2, -1, 6, -1], [3, 8, 9, 4], [5, -1, -1, 7]]) == [[5, 3, 9, 7], [2, 8, 6, 7], [3, 8, 9, 4], [5, 8, 9, 7]]\n assert candidate(matrix = [[-1, -1, -1, 10, 20], [1, 2, 3, -1, 25], [4, 5, 6, 7, 30], [-1, -1, 8, -1, -1]]) == [[4, 5, 8, 10, 20], [1, 2, 3, 10, 25], [4, 5, 6, 7, 30], [4, 5, 8, 10, 30]]\n assert candidate(matrix = [[10, 20, 30], [40, 50, 60], [70, -1, -1], [-1, 80, 90]]) == [[10, 20, 30], [40, 50, 60], [70, 80, 90], [70, 80, 90]]\n assert candidate(matrix = [[-1, 3, -1, 5], [-1, -1, -1, 9], [2, 6, -1, 4]]) == [[2, 3, -1, 5], [2, 6, -1, 9], [2, 6, -1, 4]]\n assert candidate(matrix = [[-1, -1, -1, -1], [0, -1, -1, 10], [1, -1, 2, -1], [-1, 3, -1, 4], [5, -1, 6, -1]]) == [[5, 3, 6, 10], [0, 3, 6, 10], [1, 3, 2, 10], [5, 3, 6, 4], [5, 3, 6, 10]]\n assert candidate(matrix = [[1, 2, 3, 4], [-1, -1, -1, -1], [7, 8, 9, 10], [11, 12, 13, 14]]) == [[1, 2, 3, 4], [11, 12, 13, 14], [7, 8, 9, 10], [11, 12, 13, 14]]\n assert candidate(matrix = [[-1, -1, -1, -1], [-1, -1, -1, -1], [1, 2, 3, 4]]) == [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]\n assert candidate(matrix = [[-1, 2, -1, 4, -1], [5, -1, 7, -1, 9], [10, -1, 12, -1, 14], [15, 16, -1, 18, 19]]) == [[15, 2, 12, 4, 19], [5, 16, 7, 18, 9], [10, 16, 12, 18, 14], [15, 16, 12, 18, 19]]\n assert candidate(matrix = [[-1, -1, -1], [-1, -1, -1], [1, 2, 3], [4, 5, 6]]) == [[4, 5, 6], [4, 5, 6], [1, 2, 3], [4, 5, 6]]\n assert candidate(matrix = [[-1, 10, -1, 20], [-1, 15, -1, 25], [30, 5, -1, 35]]) == [[30, 10, -1, 20], [30, 15, -1, 25], [30, 5, -1, 35]]\n assert candidate(matrix = [[1, -1, 3, 4], [-1, -1, 6, 7], [8, 9, -1, -1], [-1, -1, -1, 13]]) == [[1, 9, 3, 4], [8, 9, 6, 7], [8, 9, 6, 13], [8, 9, 6, 13]]\n assert candidate(matrix = [[-1, -1, -1, 0, -1], [1, -1, -1, 2, -1], [3, -1, -1, 4, -1], [5, -1, -1, 6, -1], [7, -1, -1, 8, -1]]) == [[7, -1, -1, 0, -1], [1, -1, -1, 2, -1], [3, -1, -1, 4, -1], [5, -1, -1, 6, -1], [7, -1, -1, 8, -1]]\n assert candidate(matrix = [[1, 2, -1, 4, 5], [6, 7, -1, 8, 9], [10, 11, 12, 13, 14], [-1, 16, 17, 18, 19]]) == [[1, 2, 17, 4, 5], [6, 7, 17, 8, 9], [10, 11, 12, 13, 14], [10, 16, 17, 18, 19]]\n assert candidate(matrix = [[-1, -1, 3], [-1, -1, 4], [-1, 5, -1], [6, -1, -1]]) == [[6, 5, 3], [6, 5, 4], [6, 5, 4], [6, 5, 4]]\n assert candidate(matrix = [[-1, -1, -1, -1], [0, 1, 2, 3], [4, 5, 6, 7]]) == [[4, 5, 6, 7], [0, 1, 2, 3], [4, 5, 6, 7]]\n assert candidate(matrix = [[50, -1, -1, 50, -1], [50, -1, -1, 50, -1], [50, -1, -1, 50, -1], [50, -1, -1, 50, -1], [50, -1, -1, 50, -1]]) == [[50, -1, -1, 50, -1], [50, -1, -1, 50, -1], [50, -1, -1, 50, -1], [50, -1, -1, 50, -1], [50, -1, -1, 50, -1]]\n assert candidate(matrix = [[-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [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]]\n assert candidate(matrix = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [-1, -1, -1, -1, -1], [6, 7, 8, 9, 10]]) == [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [6, 7, 8, 9, 10]]\n assert candidate(matrix = [[-1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [2, -1, 2, -1, 2, -1, 2, -1, 2, -1], [3, -1, 3, -1, 3, -1, 3, -1, 3, -1], [4, -1, 4, -1, 4, -1, 4, -1, 4, -1]]) == [[4, 1, 4, 1, 4, 1, 4, 1, 4, 1], [2, 1, 2, 1, 2, 1, 2, 1, 2, 1], [3, 1, 3, 1, 3, 1, 3, 1, 3, 1], [4, 1, 4, 1, 4, 1, 4, 1, 4, 1]]\n assert candidate(matrix = [[-1, 0, 1], [-1, -1, 2], [3, 4, -1]]) == [[3, 0, 1], [3, 4, 2], [3, 4, 2]]\n", "comparison": "exact"}, "public_tests": ["[[1,2,-1],[4,-1,6],[7,8,9]]", "[[3,-1],[5,2]]"], "hints": [], "metadata": {"canonical_parameter_names": ["matrix"], "leetcode_dataset_entry_point": "Solution().modifiedMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:04+00:00", "tests_total": 85, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def modified_matrix(matrix)", "container": null, "callable": "modified_matrix", "parameters": [{"name": "matrix", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3034, "task_id": "number-of-subarrays-that-match-a-pattern-i", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.\n\nA subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:\n\n- nums[i + k + 1] > nums[i + k] if pattern[k] == 1.\n- nums[i + k + 1] == nums[i + k] if pattern[k] == 0.\n- nums[i + k + 1] < nums[i + k] if pattern[k] == -1.\n\nReturn the count of subarrays in nums that match the pattern.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5,6], pattern = [1,1]\nOutput: 4\nExplanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.\nHence, there are 4 subarrays in nums that match the pattern.\n\nExample 2:\n\nInput: nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1]\nOutput: 2\nExplanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.\nHence, there are 2 subarrays in nums that match the pattern.\n\nConstraints:\n\n- 2 <= n == nums.length <= 100\n- 1 <= nums[i] <= 10^9\n- 1 <= m == pattern.length < n\n- -1 <= pattern[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 4, 4, 1, 3, 5, 5, 3],pattern = [1, 0, -1]) == 2\n assert candidate(nums = [1, 3, 2, 3, 1, 2],pattern = [1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6],pattern = [1, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],pattern = [0, 0, 0]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1],pattern = [-1, -1, -1]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4, 3, 5],pattern = [1, 0, -1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 3, 4],pattern = [1, -1, 1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5],pattern = [1, 0, 1, 0]) == 0\n assert candidate(nums = [3, 5, 2, 8, 6, 4, 7],pattern = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17],pattern = [1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],pattern = [1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, 1, 1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5],pattern = [-1, -1, -1, -1, 1, 1, 1]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [2, 1, 3, 1, 4, 1, 5, 1, 6],pattern = [-1, 1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6],pattern = [1, 1, -1, -1, 1, 1]) == 0\n assert candidate(nums = [100, 200, 150, 150, 200, 250, 300, 200, 100, 100, 200, 300, 400, 500, 600],pattern = [1, -1, 0, 1, 1, -1, 1, 0, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],pattern = [1, -1, 1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 3, 5, 3, 1, 3, 5, 3, 1],pattern = [1, -1, 1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [10, 20, 15, 15, 20, 25, 30, 20, 10],pattern = [1, -1, 0, 1, 1, -1]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5],pattern = [0, 0, 0, 0, 0, 0, 0]) == 2\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],pattern = [0, 0, 1, 0, 0, 1, 0, 0, 1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0]) == 3\n assert candidate(nums = [1, 3, 2, 2, 4, 3, 3, 5, 4, 4],pattern = [1, -1, 0, 1, -1, 0, 1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],pattern = [-1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10],pattern = [0, 0, 0, 0, 0, 0]) == 2\n assert candidate(nums = [10, 10, 10, 10, 10, 10],pattern = [0, 0, 0]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pattern = [0, 0, 0, 0, 0, 0, 0]) == 7\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0, 1, 0]) == 2\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 7, 8],pattern = [1, -1, 1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5],pattern = [1, -1, 1, -1, 1, 1]) == 0\n assert candidate(nums = [2, 1, 3, 4, 3, 5, 6, 5, 7, 8],pattern = [-1, 1, 1, -1, 1, 1, -1, 1]) == 1\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 7, 8],pattern = [1, -1, 1, 1, 0]) == 0\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],pattern = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],pattern = [0, 0, 0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 4, 3, 5, 7],pattern = [1, -1, 1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 4, 3, 2, 1, 2, 3, 4],pattern = [1, -1, 1, 0, -1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 5, 6, 5, 4],pattern = [1, 1, -1, 1, 1, -1, 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],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7],pattern = [1, -1, 1, 0, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],pattern = [1, -1, 1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5, 5, 6, 6],pattern = [1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10],pattern = [0, 0, 0]) == 2\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],pattern = [1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [10, 20, 15, 10, 15, 25, 30, 20],pattern = [1, -1, 1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],pattern = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1],pattern = [1, 0, -1, 0, 1, 0, -1]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],pattern = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(nums = [10, 20, 15, 15, 25, 30, 20, 10, 5],pattern = [1, -1, 0, 1, -1, -1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 5, 4, 3, 2, 1],pattern = [1, -1, 1, 1, -1, 1, -1, -1]) == 0\n assert candidate(nums = [10, 20, 30, 20, 10, 5, 15, 25, 35, 25, 15],pattern = [1, 1, -1, -1, 1, 1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],pattern = [1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],pattern = [1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],pattern = [1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7],pattern = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [5, 3, 8, 6, 7, 4, 9, 10, 11, 10, 9],pattern = [-1, 1, 1, -1, 1, 1, -1, -1]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1],pattern = [1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [100, 200, 150, 100, 50, 100, 150, 200, 250, 300],pattern = [1, -1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],pattern = [0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],pattern = [-1, -1, -1, -1, -1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6],pattern = [1, 1, -1, -1, 1, 1, 1]) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],pattern = [1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 3, 2, 3, 4, 5, 4, 3, 2],pattern = [1, -1, 1, 1, -1, -1, 1]) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1],pattern = [0, 1, 0, -1, 0, 1, 0, -1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0, 1, 0]) == 2\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8],pattern = [1, -1, 1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 2\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 5, 6, 5, 6],pattern = [1, 1, -1, 1, 1, -1, 1]) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5],pattern = [1, 1, 1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 8],pattern = [1, -1, 1, 1, 0]) == 0\n assert candidate(nums = [9, 8, 7, 8, 7, 8, 7, 8, 7, 8],pattern = [-1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pattern = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 4, 5, 6, 7, 5, 6, 7, 8, 9, 7, 8, 9, 10, 11],pattern = [1, -1, 1, 1, 0, -1, 1, 1, 0, -1, 1, 1, 0, -1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 2, 2, 1, 1, 1, 2, 2, 3, 3],pattern = [1, 0, 1, 0, -1, 0, -1, 0, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9],pattern = [1, 0, 1, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1, -1]) == 2\n assert candidate(nums = [10, 10, 10, 10, 10],pattern = [0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4],pattern = [1, 1, -1, -1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 6, 7],pattern = [1, -1, 1, 1, 1, 1, 0]) == 0\n assert candidate(nums = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3],pattern = [1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5],pattern = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7],pattern = [0, 0, 0, 0, 0, 0, 0]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],pattern = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1]) == 3\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],pattern = [-1, -1, -1, -1, -1, -1, -1]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5],pattern = [1, -1, 1, 0, -1, 1, 0, 1]) == 0\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1],pattern = [0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5],pattern = [1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20],pattern = [1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 3, 1, 5, 1, 7, 1, 9, 1, 11, 1, 13, 1, 15, 1, 17, 1, 19],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5, 4],pattern = [1, -1, 1, 1]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,6]\n[1,1]", "[1,4,4,1,3,5,5,3]\n[1,0,-1]"], "hints": ["Iterate over all indices i then, using a second loop, check if the subarray starting at index i matches the pattern."], "metadata": {"canonical_parameter_names": ["nums", "pattern"], "leetcode_dataset_entry_point": "Solution().countMatchingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:06+00:00", "tests_total": 112, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "rolling-hash", "string-matching", "hash-function"]}, "language": "ruby", "interface": {"raw_signature": "def count_matching_subarrays(nums, pattern)", "container": null, "callable": "count_matching_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "pattern", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3035, "task_id": "maximum-palindromes-after-operations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string array words having length n and containing 0-indexed strings.\n\nYou are allowed to perform the following operation any number of times (including zero):\n\n- Choose integers i, j, x, and y such that 0 <= i, j < n, 0 <= x < words[i].length, 0 <= y < words[j].length, and swap the characters words[i][x] and words[j][y].\n\nReturn an integer denoting the maximum number of palindromes words can contain, after performing some operations.\n\nNote: i and j may be equal during an operation.\n\nExample 1:\n\nInput: words = [\"abbb\",\"ba\",\"aa\"]\nOutput: 3\nExplanation: In this example, one way to get the maximum number of palindromes is:\nChoose i = 0, j = 1, x = 0, y = 0, so we swap words[0][0] and words[1][0]. words becomes [\"bbbb\",\"aa\",\"aa\"].\nAll strings in words are now palindromes.\nHence, the maximum number of palindromes achievable is 3.\n\nExample 2:\n\nInput: words = [\"abc\",\"ab\"]\nOutput: 2\nExplanation: In this example, one way to get the maximum number of palindromes is:\nChoose i = 0, j = 1, x = 1, y = 0, so we swap words[0][1] and words[1][0]. words becomes [\"aac\",\"bb\"].\nChoose i = 0, j = 0, x = 1, y = 2, so we swap words[0][1] and words[0][2]. words becomes [\"aca\",\"bb\"].\nBoth strings are now palindromes.\nHence, the maximum number of palindromes achievable is 2.\n\nExample 3:\n\nInput: words = [\"cd\",\"ef\",\"a\"]\nOutput: 1\nExplanation: In this example, there is no need to perform any operation.\nThere is one palindrome in words \"a\".\nIt can be shown that it is not possible to get more than one palindrome after any number of operations.\nHence, the answer is 1.\n\nConstraints:\n\n- 1 <= words.length <= 1000\n- 1 <= words[i].length <= 100\n- words[i] consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abac', 'deed', 'civic', 'rotor']) == 3\n assert candidate(words = ['aabbcc', 'ddeeff', 'gghhiijj', 'kklmmoopp']) == 4\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee']) == 5\n assert candidate(words = ['noon', 'level', 'deified', 'civic', 'rotor']) == 5\n assert candidate(words = ['aaaa', 'bbbb', 'cccc']) == 3\n assert candidate(words = ['abac', 'decd', 'efef', 'ghgh']) == 3\n assert candidate(words = ['abcde', 'fghij', 'klmno']) == 0\n assert candidate(words = ['a', 'b', 'c', 'd', 'e']) == 5\n assert candidate(words = ['abbb', 'ba', 'aa']) == 3\n assert candidate(words = ['race', 'car', 'level']) == 3\n assert candidate(words = ['race', 'car', 'level', 'deified']) == 4\n assert candidate(words = ['abc', 'ab']) == 2\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'ddd']) == 4\n assert candidate(words = ['hello', 'world', 'python', 'programming', 'code']) == 4\n assert candidate(words = ['abac', 'deed', 'racecar', 'refer', 'madam']) == 4\n assert candidate(words = ['abcde', 'fghij', 'klmno', 'pqrst']) == 0\n assert candidate(words = ['noon', 'civic', 'rotor', 'stats']) == 4\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 10\n assert candidate(words = ['deified', 'civic', 'rotor', 'redder']) == 4\n assert candidate(words = ['hello', 'world', 'python', 'programming']) == 3\n assert candidate(words = ['noon', 'civic', 'rotor', 'refer']) == 4\n assert candidate(words = ['aabbcc', 'bbaacc', 'ccabba', 'aabbbc', 'bbcaac']) == 4\n assert candidate(words = ['xyz', 'zyx', 'abc', 'cba', 'aaa', 'bbb']) == 6\n assert candidate(words = ['abcd', 'dcba', 'efgh', 'hgf', 'i', 'jklm', 'mlkj']) == 7\n assert candidate(words = ['ab', 'cd', 'ef', 'gh', 'ij']) == 0\n assert candidate(words = ['cd', 'ef', 'a']) == 1\n assert candidate(words = ['xxyyzz', 'yzyzyz', 'xzyzxz', 'zyzxzy', 'zzzyyy', 'yyzzzy', 'zzzzyy', 'xxxyyy', 'yyxxzz', 'zzxyyx']) == 9\n assert candidate(words = ['aabbccddeeff', 'abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yz', 'abcdefgh', 'ijklmnop', 'qrstuv', 'wxyz']) == 10\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'zxy', 'yxz', 'xzy', 'abc', 'cba', 'bac', 'bca', 'cab', 'acb']) == 12\n assert candidate(words = ['abcdefghijk', 'zyxwvutsrqp', 'mnopqrstuvw', 'abcdefghij', 'zyxwvutsr', 'mnopqrstu', 'abcdefgh', 'zyxwvuts', 'mnopqrs', 'abcdefg', 'zyxwvut', 'mnopqr', 'abcdef', 'zyxwvu', 'mnopq', 'abcde', 'zyxwv', 'mnop', 'abcd', 'zyxw', 'mno', 'abc', 'zyx', 'mn', 'ab', 'zy', 'm', 'a', 'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b']) == 52\n assert candidate(words = ['racecar', 'madam', 'refer', 'level', 'deified', 'rotor', 'reviled', 'deed', 'civic', 'rotor', 'redder', 'repaper', 'rotor', 'deed', 'civic', 'level']) == 16\n assert candidate(words = ['noon', 'civic', 'rotor', 'stats', 'level', 'deified', 'reviled', 'refer', 'abcba', 'babcb', 'ababa', 'abacaba']) == 12\n assert candidate(words = ['aabbaa', 'bbaabb', 'ababab', 'bababa', 'aabbba', 'bbaabb', 'ababab', 'bababa', 'aabbaa', 'bbaabb']) == 9\n assert candidate(words = ['abcdefghij', 'jihgfedcba', 'abcdefgh', 'hgfedcba', 'abcdef', 'fedcba', 'abc', 'cba', 'ab', 'ba', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 20\n assert candidate(words = ['aabbcc', 'ddeeff', 'gghhii', 'jklmno', 'pqrsut', 'vwxyzv']) == 3\n assert candidate(words = ['abacaxa', 'banana', 'civic', 'rotor', 'stats', 'level']) == 6\n assert candidate(words = ['abcdefgh', 'hgfedcba', 'abcdefg', 'gfedcba', 'abcde', 'edcba', 'abcd', 'dcba', 'abc', 'cba', 'ab', 'ba', 'a', 'b']) == 14\n assert candidate(words = ['aaabbbccc', 'dddeeefff', 'ggghhhiii', 'jjjkkklll', 'mmmnnnooo', 'pppqqqrrr', 'ssstttuuu', 'vvvwwwxxx', 'yyyzzzwww', 'xxxyyyzzz']) == 8\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj', 'kkk', 'lll', 'mmm', 'nnn', 'ooo', 'ppp', 'qqq', 'rrr', 'sss', 'ttt', 'uuu', 'vvv', 'www', 'xxx', 'yyy', 'zzz']) == 26\n assert candidate(words = ['aabbcc', 'bbaacc', 'cabbac', 'abcabc', 'acbacb', 'bababc']) == 5\n assert candidate(words = ['abcdefg', 'hijklmn', 'opqrstu', 'vwxyz', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba']) == 11\n assert candidate(words = ['abcabcabc', 'bcabcabc', 'cabcabcab', 'abcabcbca', 'bcabcabcb', 'cabcabcbc', 'abcabcabc', 'bcabcabc', 'cabcabcab', 'abcabcbca', 'bcabcabcb', 'cabcabcbc', 'abcabcabc', 'bcabcabc', 'cabcabcab', 'abcabcbca', 'bcabcabcb', 'cabcabcbc']) == 18\n assert candidate(words = ['aabbcc', 'abcabc', 'defdef', 'xyzxyz', 'mnopqr', 'qrstuv']) == 4\n assert candidate(words = ['abcdabcd', 'efefef', 'ghighi', 'jkjkjk', 'lmnmln', 'opopop', 'qrstqr', 'stuvst', 'wxyxw', 'zyzzyz']) == 8\n assert candidate(words = ['racecar', 'madam', 'level', 'refer', 'deed']) == 5\n assert candidate(words = ['racecar', 'madam', 'refer', 'deed', 'level', 'noon', 'civic', 'rotor', 'stats', 'reviled', 'repaid', 'drawer', 'civic', 'rotor', 'redder', 'deed', 'peep', 'noon', 'kayak', 'reviled', 'repaid', 'civic', 'rotor', 'redder', 'deed', 'peep', 'noon', 'kayak', 'madam', 'refer', 'deed', 'level', 'noon', 'civic', 'rotor', 'stats']) == 36\n assert candidate(words = ['aabbcc', 'abcabc', 'bbaacc', 'ccbb', 'aabb', 'abc', 'aab', 'aaa', 'bbb', 'ccc']) == 10\n assert candidate(words = ['abcd', 'dcba', 'efgh', 'hgfe', 'ijkl', 'lkji', 'mnop', 'ponm']) == 8\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyzabcdefghijkl', 'abcdefghijlmnopqrstuvwxyz', 'qrstuvwxyzabcdefghij', 'klmnopqrstuvwxyzabcdefghi', 'jklmnopqrstuvwxyzabcdefgh', 'ijklmnopqrstuvwxyzabcdefg', 'hijklmnopqrstuvwxyzabcdef', 'ghijklmnopqrstuvwxyzabcde', 'fghijklmnopqrstuvwxyzabcd', 'efghijklmnopqrstuvwxyzabc', 'defghijklmnopqrstuvwxyzab', 'cdefghijklmnopqrstuvwxyza', 'bcdefghijklmnopqrstuvwxyzab', 'abcdefghijklmnopqrstuvwxyz']) == 15\n assert candidate(words = ['aabb', 'bbaa', 'ccdd', 'ddcc', 'eeff', 'ffee', 'gghh', 'higg', 'iijj', 'jjii', 'kkll', 'llkk', 'mmnn', 'nnaa', 'aabb', 'bbcc', 'ccdd', 'ddeeff', 'ffgghh', 'hhiijj', 'kkeeff', 'gghh', 'iijj', 'aabb', 'bbcc', 'ccdd', 'ddeeff', 'ffgghh', 'hhiijj', 'kkeeff', 'gghh', 'iijj', 'aabb', 'bbcc', 'ccdd', 'ddeeff', 'ffgghh', 'hhiijj', 'kkeeff', 'gghh', 'iijj', 'aabb', 'bbcc', 'ccdd', 'ddeeff', 'ffgghh', 'hhiijj', 'kkeeff', 'gghh', 'iijj', 'aabb', 'bbcc', 'ccdd', 'ddeeff', 'ffgghh', 'hhiijj', 'kkeeff']) == 56\n assert candidate(words = ['aabbaa', 'bbccbb', 'cccddd', 'ddeecc', 'effe', 'ggh', 'hi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy', 'z']) == 19\n assert candidate(words = ['aaaaaaaaab', 'bbbbbbbbbb', 'cccccccccc', 'dddddddddd', 'eeeeeeeee', 'fffffffff', 'gggggggg', 'hhhhhhh', 'iiiiii', 'jjjjj', 'kkkk', 'lll', 'mm', 'n', 'o']) == 14\n assert candidate(words = ['aaabbbccc', 'bbbaaaccc', 'cccbbbaaa', 'aabbcc', 'bbaacc', 'ccaabb', 'aabbbc', 'bbcaac', 'ccaabb', 'abcabc', 'ababab', 'bababa', 'aaaaaa', 'bbbbbb', 'cccccc', 'dddddd']) == 16\n assert candidate(words = ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd', 'eeeeee', 'ffffff', 'gggggg', 'hhhhhh', 'iiiiii', 'jjjjjj', 'kkkkkk', 'llllll', 'mmmmmm', 'nnnnnn', 'oooooo', 'pppppp', 'qqqqqq', 'rrrrrr', 'ssssss', 'tttttt', 'uuuuuu', 'vvvvvv', 'wwwwww', 'xxxxxx', 'yyyyyy', 'zzzzzz']) == 26\n assert candidate(words = ['aabbaa', 'bbaaab', 'ababab', 'bababa', 'aabbba', 'baaabb', 'aababb', 'abbaab', 'ababba', 'babaab', 'abbaba', 'babbaa', 'baabba', 'aababb', 'abbaab']) == 15\n assert candidate(words = ['racecar', 'level', 'deified', 'civic', 'rotor', 'stats', 'refer', 'rotor', 'reviled', 'deed', 'peep', 'noon', 'racecar', 'refer', 'civic', 'level']) == 16\n assert candidate(words = ['abcba', 'babcb', 'ababa', 'abacaba', 'racecar', 'madam']) == 6\n assert candidate(words = ['aaaaaaaaaa', 'bbbbbbbbbb', 'cccccccccc', 'dddddddddd', 'eeeeeeeeee', 'ffffffffff', 'gggggggggg', 'hhhhhhhhhh', 'iiiiiiiiii', 'jjjjjjjjjj']) == 10\n assert candidate(words = ['aab', 'aac', 'abb', 'abc', 'aba', 'aca', 'aaa', 'bbb', 'aab', 'aac', 'aba', 'aca', 'aaa', 'bbb']) == 14\n assert candidate(words = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd', 'efghij', 'klmnop', 'qrstuv', 'wxyzab', 'cdefgh']) == 8\n assert candidate(words = ['zzzz', 'yyyy', 'xxxx', 'wwww', 'vvvv', 'uuuu', 'tttt', 'ssss', 'rrrr', 'qqqq', 'pppp', 'oooo', 'nnnn', 'mmmm', 'llll', 'kkkk', 'jjjj', 'iiii', 'hhhh', 'gggg', 'ffffff']) == 21\n assert candidate(words = ['abcde', 'edcba', 'fedcb', 'bcdef', 'cdefg', 'bcdea', 'gfedc', 'abcdf', 'bcadf', 'bcade', 'bcdefg', 'bcdefgh', 'bcdefghi', 'bcdefghij', 'bcdefghijk']) == 15\n assert candidate(words = ['abcd', 'dcba', 'efgh', 'hgf', 'ijkl', 'lkj', 'mnop', 'ponm', 'qrst', 'tsrq', 'uvw', 'wvu', 'xyz', 'zyx', 'abcd', 'dcba', 'efgh', 'hgf', 'ijkl', 'lkj', 'mnop', 'ponm', 'qrst', 'tsrq', 'uvw', 'wvu', 'xyz', 'zyx']) == 28\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'abcdefgh', 'hgfedcba', 'ijklmnop', 'ponmlkji', 'qrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba']) == 31\n assert candidate(words = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd', 'efghij', 'klmnop', 'qrstuv', 'wxyzab']) == 8\n assert candidate(words = ['abacax', 'bxdxcy', 'cydxdz', 'zxdxzy', 'yxzxyw', 'wxwxyv', 'vwxyvu', 'uvwxut', 'tuvwus', 'suvwtv', 'rvtwus', 'qtwvur', 'ptwvus', 'otwvur', 'ntwvus', 'mtwvur', 'ltwvus', 'kwtvur', 'jwtvus', 'itwvur', 'htwvur', 'gtwvur', 'ftwvur', 'etwvur', 'dtwvur', 'ctwvur', 'btwvur', 'atwvur']) == 24\n assert candidate(words = ['racecar', 'level', 'deified', 'rotor', 'redder', 'repaper', 'reviled', 'kayak']) == 7\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']) == 52\n assert candidate(words = ['abcdefg', 'ghijklm', 'nopqrstu', 'vwxyzabc', 'defghijk', 'lmnopqrs', 'tuvwxyz', 'abcdefghi', 'jklmnopqr', 'stuvwxyzabc']) == 8\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 52\n assert candidate(words = ['abacax', 'banana', 'anana', 'civic', 'racecar', 'madam', 'level', 'deified']) == 8\n assert candidate(words = ['abababab', 'babababa', 'acacacac', 'bacbacba', 'cdcddcdc', 'dddddddd', 'eeeeeeee', 'ffffffff', 'gggggggg', 'hhhhhhhh']) == 9\n assert candidate(words = ['racecar', 'madam', 'level', 'rotor', 'deified']) == 5\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'ae', 'ea', 'af', 'fa', 'ag', 'ga', 'ah', 'ha', 'ai', 'ia', 'aj', 'ja', 'ak', 'ka', 'al', 'la', 'am', 'ma', 'an', 'na', 'ao', 'oa', 'ap', 'pa', 'aq', 'qa', 'ar', 'ra', 'as', 'sa', 'at', 'ta', 'au', 'ua', 'av', 'va', 'aw', 'wa', 'ax', 'xa', 'ay', 'ya', 'az', 'za']) == 50\n assert candidate(words = ['abacaba', 'bcbcbcb', 'bababab', 'cacacac', 'dcdcdcd', 'efefefe', 'gigigig', 'huhuhuh', 'ijijiij', 'kjkjkjk', 'lmnlmnl', 'ponponp', 'qrqrqrq', 'stststs', 'xvxvxvx', 'wywywyw', 'uzuzuzu', 'vavavav', 'bbabbab', 'abbabba']) == 20\n assert candidate(words = ['aabbccddeeff', 'bbccddeeffgg', 'ccddeeffgghh', 'ddeeffgghhiijj', 'eeffgghhiijjkkll', 'ffgghhiijjkkllmmnn', 'gghhiijjkkllmmnnoopp', 'hhiijjkkllmmnnooppqqrr', 'iijjkkllmmnnooppqqrrssttuuvv', 'jjkkllmmnnooppqqrrssttuuvvwxyz']) == 9\n assert candidate(words = ['aabb', 'bbaa', 'abab', 'baba', 'aaaa', 'bbbb', 'abcd', 'dcba', 'efgh', 'ghfe', 'ijkl', 'lkji', 'mnop', 'ponm', 'qrst', 'tsrq', 'uvwx', 'xwvu', 'yzxy', 'yxzy', 'abcdef', 'fedcba', 'ghijkl', 'lkjihg', 'mnopqr', 'rqponm', 'stuvwx', 'xwvuts', 'yzabcd', 'dcba']) == 29\n assert candidate(words = ['racecar', 'madam', 'refer', 'deified', 'rotor', 'kayak', 'reviled', 'repaper', 'redder', 'deed', 'peep', 'noon', 'civic', 'rotor', 'stats', 'level']) == 16\n assert candidate(words = ['abcdabcd', 'bcadbcad', 'cdabcdab', 'dabcadcb', 'abcdabcd', 'bcadbcad', 'cdabcdab', 'dabcadcb']) == 8\n assert candidate(words = ['abacaxa', 'xyz', 'mnopqr', 'uvw', 'stuv', 'lmno', 'ijkl', 'hgf', 'edc', 'bac']) == 8\n assert candidate(words = ['abacax', 'zyzyzy', 'noonnoon', 'levellevel', 'rotorrotor', 'statsstats', 'civiccivic', 'deifieddeified']) == 7\n assert candidate(words = ['abcabcabc', 'bcabcbacb', 'cabacabac', 'aabbcc', 'bbaacc', 'ccaabb', 'abcabcabc', 'bcabcbacb', 'cabacabac', 'aabbcc', 'bbaacc', 'ccaabb', 'abcabcabc', 'bcabcbacb', 'cabacabac', 'aabbcc', 'bbaacc', 'ccaabb', 'abcabcabc', 'bcabcbacb', 'cabacabac', 'aabbcc', 'bbaacc', 'ccaabb', 'abcabcabc', 'bcabcbacb', 'cabacabac', 'aabbcc', 'bbaacc', 'ccaabb']) == 30\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']) == 26\n assert candidate(words = ['aabbcc', 'abcdef', 'zyxwvut', 'mnopqr', 'lkjihg', 'fedcba', 'utsrqponmlkjihgfedcba', 'abcdefghijklnmopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklnmopqrstuvwxyz']) == 9\n assert candidate(words = ['aabbcc', 'abcabc', 'abcdabcd', 'abcdeabcde', 'abcdefabcdef']) == 5\n assert candidate(words = ['racecar', 'level', 'deified', 'rotor', 'repaper', 'deed', 'civic', 'rotor', 'refer', 'redder']) == 10\n assert candidate(words = ['abacax', 'xaba', 'aa', 'bb', 'cccc', 'dddd', 'eeff', 'fffe', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz']) == 27\n assert candidate(words = ['abccba', 'abcba', 'abba', 'aba', 'a', 'b', 'c', 'd', 'e']) == 9\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx', 'zyx']) == 20\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'ab', 'ba', 'cd', 'dc', 'ef', 'fe']) == 32\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff', 'gggg', 'hhhh', 'iiii', 'jjjj', 'kkkk', 'llll', 'mmmm', 'nnnn', 'oooo', 'pppp', 'qqqq', 'rrrr', 'ssss', 'tttt', 'uuuu', 'vvvv', 'wwww', 'xxxx', 'yyyy', 'zzzz']) == 26\n assert candidate(words = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']) == 52\n assert candidate(words = ['abcde', 'edcba', 'fghij', 'jihgf', 'klmno', 'onmlk', 'pqrst', 'tsrqp', 'uvwxy', 'yxwvu', 'zabcd', 'dcbae']) == 12\n assert candidate(words = ['aabbcc', 'abcabc', 'abacab', 'aabbccddeeff', 'bbccddeeffgg', 'ccddeeffgghh', 'ddeeffgghhiijj', 'eeffgghhiijjkkll', 'ffgghhiijjkkllmmnn', 'gghhiijjkkllmmnnoopp', 'hhiijjkkllmmnnooppqqrr', 'iijjkkllmmnnooppqqrrssttuuvv', 'jjkkllmmnnooppqqrrssttuuvvwxyz']) == 12\n assert candidate(words = ['racecar', 'madam', 'refer', 'level', 'deified', 'reviled']) == 6\n", "comparison": "exact"}, "public_tests": ["[\"abbb\",\"ba\",\"aa\"]", "[\"abc\",\"ab\"]", "[\"cd\",\"ef\",\"a\"]"], "hints": ["We can redistribute all the letters freely among the words.", "Calculate the frequency of each letter and total the number of matching letter pairs that can be formed from the letters, i.e., total = sum(freq[ch] / 2) for all 'a' <= ch <= 'z'.", "We can greedily try making palindromes from words[i] with the smallest length to words[i] with the longest length.", "For the current index, i, we try to make words[i] a palindrome. We need len(words[i]) / 2 matching character pairs, and the letter in the middle (if it exists) can be freely chosen afterward.", "We can check if we have enough pairs for index i; if we do, we increase the number of palindromes we can make and decrease the number of pairs we have. Otherwise, we end the loop at this index.", "The answer is the number of palindromes we were able to make in the end."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().maxPalindromesAfterOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:09+00:00", "tests_total": 95, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "string", "greedy", "sorting", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def max_palindromes_after_operations(words)", "container": null, "callable": "max_palindromes_after_operations", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3036, "task_id": "number-of-subarrays-that-match-a-pattern-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums of size n, and a 0-indexed integer array pattern of size m consisting of integers -1, 0, and 1.\n\nA subarray nums[i..j] of size m + 1 is said to match the pattern if the following conditions hold for each element pattern[k]:\n\n- nums[i + k + 1] > nums[i + k] if pattern[k] == 1.\n- nums[i + k + 1] == nums[i + k] if pattern[k] == 0.\n- nums[i + k + 1] < nums[i + k] if pattern[k] == -1.\n\nReturn the count of subarrays in nums that match the pattern.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5,6], pattern = [1,1]\nOutput: 4\nExplanation: The pattern [1,1] indicates that we are looking for strictly increasing subarrays of size 3. In the array nums, the subarrays [1,2,3], [2,3,4], [3,4,5], and [4,5,6] match this pattern.\nHence, there are 4 subarrays in nums that match the pattern.\n\nExample 2:\n\nInput: nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1]\nOutput: 2\nExplanation: Here, the pattern [1,0,-1] indicates that we are looking for a sequence where the first number is smaller than the second, the second is equal to the third, and the third is greater than the fourth. In the array nums, the subarrays [1,4,4,1], and [3,5,5,3] match this pattern.\nHence, there are 2 subarrays in nums that match the pattern.\n\nConstraints:\n\n- 2 <= n == nums.length <= 10^6\n- 1 <= nums[i] <= 10^9\n- 1 <= m == pattern.length < n\n- -1 <= pattern[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 3, 1, 4, 3, 2],pattern = [1, -1, 1, -1]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4, 5],pattern = [1, 0, 1]) == 1\n assert candidate(nums = [1, 4, 4, 1, 3, 5, 5, 3],pattern = [1, 0, -1]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5],pattern = [0, 0, 0]) == 3\n assert candidate(nums = [1, 2, 2, 3, 4],pattern = [1, 0, 1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4],pattern = [1, 0, 1, 0]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6],pattern = [1, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],pattern = [0, 0, 0]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1],pattern = [-1, -1, -1]) == 2\n assert candidate(nums = [1, 3, 2, 3, 4, 5],pattern = [1, -1, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],pattern = [0, 0]) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5],pattern = [1, 0, 0, 1, 0, 0]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5],pattern = [1, -1, 1]) == 2\n assert candidate(nums = [10, 10, 10, 10],pattern = [0, 0]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5],pattern = [-1, -1, -1]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pattern = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 2\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2],pattern = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],pattern = [1, -1, 1, 1, 1, -1, -1]) == 0\n assert candidate(nums = [7, 10, 10, 8, 10, 5, 6, 7, 8, 9],pattern = [1, 0, -1, 1, 1, -1, 1, 1]) == 0\n assert candidate(nums = [10, 9, 8, 9, 10, 11, 10, 9, 8, 9, 10],pattern = [-1, -1, 1, 1, -1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5, 5, 6],pattern = [1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6],pattern = [1, 0, 0, 1, 0, 0, 1]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6],pattern = [1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1],pattern = [0, 1, 0, 1, 0, 1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 1, 0, 1, 0, 1, 0, 1, -1, 0, -1, 0, -1, 0, -1, 0]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],pattern = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1]) == 5\n assert candidate(nums = [1, 2, 3, 3, 3, 2, 1, 1, 1, 2, 3],pattern = [1, 0, 0, -1, -1, 0, 0, 1, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 6, 7, 8],pattern = [1, 1, -1, 1, 1, -1, 1, 1]) == 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],pattern = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pattern = [0, 0, 0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 7, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [10, 9, 8, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, 0, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],pattern = [1, -1, 1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1],pattern = [1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],pattern = [1, 1, -1, -1, 1, 1]) == 0\n assert candidate(nums = [100, 200, 150, 250, 200, 300, 250, 350, 300, 400],pattern = [1, -1, 1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1, 1, 1, 2, 2, 2, 3, 3, 3],pattern = [1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0]) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1],pattern = [1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1],pattern = [0, 1, 0, -1, 0]) == 0\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6],pattern = [1, -1, 1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1],pattern = [1, 0, 1, 0, -1, 0, -1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1],pattern = [0, 1, 0, -1, 0, 1, 0, -1, 0, 1]) == 1\n assert candidate(nums = [1, 1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8],pattern = [0, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50],pattern = [1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2],pattern = [1, -1, 1, -1, 1, -1, 1, -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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10],pattern = [-1, -1, -1, -1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],pattern = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],pattern = [-1, -1, -1, -1, 0, 1, 1, 1, 1, 0, -1, -1, -1, -1, 0, 1, 1, 1, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1]) == 4\n assert candidate(nums = [1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1],pattern = [1, -1, 0, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4],pattern = [1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3],pattern = [0, 0, 0, 1, 0, 0, 0]) == 1\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],pattern = [1, -1, 1, -1, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2],pattern = [1, 1, 1, -1, -1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1],pattern = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [10, 10, 11, 12, 13, 13, 12, 11, 12, 13, 13, 12, 10],pattern = [0, 1, 1, 1, 0, -1, -1, 1, 1, 0, -1, -1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],pattern = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1],pattern = [1, 0, -1, 1, 0, -1, 1, 0]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5],pattern = [1, 1, 1, -1, -1, -1, 1, 1, 1]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, 0, 1, 1, 1, 1, 0, -1, -1, -1, -1]) == 1\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 7, 8],pattern = [1, -1, 1, -1, 1, 0, 1, 0, 0, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pattern = [0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3],pattern = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 0\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],pattern = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 0\n assert candidate(nums = [1, 3, 5, 4, 6, 5, 7, 8, 7, 9, 10, 9, 11, 12],pattern = [1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],pattern = [1, 0, 1, 0, 1, 0, 1]) == 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],pattern = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [9, 8, 7, 8, 9, 10, 9, 8, 7, 8, 9, 10],pattern = [-1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],pattern = [0, 1, 0, 1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],pattern = [0, 1, 0, 1, 0, 1, 0]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8],pattern = [1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [3, 1, 2, 4, 3, 5, 6, 5, 7, 8, 7, 9, 10, 11, 10, 12, 13, 14, 13, 15, 16],pattern = [1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 5, 7, 8, 7, 9, 10, 11, 10, 12, 13, 14, 13, 15, 16, 15, 17, 18, 17, 19, 20, 19, 21, 22],pattern = [1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1]) == 0\n assert candidate(nums = [3, 2, 3, 2, 3, 2, 3, 2, 3, 2],pattern = [-1, 1, -1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10],pattern = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1]) == 3\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1]) == 5\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9],pattern = [1, 0, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6],pattern = [1, -1, 1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6],pattern = [1, 1, 1, -1, -1, -1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pattern = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 2, 1, 3, 2, 1],pattern = [1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 2, 2, 1, 1],pattern = [1, 0, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 0, -1, -1, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],pattern = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1, 3, 5, 4, 6, 7, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5, 4, 5, 6],pattern = [1, -1, 1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],pattern = [1, -1, 1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],pattern = [1, -1, 1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pattern = [1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],pattern = [-1, -1, -1, -1, -1, -1, 1, 1, 1]) == 0\n assert candidate(nums = [5, 6, 7, 8, 7, 6, 7, 8, 9, 10],pattern = [1, 1, -1, -1, 1, 1, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pattern = [-1, -1, -1, -1, -1, -1, -1]) == 3\n assert candidate(nums = [3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],pattern = [0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1],pattern = [1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3],pattern = [0, 1, 0, -1, 0, 1, 0, -1]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],pattern = [1, -1, 1, -1, 1]) == 3\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,6]\n[1,1]", "[1,4,4,1,3,5,5,3]\n[1,0,-1]"], "hints": ["Create a second array nums2 such that nums2[i] = 1 if nums[i + 1] > nums[i], nums2[i] = 0 if nums[i + 1] == nums[i], and nums2[i] = -1 if nums[i + 1] < nums[i].", "The problem becomes: “Count the number of subarrays in nums2 that are equal to pattern.", "Use Knuth-Morris-Pratt or Z-Function algorithms."], "metadata": {"canonical_parameter_names": ["nums", "pattern"], "leetcode_dataset_entry_point": "Solution().countMatchingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:12+00:00", "tests_total": 111, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "rolling-hash", "string-matching", "hash-function"]}, "language": "ruby", "interface": {"raw_signature": "def count_matching_subarrays(nums, pattern)", "container": null, "callable": "count_matching_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "pattern", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3038, "task_id": "maximum-number-of-operations-with-the-same-score-i", "difficulty": "Easy", "problem_description": "You are given an array of integers nums. Consider the following operation:\n\n- Delete the first two elements nums and define the score of the operation as the sum of these two elements.\n\nYou can perform this operation until nums contains fewer than two elements. Additionally, the same score must be achieved in all operations.\n\nReturn the maximum number of operations you can perform.\n\nExample 1:\n\nInput: nums = [3,2,1,4,5]\nOutput: 2\nExplanation:\n- We can perform the first operation with the score 3 + 2 = 5. After this operation, nums = [1,4,5].\n- We can perform the second operation as its score is 4 + 1 = 5, the same as the previous operation. After this operation, nums = [5].\n- As there are fewer than two elements, we can't perform more operations.\n\nExample 2:\n\nInput: nums = [1,5,3,3,4,1,3,2,2,3]\nOutput: 2\nExplanation:\n- We can perform the first operation with the score 1 + 5 = 6. After this operation, nums = [3,3,4,1,3,2,2,3].\n- We can perform the second operation as its score is 3 + 3 = 6, the same as the previous operation. After this operation, nums = [4,1,3,2,2,3].\n- We cannot perform the next operation as its score is 4 + 1 = 5, which is different from the previous scores.\n\nExample 3:\n\nInput: nums = [5,3]\nOutput: 1\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 1\n assert candidate(nums = [1, 100, 1, 100, 1, 100]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 5\n assert candidate(nums = [1000, 1, 999, 2, 998, 3]) == 3\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 5, 3, 3, 4, 1, 3, 2, 2, 3]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 5\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1]) == 3\n assert candidate(nums = [100, 200, 100, 200, 100, 200]) == 3\n assert candidate(nums = [3, 2, 1, 4, 5]) == 2\n assert candidate(nums = [100, 200, 100, 200, 100]) == 2\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [5, 3]) == 1\n assert candidate(nums = [99, 1, 98, 2, 97, 3]) == 3\n assert candidate(nums = [10, 10, 10, 10, 10, 10]) == 3\n assert candidate(nums = [10, 10, 20, 20, 30, 30]) == 1\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3]) == 4\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(nums = [10, 20, 10, 20, 30, 40]) == 2\n assert candidate(nums = [7, 13, 13, 7, 10, 10, 10, 10, 15, 15]) == 4\n assert candidate(nums = [10, 10, 20, 20, 10, 10, 20, 20, 10, 10, 20, 20, 10, 10]) == 1\n assert candidate(nums = [250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250]) == 11\n assert candidate(nums = [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 = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 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]) == 10\n assert candidate(nums = [33, 67, 33, 67, 33, 67, 33, 67, 33, 67, 33, 67, 33, 67, 33, 67, 33, 67, 33, 67, 33, 67]) == 11\n assert candidate(nums = [45, 55, 45, 55, 45, 55, 45, 55, 45, 55, 45, 55, 45, 55, 45, 55, 45, 55, 45, 55]) == 10\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]) == 15\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 1\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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [100, 100, 1, 1, 100, 100, 2, 2, 100, 100, 3, 3, 100, 100, 4, 4]) == 1\n assert candidate(nums = [6, 6, 12, 12, 18, 18, 24, 24, 30, 30, 36, 36, 42, 42, 48, 48, 54, 54, 60, 60]) == 1\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60]) == 1\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100]) == 1\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\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 6\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8]) == 1\n assert candidate(nums = [10, 10, 5, 5, 2, 8, 6, 4, 3, 7, 1, 9]) == 1\n assert candidate(nums = [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, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 30\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 8\n assert candidate(nums = [500, 500, 250, 250, 125, 125, 625, 625, 312, 312]) == 1\n assert candidate(nums = [9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1]) == 16\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1]) == 8\n assert candidate(nums = [3, 1, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2]) == 1\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100]) == 5\n assert candidate(nums = [7, 3, 3, 7, 5, 5, 2, 2, 8, 8, 1, 1, 9, 9, 4, 4, 6, 6]) == 3\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 9\n assert candidate(nums = [5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40]) == 1\n assert candidate(nums = [1, 2, 3, 3, 2, 1, 4, 5, 5, 4, 6, 7, 7, 6]) == 1\n assert candidate(nums = [7, 3, 3, 7, 7, 3, 3, 7, 7, 3, 3, 7, 7, 3, 3, 7]) == 8\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 1\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == 1\n assert candidate(nums = [50, 50, 50, 49, 49, 50, 49, 50, 49, 48, 48, 48]) == 1\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 5\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9]) == 9\n assert candidate(nums = [10, 20, 10, 20, 30, 30, 40, 40, 50, 50]) == 2\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]) == 15\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3]) == 1\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\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 10\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]) == 19\n assert candidate(nums = [5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10]) == 1\n assert candidate(nums = [10, 10, 5, 5, 10, 10, 5, 5, 10, 10, 5, 5, 10, 10]) == 1\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]) == 11\n assert candidate(nums = [500, 500, 250, 250, 750, 250, 500, 250, 500, 250, 750, 250, 500, 250, 750, 250, 500, 250]) == 1\n assert candidate(nums = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5]) == 5\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 6\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]) == 1\n assert candidate(nums = [1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000]) == 6\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3]) == 12\n assert candidate(nums = [50, 50, 25, 25, 75, 75, 25, 25, 75, 75]) == 1\n assert candidate(nums = [5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45, 45, 50, 50]) == 1\n assert candidate(nums = [100, 1, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93]) == 1\n assert candidate(nums = [8, 1, 1, 8, 2, 7, 3, 6, 4, 5, 1, 8, 1, 8, 2, 7, 3, 6, 4, 5]) == 10\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94, 6, 93, 7, 92, 8, 91, 9]) == 9\n assert candidate(nums = [7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3]) == 15\n assert candidate(nums = [8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1]) == 11\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\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 6\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 8\n assert candidate(nums = [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]) == 13\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 5\n assert candidate(nums = [1, 999, 998, 1, 499, 500, 249, 751, 374, 626, 187, 813, 93, 907, 46, 954]) == 1\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\n assert candidate(nums = [1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999]) == 9\n assert candidate(nums = [7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92]) == 8\n assert candidate(nums = [1, 999, 1, 999, 1, 999, 1, 999, 1, 999]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 1\n assert candidate(nums = [10, 20, 10, 20, 30, 30, 40, 40, 50, 50, 60, 60]) == 2\n", "comparison": "exact"}, "public_tests": ["[3,2,1,4,5]", "[1,5,3,3,4,1,3,2,2,3]", "[5,3]"], "hints": [], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:14+00:00", "tests_total": 109, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def max_operations(nums)", "container": null, "callable": "max_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3039, "task_id": "apply-operations-to-make-string-empty", "difficulty": "Medium", "problem_description": "You are given a string s.\n\nConsider performing the following operation until s becomes empty:\n\n- For every alphabet character from 'a' to 'z', remove the first occurrence of that character in s (if it exists).\n\nFor example, let initially s = \"aabcbbca\". We do the following operations:\n\n- Remove the underlined characters s = \"aabcbbca\". The resulting string is s = \"abbca\".\n- Remove the underlined characters s = \"abbca\". The resulting string is s = \"ba\".\n- Remove the underlined characters s = \"ba\". The resulting string is s = \"\".\n\nReturn the value of the string s right before applying the last operation. In the example above, answer is \"ba\".\n\nExample 1:\n\nInput: s = \"aabcbbca\"\nOutput: \"ba\"\nExplanation: Explained in the statement.\n\nExample 2:\n\nInput: s = \"abcd\"\nOutput: \"abcd\"\nExplanation: We do the following operation:\n- Remove the underlined characters s = \"abcd\". The resulting string is s = \"\".\nThe string just before the last operation is \"abcd\".\n\nConstraints:\n\n- 1 <= s.length <= 5 * 10^5\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzzz\") == \"z\"\n assert candidate(s = \"aabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccdd\") == \"abcd\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == \"abc\"\n assert candidate(s = \"ababababababababababababababababababababababababab\") == \"ab\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyyzzzz\") == \"iyz\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"abcabcabcabcabc\") == \"abc\"\n assert candidate(s = \"aabcbbca\") == \"ba\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"abcd\") == \"abcd\"\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxyyyyzzzz\") == \"ijklmnopqrstuvwyz\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"bbaaccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"bacdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"mnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnlmlnl\") == \"l\"\n assert candidate(s = \"uniquecharacterswithoutrepeats\") == \"et\"\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == \"xyz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeeffffffffggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmmnnnnnnnnnnnooooooooooooppppppppppppqqqqqqqqqqqqrrrrrrrrrrrrsssssssssssstttttttttttttuuuuuuuuuuuuuvvvvvvvvvvvvvwwwwwwwwwwwwwxxxxxxxxxxxxxyyyyyyyyyyyyyyzzzzzzzzzzzzzz\") == \"yz\"\n assert candidate(s = \"qwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwertqwert\") == \"qwert\"\n assert candidate(s = \"zzzzzyyyyxxxwwvvvuuutttssrrqqppoonnmmmlllkkkjjjiiiighhhgggfffeeedddccccbbbaaaa\") == \"z\"\n assert candidate(s = \"zzzzzyyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaaa\") == \"z\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyyyyxxxwwvvvuuutttssrrqqppoonnmmmlllkkkjjjiiiighhhgggfffeeedddccccbbbaaaa\") == \"yigca\"\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbccccccccddddddddddeeeeeeeeefffffffffggggggggghhhhhhhhhhiiiiiiiiijjjjjjjjkkkkkkkkklllllllllmmmmmmmmmnnnnnnnnnooooooooooppppppppppqqqqqqqqqrrrrrrrrrssssssssstttttttttuuuuuuuuuvvvvvvvvvwwwwwwwwwxxxxxxxxxyyyyyyyyyzzzzzzzzz\") == \"adhop\"\n assert candidate(s = \"aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccdddddddddddddd\") == \"a\"\n assert candidate(s = \"zzyyxxwwvvttuusssrrrqqqpppoonnnmmmllllkkkkjjjjiiiidddddhhhgggeeeefffccccba\") == \"d\"\n assert candidate(s = \"thisisaverylongstringwithmanycharactersrepeatingoverandoveragainoverandoveragain\") == \"a\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == \"abc\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaaa\") == \"y\"\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == \"a\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == \"abc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"repeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeatedrepeated\") == \"e\"\n", "comparison": "exact"}, "public_tests": ["\"aabcbbca\"", "\"abcd\""], "hints": ["Before the last operation, only the most frequent characters in the original string will remain.", "Keep only the last occurence of each of the most frequent characters."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().lastNonEmptyString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:16+00:00", "tests_total": 40, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def last_non_empty_string(s)", "container": null, "callable": "last_non_empty_string", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3040, "task_id": "maximum-number-of-operations-with-the-same-score-ii", "difficulty": "Medium", "problem_description": "Given an array of integers called nums, you can perform any of the following operation while nums contains at least 2 elements:\n\n- Choose the first two elements of nums and delete them.\n- Choose the last two elements of nums and delete them.\n- Choose the first and the last elements of nums and delete them.\n\nThe score of the operation is the sum of the deleted elements.\n\nYour task is to find the maximum number of operations that can be performed, such that all operations have the same score.\n\nReturn the maximum number of operations possible that satisfy the condition mentioned above.\n\nExample 1:\n\nInput: nums = [3,2,1,2,3,4]\nOutput: 3\nExplanation: We perform the following operations:\n- Delete the first two elements, with score 3 + 2 = 5, nums = [1,2,3,4].\n- Delete the first and the last elements, with score 1 + 4 = 5, nums = [2,3].\n- Delete the first and the last elements, with score 2 + 3 = 5, nums = [].\nWe are unable to perform any more operations as nums is empty.\n\nExample 2:\n\nInput: nums = [3,2,6,1,4]\nOutput: 2\nExplanation: We perform the following operations:\n- Delete the first two elements, with score 3 + 2 = 5, nums = [6,1,4].\n- Delete the last two elements, with score 1 + 4 = 5, nums = [6].\nIt can be proven that we can perform at most 2 operations.\n\nConstraints:\n\n- 2 <= nums.length <= 2000\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 3\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2]) == 4\n assert candidate(nums = [1, 3, 2, 2, 3, 1]) == 3\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 4\n assert candidate(nums = [5, 8, 8, 5, 8, 8, 5]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1]) == 3\n assert candidate(nums = [1, 3, 2, 3, 1]) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 3\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10]) == 4\n assert candidate(nums = [3, 2, 6, 1, 4]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1]) == 2\n assert candidate(nums = [3, 2, 1, 2, 3, 4]) == 3\n assert candidate(nums = [5, 8, 9, 1, 2, 3, 4, 8, 5]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [10, 10, 10, 10, 10, 10]) == 3\n assert candidate(nums = [1000, 1, 1, 1000]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2]) == 4\n assert candidate(nums = [1, 2, 3, 2, 1]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 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]) == 10\n assert candidate(nums = [10, 10, 10, 10, 10]) == 2\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7, 6, 5, 6, 7, 8, 9]) == 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]) == 10\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5]) == 4\n assert candidate(nums = [8, 5, 8, 5, 8, 5, 8, 5, 8, 5, 8, 5, 8, 5, 8, 5]) == 8\n assert candidate(nums = [1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000]) == 5\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 3, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 500, 400, 300, 200, 100]) == 2\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 40, 30, 20, 10]) == 2\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 15\n assert candidate(nums = [5, 10, 15, 10, 5, 10, 15, 10, 5]) == 2\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2]) == 16\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 5\n assert candidate(nums = [3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4]) == 6\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]) == 16\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 4, 5, 6, 5, 4, 3, 2, 1, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1]) == 1\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [9, 3, 9, 3, 9, 3, 9, 3, 9, 3]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 1\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [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]) == 1\n assert candidate(nums = [5, 10, 15, 10, 5, 10, 15, 10, 5]) == 2\n assert candidate(nums = [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, 2, 2, 2]) == 14\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112]) == 8\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]) == 13\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9]) == 2\n assert candidate(nums = [5, 8, 5, 8, 5, 8, 5, 8]) == 4\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]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [8, 1, 4, 3, 2, 1, 8, 1, 4, 3, 2, 1]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40]) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 2\n assert candidate(nums = [1000, 1, 1000, 2, 1000, 3, 1000, 4, 1000, 5, 1000, 6, 1000, 7, 1000, 8, 1000, 9, 1000, 10]) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 10\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 2\n assert candidate(nums = [100, 200, 100, 300, 200, 100, 300, 200, 100]) == 2\n assert candidate(nums = [100, 200, 100, 300, 200, 100, 400, 300]) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 40, 30, 20, 10]) == 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, 21, 22, 23, 24, 25]) == 12\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 2\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700]) == 6\n assert candidate(nums = [5, 5, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35]) == 2\n assert candidate(nums = [1, 3, 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\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 400, 300, 200, 100, 100, 200, 300, 400, 500, 400, 300, 200, 100]) == 2\n assert candidate(nums = [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, 2, 2, 2, 2, 2, 2]) == 15\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175, 182, 189, 196, 203, 210]) == 15\n assert candidate(nums = [10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15]) == 10\n assert candidate(nums = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 10\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10, 90, 10, 100]) == 1\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]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 2\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]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 6\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 95, 85, 75, 65, 55, 45, 35, 25, 15, 5]) == 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]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 2\n assert candidate(nums = [5, 9, 5, 9, 5, 9, 5, 9, 5, 9]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [15, 25, 15, 25, 15, 25, 15, 25, 15, 25, 15, 25, 15, 25, 15, 25, 15, 25, 15, 25]) == 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]) == 10\n assert candidate(nums = [3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1]) == 1\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 10\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]) == 16\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2\n assert candidate(nums = [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]) == 15\n assert candidate(nums = [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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 23\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]) == 8\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 15\n assert candidate(nums = [3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4]) == 17\n assert candidate(nums = [5, 9, 1, 9, 5, 9, 1, 9, 5, 9]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 500, 400, 300, 200, 100]) == 2\n", "comparison": "exact"}, "public_tests": ["[3,2,1,2,3,4]", "[3,2,6,1,4]"], "hints": ["After the first operation, the score of other operations is fixed.", "For the fixed score use dynamic programming dp[l][r] to find a maximum number of operations on the subarray nums[l..r]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:19+00:00", "tests_total": 116, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming", "memoization"]}, "language": "ruby", "interface": {"raw_signature": "def max_operations(nums)", "container": null, "callable": "max_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3041, "task_id": "maximize-consecutive-elements-in-an-array-after-modification", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array nums consisting of positive integers.\n\nInitially, you can increase the value of any element in the array by at most 1.\n\nAfter that, you need to select one or more elements from the final array such that those elements are consecutive when sorted in increasing order. For example, the elements [3, 4, 5] are consecutive while [3, 4, 6] and [1, 1, 2, 3] are not.\n\nReturn the maximum number of elements that you can select.\n\nExample 1:\n\nInput: nums = [2,1,5,1,1]\nOutput: 3\nExplanation: We can increase the elements at indices 0 and 3. The resulting array is nums = [3,1,5,2,1].\nWe select the elements [3,1,5,2,1] and we sort them to obtain [1,2,3], which are consecutive.\nIt can be shown that we cannot select more than 3 consecutive elements.\n\nExample 2:\n\nInput: nums = [1,4,7,10]\nOutput: 1\nExplanation: The maximum consecutive elements that we can select is 1.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000]) == 1\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9]) == 2\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996]) == 5\n assert candidate(nums = [1000000, 999999, 999998, 1, 2]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 6\n assert candidate(nums = [5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6]) == 5\n assert candidate(nums = [1, 4, 7, 10]) == 1\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 3, 5, 4, 7, 9, 8, 11, 13, 12]) == 6\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6]) == 7\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996]) == 5\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [2, 1, 5, 1, 1]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5]) == 6\n assert candidate(nums = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18]) == 3\n assert candidate(nums = [1000000]) == 1\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]) == 2\n assert candidate(nums = [1, 2, 2, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 9, 9, 10, 11, 12, 12, 12, 12, 13, 14, 15, 16, 16, 16, 17, 18, 19, 20, 20, 20, 20, 21, 22, 23, 24, 25, 25, 25, 25, 26, 27, 28, 29, 30]) == 31\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418]) == 4\n assert candidate(nums = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 3\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 10, 11, 12, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26]) == 7\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 2\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 2\n assert candidate(nums = [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]) == 26\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5, 999996, 6, 999995, 7, 999994, 8, 999993, 9, 999992, 10, 999991]) == 10\n assert candidate(nums = [100, 101, 102, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 13\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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 100\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\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 6\n assert candidate(nums = [100000, 99999, 99998, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [1000000, 1000000, 1000000, 999999, 999999, 999999, 999998, 999998, 999998, 999997, 999997, 999997]) == 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]) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 2\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]) == 2\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]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 2\n assert candidate(nums = [1, 10, 11, 12, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52, 60, 61, 62, 70, 71, 72, 80, 81, 82, 90, 91, 92]) == 3\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 20\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]) == 30\n assert candidate(nums = [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]) == 2\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]) == 2\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 11\n assert candidate(nums = [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]) == 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, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 11\n assert candidate(nums = [10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 12\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]) == 2\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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [1, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23, 24, 26, 27, 29, 30, 32, 33, 35, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51, 53, 54, 56, 57, 59, 60, 62, 63, 65, 66, 68, 69, 71, 72, 74, 75, 77, 78, 80, 81, 83, 84, 86, 87, 89, 90]) == 5\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]) == 40\n assert candidate(nums = [1, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23, 24, 26, 27, 29]) == 5\n assert candidate(nums = [3, 1, 2, 4, 6, 5, 7, 9, 8, 10, 12, 11, 13, 15, 14, 16, 18, 17, 19, 20]) == 20\n assert candidate(nums = [5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11]) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 22\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\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23]) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 11\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\n assert candidate(nums = [2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37]) == 4\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]) == 2\n assert candidate(nums = [1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10]) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7]) == 4\n assert candidate(nums = [100, 200, 101, 201, 102, 202, 103, 203, 104, 204, 105, 205]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 25]) == 14\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 10\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]) == 40\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == 20\n assert candidate(nums = [1, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8]) == 9\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 109, 118, 127, 136, 145, 154, 163, 172, 181, 190, 199]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 11\n assert candidate(nums = [1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 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]) == 11\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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 11\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 10\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]) == 30\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 14]) == 15\n assert candidate(nums = [10, 2, 10, 10, 2, 3, 4, 5, 6, 7, 8, 9]) == 10\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14, 16]) == 17\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000]) == 2\n assert candidate(nums = [100, 101, 102, 200, 201, 202, 300, 301, 302, 400, 401, 402, 500, 501, 502]) == 3\n assert candidate(nums = [1, 2, 3, 10, 11, 12, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52, 60, 61, 62, 70, 71, 72, 80, 81, 82, 90, 91, 92, 93, 94, 95]) == 6\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 31\n assert candidate(nums = [2, 1, 5, 1, 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\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 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]) == 11\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]) == 21\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000]) == 1\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23]) == 4\n assert candidate(nums = [500000, 500001, 500002, 500003, 500004, 500005, 500006, 500007, 500008, 500009, 500010]) == 11\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 9, 10, 10, 10, 10, 11, 12, 13]) == 14\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 8, 7, 9, 10, 12, 11, 14, 13, 15, 17, 16, 18, 20, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 30\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, 23, 22, 25, 24, 27, 26, 29, 28]) == 29\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 20\n assert candidate(nums = [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]) == 6\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\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\n assert candidate(nums = [1, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 1\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, 861, 903, 946, 990]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == 21\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986, 999985, 999984, 999983, 999982, 999981]) == 20\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15, 16, 18, 17, 19, 20]) == 20\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23]) == 6\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 16\n assert candidate(nums = [1, 1, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 8, 8, 9, 10, 11, 11, 11, 12, 13, 14, 14, 14, 15, 16, 17, 17, 17]) == 18\n assert candidate(nums = [5, 3, 1, 4, 2, 6, 8, 7, 9, 10, 12, 11]) == 12\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 20\n assert candidate(nums = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]) == 3\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109]) == 1\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]) == 31\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20]) == 4\n", "comparison": "exact"}, "public_tests": ["[2,1,5,1,1]", "[1,4,7,10]"], "hints": ["Sort the array and try using dynamic programming.", "Let dp[i] be the length of the longest consecutive elements ending at element at index i in the sorted array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxSelectedElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:21+00:00", "tests_total": 144, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_selected_elements(nums)", "container": null, "callable": "max_selected_elements", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3042, "task_id": "count-prefix-and-suffix-pairs-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string array words.\n\nLet's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:\n\n- isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.\n\nFor example, isPrefixAndSuffix(\"aba\", \"ababa\") is true because \"aba\" is a prefix of \"ababa\" and also a suffix, but isPrefixAndSuffix(\"abc\", \"abcd\") is false.\n\nReturn an integer denoting the number of index pairs (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) is true.\n\nExample 1:\n\nInput: words = [\"a\",\"aba\",\"ababa\",\"aa\"]\nOutput: 4\nExplanation: In this example, the counted index pairs are:\ni = 0 and j = 1 because isPrefixAndSuffix(\"a\", \"aba\") is true.\ni = 0 and j = 2 because isPrefixAndSuffix(\"a\", \"ababa\") is true.\ni = 0 and j = 3 because isPrefixAndSuffix(\"a\", \"aa\") is true.\ni = 1 and j = 2 because isPrefixAndSuffix(\"aba\", \"ababa\") is true.\nTherefore, the answer is 4.\n\nExample 2:\n\nInput: words = [\"pa\",\"papa\",\"ma\",\"mama\"]\nOutput: 2\nExplanation: In this example, the counted index pairs are:\ni = 0 and j = 1 because isPrefixAndSuffix(\"pa\", \"papa\") is true.\ni = 2 and j = 3 because isPrefixAndSuffix(\"ma\", \"mama\") is true.\nTherefore, the answer is 2.\n\nExample 3:\n\nInput: words = [\"abab\",\"ab\"]\nOutput: 0\nExplanation: In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix(\"abab\", \"ab\") is false.\nTherefore, the answer is 0.\n\nConstraints:\n\n- 1 <= words.length <= 50\n- 1 <= words[i].length <= 10\n- words[i] consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'abcabc', 'bc', 'abcabcabc']) == 3\n assert candidate(words = ['xyz', 'xyzxyz', 'zyx', 'z', 'x']) == 1\n assert candidate(words = ['z', 'zaz', 'zzz', 'zazaz']) == 4\n assert candidate(words = ['aaa', 'aaaa', 'aaaaa', 'aa', 'a']) == 3\n assert candidate(words = ['cat', 'tac', 'catcat', 'tacatc']) == 1\n assert candidate(words = ['pa', 'papa', 'ma', 'mama']) == 2\n assert candidate(words = ['m', 'mnm', 'nmn', 'mnmnm']) == 3\n assert candidate(words = ['test', 'testing', 'testtest', 'sett']) == 1\n assert candidate(words = ['y', 'yxy', 'xyx', 'yxyxy']) == 3\n assert candidate(words = ['hello', 'hellohello', 'world', 'worldworld']) == 2\n assert candidate(words = ['x', 'xx', 'xxx', 'xxxx']) == 6\n assert candidate(words = ['z', 'zzz', 'zzzzz', 'zzzzzzz']) == 6\n assert candidate(words = ['dog', 'dogcat', 'dogcatdog']) == 1\n assert candidate(words = ['a', 'aba', 'ababa', 'aa']) == 4\n assert candidate(words = ['t', 'tt', 'ttt', 'tttt', 'ttttt', 'tttttt']) == 15\n assert candidate(words = ['aabb', 'aabbcc', 'aabbccaabb']) == 1\n assert candidate(words = ['abc', 'abcabc', 'ab', 'a']) == 1\n assert candidate(words = ['z', 'zzz', 'zzzz', 'zzzzz']) == 6\n assert candidate(words = ['abab', 'ab']) == 0\n assert candidate(words = ['x', 'xx', 'xxx', 'xxxx']) == 6\n assert candidate(words = ['s', 'ss', 'sss', 'ssss', 'sssss']) == 10\n assert candidate(words = ['a', 'b', 'c', 'd']) == 0\n assert candidate(words = ['hello', 'hellohello', 'lohel', 'ohelloh']) == 1\n assert candidate(words = ['test', 'testtest', 'sttes', 'ttest']) == 1\n assert candidate(words = ['abc', 'abcabc', 'abcabcabc']) == 3\n assert candidate(words = ['abc', 'abcabc', 'bcb', 'bcbcbcb']) == 2\n assert candidate(words = ['xy', 'xyxy', 'yxyx', 'xyxyxy', 'yxyxyx', 'xyxyxyxy', 'yxyxyxyx', 'xyxyxyxyxy']) == 13\n assert candidate(words = ['abc', 'cab', 'bac', 'abcabc', 'abcabcabc', 'cababcabc', 'bacbacbac']) == 4\n assert candidate(words = ['abab', 'baba', 'ab', 'ba', 'aba', 'bab', 'ababab', 'bababa', 'abababa', 'bababab', 'abababab', 'babababa']) == 12\n assert candidate(words = ['ab', 'baba', 'abab', 'bababa', 'ababab', 'babababa', 'abababab', 'bababababa']) == 12\n assert candidate(words = ['abab', 'baba', 'ababa', 'babab', 'ababab', 'bababa', 'abababa', 'bababab', 'abababab', 'babababa']) == 8\n assert candidate(words = ['aabb', 'bbaa', 'aabbcc', 'ccaabb', 'aabbccaabb', 'bbaaabbbaa', 'ccaabbaacc']) == 2\n assert candidate(words = ['aaaaa', 'baaaaa', 'caaaaa', 'daaaaa', 'eaaaaa', 'faaaaa', 'baaaaaa', 'caaaaaa']) == 0\n assert candidate(words = ['z', 'zz', 'zzz', 'zzzz', 'zzzzz', 'zzzzzz', 'zzzzzzz']) == 21\n assert candidate(words = ['ababab', 'bababa', 'abab', 'baba', 'aba', 'ba', 'a', 'b', 'ab', 'ba', 'aba', 'bab', 'abb', 'bba']) == 4\n assert candidate(words = ['ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg']) == 0\n assert candidate(words = ['abc', 'cab', 'bac', 'abcabc', 'bcabc', 'abcabcabc']) == 3\n assert candidate(words = ['pqr', 'pqrpqr', 'qrpqrpqr', 'rpqrpqrpqr', 'pqrpqrpqr', 'qrpqrpqr', 'rpqrpqrpqr', 'pqrpqrpqr']) == 8\n assert candidate(words = ['aba', 'abacaba', 'cabacabac', 'abcabcabc']) == 1\n assert candidate(words = ['abcabc', 'abc', 'abcabcabc', 'abca', 'abcb', 'abcab', 'abcabcab', 'a', 'aa', 'aaa']) == 6\n assert candidate(words = ['xyz', 'xyzxyz', 'xyzxyzxyz', 'xyxzyx', 'xyzzyx']) == 3\n assert candidate(words = ['zzz', 'zzzz', 'zzzzz', 'zzzzzz', 'zzzzzzz', 'zzzzzzzz']) == 15\n assert candidate(words = ['aaaa', 'aaa', 'aa', 'a', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa', 'aaaaaaaaa', 'aaaaaaaaaa', 'aaaaaab', 'aaaaaaab', 'aaaaaaaab']) == 30\n assert candidate(words = ['mama', 'mamama', 'mamamama', 'ma', 'm', 'mam', 'mamam', 'mamama', 'mamamam', 'mamamama']) == 17\n assert candidate(words = ['aaa', 'aaaa', 'aaaaa', 'aa', 'a', 'aaaaaa', 'aaaaaaa']) == 14\n assert candidate(words = ['test', 'testtest', 'tset', 'sett', 'sttest', 'testset']) == 1\n assert candidate(words = ['ababab', 'bababa', 'ab', 'aba', 'baba', 'bababab', 'bababa', 'abab', 'bab']) == 3\n assert candidate(words = ['abcabc', 'abc', 'bcabc', 'abcabcabc', 'abcabca']) == 2\n assert candidate(words = ['abcabcabc', 'bcabcabcab', 'cabcabcab', 'abcabc', 'bcabc', 'cabc', 'abc', 'bc', 'c']) == 0\n assert candidate(words = ['aaa', 'aaabaaa', 'baaabaaa', 'aaabaaba', 'abaabaaa', 'aaabaaba', 'baaabaaa']) == 3\n assert candidate(words = ['abcdabcd', 'abcd', 'abcde', 'abcdeabcd', 'abcdeabcde']) == 2\n assert candidate(words = ['aaaa', 'aa', 'a', 'aaaaaa', 'aaa']) == 5\n assert candidate(words = ['xyz', 'xyzxyz', 'xyzxyzxyz', 'xy']) == 3\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa']) == 10\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == 45\n assert candidate(words = ['aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa', 'aaaaaaaaa']) == 21\n assert candidate(words = ['aaaa', 'aa', 'a', 'aaaaaa', 'aaa', 'aaaaaaa']) == 10\n assert candidate(words = ['xyz', 'xyzxyz', 'xyzxyzxyz', 'xy', 'xyxy', 'xyxyxy']) == 6\n assert candidate(words = ['ab', 'abcba', 'abcabcba', 'a', 'aba', 'abababa']) == 3\n assert candidate(words = ['abacaba', 'aba', 'abacababa', 'a']) == 1\n assert candidate(words = ['xyz', 'xyzyx', 'xyzxyz', 'xyzxyzyx', 'xyzxyzyxyz']) == 2\n assert candidate(words = ['xyxy', 'yxyx', 'xyxyxy', 'yxyxyx', 'xyxyxyxy', 'yxyxyxyx', 'xyxyxyxyxy', 'yxyxyxyxyx']) == 12\n assert candidate(words = ['xyz', 'xyzxyz', 'zyxzyx', 'xyzzyxxyz', 'xyz']) == 3\n assert candidate(words = ['aaa', 'aaaa', 'aaaaa', 'aaaaaa']) == 6\n assert candidate(words = ['abcabc', 'abc', 'abcabcabc', 'a', 'aa', 'aaa', 'aaaa']) == 8\n assert candidate(words = ['aaa', 'aa', 'a', 'aaaa', 'aaaaa']) == 7\n assert candidate(words = ['ab', 'abc', 'ababc', 'abcababc']) == 1\n assert candidate(words = ['p', 'pp', 'ppp', 'pppp', 'ppppp', 'pppppp', 'ppppppp']) == 21\n assert candidate(words = ['xyz', 'xyzyx', 'xyzxyz', 'zyxzyxzyx']) == 1\n assert candidate(words = ['zzz', 'zzzz', 'zz', 'z', 'zzzzz', 'zzzzzz', 'zzzzzzz', 'zzzzzzzz', 'zzzzzzzzz', 'zzzzzzzzzz']) == 40\n assert candidate(words = ['ab', 'aba', 'abab', 'ababa', 'ababab', 'abababa']) == 6\n assert candidate(words = ['xyz', 'xyzxyz', 'xyzxyzxyz', 'xyx']) == 3\n assert candidate(words = ['abcd', 'abcdabcd', 'abcde', 'abcdeabcde', 'ab', 'abab', 'abc', 'abcabc', 'a', 'aaaa']) == 5\n assert candidate(words = ['abcd', 'abcdabcd', 'bcdabcde', 'cdabcde', 'dabcde', 'abcde']) == 1\n assert candidate(words = ['mnop', 'nopm', 'opmn', 'pqrs', 'rspq', 'srpq', 'qpsr', 'mnopmnop', 'nopmnopm', 'opmnopno']) == 2\n assert candidate(words = ['x', 'xx', 'xxx', 'xxxx', 'xxxxx', 'xxxxxx', 'xxxxxxx', 'xxxxxxxx', 'xxxxxxxxx', 'xxxxxxxxxx']) == 45\n assert candidate(words = ['pqr', 'pqrpqr', 'pq', 'pqpq', 'prq', 'prqprq', 'pr', 'prpr', 'qpr', 'qprqpr']) == 5\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa']) == 28\n assert candidate(words = ['abc', 'bac', 'cab', 'abcabc', 'bacbac', 'cabcab', 'abcabca', 'bcabcabc', 'cababcab', 'abcabcabca']) == 5\n assert candidate(words = ['abc', 'abca', 'abcabc', 'cabcabc']) == 1\n assert candidate(words = ['abcd', 'bcde', 'cdef', 'defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno', 'mnop']) == 0\n assert candidate(words = ['aabb', 'bbaa', 'aabbcc', 'ccbaab', 'aabbccbaab']) == 0\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa']) == 15\n assert candidate(words = ['ababab', 'ab', 'abab', 'abababab', 'baba', 'abababa']) == 4\n assert candidate(words = ['xy', 'xyxy', 'xyxyxy', 'xyxyxyxy', 'xyxyxyxyxy']) == 10\n assert candidate(words = ['banana', 'ban', 'banana', 'nan', 'banananan', 'ananan']) == 1\n", "comparison": "exact"}, "public_tests": ["[\"a\",\"aba\",\"ababa\",\"aa\"]", "[\"pa\",\"papa\",\"ma\",\"mama\"]", "[\"abab\",\"ab\"]"], "hints": ["Iterate through all index pairs (i, j), such that i < j, and check isPrefixAndSuffix(words[i], words[j]).", "The answer is the total number of pairs where isPrefixAndSuffix(words[i], words[j]) == true."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().countPrefixSuffixPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:23+00:00", "tests_total": 119, "tests_dropped": 33, "flags": [], "topic_tags": ["array", "string", "trie", "rolling-hash", "string-matching", "hash-function"]}, "language": "ruby", "interface": {"raw_signature": "def count_prefix_suffix_pairs(words)", "container": null, "callable": "count_prefix_suffix_pairs", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3043, "task_id": "find-the-length-of-the-longest-common-prefix", "difficulty": "Medium", "problem_description": "You are given two arrays with positive integers arr1 and arr2.\n\nA prefix of a positive integer is an integer formed by one or more of its digits, starting from its leftmost digit. For example, 123 is a prefix of the integer 12345, while 234 is not.\n\nA common prefix of two integers a and b is an integer c, such that c is a prefix of both a and b. For example, 5655359 and 56554 have common prefixes 565 and 5655 while 1223 and 43456 do not have a common prefix.\n\nYou need to find the length of the longest common prefix between all pairs of integers (x, y) such that x belongs to arr1 and y belongs to arr2.\n\nReturn the length of the longest common prefix among all pairs. If no common prefix exists among them, return 0.\n\nExample 1:\n\nInput: arr1 = [1,10,100], arr2 = [1000]\nOutput: 3\nExplanation: There are 3 pairs (arr1[i], arr2[j]):\n- The longest common prefix of (1, 1000) is 1.\n- The longest common prefix of (10, 1000) is 10.\n- The longest common prefix of (100, 1000) is 100.\nThe longest common prefix is 100 with a length of 3.\n\nExample 2:\n\nInput: arr1 = [1,2,3], arr2 = [4,4,4]\nOutput: 0\nExplanation: There exists no common prefix for any pair (arr1[i], arr2[j]), hence we return 0.\nNote that common prefixes between elements of the same array do not count.\n\nConstraints:\n\n- 1 <= arr1.length, arr2.length <= 5 * 10^4\n- 1 <= arr1[i], arr2[i] <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr1 = [100000, 99999, 88888],arr2 = [10000, 9999, 8888]) == 5\n assert candidate(arr1 = [1, 10, 100, 1000],arr2 = [1000, 10000, 100000]) == 4\n assert candidate(arr1 = [1, 1, 1],arr2 = [1, 1, 1]) == 1\n assert candidate(arr1 = [100000000],arr2 = [10000000, 1000000, 100000]) == 8\n assert candidate(arr1 = [123, 456, 789],arr2 = [12345, 45678, 78901]) == 3\n assert candidate(arr1 = [1, 2, 3],arr2 = [4, 4, 4]) == 0\n assert candidate(arr1 = [1],arr2 = [2]) == 0\n assert candidate(arr1 = [10, 20, 30],arr2 = [100, 200, 300]) == 2\n assert candidate(arr1 = [5, 55, 555],arr2 = [5, 50, 55]) == 2\n assert candidate(arr1 = [5678, 567, 56],arr2 = [56789, 56780, 5670]) == 4\n assert candidate(arr1 = [1],arr2 = [10, 100, 1000]) == 1\n assert candidate(arr1 = [5655359, 56554],arr2 = [565, 5655]) == 4\n assert candidate(arr1 = [1, 11, 111],arr2 = [111, 11, 1]) == 3\n assert candidate(arr1 = [123, 12, 1],arr2 = [1234, 12, 123]) == 3\n assert candidate(arr1 = [111, 222, 333],arr2 = [1111, 2222, 3333]) == 3\n assert candidate(arr1 = [123, 456, 789],arr2 = [1234, 4567, 7890]) == 3\n assert candidate(arr1 = [1234, 123, 12],arr2 = [12345, 1230, 120]) == 4\n assert candidate(arr1 = [12345, 67890, 1234],arr2 = [123456, 1234, 112233]) == 5\n assert candidate(arr1 = [1, 10, 100],arr2 = [1000]) == 3\n assert candidate(arr1 = [100, 200, 300],arr2 = [100, 200, 300]) == 3\n assert candidate(arr1 = [1234567, 123456, 12345, 1234, 123],arr2 = [12345678, 1234567, 123456, 12345, 1234]) == 7\n assert candidate(arr1 = [111111, 222222, 333333],arr2 = [1111111, 2222222, 3333333, 111111, 222222, 333333]) == 6\n assert candidate(arr1 = [1, 101, 1001, 10001],arr2 = [10, 100, 1000, 10000]) == 4\n assert candidate(arr1 = [888888, 777777, 666666, 555555],arr2 = [8888888, 7777777, 6666666, 5555555, 8888880, 7777770, 6666660, 5555550]) == 6\n assert candidate(arr1 = [12345, 54321, 67890, 98765],arr2 = [123456, 654321, 678901, 567890]) == 5\n assert candidate(arr1 = [1, 10, 100, 1000, 10000],arr2 = [1, 10, 100, 1000, 10000, 100000]) == 5\n assert candidate(arr1 = [12345, 54321, 13579],arr2 = [123456, 543210, 135790]) == 5\n assert candidate(arr1 = [1, 10, 100, 1000, 10000],arr2 = [10000, 1000, 100, 10, 1]) == 5\n assert candidate(arr1 = [1001, 2002, 3003, 4004],arr2 = [10010, 20020, 30030, 40040]) == 4\n assert candidate(arr1 = [5, 55, 555, 5555, 55555],arr2 = [555555, 555550, 55550, 5550, 550]) == 5\n assert candidate(arr1 = [123456, 654321, 234567],arr2 = [1234567, 6543217, 2345678]) == 6\n assert candidate(arr1 = [55555, 66666, 77777],arr2 = [555555, 666666, 777777]) == 5\n assert candidate(arr1 = [123456, 654321, 111111, 222222],arr2 = [1234560, 6543210, 1111110, 2222220]) == 6\n assert candidate(arr1 = [1, 10, 100, 1000, 10000],arr2 = [10, 100, 1000, 10000, 100000]) == 5\n assert candidate(arr1 = [100000, 200000, 300000, 400000],arr2 = [1000001, 2000002, 3000003, 4000004]) == 6\n assert candidate(arr1 = [1234, 4321, 1111, 2222],arr2 = [12345, 43210, 11111, 22222]) == 4\n assert candidate(arr1 = [12345, 23456, 34567],arr2 = [54321, 65432, 76543]) == 0\n assert candidate(arr1 = [99999, 888888, 7777777],arr2 = [999999, 8888888, 77777777]) == 7\n assert candidate(arr1 = [99999, 88888, 77777, 66666],arr2 = [999999, 888888, 777777, 666666]) == 5\n assert candidate(arr1 = [1, 10, 100, 1000],arr2 = [10000, 100000, 1000000]) == 4\n assert candidate(arr1 = [112233, 223344, 334455],arr2 = [11223311, 22334422, 33445533]) == 6\n assert candidate(arr1 = [1001001, 2002002, 3003003],arr2 = [10010010, 20020020, 30030030]) == 7\n assert candidate(arr1 = [1, 10, 100, 1000],arr2 = [10000, 1000, 100, 10]) == 4\n assert candidate(arr1 = [1001001, 1010101, 1101101],arr2 = [10010010, 10101010, 11011010]) == 7\n assert candidate(arr1 = [9, 99, 999, 9999],arr2 = [99999, 999999, 9999999]) == 4\n assert candidate(arr1 = [123, 456, 789, 101112],arr2 = [123456, 456789, 789101, 10111213]) == 6\n assert candidate(arr1 = [101010, 202020, 303030],arr2 = [1010101, 2020202, 3030303]) == 6\n assert candidate(arr1 = [9999999, 8888888, 7777777],arr2 = [99999999, 88888888, 77777777]) == 7\n assert candidate(arr1 = [1, 22, 333, 4444, 55555],arr2 = [10, 220, 3330, 44440, 555550]) == 5\n assert candidate(arr1 = [54321, 12345, 55555],arr2 = [543210, 123450, 555550]) == 5\n assert candidate(arr1 = [1, 11, 111, 1111],arr2 = [11111, 111111, 1111111, 11111111]) == 4\n assert candidate(arr1 = [101010, 1010, 10],arr2 = [1010101, 10101, 101]) == 6\n assert candidate(arr1 = [1, 11, 111, 1111, 11111, 111111],arr2 = [10, 110, 1110, 11110, 111110, 1111110]) == 6\n assert candidate(arr1 = [11, 22, 33, 44, 55],arr2 = [111, 222, 333, 444, 555]) == 2\n assert candidate(arr1 = [123, 456, 789, 101112, 131415],arr2 = [1234, 4567, 7890, 10111213, 13141516]) == 6\n assert candidate(arr1 = [123, 456, 789],arr2 = [123123, 456456, 789789]) == 3\n assert candidate(arr1 = [1111111, 2222222, 3333333],arr2 = [11111111, 22222222, 33333333]) == 7\n assert candidate(arr1 = [123456, 12345, 1234, 123, 12, 1],arr2 = [1234567, 1234560, 123450, 12340, 1230, 120]) == 6\n assert candidate(arr1 = [999, 888, 777, 666, 555, 444, 333, 222, 111],arr2 = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 3\n assert candidate(arr1 = [1, 2, 3, 4, 5],arr2 = [5, 4, 3, 2, 1]) == 1\n assert candidate(arr1 = [1, 2, 3, 4, 5],arr2 = [10, 20, 30, 40, 50, 12, 21, 32, 43, 54]) == 1\n assert candidate(arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],arr2 = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 1\n assert candidate(arr1 = [111, 222, 333, 444, 555],arr2 = [1111, 2222, 3333, 4444, 5555]) == 3\n assert candidate(arr1 = [123123, 234234, 345345, 456456],arr2 = [1231231, 2342342, 3453453, 4564564]) == 6\n assert candidate(arr1 = [1, 11, 111, 1111],arr2 = [1, 11, 111, 1111, 11111, 111111]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,10,100]\n[1000]", "[1,2,3]\n[4,4,4]"], "hints": ["Put all the possible prefixes of each element in arr1 into a HashSet.", "For all the possible prefixes of each element in arr2, check if it exists in the HashSet."], "metadata": {"canonical_parameter_names": ["arr1", "arr2"], "leetcode_dataset_entry_point": "Solution().longestCommonPrefix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:26+00:00", "tests_total": 121, "tests_dropped": 56, "flags": [], "topic_tags": ["array", "hash-table", "string", "trie"]}, "language": "ruby", "interface": {"raw_signature": "def longest_common_prefix(arr1, arr2)", "container": null, "callable": "longest_common_prefix", "parameters": [{"name": "arr1", "type": "Integer[]"}, {"name": "arr2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3044, "task_id": "most-frequent-prime", "difficulty": "Medium", "problem_description": "You are given a m x n 0-indexed 2D matrix mat. From every cell, you can create numbers in the following way:\n\n- There could be at most 8 paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east.\n- Select a path from them and append digits in this path to the number being formed by traveling in this direction.\n- Note that numbers are generated at every step, for example, if the digits along the path are 1, 9, 1, then there will be three numbers generated along the way: 1, 19, 191.\n\nReturn the most frequent prime number greater than 10 out of all the numbers created by traversing the matrix or -1 if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the largest among them.\n\nNote: It is invalid to change the direction during the move.\n\nExample 1:\n\nInput: mat = [[1,1],[9,9],[1,1]]\nOutput: 19\nExplanation:\nFrom cell (0,0) there are 3 possible directions and the numbers greater than 10 which can be created in those directions are:\nEast: [11], South-East: [19], South: [19,191].\nNumbers greater than 10 created from the cell (0,1) in all possible directions are: [19,191,19,11].\nNumbers greater than 10 created from the cell (1,0) in all possible directions are: [99,91,91,91,91].\nNumbers greater than 10 created from the cell (1,1) in all possible directions are: [91,91,99,91,91].\nNumbers greater than 10 created from the cell (2,0) in all possible directions are: [11,19,191,19].\nNumbers greater than 10 created from the cell (2,1) in all possible directions are: [11,19,19,191].\nThe most frequent prime number among all the created numbers is 19.\n\nExample 2:\n\nInput: mat = [[7]]\nOutput: -1\nExplanation: The only number which can be formed is 7. It is a prime number however it is not greater than 10, so return -1.\n\nExample 3:\n\nInput: mat = [[9,7,8],[4,6,5],[2,8,6]]\nOutput: 97\nExplanation:\nNumbers greater than 10 created from the cell (0,0) in all possible directions are: [97,978,96,966,94,942].\nNumbers greater than 10 created from the cell (0,1) in all possible directions are: [78,75,76,768,74,79].\nNumbers greater than 10 created from the cell (0,2) in all possible directions are: [85,856,86,862,87,879].\nNumbers greater than 10 created from the cell (1,0) in all possible directions are: [46,465,48,42,49,47].\nNumbers greater than 10 created from the cell (1,1) in all possible directions are: [65,66,68,62,64,69,67,68].\nNumbers greater than 10 created from the cell (1,2) in all possible directions are: [56,58,56,564,57,58].\nNumbers greater than 10 created from the cell (2,0) in all possible directions are: [28,286,24,249,26,268].\nNumbers greater than 10 created from the cell (2,1) in all possible directions are: [86,82,84,86,867,85].\nNumbers greater than 10 created from the cell (2,2) in all possible directions are: [68,682,66,669,65,658].\nThe most frequent prime number among all the created numbers is 97.\n\nConstraints:\n\n- m == mat.length\n- n == mat[i].length\n- 1 <= m, n <= 6\n- 1 <= mat[i][j] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[7]]) == -1\n assert candidate(mat = [[1, 1], [9, 9], [1, 1]]) == 19\n assert candidate(mat = [[2, 3, 5], [3, 5, 7], [5, 7, 1]]) == 53\n assert candidate(mat = [[9, 7, 8], [4, 6, 5], [2, 8, 6]]) == 97\n assert candidate(mat = [[3, 3, 3], [3, 3, 3], [3, 3, 3]]) == -1\n assert candidate(mat = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 11\n assert candidate(mat = [[2, 3, 5], [7, 1, 1], [6, 4, 9]]) == 41\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 8, 7, 6], [5, 4, 3, 2]]) == 67\n assert candidate(mat = [[2, 3, 5], [7, 1, 4], [6, 9, 8]]) == 97\n assert candidate(mat = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 1, 2, 3]]) == 83\n assert candidate(mat = [[8, 1, 6, 3], [3, 5, 7, 8], [4, 9, 2, 4], [9, 5, 1, 8]]) == 59\n assert candidate(mat = [[3, 5, 7, 2], [9, 4, 6, 8], [1, 3, 7, 5], [2, 8, 4, 9]]) == 47\n assert candidate(mat = [[3, 7, 2, 5, 9], [8, 6, 4, 3, 1], [7, 5, 3, 2, 9], [6, 4, 2, 1, 8], [5, 3, 1, 9, 7]]) == 23\n assert candidate(mat = [[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]]) == 43\n assert candidate(mat = [[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]]) == 89\n assert candidate(mat = [[5, 9, 3, 8, 2, 7], [6, 1, 4, 5, 9, 3], [8, 4, 2, 6, 1, 5], [7, 3, 5, 8, 4, 2], [9, 6, 8, 7, 3, 1], [4, 2, 3, 9, 6, 5]]) == 83\n assert candidate(mat = [[7, 7, 7, 7, 7, 7], [7, 7, 7, 7, 7, 7], [7, 7, 7, 7, 7, 7], [7, 7, 7, 7, 7, 7], [7, 7, 7, 7, 7, 7], [7, 7, 7, 7, 7, 7]]) == -1\n assert candidate(mat = [[5, 3, 7, 9, 1, 5], [3, 1, 5, 7, 9, 3], [7, 9, 3, 1, 5, 7], [9, 1, 5, 3, 7, 9], [1, 5, 7, 9, 3, 1], [5, 7, 9, 3, 1, 5]]) == 97\n assert candidate(mat = [[2, 7, 3, 5, 8, 6], [1, 9, 4, 7, 2, 5], [8, 3, 6, 1, 9, 4], [7, 2, 5, 8, 3, 6], [9, 4, 7, 2, 5, 8], [6, 1, 9, 4, 7, 2]]) == 47\n assert candidate(mat = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 11\n assert candidate(mat = [[2, 3, 5, 7], [3, 5, 7, 2], [5, 7, 2, 3], [7, 2, 3, 5]]) == 53\n assert candidate(mat = [[1, 3, 2, 1, 1], [1, 9, 2, 1, 9], [1, 1, 2, 9, 1], [1, 9, 2, 1, 9], [1, 1, 1, 1, 1]]) == 11\n assert candidate(mat = [[7, 3, 1, 6, 8, 2], [5, 9, 4, 7, 1, 3], [6, 2, 8, 5, 3, 9], [1, 4, 7, 2, 8, 5], [3, 6, 9, 1, 4, 7], [8, 5, 2, 9, 7, 3]]) == 73\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 89\n assert candidate(mat = [[9, 3, 7, 2, 5, 8], [1, 6, 4, 9, 2, 3], [7, 8, 6, 5, 1, 9], [3, 4, 1, 2, 8, 7], [5, 6, 9, 8, 7, 3], [2, 4, 7, 8, 6, 5]]) == 73\n assert candidate(mat = [[5, 3, 2, 8, 9, 4], [7, 1, 6, 5, 3, 2], [9, 8, 7, 6, 5, 4], [3, 2, 1, 8, 9, 7], [1, 2, 3, 4, 5, 6], [7, 8, 9, 1, 2, 3]]) == 23\n assert candidate(mat = [[3, 7, 2, 5, 9, 1], [6, 1, 8, 3, 4, 7], [5, 9, 2, 6, 8, 3], [4, 7, 3, 1, 5, 6], [9, 8, 7, 6, 5, 4], [2, 3, 4, 5, 6, 7]]) == 83\n assert candidate(mat = [[7, 7, 7], [7, 7, 7], [7, 7, 7], [7, 7, 7], [7, 7, 7]]) == -1\n assert candidate(mat = [[7, 8, 9], [8, 9, 7], [9, 7, 8], [7, 8, 9], [8, 9, 7]]) == 97\n assert candidate(mat = [[5, 3, 7, 1, 9], [2, 6, 5, 3, 7], [8, 9, 2, 6, 5], [3, 7, 1, 9, 2], [6, 5, 3, 7, 1]]) == 73\n assert candidate(mat = [[1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [1, 3, 5, 7, 9]]) == 53\n assert candidate(mat = [[5, 3, 5, 9, 2, 8], [2, 4, 2, 8, 7, 7], [3, 7, 8, 6, 3, 8], [7, 3, 6, 2, 6, 2], [5, 8, 4, 3, 1, 6], [7, 1, 5, 6, 1, 9]]) == 73\n assert candidate(mat = [[9, 8, 7, 6, 5], [8, 7, 6, 5, 4], [7, 6, 5, 4, 3], [6, 5, 4, 3, 2], [5, 4, 3, 2, 1]]) == 67\n assert candidate(mat = [[8, 9, 9, 8, 9, 8], [9, 8, 8, 9, 8, 9], [9, 8, 9, 8, 9, 8], [8, 9, 8, 9, 8, 9], [9, 8, 9, 8, 9, 8], [8, 9, 8, 9, 8, 9]]) == 89\n assert candidate(mat = [[3, 1, 4, 1, 5], [9, 2, 6, 5, 3], [5, 8, 9, 7, 9], [3, 2, 3, 8, 4], [6, 2, 6, 4, 3]]) == 23\n assert candidate(mat = [[5, 9, 3, 7, 1], [2, 4, 6, 8, 3], [7, 1, 5, 9, 3], [3, 5, 7, 2, 4], [9, 1, 2, 6, 8]]) == 71\n assert candidate(mat = [[9, 7, 3, 1, 8, 6], [2, 5, 9, 4, 7, 1], [3, 8, 1, 2, 5, 9], [1, 6, 7, 3, 8, 2], [9, 4, 2, 6, 7, 3], [5, 8, 3, 9, 2, 1]]) == 23\n assert candidate(mat = [[7, 3, 5, 2, 9], [8, 6, 4, 1, 7], [3, 2, 8, 6, 5], [4, 1, 9, 7, 3], [2, 8, 6, 4, 1]]) == 67\n assert candidate(mat = [[5, 3, 1], [3, 5, 3], [1, 3, 5]]) == 53\n assert candidate(mat = [[2, 3, 5, 7, 9, 1], [3, 5, 7, 9, 1, 2], [5, 7, 9, 1, 2, 3], [7, 9, 1, 2, 3, 5], [9, 1, 2, 3, 5, 7], [1, 2, 3, 5, 7, 9]]) == 97\n assert candidate(mat = [[9, 9, 9, 9, 9, 9], [9, 8, 8, 8, 8, 9], [9, 8, 7, 7, 8, 9], [9, 8, 7, 6, 7, 9], [9, 8, 7, 7, 8, 9], [9, 8, 8, 8, 8, 9]]) == 89\n assert candidate(mat = [[7, 9, 5, 8, 2], [6, 3, 1, 9, 4], [1, 6, 7, 4, 3], [9, 8, 3, 2, 5], [4, 5, 8, 7, 9]]) == 73\n assert candidate(mat = [[8, 3, 1, 7, 9, 2], [4, 6, 8, 3, 1, 5], [9, 7, 5, 3, 1, 7], [2, 4, 6, 8, 3, 1], [5, 9, 7, 5, 3, 1], [1, 7, 9, 2, 4, 6]]) == 31\n assert candidate(mat = [[7, 1, 2, 3, 4, 5], [6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6], [7, 8, 9, 1, 2, 3], [4, 5, 6, 7, 8, 9], [1, 1, 1, 1, 1, 1]]) == 11\n assert candidate(mat = [[7, 3, 8, 9, 5, 1], [4, 6, 2, 7, 3, 8], [9, 5, 1, 4, 6, 2], [7, 3, 8, 9, 5, 1], [4, 6, 2, 7, 3, 8], [9, 5, 1, 4, 6, 2]]) == 83\n assert candidate(mat = [[3, 2, 5, 7, 9], [7, 8, 5, 3, 1], [2, 6, 9, 4, 3], [5, 1, 8, 2, 6], [9, 7, 3, 5, 1]]) == 73\n assert candidate(mat = [[3, 5, 7, 2, 1], [5, 3, 5, 3, 5], [7, 5, 3, 5, 7], [2, 1, 5, 3, 5], [1, 2, 3, 5, 3]]) == 53\n assert candidate(mat = [[5, 3, 7, 1, 9, 2], [3, 1, 5, 7, 2, 9], [7, 9, 2, 3, 5, 1], [9, 2, 1, 5, 3, 7], [2, 1, 5, 3, 7, 9], [1, 5, 3, 7, 9, 2]]) == 53\n assert candidate(mat = [[5, 2, 8, 3, 9], [1, 7, 4, 6, 2], [9, 3, 8, 5, 1], [4, 6, 2, 8, 3], [7, 5, 1, 9, 4]]) == 43\n assert candidate(mat = [[1, 3, 1, 3, 1], [3, 1, 3, 1, 3], [1, 3, 1, 3, 1], [3, 1, 3, 1, 3], [1, 3, 1, 3, 1]]) == 31\n assert candidate(mat = [[3, 7, 2, 5, 9, 1], [4, 6, 8, 3, 7, 2], [5, 9, 1, 4, 6, 8], [2, 5, 9, 1, 4, 6], [8, 3, 7, 2, 5, 9], [1, 4, 6, 8, 3, 7]]) == 59\n assert candidate(mat = [[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]]) == 83\n", "comparison": "exact"}, "public_tests": ["[[1,1],[9,9],[1,1]]", "[[7]]", "[[9,7,8],[4,6,5],[2,8,6]]"], "hints": ["Use recursion to find all possible numbers for each cell and then check for prime."], "metadata": {"canonical_parameter_names": ["mat"], "leetcode_dataset_entry_point": "Solution().mostFrequentPrime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:28+00:00", "tests_total": 81, "tests_dropped": 29, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "math", "matrix", "counting", "enumeration", "number-theory", "primality-test", "sieve-theory", "prime-number-sieve"]}, "language": "ruby", "interface": {"raw_signature": "def most_frequent_prime(mat)", "container": null, "callable": "most_frequent_prime", "parameters": [{"name": "mat", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3045, "task_id": "count-prefix-and-suffix-pairs-ii", "difficulty": "Hard", "problem_description": "You are given a 0-indexed string array words.\n\nLet's define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2:\n\n- isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.\n\nFor example, isPrefixAndSuffix(\"aba\", \"ababa\") is true because \"aba\" is a prefix of \"ababa\" and also a suffix, but isPrefixAndSuffix(\"abc\", \"abcd\") is false.\n\nReturn an integer denoting the number of index pairs (i, j) such that i < j, and isPrefixAndSuffix(words[i], words[j]) is true.\n\nExample 1:\n\nInput: words = [\"a\",\"aba\",\"ababa\",\"aa\"]\nOutput: 4\nExplanation: In this example, the counted index pairs are:\ni = 0 and j = 1 because isPrefixAndSuffix(\"a\", \"aba\") is true.\ni = 0 and j = 2 because isPrefixAndSuffix(\"a\", \"ababa\") is true.\ni = 0 and j = 3 because isPrefixAndSuffix(\"a\", \"aa\") is true.\ni = 1 and j = 2 because isPrefixAndSuffix(\"aba\", \"ababa\") is true.\nTherefore, the answer is 4.\n\nExample 2:\n\nInput: words = [\"pa\",\"papa\",\"ma\",\"mama\"]\nOutput: 2\nExplanation: In this example, the counted index pairs are:\ni = 0 and j = 1 because isPrefixAndSuffix(\"pa\", \"papa\") is true.\ni = 2 and j = 3 because isPrefixAndSuffix(\"ma\", \"mama\") is true.\nTherefore, the answer is 2.\n\nExample 3:\n\nInput: words = [\"abab\",\"ab\"]\nOutput: 0\nExplanation: In this example, the only valid index pair is i = 0 and j = 1, and isPrefixAndSuffix(\"abab\", \"ab\") is false.\nTherefore, the answer is 0.\n\nConstraints:\n\n- 1 <= words.length <= 10^5\n- 1 <= words[i].length <= 10^5\n- words[i] consists only of lowercase English letters.\n- The sum of the lengths of all words[i] does not exceed 5 * 10^5.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['aaaa', 'aa', 'a']) == 0\n assert candidate(words = ['a', 'a', 'a', 'a', 'a']) == 10\n assert candidate(words = ['x', 'xx', 'xxx', 'xxxx']) == 6\n assert candidate(words = ['abab', 'ab']) == 0\n assert candidate(words = ['x', 'xx', 'xxx', 'xxxx', 'xxxxx']) == 10\n assert candidate(words = ['z', 'zz', 'zzz', 'zzzz', 'zzzzz', 'zzzzzz']) == 15\n assert candidate(words = ['hello', 'hellohello', 'hellohellohello', 'he']) == 3\n assert candidate(words = ['abc', 'abcabc', 'abcd', 'abcabcabc']) == 3\n assert candidate(words = ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']) == 45\n assert candidate(words = ['unique', 'uniqueword', 'uniquewordunique', 'uniq']) == 1\n assert candidate(words = ['abc', 'abcabc', 'abcabcabc']) == 3\n assert candidate(words = ['xyz', 'xyzxyz', 'zyxzyx']) == 1\n assert candidate(words = ['abcd', 'abcdeabcda', 'ab']) == 0\n assert candidate(words = ['a', 'aba', 'ababa', 'aa']) == 4\n assert candidate(words = ['pa', 'papa', 'ma', 'mama']) == 2\n assert candidate(words = ['test', 'testtest', 'testtesttest', 't']) == 3\n assert candidate(words = ['abc', 'abcabc', 'abcabcabc', 'a']) == 3\n assert candidate(words = ['pattern', 'patternpattern', 'patternpatternpattern', 'patternpatternpatternpattern']) == 6\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == 45\n assert candidate(words = ['mississippi', 'issis', 'sis', 'issippi', 'iss', 'missi', 'ippi', 'pi', 'ssippi', 'mississipi', 'ississippiissippi']) == 0\n assert candidate(words = ['aaaabbbb', 'aaaabbbbcccc', 'aaaabbbbccccdddd', 'aaaabbbbccccddddaaaa', 'aa', 'bb', 'cc', 'dd']) == 0\n assert candidate(words = ['abcabcabc', 'abc', 'abcabc', 'ab', 'a', 'abcabcabcabcabc']) == 4\n assert candidate(words = ['ababab', 'abab', 'ab', 'a', 'babab', 'bab', 'b']) == 0\n assert candidate(words = ['xyzyxyzyx', 'xyzyx', 'zyxzyx', 'xyz', 'zyx', 'yzy', 'zyzy', 'yzyxyzyx', 'yzyxyzyxyzyxyzyx']) == 1\n assert candidate(words = ['repeat', 'repeatrepeat', 'repeatrepeatrepeat', 'peat', 'eat', 'at', 't', 'rep', 're', 'r', 'e', 'a', 'p', 'te']) == 3\n assert candidate(words = ['abcde', 'edcba', 'abcdeabcde', 'edcbaedcba', 'abcdeedcbaabcde']) == 3\n assert candidate(words = ['xyxyxy', 'xyxyxyxyxy', 'xyxyxyxyxyxyxy', 'xy', 'yx', 'x', 'y', 'xyxy', 'yxyx', 'xyyx', 'xxyx']) == 7\n assert candidate(words = ['prefixsuffix', 'prefixsuffixprefixsuffix', 'prefixsuffixprefixsuffixprefixsuffix']) == 3\n assert candidate(words = ['abcdeabcde', 'bcdeabcd', 'cdeabcde', 'deabcdec', 'eabcdabc', 'abcde', 'bcde', 'cde', 'de', 'e', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == 1\n assert candidate(words = ['longwordlongword', 'longwordlongwordlongword', 'longword', 'word', 'long', 'wo', 'rd', 'ngwordlongword', 'wordlongwordlong', 'ngwordlongwordngwordlongword']) == 2\n assert candidate(words = ['abcdabcdabcd', 'abcdabcd', 'abcd', 'abc', 'ab', 'a', 'abcdabcdabcdabcdabcdabcd']) == 3\n assert candidate(words = ['pattern', 'ternpat', 'ternpatpat', 'pat', 'tern', 'patternpat', 'ternpattern', 'patterntern', 'ternpatternpat']) == 3\n assert candidate(words = ['abcdabcdabcdabcd', 'abcdabcdabcd', 'abcdabcd', 'abcd', 'abc', 'ab', 'a', 'b', 'c', 'd', 'abcdabcdabcdabcdabcdabcdabcdabcd', 'abcdabcdabcdabcdabcdabcdabcd', 'abcdabcdabcdabcdabcdabcd', 'abcdabcdabcdabcdabcd', 'abcdabcdabcdabcd', 'abcdabcdabcd', 'abcdabcd', 'abcd', 'abc', 'ab', 'a', 'b', 'c', 'd']) == 32\n assert candidate(words = ['aaaaa', 'aaa', 'aaaa', 'aaaaaa', 'aa']) == 4\n assert candidate(words = ['prefixsuffix', 'prefix', 'suffix', 'prefixprefix', 'suffixsuffix', 'pre', 'suf']) == 2\n assert candidate(words = ['xyxyxyxy', 'xyxy', 'xyxyxy', 'xy', 'x', 'xyxyxyxyxyxy']) == 5\n assert candidate(words = ['xyxyxyxyxy', 'xyxyxyxy', 'xyxyxy', 'xyxy', 'xy', 'x', 'y', 'xyxyxyxyxyxyxyxy', 'xyxyxyxyxyxyxyxyxyxyxy', 'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxy', 'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy']) == 26\n assert candidate(words = ['complexwordcomplexword', 'complexword', 'complex', 'com', 'co', 'complexwordcomplexwordcomplexword']) == 2\n assert candidate(words = ['aaaa', 'aa', 'a', 'aaaaaaaaaaaa', 'aaaa']) == 6\n assert candidate(words = ['abcabcabc', 'abc', 'abcabc', 'ab', 'a', 'b', 'c']) == 1\n assert candidate(words = ['abcdabcd', 'abcd', 'cdab', 'dabc', 'bcda', 'cabd', 'bacd', 'abcdabcdabcd', 'abcdabcdabcdabcd', 'abcdabcdabcdabcdabcdabcdabcdabcd']) == 9\n assert candidate(words = ['abcabcabc', 'abcabc', 'abc', 'a', 'b', 'c', 'abcabcabcabc']) == 3\n assert candidate(words = ['longprefix', 'longprefixlongprefix', 'longprefixlongprefixlongprefix']) == 3\n assert candidate(words = ['abc', 'abcabc', 'abcabcabc', 'abcabcabcabc']) == 6\n assert candidate(words = ['abcabcabc', 'abcabc', 'abc', 'a', 'b', 'c']) == 0\n assert candidate(words = ['prefixsuffix', 'prefix', 'suffix', 'prefixsuffixprefixsuffix', 'prefixprefix', 'suffixsuffix', 'prefixsuffixprefix', 'suffixprefixsuffix']) == 5\n assert candidate(words = ['repeatedrepeated', 'repeated', 'repeatedrepeatedrepeated', 'repeatedrepeatedrepeatedrepeated', 'repeatedrepeatedrepeatedrepeatedrepeated', 'repeatedrepeatedrepeated', 'repeated', 'repeatedrepeatedrepeatedrepeatedrepeated']) == 20\n assert candidate(words = ['aaaa', 'aaab', 'aabb', 'abbb', 'bbbb', 'baaa', 'baab', 'babb', 'bbba', 'bbbb', 'abab', 'baba', 'abba', 'baab', 'abba', 'baab', 'abba', 'baab']) == 10\n assert candidate(words = ['abcd', 'abcdabcd', 'abcdabcdabcd', 'abcde', 'abcdeabcde']) == 4\n assert candidate(words = ['abacaba', 'abac', 'acaba', 'aba', 'ba', 'a', 'abacabaabacaba', 'abacabaabacabaabacaba']) == 7\n assert candidate(words = ['banana', 'anan', 'nana', 'anana', 'banana', 'bananaana', 'anana', 'ana', 'nana', 'banana']) == 5\n assert candidate(words = ['aabbcc', 'bbccdd', 'ccddaa', 'aabb', 'bbaa', 'ccdd', 'aabbccdd', 'ddccbb', 'bbccddaa', 'aabbccbbcc', 'ccddbbcc', 'bbccddcc', 'aabbccddccdd', 'ddccbbccbbcc']) == 0\n assert candidate(words = ['abcdabcdabcd', 'abcd', 'abc', 'ab', 'a', 'abcdabcd']) == 1\n assert candidate(words = ['aaaaaa', 'aaaaaaa', 'aaaaaaaa', 'aaaaaaaaa', 'aaaaaaaaaa']) == 10\n assert candidate(words = ['aabb', 'aabbaabb', 'aabbaabbaabb', 'aabbaabbaabbaabb', 'aabbaabbaabbaabbaabb', 'aabb', 'aabbaabb', 'aabbaabbaabb', 'aabbaabbaabbaabbaabb']) == 27\n assert candidate(words = ['abcabcabc', 'abcabc', 'abc', 'ab', 'a']) == 0\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa']) == 15\n assert candidate(words = ['ababab', 'abab', 'aba', 'ab', 'a', 'abcabcabcabc']) == 0\n assert candidate(words = ['longwordlongword', 'longword', 'word', 'long', 'short', 'longwordlong', 'longwordshort']) == 1\n assert candidate(words = ['racecar', 'race', 'car', 'racecar', 'racecarcar', 'racecarcarcar']) == 1\n assert candidate(words = ['ababababab', 'babababa', 'abab', 'bab', 'ab', 'a', 'abababababababababab', 'abababababababababababababababababab']) == 7\n assert candidate(words = ['racecar', 'racecarracecar', 'racecarracecarracecar', 'racecarracecarracecarracecar', 'racecarracecarracecarracecarracecar', 'racecarracecarracecarracecarracecarracecar']) == 15\n assert candidate(words = ['repeated', 'repeatedrepeated', 'repeatedrepeatedrepeated']) == 3\n assert candidate(words = ['repeatrepeatrepeat', 'repeat', 'repeatrepeat', 'rep', 're', 'repeatrepeatrepeatrepeat']) == 4\n assert candidate(words = ['aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa']) == 15\n assert candidate(words = ['repeatedrepeated', 'repeated', 'rep', 'eated', 'eat', 'eatereat', 'eatrepeat']) == 2\n assert candidate(words = ['palindromemordnilap', 'mordnilap', 'ordnil', 'rnil', 'nil', 'il', 'l', 'o', 'd', 'p', 'emordnilap']) == 0\n assert candidate(words = ['mixedcase', 'mixed', 'mix', 'edcase', 'edc', 'ase', 'asem', 'mixedcasemixed', 'mixedcasem', 'mixedcasease']) == 1\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == 190\n", "comparison": "exact"}, "public_tests": ["[\"a\",\"aba\",\"ababa\",\"aa\"]", "[\"pa\",\"papa\",\"ma\",\"mama\"]", "[\"abab\",\"ab\"]"], "hints": ["We can use a trie to solve it.", "Process all words[i] from left to right. The trie stores the pair (words[i][j], words[i][words[i].length - j - 1]) as a single character; we process all the words in this way.", "During insertion, keep a counter in each trie node, as in a normal trie. If the current node is the end of a word (namely, the pair on that node is (words[i][words[i].length - 1], words[i][0])), increase the node's counter by 1.", "From left to right, insert each word into the trie, and increase our final result by each node's counter when going down the trie during insertion. This means there was at least one word that is both a prefix and a suffix of the current word before."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().countPrefixSuffixPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:30+00:00", "tests_total": 69, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "trie", "rolling-hash", "string-matching", "hash-function", "z-algorithm"]}, "language": "ruby", "interface": {"raw_signature": "def count_prefix_suffix_pairs(words)", "container": null, "callable": "count_prefix_suffix_pairs", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3046, "task_id": "split-the-array", "difficulty": "Easy", "problem_description": "You are given an integer array nums of even length. You have to split the array into two parts nums1 and nums2 such that:\n\n- nums1.length == nums2.length == nums.length / 2.\n- nums1 should contain distinct elements.\n- nums2 should also contain distinct elements.\n\nReturn true if it is possible to split the array, and false otherwise.\n\nExample 1:\n\nInput: nums = [1,1,2,2,3,4]\nOutput: true\nExplanation: One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].\n\nExample 2:\n\nInput: nums = [1,1,1,1]\nOutput: false\nExplanation: The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- nums.length % 2 == 0\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [1, 1, 1, 1]) == False\n assert candidate(nums = [50, 50, 50, 50]) == False\n assert candidate(nums = [1, 1, 2, 2, 3, 4]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 4]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4]) == True\n assert candidate(nums = [5, 5, 6, 6, 7, 7, 8, 8]) == True\n assert candidate(nums = [1, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 5]) == True\n assert candidate(nums = [5, 5, 6, 6, 7, 7]) == True\n assert candidate(nums = [1, 2, 1, 2, 3, 4]) == True\n assert candidate(nums = [2, 2, 2, 2, 3, 3]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [10, 20, 10, 20, 30, 30]) == True\n assert candidate(nums = [50, 50, 50, 50, 60, 60]) == False\n assert candidate(nums = [10, 10, 20, 20, 30, 30]) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == True\n assert candidate(nums = [1, 1, 2, 3, 4, 4]) == True\n assert candidate(nums = [1, 2, 1, 2, 3, 3]) == True\n assert candidate(nums = [99, 99, 100, 100, 98, 98]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]) == False\n assert candidate(nums = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5]) == False\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 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]) == False\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, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == False\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == False\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [7, 8, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13]) == True\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100]) == True\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 7, 8, 9, 10]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == False\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5]) == False\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == True\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]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(nums = [17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23]) == True\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]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1]) == False\n assert candidate(nums = [7, 7, 8, 8, 8, 8, 9, 9, 10, 10]) == False\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == True\n assert candidate(nums = [1, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 4, 5, 6, 7]) == False\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]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == True\n assert candidate(nums = [5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 10, 20, 30, 40, 50, 60]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == True\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == True\n assert candidate(nums = [50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60]) == True\n assert candidate(nums = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == False\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60]) == True\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == False\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\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]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, 50, 50]) == True\n assert candidate(nums = [42, 42, 43, 43, 44, 44, 45, 45, 46, 46]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == False\n assert candidate(nums = [51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60]) == True\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 7, 7]) == False\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12]) == False\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6]) == True\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]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(nums = [61, 61, 62, 62, 63, 63, 64, 64, 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 71, 71]) == True\n assert candidate(nums = [99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 92, 91, 91, 90, 90, 89, 89, 88, 88, 87, 87, 86, 86, 85, 85]) == True\n assert candidate(nums = [11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == True\n assert candidate(nums = [50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56]) == True\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]) == False\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [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]) == False\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 5]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 50, 50]) == False\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 6, 6]) == False\n assert candidate(nums = [5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == True\n assert candidate(nums = [6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]) == True\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]) == False\n assert candidate(nums = [32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == False\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]) == True\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]) == True\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]) == True\n assert candidate(nums = [99, 99, 100, 100, 98, 98, 97, 97, 96, 96]) == True\n assert candidate(nums = [24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == True\n assert candidate(nums = [5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == True\n", "comparison": "exact"}, "public_tests": ["[1,1,2,2,3,4]", "[1,1,1,1]"], "hints": ["It’s impossible if the same number occurs more than twice. So just check the frequency of each value."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().isPossibleToSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:32+00:00", "tests_total": 110, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def is_possible_to_split(nums)", "container": null, "callable": "is_possible_to_split", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3047, "task_id": "find-the-largest-area-of-square-inside-two-rectangles", "difficulty": "Medium", "problem_description": "There exist n rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays bottomLeft and topRight where bottomLeft[i] = [a_i, b_i] and topRight[i] = [c_i, d_i] represent the bottom-left and top-right coordinates of the i^th rectangle, respectively.\n\nYou need to find the maximum area of a square that can fit inside the intersecting region of at least two rectangles. Return 0 if such a square does not exist.\n\nExample 1:\n\nInput: bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]]\n\nOutput: 1\n\nExplanation:\n\nA square with side length 1 can fit inside either the intersecting region of rectangles 0 and 1 or the intersecting region of rectangles 1 and 2. Hence the maximum area is 1. It can be shown that a square with a greater side length can not fit inside any intersecting region of two rectangles.\n\nExample 2:\n\nInput: bottomLeft = [[1,1],[1,3],[1,5]], topRight = [[5,5],[5,7],[5,9]]\n\nOutput: 4\n\nExplanation:\n\nA square with side length 2 can fit inside either the intersecting region of rectangles 0 and 1 or the intersecting region of rectangles 1 and 2. Hence the maximum area is 2 * 2 = 4. It can be shown that a square with a greater side length can not fit inside any intersecting region of two rectangles.\n\nExample 3:\n\nInput: bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]]\n\nOutput: 1\n\nExplanation:\n\nA square with side length 1 can fit inside the intersecting region of any two rectangles. Also, no larger square can, so the maximum area is 1. Note that the region can be formed by the intersection of more than 2 rectangles.\n\nExample 4:\n\nInput: bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]]\n\nOutput: 0\n\nExplanation:\n\nNo pair of rectangles intersect, hence, the answer is 0.\n\nConstraints:\n\n- n == bottomLeft.length == topRight.length\n- 2 <= n <= 10^3\n- bottomLeft[i].length == topRight[i].length == 2\n- 1 <= bottomLeft[i][0], bottomLeft[i][1] <= 10^7\n- 1 <= topRight[i][0], topRight[i][1] <= 10^7\n- bottomLeft[i][0] < topRight[i][0]\n- bottomLeft[i][1] < topRight[i][1]\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 1]],topRight = [[3, 3], [4, 4], [6, 6]]) == 1\n assert candidate(bottomLeft = [[2, 2], [4, 4], [6, 6]],topRight = [[4, 4], [6, 6], [8, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [3, 1]],topRight = [[2, 2], [4, 4], [4, 2]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4]],topRight = [[3, 3], [4, 4], [5, 5], [6, 6]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 2]],topRight = [[3, 3], [4, 4]]) == 1\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5]],topRight = [[2, 2], [4, 4], [6, 6]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 1]],topRight = [[2, 2], [2, 2]]) == 1\n assert candidate(bottomLeft = [[1, 1], [1, 3], [1, 5]],topRight = [[5, 5], [5, 7], [5, 9]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3]],topRight = [[4, 4], [5, 5], [6, 6]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 2], [1, 2]],topRight = [[3, 3], [4, 4], [3, 4]]) == 1\n assert candidate(bottomLeft = [[1, 1], [6, 1], [1, 6], [6, 6]],topRight = [[5, 5], [7, 3], [3, 7], [10, 10]]) == 0\n assert candidate(bottomLeft = [[2, 2], [3, 4], [5, 3], [6, 6]],topRight = [[4, 4], [7, 5], [6, 6], [8, 8]]) == 1\n assert candidate(bottomLeft = [[1, 1], [3, 3], [3, 1]],topRight = [[3, 3], [5, 5], [5, 3]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],topRight = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 3], [4, 5], [6, 7]],topRight = [[5, 5], [6, 8], [8, 9], [10, 10]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 3], [4, 5], [6, 7]],topRight = [[3, 5], [5, 7], [7, 9], [9, 11]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) == 9\n assert candidate(bottomLeft = [[2, 2], [3, 3], [5, 5], [7, 7]],topRight = [[4, 4], [6, 6], [8, 8], [10, 10]]) == 1\n assert candidate(bottomLeft = [[1, 1], [1, 1], [1, 1], [1, 1]],topRight = [[2, 2], [2, 2], [2, 2], [2, 2]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4]],topRight = [[10, 10], [11, 11], [12, 12], [13, 13]]) == 64\n assert candidate(bottomLeft = [[1, 1], [5, 5], [10, 10], [15, 15]],topRight = [[4, 4], [8, 8], [13, 13], [18, 18]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [6, 6], [9, 9], [12, 12]],topRight = [[2, 2], [5, 5], [8, 8], [11, 11], [14, 14]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 3], [3, 5], [4, 7]],topRight = [[5, 5], [6, 8], [7, 10], [8, 12]]) == 9\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 9\n assert candidate(bottomLeft = [[1, 1], [5, 1], [9, 1], [13, 1]],topRight = [[3, 5], [7, 5], [11, 5], [15, 5]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4]],topRight = [[2, 2], [4, 4], [6, 6], [8, 8]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == 4\n assert candidate(bottomLeft = [[1, 1], [5, 5], [9, 9]],topRight = [[3, 3], [7, 7], [11, 11]]) == 0\n assert candidate(bottomLeft = [[1, 1], [5, 5], [9, 9], [13, 13]],topRight = [[3, 3], [7, 7], [11, 11], [15, 15]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5], [7, 7]],topRight = [[2, 2], [4, 4], [6, 6], [8, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [3, 1], [5, 5]],topRight = [[2, 2], [4, 4], [4, 2], [6, 6]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 3], [1, 5], [1, 7]],topRight = [[5, 5], [5, 7], [5, 9], [5, 11]]) == 4\n assert candidate(bottomLeft = [[5, 5], [10, 10], [15, 15], [20, 20]],topRight = [[10, 10], [15, 15], [20, 20], [25, 25]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 2], [1, 3], [1, 4]],topRight = [[10, 10], [10, 11], [10, 12], [10, 13]]) == 64\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],topRight = [[4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 1], [1, 2], [2, 2]],topRight = [[4, 4], [5, 4], [4, 5], [5, 5]]) == 4\n assert candidate(bottomLeft = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9]],topRight = [[5, 5], [5, 7], [5, 9], [5, 11], [5, 13]]) == 4\n assert candidate(bottomLeft = [[1, 1], [1, 1], [1, 1], [1, 1]],topRight = [[5, 5], [5, 5], [5, 5], [5, 5]]) == 16\n assert candidate(bottomLeft = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11]],topRight = [[3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 4], [5, 5], [8, 8], [11, 11]],topRight = [[3, 3], [7, 7], [10, 10], [13, 13], [15, 15]]) == 4\n assert candidate(bottomLeft = [[1, 1], [2, 3], [4, 5], [6, 7]],topRight = [[3, 2], [5, 4], [7, 6], [9, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5]],topRight = [[3, 3], [5, 5], [7, 7]]) == 0\n assert candidate(bottomLeft = [[1, 1], [6, 1], [11, 1], [1, 6], [6, 6], [11, 6]],topRight = [[6, 6], [11, 6], [16, 6], [6, 11], [11, 11], [16, 11]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]) == 0\n assert candidate(bottomLeft = [[1, 1], [10, 10], [20, 20], [30, 30]],topRight = [[5, 5], [15, 15], [25, 25], [35, 35]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]],topRight = [[2, 2], [3, 2], [4, 2], [5, 2], [6, 2]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 3], [1, 5], [1, 7]],topRight = [[7, 2], [7, 4], [7, 6], [7, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [10, 10], [20, 20], [30, 30]],topRight = [[15, 15], [25, 25], [35, 35], [45, 45]]) == 25\n assert candidate(bottomLeft = [[1, 1], [4, 4], [7, 7]],topRight = [[2, 2], [5, 5], [8, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [6, 6], [10, 10]],topRight = [[4, 4], [7, 7], [11, 11], [15, 15]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4]],topRight = [[2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(bottomLeft = [[1, 1], [5, 5], [9, 9]],topRight = [[10, 10], [12, 12], [14, 14]]) == 25\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 16\n assert candidate(bottomLeft = [[1, 1], [2, 3], [3, 5], [5, 7]],topRight = [[3, 3], [4, 5], [6, 7], [8, 9]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [1, 2], [3, 3]],topRight = [[3, 3], [4, 4], [3, 4], [5, 5]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 3], [4, 5], [6, 7], [8, 9]],topRight = [[2, 2], [5, 6], [7, 8], [9, 10], [11, 12]]) == 1\n assert candidate(bottomLeft = [[1, 1], [5, 5], [9, 9], [13, 13]],topRight = [[4, 4], [8, 8], [12, 12], [16, 16]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 3], [1, 5], [1, 7]],topRight = [[3, 3], [3, 5], [3, 7], [3, 9]]) == 0\n assert candidate(bottomLeft = [[2, 3], [4, 1], [6, 5], [8, 7]],topRight = [[4, 5], [6, 3], [8, 7], [10, 9]]) == 0\n assert candidate(bottomLeft = [[10, 10], [20, 20], [30, 30], [40, 40]],topRight = [[20, 20], [30, 30], [40, 40], [50, 50]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5], [7, 7]],topRight = [[4, 4], [6, 6], [8, 8], [10, 10]]) == 1\n assert candidate(bottomLeft = [[1, 1], [1, 2], [1, 3], [1, 4]],topRight = [[2, 4], [2, 5], [2, 6], [2, 7]]) == 1\n assert candidate(bottomLeft = [[1, 1], [3, 1], [1, 3], [3, 3]],topRight = [[4, 2], [6, 2], [4, 6], [6, 6]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4]],topRight = [[2, 2], [3, 3], [4, 4], [5, 5]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4]],topRight = [[5, 5], [6, 6], [7, 7], [8, 8]]) == 9\n assert candidate(bottomLeft = [[1, 1], [5, 5], [3, 3]],topRight = [[4, 4], [7, 7], [6, 6]]) == 1\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],topRight = [[2, 4], [6, 8], [10, 12], [14, 16], [18, 20]]) == 25\n assert candidate(bottomLeft = [[1, 1], [3, 1], [5, 1], [7, 1]],topRight = [[2, 3], [4, 3], [6, 3], [8, 3]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [10, 10], [15, 15]],topRight = [[2, 2], [3, 3], [12, 12], [16, 16]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 1], [3, 1], [4, 1]],topRight = [[4, 10], [5, 10], [6, 10], [7, 10]]) == 4\n assert candidate(bottomLeft = [[1, 1], [10, 1], [1, 10], [10, 10]],topRight = [[10, 10], [20, 10], [10, 20], [20, 20]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 1], [1, 1], [1, 1]],topRight = [[10, 10], [10, 10], [10, 10], [10, 10]]) == 81\n assert candidate(bottomLeft = [[1, 1], [2, 1], [3, 1], [4, 1]],topRight = [[4, 2], [5, 2], [6, 2], [7, 2]]) == 1\n assert candidate(bottomLeft = [[1, 1], [10, 1], [1, 10], [10, 10]],topRight = [[5, 5], [15, 5], [5, 15], [15, 15]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 1], [5, 1], [7, 1]],topRight = [[2, 2], [4, 2], [6, 2], [8, 2]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],topRight = [[3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == 1\n assert candidate(bottomLeft = [[1, 1], [1, 2], [2, 1], [2, 2]],topRight = [[3, 3], [3, 4], [4, 3], [4, 4]]) == 1\n assert candidate(bottomLeft = [[1, 10], [10, 20], [20, 30]],topRight = [[10, 20], [20, 30], [30, 40]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2]],topRight = [[3, 3], [3, 4], [4, 3], [4, 4], [5, 3], [5, 4]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9]],topRight = [[4, 5], [6, 8], [8, 11], [10, 13], [12, 15]]) == 16\n assert candidate(bottomLeft = [[1, 1], [4, 4], [7, 7], [10, 10]],topRight = [[5, 5], [8, 8], [11, 11], [13, 13]]) == 1\n assert candidate(bottomLeft = [[1, 1], [2, 3], [3, 5], [4, 7]],topRight = [[2, 2], [4, 4], [6, 6], [8, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [4, 4], [7, 7], [10, 10]],topRight = [[3, 3], [6, 6], [9, 9], [12, 12]]) == 0\n assert candidate(bottomLeft = [[1, 1], [1, 5], [1, 9], [1, 13]],topRight = [[10, 10], [10, 15], [10, 19], [10, 23]]) == 36\n assert candidate(bottomLeft = [[1, 1], [4, 4], [6, 6], [8, 8]],topRight = [[3, 3], [7, 7], [10, 10], [12, 12]]) == 4\n assert candidate(bottomLeft = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9]],topRight = [[2, 2], [2, 4], [2, 6], [2, 8], [2, 10]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],topRight = [[2, 2], [4, 4], [6, 6], [8, 8], [10, 10]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 3], [4, 5], [6, 7]],topRight = [[3, 2], [4, 4], [6, 6], [8, 8]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 4], [3, 7], [4, 10], [5, 13]],topRight = [[6, 6], [7, 9], [8, 12], [9, 15], [10, 18]]) == 4\n assert candidate(bottomLeft = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11]],topRight = [[2, 2], [4, 4], [6, 6], [8, 8], [10, 10], [12, 12]]) == 0\n assert candidate(bottomLeft = [[10, 10], [20, 20], [30, 30]],topRight = [[20, 20], [30, 30], [40, 40]]) == 0\n assert candidate(bottomLeft = [[2, 2], [5, 5], [8, 8], [11, 11], [14, 14]],topRight = [[4, 4], [7, 7], [10, 10], [13, 13], [16, 16]]) == 0\n assert candidate(bottomLeft = [[2, 2], [6, 6], [10, 10], [14, 14]],topRight = [[4, 4], [8, 8], [12, 12], [16, 16]]) == 0\n assert candidate(bottomLeft = [[2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[3, 3], [4, 4], [5, 5], [6, 6]]) == 0\n assert candidate(bottomLeft = [[1, 1], [2, 2], [5, 5], [7, 7]],topRight = [[3, 3], [6, 6], [8, 8], [10, 10]]) == 1\n assert candidate(bottomLeft = [[1, 1], [1, 5], [5, 1], [5, 5]],topRight = [[5, 5], [5, 9], [9, 5], [9, 9]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 1], [5, 1], [7, 1]],topRight = [[3, 3], [5, 3], [7, 3], [9, 3]]) == 0\n assert candidate(bottomLeft = [[1, 10], [5, 15], [10, 20], [15, 25]],topRight = [[10, 20], [20, 25], [25, 30], [30, 35]]) == 25\n assert candidate(bottomLeft = [[2, 2], [3, 3], [4, 4], [5, 5]],topRight = [[6, 6], [7, 7], [8, 8], [9, 9]]) == 9\n assert candidate(bottomLeft = [[1, 1], [3, 3], [6, 6], [8, 8]],topRight = [[4, 4], [6, 6], [9, 9], [11, 11]]) == 1\n assert candidate(bottomLeft = [[1, 1], [3, 2], [5, 3], [7, 4]],topRight = [[2, 2], [4, 3], [6, 4], [8, 5]]) == 0\n assert candidate(bottomLeft = [[1, 1], [3, 1], [5, 1], [7, 1], [9, 1]],topRight = [[2, 2], [4, 2], [6, 2], [8, 2], [10, 2]]) == 0\n", "comparison": "exact"}, "public_tests": ["[[1,1],[2,2],[3,1]]\n[[3,3],[4,4],[6,6]]", "[[1,1],[1,3],[1,5]]\n[[5,5],[5,7],[5,9]]", "[[1,1],[2,2],[1,2]]\n[[3,3],[4,4],[3,4]]", "[[1,1],[3,3],[3,1]]\n[[2,2],[4,4],[4,2]]"], "hints": ["Brute Force the intersection area of each pair of rectangles.", "Two rectangles will not overlap when the bottom left x coordinate of one rectangle is greater than the top right x coordinate of the other rectangle. The same is true for the y coordinate.", "The intersection area (if any) is also a rectangle. Find its corners."], "metadata": {"canonical_parameter_names": ["bottomLeft", "topRight"], "leetcode_dataset_entry_point": "Solution().largestSquareArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:35+00:00", "tests_total": 102, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "geometry"]}, "language": "ruby", "interface": {"raw_signature": "def largest_square_area(bottom_left, top_right)", "container": null, "callable": "largest_square_area", "parameters": [{"name": "bottom_left", "type": "Integer[][]"}, {"name": "top_right", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3048, "task_id": "earliest-second-to-mark-indices-i", "difficulty": "Medium", "problem_description": "You are given two 1-indexed integer arrays, nums and, changeIndices, having lengths n and m, respectively.\n\nInitially, all indices in nums are unmarked. Your task is to mark all indices in nums.\n\nIn each second, s, in order from 1 to m (inclusive), you can perform one of the following operations:\n\n- Choose an index i in the range [1, n] and decrement nums[i] by 1.\n- If nums[changeIndices[s]] is equal to 0, mark the index changeIndices[s].\n- Do nothing.\n\nReturn an integer denoting the earliest second in the range [1, m] when all indices in nums can be marked by choosing operations optimally, or -1 if it is impossible.\n\nExample 1:\n\nInput: nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]\nOutput: 8\nExplanation: In this example, we have 8 seconds. The following operations can be performed to mark all indices:\nSecond 1: Choose index 1 and decrement nums[1] by one. nums becomes [1,2,0].\nSecond 2: Choose index 1 and decrement nums[1] by one. nums becomes [0,2,0].\nSecond 3: Choose index 2 and decrement nums[2] by one. nums becomes [0,1,0].\nSecond 4: Choose index 2 and decrement nums[2] by one. nums becomes [0,0,0].\nSecond 5: Mark the index changeIndices[5], which is marking index 3, since nums[3] is equal to 0.\nSecond 6: Mark the index changeIndices[6], which is marking index 2, since nums[2] is equal to 0.\nSecond 7: Do nothing.\nSecond 8: Mark the index changeIndices[8], which is marking index 1, since nums[1] is equal to 0.\nNow all indices have been marked.\nIt can be shown that it is not possible to mark all indices earlier than the 8th second.\nHence, the answer is 8.\n\nExample 2:\n\nInput: nums = [1,3], changeIndices = [1,1,1,2,1,1,1]\nOutput: 6\nExplanation: In this example, we have 7 seconds. The following operations can be performed to mark all indices:\nSecond 1: Choose index 2 and decrement nums[2] by one. nums becomes [1,2].\nSecond 2: Choose index 2 and decrement nums[2] by one. nums becomes [1,1].\nSecond 3: Choose index 2 and decrement nums[2] by one. nums becomes [1,0].\nSecond 4: Mark the index changeIndices[4], which is marking index 2, since nums[2] is equal to 0.\nSecond 5: Choose index 1 and decrement nums[1] by one. nums becomes [0,0].\nSecond 6: Mark the index changeIndices[6], which is marking index 1, since nums[1] is equal to 0.\nNow all indices have been marked.\nIt can be shown that it is not possible to mark all indices earlier than the 6th second.\nHence, the answer is 6.\n\nExample 3:\n\nInput: nums = [0,1], changeIndices = [2,2,2]\nOutput: -1\nExplanation: In this example, it is impossible to mark all indices because index 1 isn't in changeIndices.\nHence, the answer is -1.\n\nConstraints:\n\n- 1 <= n == nums.length <= 2000\n- 0 <= nums[i] <= 10^9\n- 1 <= m == changeIndices.length <= 2000\n- 1 <= changeIndices[i] <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 0, 1, 0],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 6\n assert candidate(nums = [10, 0, 10],changeIndices = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0],changeIndices = [1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 3],changeIndices = [1, 1, 1, 2, 1, 1, 1]) == 6\n assert candidate(nums = [0, 0, 0],changeIndices = [1, 2, 3]) == 3\n assert candidate(nums = [5, 4, 3],changeIndices = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == -1\n assert candidate(nums = [1, 2, 3, 4],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 20, 30, 40],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [3, 3, 3, 3],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 1, 1, 1],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 10, 10, 10],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4]) == 4\n assert candidate(nums = [100, 200, 300],changeIndices = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == -1\n assert candidate(nums = [10, 10, 10],changeIndices = [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]) == -1\n assert candidate(nums = [0, 1],changeIndices = [2, 2, 2]) == -1\n assert candidate(nums = [1000000000, 1000000000],changeIndices = [1, 2, 1, 2, 1, 2]) == -1\n assert candidate(nums = [100, 0, 50],changeIndices = [1, 1, 1, 3, 3, 3, 2, 2, 2]) == -1\n assert candidate(nums = [2, 2, 0],changeIndices = [2, 2, 2, 2, 3, 2, 2, 1]) == 8\n assert candidate(nums = [5, 5, 5],changeIndices = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == -1\n assert candidate(nums = [1, 0, 3],changeIndices = [3, 3, 3, 1, 1, 2, 2, 2]) == -1\n assert candidate(nums = [1, 2, 3, 4],changeIndices = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 14\n assert candidate(nums = [3, 2, 1],changeIndices = [3, 2, 1, 3, 2, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [10, 20, 30],changeIndices = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == -1\n assert candidate(nums = [10, 10, 10],changeIndices = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8]) == 16\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],changeIndices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 200, 300, 400],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1, 0],changeIndices = [2, 4, 6, 1, 3, 5, 1, 3, 5, 2, 4, 6]) == 9\n assert candidate(nums = [0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],changeIndices = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5],changeIndices = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13],changeIndices = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],changeIndices = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 15\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9],changeIndices = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [10, 20, 30, 40],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 200, 300],changeIndices = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],changeIndices = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50],changeIndices = [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]) == -1\n assert candidate(nums = [100, 100, 100, 100],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [10, 0, 0, 10],changeIndices = [4, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1]) == -1\n assert candidate(nums = [5, 7, 9, 10],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5],changeIndices = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == -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],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5],changeIndices = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 200, 300, 400],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],changeIndices = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],changeIndices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [0, 10, 20, 30, 40],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 0, 2, 3, 4],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70],changeIndices = [7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 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],changeIndices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [100, 200, 300],changeIndices = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],changeIndices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],changeIndices = [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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == -1\n assert candidate(nums = [5, 0, 2, 7, 3],changeIndices = [1, 5, 3, 4, 4, 2, 5, 3, 1, 2, 4, 3]) == -1\n assert candidate(nums = [10, 20, 30, 40],changeIndices = [4, 3, 2, 1, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [999999999, 999999999, 999999999],changeIndices = [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\n assert candidate(nums = [5, 10, 15, 20],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000],changeIndices = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == -1\n assert candidate(nums = [0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0],changeIndices = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],changeIndices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000],changeIndices = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, 0, 8, 3],changeIndices = [4, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [9, 8, 7, 6, 5],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 200, 300, 400],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000],changeIndices = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000],changeIndices = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5],changeIndices = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [100, 0, 50, 25, 75],changeIndices = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500],changeIndices = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50],changeIndices = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [0, 0, 1, 1, 2, 2],changeIndices = [3, 3, 4, 4, 5, 5, 1, 1, 2, 2]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4]) == 4\n assert candidate(nums = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1000000000, 1000000000],changeIndices = [1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == -1\n assert candidate(nums = [100, 200, 300, 400],changeIndices = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1000, 1000, 1000, 1000],changeIndices = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == -1\n assert candidate(nums = [1, 0, 0, 1],changeIndices = [4, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1, 4, 4, 4, 1, 1, 1]) == -1\n assert candidate(nums = [10, 20, 30],changeIndices = [1, 2, 3, 3, 2, 1, 1, 2, 3, 3, 2, 1, 1, 2, 3]) == -1\n assert candidate(nums = [1, 0, 0, 0, 1],changeIndices = [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 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],changeIndices = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],changeIndices = [8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1],changeIndices = [1, 3, 5, 7, 2, 4, 6, 1, 3, 5, 7, 2, 4, 6]) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],changeIndices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],changeIndices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums = [10, 20, 30, 40],changeIndices = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == -1\n", "comparison": "exact"}, "public_tests": ["[2,2,0]\n[2,2,2,2,3,2,2,1]", "[1,3]\n[1,1,1,2,1,1,1]", "[0,1]\n[2,2,2]"], "hints": ["Consider using binary search.", "Suppose the answer <= x; we can mark each index as late as possible. Namely, mark each index at the last occurrence in the array changeIndices[1..x].", "When marking an index, which is the last occurrence at the second i, we check whether we have a sufficient number of decrement operations to mark all the previous indices whose last occurrences have already been marked, and the current index, i.e., i - sum_of_marked_indices_values - cnt_of_marked_indices >= nums[changeIndices[i]].", "The answer is the earliest second when all indices can be marked after running the binary search or -1 if there is no such second."], "metadata": {"canonical_parameter_names": ["nums", "changeIndices"], "leetcode_dataset_entry_point": "Solution().earliestSecondToMarkIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:37+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "ruby", "interface": {"raw_signature": "def earliest_second_to_mark_indices(nums, change_indices)", "container": null, "callable": "earliest_second_to_mark_indices", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "change_indices", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3065, "task_id": "minimum-operations-to-exceed-threshold-value-i", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums, and an integer k.\n\nIn one operation, you can remove one occurrence of the smallest element of nums.\n\nReturn the minimum number of operations needed so that all elements of the array are greater than or equal to k.\n\nExample 1:\n\nInput: nums = [2,11,10,1,3], k = 10\nOutput: 3\nExplanation: After one operation, nums becomes equal to [2, 11, 10, 3].\nAfter two operations, nums becomes equal to [11, 10, 3].\nAfter three operations, nums becomes equal to [11, 10].\nAt this stage, all the elements of nums are greater than or equal to 10 so we can stop.\nIt can be shown that 3 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.\n\nExample 2:\n\nInput: nums = [1,1,2,4,9], k = 1\nOutput: 0\nExplanation: All elements of the array are greater than or equal to 1 so we do not need to apply any operations on nums.\n\nExample 3:\n\nInput: nums = [1,1,2,4,9], k = 9\nOutput: 4\nExplanation: only a single element of nums is greater than or equal to 9 so we need to apply the operations 4 times on nums.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 10^9\n- The input is generated such that there is at least one index i such that nums[i] >= k.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7],k = 7) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 1, 2, 4, 9],k = 1) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 2\n assert candidate(nums = [5, 3, 8, 9, 2],k = 5) == 2\n assert candidate(nums = [100, 200, 300, 400, 500],k = 100) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 4\n assert candidate(nums = [3, 6, 9, 12, 15],k = 12) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],k = 25) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],k = 15) == 1\n assert candidate(nums = [1, 1, 2, 4, 9],k = 9) == 4\n assert candidate(nums = [8, 8, 8, 8, 8, 8],k = 8) == 0\n assert candidate(nums = [2, 11, 10, 1, 3],k = 10) == 3\n assert candidate(nums = [10, 9, 8, 7, 6],k = 7) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 95) == 5\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],k = 555555555) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 9\n assert candidate(nums = [10, 20, 30, 40, 50],k = 25) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 25) == 8\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1],k = 5) == 4\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 60) == 5\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],k = 5) == 0\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 999999997) == 1\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 95) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],k = 2) == 5\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42],k = 42) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 8\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 28) == 13\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(nums = [5, 3, 8, 2, 6, 1, 4],k = 4) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 6) == 5\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],k = 15) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 20) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 5\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 4) == 5\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 = 15) == 14\n assert candidate(nums = [34, 23, 54, 12, 45, 67, 89, 23, 45, 67, 89, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90],k = 45) == 12\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1000) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],k = 6) == 5\n assert candidate(nums = [5, 3, 1, 4, 2, 6],k = 4) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 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],k = 15) == 14\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000],k = 1000000000) == 3\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 999999997) == 1\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5],k = 5) == 19\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34],k = 33) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2],k = 2) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 10) == 5\n assert candidate(nums = [10, 10, 10, 10, 10],k = 10) == 0\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31],k = 35) == 4\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 13\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 60) == 5\n assert candidate(nums = [5, 3, 8, 6, 2, 10, 4, 9],k = 5) == 3\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],k = 40) == 39\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 = 5) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 4\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],k = 40) == 10\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 99) == 0\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],k = 6) == 45\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 4\n assert candidate(nums = [5, 3, 3, 2, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 6) == 10\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 999999997) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 20) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 75) == 7\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10],k = 4) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 15) == 7\n assert candidate(nums = [2, 3, 1, 5, 4, 7, 6, 9, 8, 10],k = 7) == 6\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 30) == 5\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94],k = 96) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42],k = 25) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 7\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000],k = 1000000000) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 25) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1) == 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, 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) == 23\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 500) == 4\n assert candidate(nums = [5, 3, 1, 4, 2, 6, 7],k = 4) == 3\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 4) == 10\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 999999998) == 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],k = 10) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 4\n assert candidate(nums = [47, 23, 89, 5, 76, 12, 34, 67, 9, 100],k = 25) == 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],k = 25) == 24\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15],k = 10) == 9\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10],k = 10) == 10\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 8) == 0\n assert candidate(nums = [100, 99, 98, 97, 96, 95],k = 98) == 3\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 10) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 2\n", "comparison": "exact"}, "public_tests": ["[2,11,10,1,3]\n10", "[1,1,2,4,9]\n1", "[1,1,2,4,9]\n9"], "hints": ["Iterate over nums and count the number of elements less than k."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:44+00:00", "tests_total": 104, "tests_dropped": 2, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums, k)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3066, "task_id": "minimum-operations-to-exceed-threshold-value-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums, and an integer k.\n\nYou are allowed to perform some operations on nums, where in a single operation, you can:\n\n- Select the two smallest integers x and y from nums.\n- Remove x and y from nums.\n- Insert (min(x, y) * 2 + max(x, y)) at any position in the array.\n\nNote that you can only apply the described operation if nums contains at least two elements.\n\nReturn the minimum number of operations needed so that all elements of the array are greater than or equal to k.\n\nExample 1:\n\nInput: nums = [2,11,10,1,3], k = 10\nOutput: 2\nExplanation:\n1. In the first operation, we remove elements 1 and 2, then add 1 * 2 + 2 to nums. nums becomes equal to [4, 11, 10, 3].\n2. In the second operation, we remove elements 3 and 4, then add 3 * 2 + 4 to nums. nums becomes equal to [10, 11, 10].\n\nAt this stage, all the elements of nums are greater than or equal to 10 so we can stop.\nIt can be shown that 2 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10.\n\nExample 2:\n\nInput: nums = [1,1,2,4,9], k = 20\nOutput: 4\nExplanation:\n1. After one operation, nums becomes equal to [2, 4, 9, 3].\n2. After two operations, nums becomes equal to [7, 4, 9].\n3. After three operations, nums becomes equal to [15, 9].\n4. After four operations, nums becomes equal to [33].\n\nAt this stage, all the elements of nums are greater than 20 so we can stop.\nIt can be shown that 4 is the minimum number of operations needed so that all elements of the array are greater than or equal to 20.\n\nConstraints:\n\n- 2 <= nums.length <= 2 * 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 10^9\n- The input is generated such that an answer always exists. That is, after performing some number of operations, all elements of the array are greater than or equal to k.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 10) == 7\n assert candidate(nums = [5, 4, 3, 2, 1],k = 10) == 3\n assert candidate(nums = [5, 5, 5, 5],k = 10) == 2\n assert candidate(nums = [5, 10, 15, 20],k = 25) == 3\n assert candidate(nums = [5, 5, 5, 5, 5],k = 11) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 10) == 4\n assert candidate(nums = [1, 1000000000],k = 1000000000) == 1\n assert candidate(nums = [100, 200, 300],k = 500) == 2\n assert candidate(nums = [2, 11, 10, 1, 3],k = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 10) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1],k = 2) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 9\n assert candidate(nums = [5, 6, 7],k = 14) == 2\n assert candidate(nums = [1000000000, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 18) == 6\n assert candidate(nums = [1, 1, 2, 4, 9],k = 20) == 4\n assert candidate(nums = [1000000000, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 1000000000],k = 1000000000) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 14\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 4) == 5\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1000) == 8\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],k = 40) == 24\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 = 30) == 13\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 = 2) == 10\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],k = 100) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 7\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256],k = 512) == 8\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],k = 100) == 7\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1500) == 7\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) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 3) == 32\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 35) == 9\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1000) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 105) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 20) == 5\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 5\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1024) == 9\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 50) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 60) == 6\n assert candidate(nums = [2, 3, 1, 6, 5, 4],k = 7) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 8\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 = 3) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 25) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 15) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 9\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 50) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 40) == 12\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16],k = 50) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 35) == 19\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 20) == 10\n assert candidate(nums = [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],k = 50) == 14\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 10) == 8\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 8\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 = 10) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 150) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 7\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 100) == 14\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000],k = 1000000000) == 3\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 32768) == 14\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 1999990) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 12) == 6\n assert candidate(nums = [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],k = 250) == 14\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],k = 6) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 20) == 7\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],k = 7) == 15\n assert candidate(nums = [500000000, 400000000, 300000000, 200000000, 100000000, 90000000, 80000000, 70000000, 60000000, 50000000],k = 1000000000) == 8\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 1048576) == 19\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 10) == 9\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 1500) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 8\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 = 10) == 26\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 7\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],k = 200) == 5\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 1000000000) == 9\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 512) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 10) == 5\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55],k = 100) == 8\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 50) == 7\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 500000000) == 9\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],k = 100) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 30) == 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 16\n assert candidate(nums = [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 10) == 13\n assert candidate(nums = [1, 2, 3, 6, 9, 18, 27, 54, 81, 162, 243, 486, 729, 1458, 2187, 4374, 6561, 13122, 19683, 38364],k = 10000) == 15\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 2048) == 10\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 = 25) == 12\n assert candidate(nums = [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],k = 61) == 18\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 = 30) == 17\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],k = 18) == 7\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],k = 60) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2],k = 10) == 9\n", "comparison": "exact"}, "public_tests": ["[2,11,10,1,3]\n10", "[1,1,2,4,9]\n20"], "hints": ["Use priority queue to keep track of minimum elements.", "Remove the minimum two elements, perform the operation, and insert the resulting number into the priority queue."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:46+00:00", "tests_total": 103, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "heap-priority-queue", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums, k)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3067, "task_id": "count-pairs-of-connectable-servers-in-a-weighted-tree-network", "difficulty": "Medium", "problem_description": "You are given an unrooted weighted tree with n vertices representing servers numbered from 0 to n - 1, an array edges where edges[i] = [a_i, b_i, weight_i] represents a bidirectional edge between vertices a_i and b_i of weight weight_i. You are also given an integer signalSpeed.\n\nTwo servers a and b are connectable through a server c if:\n\n- a < b, a != c and b != c.\n- The distance from c to a is divisible by signalSpeed.\n- The distance from c to b is divisible by signalSpeed.\n- The path from c to b and the path from c to a do not share any edges.\n\nReturn an integer array count of length n where count[i] is the number of server pairs that are connectable through the server i.\n\nExample 1:\n\nInput: edges = [[0,1,1],[1,2,5],[2,3,13],[3,4,9],[4,5,2]], signalSpeed = 1\nOutput: [0,4,6,6,4,0]\nExplanation: Since signalSpeed is 1, count[c] is equal to the number of pairs of paths that start at c and do not share any edges.\nIn the case of the given path graph, count[c] is equal to the number of servers to the left of c multiplied by the servers to the right of c.\n\nExample 2:\n\nInput: edges = [[0,6,3],[6,5,3],[0,3,1],[3,2,7],[3,1,6],[3,4,2]], signalSpeed = 3\nOutput: [2,0,0,0,0,0,2]\nExplanation: Through server 0, there are 2 pairs of connectable servers: (4, 5) and (4, 6).\nThrough server 6, there are 2 pairs of connectable servers: (4, 5) and (0, 5).\nIt can be shown that no two servers are connectable through servers other than 0 and 6.\n\nConstraints:\n\n- 2 <= n <= 1000\n- edges.length == n - 1\n- edges[i].length == 3\n- 0 <= a_i, b_i < n\n- edges[i] = [a_i, b_i, weight_i]\n- 1 <= weight_i <= 10^6\n- 1 <= signalSpeed <= 10^6\n- The input is generated such that edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1]],signalSpeed = 1) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 1], [1, 2, 5], [2, 3, 13], [3, 4, 9], [4, 5, 2]],signalSpeed = 1) == [0, 4, 6, 6, 4, 0]\n assert candidate(edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20]],signalSpeed = 5) == [0, 3, 4, 3, 0]\n assert candidate(edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 5, 6], [2, 6, 7]],signalSpeed = 1) == [9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10]],signalSpeed = 5) == [9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 4], [1, 2, 8], [2, 3, 12], [3, 4, 16]],signalSpeed = 4) == [0, 3, 4, 3, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]],signalSpeed = 2) == [0, 2, 0, 0, 2, 0]\n assert candidate(edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 4], [1, 5, 5], [2, 6, 6], [3, 7, 7]],signalSpeed = 1) == [16, 11, 6, 6, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 6], [3, 4, 8]],signalSpeed = 2) == [0, 3, 4, 3, 0]\n assert candidate(edges = [[0, 1, 3], [1, 2, 6], [2, 3, 9], [3, 4, 12], [4, 5, 15]],signalSpeed = 3) == [0, 4, 6, 6, 4, 0]\n assert candidate(edges = [[0, 6, 3], [6, 5, 3], [0, 3, 1], [3, 2, 7], [3, 1, 6], [3, 4, 2]],signalSpeed = 3) == [2, 0, 0, 0, 0, 0, 2]\n assert candidate(edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40]],signalSpeed = 10) == [0, 3, 4, 3, 0]\n assert candidate(edges = [[0, 1, 4], [1, 2, 8], [2, 3, 12]],signalSpeed = 4) == [0, 2, 2, 0]\n assert candidate(edges = [[0, 1, 4], [1, 2, 5], [2, 3, 6]],signalSpeed = 2) == [0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 8], [3, 4, 16]],signalSpeed = 2) == [0, 3, 4, 3, 0]\n assert candidate(edges = [[0, 1, 13], [0, 2, 26], [1, 3, 39], [1, 4, 52], [2, 5, 65], [2, 6, 78], [3, 7, 91], [4, 8, 104], [5, 9, 117], [6, 10, 130], [7, 11, 143], [8, 12, 156], [9, 13, 169]],signalSpeed = 13) == [42, 51, 46, 22, 22, 22, 12, 12, 12, 12, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 19], [1, 2, 38], [1, 3, 57], [2, 4, 76], [2, 5, 95], [3, 6, 114], [3, 7, 133], [4, 8, 152], [5, 9, 171], [6, 10, 190], [7, 11, 209], [8, 12, 228], [9, 13, 247], [10, 14, 266], [11, 15, 285], [12, 16, 304], [13, 17, 323], [14, 18, 342]],signalSpeed = 19) == [0, 89, 96, 89, 45, 45, 45, 32, 32, 32, 32, 17, 17, 17, 17, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 6], [0, 2, 12], [1, 3, 18], [1, 4, 24], [2, 5, 30], [2, 6, 36], [3, 7, 42], [3, 8, 48], [4, 9, 54], [5, 10, 60], [6, 11, 66]],signalSpeed = 6) == [30, 36, 32, 19, 10, 10, 10, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 7], [0, 2, 14], [1, 3, 21], [1, 4, 28], [2, 5, 35], [2, 6, 42], [3, 7, 49], [3, 8, 56], [4, 9, 63], [4, 10, 70]],signalSpeed = 7) == [21, 33, 17, 17, 17, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 11], [1, 2, 22], [2, 3, 33], [3, 4, 44], [4, 5, 55], [5, 6, 66], [6, 7, 77], [7, 8, 88], [8, 9, 99], [9, 10, 110]],signalSpeed = 11) == [0, 9, 16, 21, 24, 25, 24, 21, 16, 9, 0]\n assert candidate(edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [0, 4, 4], [1, 5, 5], [1, 6, 6], [2, 7, 7], [2, 8, 8], [3, 9, 9], [3, 10, 10], [4, 11, 11], [4, 12, 12]],signalSpeed = 1) == [54, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 9], [1, 2, 18], [2, 3, 27], [3, 4, 36], [4, 5, 45], [5, 6, 54], [6, 7, 63], [7, 8, 72], [8, 9, 81], [9, 10, 90], [10, 11, 99], [11, 12, 108]],signalSpeed = 9) == [0, 11, 20, 27, 32, 35, 36, 35, 32, 27, 20, 11, 0]\n assert candidate(edges = [[0, 1, 7], [0, 2, 14], [1, 3, 21], [1, 4, 28], [2, 5, 35], [2, 6, 42], [3, 7, 49], [3, 8, 56], [4, 9, 63], [5, 10, 70], [6, 11, 77]],signalSpeed = 7) == [30, 36, 32, 19, 10, 10, 10, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 7], [0, 2, 14], [1, 3, 21], [1, 4, 28], [2, 5, 35], [2, 6, 42], [3, 7, 49], [3, 8, 56], [4, 9, 63], [4, 10, 70], [5, 11, 77], [5, 12, 84], [6, 13, 91], [6, 14, 98]],signalSpeed = 7) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 17], [0, 2, 34], [1, 3, 51], [1, 4, 68], [2, 5, 85], [2, 6, 102], [3, 7, 119], [3, 8, 136], [4, 9, 153], [4, 10, 170], [5, 11, 187], [5, 12, 204], [6, 13, 221], [6, 14, 238]],signalSpeed = 17) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 8], [3, 4, 16], [4, 5, 32], [5, 6, 64], [6, 7, 128], [7, 8, 256], [8, 9, 512]],signalSpeed = 2) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 100000], [1, 2, 200000], [2, 3, 300000], [3, 4, 400000], [4, 5, 500000], [5, 6, 600000], [6, 7, 700000]],signalSpeed = 100000) == [0, 6, 10, 12, 12, 10, 6, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 8], [3, 4, 16], [4, 5, 32], [5, 6, 64]],signalSpeed = 2) == [0, 5, 8, 9, 8, 5, 0]\n assert candidate(edges = [[0, 1, 10], [0, 2, 20], [0, 3, 30], [1, 4, 40], [1, 5, 50], [2, 6, 60], [2, 7, 70], [3, 8, 80], [3, 9, 90], [4, 10, 100], [5, 11, 110], [6, 12, 120]],signalSpeed = 10) == [47, 36, 29, 21, 11, 11, 11, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10]],signalSpeed = 2) == [0, 4, 0, 2, 6, 6, 2, 0, 4, 0]\n assert candidate(edges = [[0, 1, 5], [1, 2, 10], [1, 3, 15], [2, 4, 20], [3, 5, 25], [4, 6, 30], [5, 7, 35]],signalSpeed = 5) == [0, 15, 10, 10, 6, 6, 0, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 8], [3, 4, 16], [4, 5, 32], [5, 6, 64], [6, 7, 128], [7, 8, 256], [8, 9, 512], [9, 10, 1024]],signalSpeed = 2) == [0, 9, 16, 21, 24, 25, 24, 21, 16, 9, 0]\n assert candidate(edges = [[0, 1, 3], [0, 2, 6], [1, 3, 9], [1, 4, 12], [2, 5, 15], [2, 6, 18]],signalSpeed = 3) == [9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 7], [1, 2, 14], [2, 3, 21], [3, 4, 28], [4, 5, 35], [5, 6, 42], [6, 7, 49], [7, 8, 56]],signalSpeed = 7) == [0, 7, 12, 15, 16, 15, 12, 7, 0]\n assert candidate(edges = [[0, 1, 6], [1, 2, 12], [1, 3, 18], [3, 4, 24], [3, 5, 30], [5, 6, 36], [5, 7, 42], [7, 8, 48], [7, 9, 54], [9, 10, 60], [10, 11, 66]],signalSpeed = 6) == [0, 19, 0, 31, 0, 35, 0, 31, 0, 18, 10, 0]\n assert candidate(edges = [[0, 1, 10], [0, 2, 20], [1, 3, 15], [1, 4, 25], [2, 5, 30], [2, 6, 35]],signalSpeed = 5) == [9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 7], [0, 2, 14], [1, 3, 21], [1, 4, 28], [2, 5, 35], [2, 6, 42], [3, 7, 49], [4, 8, 56], [5, 9, 63], [6, 10, 70], [7, 11, 77], [8, 12, 84], [9, 13, 91], [10, 14, 98], [11, 15, 105], [12, 16, 112], [13, 17, 119], [14, 18, 126]],signalSpeed = 7) == [81, 96, 96, 45, 45, 45, 45, 32, 32, 32, 32, 17, 17, 17, 17, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 3], [0, 2, 9], [1, 3, 12], [1, 4, 6], [2, 5, 15], [2, 6, 3]],signalSpeed = 3) == [9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [1, 5, 1], [1, 6, 1], [2, 7, 1], [2, 8, 1], [3, 9, 1], [3, 10, 1], [4, 11, 1], [4, 12, 1]],signalSpeed = 1) == [54, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 5], [0, 2, 10], [0, 3, 15], [1, 4, 20], [2, 5, 25], [3, 6, 30]],signalSpeed = 5) == [12, 5, 5, 5, 0, 0, 0]\n assert candidate(edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70]],signalSpeed = 5) == [0, 6, 10, 12, 12, 10, 6, 0]\n assert candidate(edges = [[0, 1, 5], [0, 2, 10], [1, 3, 15], [1, 4, 20], [2, 5, 25], [2, 6, 30], [3, 7, 35], [4, 8, 40], [5, 9, 45], [6, 10, 50], [7, 11, 55], [8, 12, 60], [9, 13, 65], [10, 14, 70]],signalSpeed = 5) == [49, 57, 57, 24, 24, 24, 24, 13, 13, 13, 13, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70], [7, 8, 80], [8, 9, 90], [9, 10, 100], [10, 11, 110]],signalSpeed = 10) == [0, 10, 18, 24, 28, 30, 30, 28, 24, 18, 10, 0]\n assert candidate(edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [3, 8, 8], [4, 9, 9], [5, 10, 10], [6, 11, 11]],signalSpeed = 1) == [30, 36, 32, 19, 10, 10, 10, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 11], [1, 2, 22], [2, 3, 33], [3, 4, 44], [4, 5, 55], [5, 6, 66], [6, 7, 77], [7, 8, 88], [8, 9, 99]],signalSpeed = 33) == [0, 0, 5, 8, 1, 9, 8, 0, 5, 0]\n assert candidate(edges = [[0, 1, 100], [1, 2, 200], [2, 3, 300], [3, 4, 400], [4, 5, 500], [5, 6, 600], [6, 7, 700], [7, 8, 800]],signalSpeed = 100) == [0, 7, 12, 15, 16, 15, 12, 7, 0]\n assert candidate(edges = [[0, 1, 3], [1, 2, 4], [2, 3, 5], [3, 4, 6], [4, 5, 7], [5, 6, 8], [6, 7, 9]],signalSpeed = 3) == [0, 4, 0, 6, 6, 0, 4, 0]\n assert candidate(edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40]],signalSpeed = 7) == [0, 0, 0, 0, 0, 1, 1, 0, 0]\n assert candidate(edges = [[0, 1, 11], [0, 2, 22], [2, 3, 33], [2, 4, 44], [4, 5, 55], [4, 6, 66], [6, 7, 77], [6, 8, 88], [8, 9, 99], [8, 10, 110], [9, 11, 121], [11, 12, 132]],signalSpeed = 11) == [11, 0, 29, 0, 39, 0, 41, 0, 35, 20, 0, 11, 0]\n assert candidate(edges = [[0, 1, 5], [1, 2, 15], [1, 3, 25], [3, 4, 35], [3, 5, 45], [5, 6, 55], [5, 7, 65], [7, 8, 75], [7, 9, 85], [9, 10, 95]],signalSpeed = 5) == [0, 17, 0, 27, 0, 29, 0, 23, 0, 9, 0]\n assert candidate(edges = [[0, 1, 8], [0, 2, 16], [1, 3, 24], [1, 4, 32], [2, 5, 40], [2, 6, 48], [3, 7, 56], [3, 8, 64], [4, 9, 72], [4, 10, 80], [5, 11, 88], [5, 12, 96], [6, 13, 104], [6, 14, 112]],signalSpeed = 8) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 11], [0, 2, 22], [1, 3, 33], [1, 4, 44], [2, 5, 55], [2, 6, 66], [3, 7, 77], [4, 8, 88], [5, 9, 99], [6, 10, 110], [7, 11, 121], [8, 12, 132], [9, 13, 143], [10, 14, 154], [11, 15, 165], [12, 16, 176], [13, 17, 187], [14, 18, 198], [15, 19, 209], [16, 20, 220]],signalSpeed = 11) == [99, 125, 112, 64, 64, 51, 51, 51, 51, 36, 36, 36, 36, 19, 19, 19, 19, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 19], [0, 2, 38], [1, 3, 57], [1, 4, 76], [2, 5, 95], [2, 6, 114], [3, 7, 133], [3, 8, 152], [4, 9, 171], [4, 10, 190], [5, 11, 209], [5, 12, 228], [6, 13, 247], [6, 14, 266]],signalSpeed = 19) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40], [8, 9, 45]],signalSpeed = 5) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 13], [1, 2, 26], [2, 3, 39], [3, 4, 52], [4, 5, 65], [5, 6, 78], [6, 7, 91], [7, 8, 104], [8, 9, 117], [9, 10, 130]],signalSpeed = 13) == [0, 9, 16, 21, 24, 25, 24, 21, 16, 9, 0]\n assert candidate(edges = [[0, 1, 15], [1, 2, 30], [2, 3, 45], [3, 4, 60], [4, 5, 75], [5, 6, 90], [6, 7, 105], [7, 8, 120]],signalSpeed = 15) == [0, 7, 12, 15, 16, 15, 12, 7, 0]\n assert candidate(edges = [[0, 1, 3], [0, 2, 9], [2, 3, 27], [2, 4, 81], [4, 5, 243], [4, 6, 729], [6, 7, 2187], [6, 8, 6561], [8, 9, 19683], [8, 10, 59049]],signalSpeed = 3) == [9, 0, 23, 0, 29, 0, 27, 0, 17, 0, 0]\n assert candidate(edges = [[0, 1, 7], [1, 2, 14], [2, 3, 21], [3, 4, 28], [4, 5, 35], [5, 6, 42], [6, 7, 49], [7, 8, 56], [8, 9, 63], [9, 10, 70]],signalSpeed = 7) == [0, 9, 16, 21, 24, 25, 24, 21, 16, 9, 0]\n assert candidate(edges = [[0, 1, 3], [1, 2, 9], [2, 3, 12], [1, 4, 7], [4, 5, 14], [5, 6, 8]],signalSpeed = 3) == [0, 5, 3, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 13], [0, 2, 26], [1, 3, 39], [1, 4, 52], [2, 5, 65], [2, 6, 78], [3, 7, 91], [3, 8, 104], [4, 9, 117], [4, 10, 130], [5, 11, 143], [5, 12, 156], [6, 13, 169], [6, 14, 182]],signalSpeed = 13) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 1], [0, 2, 3], [0, 3, 5], [1, 4, 7], [1, 5, 9], [2, 6, 11], [2, 7, 13], [3, 8, 15], [3, 9, 17]],signalSpeed = 1) == [27, 15, 15, 15, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 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]],signalSpeed = 3) == [0, 0, 5, 8, 1, 9, 8, 0, 5, 0]\n assert candidate(edges = [[0, 1, 10], [0, 2, 20], [0, 3, 30], [1, 4, 40], [1, 5, 50], [2, 6, 60], [2, 7, 70], [3, 8, 80], [3, 9, 90]],signalSpeed = 10) == [27, 15, 15, 15, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 11], [0, 2, 22], [1, 3, 33], [1, 4, 44], [2, 5, 55], [2, 6, 66], [3, 7, 77], [3, 8, 88], [4, 9, 99], [4, 10, 110], [5, 11, 121], [5, 12, 132], [6, 13, 143], [6, 14, 154]],signalSpeed = 11) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 5], [0, 2, 10], [1, 3, 15], [1, 4, 20], [2, 5, 25], [2, 6, 30], [3, 7, 35], [3, 8, 40], [4, 9, 45], [4, 10, 50], [5, 11, 55], [5, 12, 60], [6, 13, 65], [6, 14, 70]],signalSpeed = 5) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [1, 4, 40], [2, 5, 50], [2, 6, 60], [5, 7, 70], [5, 8, 80]],signalSpeed = 10) == [15, 13, 19, 0, 0, 13, 0, 0, 0]\n assert candidate(edges = [[0, 1, 13], [1, 2, 26], [2, 3, 39], [3, 4, 52], [4, 5, 65], [5, 6, 78], [6, 7, 91], [7, 8, 104], [8, 9, 117], [9, 10, 130], [10, 11, 143]],signalSpeed = 13) == [0, 10, 18, 24, 28, 30, 30, 28, 24, 18, 10, 0]\n assert candidate(edges = [[0, 1, 6], [1, 2, 12], [2, 3, 18], [3, 4, 24], [4, 5, 30], [5, 6, 36], [6, 7, 42], [7, 8, 48], [8, 9, 54]],signalSpeed = 6) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 6], [3, 4, 8], [4, 5, 10], [5, 6, 12], [6, 7, 14], [7, 8, 16], [8, 9, 18], [9, 10, 20]],signalSpeed = 2) == [0, 9, 16, 21, 24, 25, 24, 21, 16, 9, 0]\n assert candidate(edges = [[0, 1, 3], [1, 2, 9], [2, 3, 27], [3, 4, 81], [4, 5, 243], [5, 6, 729], [6, 7, 2187], [7, 8, 6561], [8, 9, 19683]],signalSpeed = 3) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 7], [0, 2, 14], [1, 3, 21], [1, 4, 28], [2, 5, 35], [2, 6, 42], [3, 7, 49], [4, 8, 56], [5, 9, 63]],signalSpeed = 7) == [20, 24, 20, 8, 8, 8, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 9], [1, 2, 18], [2, 3, 27], [3, 4, 36], [4, 5, 45], [5, 6, 54], [6, 7, 63], [7, 8, 72], [8, 9, 81], [9, 10, 90], [10, 11, 99]],signalSpeed = 9) == [0, 10, 18, 24, 28, 30, 30, 28, 24, 18, 10, 0]\n assert candidate(edges = [[0, 1, 17], [1, 2, 34], [2, 3, 51], [3, 4, 68], [4, 5, 85], [5, 6, 102], [6, 7, 119], [7, 8, 136], [8, 9, 153], [9, 10, 170], [10, 11, 187], [11, 12, 204]],signalSpeed = 17) == [0, 11, 20, 27, 32, 35, 36, 35, 32, 27, 20, 11, 0]\n assert candidate(edges = [[0, 1, 2], [1, 2, 4], [2, 3, 6], [3, 4, 8], [4, 5, 10], [5, 6, 12], [6, 7, 14], [7, 8, 16], [8, 9, 18]],signalSpeed = 2) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40]],signalSpeed = 5) == [0, 7, 12, 15, 16, 15, 12, 7, 0]\n assert candidate(edges = [[0, 1, 23], [1, 2, 46], [2, 3, 69], [3, 4, 92], [4, 5, 115], [5, 6, 138], [6, 7, 161], [7, 8, 184], [8, 9, 207], [9, 10, 230], [10, 11, 253], [11, 12, 276], [12, 13, 299], [13, 14, 322]],signalSpeed = 23) == [0, 13, 24, 33, 40, 45, 48, 49, 48, 45, 40, 33, 24, 13, 0]\n assert candidate(edges = [[0, 1, 12], [0, 2, 24], [1, 3, 36], [1, 4, 48], [2, 5, 60], [2, 6, 72], [3, 7, 84], [3, 8, 96], [4, 9, 108], [4, 10, 120], [5, 11, 132], [5, 12, 144], [6, 13, 156], [6, 14, 168]],signalSpeed = 12) == [49, 57, 57, 25, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 100], [1, 2, 200], [2, 3, 300], [3, 4, 400], [4, 5, 500], [5, 6, 600], [6, 7, 700], [7, 8, 800], [8, 9, 900]],signalSpeed = 50) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 19], [1, 2, 38], [2, 3, 57], [3, 4, 76], [4, 5, 95], [5, 6, 114], [6, 7, 133], [7, 8, 152], [8, 9, 171], [9, 10, 190], [10, 11, 209], [11, 12, 228], [12, 13, 247]],signalSpeed = 19) == [0, 12, 22, 30, 36, 40, 42, 42, 40, 36, 30, 22, 12, 0]\n assert candidate(edges = [[0, 1, 11], [1, 2, 22], [2, 3, 33], [3, 4, 44], [4, 5, 55], [5, 6, 66], [6, 7, 77], [7, 8, 88], [8, 9, 99]],signalSpeed = 11) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 11], [0, 2, 22], [0, 3, 33], [1, 4, 44], [1, 5, 55], [2, 6, 66], [2, 7, 77], [3, 8, 88], [3, 9, 99], [4, 10, 110], [4, 11, 121], [5, 12, 132], [5, 13, 143], [6, 14, 154], [6, 15, 165], [7, 16, 176], [7, 17, 187], [8, 18, 198], [8, 19, 209], [9, 20, 220], [9, 21, 231]],signalSpeed = 11) == [147, 99, 99, 99, 39, 39, 39, 39, 39, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 11], [1, 2, 22], [1, 3, 33], [2, 4, 44], [2, 5, 55], [3, 6, 66], [3, 7, 77], [4, 8, 88], [5, 9, 99], [6, 10, 110], [7, 11, 121]],signalSpeed = 11) == [0, 35, 32, 32, 10, 10, 10, 10, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 3], [1, 2, 6], [1, 3, 9], [2, 4, 12], [2, 5, 15], [3, 6, 18], [3, 7, 21]],signalSpeed = 3) == [0, 15, 11, 11, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 2], [0, 2, 4], [0, 3, 6], [1, 4, 8], [1, 5, 10], [2, 6, 12], [2, 7, 14], [3, 8, 16], [3, 9, 18]],signalSpeed = 2) == [27, 15, 15, 15, 0, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 6], [1, 2, 12], [2, 3, 18], [3, 4, 24], [4, 5, 30], [5, 6, 36], [6, 7, 42], [7, 8, 48], [8, 9, 54], [9, 10, 60], [10, 11, 66]],signalSpeed = 6) == [0, 10, 18, 24, 28, 30, 30, 28, 24, 18, 10, 0]\n assert candidate(edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70]],signalSpeed = 10) == [0, 6, 10, 12, 12, 10, 6, 0]\n assert candidate(edges = [[0, 1, 3], [0, 2, 6], [1, 3, 9], [1, 4, 12], [2, 5, 15], [2, 6, 18], [3, 7, 21], [4, 8, 24], [5, 9, 27], [6, 10, 30]],signalSpeed = 3) == [25, 28, 28, 9, 9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 2], [0, 2, 4], [1, 3, 6], [1, 4, 8], [2, 5, 10], [2, 6, 12]],signalSpeed = 2) == [9, 9, 9, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 7], [1, 2, 14], [2, 3, 21], [3, 4, 28], [4, 5, 35], [5, 6, 42], [6, 7, 49], [7, 8, 56], [8, 9, 63]],signalSpeed = 7) == [0, 8, 14, 18, 20, 20, 18, 14, 8, 0]\n assert candidate(edges = [[0, 1, 17], [1, 2, 34], [1, 3, 51], [2, 4, 68], [2, 5, 85], [3, 6, 102], [3, 7, 119], [4, 8, 136], [5, 9, 153], [6, 10, 170], [7, 11, 187], [8, 12, 204], [9, 13, 221], [10, 14, 238]],signalSpeed = 17) == [0, 55, 57, 51, 24, 24, 24, 13, 13, 13, 13, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 14], [0, 2, 28], [1, 3, 42], [1, 4, 56], [2, 5, 70], [2, 6, 84], [4, 7, 98], [4, 8, 112], [5, 9, 126], [5, 10, 140], [7, 11, 154], [7, 12, 168]],signalSpeed = 14) == [35, 41, 35, 0, 35, 21, 0, 21, 0, 0, 0, 0, 0]\n assert candidate(edges = [[0, 1, 3], [1, 2, 6], [2, 3, 9], [3, 4, 12], [4, 5, 15], [5, 6, 18]],signalSpeed = 3) == [0, 5, 8, 9, 8, 5, 0]\n", "comparison": "exact"}, "public_tests": ["[[0,1,1],[1,2,5],[2,3,13],[3,4,9],[4,5,2]]\n1", "[[0,6,3],[6,5,3],[0,3,1],[3,2,7],[3,1,6],[3,4,2]]\n3"], "hints": ["Take each node as the root of the tree, run DFS, and save for each node i, the number of nodes in the subtree rooted at i whose distance to the root is divisible by signalSpeed.", "If the root has m children named c_1, c_2, …, c_m that respectively have num[c_1], num[c_2], …, num[c_m] nodes in their subtrees whose distance is divisible by signalSpeed. Then, there are ((S - num[c_i]) * num[c_i]) / 2that are connectable through the root that we have fixed, where S is the sum of num[c_i]."], "metadata": {"canonical_parameter_names": ["edges", "signalSpeed"], "leetcode_dataset_entry_point": "Solution().countPairsOfConnectableServers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:49+00:00", "tests_total": 92, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "tree", "depth-first-search"]}, "language": "ruby", "interface": {"raw_signature": "def count_pairs_of_connectable_servers(edges, signal_speed)", "container": null, "callable": "count_pairs_of_connectable_servers", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "signal_speed", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3068, "task_id": "find-the-maximum-sum-of-node-values", "difficulty": "Hard", "problem_description": "There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 0-indexed 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i] indicates that there is an edge between nodes u_i and v_i in the tree. You are also given a positive integer k, and a 0-indexed array of non-negative integers nums of length n, where nums[i] represents the value of the node numbered i.\n\nAlice wants the sum of values of tree nodes to be maximum, for which Alice can perform the following operation any number of times (including zero) on the tree:\n\n- Choose any edge [u, v] connecting the nodes u and v, and update their values as follows:\n - nums[u] = nums[u] XOR k\n - nums[v] = nums[v] XOR k\n\nReturn the maximum possible sum of the values Alice can achieve by performing the operation any number of times.\n\nExample 1:\n\nInput: nums = [1,2,1], k = 3, edges = [[0,1],[0,2]]\nOutput: 6\nExplanation: Alice can achieve the maximum sum of 6 using a single operation:\n- Choose the edge [0,2]. nums[0] and nums[2] become: 1 XOR 3 = 2, and the array nums becomes: [1,2,1] -> [2,2,2].\nThe total sum of values is 2 + 2 + 2 = 6.\nIt can be shown that 6 is the maximum achievable sum of values.\n\nExample 2:\n\nInput: nums = [2,3], k = 7, edges = [[0,1]]\nOutput: 9\nExplanation: Alice can achieve the maximum sum of 9 using a single operation:\n- Choose the edge [0,1]. nums[0] becomes: 2 XOR 7 = 5 and nums[1] become: 3 XOR 7 = 4, and the array nums becomes: [2,3] -> [5,4].\nThe total sum of values is 5 + 4 = 9.\nIt can be shown that 9 is the maximum achievable sum of values.\n\nExample 3:\n\nInput: nums = [7,7,7,7,7,7], k = 3, edges = [[0,1],[0,2],[0,3],[0,4],[0,5]]\nOutput: 42\nExplanation: The maximum achievable sum is 42 which can be achieved by Alice performing no operations.\n\nConstraints:\n\n- 2 <= n == nums.length <= 2 * 10^4\n- 1 <= k <= 10^9\n- 0 <= nums[i] <= 10^9\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= edges[i][0], edges[i][1] <= n - 1\n- The input is generated such that edges represent a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4],k = 5,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 26\n assert candidate(nums = [7, 7, 7, 7, 7, 7],k = 3,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == 42\n assert candidate(nums = [1, 2, 3, 4, 5],k = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 51\n assert candidate(nums = [1, 2, 1],k = 3,edges = [[0, 1], [0, 2]]) == 6\n assert candidate(nums = [5, 9, 14],k = 8,edges = [[0, 1], [1, 2]]) == 28\n assert candidate(nums = [0, 0, 0, 0],k = 1,edges = [[0, 1], [1, 2], [2, 3]]) == 4\n assert candidate(nums = [2, 3],k = 7,edges = [[0, 1]]) == 9\n assert candidate(nums = [10, 10, 10, 10],k = 1,edges = [[0, 1], [1, 2], [2, 3]]) == 44\n assert candidate(nums = [0, 0, 0],k = 5,edges = [[0, 1], [1, 2]]) == 10\n assert candidate(nums = [5, 9, 14, 10],k = 6,edges = [[0, 1], [1, 2], [1, 3]]) == 46\n assert candidate(nums = [5, 9, 4, 8],k = 6,edges = [[0, 1], [1, 2], [2, 3]]) == 38\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256],k = 255,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]]) == 2297\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 108\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 3,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 2075\n assert candidate(nums = [100, 200, 300, 400, 500],k = 50,edges = [[0, 1], [0, 2], [1, 3], [1, 4]]) == 1568\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 = 9,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 306\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600],k = 123,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 2234\n assert candidate(nums = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000],k = 123456789,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 514688170\n assert candidate(nums = [123456789, 987654321, 111222333, 444555666, 777888999],k = 987654321,edges = [[0, 1], [0, 2], [1, 3], [2, 4]]) == 4257254234\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333],k = 987654321,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4656069870\n assert candidate(nums = [1000, 900, 800, 700, 600],k = 150,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4268\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 592\n assert candidate(nums = [123456789, 987654321, 112233445, 556677889, 998877665, 443322110],k = 987654321,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 5049931145\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70],k = 25,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 316\n assert candidate(nums = [10, 20, 30, 40, 50, 60],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 228\n assert candidate(nums = [0, 1000000000, 500000000, 250000000, 125000000],k = 987654321,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4554116228\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 = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29]]) == 30\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35],k = 50,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 332\n assert candidate(nums = [1, 10, 100, 1000, 10000],k = 1234,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 15531\n assert candidate(nums = [10, 20, 30, 40, 50, 60],k = 13,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 228\n assert candidate(nums = [10, 20, 30, 40, 50, 60],k = 25,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == 228\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1000000000,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 20000000000\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109],k = 101,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 859\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 11,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 103\n assert candidate(nums = [10, 20, 30, 40, 50],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 168\n assert candidate(nums = [20, 15, 10, 5, 0],k = 25,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 114\n assert candidate(nums = [100, 200, 300, 400, 500],k = 123,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 1634\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1024,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 14456\n assert candidate(nums = [10, 20, 30, 40, 50],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 168\n assert candidate(nums = [10, 15, 20, 25, 30],k = 17,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 132\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 110\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80],k = 23,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 404\n assert candidate(nums = [12, 13, 14, 15, 16, 17, 18, 19, 20],k = 7,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 160\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 11,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 193\n assert candidate(nums = [123456789, 987654321, 234567890, 345678901, 456789012, 567890123, 678901234, 789012345],k = 890123456,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 6162095767\n assert candidate(nums = [9, 18, 27, 36, 45],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 153\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 16,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 192\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800],k = 123,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 3804\n assert candidate(nums = [9, 14, 3, 5, 8, 12],k = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == 63\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 89\n assert candidate(nums = [10, 20, 30, 40, 50, 60],k = 15,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == 228\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]]) == 8000000008\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14]]) == 15\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63],k = 23,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 288\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 11,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 216\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 1000000000,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 9340892827\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 500000000,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4999999990\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 7,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 293\n assert candidate(nums = [8, 16, 32, 64, 128, 256],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 578\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40],k = 17,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 244\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 123456789,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 1976228234\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 49\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 31,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 353\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109],k = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 643\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 5636\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505, 606, 707],k = 111,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9]]) == 4400\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 16\n assert candidate(nums = [999, 888, 777, 666, 555, 444, 333, 222, 111, 0],k = 456,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 6387\n assert candidate(nums = [12, 14, 16, 18, 20, 22, 24, 26, 28],k = 13,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 216\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 64\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 30,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 614\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 15,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9]]) == 109\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995],k = 123456789,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 6115696553\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 7,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 73\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1000000000,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4000000015\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 49\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800],k = 255,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 4092\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 255,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9]]) == 3063\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000],k = 123456789,edges = [[0, 1], [1, 2], [2, 3]]) == 1875000000\n assert candidate(nums = [12345, 67890, 54321, 98765, 43210, 87654, 32109, 76543],k = 11111,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 510661\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 = 21,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 434\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 999999995,edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4999999990\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 255,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 4343\n", "comparison": "exact"}, "public_tests": ["[1,2,1]\n3\n[[0,1],[0,2]]", "[2,3]\n7\n[[0,1]]", "[7,7,7,7,7,7]\n3\n[[0,1],[0,2],[0,3],[0,4],[0,5]]"], "hints": ["Select any node as the root.", "Let dp[x][c] be the maximum sum we can get for the subtree rooted at node x, where c is a boolean representing whether the edge between node x and its parent (if any) is selected or not.", "dp[x][c] = max(sum(dp[y][cy]) + v(nums[x], sum(cy) + c)) where cy is 0 or 1. When sum(cy) + c is odd, v(nums[x], sum(cy) + c) = nums[x] XOR k. When sum(cy) + c is even, v(nums[x], sum(cy) + c) = nums[x].", "There’s also an easier solution - does the parity of the number of elements where nums[i] XOR k > nums[i] help?"], "metadata": {"canonical_parameter_names": ["nums", "k", "edges"], "leetcode_dataset_entry_point": "Solution().maximumValueSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:51+00:00", "tests_total": 91, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "greedy", "bit-manipulation", "tree", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_value_sum(nums, k, edges)", "container": null, "callable": "maximum_value_sum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3069, "task_id": "distribute-elements-into-two-arrays-i", "difficulty": "Easy", "problem_description": "You are given a 1-indexed array of distinct integers nums of length n.\n\nYou need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the i^th operation:\n\n- If the last element of arr1 is greater than the last element of arr2, append nums[i] to arr1. Otherwise, append nums[i] to arr2.\n\nThe array result is formed by concatenating the arrays arr1 and arr2. Concatenating two arrays appends the second to the end of the first; for example, concatenating [1,2,3] with [4,5,6] gives [1,2,3,4,5,6].\n\nReturn the array result.\n\nExample 1:\n\nInput: nums = [2,1,3]\nOutput: [2,3,1]\nExplanation: After the first 2 operations, arr1 = [2] and arr2 = [1].\nIn the 3^rd operation, as the last element of arr1 is greater than the last element of arr2 (2 > 1), append nums[3] to arr1.\nAfter 3 operations, arr1 = [2,3] and arr2 = [1].\nHence, the array result formed by concatenation is [2,3,1].\n\nExample 2:\n\nInput: nums = [5,4,3,8]\nOutput: [5,3,4,8]\nExplanation: After the first 2 operations, arr1 = [5] and arr2 = [4].\nIn the 3^rd operation, as the last element of arr1 is greater than the last element of arr2 (5 > 4), append nums[3] to arr1, hence arr1 becomes [5,3].\nIn the 4^th operation, as the last element of arr2 is greater than the last element of arr1 (4 > 3), append nums[4] to arr2, hence arr2 becomes [4,8].\nAfter 4 operations, arr1 = [5,3] and arr2 = [4,8].\nHence, the array result formed by concatenation is [5,3,4,8].\n\nConstraints:\n\n- 3 <= n <= 50\n- 1 <= nums[i] <= 100\n- All elements in nums are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == [1, 3, 2, 4, 5]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == [7, 5, 3, 1, 6, 4, 2]\n assert candidate(nums = [3, 1, 2, 5, 4]) == [3, 2, 5, 4, 1]\n assert candidate(nums = [10, 20, 30, 5, 15]) == [10, 15, 20, 30, 5]\n assert candidate(nums = [1, 3, 2, 4, 6, 5]) == [1, 3, 2, 4, 6, 5]\n assert candidate(nums = [5, 4, 3, 8]) == [5, 3, 4, 8]\n assert candidate(nums = [2, 1, 3]) == [2, 3, 1]\n assert candidate(nums = [8, 9, 7, 6, 10, 5]) == [8, 6, 9, 7, 10, 5]\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]) == [50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11]\n assert candidate(nums = [10, 20, 15, 25, 30]) == [10, 20, 15, 25, 30]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 8, 6, 4, 2, 9, 7, 5, 3, 1]\n assert candidate(nums = [3, 5, 2, 4, 6, 8, 1]) == [3, 4, 6, 8, 1, 5, 2]\n assert candidate(nums = [3, 1, 4, 2, 5]) == [3, 4, 2, 5, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\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]) == [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]\n assert candidate(nums = [8, 2, 14, 10, 6, 12, 4, 1, 9, 5, 11, 7, 13, 3]) == [8, 14, 10, 6, 12, 4, 1, 2, 9, 5, 11, 7, 13, 3]\n assert candidate(nums = [6, 3, 9, 2, 8, 5, 11, 4, 10, 7]) == [6, 9, 2, 3, 8, 5, 11, 4, 10, 7]\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [30, 28, 26, 24, 22, 1, 29, 27, 25, 23, 21, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 3, 9, 1, 5, 11, 13, 2, 8, 6, 10, 4]) == [7, 9, 1, 3, 5, 11, 13, 2, 8, 6, 10, 4]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91, 11, 90, 12, 89, 13, 88, 14, 87, 15, 86]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91, 11, 90, 12, 89, 13, 88, 14, 87, 15, 86]\n assert candidate(nums = [5, 20, 3, 10, 8, 15, 6, 25, 12, 30, 18, 35, 22, 40, 26, 45, 32, 50, 38, 1]) == [5, 10, 8, 15, 6, 25, 12, 30, 18, 35, 22, 40, 26, 45, 32, 50, 38, 1, 20, 3]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == [25, 23, 21, 19, 17, 15, 13, 11, 24, 22, 20, 18, 16, 14, 12]\n assert candidate(nums = [10, 20, 5, 15, 25, 1, 30, 3, 2, 28]) == [10, 15, 25, 1, 20, 5, 30, 3, 2, 28]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [15, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [25, 15, 5, 1, 4, 9, 14, 3, 8, 13, 2, 7, 12, 6, 11, 10, 20, 16, 18, 19, 21, 22, 23, 24]) == [25, 5, 4, 9, 14, 3, 8, 13, 2, 7, 12, 6, 11, 10, 20, 16, 18, 19, 21, 22, 23, 24, 15, 1]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]\n assert candidate(nums = [8, 16, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]) == [8, 12, 2, 9, 5, 13, 3, 11, 7, 15, 16, 4, 10, 6, 14, 1]\n assert candidate(nums = [3, 1, 4, 2, 5, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30, 33, 32, 35, 34, 37, 36, 39, 38, 41, 40, 43, 42, 45, 44, 47, 46, 49, 48, 50]) == [3, 4, 2, 5, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30, 33, 32, 35, 34, 37, 36, 39, 38, 41, 40, 43, 42, 45, 44, 47, 46, 49, 48, 50, 1]\n assert candidate(nums = [5, 3, 1, 4, 2, 7, 6, 9, 8, 10]) == [5, 1, 3, 4, 2, 7, 6, 9, 8, 10]\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10]) == [5, 9, 2, 8, 3, 7, 4, 6, 10, 1]\n assert candidate(nums = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [13, 11, 9, 7, 5, 3, 1, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [2, 4, 6, 8, 10, 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]) == [2, 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, 4, 6, 8, 10, 1]\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 45, 50]) == [10, 35, 40, 45, 50, 20, 15, 25, 30, 5]\n assert candidate(nums = [13, 8, 5, 17, 12, 10, 20, 6, 15, 11, 18, 3, 14, 7, 19, 2, 9, 4, 16]) == [13, 5, 14, 7, 19, 2, 8, 17, 12, 10, 20, 6, 15, 11, 18, 3, 9, 4, 16]\n assert candidate(nums = [5, 9, 3, 8, 1, 7, 4, 6, 2]) == [5, 8, 1, 9, 3, 7, 4, 6, 2]\n assert candidate(nums = [37, 52, 45, 63, 28, 75, 19, 84, 12, 91]) == [37, 75, 19, 91, 52, 45, 63, 28, 84, 12]\n assert candidate(nums = [2, 10, 3, 9, 4, 8, 5, 7, 6, 11, 12, 13, 14, 15]) == [2, 10, 3, 9, 4, 8, 5, 7, 6, 11, 12, 13, 14, 15]\n assert candidate(nums = [7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1]) == [7, 8, 5, 10, 3, 12, 1, 6, 9, 4, 11, 2]\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, 31]) == [30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [10, 2, 3, 4, 5, 6, 7, 8, 9, 20, 30, 40, 50, 1]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 9, 10]) == [8, 6, 4, 2, 9, 10, 7, 5, 3, 1]\n assert candidate(nums = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11]) == [2, 3, 5, 7, 9, 11, 4, 6, 8, 10, 1]\n assert candidate(nums = [40, 35, 30, 25, 20, 15, 10, 5, 1, 6, 11, 16, 21, 26, 31, 36, 41, 2, 7, 12, 17, 22, 27, 32, 37, 42, 3, 8, 13, 18, 23, 28, 33, 38, 43, 4, 9, 14, 19, 24, 29, 34, 39, 44]) == [40, 30, 20, 10, 1, 35, 25, 15, 5, 6, 11, 16, 21, 26, 31, 36, 41, 2, 7, 12, 17, 22, 27, 32, 37, 42, 3, 8, 13, 18, 23, 28, 33, 38, 43, 4, 9, 14, 19, 24, 29, 34, 39, 44]\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]\n assert candidate(nums = [12, 6, 18, 3, 21, 9, 15, 1, 13, 5, 17, 7, 2, 14, 8, 10, 16, 4, 19, 11]) == [12, 18, 3, 13, 5, 17, 7, 2, 14, 8, 10, 16, 4, 19, 11, 6, 21, 9, 15, 1]\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]) == [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]\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4]) == [10, 20, 2, 30, 3, 40, 4, 1]\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [10, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 1]\n assert candidate(nums = [5, 8, 6, 3, 9, 2, 11, 7, 1, 4, 10]) == [5, 9, 2, 4, 10, 8, 6, 3, 11, 7, 1]\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, 50]) == [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, 50]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [10, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [10, 8, 6, 4, 2, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 9, 7, 5, 3, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [10, 8, 6, 4, 2, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 9, 7, 5, 3, 1]\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]) == [25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [50, 1, 49, 2, 48, 3, 47, 4, 46, 5, 45, 6, 44, 7, 43, 8, 42, 9, 41, 10, 40, 11, 39, 12, 38, 13, 37, 14, 36, 15, 35, 16, 34, 17, 33, 18, 32, 19, 31, 20, 30, 21, 29, 22, 28, 23, 27, 24, 26, 25]) == [50, 49, 2, 48, 3, 47, 4, 46, 5, 45, 6, 44, 7, 43, 8, 42, 9, 41, 10, 40, 11, 39, 12, 38, 13, 37, 14, 36, 15, 35, 16, 34, 17, 33, 18, 32, 19, 31, 20, 30, 21, 29, 22, 28, 23, 27, 24, 26, 25, 1]\n assert candidate(nums = [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [41, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 20, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 42, 43, 44, 45, 46, 47, 48, 49, 50, 30, 21, 22, 23, 24, 25, 26, 27, 28, 29, 10, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [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]) == [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]) == [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 8, 6, 4, 2, 9, 7, 5, 3, 1]\n assert candidate(nums = [1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6, 10, 7, 9, 8]) == [1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6, 10, 7, 9, 8]\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, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100]) == [30, 10, 20, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [45, 35, 25, 15, 5, 6, 16, 26, 36, 46, 55, 44, 33, 22, 11]) == [45, 25, 5, 35, 15, 6, 16, 26, 36, 46, 55, 44, 33, 22, 11]\n assert candidate(nums = [3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10]) == [3, 1, 2, 6, 5, 4, 9, 8, 7, 12, 11, 10]\n assert candidate(nums = [3, 2, 5, 1, 8, 4, 7, 6]) == [3, 5, 1, 2, 8, 4, 7, 6]\n assert candidate(nums = [25, 50, 1, 24, 49, 2, 23, 48, 3, 22, 47, 4, 21, 46, 5, 20, 45, 6, 19, 44, 7, 18, 43, 8, 17, 42, 9, 16, 41, 10, 15, 40, 11, 14, 39, 12, 13, 38]) == [25, 24, 49, 2, 23, 48, 3, 22, 47, 4, 21, 46, 5, 20, 45, 6, 19, 44, 7, 18, 43, 8, 17, 42, 9, 16, 41, 10, 15, 40, 11, 14, 39, 12, 13, 38, 50, 1]\n assert candidate(nums = [7, 6, 5, 8, 9, 10, 1, 2, 3, 4]) == [7, 5, 2, 3, 4, 6, 8, 9, 10, 1]\n assert candidate(nums = [15, 20, 10, 25, 5, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [15, 25, 5, 20, 10, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]\n assert candidate(nums = [13, 7, 21, 3, 18, 11, 29, 6, 27, 15]) == [13, 21, 3, 7, 18, 11, 29, 6, 27, 15]\n assert candidate(nums = [25, 26, 23, 27, 21, 28, 19, 30, 17, 31, 15, 32, 13, 33, 11, 34, 9, 35, 7, 36, 5, 37, 3, 38, 1, 39]) == [25, 27, 21, 30, 17, 32, 13, 34, 9, 36, 5, 38, 1, 26, 23, 28, 19, 31, 15, 33, 11, 35, 7, 37, 3, 39]\n assert candidate(nums = [8, 6, 10, 3, 7, 5, 9, 2, 4, 1]) == [8, 10, 3, 4, 1, 6, 7, 5, 9, 2]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]\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]) == [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]\n assert candidate(nums = [10, 5, 7, 3, 8, 6, 9, 2, 4, 1]) == [10, 7, 3, 4, 1, 5, 8, 6, 9, 2]\n assert candidate(nums = [10, 15, 5, 20, 1, 25, 100, 50, 75, 2]) == [10, 20, 1, 15, 5, 25, 100, 50, 75, 2]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5]) == [9, 8, 2, 7, 3, 6, 4, 5, 1]\n assert candidate(nums = [20, 2, 18, 4, 16, 6, 14, 8, 12, 10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [20, 18, 4, 16, 6, 14, 8, 12, 10, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 11, 12, 13, 14, 15]) == [8, 6, 4, 2, 10, 9, 11, 12, 13, 14, 15, 7, 5, 3, 1]\n assert candidate(nums = [15, 1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8]) == [15, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8, 1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [7, 10, 5, 3, 8, 12, 9, 6, 11, 4]) == [7, 3, 10, 5, 8, 12, 9, 6, 11, 4]\n assert candidate(nums = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == [2, 3, 5, 7, 9, 4, 6, 8, 10, 1]\n assert candidate(nums = [42, 24, 63, 12, 84, 36, 54, 72, 90, 18]) == [42, 63, 12, 24, 84, 36, 54, 72, 90, 18]\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]) == [100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 52, 99, 97, 95, 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 53, 51]\n assert candidate(nums = [80, 70, 60, 50, 40, 30, 20, 10, 90, 85, 75, 65, 55, 45, 35, 25, 15, 5, 95, 88]) == [80, 60, 40, 20, 90, 85, 75, 65, 55, 45, 35, 25, 15, 5, 70, 50, 30, 10, 95, 88]\n assert candidate(nums = [1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10, 90, 11, 89, 12, 88, 13, 87, 14, 86, 15, 85, 16, 84, 17, 83, 18, 82, 19, 81, 20, 80, 21, 79, 22, 78, 23, 77, 24, 76, 25, 75, 26, 74, 27, 73, 28, 72, 29, 71, 30, 70]) == [1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10, 90, 11, 89, 12, 88, 13, 87, 14, 86, 15, 85, 16, 84, 17, 83, 18, 82, 19, 81, 20, 80, 21, 79, 22, 78, 23, 77, 24, 76, 25, 75, 26, 74, 27, 73, 28, 72, 29, 71, 30, 70]\n assert candidate(nums = [7, 10, 3, 6, 9, 2, 5, 8, 1, 4]) == [7, 6, 9, 2, 4, 10, 3, 5, 8, 1]\n assert candidate(nums = [1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == [1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]\n assert candidate(nums = [7, 3, 9, 1, 5, 11, 13, 2, 8, 4, 10, 6]) == [7, 9, 1, 3, 5, 11, 13, 2, 8, 4, 10, 6]\n assert candidate(nums = [30, 20, 10, 5, 15, 25, 40, 35, 3, 7, 1, 9, 2, 8, 6, 14, 12, 18, 16, 11, 17, 13, 19, 21, 23, 24, 22, 26, 28, 27, 29]) == [30, 10, 15, 25, 40, 35, 3, 9, 2, 8, 6, 14, 12, 18, 16, 11, 17, 13, 19, 21, 23, 24, 22, 26, 28, 27, 29, 20, 5, 7, 1]\n assert candidate(nums = [30, 1, 29, 2, 28, 3, 27, 4, 26, 5, 25, 6, 24, 7, 23, 8, 22, 9, 21, 10]) == [30, 29, 2, 28, 3, 27, 4, 26, 5, 25, 6, 24, 7, 23, 8, 22, 9, 21, 10, 1]\n assert candidate(nums = [25, 19, 30, 14, 24, 9, 29, 4, 23, 10, 13, 28, 5, 22, 8, 12, 27, 6, 21, 7, 20, 11, 18, 15, 17, 16]) == [25, 30, 14, 29, 4, 19, 24, 9, 23, 10, 13, 28, 5, 22, 8, 12, 27, 6, 21, 7, 20, 11, 18, 15, 17, 16]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]\n assert candidate(nums = [12, 9, 15, 8, 18, 7, 21, 6, 24, 5]) == [12, 15, 8, 21, 6, 9, 18, 7, 24, 5]\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10]) == [2, 4, 5, 6, 7, 8, 9, 10, 3, 1]\n", "comparison": "exact"}, "public_tests": ["[2,1,3]", "[5,4,3,8]"], "hints": ["Divide the array into two arrays by keeping track of the last elements of both subarrays."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().resultArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:53+00:00", "tests_total": 107, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "two-pointers", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def result_array(nums)", "container": null, "callable": "result_array", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3070, "task_id": "count-submatrices-with-top-left-element-and-sum-less-than-k", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer matrix grid and an integer k.\n\nReturn the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k.\n\nExample 1:\n\nInput: grid = [[7,6,3],[6,6,1]], k = 18\nOutput: 4\nExplanation: There are only 4 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 18.\n\nExample 2:\n\nInput: grid = [[7,2,9],[1,5,0],[2,6,6]], k = 20\nOutput: 6\nExplanation: There are only 6 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 20.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= n, m <= 1000\n- 0 <= grid[i][j] <= 1000\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],k = 15) == 5\n assert candidate(grid = [[1, 2], [3, 4]],k = 10) == 4\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]],k = 2) == 6\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 5) == 6\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],k = 15) == 5\n assert candidate(grid = [[1]],k = 1) == 1\n assert candidate(grid = [[7, 2, 9], [1, 5, 0], [2, 6, 6]],k = 20) == 6\n assert candidate(grid = [[7, 6, 3], [6, 6, 1]],k = 18) == 4\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 15) == 6\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],k = 1) == 9\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],k = 10) == 4\n assert candidate(grid = [[1000, 1000], [1000, 1000]],k = 3000) == 3\n assert candidate(grid = [[1, 1, 1], [1, 1, 1]],k = 2) == 3\n assert candidate(grid = [[1000, 1000], [1000, 1000]],k = 2000) == 3\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],k = 25) == 6\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],k = 50) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],k = 50) == 11\n assert candidate(grid = [[9, 8, 7, 6, 5], [4, 3, 2, 1, 0], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],k = 100) == 23\n assert candidate(grid = [[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60]],k = 100) == 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]],k = 5) == 8\n assert candidate(grid = [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60], [65, 70, 75, 80]],k = 150) == 9\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],k = 30) == 9\n assert candidate(grid = [[1000, 0, 0, 0, 0], [0, 1000, 0, 0, 0], [0, 0, 1000, 0, 0], [0, 0, 0, 1000, 0], [0, 0, 0, 0, 1000]],k = 4000) == 24\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],k = 40) == 10\n assert candidate(grid = [[900, 100, 100], [100, 900, 100], [100, 100, 900]],k = 1500) == 5\n assert candidate(grid = [[2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]],k = 16) == 12\n assert candidate(grid = [[1000, 1000, 1000], [1000, 1000, 1000], [1000, 1000, 1000], [1000, 1000, 1000]],k = 10000) == 11\n assert candidate(grid = [[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]],k = 100) == 17\n assert candidate(grid = [[3, 6, 9, 12, 15, 18, 21], [24, 27, 30, 33, 36, 39, 42], [45, 48, 51, 54, 57, 60, 63]],k = 200) == 14\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]],k = 10) == 17\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],k = 2) == 12\n assert candidate(grid = [[999, 999], [999, 999], [999, 999]],k = 2997) == 4\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],k = 5) == 20\n assert candidate(grid = [[9, 9, 9], [9, 9, 9], [9, 9, 9]],k = 81) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10]],k = 50) == 13\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11]],k = 30) == 10\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 = 15) == 22\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]],k = 20) == 4\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]],k = 50) == 13\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],k = 20) == 6\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],k = 100) == 20\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 = 1) == 25\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]],k = 20) == 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]],k = 7) == 12\n assert candidate(grid = [[100, 200], [300, 400], [500, 600]],k = 1200) == 5\n assert candidate(grid = [[7, 6, 3, 4], [6, 6, 1, 2], [5, 3, 8, 1], [4, 2, 7, 5]],k = 25) == 8\n assert candidate(grid = [[100, 200, 300], [400, 500, 600], [700, 800, 900]],k = 1500) == 6\n assert candidate(grid = [[5, 10, 15], [20, 25, 30], [35, 40, 45]],k = 100) == 6\n assert candidate(grid = [[999, 999, 999], [999, 999, 999], [999, 999, 999], [999, 999, 999]],k = 3000) == 5\n assert candidate(grid = [[10, 20, 30, 40], [40, 30, 20, 10], [5, 5, 5, 5]],k = 50) == 3\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],k = 200) == 6\n assert candidate(grid = [[999, 999], [999, 999]],k = 1998) == 3\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 = 10) == 15\n assert candidate(grid = [[100, 200, 300], [400, 500, 600], [700, 800, 900]],k = 1500) == 6\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],k = 1) == 16\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]],k = 10) == 17\n assert candidate(grid = [[500, 500, 500, 500], [500, 500, 500, 500], [500, 500, 500, 500], [500, 500, 500, 500]],k = 5000) == 13\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],k = 30) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2]],k = 25) == 12\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [3, 4, 5, 6, 7]],k = 50) == 20\n assert candidate(grid = [[500, 500], [500, 500], [500, 500], [500, 500], [500, 500]],k = 1500) == 4\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]],k = 100) == 25\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],k = 100) == 4\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],k = 10) == 16\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]],k = 10) == 14\n assert candidate(grid = [[100, 200, 300], [200, 100, 400], [300, 400, 500]],k = 1500) == 8\n assert candidate(grid = [[1000, 900, 800], [700, 600, 500], [400, 300, 200]],k = 3000) == 5\n assert candidate(grid = [[10, 20, 30, 40], [5, 15, 25, 35], [50, 60, 70, 80]],k = 100) == 7\n assert candidate(grid = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50]],k = 100) == 6\n assert candidate(grid = [[100, 200], [300, 400], [500, 600], [700, 800]],k = 1000) == 5\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]],k = 20) == 31\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]],k = 40) == 10\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],k = 100) == 16\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5]],k = 100) == 20\n assert candidate(grid = [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60], [65, 70, 75, 80]],k = 100) == 7\n assert candidate(grid = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]],k = 25) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],k = 50) == 12\n assert candidate(grid = [[100, 200, 300], [400, 500, 600], [700, 800, 900]],k = 2500) == 7\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],k = 30) == 8\n assert candidate(grid = [[3, 1, 2], [1, 4, 5], [5, 2, 3]],k = 25) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],k = 30) == 9\n assert candidate(grid = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]],k = 250) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],k = 50) == 11\n assert candidate(grid = [[3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3]],k = 30) == 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 25) == 34\n assert candidate(grid = [[9, 8, 7, 6], [5, 4, 3, 2], [1, 0, 1, 0], [2, 3, 4, 5]],k = 25) == 6\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 = 10) == 25\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 = 20) == 35\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],k = 150) == 6\n assert candidate(grid = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]],k = 500) == 11\n assert candidate(grid = [[250, 250, 250, 250], [250, 250, 250, 250], [250, 250, 250, 250]],k = 750) == 5\n assert candidate(grid = [[999, 998, 997], [996, 995, 994], [993, 992, 991]],k = 3000) == 5\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90], [100, 110, 120]],k = 100) == 4\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]],k = 20) == 6\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 20) == 7\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]],k = 20) == 30\n assert candidate(grid = [[10, 20, 30, 40, 50], [60, 70, 80, 90, 100], [110, 120, 130, 140, 150], [160, 170, 180, 190, 200]],k = 500) == 12\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]],k = 150) == 17\n assert candidate(grid = [[900, 100, 200], [300, 400, 500], [600, 700, 800]],k = 2000) == 6\n", "comparison": "exact"}, "public_tests": ["[[7,6,3],[6,6,1]]\n18", "[[7,2,9],[1,5,0],[2,6,6]]\n20"], "hints": [], "metadata": {"canonical_parameter_names": ["grid", "k"], "leetcode_dataset_entry_point": "Solution().countSubmatrices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:56+00:00", "tests_total": 104, "tests_dropped": 5, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def count_submatrices(grid, k)", "container": null, "callable": "count_submatrices", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3071, "task_id": "minimum-operations-to-write-the-letter-y-on-a-grid", "difficulty": "Medium", "problem_description": "You are given a 0-indexed n x n grid where n is odd, and grid[r][c] is 0, 1, or 2.\n\nWe say that a cell belongs to the Letter Y if it belongs to one of the following:\n\n- The diagonal starting at the top-left cell and ending at the center cell of the grid.\n- The diagonal starting at the top-right cell and ending at the center cell of the grid.\n- The vertical line starting at the center cell and ending at the bottom border of the grid.\n\nThe Letter Y is written on the grid if and only if:\n\n- All values at cells belonging to the Y are equal.\n- All values at cells not belonging to the Y are equal.\n- The values at cells belonging to the Y are different from the values at cells not belonging to the Y.\n\nReturn the minimum number of operations needed to write the letter Y on the grid given that in one operation you can change the value at any cell to 0, 1, or 2.\n\nExample 1:\n\nInput: grid = [[1,2,2],[1,1,0],[0,1,0]]\nOutput: 3\nExplanation: We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 1 while those that do not belong to Y are equal to 0.\nIt can be shown that 3 is the minimum number of operations needed to write Y on the grid.\n\nExample 2:\n\nInput: grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]]\nOutput: 12\nExplanation: We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 0 while those that do not belong to Y are equal to 2.\nIt can be shown that 12 is the minimum number of operations needed to write Y on the grid.\n\nConstraints:\n\n- 3 <= n <= 49\n- n == grid.length == grid[i].length\n- 0 <= grid[i][j] <= 2\n- n is odd.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 4\n assert candidate(grid = [[1, 0, 2], [0, 1, 0], [2, 0, 1]]) == 4\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 3\n assert candidate(grid = [[1, 0, 1], [0, 0, 0], [1, 0, 1]]) == 4\n assert candidate(grid = [[1, 2, 2], [1, 1, 0], [0, 1, 0]]) == 3\n assert candidate(grid = [[2, 1, 0], [1, 2, 1], [0, 1, 2]]) == 4\n assert candidate(grid = [[0, 1, 2], [1, 1, 2], [2, 1, 0]]) == 5\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 4\n assert candidate(grid = [[0, 1, 2], [1, 0, 1], [2, 1, 0]]) == 4\n assert candidate(grid = [[2, 2, 2], [2, 2, 2], [2, 2, 2]]) == 4\n assert candidate(grid = [[0, 1, 0, 1, 0], [2, 1, 0, 1, 2], [2, 2, 2, 0, 1], [2, 2, 2, 2, 2], [2, 1, 2, 2, 2]]) == 12\n assert candidate(grid = [[2, 1, 0], [1, 1, 1], [0, 1, 2]]) == 5\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 2, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 20\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 19\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 0, 0, 0, 0, 0, 1, 2], [2, 1, 0, 0, 0, 0, 0, 1, 2], [2, 1, 0, 0, 2, 0, 0, 1, 2], [2, 1, 0, 0, 0, 0, 0, 1, 2], [2, 1, 0, 0, 0, 0, 0, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2]]) == 46\n assert candidate(grid = [[2, 0, 0, 0, 2], [0, 1, 1, 1, 0], [0, 1, 2, 1, 0], [0, 1, 1, 1, 0], [2, 0, 0, 0, 2]]) == 11\n assert candidate(grid = [[0, 1, 2, 1, 0], [1, 0, 1, 0, 1], [2, 1, 0, 1, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2]]) == 9\n assert candidate(grid = [[1, 2, 2, 2, 1], [2, 2, 1, 2, 2], [2, 1, 2, 1, 2], [2, 0, 2, 0, 2], [2, 2, 2, 2, 2]]) == 10\n assert candidate(grid = [[0, 2, 2, 2, 0], [2, 0, 2, 0, 2], [2, 2, 1, 2, 2], [2, 0, 2, 0, 2], [0, 2, 2, 2, 0]]) == 7\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1]]) == 9\n assert candidate(grid = [[2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 0, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2]]) == 6\n assert candidate(grid = [[2, 0, 2, 0, 2, 0, 2], [0, 1, 0, 1, 0, 1, 0], [2, 0, 1, 0, 1, 0, 2], [0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 11\n assert candidate(grid = [[0, 2, 1, 2, 0], [2, 1, 0, 1, 2], [1, 0, 0, 0, 1], [0, 1, 1, 1, 0], [2, 0, 1, 0, 2]]) == 14\n assert candidate(grid = [[2, 2, 2, 2, 2], [2, 1, 1, 1, 2], [2, 1, 0, 1, 2], [2, 1, 1, 1, 2], [2, 2, 2, 2, 2]]) == 9\n assert candidate(grid = [[1, 1, 2, 1, 1], [1, 0, 0, 0, 1], [2, 0, 1, 0, 2], [2, 0, 1, 0, 2], [2, 2, 2, 2, 2]]) == 12\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 1], [1, 2, 0, 0, 0, 2, 1], [1, 2, 0, 1, 0, 2, 1], [1, 2, 0, 0, 0, 2, 1], [1, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]]) == 25\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 2, 1], [1, 2, 1, 0, 1, 2, 1], [1, 2, 1, 1, 1, 2, 1], [1, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]]) == 20\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == 9\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]]) == 10\n assert candidate(grid = [[2, 0, 1, 0, 2], [0, 0, 2, 0, 0], [1, 2, 1, 2, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) == 11\n assert candidate(grid = [[2, 0, 2, 0, 2], [0, 1, 0, 1, 0], [2, 0, 2, 0, 2], [0, 1, 0, 1, 0], [2, 0, 2, 0, 2]]) == 10\n assert candidate(grid = [[2, 0, 0, 0, 2], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 2, 0, 0]]) == 7\n assert candidate(grid = [[2, 2, 1, 1, 2], [2, 2, 1, 1, 2], [1, 1, 2, 1, 1], [2, 1, 2, 1, 2], [2, 2, 1, 1, 2]]) == 10\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 11\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1]]) == 6\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 2, 2, 2, 2, 2, 1, 2], [2, 1, 2, 1, 1, 1, 2, 1, 2], [2, 1, 2, 1, 0, 1, 2, 1, 2], [2, 1, 2, 1, 1, 1, 2, 1, 2], [2, 1, 2, 2, 2, 2, 2, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2]]) == 33\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 2, 2, 2, 1, 0], [0, 1, 2, 1, 2, 1, 0], [0, 1, 2, 2, 2, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 24\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 1, 1, 1, 1, 1, 1, 1, 2, 0], [0, 2, 2, 1, 1, 1, 1, 1, 2, 2, 0], [0, 2, 2, 2, 1, 1, 1, 2, 2, 2, 0], [0, 2, 2, 2, 2, 1, 2, 2, 2, 2, 0], [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0], [0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0], [0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 51\n assert candidate(grid = [[2, 0, 1, 0, 2], [0, 1, 0, 1, 0], [1, 0, 2, 0, 1], [0, 1, 0, 1, 0], [2, 0, 1, 0, 2]]) == 11\n assert candidate(grid = [[0, 2, 1, 2, 0], [1, 1, 0, 1, 1], [2, 0, 2, 0, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2]]) == 11\n assert candidate(grid = [[2, 0, 2, 0, 2], [0, 2, 0, 2, 0], [2, 0, 2, 0, 2], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[0, 1, 2, 1, 0], [1, 2, 1, 2, 1], [2, 1, 0, 1, 2], [2, 1, 0, 1, 2], [2, 1, 0, 1, 2]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 2, 1, 1, 1, 1, 1, 1, 1, 2, 0], [0, 2, 1, 0, 0, 0, 0, 0, 1, 2, 0], [0, 2, 1, 0, 0, 0, 0, 0, 1, 2, 0], [0, 2, 1, 0, 0, 0, 0, 0, 1, 2, 0], [0, 2, 1, 0, 0, 0, 0, 0, 1, 2, 0], [0, 2, 1, 0, 0, 0, 0, 0, 1, 2, 0], [0, 2, 1, 1, 1, 1, 1, 1, 1, 2, 0], [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 63\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0]]) == 8\n assert candidate(grid = [[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]]) == 8\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 2, 1, 0], [1, 2, 0, 2, 1], [2, 2, 2, 2, 2], [0, 0, 2, 0, 0]]) == 15\n assert candidate(grid = [[2, 1, 1, 1, 1, 1, 2], [1, 2, 1, 1, 1, 2, 1], [1, 1, 2, 1, 2, 1, 1], [1, 1, 1, 2, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1]]) == 3\n assert candidate(grid = [[1, 1, 2, 1, 1], [1, 2, 2, 2, 1], [1, 2, 0, 2, 1], [0, 2, 0, 2, 0], [0, 0, 0, 0, 0]]) == 16\n assert candidate(grid = [[2, 0, 0, 0, 2, 0, 0, 0, 2], [0, 1, 0, 0, 1, 0, 0, 1, 0], [0, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 2, 2, 2, 0, 0, 0], [0, 0, 0, 2, 2, 2, 0, 0, 0], [0, 0, 0, 2, 2, 2, 0, 0, 0], [0, 0, 0, 2, 2, 2, 0, 0, 0], [0, 0, 1, 0, 2, 0, 1, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1, 0]]) == 17\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 0, 0, 0, 0, 0, 1, 2], [2, 1, 0, 2, 2, 2, 0, 1, 2], [2, 1, 0, 2, 1, 2, 0, 1, 2], [2, 1, 0, 2, 2, 2, 0, 1, 2], [2, 1, 0, 0, 0, 0, 0, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2]]) == 43\n assert candidate(grid = [[2, 0, 1, 0, 2], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [2, 0, 1, 0, 2]]) == 12\n assert candidate(grid = [[2, 1, 0, 1, 2], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [2, 1, 0, 1, 2]]) == 13\n assert candidate(grid = [[1, 2, 2, 1, 1], [2, 1, 2, 1, 2], [1, 2, 2, 1, 1], [1, 2, 1, 1, 1], [1, 1, 1, 1, 1]]) == 12\n assert candidate(grid = [[1, 1, 2, 2, 1], [1, 1, 1, 2, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) == 10\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 2, 2, 2, 2, 2, 1, 2], [2, 1, 2, 1, 1, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 1, 1, 2, 1, 2], [2, 1, 2, 2, 2, 2, 2, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2]]) == 33\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1]]) == 9\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 2, 2, 2, 0, 1], [1, 0, 2, 1, 2, 0, 1], [1, 0, 2, 2, 2, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == 25\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, 0, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2]]) == 9\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 2, 1, 2, 1, 2, 1, 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, 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, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2]]) == 13\n assert candidate(grid = [[1, 2, 0, 2, 0, 2, 1], [2, 0, 0, 0, 0, 0, 2], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 2, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 17\n assert candidate(grid = [[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], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 26\n assert candidate(grid = [[1, 2, 1, 2, 1], [2, 1, 0, 1, 2], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 2, 1, 2, 1]]) == 13\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2], [2, 0, 0, 0, 0, 0, 2], [2, 0, 1, 1, 1, 0, 2], [2, 0, 1, 0, 1, 0, 2], [2, 0, 1, 1, 1, 0, 2], [2, 0, 0, 0, 0, 0, 2], [2, 2, 2, 2, 2, 2, 2]]) == 24\n assert candidate(grid = [[2, 1, 0, 1, 2], [1, 0, 1, 0, 1], [0, 1, 2, 1, 0], [0, 1, 1, 0, 0], [0, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[0, 1, 2, 1, 0], [1, 0, 2, 0, 1], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 1, 2, 2, 2]]) == 8\n assert candidate(grid = [[1, 2, 1, 2, 1], [2, 1, 2, 1, 2], [1, 2, 1, 2, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 11\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, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1]]) == 9\n assert candidate(grid = [[2, 0, 1, 0, 2, 0, 2], [0, 2, 0, 2, 0, 2, 0], [1, 0, 1, 0, 1, 0, 1], [0, 2, 0, 2, 0, 2, 0], [2, 0, 2, 2, 2, 0, 2], [0, 2, 0, 2, 0, 2, 0], [2, 0, 2, 0, 2, 0, 2]]) == 20\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]]) == 10\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 2, 1], [1, 2, 1, 0, 1, 2, 1], [1, 2, 1, 1, 1, 2, 1], [1, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]]) == 20\n assert candidate(grid = [[0, 1, 2, 1, 0, 1, 2], [1, 0, 1, 0, 1, 0, 1], [2, 1, 0, 1, 2, 1, 0], [1, 0, 1, 2, 1, 0, 1], [0, 1, 2, 1, 0, 1, 2], [1, 0, 1, 0, 1, 0, 1], [2, 1, 0, 1, 2, 1, 0]]) == 22\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 1, 2, 2, 2], [2, 2, 1, 0, 1, 2, 2], [2, 1, 0, 0, 0, 1, 2], [2, 0, 0, 0, 0, 0, 2], [2, 0, 0, 0, 0, 0, 2]]) == 21\n", "comparison": "exact"}, "public_tests": ["[[1,2,2],[1,1,0],[0,1,0]]", "[[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]]"], "hints": [], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumOperationsToWriteY", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:11:58+00:00", "tests_total": 76, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "matrix", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations_to_write_y(grid)", "container": null, "callable": "minimum_operations_to_write_y", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3072, "task_id": "distribute-elements-into-two-arrays-ii", "difficulty": "Hard", "problem_description": "You are given a 1-indexed array of integers nums of length n.\n\nWe define a function greaterCount such that greaterCount(arr, val) returns the number of elements in arr that are strictly greater than val.\n\nYou need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the i^th operation:\n\n- If greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i]), append nums[i] to arr1.\n- If greaterCount(arr1, nums[i]) < greaterCount(arr2, nums[i]), append nums[i] to arr2.\n- If greaterCount(arr1, nums[i]) == greaterCount(arr2, nums[i]), append nums[i] to the array with a lesser number of elements.\n- If there is still a tie, append nums[i] to arr1.\n\nThe array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6].\n\nReturn the integer array result.\n\nExample 1:\n\nInput: nums = [2,1,3,3]\nOutput: [2,3,1,3]\nExplanation: After the first 2 operations, arr1 = [2] and arr2 = [1].\nIn the 3^rd operation, the number of elements greater than 3 is zero in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1.\nIn the 4^th operation, the number of elements greater than 3 is zero in both arrays. As the length of arr2 is lesser, hence, append nums[4] to arr2.\nAfter 4 operations, arr1 = [2,3] and arr2 = [1,3].\nHence, the array result formed by concatenation is [2,3,1,3].\n\nExample 2:\n\nInput: nums = [5,14,3,1,2]\nOutput: [5,3,1,2,14]\nExplanation: After the first 2 operations, arr1 = [5] and arr2 = [14].\nIn the 3^rd operation, the number of elements greater than 3 is one in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1.\nIn the 4^th operation, the number of elements greater than 1 is greater in arr1 than arr2 (2 > 1). Hence, append nums[4] to arr1.\nIn the 5^th operation, the number of elements greater than 2 is greater in arr1 than arr2 (2 > 1). Hence, append nums[5] to arr1.\nAfter 5 operations, arr1 = [5,3,1,2] and arr2 = [14].\nHence, the array result formed by concatenation is [5,3,1,2,14].\n\nExample 3:\n\nInput: nums = [3,3,3,3]\nOutput: [3,3,3,3]\nExplanation: At the end of 4 operations, arr1 = [3,3] and arr2 = [3,3].\nHence, the array result formed by concatenation is [3,3,3,3].\n\nConstraints:\n\n- 3 <= n <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 2, 1, 5, 4, 9, 8, 7, 6, 10]) == [3, 1, 9, 8, 7, 6, 2, 5, 4, 10]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [100, 80, 70, 60, 50, 40, 30, 20, 10, 90]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]\n assert candidate(nums = [7, 10, 4, 3, 20, 15]) == [7, 4, 3, 10, 20, 15]\n assert candidate(nums = [10, 5, 20, 15, 25, 30]) == [10, 20, 15, 5, 25, 30]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == [1000000000, 1000000000, 1, 1, 1000000000, 1, 1, 1000000000, 1000000000, 1]\n assert candidate(nums = [5, 14, 3, 1, 2]) == [5, 3, 1, 2, 14]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10]) == [9, 8, 2, 7, 3, 6, 4, 5, 1, 10]\n assert candidate(nums = [2, 1, 3, 3]) == [2, 3, 1, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 8, 7, 6, 5, 4, 3, 2, 1, 9]\n assert candidate(nums = [3, 3, 3, 3]) == [3, 3, 3, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]\n assert candidate(nums = [1, 3, 2, 6, 5, 4, 9, 8, 7, 10, 13, 12, 11, 15, 14, 17, 16, 19, 18, 20, 21, 22, 23, 24, 25]) == [1, 6, 5, 4, 10, 13, 12, 11, 19, 18, 21, 23, 25, 3, 2, 9, 8, 7, 15, 14, 17, 16, 20, 22, 24]\n assert candidate(nums = [1000000000, 1, 1000000000, 2, 1000000000, 3, 1000000000, 4, 1000000000]) == [1000000000, 1000000000, 2, 3, 1000000000, 1, 1000000000, 1000000000, 4]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16]) == [15, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 14, 20, 19, 18, 17, 16]\n assert candidate(nums = [50, 25, 75, 12, 37, 62, 88, 43, 59, 100, 20, 90, 30, 80, 40, 70, 60, 50, 10, 95]) == [50, 75, 12, 37, 62, 43, 59, 20, 30, 40, 10, 25, 88, 100, 90, 80, 70, 60, 50, 95]\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993, 9, 999999992, 10, 999999991]) == [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993, 9, 999999992, 10, 999999991]\n assert candidate(nums = [20, 10, 30, 5, 25, 15, 35, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38, 39, 40]) == [20, 30, 5, 25, 15, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24, 10, 35, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38, 39, 40]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [20, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 19]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == [5, 3, 2, 1, 9, 4, 6, 7, 8, 10, 1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 45, 50, 55, 5, 60, 65, 70]) == [10, 25, 30, 5, 45, 55, 60, 70, 20, 15, 35, 40, 50, 5, 65]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == [1, 3, 2, 1, 3, 2, 1, 2, 3, 2, 1, 3]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == [1, 1, 1, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3, 3]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [15, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 14]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [15, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 14]\n assert candidate(nums = [5, 3, 8, 6, 7, 2, 4, 1, 9, 10]) == [5, 8, 6, 7, 2, 4, 1, 3, 9, 10]\n assert candidate(nums = [100, 99, 101, 98, 102, 97, 103, 96, 104, 95, 105, 94, 106, 93, 107]) == [100, 101, 98, 97, 96, 95, 94, 93, 99, 102, 103, 104, 105, 106, 107]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\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]) == [25, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 24]\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1000000000, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10]) == [5, 9, 2, 8, 3, 7, 4, 6, 1, 10]\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, 23, 22, 25, 24]) == [1, 5, 4, 9, 8, 13, 12, 17, 16, 21, 20, 25, 24, 3, 2, 7, 6, 11, 10, 15, 14, 19, 18, 23, 22]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == [5, 7, 9, 1, 3, 6, 8, 10, 2, 4, 6, 8, 10, 2, 4, 5, 7, 9, 1, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2]\n assert candidate(nums = [109, 108, 107, 106, 105, 104, 103, 102, 101, 100]) == [109, 107, 106, 105, 104, 103, 102, 101, 100, 108]\n assert candidate(nums = [2, 3, 1, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == [2, 1, 7, 6, 11, 10, 15, 14, 19, 18, 3, 5, 4, 9, 8, 13, 12, 17, 16, 20]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == [3, 2, 1, 3, 1, 2, 1, 3, 2, 3]\n assert candidate(nums = [10, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 20]) == [10, 11, 2, 3, 14, 5, 16, 7, 18, 9, 1, 12, 13, 4, 15, 6, 17, 8, 19, 20]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 30, 50, 70, 90, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 40, 60, 80, 100]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == [10, 20, 2, 3, 50, 5, 1, 30, 40, 4]\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [1, 5, 9, 4, 8, 3, 7, 2, 6, 10]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == [1000000000, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999999]\n assert candidate(nums = [5, 10, 15, 20, 25, 1, 6, 11, 16, 21, 3, 8, 13, 18, 23, 4, 9, 14, 19, 24, 7, 12, 17, 22, 26]) == [5, 15, 25, 1, 11, 21, 3, 8, 13, 18, 23, 4, 9, 14, 19, 24, 7, 12, 17, 22, 10, 20, 6, 16, 26]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == [1000000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 500000000]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]\n assert candidate(nums = [7, 10, 5, 8, 3, 6, 9, 2, 1, 4]) == [7, 5, 3, 10, 8, 6, 9, 2, 1, 4]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == [100, 102, 104, 106, 108, 101, 103, 105, 107, 109]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]\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]) == [100, 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, 99]\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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10, 11, 12, 13, 14, 15]) == [9, 8, 2, 7, 3, 6, 4, 5, 1, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [10, 8, 7, 6, 5, 4, 3, 2, 1, 19, 9, 11, 12, 13, 14, 15, 16, 17, 18, 20]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10]) == [5, 8, 6, 2, 7, 4, 1, 3, 9, 10]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == [5, 3, 2, 1, 9, 4, 6, 7, 8, 10]\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]) == [25, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 24]\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]\n assert candidate(nums = [5, 2, 7, 1, 8, 3, 6, 4, 9, 10, 1, 1, 1, 1, 1]) == [5, 7, 1, 3, 9, 2, 8, 6, 4, 10, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == [1, 5, 4, 9, 8, 13, 12, 3, 2, 7, 6, 11, 10, 15, 14]\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == [2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == [1, 3, 2, 1, 3, 2, 1, 3, 2, 1]\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]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]) == [1, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16, 10, 2, 9, 3, 8, 4, 7, 5, 6]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 8, 7, 6, 5, 4, 3, 2, 1, 9]\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == [1, 3, 2, 1, 3, 2, 1, 3, 2, 3, 2, 1, 3, 2, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 21, 22, 23, 24, 25]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 3, 5, 7, 9, 2, 4, 6, 8]\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 55, 45, 35, 25, 15]) == [10, 30, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 25, 15, 20, 40, 55, 45, 35]\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 2, 1, 3, 18, 19, 21, 22, 23, 24, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [10, 25, 30, 5, 2, 1, 3, 18, 19, 21, 22, 23, 24, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 15]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == [1, 5, 4, 9, 8, 13, 12, 3, 2, 7, 6, 11, 10, 15, 14]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 1, 2, 2, 3, 4, 4, 5]\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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [7, 3, 15, 10, 12, 1, 13, 5, 8, 2, 14, 9, 6, 11, 4]) == [7, 15, 10, 12, 1, 13, 5, 8, 2, 14, 9, 6, 11, 4, 3]\n assert candidate(nums = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10]) == [5, 9, 2, 8, 3, 7, 4, 6, 1, 10]\n assert candidate(nums = [1, 2, 3, 10, 9, 8, 7, 6, 5, 4]) == [1, 3, 2, 10, 9, 8, 7, 6, 5, 4]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [9, 7, 6, 5, 4, 3, 2, 1, 8]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5]) == [9, 8, 2, 7, 3, 6, 4, 5, 1]\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, 3, 5, 7, 9, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 110, 120, 130, 140, 150, 5, 15, 25, 35, 45]) == [100, 80, 70, 60, 50, 40, 30, 20, 10, 5, 15, 25, 90, 110, 120, 130, 140, 150, 35, 45]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [1, 5, 9, 13, 17, 4, 8, 12, 16, 20, 3, 7, 11, 15, 19, 2, 6, 10, 14, 18]\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1000000000, 2, 3, 4, 5, 6, 7, 8, 9, 1]\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 3]) == [1, 1, 2, 3, 3, 1, 2, 2, 3, 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, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\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, 3, 5, 2, 4, 1, 3, 5, 2, 4, 2, 4, 1, 3, 5, 2, 4, 1, 3, 5]\n assert candidate(nums = [10, 20, 15, 10, 5, 25, 30, 5, 15, 25]) == [10, 25, 30, 5, 15, 25, 20, 15, 10, 5]\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1000000000, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == [1, 5, 4, 9, 8, 13, 12, 17, 16, 20, 3, 2, 7, 6, 11, 10, 15, 14, 19, 18]\n assert candidate(nums = [50, 20, 30, 10, 40, 1, 2, 3, 4, 5]) == [50, 30, 10, 40, 1, 2, 3, 4, 5, 20]\n assert candidate(nums = [50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155]) == [50, 30, 20, 10, 15, 25, 45, 105, 125, 145, 40, 35, 55, 65, 75, 85, 95, 115, 135, 155]\n assert candidate(nums = [25, 25, 25, 25, 25, 50, 50, 50, 50, 50, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100]) == [25, 25, 25, 50, 50, 75, 75, 75, 100, 100, 25, 25, 50, 50, 50, 75, 75, 100, 100, 100]\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, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]\n", "comparison": "exact"}, "public_tests": ["[2,1,3,3]", "[5,14,3,1,2]", "[3,3,3,3]"], "hints": ["We need a data structure that counts the number of integers greater than a given value x and supports insertion.", "Use Segment Tree or Binary Indexed Tree by compressing the numbers to the range [1,n]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().resultArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:01+00:00", "tests_total": 106, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-indexed-tree", "segment-tree", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def result_array(nums)", "container": null, "callable": "result_array", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3074, "task_id": "apple-redistribution-into-boxes", "difficulty": "Easy", "problem_description": "You are given an array apple of size n and an array capacity of size m.\n\nThere are n packs where the i^th pack contains apple[i] apples. There are m boxes as well, and the i^th box has a capacity of capacity[i] apples.\n\nReturn the minimum number of boxes you need to select to redistribute these n packs of apples into boxes.\n\nNote that, apples from the same pack can be distributed into different boxes.\n\nExample 1:\n\nInput: apple = [1,3,2], capacity = [4,3,1,5,2]\nOutput: 2\nExplanation: We will use boxes with capacities 4 and 5.\nIt is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples.\n\nExample 2:\n\nInput: apple = [5,5,5], capacity = [2,4,2,7]\nOutput: 4\nExplanation: We will need to use all the boxes.\n\nConstraints:\n\n- 1 <= n == apple.length <= 50\n- 1 <= m == capacity.length <= 50\n- 1 <= apple[i], capacity[i] <= 50\n- The input is generated such that it's possible to redistribute packs of apples into boxes.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(apple = [10, 20, 30],capacity = [15, 10, 25]) == None\n assert candidate(apple = [10, 20, 30, 40],capacity = [10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [45, 5],capacity = [50]) == 1\n assert candidate(apple = [1, 1, 1, 1, 1],capacity = [1, 1, 1, 1, 1, 1]) == 5\n assert candidate(apple = [10, 20, 30],capacity = [5, 15, 10, 20]) == None\n assert candidate(apple = [2, 2, 2, 2],capacity = [1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(apple = [1, 1, 1, 1],capacity = [1, 1, 1, 1, 1]) == 4\n assert candidate(apple = [2, 2, 2, 2, 2],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(apple = [1, 1, 1, 1, 1],capacity = [1, 1, 1, 1, 1]) == 5\n assert candidate(apple = [40, 10, 10],capacity = [20, 20, 20]) == 3\n assert candidate(apple = [25, 25],capacity = [30, 20]) == 2\n assert candidate(apple = [1, 1, 1, 1],capacity = [1, 1, 1, 1, 1, 1]) == 4\n assert candidate(apple = [5, 5, 5],capacity = [2, 4, 2, 7]) == 4\n assert candidate(apple = [45, 3, 2],capacity = [50, 1, 1, 1]) == 1\n assert candidate(apple = [15, 15, 15],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(apple = [3, 5, 7, 9],capacity = [2, 4, 6, 8, 10]) == 3\n assert candidate(apple = [10, 20, 30],capacity = [5, 10, 15, 25]) == None\n assert candidate(apple = [1, 3, 2],capacity = [4, 3, 1, 5, 2]) == 2\n assert candidate(apple = [50],capacity = [50]) == 1\n assert candidate(apple = [10, 20, 30],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == None\n assert candidate(apple = [25, 25, 25, 25, 25],capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [48, 48, 48],capacity = [16, 16, 16, 16, 16, 16]) == None\n assert candidate(apple = [25, 25, 25],capacity = [10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [49, 1, 1],capacity = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == 3\n assert candidate(apple = [15, 20, 5],capacity = [12, 18, 9, 7]) == 4\n assert candidate(apple = [1, 2, 3, 4, 5],capacity = [2, 3, 4, 5, 6]) == 3\n assert candidate(apple = [25, 25, 25, 25, 25],capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 13\n assert candidate(apple = [50, 40, 30, 20, 10],capacity = [10, 20, 30, 40, 50]) == 5\n assert candidate(apple = [48, 1, 1],capacity = [24, 24, 1, 1, 1]) == 4\n assert candidate(apple = [25, 25, 25, 25],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == None\n assert candidate(apple = [40, 30, 20, 10],capacity = [50, 20, 10, 10, 10]) == 5\n assert candidate(apple = [15, 25, 35],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == None\n assert candidate(apple = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(apple = [15, 25, 35, 45],capacity = [10, 20, 30, 40, 50]) == 3\n assert candidate(apple = [30, 20, 10, 40],capacity = [10, 15, 5, 25, 30, 5]) == None\n assert candidate(apple = [50, 50, 50],capacity = [16, 17, 18, 19, 20]) == None\n assert candidate(apple = [2, 3, 5, 7, 11, 13],capacity = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 2\n assert candidate(apple = [10, 20, 30, 40],capacity = [10, 20, 30, 40, 50]) == 3\n assert candidate(apple = [30, 10, 5],capacity = [15, 10, 10, 5, 5]) == 5\n assert candidate(apple = [3, 6, 9, 12],capacity = [2, 4, 6, 8, 10, 12, 14]) == 3\n assert candidate(apple = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = [5, 10, 15, 20, 25]) == 3\n assert candidate(apple = [25, 25, 25],capacity = [20, 15, 30, 10, 25]) == 3\n assert candidate(apple = [45, 35, 25],capacity = [20, 15, 10, 5, 5, 5]) == None\n assert candidate(apple = [49, 49, 49],capacity = [50, 50, 50, 50, 50, 50]) == 3\n assert candidate(apple = [30, 30, 30],capacity = [25, 25, 25, 25]) == 4\n assert candidate(apple = [10, 20, 30, 40],capacity = [15, 25, 35, 5, 5, 5]) == None\n assert candidate(apple = [10, 20, 30, 40, 50],capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [10, 20, 30],capacity = [5, 15, 10, 25]) == None\n assert candidate(apple = [45, 45, 5],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == None\n assert candidate(apple = [40, 30, 20, 10],capacity = [15, 15, 15, 15, 15, 15]) == None\n assert candidate(apple = [30, 20, 10],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == None\n assert candidate(apple = [25, 25, 25],capacity = [10, 10, 10, 10, 10, 10, 10, 10]) == 8\n assert candidate(apple = [15, 15, 15, 15],capacity = [10, 10, 10, 10, 10]) == None\n assert candidate(apple = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == None\n assert candidate(apple = [50, 40, 30, 20, 10],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == None\n assert candidate(apple = [3, 6, 9, 12, 15],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(apple = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],capacity = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4\n assert candidate(apple = [2, 3, 5, 7, 11],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(apple = [45, 5, 3, 7],capacity = [12, 8, 15, 10, 2]) == None\n assert candidate(apple = [49, 1],capacity = [50]) == 1\n assert candidate(apple = [5, 5, 5, 5, 5, 5, 5],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 35\n assert candidate(apple = [10, 10, 10],capacity = [5, 5, 5, 5, 5, 5]) == 6\n assert candidate(apple = [50, 45, 40],capacity = [10, 20, 15, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == None\n assert candidate(apple = [1, 1, 2, 2, 3, 3, 4, 4],capacity = [1, 2, 3, 4, 5, 6, 7, 8]) == 3\n assert candidate(apple = [1, 2, 3, 4, 5, 6],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(apple = [7, 8, 9],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 3\n assert candidate(apple = [49, 49, 49, 49, 49],capacity = [50, 50, 50, 50, 50]) == 5\n assert candidate(apple = [10, 20, 30, 40, 50],capacity = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 4\n assert candidate(apple = [9, 11, 13, 17],capacity = [8, 15, 7, 10, 6, 12]) == 5\n assert candidate(apple = [48, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 18\n assert candidate(apple = [49, 1],capacity = [25, 24, 1]) == 3\n assert candidate(apple = [40, 30, 20],capacity = [10, 10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [20, 20, 10, 10],capacity = [15, 15, 15, 15, 15]) == 4\n assert candidate(apple = [25, 25, 25],capacity = [50, 50]) == 2\n assert candidate(apple = [45, 2, 3],capacity = [10, 10, 10, 10, 10]) == 5\n assert candidate(apple = [10, 20, 30],capacity = [5, 15, 25, 10]) == None\n assert candidate(apple = [10, 20, 30],capacity = [5, 15, 20, 10]) == None\n assert candidate(apple = [3, 7, 2, 8],capacity = [5, 10, 3, 6, 1]) == 3\n assert candidate(apple = [25, 25, 25, 25],capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(apple = [40, 40, 40, 40],capacity = [20, 20, 20, 20, 20, 20, 20, 20]) == 8\n assert candidate(apple = [10, 20, 30, 40],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 20\n assert candidate(apple = [49, 49, 49],capacity = [16, 16, 16, 16, 16, 16]) == None\n assert candidate(apple = [50, 50, 50, 50, 50],capacity = [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]) == 6\n assert candidate(apple = [15, 25, 10, 5],capacity = [10, 20, 5, 5, 5, 5]) == None\n assert candidate(apple = [23, 17, 15, 12],capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 7\n assert candidate(apple = [5, 10, 15, 20, 25],capacity = [30, 20, 10, 5, 1, 1, 1, 1]) == None\n assert candidate(apple = [4, 4, 4, 4, 4],capacity = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 7\n assert candidate(apple = [45, 3, 2, 1],capacity = [40, 5, 3, 2, 1, 1, 1, 1, 1]) == 5\n assert candidate(apple = [45, 5, 5],capacity = [25, 20, 5, 5, 5, 5]) == 4\n assert candidate(apple = [10, 10, 10, 10, 10],capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(apple = [1, 2, 3, 4, 5],capacity = [15, 10, 5]) == 1\n assert candidate(apple = [3, 3, 3, 3, 3, 3],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 18\n assert candidate(apple = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == None\n assert candidate(apple = [10, 20, 30, 40],capacity = [20, 20, 20, 20, 20]) == 5\n assert candidate(apple = [1, 2, 3, 4, 5],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == None\n assert candidate(apple = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(apple = [45, 3, 2],capacity = [50, 25, 10, 5]) == 1\n assert candidate(apple = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = [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]) == 11\n assert candidate(apple = [45, 45, 45],capacity = [15, 15, 15, 15, 15, 15]) == None\n assert candidate(apple = [10, 20, 30],capacity = [5, 15, 10, 20, 25]) == 3\n assert candidate(apple = [50, 50, 50],capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [45, 30, 10, 5],capacity = [20, 15, 10, 5, 1]) == None\n assert candidate(apple = [10, 20, 30],capacity = [5, 15, 25, 35]) == 2\n assert candidate(apple = [8, 16, 24, 32],capacity = [4, 8, 12, 16, 20, 24, 28, 32]) == 3\n assert candidate(apple = [45, 30, 15],capacity = [10, 10, 10, 10, 10, 10]) == None\n assert candidate(apple = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 30\n assert candidate(apple = [40, 10, 10],capacity = [20, 20, 20, 20, 20, 20]) == 3\n assert candidate(apple = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(apple = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(apple = [10, 20, 30, 40],capacity = [5, 10, 15, 20, 25, 30]) == 5\n", "comparison": "exact"}, "public_tests": ["[1,3,2]\n[4,3,1,5,2]", "[5,5,5]\n[2,4,2,7]"], "hints": ["Sort array capacity in non-decreasing order.", "Greedily select boxes with the largest capacities to redistribute apples optimally."], "metadata": {"canonical_parameter_names": ["apple", "capacity"], "leetcode_dataset_entry_point": "Solution().minimumBoxes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:06+00:00", "tests_total": 115, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_boxes(apple, capacity)", "container": null, "callable": "minimum_boxes", "parameters": [{"name": "apple", "type": "Integer[]"}, {"name": "capacity", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3075, "task_id": "maximize-happiness-of-selected-children", "difficulty": "Medium", "problem_description": "You are given an array happiness of length n, and a positive integer k.\n\nThere are n children standing in a queue, where the i^th child has happiness value happiness[i]. You want to select k children from these n children in k turns.\n\nIn each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive.\n\nReturn the maximum sum of the happiness values of the selected children you can achieve by selecting k children.\n\nExample 1:\n\nInput: happiness = [1,2,3], k = 2\nOutput: 4\nExplanation: We can pick 2 children in the following way:\n- Pick the child with the happiness value == 3. The happiness value of the remaining children becomes [0,1].\n- Pick the child with the happiness value == 1. The happiness value of the remaining child becomes [0]. Note that the happiness value cannot become less than 0.\nThe sum of the happiness values of the selected children is 3 + 1 = 4.\n\nExample 2:\n\nInput: happiness = [1,1,1,1], k = 2\nOutput: 1\nExplanation: We can pick 2 children in the following way:\n- Pick any child with the happiness value == 1. The happiness value of the remaining children becomes [0,0,0].\n- Pick the child with the happiness value == 0. The happiness value of the remaining child becomes [0,0].\nThe sum of the happiness values of the selected children is 1 + 0 = 1.\n\nExample 3:\n\nInput: happiness = [2,3,4,5], k = 1\nOutput: 5\nExplanation: We can pick 1 child in the following way:\n- Pick the child with the happiness value == 5. The happiness value of the remaining children becomes [1,2,3].\nThe sum of the happiness values of the selected children is 5.\n\nConstraints:\n\n- 1 <= n == happiness.length <= 2 * 10^5\n- 1 <= happiness[i] <= 10^8\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(happiness = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 30\n assert candidate(happiness = [10, 20, 30, 40, 50],k = 5) == 140\n assert candidate(happiness = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(happiness = [100000000, 100000000, 100000000],k = 2) == 199999999\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 30\n assert candidate(happiness = [1],k = 1) == 1\n assert candidate(happiness = [100000000, 100000000, 100000000, 100000000],k = 2) == 199999999\n assert candidate(happiness = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 25\n assert candidate(happiness = [10, 9, 8, 7, 6],k = 3) == 24\n assert candidate(happiness = [100, 100, 100],k = 1) == 100\n assert candidate(happiness = [1, 1, 1, 1],k = 2) == 1\n assert candidate(happiness = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 5) == 12\n assert candidate(happiness = [1, 2, 3],k = 2) == 4\n assert candidate(happiness = [2, 3, 4, 5],k = 1) == 5\n assert candidate(happiness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(happiness = [5, 4, 3, 2, 1],k = 3) == 9\n assert candidate(happiness = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 12\n assert candidate(happiness = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 5) == 40\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 24\n assert candidate(happiness = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 10) == 15\n assert candidate(happiness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 334\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 12) == 110\n assert candidate(happiness = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 15) == 15\n assert candidate(happiness = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 18) == 55\n assert candidate(happiness = [10, 20, 30, 40, 50],k = 3) == 117\n assert candidate(happiness = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],k = 7) == 24\n assert candidate(happiness = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000],k = 10) == 549999955\n assert candidate(happiness = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 10) == 5455\n assert candidate(happiness = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 40\n assert candidate(happiness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 7) == 1\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 110\n assert candidate(happiness = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 3\n assert candidate(happiness = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81],k = 10) == 910\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 8) == 492\n assert candidate(happiness = [1, 100000000, 1, 100000000, 1, 100000000, 1, 100000000, 1, 100000000],k = 5) == 499999990\n assert candidate(happiness = [98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79],k = 15) == 1260\n assert candidate(happiness = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 15) == 273\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 10\n assert candidate(happiness = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 6) == 30\n assert candidate(happiness = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 8) == 156\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 63\n assert candidate(happiness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 1\n assert candidate(happiness = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 15) == 9995\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 63\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 20) == 110\n assert candidate(happiness = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000],k = 5) == 399999990\n assert candidate(happiness = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 10) == 465\n assert candidate(happiness = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 10) == 910\n assert candidate(happiness = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 30\n assert candidate(happiness = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 40\n assert candidate(happiness = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 3990\n assert candidate(happiness = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 3) == 132\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 30\n assert candidate(happiness = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 15) == 256\n assert candidate(happiness = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 4) == 34\n assert candidate(happiness = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10],k = 15) == 43\n assert candidate(happiness = [5, 4, 3, 2, 1],k = 3) == 9\n assert candidate(happiness = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 15) == 55\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 390\n assert candidate(happiness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(happiness = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 6) == 20\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 64\n assert candidate(happiness = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 3\n assert candidate(happiness = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 25\n assert candidate(happiness = [100, 50, 10, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 159\n assert candidate(happiness = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 8) == 772\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 15) == 1845\n assert candidate(happiness = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 15\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 390\n assert candidate(happiness = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 8) == 40\n assert candidate(happiness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 20) == 1\n assert candidate(happiness = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 9) == 9864\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 30\n assert candidate(happiness = [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 = 20) == 240\n assert candidate(happiness = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 5) == 12\n assert candidate(happiness = [5, 15, 25, 35, 45, 55, 65],k = 4) == 194\n assert candidate(happiness = [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 = 15) == 240\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 110\n assert candidate(happiness = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 30\n assert candidate(happiness = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10],k = 6) == 30\n assert candidate(happiness = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],k = 8) == 64\n assert candidate(happiness = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],k = 10) == 14\n assert candidate(happiness = [100000000, 90000000, 80000000, 70000000, 60000000],k = 3) == 269999997\n assert candidate(happiness = [5, 15, 25, 35, 45, 55],k = 4) == 154\n assert candidate(happiness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 30\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 505\n assert candidate(happiness = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 10) == 255\n assert candidate(happiness = [5, 3, 8, 6, 2, 7, 4, 1, 9],k = 4) == 24\n assert candidate(happiness = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 15) == 15\n assert candidate(happiness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 267\n assert candidate(happiness = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11],k = 5) == 35\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n2", "[1,1,1,1]\n2", "[2,3,4,5]\n1"], "hints": ["Since all the unselected numbers are decreasing at the same rate, we should greedily select k largest values.", "The ith largest number (i = 1, 2, 3,…k) should decrease by (i - 1) when it is picked.", "Add 0 if the decreased value is negative."], "metadata": {"canonical_parameter_names": ["happiness", "k"], "leetcode_dataset_entry_point": "Solution().maximumHappinessSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:09+00:00", "tests_total": 100, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_happiness_sum(happiness, k)", "container": null, "callable": "maximum_happiness_sum", "parameters": [{"name": "happiness", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3076, "task_id": "shortest-uncommon-substring-in-an-array", "difficulty": "Medium", "problem_description": "You are given an array arr of size n consisting of non-empty strings.\n\nFind a string array answer of size n such that:\n\n- answer[i] is the shortest substring of arr[i] that does not occur as a substring in any other string in arr. If multiple such substrings exist, answer[i] should be the lexicographically smallest. And if no such substring exists, answer[i] should be an empty string.\n\nReturn the array answer.\n\nExample 1:\n\nInput: arr = [\"cab\",\"ad\",\"bad\",\"c\"]\nOutput: [\"ab\",\"\",\"ba\",\"\"]\nExplanation: We have the following:\n- For the string \"cab\", the shortest substring that does not occur in any other string is either \"ca\" or \"ab\", we choose the lexicographically smaller substring, which is \"ab\".\n- For the string \"ad\", there is no substring that does not occur in any other string.\n- For the string \"bad\", the shortest substring that does not occur in any other string is \"ba\".\n- For the string \"c\", there is no substring that does not occur in any other string.\n\nExample 2:\n\nInput: arr = [\"abc\",\"bcd\",\"abcd\"]\nOutput: [\"\",\"\",\"abcd\"]\nExplanation: We have the following:\n- For the string \"abc\", there is no substring that does not occur in any other string.\n- For the string \"bcd\", there is no substring that does not occur in any other string.\n- For the string \"abcd\", the shortest substring that does not occur in any other string is \"abcd\".\n\nConstraints:\n\n- n == arr.length\n- 2 <= n <= 100\n- 1 <= arr[i].length <= 20\n- arr[i] consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = ['abcabc', 'bcabc', 'cabc', 'abcd']) == ['abca', '', '', 'd']\n assert candidate(arr = ['aaa', 'aab', 'aba', 'abb']) == ['aaa', 'aab', 'ba', 'bb']\n assert candidate(arr = ['abc', 'bcd', 'abcd']) == ['', '', 'abcd']\n assert candidate(arr = ['abcd', 'bcde', 'cdef', 'defg']) == ['a', 'bcde', 'cdef', 'g']\n assert candidate(arr = ['hello', 'world', 'hel', 'wor', 'ld']) == ['ll', 'rl', '', '', '']\n assert candidate(arr = ['unique', 'strings', 'array', 'test']) == ['q', 'g', 'a', 'es']\n assert candidate(arr = ['cab', 'ad', 'bad', 'c']) == ['ab', '', 'ba', '']\n assert candidate(arr = ['aaaa', 'aaab', 'aabb', 'abbb']) == ['aaaa', 'aaab', 'aabb', 'bbb']\n assert candidate(arr = ['xyz', 'zyx', 'yzx']) == ['xy', 'yx', 'zx']\n assert candidate(arr = ['abcde', 'bcdef', 'cdefg', 'defgh']) == ['a', 'bcdef', 'cdefg', 'h']\n assert candidate(arr = ['a', 'b', 'c', 'd']) == ['a', 'b', 'c', 'd']\n assert candidate(arr = ['hello', 'world', 'python', 'programming']) == ['e', 'd', 't', 'a']\n assert candidate(arr = ['same', 'same', 'same', 'same']) == ['', '', '', '']\n assert candidate(arr = ['banana', 'bandana', 'band']) == ['nan', 'da', '']\n assert candidate(arr = ['aaa', 'aab', 'aac', 'abc']) == ['aaa', 'aab', 'ac', 'bc']\n assert candidate(arr = ['abc', 'def', 'ghi', 'jkl', 'mno']) == ['a', 'd', 'g', 'j', 'm']\n assert candidate(arr = ['banana', 'ananas', 'nana', 'ana', 'nan']) == ['b', 's', '', '', '']\n assert candidate(arr = ['xyz', 'xyzz', 'xyzzz', 'xyzzzz']) == ['', '', '', 'zzzz']\n assert candidate(arr = ['mississippi', 'missouri', 'mismatch', 'misinterpret', 'misspoke']) == ['ip', 'u', 'a', 'n', 'k']\n assert candidate(arr = ['abcdefghij', 'bcdefghijk', 'cdefghijkl', 'defghijklm', 'efghijklmn', 'fghijklmno', 'ghijklmnop', 'hijklmnopq', 'ijklmnopqr', 'jklmnopqrs']) == ['a', 'bcdefghijk', 'cdefghijkl', 'defghijklm', 'efghijklmn', 'fghijklmno', 'ghijklmnop', 'hijklmnopq', 'ijklmnopqr', 's']\n assert candidate(arr = ['mississippi', 'missouri', 'miss', 'mis', 'is', 'sip', 'pip']) == ['pp', 'o', '', '', '', '', 'pip']\n assert candidate(arr = ['abacabadabacaba', 'bacabadaba', 'acabadaba', 'cabacaba', 'abacaba', 'bacaba', 'acaba', 'cabaca']) == ['dabac', '', '', 'cabacab', '', '', '', '']\n assert candidate(arr = ['banana', 'anana', 'nana', 'ana', 'na', 'a', 'bandana', 'band']) == ['bana', '', '', '', '', '', 'da', '']\n assert candidate(arr = ['aabbcc', 'bbccdd', 'ccddaa', 'ddeaab']) == ['abb', 'bccd', 'da', 'e']\n assert candidate(arr = ['aabbccddeeff', 'bbaacceeffdd', 'ccddeeffaabb', 'ddeeffaabbcc', 'eeffddbbaacc', 'ffddbbaaccee']) == ['bccd', 'ceef', 'cddeeffa', 'faabbc', 'effddb', 'dbbaacce']\n assert candidate(arr = ['zxyzyx', 'zyxzyx', 'yzyxzy', 'xyzyxz', 'yzyxzyx', 'zyxzyxzy']) == ['zx', '', '', 'xyzyxz', 'yzyxzyx', 'xzyxz']\n assert candidate(arr = ['banana', 'ananas', 'nana', 'anan']) == ['b', 's', '', '']\n assert candidate(arr = ['abacabadaba', 'bacabadabac', 'acabadabaca', 'cadabacabad', 'adabacabadab']) == ['abacabadaba', 'bacabadabac', 'badabaca', 'cad', 'dabacabada']\n assert candidate(arr = ['xyxyxy', 'yxyx', 'xyx', 'yx', 'xyz', 'zyx']) == ['xyxy', '', '', '', 'yz', 'zy']\n assert candidate(arr = ['xyx', 'yxy', 'xyxy', 'yxyx', 'xyxyx', 'yxyxy']) == ['', '', '', '', 'xyxyx', 'yxyxy']\n assert candidate(arr = ['abacabad', 'bacabadab', 'acabadabc', 'cababad']) == ['abac', 'bacabada', 'bc', 'bab']\n assert candidate(arr = ['zzzzz', 'zzzz', 'zzz', 'zz', 'z']) == ['zzzzz', '', '', '', '']\n assert candidate(arr = ['aabbccddeeff', 'bbccddeeffaa', 'ccddeeffaabb', 'ddeeffaabbcc', 'eeffaabbc', 'ffaabbcdd', 'aabbcdd', 'bbccdd', 'ccdd', 'ddee', 'eff', 'ff', 'ee', 'dd', 'cc', 'bb', 'aa']) == ['abbccd', 'bccddeeffa', 'cddeeffaab', 'faabbcc', '', 'faabbcd', '', '', '', '', '', '', '', '', '', '', '']\n assert candidate(arr = ['longstring', 'longstringa', 'longstringb', 'longstringc', 'longstringd', 'longstringe']) == ['', 'a', 'b', 'c', 'd', 'e']\n assert candidate(arr = ['aaaaab', 'bbbbb', 'cccc', 'dddd', 'eeeee', 'aaaaabbbb', 'bbbbbcccc', 'ccccdddd', 'ddddeeee']) == ['', '', '', '', 'eeeee', 'abb', 'bc', 'cd', 'de']\n assert candidate(arr = ['aabbccddeeff', 'bbaacceeffgg', 'ccaabbeeffhh', 'ddbbccffeeii', 'eekkllmmnn', 'ffggklllnnoo', 'gggghhkkllmm', 'hhhiiikkllmm', 'iiijjkklmmnn', 'jjjjkkklnnnoo']) == ['cd', 'ac', 'be', 'cf', 'ek', 'gk', 'gh', 'hi', 'ij', 'jjj']\n assert candidate(arr = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij', 'fghijk', 'ghijkl']) == ['a', 'bcdefg', 'cdefgh', 'defghi', 'efghij', 'fghijk', 'l']\n assert candidate(arr = ['abacaba', 'cabcabc', 'babcbab', 'abcabca', 'babcabc', 'cacacac', 'abcabcabc', 'bcabcbc', 'abcbcab', 'cacbcac']) == ['aba', '', 'cba', '', 'babca', 'acac', 'bcabcab', 'cabcb', 'bcbca', 'acb']\n assert candidate(arr = ['mississippi', 'mississippis', 'mississippii', 'mississippiii', 'mississippiiii']) == ['', 'pis', '', '', 'iiii']\n assert candidate(arr = ['xyz', 'xyzz', 'xyzzy', 'xyzzz', 'zyxzyx']) == ['', '', 'zzy', 'zzz', 'xz']\n assert candidate(arr = ['aaaabbbb', 'bbbbaaaa', 'aabbaabb', 'baabbaab', 'bbaabbab']) == ['aaab', 'baaa', 'abbaabb', 'baabbaa', 'bab']\n assert candidate(arr = ['abacaba', 'bacabab', 'acababa']) == ['abac', 'bacabab', 'baba']\n assert candidate(arr = ['pqr', 'pqs', 'pqt', 'pqu', 'pqv', 'pqw', 'pqx', 'pqy', 'pqz']) == ['r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n assert candidate(arr = ['abcdefgh', 'efghijkl', 'ghijklmn', 'hijklmno', 'ijklmnop']) == ['a', 'fghi', 'ghijklm', 'hijklmno', 'p']\n assert candidate(arr = ['banana', 'nanana', 'anana', 'bananaaa', 'anananan', 'ananan', 'anan', 'ana', 'a', 'n', 'an', 'na']) == ['', '', '', 'aa', 'ananana', '', '', '', '', '', '', '']\n assert candidate(arr = ['abcdefg', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == ['a', '', '', '', '', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'z']\n assert candidate(arr = ['abcdefghij', 'jabcdefghi', 'ijabcdefgh', 'hijabcdefg', 'ghijabcdef', 'fghijabcde', 'efghijabcd', 'defghijabc', 'cdefghijab', 'bcdefghija']) == ['abcdefghij', 'jabcdefghi', 'ijabcdefgh', 'hijabcdefg', 'ghijabcdef', 'fghijabcde', 'efghijabcd', 'defghijabc', 'cdefghijab', 'bcdefghija']\n assert candidate(arr = ['abcdefg', 'bcdefgh', 'cdefghi', 'defghij', 'efghijk', 'fghijkl', 'ghijklm']) == ['a', 'bcdefgh', 'cdefghi', 'defghij', 'efghijk', 'fghijkl', 'm']\n assert candidate(arr = ['mamma', 'pappa', 'bappa', 'kappa', 'dappa', 'lappa', 'sappa', 'tappa', 'gappa', 'yappa', 'xappa']) == ['m', 'pap', 'b', 'k', 'd', 'l', 's', 't', 'g', 'y', 'x']\n assert candidate(arr = ['algorithm', 'logarithm', 'rhythm', 'algorithmic', 'algorhythm']) == ['', 'ar', '', 'c', 'orh']\n assert candidate(arr = ['pqrstuvw', 'qrstuvwx', 'rstuvwxy', 'stuvwxyz', 'tuvwxyzx', 'uvwxyzxy', 'vwxyzxyz']) == ['p', 'qrstuvwx', 'rstuvwxy', 'stuvwxyz', 'tuvwxyzx', 'uvwxyzxy', 'zxyz']\n assert candidate(arr = ['xyxzyxzyx', 'yxyxzyxzx', 'xzyxzyxzy', 'zyxzyxzyx', 'yxzxzyxzy']) == ['xyxzyxzy', 'yxy', 'xzyxzyxz', 'zyxzyxzyx', 'zxz']\n assert candidate(arr = ['abcdefghij', 'bcdefghija', 'cdefghijab', 'defghijabc', 'efghijabcd', 'fghijabcde', 'ghijabcdef', 'hijabcdefg', 'ijabcdefgh', 'jabcdefghi']) == ['abcdefghij', 'bcdefghija', 'cdefghijab', 'defghijabc', 'efghijabcd', 'fghijabcde', 'ghijabcdef', 'hijabcdefg', 'ijabcdefgh', 'jabcdefghi']\n assert candidate(arr = ['mississippi', 'missouri', 'miss', 'issi', 'siss']) == ['p', 'o', '', '', '']\n assert candidate(arr = ['hello', 'world', 'hold', 'hellohold', 'holdworld']) == ['', '', '', 'oh', 'dw']\n assert candidate(arr = ['elephant', 'elephantology', 'elephantine', 'elephantmania', 'elephantdom', 'elephants']) == ['', 'g', 'in', 'ia', 'd', 's']\n assert candidate(arr = ['abcdabcd', 'cdabcdab', 'bcabcdab', 'ababcdcd', 'abcdabcd', 'cdabcdabcd', 'abcdabcda', 'bcdabcdabc', 'abcdabcdab', 'abcdabcdabc']) == ['', '', 'ca', 'ba', '', 'dabcdabcd', '', '', '', 'abcdabcdabc']\n assert candidate(arr = ['hellohello', 'elloworld', 'loworldhe', 'oworldhel', 'worldhell', 'orldhello', 'rldhelloe', 'ldhelloel', 'dhelloell']) == ['oh', 'llow', 'loworldh', 'oworldhel', 'worldhell', 'orldhello', 'rldhelloe', 'ldhelloel', 'oell']\n assert candidate(arr = ['nancy', 'randy', 'bandy', 'pancy', 'pandy', 'landy']) == ['na', 'r', 'b', 'panc', 'pand', 'l']\n assert candidate(arr = ['abcdabc', 'bcdbcda', 'cdabcdab']) == ['bcdabc', 'db', 'dabcd']\n assert candidate(arr = ['abcabcabc', 'bcabcabca', 'cabcabcab', 'abcabcaaa', 'abcaaacab', 'caaacabca', 'aaacabcab']) == ['abcabcabc', 'bcabcabca', 'cabcabcab', 'cabcaa', 'bcaaac', 'caaacabc', 'acabcab']\n assert candidate(arr = ['abcdefg', 'bcdefga', 'cdefgab', 'defgabc', 'efgabcd', 'fgabcde', 'gabcdef']) == ['abcdefg', 'bcdefga', 'cdefgab', 'defgabc', 'efgabcd', 'fgabcde', 'gabcdef']\n assert candidate(arr = ['abcdabcd', 'bcdbcdbd', 'cdabcdab', 'dabcdabc', 'abcdabca']) == ['bcdabcd', 'bd', 'cdabcda', 'dabcdabc', 'ca']\n assert candidate(arr = ['xxyyyzzz', 'yyzzzxxy', 'zzxxyyyz', 'xzzyyxxy', 'yzzxxyyy', 'zxyyyzzx']) == ['yyyzzz', 'zzzx', 'zxxyyyz', 'xz', 'yzzxx', 'zxy']\n assert candidate(arr = ['algorithm', 'logarithm', 'rhythm', 'algorithmic', 'logarithmic', 'rhythmical']) == ['', '', '', 'orithmi', 'arithmi', 'ca']\n assert candidate(arr = ['abcdefg', 'bcdefgh', 'cdefghi', 'defghij', 'efghijk']) == ['a', 'bcdefgh', 'cdefghi', 'defghij', 'k']\n assert candidate(arr = ['abacabad', 'bacabad', 'acabad', 'cabad', 'abad', 'bad', 'ad', 'd']) == ['abac', '', '', '', '', '', '', '']\n assert candidate(arr = ['zxy', 'zyx', 'xyz', 'yzx', 'xzy', 'yxz', 'zyxz', 'zxzy', 'yxzx', 'xyzy']) == ['zxy', '', '', 'yzx', '', '', 'zyxz', 'zxz', 'xzx', 'yzy']\n assert candidate(arr = ['aaaabc', 'aabbb', 'acabc', 'bbccc', 'aabbcc']) == ['aaa', 'bbb', 'ac', 'ccc', 'abbc']\n assert candidate(arr = ['zzzzzz', 'zzzzzy', 'zzzyzz', 'zzyzzz']) == ['zzzzzz', 'zzzzy', 'zzzyz', 'yzzz']\n assert candidate(arr = ['mississippi', 'mississippis', 'mississippiss', 'mississippisss', 'mississippi', 'mississippis', 'mississippiss', 'mississippisss', 'mississippi']) == ['', '', '', '', '', '', '', '', '']\n assert candidate(arr = ['xyzzxyzz', 'zzyxzyzx', 'yzyzyzyz']) == ['xy', 'xz', 'yzy']\n assert candidate(arr = ['zxy', 'zyx', 'yzx', 'xyz', 'yxz', 'xzy', 'zyx']) == ['zxy', '', 'yzx', 'xyz', 'yxz', 'xzy', '']\n assert candidate(arr = ['aabbccddeeff', 'bbccddeeffgg', 'ccddeeffgghh', 'ddeeffgghhii', 'eeffgghhiijj']) == ['a', 'bccddeeffg', 'cddeeffggh', 'deeffgghhi', 'j']\n assert candidate(arr = ['aabbccdd', 'bbaacccd', 'ccddaabb', 'ddccbbaa', 'aabbddcc']) == ['bc', 'ac', 'da', 'cb', 'bd']\n assert candidate(arr = ['xyxyxyxy', 'yxyxyxyx', 'xyxyxyyx', 'xyxxyxyx', 'xxyxyxyx']) == ['xyxyxyxy', 'yxyxyxyx', 'yy', 'yxx', 'xxyxyxy']\n assert candidate(arr = ['aaaaabbbbb', 'bbbbbccccc', 'cccccddddd', 'dddddeeeee', 'eeeeefffff']) == ['a', 'bc', 'cd', 'de', 'f']\n assert candidate(arr = ['abcdabcd', 'bcdbcdbcd', 'cdcdcdcd', 'dcdcdcdc', 'cdcdcd']) == ['a', 'db', 'cdcdcdcd', 'dcdcdcdc', '']\n assert candidate(arr = ['zzzzzzz', 'zzzzzzzz', 'zzzzzzzzz', 'zzzzzzzzzz']) == ['', '', '', 'zzzzzzzzzz']\n assert candidate(arr = ['mnopqrst', 'nopqrstu', 'opqrstuv', 'pqrstuvw', 'qrstuvwx', 'rstuvwxy', 'stuvwxyz', 'tuvwxyzx']) == ['m', 'nopqrstu', 'opqrstuv', 'pqrstuvw', 'qrstuvwx', 'rstuvwxy', 'stuvwxyz', 'zx']\n assert candidate(arr = ['abababab', 'baba', 'ab', 'ba', 'aba', 'bab']) == ['abab', '', '', '', '', '']\n assert candidate(arr = ['aabbcc', 'bbaacc', 'aabbbc', 'aabbccdd', 'aabccdde', 'aabbccde']) == ['', 'ac', 'bbb', 'bbccdd', 'abc', 'cde']\n assert candidate(arr = ['abcdef', 'defgh', 'fghij', 'ghijkl', 'hijklm', 'ijklmn']) == ['a', 'efg', 'fghi', 'ghijk', 'hijklm', 'n']\n assert candidate(arr = ['abcabc', 'bcabc', 'cabc', 'abcd', 'bcde', 'cdef']) == ['abca', '', '', 'abcd', 'bcde', 'f']\n assert candidate(arr = ['zzzzzzzzzz', 'zzzzzzzzzy', 'zzzzzzzzzx', 'zzzzzzzzww', 'zzzzzzzvvv', 'zzzzzzuuuu', 'zzzzzttttt', 'zzzzsssss', 'zzzrrrrr', 'zzqqqqq', 'zppppp', 'oooooo']) == ['zzzzzzzzzz', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o']\n assert candidate(arr = ['abcde', 'bcdef', 'cdefg', 'defgh', 'efghi']) == ['a', 'bcdef', 'cdefg', 'defgh', 'i']\n assert candidate(arr = ['aaa', 'aab', 'aba', 'baa', 'aabbaa', 'baabaa', 'aabaab', 'baabaa', 'abaaab', 'aababa']) == ['', '', '', '', 'bb', '', 'abaab', '', 'aaab', 'bab']\n assert candidate(arr = ['mississippi', 'missouri', 'missed', 'miss', 'mississippi']) == ['', 'o', 'd', '', '']\n assert candidate(arr = ['aaaabbbb', 'aabbbbaa', 'abbaabba', 'bbaaaabb']) == ['aaabbb', 'bbba', 'abba', 'baaa']\n assert candidate(arr = ['aaaaab', 'bbbba', 'abbbb', 'baaaa', 'abba', 'baba']) == ['aab', 'bbba', 'abbb', 'baa', 'abba', 'aba']\n assert candidate(arr = ['aabbcc', 'bbaacc', 'ccaabb', 'aabbbc', 'bbccaa']) == ['abbc', 'ac', 'caab', 'bbb', 'bcca']\n assert candidate(arr = ['abcde', 'bcdef', 'cdefg', 'defgh', 'efghi', 'fghij', 'ghijk', 'hijkl', 'ijklm', 'jklmn']) == ['a', 'bcdef', 'cdefg', 'defgh', 'efghi', 'fghij', 'ghijk', 'hijkl', 'ijklm', 'n']\n assert candidate(arr = ['elephant', 'elphant', 'lphant', 'phant', 'hant', 'ant', 'nt', 't']) == ['ep', 'elp', '', '', '', '', '', '']\n assert candidate(arr = ['abcdabcd', 'bcdabcda', 'cdabcdab', 'dabcabcd']) == ['abcdabc', 'bcdabcda', 'dabcdab', 'ca']\n assert candidate(arr = ['aaaaaaa', 'aaaaaab', 'aaaaabb', 'aaaabb', 'aaabb', 'aabb', 'abb', 'bb']) == ['aaaaaaa', 'aaaaaab', 'aaaaabb', '', '', '', '', '']\n assert candidate(arr = ['apple', 'application', 'applet', 'app']) == ['', 'c', 'et', '']\n assert candidate(arr = ['xzy', 'zyx', 'xyzzy', 'zyxzyx']) == ['', '', 'xy', 'yxz']\n assert candidate(arr = ['abcdefg', 'bcdefgh', 'cdefghi', 'defghij', 'efghijk', 'fghijkl']) == ['a', 'bcdefgh', 'cdefghi', 'defghij', 'efghijk', 'l']\n assert candidate(arr = ['aaaaabbbbb', 'bbbbbccccc', 'cccccaaaaa', 'dddddeeeee', 'eeeeeaaaaa', 'fffffbbbbb', 'gggggccccc', 'hhhhhdddd', 'iiiiieeeee', 'jjjjjfffff', 'kkkkkggggg', 'lllllhhhhh', 'mmmmmiiiii', 'nnnnnjjjjj', 'oooookkkkk', 'ppppplllll']) == ['ab', 'bc', 'ca', 'de', 'ea', 'fb', 'gc', 'hd', 'ie', 'jf', 'kg', 'lh', 'm', 'n', 'o', 'p']\n assert candidate(arr = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm', 'qwerty', 'asdfg', 'zxcvb']) == ['i', 'h', 'm', '', '', '']\n assert candidate(arr = ['abcdefghij', 'bcdefghij', 'cdefghij', 'defghij', 'efghij', 'fghij', 'ghij', 'hij', 'ij', 'j']) == ['a', '', '', '', '', '', '', '', '', '']\n assert candidate(arr = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd', 'efghij', 'klmnop', 'qrstuv', 'wxyzab', 'cdefgh']) == ['bcde', 'jk', 'pq', 'vw', 'zabc', 'fghi', 'lm', 'rs', 'xy', 'defg']\n assert candidate(arr = ['unique', 'uneque', 'uniquely', 'uniqely', 'unieqly']) == ['', 'ne', 'uel', 'qe', 'ie']\n assert candidate(arr = ['aabbcc', 'ababab', 'abcabc', 'aabb', 'abbb', 'bbcc', 'acca', 'bbac', 'aabbccdd', 'bbccddaa']) == ['', 'aba', 'abc', '', 'bbb', '', 'acc', 'bac', 'abbccd', 'da']\n assert candidate(arr = ['aaaaaabbbbb', 'bbbbbccccc', 'cccccaaaaa', 'aacccbbbbb', 'bbcccaaaaa']) == ['ab', 'bbbc', 'cccca', 'ac', 'bccca']\n assert candidate(arr = ['algorithm', 'algorith', 'algorit', 'algori', 'algor', 'algo', 'algr', 'alg', 'al', 'a', 'bmw', 'bmv', 'bvw', 'b', 'm', 'w']) == ['hm', '', '', '', '', '', 'gr', '', '', '', 'mw', 'mv', 'bv', '', '', '']\n assert candidate(arr = ['abcabc', 'bcabcabc', 'cabcabcab', 'abcabcabc']) == ['', '', 'cabcabca', 'abcabcabc']\n assert candidate(arr = ['aabbccddeeff', 'bbccddeeffgg', 'ccddeeffgghh', 'ddeeffgghhii', 'eeffgghhiijj', 'ffgghhiijjkk']) == ['a', 'bccddeeffg', 'cddeeffggh', 'deeffgghhi', 'effgghhiij', 'k']\n assert candidate(arr = ['abcdabcd', 'bcdbcd', 'cdabcd', 'dabcabcd', 'abcddabc']) == ['bcda', 'db', '', 'ca', 'dd']\n", "comparison": "exact"}, "public_tests": ["[\"cab\",\"ad\",\"bad\",\"c\"]", "[\"abc\",\"bcd\",\"abcd\"]"], "hints": ["Try a brute force solution where you check every substring.", "Use a Hash map to keep track of the substrings."], "metadata": {"canonical_parameter_names": ["arr"], "leetcode_dataset_entry_point": "Solution().shortestSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:11+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "string", "trie"]}, "language": "ruby", "interface": {"raw_signature": "def shortest_substrings(arr)", "container": null, "callable": "shortest_substrings", "parameters": [{"name": "arr", "type": "String[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3077, "task_id": "maximum-strength-of-k-disjoint-subarrays", "difficulty": "Hard", "problem_description": "You are given an array of integers nums with length n, and a positive odd integer k.\n\nSelect exactly k disjoint subarrays sub_1, sub_2, ..., sub_k from nums such that the last element of sub_i appears before the first element of sub_{i+1} for all 1 <= i <= k-1. The goal is to maximize their combined strength.\n\nThe strength of the selected subarrays is defined as:\n\nstrength = k * sum(sub_1)- (k - 1) * sum(sub_2) + (k - 2) * sum(sub_3) - ... - 2 * sum(sub_{k-1}) + sum(sub_k)\n\nwhere sum(sub_i) is the sum of the elements in the i-th subarray.\n\nReturn the maximum possible strength that can be obtained from selecting exactly k disjoint subarrays from nums.\n\nNote that the chosen subarrays don't need to cover the entire array.\n\nExample 1:\n\nInput: nums = [1,2,3,-1,2], k = 3\n\nOutput: 22\n\nExplanation:\n\nThe best possible way to select 3 subarrays is: nums[0..2], nums[3..3], and nums[4..4]. The strength is calculated as follows:\n\nstrength = 3 * (1 + 2 + 3) - 2 * (-1) + 2 = 22\n\nExample 2:\n\nInput: nums = [12,-2,-2,-2,-2], k = 5\n\nOutput: 64\n\nExplanation:\n\nThe only possible way to select 5 disjoint subarrays is: nums[0..0], nums[1..1], nums[2..2], nums[3..3], and nums[4..4]. The strength is calculated as follows:\n\nstrength = 5 * 12 - 4 * (-2) + 3 * (-2) - 2 * (-2) + (-2) = 64\n\nExample 3:\n\nInput: nums = [-1,-2,-3], k = 1\n\nOutput: -1\n\nExplanation:\n\nThe best possible way to select 1 subarray is: nums[0..0]. The strength is -1.\n\nConstraints:\n\n- 1 <= n <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- 1 <= k <= n\n- 1 <= n * k <= 10^6\n- k is odd.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 3) == 100\n assert candidate(nums = [12, -2, -2, -2, -2],k = 5) == 64\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6],k = 3) == 41\n assert candidate(nums = [1, -1, 1, -1, 1, -1],k = 3) == 6\n assert candidate(nums = [10, -5, 1, 0, 20, -1, 3],k = 5) == 138\n assert candidate(nums = [-1, -2, -3],k = 1) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 28\n assert candidate(nums = [5, -1, 3, -2, 4, -1, 2],k = 3) == 31\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 30\n assert candidate(nums = [0, 0, 0, 0, 0],k = 5) == 0\n assert candidate(nums = [100, -100, 100, -100, 100],k = 5) == 1500\n assert candidate(nums = [0, 0, 0, 0, 0],k = 1) == 0\n assert candidate(nums = [5, 3, 2, 7, 1, 9],k = 3) == 58\n assert candidate(nums = [1, 2, 3, -1, 2],k = 3) == 22\n assert candidate(nums = [5, 1, 3, 2, -4, 7],k = 3) == 48\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 140\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 101) == 6111\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 = 19) == 115\n assert candidate(nums = [-10, 10, -10, 10, -10, 10, -10, 10, -10, 10],k = 5) == 150\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 9) == 320\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 9) == 260\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 7) == 284\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 11) == 6050\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 7) == 62\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 145\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],k = 15) == 2515\n assert candidate(nums = [-1, -3, -5, -7, -9, -11, -13, -15, -17, -19],k = 3) == 138\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],k = 17) == 981\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 = 17) == 1959\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500],k = 7) == 7800\n assert candidate(nums = [-5, 1, -3, 2, -1, 4, -2, 3, -1, 2, 5],k = 5) == 51\n assert candidate(nums = [100, 200, -100, 300, -200, 400, -300, 500, -400, 600],k = 7) == 10800\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 55\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4],k = 7) == 92\n assert candidate(nums = [10, 20, 30, -5, -10, 40, 50, -15, 60, 70],k = 5) == 790\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 4000\n assert candidate(nums = [10, -5, 3, -2, 1, -1, 2, -3, 4, -4, 5, -5, 6, -6, 7, -7],k = 7) == 182\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 = 25) == 138\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9],k = 9) == 442\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],k = 11) == 66000\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 11) == 540\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 5) == 52\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) == 57\n assert candidate(nums = [100, -50, 25, -12, 6, -3, 1, -1, 0, 2],k = 5) == 805\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000],k = 9) == 45000000000\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 = 9) == 104\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 19) == 1150\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7],k = 11) == 227\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == 330\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 = 19) == 29\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 = 49) == 1642\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 288\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 9300\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],k = 5) == 8700\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 = 11) == 105\n assert candidate(nums = [-999999999, 999999999, -999999999, 999999999, -999999999, 999999999, -999999999, 999999999, -999999999, 999999999],k = 9) == 44999999955\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100],k = 5) == 1100\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 = 9) == 665\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500],k = 9) == 9500\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 11) == 0\n assert candidate(nums = [10, 20, -30, 40, -50, 60, -70, 80, -90, 100],k = 7) == 1680\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110, 120],k = 7) == 2240\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -110, -120, -130, -140, -150, -160, -170, -180, -190, -200],k = 19) == 950\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 5) == 87\n assert candidate(nums = [-1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000],k = 3) == 6000000000\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],k = 5) == 95\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60],k = 7) == 1060\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110, 120, -130, 140, -150],k = 9) == 3900\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 = 19) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 308\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000],k = 3) == 6000000000\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 9) == 22\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 15) == 80\n assert candidate(nums = [100, -100, 100, -100, 100, -100, 100, -100, 100, -100],k = 7) == 2800\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 6, 7, 8, 9, 10],k = 7) == 213\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 9) == 3300\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000],k = 3) == 6000000000\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80, 90, -90, 100, -100],k = 9) == 3200\n assert candidate(nums = [10, -3, 4, -1, 2, 1, -5, 6, 7, -2, 8, -4],k = 5) == 136\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 9) == 25\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500],k = 5) == 5200\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 11) == 20400\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 5) == 28000000000\n assert candidate(nums = [-1, 3, -2, 4, -5, 6, -7, 8, -9, 10],k = 7) == 175\n assert candidate(nums = [10, 20, 30, -10, -20, -30, 40, 50, 60, -40, -50, -60, 70, 80, 90, -70, -80, -90, 100, 110],k = 7) == 3580\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 1000\n assert candidate(nums = [100, -50, 200, -150, 300, -250, 400, -350, 500, -450],k = 7) == 7550\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],k = 5) == 85\n assert candidate(nums = [100, -50, 200, -150, 300, -250, 400, -350, 500, -450],k = 5) == 5400\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50, -60, 60, -70, 70, -80, 80, -90, 90, -100, 100, -110, 110, -120, 120, -130, 130, -140, 140, -150, 150, -160, 160],k = 25) == 26780\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5],k = 9) == 115\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 = 11) == 618\n assert candidate(nums = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50],k = 5) == 435\n assert candidate(nums = [10, -1, 20, -2, 30, -3, 40, -4, 50, -5],k = 3) == 340\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 8\n assert candidate(nums = [-5, 0, 5, -10, 15, -20, 25, -30, 35, -40, 45, -50, 55, -60, 65, -70],k = 13) == 2275\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5],k = 9) == 227\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 5) == 520\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 8\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],k = 7) == 1400\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8],k = 13) == 385\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 15) == 120\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 3) == 12\n assert candidate(nums = [100, -100, 100, -100, 100, -100, 100, -100, 100, -100],k = 9) == 4500\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1],k = 9) == 45\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400],k = 7) == 5000\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 123\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 19) == 715\n", "comparison": "exact"}, "public_tests": ["[1,2,3,-1,2]\n3", "[12,-2,-2,-2,-2]\n5", "[-1,-2,-3]\n1"], "hints": ["Let dp[i][j][x == 0/1] be the maximum strength to select j disjoint subarrays from the original array’s suffix (nums[i..(n - 1)]), x denotes whether we select the element or not.", "Initially dp[n][0][0] == 0.", "We have dp[i][j][1] = nums[i] * get(j) + max(dp[i + 1][j - 1][0], dp[i + 1][j][1]) where get(j) = j if j is odd, otherwise -j.", "We can select nums[i] as a separate subarray or select at least nums[i] and nums[i + 1] as the first subarray. dp[i][j][0] = max(dp[i + 1][j][0], dp[i][j][1]).", "The answer is dp[0][k][0]."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumStrength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:14+00:00", "tests_total": 108, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_strength(nums, k)", "container": null, "callable": "maximum_strength", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3079, "task_id": "find-the-sum-of-encrypted-integers", "difficulty": "Easy", "problem_description": "You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333.\n\nReturn the sum of encrypted elements.\n\nExample 1:\n\nInput: nums = [1,2,3]\nOutput: 6\nExplanation: The encrypted elements are [1,2,3]. The sum of encrypted elements is 1 + 2 + 3 == 6.\n\nExample 2:\n\nInput: nums = [10,21,31]\nOutput: 66\nExplanation: The encrypted elements are [11,22,33]. The sum of encrypted elements is 11 + 22 + 33 == 66.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [523, 213, 111]) == 999\n assert candidate(nums = [523, 213, 111]) == 999\n assert candidate(nums = [1, 10, 100, 1000]) == 1234\n assert candidate(nums = [999, 100, 101]) == 1221\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [456, 789, 321]) == 1998\n assert candidate(nums = [987, 654, 321]) == 1998\n assert candidate(nums = [5, 15, 25, 35]) == 170\n assert candidate(nums = [100, 200, 300]) == 666\n assert candidate(nums = [12, 21, 34, 43, 56, 65]) == 264\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99]) == 495\n assert candidate(nums = [123, 456, 789]) == 1998\n assert candidate(nums = [999, 888, 777]) == 2664\n assert candidate(nums = [123, 456, 789]) == 1998\n assert candidate(nums = [999, 123, 456]) == 1998\n assert candidate(nums = [1000, 100, 10, 1]) == 1234\n assert candidate(nums = [12, 23, 34, 45, 56, 67, 78, 89]) == 484\n assert candidate(nums = [999, 888, 777, 666]) == 3330\n assert candidate(nums = [5, 15, 25]) == 115\n assert candidate(nums = [111, 222, 333]) == 666\n assert candidate(nums = [11, 22, 33, 44, 55]) == 165\n assert candidate(nums = [999, 100, 200]) == 1332\n assert candidate(nums = [1, 2, 3]) == 6\n assert candidate(nums = [10, 21, 31]) == 66\n assert candidate(nums = [199, 299, 399, 499, 599, 699, 799, 899, 991]) == 8991\n assert candidate(nums = [865, 743, 219, 987, 567, 432, 321]) == 5217\n assert candidate(nums = [901, 892, 783, 674, 567]) == 4440\n assert candidate(nums = [199, 288, 377, 466, 555, 644, 733, 822, 911]) == 7215\n assert candidate(nums = [987, 654, 321, 123, 456, 789, 876, 543, 210]) == 5661\n assert candidate(nums = [987, 654, 321, 987]) == 2997\n assert candidate(nums = [123, 122, 121, 120, 119]) == 1998\n assert candidate(nums = [100, 200, 300, 400, 500]) == 1665\n assert candidate(nums = [1000, 999, 888, 777, 666]) == 4441\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 111, 222, 333]) == 4662\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 4995\n assert candidate(nums = [50, 51, 52, 53, 54]) == 275\n assert candidate(nums = [987, 654, 321, 123, 456]) == 2997\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 4995\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901]) == 6660\n assert candidate(nums = [56, 78, 90, 123, 456, 789]) == 2251\n assert candidate(nums = [12, 23, 34, 45, 56, 67, 78, 89, 90]) == 583\n assert candidate(nums = [12, 21, 345, 543, 654]) == 1820\n assert candidate(nums = [990, 881, 772, 663, 554, 445, 336, 227, 118]) == 6771\n assert candidate(nums = [59, 68, 77, 86, 95, 104, 213, 322, 431]) == 2005\n assert candidate(nums = [888, 887, 886, 885, 884]) == 4440\n assert candidate(nums = [101, 102, 103, 104, 105]) == 1665\n assert candidate(nums = [199, 299, 399, 499, 599]) == 4995\n assert candidate(nums = [56, 65, 78, 87, 90, 900]) == 1406\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 606\n assert candidate(nums = [101, 202, 303, 404, 505]) == 1665\n assert candidate(nums = [199, 299, 399, 499, 599, 699, 799, 899, 999]) == 8991\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909]) == 4995\n assert candidate(nums = [987, 654, 321, 111, 222, 333]) == 2664\n", "comparison": "exact"}, "public_tests": ["[1,2,3]", "[10,21,31]"], "hints": ["Encrypted numbers are of the form 11…1 * maxDigit."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumOfEncryptedInt", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:18+00:00", "tests_total": 102, "tests_dropped": 49, "flags": [], "topic_tags": ["array", "math"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_encrypted_int(nums)", "container": null, "callable": "sum_of_encrypted_int", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3080, "task_id": "mark-elements-on-array-by-performing-queries", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums of size n consisting of positive integers.\n\nYou are also given a 2D array queries of size m where queries[i] = [index_i, k_i].\n\nInitially all elements of the array are unmarked.\n\nYou need to apply m queries on the array in order, where on the i^th query you do the following:\n\n- Mark the element at index index_i if it is not already marked.\n- Then mark k_i unmarked elements in the array with the smallest values. If multiple such elements exist, mark the ones with the smallest indices. And if less than k_i unmarked elements exist, then mark all of them.\n\nReturn an array answer of size m where answer[i] is the sum of unmarked elements in the array after the i^th query.\n\nExample 1:\n\nInput: nums = [1,2,2,1,2,3,1], queries = [[1,2],[3,3],[4,2]]\nOutput: [8,3,0]\nExplanation:\nWe do the following queries on the array:\n- Mark the element at index 1, and 2 of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 2 + 2 + 3 + 1 = 8.\n- Mark the element at index 3, since it is already marked we skip it. Then we mark 3 of the smallest unmarked elements with the smallest indices, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 3.\n- Mark the element at index 4, since it is already marked we skip it. Then we mark 2 of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [1,2,2,1,2,3,1]. The sum of unmarked elements is 0.\n\nExample 2:\n\nInput: nums = [1,4,2,3], queries = [[0,1]]\nOutput: [7]\nExplanation: We do one query which is mark the element at index 0 and mark the smallest element among unmarked elements. The marked elements will be nums = [1,4,2,3], and the sum of unmarked elements is 4 + 3 = 7.\n\nConstraints:\n\n- n == nums.length\n- m == queries.length\n- 1 <= m <= n <= 10^5\n- 1 <= nums[i] <= 10^5\n- queries[i].length == 2\n- 0 <= index_i, k_i <= n - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[4, 1], [0, 2], [2, 2]]) == [90, 40, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[0, 2], [1, 1]]) == [90, 50]\n assert candidate(nums = [5, 3, 8, 1, 4],queries = [[2, 1], [4, 2], [0, 2]]) == [12, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [3, 3], [1, 1]]) == [4, 1, 0]\n assert candidate(nums = [1, 4, 2, 3],queries = [[0, 1]]) == [7]\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 1],queries = [[1, 2], [3, 3], [4, 2]]) == [8, 3, 0]\n assert candidate(nums = [7, 7, 7, 7, 7],queries = [[0, 3], [2, 2]]) == [7, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[1, 2], [2, 1], [4, 2]]) == [90, 50, 0]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [[0, 3], [1, 1], [2, 1]]) == [1, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [[0, 2], [1, 1], [3, 2]]) == [2, 1, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[0, 3], [1, 2], [2, 1]]) == [50, 0, 0]\n assert candidate(nums = [5, 3, 1, 2, 4],queries = [[2, 1], [0, 2], [3, 3]]) == [12, 0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[0, 3], [1, 1], [4, 1]]) == [50, 0, 0]\n assert candidate(nums = [5, 3, 8, 1, 9],queries = [[2, 1], [4, 2]]) == [17, 0]\n assert candidate(nums = [5, 5, 5, 5, 5],queries = [[2, 1], [0, 2], [1, 2]]) == [15, 5, 0]\n assert candidate(nums = [5, 5, 5, 5, 5],queries = [[0, 2], [1, 1], [2, 3]]) == [10, 5, 0]\n assert candidate(nums = [7, 5, 3, 8, 1, 4, 6, 2],queries = [[6, 2], [3, 1], [0, 3], [5, 2]]) == [27, 16, 0, 0]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],queries = [[0, 5], [2, 3], [4, 2], [8, 1]]) == [12, 3, 0, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [5200, 4900, 4500, 4000, 3400, 2700, 1900, 1000, 0, 0]\n assert candidate(nums = [5, 2, 7, 3, 4, 1, 6, 8, 9, 10],queries = [[4, 2], [1, 1], [7, 3], [9, 2]]) == [48, 45, 19, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 10], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5]]) == [70, 27, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[9, 3], [8, 2], [7, 1], [6, 4], [5, 5]]) == [39, 21, 7, 0, 0]\n assert candidate(nums = [7, 3, 9, 1, 5, 2, 8, 4, 6, 10],queries = [[0, 2], [5, 3], [8, 2], [3, 1]]) == [45, 33, 10, 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],queries = [[0, 10], [1, 5], [2, 3], [3, 2], [4, 1]]) == [144, 74, 20, 0, 0]\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 9, 8, 10],queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [52, 45, 40, 34, 27, 19, 10, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [2, 3], [4, 2], [9, 1]]) == [4, 1, 0, 0]\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [49, 44, 19, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [[0, 5], [1, 5], [2, 5], [3, 5], [4, 5]]) == [990, 540, 0, 0, 0]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]) == [28, 26, 24, 21, 18, 14]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 5], [1, 5], [2, 5], [3, 5], [4, 5]]) == [189, 144, 74, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5]]) == [44, 30, 7, 0, 0]\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1],queries = [[1, 3], [3, 2], [5, 1], [7, 4]]) == [51, 40, 30, 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],queries = [[0, 5], [5, 5], [10, 5], [15, 5]]) == [189, 144, 74, 0]\n assert candidate(nums = [5, 3, 1, 2, 4, 5, 3, 1, 2, 4, 5, 3, 1, 2, 4, 5, 3, 1, 2, 4],queries = [[2, 1], [0, 2], [3, 3], [1, 4], [4, 5]]) == [58, 51, 43, 27, 5]\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1],queries = [[0, 3], [1, 3], [2, 3], [3, 3], [4, 3]]) == [22, 15, 0, 0, 0]\n assert candidate(nums = [15, 12, 18, 14, 16, 17, 13, 19, 20, 11],queries = [[3, 2], [0, 1], [8, 4], [2, 3]]) == [118, 90, 0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 5], [5, 3], [9, 2]]) == [340, 100, 0]\n assert candidate(nums = [100, 100, 100, 100, 100],queries = [[0, 2], [1, 1], [2, 2], [3, 1], [4, 1]]) == [200, 100, 0, 0, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 0]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 3, 1, 2, 4, 6, 8, 7, 9],queries = [[2, 3], [0, 1], [3, 2], [5, 2]]) == [35, 24, 9, 0]\n assert candidate(nums = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [54, 49, 34, 0, 0]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],queries = [[4, 2], [3, 1], [2, 2], [1, 1], [0, 1]]) == [199999, 100000, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[9, 1], [8, 1], [7, 1], [6, 1], [5, 1], [4, 1], [3, 1], [2, 1], [1, 1], [0, 1]]) == [44, 33, 22, 11, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[9, 5], [3, 3], [1, 2]]) == [34, 0, 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],queries = [[0, 10], [10, 5], [15, 3], [19, 2], [0, 5]]) == [144, 74, 20, 0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [[0, 5], [5, 5], [10, 5]]) == [990, 540, 0]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 7], [2, 5], [4, 4], [6, 3], [8, 2]]) == [77, 14, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [1, 3], [2, 1], [3, 1]]) == [4, 1, 0, 0]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [52, 35, 17, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 3], [1, 2], [2, 1], [3, 3], [4, 1]]) == [450, 340, 270, 0, 0]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1]]) == [189, 168, 147, 126, 105, 84, 63, 42, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 1],queries = [[1, 2], [3, 3], [4, 2], [5, 1], [6, 0], [0, 1]]) == [8, 3, 0, 0, 0, 0]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 2], [3, 2], [5, 1], [7, 3], [9, 1]]) == [420, 280, 170, 0, 0]\n assert candidate(nums = [5, 3, 1, 2, 4, 1, 2, 3, 4, 5],queries = [[0, 2], [3, 3], [5, 1], [2, 2], [7, 4]]) == [23, 13, 9, 0, 0]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 10], [1, 5], [2, 3], [3, 2], [4, 1]]) == [135, 51, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]) == [114, 99, 65, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [5, 3], [2, 2]]) == [4, 1, 0]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],queries = [[0, 5], [1, 2], [2, 3], [3, 1]]) == [12, 6, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[9, 5], [8, 4], [7, 3], [6, 2], [5, 1]]) == [30, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 1], [2, 1], [4, 1], [6, 1], [8, 1], [1, 1], [3, 1], [5, 1], [7, 1], [9, 1]]) == [52, 45, 34, 19, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 5], [1, 3], [2, 2], [3, 1], [4, 0]]) == [34, 10, 0, 0, 0]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],queries = [[0, 5], [2, 2], [4, 3], [6, 2], [8, 1]]) == [80, 40, 0, 0, 0]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 5], [1, 2], [2, 2], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [34, 19, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 5], [2, 3], [8, 2], [5, 1], [7, 1]]) == [30, 0, 0, 0, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0]]) == [140, 120, 90, 50, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [2, 2], [4, 3]]) == [4, 2, 0]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],queries = [[2, 2], [0, 1], [4, 2]]) == [199999, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [52, 49, 45, 40, 34, 27, 19, 10, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 3], [1, 3], [2, 3], [3, 3], [4, 3]]) == [110, 92, 65, 29, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[0, 3], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3]]) == [55, 40, 25, 10, 0, 0]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995],queries = [[0, 1], [1, 2], [2, 3], [3, 1]]) == [399990, 99998, 0, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],queries = [[0, 2], [1, 2], [2, 2], [3, 2], [4, 2]]) == [25, 19, 12, 4, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 5], [2, 2], [4, 1], [6, 3], [8, 1]]) == [34, 19, 10, 0, 0]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [440, 300, 70, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [2, 3], [4, 2], [8, 1]]) == [4, 1, 0, 0]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[9, 5], [8, 3], [7, 2], [6, 1], [5, 4]]) == [340, 100, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 2], [4, 1]]) == [8, 6, 3, 1, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [8, 7, 6, 5, 4, 3, 2, 1, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 5], [2, 4], [4, 3], [6, 2], [8, 1]]) == [99, 65, 29, 0, 0]\n assert candidate(nums = [5, 1, 3, 4, 2, 5, 4, 3, 2, 1],queries = [[4, 2], [0, 2], [9, 1], [2, 3]]) == [26, 16, 13, 0]\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10],queries = [[0, 4], [5, 2], [9, 3], [2, 1]]) == [40, 27, 0, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 5], [1, 3], [4, 2], [7, 1], [9, 1]]) == [3400, 1000, 0, 0, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[9, 1], [8, 2], [7, 3], [6, 4]]) == [52, 45, 27, 0]\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],queries = [[0, 5], [1, 3], [2, 2], [3, 1], [4, 1]]) == [300000, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[0, 2], [2, 2], [4, 2], [6, 2], [8, 2]]) == [35, 25, 15, 5, 0]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[1, 4], [3, 3], [5, 2], [7, 1], [9, 1]]) == [75, 36, 0, 0, 0]\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 8, 7, 10, 9],queries = [[0, 5], [3, 3], [8, 2]]) == [34, 10, 0]\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1],queries = [[4, 3], [0, 2], [9, 4]]) == [24, 13, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [1, 3], [5, 2], [8, 1]]) == [4, 1, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [2, 3], [8, 2], [1, 1]]) == [4, 1, 0, 0]\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 1, 3, 2, 2],queries = [[1, 2], [3, 3], [4, 2], [0, 1], [5, 1]]) == [15, 10, 6, 3, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 5], [5, 3], [9, 2], [4, 1], [2, 1]]) == [34, 10, 0, 0, 0]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 5], [5, 5], [10, 5], [15, 5]]) == [175, 120, 54, 0]\n assert candidate(nums = [50, 20, 30, 10, 40],queries = [[4, 2], [3, 1], [2, 1], [1, 1], [0, 1]]) == [80, 50, 0, 0, 0]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[9, 5], [4, 2], [0, 3], [8, 4]]) == [340, 190, 0, 0]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],queries = [[0, 3], [2, 2], [5, 1]]) == [599979, 299992, 199996]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[9, 3], [0, 2], [5, 4]]) == [39, 30, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 5], [1, 2], [5, 3]]) == [4, 2, 0]\n", "comparison": "exact"}, "public_tests": ["[1,2,2,1,2,3,1]\n[[1,2],[3,3],[4,2]]", "[1,4,2,3]\n[[0,1]]"], "hints": ["Use another array to keep track of marked indices.", "Sort the array nums to be able to find the smallest unmarked elements quickly in each query."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().unmarkedSumArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:21+00:00", "tests_total": 111, "tests_dropped": 13, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "heap-priority-queue", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def unmarked_sum_array(nums, queries)", "container": null, "callable": "unmarked_sum_array", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3081, "task_id": "replace-question-marks-in-string-to-minimize-its-value", "difficulty": "Medium", "problem_description": "You are given a string s. s[i] is either a lowercase English letter or '?'.\n\nFor a string t having length m containing only lowercase English letters, we define the function cost(i) for an index i as the number of characters equal to t[i] that appeared before it, i.e. in the range [0, i - 1].\n\nThe value of t is the sum of cost(i) for all indices i.\n\nFor example, for the string t = \"aab\":\n\n- cost(0) = 0\n- cost(1) = 1\n- cost(2) = 0\n- Hence, the value of \"aab\" is 0 + 1 + 0 = 1.\n\nYour task is to replace all occurrences of '?' in s with any lowercase English letter so that the value of s is minimized.\n\nReturn a string denoting the modified string with replaced occurrences of '?'. If there are multiple strings resulting in the minimum value, return the lexicographically smallest one.\n\nExample 1:\n\nInput: s = \"???\"\nOutput: \"abc\"\nExplanation: In this example, we can replace the occurrences of '?' to make s equal to \"abc\".\nFor \"abc\", cost(0) = 0, cost(1) = 0, and cost(2) = 0.\nThe value of \"abc\" is 0.\nSome other modifications of s that have a value of 0 are \"cba\", \"abz\", and, \"hey\".\nAmong all of them, we choose the lexicographically smallest.\n\nExample 2:\n\nInput: s = \"a?a?\"\nOutput: \"abac\"\nExplanation: In this example, the occurrences of '?' can be replaced to make s equal to \"abac\".\nFor \"abac\", cost(0) = 0, cost(1) = 0, cost(2) = 1, and cost(3) = 0.\nThe value of \"abac\" is 1.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s[i] is either a lowercase English letter or '?'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc??\") == \"aabbccde\"\n assert candidate(s = \"abcabcabc???\") == \"abcabcabcdef\"\n assert candidate(s = \"a????b\") == \"acdefb\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"????????\") == \"abcdefgh\"\n assert candidate(s = \"abacabadabacaba\") == \"abacabadabacaba\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz?\") == \"abcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"abc?de?\") == \"abcfdeg\"\n assert candidate(s = \"zzzz????\") == \"zzzzabcd\"\n assert candidate(s = \"a?????\") == \"abcdef\"\n assert candidate(s = \"??????????\") == \"abcdefghij\"\n assert candidate(s = \"aabbcc?\") == \"aabbccd\"\n assert candidate(s = \"???\") == \"abc\"\n assert candidate(s = \"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\") == \"aaaaaaaaabbbbbbbbbcccccccccdddddddddeeeeeeeeefffffffffggggggggghhhhhhhhhiiiiiiiiijjjjjjjjjkkkkkkkkklllllllllmmmmmmmmmnnnnnnnnnooooooooopppppppppqqqqqqqqqrrrrrrrrrssssssssstttttttttuuuuuuuuvvvvvvvvwwwwwwwwxxxxxxxxyyyyyyyyzzzzzzzz\"\n assert candidate(s = \"a????b????c????\") == \"adefgbhijkclmno\"\n assert candidate(s = \"a?a?\") == \"abac\"\n assert candidate(s = \"abc??\") == \"abcde\"\n assert candidate(s = \"z?y?x?w?v?u?t?s?r?q?p?o?n?m?l?k?j?i?h?g?f?e?d?c?b?a\") == \"zaybxcwdveuftgshriqjpkolnmmnlokpjqirhsgtfuevdwcxbya\"\n assert candidate(s = \"?????abc?????def?????ghi?????jkl?????mno?????pqr?????stu?????vwx?????yz?????\") == \"aabbcabccddeedefffgghghihiijjjklkkllmmnomnnoopqrppqqrsturssttvwxuuvvwyzwxxyz\"\n assert candidate(s = \"abc?def?ghi?\") == \"abcjdefkghil\"\n assert candidate(s = \"????????????????????????????????????????\") == \"aabbccddeeffgghhiijjkkllmmnnopqrstuvwxyz\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzz???\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzabc\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba????????\") == \"zyxwvutsrqponmlkjihgfedcbaabcdefgh\"\n assert candidate(s = \"a?b?c?d?e?f?g?h?i?j?k?l?m?n?o?p?q?r?s?t?u?v?w?x?y?z?\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc???\") == \"abcabcabcabcabcabcabcabcabcabcdef\"\n assert candidate(s = \"xyz?xyz?xyz?\") == \"xyzaxyzbxyzc\"\n assert candidate(s = \"a?????b?????c?????d?????e?????f?????g?????h?????i?????j?????k?????l?????m?????n?????o?????p?????q?????r?????s?????t?????u?????v?????w?????x?????y?????z?????\") == \"aaaaaabbbbbbccccccddddddeeeeeeffffffgggggghhhhhhiiiiiijjjjjjkkkkkkllllllmmmmmmnnnnnnooooooppppppqqqqqqrrrrrrssssssttttttuuuuuuvvvvvvwwwwwwxxxxxxyyyyyyzzzzzz\"\n assert candidate(s = \"abc?????def?????ghi?????\") == \"abcjklmndefopqrsghituvwx\"\n assert candidate(s = \"a?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?fa?b?c?d?e?f\") == \"agbgcgdhehfahbicidiejfajbjckdkekfalblcmdmenfanbocodpepfaqbqcrdresfasbtctdueufavbvcwdwexfaxbycydzezf\"\n assert candidate(s = \"aaaabbbbccccdddd????\") == \"aaaabbbbccccddddefgh\"\n assert candidate(s = \"aaaa?bbbb?cccc?dddd?eeee?ffff?gggg?hhhh?iiii?jjjj?kkkk?llll?mmmm?nnnn?oooo?pppp?qqqq?rrrr?ssss?tttt?uuuu?vvvv?wwww?xxxx?yyyy?zzzz?\") == \"aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrssssstttttuuuuuvvvvvwwwwwxxxxxyyyyyzzzzz\"\n assert candidate(s = \"abacabadabacabadabacabadabacabad?\") == \"abacabadabacabadabacabadabacabade\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz???\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabc\"\n assert candidate(s = \"zzzzzzzzzz???\") == \"zzzzzzzzzzabc\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc???\") == \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcdef\"\n assert candidate(s = \"zzzzzzzzzzzz????????????\") == \"zzzzzzzzzzzzabcdefghijkl\"\n assert candidate(s = \"???????????\") == \"abcdefghijk\"\n assert candidate(s = \"abcd?efg?hijk?lmn?opq?rstuvwxyz\") == \"abcdaefgbhijkclmndopqerstuvwxyz\"\n", "comparison": "exact"}, "public_tests": ["\"???\"", "\"a?a?\""], "hints": ["The cost does not depend on the order of characters. If a character c appears x times, the cost is exactly 0 + 1 + 2 + … + (x - 1) = x * (x - 1) / 2.", "We know the total number of question marks; for each one, we should select the letter with the minimum frequency to replace it.", "The letter selection can be achieved by a min-heap (or even by brute-forcing the 26 possibilities).", "So, we know the extra letters we need to replace finally. However, we must put those letters in order from left to right so that the resulting string is the lexicographically smallest one."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimizeStringValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:24+00:00", "tests_total": 38, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "greedy", "sorting", "heap-priority-queue", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimize_string_value(s)", "container": null, "callable": "minimize_string_value", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3082, "task_id": "find-the-sum-of-the-power-of-all-subsequences", "difficulty": "Hard", "problem_description": "You are given an integer array nums of length n and a positive integer k.\n\nThe power of an array of integers is defined as the number of subsequences with their sum equal to k.\n\nReturn the sum of power of all subsequences of nums.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: nums = [1,2,3], k = 3\nOutput: 6\nExplanation:\nThere are 5 subsequences of nums with non-zero power:\n- The subsequence [1,2,3] has 2 subsequences with sum == 3: [1,2,3] and [1,2,3].\n- The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n- The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n- The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n- The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].\n\nHence the answer is 2 + 1 + 1 + 1 + 1 = 6.\n\nExample 2:\n\nInput: nums = [2,3,3], k = 5\nOutput: 4\nExplanation:\nThere are 3 subsequences of nums with non-zero power:\n- The subsequence [2,3,3] has 2 subsequences with sum == 5: [2,3,3] and [2,3,3].\n- The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].\n- The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].\n\nHence the answer is 2 + 1 + 1 = 4.\n\nExample 3:\n\nInput: nums = [1,2,3], k = 7\nOutput: 0\nExplanation: There exists no subsequence with sum 7. Hence all subsequences of nums have power = 0.\n\nConstraints:\n\n- 1 <= n <= 100\n- 1 <= nums[i] <= 10^4\n- 1 <= k <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 40\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 15) == 8064\n assert candidate(nums = [1, 2, 4, 8, 16],k = 31) == 1\n assert candidate(nums = [10, 20, 30],k = 60) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],k = 90) == 16\n assert candidate(nums = [100, 200, 300],k = 100) == 4\n assert candidate(nums = [10, 20, 30, 40],k = 50) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 800\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 8064\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],k = 15) == 8\n assert candidate(nums = [2, 3, 3],k = 5) == 4\n assert candidate(nums = [1, 1, 1, 1],k = 2) == 24\n assert candidate(nums = [5, 5, 5, 5],k = 10) == 24\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 10\n assert candidate(nums = [5, 5, 5, 5, 5],k = 15) == 40\n assert candidate(nums = [2, 4, 6, 8, 10],k = 20) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],k = 8) == 592\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4],k = 6) == 256\n assert candidate(nums = [1, 2, 3],k = 7) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 512\n assert candidate(nums = [3, 6, 9, 12, 15],k = 21) == 20\n assert candidate(nums = [1, 2, 3],k = 3) == 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],k = 25) == 508035072\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],k = 25) == 991480774\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 52105216\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],k = 15) == 137887744\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 40) == 239616\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22],k = 60) == 1584\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) == 508035072\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 20) == 52105216\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 50) == 6717440\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 45) == 508035072\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 21) == 617366278\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6],k = 9) == 168\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) == 508035072\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],k = 30) == 126471695\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 30) == 2464\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],k = 15) == 219464424\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 20) == 508035072\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 80) == 29962240\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],k = 50) == 545703072\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 = 10) == 49807360\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 55) == 1984\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 2464\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],k = 10) == 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 = 50) == 43079680\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 4608\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 12845056\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 40) == 185344\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 50) == 313344\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 100) == 23942144\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],k = 5) == 853234987\n assert candidate(nums = [10, 20, 30, 40, 50],k = 60) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 12) == 17907712\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],k = 78) == 112\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 100) == 2272\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 100) == 7432192\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 = 25) == 508035072\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 100) == 23942144\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 50) == 11681792\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 = 50) == 43079680\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 50) == 138240\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],k = 15) == 624381870\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 = 20) == 317521920\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 30) == 1136\n assert candidate(nums = [5, 7, 1, 3, 9, 2, 8],k = 10) == 128\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 100) == 879122432\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 = 100) == 26176512\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 40) == 4882432\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],k = 30) == 394056145\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],k = 100) == 399689153\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],k = 15) == 707853125\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 25) == 1184\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 50) == 768\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 = 100) == 26176512\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],k = 15) == 407836790\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n3", "[2,3,3]\n5", "[1,2,3]\n7"], "hints": ["If there is a subsequence of length j with the sum of elements k, it contributes 2^{n - j} to the answer.", "Let dp[i][j] represent the number of subsequences in the subarray nums[0..i] which have a sum of j.", "We can find the dp[i][k] for all 0 <= i <= n-1 and multiply them with 2^{n - j} to get final answer."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().sumOfPower", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:26+00:00", "tests_total": 103, "tests_dropped": 26, "flags": [], "topic_tags": ["array", "dynamic-programming", "knapsack-problem", "0-1-knapsack"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_power(nums, k)", "container": null, "callable": "sum_of_power", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3083, "task_id": "existence-of-a-substring-in-a-string-and-its-reverse", "difficulty": "Easy", "problem_description": "Given a string s, find any substring of length 2 which is also present in the reverse of s.\n\nReturn true if such a substring exists, and false otherwise.\n\nExample 1:\n\nInput: s = \"leetcode\"\nOutput: true\nExplanation: Substring \"ee\" is of length 2 which is also present in reverse(s) == \"edocteel\".\n\nExample 2:\n\nInput: s = \"abcba\"\nOutput: true\nExplanation: All of the substrings of length 2 \"ab\", \"bc\", \"cb\", \"ba\" are also present in reverse(s) == \"abcba\".\n\nExample 3:\n\nInput: s = \"abcd\"\nOutput: false\nExplanation: There is no substring of length 2 in s, which is also present in the reverse of s.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == True\n assert candidate(s = \"deified\") == True\n assert candidate(s = \"abab\") == True\n assert candidate(s = \"ab\") == False\n assert candidate(s = \"mnopqr\") == False\n assert candidate(s = \"aa\") == True\n assert candidate(s = \"rotor\") == True\n assert candidate(s = \"zzz\") == True\n assert candidate(s = \"leetcode\") == True\n assert candidate(s = \"racecar\") == True\n assert candidate(s = \"aabb\") == True\n assert candidate(s = \"gfedcba\") == False\n assert candidate(s = \"world\") == False\n assert candidate(s = \"noon\") == True\n assert candidate(s = \"reviled\") == False\n assert candidate(s = \"abcd\") == False\n assert candidate(s = \"hello\") == True\n assert candidate(s = \"aabbcc\") == True\n assert candidate(s = \"level\") == True\n assert candidate(s = \"abcdefg\") == False\n assert candidate(s = \"xyzzxyzzxyzz\") == True\n assert candidate(s = \"detartrateddetartrated\") == True\n assert candidate(s = \"repaperrepaper\") == True\n assert candidate(s = \"xyzzyxxyzzyx\") == True\n assert candidate(s = \"referrefer\") == True\n assert candidate(s = \"rotorrotor\") == True\n assert candidate(s = \"abracadabra\") == True\n assert candidate(s = \"noonnoon\") == True\n assert candidate(s = \"reviverreviver\") == True\n assert candidate(s = \"deifieddeifieddeified\") == True\n assert candidate(s = \"abacaxabacax\") == True\n assert candidate(s = \"palindromemordnilap\") == True\n assert candidate(s = \"stepikiktepset\") == True\n assert candidate(s = \"qwertyuiopoiuytrewq\") == True\n assert candidate(s = \"algorithm\") == False\n assert candidate(s = \"abccbaabccba\") == True\n assert candidate(s = \"redder\") == True\n assert candidate(s = \"repelrepel\") == True\n assert candidate(s = \"noonnoonnoonnoon\") == True\n assert candidate(s = \"xyzzyx\") == True\n assert candidate(s = \"peep\") == True\n assert candidate(s = \"abacaba\") == True\n assert candidate(s = \"tamelephant\") == True\n assert candidate(s = \"rotavator\") == True\n assert candidate(s = \"revolver\") == True\n assert candidate(s = \"qwertyuioplkjhgfdsazxcvbnmnbvcxzgfdsahjklpoiuytrewq\") == True\n assert candidate(s = \"helloolleh\") == True\n assert candidate(s = \"palindrome\") == False\n assert candidate(s = \"dessertsstressed\") == True\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == False\n assert candidate(s = \"kayak\") == True\n assert candidate(s = \"abccbaabccbaabccba\") == True\n assert candidate(s = \"levelup\") == True\n assert candidate(s = \"deedeed\") == True\n assert candidate(s = \"sagassagasagasag\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(s = \"semordnilap\") == False\n assert candidate(s = \"reviler\") == True\n assert candidate(s = \"nursesrun\") == True\n assert candidate(s = \"abcdeffedcba\") == True\n assert candidate(s = \"wasitacaroracatisaw\") == True\n assert candidate(s = \"levellevel\") == True\n assert candidate(s = \"aibohphobia\") == True\n assert candidate(s = \"stepontostep\") == False\n assert candidate(s = \"programming\") == True\n assert candidate(s = \"aabbccdd\") == True\n assert candidate(s = \"madam\") == True\n assert candidate(s = \"desserts\") == True\n assert candidate(s = \"refer\") == True\n assert candidate(s = \"radar\") == True\n assert candidate(s = \"abcdefgihgfedcba\") == True\n assert candidate(s = \"xyzyx\") == True\n assert candidate(s = \"repelrepelrepel\") == True\n assert candidate(s = \"redivider\") == True\n assert candidate(s = \"redderredder\") == True\n assert candidate(s = \"racecarabc\") == True\n assert candidate(s = \"abcdabcddcbaabcd\") == True\n assert candidate(s = \"abba\") == True\n assert candidate(s = \"abcdefgfedcba\") == True\n assert candidate(s = \"banana\") == True\n assert candidate(s = \"abcdefghijutsavajihgfedcba\") == True\n assert candidate(s = \"ananab\") == True\n assert candidate(s = \"aabbccddeeffgg\") == True\n assert candidate(s = \"detartrated\") == True\n assert candidate(s = \"civiccivic\") == True\n assert candidate(s = \"abccba\") == True\n assert candidate(s = \"aabbccddeeff\") == True\n assert candidate(s = \"xyzzyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(s = \"xyzyzyzyx\") == True\n assert candidate(s = \"reviver\") == True\n assert candidate(s = \"madamimadam\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s = \"aabbccddeeffgghhiijj\") == True\n assert candidate(s = \"zxcvbnmlkjhgfdsapoiuytrewq\") == False\n assert candidate(s = \"amanaplanacanalpanama\") == True\n assert candidate(s = \"sagasagasag\") == True\n assert candidate(s = \"racecarracecar\") == True\n assert candidate(s = \"noonnoonnoon\") == True\n assert candidate(s = \"repaper\") == True\n assert candidate(s = \"abcdedcba\") == True\n assert candidate(s = \"hellokayak\") == True\n assert candidate(s = \"stressed\") == True\n assert candidate(s = \"ababababab\") == True\n assert candidate(s = \"deifieddeified\") == True\n assert candidate(s = \"elephanttame\") == True\n assert candidate(s = \"civic\") == True\n assert candidate(s = \"abcdefghihgfedcba\") == True\n assert candidate(s = \"xyzyxzyxzyx\") == True\n assert candidate(s = \"xyxzyx\") == True\n assert candidate(s = \"abacaxa\") == True\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\") == True\n assert candidate(s = \"abacabadaba\") == True\n assert candidate(s = \"xyzyxzyx\") == True\n assert candidate(s = \"tacocat\") == True\n assert candidate(s = \"thisisatest\") == True\n assert candidate(s = \"mississippi\") == True\n assert candidate(s = \"xyzyxyzyx\") == True\n assert candidate(s = \"testset\") == True\n assert candidate(s = \"deed\") == True\n assert candidate(s = \"abacaxaba\") == True\n assert candidate(s = \"asdfghjklkljhgfdsa\") == True\n", "comparison": "exact"}, "public_tests": ["\"leetcode\"", "\"abcba\"", "\"abcd\""], "hints": ["Make a new string by reversing the string s.", "For every substring of length 2 in s, check if there is a corresponding substring in the reverse of s."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().isSubstringPresent", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:28+00:00", "tests_total": 122, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "ruby", "interface": {"raw_signature": "def is_substring_present(s)", "container": null, "callable": "is_substring_present", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3084, "task_id": "count-substrings-starting-and-ending-with-given-character", "difficulty": "Medium", "problem_description": "You are given a string s and a character c. Return the total number of substrings of s that start and end with c.\n\nExample 1:\n\nInput: s = \"abada\", c = \"a\"\nOutput: 6\nExplanation: Substrings starting and ending with \"a\" are: \"abada\", \"abada\", \"abada\", \"abada\", \"abada\", \"abada\".\n\nExample 2:\n\nInput: s = \"zzz\", c = \"z\"\nOutput: 6\nExplanation: There are a total of 6 substrings in s and all start and end with \"z\".\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s and c consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzz\",c = \"z\") == 6\n assert candidate(s = \"abcabcabc\",c = \"b\") == 6\n assert candidate(s = \"abcdefg\",c = \"f\") == 1\n assert candidate(s = \"abcabcabc\",c = \"a\") == 6\n assert candidate(s = \"hello\",c = \"l\") == 3\n assert candidate(s = \"xyz\",c = \"a\") == 0\n assert candidate(s = \"aaaaa\",c = \"a\") == 15\n assert candidate(s = \"abc\",c = \"a\") == 1\n assert candidate(s = \"abcabcabc\",c = \"c\") == 6\n assert candidate(s = \"aaa\",c = \"a\") == 6\n assert candidate(s = \"abada\",c = \"a\") == 6\n assert candidate(s = \"mississippi\",c = \"i\") == 10\n assert candidate(s = \"lalalalalalalala\",c = \"l\") == 36\n assert candidate(s = \"aabaaacaaadaaae\",c = \"e\") == 1\n assert candidate(s = \"bcbcbcbcb\",c = \"b\") == 15\n assert candidate(s = \"aabbccddeeff\",c = \"f\") == 3\n assert candidate(s = \"lkjkljkljkljklj\",c = \"k\") == 15\n assert candidate(s = \"repeatedcharactersrepeatedcharacters\",c = \"r\") == 21\n assert candidate(s = \"abcbcbcbc\",c = \"b\") == 10\n assert candidate(s = \"acbacbacbacbacbac\",c = \"a\") == 21\n assert candidate(s = \"racecar\",c = \"r\") == 3\n assert candidate(s = \"abababababa\",c = \"b\") == 15\n assert candidate(s = \"xyzzyxzyzxzyz\",c = \"z\") == 21\n assert candidate(s = \"pppppppppppp\",c = \"p\") == 78\n assert candidate(s = \"abcdefghijk\",c = \"j\") == 1\n assert candidate(s = \"pqrsrqpqrsrqpqrs\",c = \"r\") == 15\n assert candidate(s = \"bookkeeper\",c = \"e\") == 6\n assert candidate(s = \"aaaabbbcccddd\",c = \"b\") == 6\n assert candidate(s = \"noonnoonnoon\",c = \"n\") == 21\n assert candidate(s = \"xyxzyxzyxzyxzyx\",c = \"y\") == 15\n assert candidate(s = \"aaaaabaaaa\",c = \"a\") == 45\n assert candidate(s = \"aabbccddeeffgg\",c = \"g\") == 3\n assert candidate(s = \"banana\",c = \"a\") == 6\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",c = \"z\") == 990\n assert candidate(s = \"bbaabbaabbaa\",c = \"b\") == 21\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\",c = \"m\") == 3\n assert candidate(s = \"bananabananabanana\",c = \"a\") == 45\n assert candidate(s = \"aabbccddeeffgg\",c = \"b\") == 3\n assert candidate(s = \"abacabadabacaba\",c = \"a\") == 36\n assert candidate(s = \"aaaaabaaa\",c = \"a\") == 36\n assert candidate(s = \"qwertyuiop\",c = \"q\") == 1\n assert candidate(s = \"ababababab\",c = \"b\") == 15\n assert candidate(s = \"xyxzyxzyx\",c = \"x\") == 10\n assert candidate(s = \"abcdefghij\",c = \"a\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzz\",c = \"z\") == 153\n assert candidate(s = \"hellohellohello\",c = \"o\") == 6\n assert candidate(s = \"hello\",c = \"o\") == 1\n assert candidate(s = \"abcdefgabcdefgabcdefg\",c = \"d\") == 6\n assert candidate(s = \"qqwweerrttyyuuiioopp\",c = \"q\") == 3\n assert candidate(s = \"aabacabaa\",c = \"a\") == 21\n assert candidate(s = \"lkjlkjlkjlkj\",c = \"l\") == 10\n assert candidate(s = \"aaabaaaabaaaa\",c = \"a\") == 66\n assert candidate(s = \"aabbccddeeff\",c = \"d\") == 3\n assert candidate(s = \"aabbccddeeff\",c = \"c\") == 3\n assert candidate(s = \"abcdabcde\",c = \"d\") == 3\n assert candidate(s = \"aaaaabbbbbb\",c = \"b\") == 21\n assert candidate(s = \"ananananananananana\",c = \"n\") == 45\n assert candidate(s = \"abcababcabcab\",c = \"b\") == 15\n assert candidate(s = \"abacaba\",c = \"a\") == 10\n assert candidate(s = \"xyxzxyxzyzx\",c = \"x\") == 15\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaa\",c = \"a\") == 351\n assert candidate(s = \"hellohellobyehello\",c = \"o\") == 6\n assert candidate(s = \"zzzzzzzzzzzzz\",c = \"z\") == 91\n assert candidate(s = \"aninterestingproblem\",c = \"n\") == 6\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",c = \"i\") == 6\n assert candidate(s = \"llllllllllllllllllllllllll\",c = \"l\") == 351\n assert candidate(s = \"bcbcbcbcbcb\",c = \"b\") == 21\n assert candidate(s = \"bababababababa\",c = \"b\") == 28\n assert candidate(s = \"abcdefghefghijklmnopqrstuvwxyz\",c = \"a\") == 1\n assert candidate(s = \"abcdefghi\",c = \"a\") == 1\n assert candidate(s = \"aaaaabaaaaa\",c = \"a\") == 55\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\",c = \"q\") == 3\n assert candidate(s = \"abcdefghij\",c = \"j\") == 1\n assert candidate(s = \"thisisaverylongstringwithseveralcharacters\",c = \"t\") == 10\n assert candidate(s = \"abcdefghigklmnopqrstuvwxyz\",c = \"a\") == 1\n assert candidate(s = \"xyzzzyzxzyzxzyz\",c = \"z\") == 36\n assert candidate(s = \"zzzzzzzzzz\",c = \"z\") == 55\n assert candidate(s = \"xyzyxzyzxzyzx\",c = \"x\") == 10\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",c = \"z\") == 3\n assert candidate(s = \"xyzxyzxyzxyz\",c = \"x\") == 10\n assert candidate(s = \"abacabadaba\",c = \"a\") == 21\n assert candidate(s = \"programming\",c = \"m\") == 3\n assert candidate(s = \"aaabaaa\",c = \"a\") == 21\n assert candidate(s = \"anananananan\",c = \"a\") == 21\n assert candidate(s = \"cccccccccc\",c = \"c\") == 55\n assert candidate(s = \"cccccccccccccccccc\",c = \"c\") == 171\n assert candidate(s = \"xyzxyzxyz\",c = \"z\") == 6\n assert candidate(s = \"zazazazazaz\",c = \"z\") == 21\n assert candidate(s = \"abcdefghigklmnopqrstuvwxyz\",c = \"z\") == 1\n assert candidate(s = \"aabaaacaaadaaae\",c = \"a\") == 66\n assert candidate(s = \"bcbcbcbc\",c = \"b\") == 10\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",c = \"a\") == 0\n assert candidate(s = \"aabbccddeeffaabbccddeeff\",c = \"d\") == 10\n assert candidate(s = \"abcdefabcdefabcdef\",c = \"f\") == 6\n assert candidate(s = \"abracadabra\",c = \"a\") == 15\n assert candidate(s = \"aaaaaaaaaaaaaa\",c = \"a\") == 105\n assert candidate(s = \"popcornpopcorn\",c = \"p\") == 10\n assert candidate(s = \"xyxxyxyxy\",c = \"x\") == 15\n assert candidate(s = \"bbbbbbbbbb\",c = \"b\") == 55\n assert candidate(s = \"abcdefg\",c = \"g\") == 1\n assert candidate(s = \"hellohellohellohello\",c = \"l\") == 36\n assert candidate(s = \"abcdeabcdeabcde\",c = \"a\") == 6\n assert candidate(s = \"abcdefhijklmnopqrstuvwxyz\",c = \"z\") == 1\n assert candidate(s = \"aabbccddeeff\",c = \"b\") == 3\n", "comparison": "exact"}, "public_tests": ["\"abada\"\n\"a\"", "\"zzz\"\n\"z\""], "hints": ["Count the number of characters 'c' in string s, let’s call it m.", "We can select 2 numbers i and j such that i <= j are the start and end indices of substring. Note that i and j can be the same.", "The answer is m * (m + 1) / 2."], "metadata": {"canonical_parameter_names": ["s", "c"], "leetcode_dataset_entry_point": "Solution().countSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:30+00:00", "tests_total": 105, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def count_substrings(s, c)", "container": null, "callable": "count_substrings", "parameters": [{"name": "s", "type": "String"}, {"name": "c", "type": "Character"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3085, "task_id": "minimum-deletions-to-make-string-k-special", "difficulty": "Medium", "problem_description": "You are given a string word and an integer k.\n\nWe consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the string.\n\nHere, freq(x) denotes the frequency of the character x in word, and |y| denotes the absolute value of y.\n\nReturn the minimum number of characters you need to delete to make word k-special.\n\nExample 1:\n\nInput: word = \"aabcaba\", k = 0\nOutput: 3\nExplanation: We can make word 0-special by deleting 2 occurrences of \"a\" and 1 occurrence of \"c\". Therefore, word becomes equal to \"baba\" where freq('a') == freq('b') == 2.\n\nExample 2:\n\nInput: word = \"dabdcbdcdcd\", k = 2\nOutput: 2\nExplanation: We can make word 2-special by deleting 1 occurrence of \"a\" and 1 occurrence of \"d\". Therefore, word becomes equal to \"bdcbdcdcd\" where freq('b') == 2, freq('c') == 3, and freq('d') == 4.\n\nExample 3:\n\nInput: word = \"aaabaaa\", k = 2\nOutput: 1\nExplanation: We can make word 2-special by deleting 1 occurrence of \"b\". Therefore, word becomes equal to \"aaaaaa\" where each letter's frequency is now uniformly 6.\n\nConstraints:\n\n- 1 <= word.length <= 10^5\n- 0 <= k <= 10^5\n- word consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"abacabadaba\",k = 2) == 3\n assert candidate(word = \"abacabadabacaba\",k = 3) == 4\n assert candidate(word = \"xyz\",k = 0) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 10) == 0\n assert candidate(word = \"abcabcabc\",k = 1) == 0\n assert candidate(word = \"mnbvcxzlkjhgfdsapoiuytrewq\",k = 5) == 0\n assert candidate(word = \"aabcaba\",k = 0) == 3\n assert candidate(word = \"dabdcbdcdcd\",k = 2) == 2\n assert candidate(word = \"zzzzz\",k = 0) == 0\n assert candidate(word = \"aaabaaa\",k = 2) == 1\n assert candidate(word = \"abcdabcdabcd\",k = 1) == 0\n assert candidate(word = \"aaaaa\",k = 0) == 0\n assert candidate(word = \"xyz\",k = 1) == 0\n assert candidate(word = \"abcde\",k = 3) == 0\n assert candidate(word = \"abacabadabacaba\",k = 1) == 6\n assert candidate(word = \"qqwweerrttyyuuiioopp\",k = 2) == 0\n assert candidate(word = \"aabcccdddd\",k = 1) == 2\n assert candidate(word = \"xyxxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\",k = 2) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 0) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 0\n assert candidate(word = \"lkjghwertyuiopasdfghjklzxcvbnmlkjhgfdwsazxcvbnmlkjhgfdwsazxcvbnmlkjhgfdwsa\",k = 15) == 0\n assert candidate(word = \"zzzzzyyyyyxxxxxwwwwvvvvuttttssssrrrrqqqqppppooooonnnnmmmmmllllkkkkjjjjiiiihhhhggggffffffeeeeee\",k = 5) == 0\n assert candidate(word = \"xyzzzzzzzzzyxyzzzzzzzzzyxyzzzzzzzzzy\",k = 5) == 9\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 3) == 0\n assert candidate(word = \"mnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewq\",k = 8) == 0\n assert candidate(word = \"aaabbbcccddddeeeffffffgggggggg\",k = 4) == 1\n assert candidate(word = \"thisisanexamplestringwithvariousfrequencies\",k = 3) == 4\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 5) == 0\n assert candidate(word = \"almosteveryletterisusedbutnotallabcdefghijklmnopqrstuvwxyzzzzzzzzzzz\",k = 2) == 17\n assert candidate(word = \"thisisaverylongwordthatcontainsmanycharactersandneedscomplexprocessing\",k = 10) == 0\n assert candidate(word = \"aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbcccccccccccccccc\",k = 2) == 0\n assert candidate(word = \"aaaaaaaaaaabbbbbbbbbbbccccccccccdddddddddd\",k = 5) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 25) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzz\",k = 0) == 0\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",k = 0) == 0\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzz\",k = 5) == 4\n assert candidate(word = \"aaaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeffffffffggggggghhhhhhhhiiiiiiiiii\",k = 3) == 0\n assert candidate(word = \"unevenfrequenciesaxbxcxdxeuxyvxuyvyvxvyvxvyvxvyvxvyvxvyvxyvxyvxyvxyvxyvxyvxyvxyvxyvxyvxyvxy\",k = 10) == 23\n assert candidate(word = \"aaaaaabbbccccdddddeeeeeffffffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\",k = 5) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzz\",k = 1) == 17\n assert candidate(word = \"abcdefghij\",k = 0) == 0\n assert candidate(word = \"ppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxxyyyyyyyyyyzzzzzzzzzz\",k = 10) == 0\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\",k = 10) == 0\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 10) == 0\n assert candidate(word = \"verylongstringwithrepeatingcharactersaaaaaaaaaabbbbbbbbbbcccccccccc\",k = 4) == 20\n assert candidate(word = \"ppppppppppppppppppppppppppppppppppppppppppppppppppppp\",k = 0) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1) == 0\n assert candidate(word = \"abcdeabcdabcdeabcdeabcdeabcdeabcde\",k = 2) == 0\n assert candidate(word = \"ppppqqqqrrrsssttttuuuuvvvvwwwwxxxxxyyyyyzzzzzaaaaabbbbccccddddeeeeffffgggghhhhiiii\",k = 5) == 0\n assert candidate(word = \"aabbaaccddccbbbaaadddcccbbaaa\",k = 1) == 6\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 0) == 0\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabc\",k = 1) == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzqqqqqqqqqq\",k = 4) == 6\n", "comparison": "exact"}, "public_tests": ["\"aabcaba\"\n0", "\"dabdcbdcdcd\"\n2", "\"aaabaaa\"\n2"], "hints": ["Count the frequency of each letter.", "Suppose we select several characters as the final answer, and let x be the character with the smallest frequency in the answer. It can be shown that out of the selected characters, the optimal solution will never delete an occurrence of character x to obtain the answer.", "We will fix a character c and assume that it will be the character with the smallest frequency in the answer. Suppose its frequency is x.", "Then, for every other character, we will count the number of occurrences that will be deleted. Suppose that the current character has y occurrences.\n1. If y < x, we need to delete all of them.\n2. if y > x + k, we should delete y - x - k of such character.\n3. Otherwise we don’t need to delete it."], "metadata": {"canonical_parameter_names": ["word", "k"], "leetcode_dataset_entry_point": "Solution().minimumDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:33+00:00", "tests_total": 53, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "greedy", "sorting", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_deletions(word, k)", "container": null, "callable": "minimum_deletions", "parameters": [{"name": "word", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3086, "task_id": "minimum-moves-to-pick-k-ones", "difficulty": "Hard", "problem_description": "You are given a binary array nums of length n, a positive integer k and a non-negative integer maxChanges.\n\nAlice plays a game, where the goal is for Alice to pick up k ones from nums using the minimum number of moves. When the game starts, Alice picks up any index aliceIndex in the range [0, n - 1] and stands there. If nums[aliceIndex] == 1 , Alice picks up the one and nums[aliceIndex] becomes 0(this does not count as a move). After this, Alice can make any number of moves (including zero) where in each move Alice must perform exactly one of the following actions:\n\n- Select any index j != aliceIndex such that nums[j] == 0 and set nums[j] = 1. This action can be performed at most maxChanges times.\n- Select any two adjacent indices x and y (|x - y| == 1) such that nums[x] == 1, nums[y] == 0, then swap their values (set nums[y] = 1 and nums[x] = 0). If y == aliceIndex, Alice picks up the one after this move and nums[y] becomes 0.\n\nReturn the minimum number of moves required by Alice to pick exactly k ones.\n\nExample 1:\n\nInput: nums = [1,1,0,0,0,1,1,0,0,1], k = 3, maxChanges = 1\nOutput: 3\nExplanation: Alice can pick up 3 ones in 3 moves, if Alice performs the following actions in each move when standing at aliceIndex == 1:\n- At the start of the game Alice picks up the one and nums[1] becomes 0. nums becomes [1,0,0,0,0,1,1,0,0,1].\n- Select j == 2 and perform an action of the first type. nums becomes [1,0,1,0,0,1,1,0,0,1]\n- Select x == 2 and y == 1, and perform an action of the second type. nums becomes [1,1,0,0,0,1,1,0,0,1]. As y == aliceIndex, Alice picks up the one and nums becomes [1,0,0,0,0,1,1,0,0,1].\n- Select x == 0 and y == 1, and perform an action of the second type. nums becomes [0,1,0,0,0,1,1,0,0,1]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0,0,1,1,0,0,1].\n\nNote that it may be possible for Alice to pick up 3 ones using some other sequence of 3 moves.\n\nExample 2:\n\nInput: nums = [0,0,0,0], k = 2, maxChanges = 3\nOutput: 4\nExplanation: Alice can pick up 2 ones in 4 moves, if Alice performs the following actions in each move when standing at aliceIndex == 0:\n- Select j == 1 and perform an action of the first type. nums becomes [0,1,0,0].\n- Select x == 1 and y == 0, and perform an action of the second type. nums becomes [1,0,0,0]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0].\n- Select j == 1 again and perform an action of the first type. nums becomes [0,1,0,0].\n- Select x == 1 and y == 0 again, and perform an action of the second type. nums becomes [1,0,0,0]. As y == aliceIndex, Alice picks up the one and nums becomes [0,0,0,0].\n\nConstraints:\n\n- 2 <= n <= 10^5\n- 0 <= nums[i] <= 1\n- 1 <= k <= 10^5\n- 0 <= maxChanges <= 10^5\n- maxChanges + sum(nums) >= k\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5,maxChanges = 5) == 8\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 0, 0, 0, 1],k = 3,maxChanges = 2) == 3\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2,maxChanges = 1) == 2\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 0, 1, 0],k = 2,maxChanges = 1) == 2\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1,maxChanges = 0) == 0\n assert candidate(nums = [0, 0, 0, 0],k = 2,maxChanges = 3) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 4,maxChanges = 0) == 8\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 0, 0, 1],k = 3,maxChanges = 1) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,maxChanges = 3) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],k = 5,maxChanges = 5) == 6\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5,maxChanges = 0) == 12\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],k = 5,maxChanges = 5) == 6\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0],k = 2,maxChanges = 1) == 2\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 5,maxChanges = 2) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,maxChanges = 0) == 6\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 12,maxChanges = 7) == 26\n assert candidate(nums = [1, 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, 1],k = 2,maxChanges = 1) == 2\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],k = 15,maxChanges = 20) == 28\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 10,maxChanges = 5) == 22\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1],k = 7,maxChanges = 3) == 13\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1],k = 6,maxChanges = 3) == 8\n assert candidate(nums = [0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],k = 4,maxChanges = 2) == 9\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0],k = 4,maxChanges = 2) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 10,maxChanges = 5) == 22\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],k = 5,maxChanges = 3) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 7,maxChanges = 10) == 10\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1],k = 4,maxChanges = 0) == 12\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],k = 5,maxChanges = 5) == 8\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 20,maxChanges = 15) == 42\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 15,maxChanges = 5) == 85\n assert candidate(nums = [1, 1, 0, 0, 1, 0, 1, 0, 1, 0],k = 4,maxChanges = 0) == 9\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],k = 4,maxChanges = 10) == 4\n assert candidate(nums = [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],k = 10,maxChanges = 5) == 22\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],k = 2,maxChanges = 0) == 1\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 6,maxChanges = 2) == 12\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],k = 15,maxChanges = 5) == 35\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 7,maxChanges = 2) == 16\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 4,maxChanges = 5) == 4\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0],k = 10,maxChanges = 5) == 22\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],k = 3,maxChanges = 2) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 4,maxChanges = 2) == 6\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5,maxChanges = 3) == 8\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],k = 5,maxChanges = 5) == 8\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],k = 6,maxChanges = 3) == 8\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5,maxChanges = 25) == 8\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],k = 2,maxChanges = 5) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2,maxChanges = 2) == 2\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 3,maxChanges = 0) == 19\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 0, 0, 1, 0],k = 3,maxChanges = 2) == 3\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1],k = 3,maxChanges = 1) == 5\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 4,maxChanges = 1) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1],k = 1,maxChanges = 0) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],k = 2,maxChanges = 0) == 1\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 3,maxChanges = 0) == 2\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 0, 1, 0],k = 2,maxChanges = 2) == 2\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 1, 1, 1],k = 3,maxChanges = 0) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0],k = 3,maxChanges = 3) == 4\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 1, 1],k = 4,maxChanges = 2) == 4\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],k = 4,maxChanges = 2) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],k = 5,maxChanges = 1) == 6\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],k = 4,maxChanges = 3) == 6\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2,maxChanges = 0) == 60\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 4,maxChanges = 0) == 12\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 3,maxChanges = 0) == 2\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 4,maxChanges = 2) == 6\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3,maxChanges = 1) == 4\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1],k = 2,maxChanges = 1) == 1\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 4,maxChanges = 1) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 1,maxChanges = 1) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 25,maxChanges = 10) == 76\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 6,maxChanges = 4) == 10\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],k = 4,maxChanges = 2) == 8\n assert candidate(nums = [1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],k = 4,maxChanges = 2) == 5\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1,maxChanges = 10) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 3,maxChanges = 1) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 6,maxChanges = 4) == 10\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 6,maxChanges = 0) == 27\n assert candidate(nums = [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1],k = 5,maxChanges = 3) == 7\n assert candidate(nums = [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, 1, 0, 1],k = 10,maxChanges = 0) == 50\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,maxChanges = 10) == 6\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2,maxChanges = 1) == 1\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],k = 3,maxChanges = 1) == 7\n assert candidate(nums = [1, 1, 1, 1, 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, 1, 1, 1, 1],k = 8,maxChanges = 4) == 12\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 4,maxChanges = 0) == 4\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 1,maxChanges = 5) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5,maxChanges = 10) == 6\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],k = 5,maxChanges = 10) == 8\n assert candidate(nums = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0],k = 25,maxChanges = 30) == 47\n assert candidate(nums = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],k = 3,maxChanges = 2) == 4\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],k = 5,maxChanges = 1) == 15\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 10,maxChanges = 3) == 30\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1],k = 7,maxChanges = 5) == 11\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 5,maxChanges = 0) == 12\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],k = 8,maxChanges = 3) == 22\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3,maxChanges = 2) == 4\n", "comparison": "exact"}, "public_tests": ["[1,1,0,0,0,1,1,0,0,1]\n3\n1", "[0,0,0,0]\n2\n3"], "hints": ["Ones created using a change require 2 moves. Hence except for the immediate neighbors of the index where we move all the ones, we should try to use change operations.", "For some subset of ones, it is always better to move the ones to the median position.", "We only need to be concerned with the indices where nums[i] == 1."], "metadata": {"canonical_parameter_names": ["nums", "k", "maxChanges"], "leetcode_dataset_entry_point": "Solution().minimumMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:35+00:00", "tests_total": 95, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sliding-window", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_moves(nums, k, max_changes)", "container": null, "callable": "minimum_moves", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}, {"name": "max_changes", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3090, "task_id": "maximum-length-substring-with-two-occurrences", "difficulty": "Easy", "problem_description": "Given a string s, return the maximum length of a substring such that it contains at most two occurrences of each character.\n\nExample 1:\n\nInput: s = \"bcbbbcba\"\nOutput: 4\nExplanation:\nThe following substring has a length of 4 and contains at most two occurrences of each character: \"bcbbbcba\".\n\nExample 2:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation:\nThe following substring has a length of 2 and contains at most two occurrences of each character: \"aaaa\".\n\nConstraints:\n\n- 2 <= s.length <= 100\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 2\n assert candidate(s = \"aaabbbccc\") == 4\n assert candidate(s = \"aabbaa\") == 4\n assert candidate(s = \"abababab\") == 4\n assert candidate(s = \"aabacbebebe\") == 6\n assert candidate(s = \"abacabadabacaba\") == 5\n assert candidate(s = \"abab\") == 4\n assert candidate(s = \"abcabcabc\") == 6\n assert candidate(s = \"aabbc\") == 5\n assert candidate(s = \"aabacbacbac\") == 6\n assert candidate(s = \"ababababab\") == 4\n assert candidate(s = \"abcabc\") == 6\n assert candidate(s = \"aabb\") == 4\n assert candidate(s = \"zzzzyyxx\") == 6\n assert candidate(s = \"xyzxyzxyz\") == 6\n assert candidate(s = \"bcbbbcba\") == 4\n assert candidate(s = \"zzzzzzzzzz\") == 2\n assert candidate(s = \"zzzzzzzzzzzz\") == 2\n assert candidate(s = \"abacabad\") == 5\n assert candidate(s = \"abababababab\") == 4\n assert candidate(s = \"aabbccddeeffgg\") == 14\n assert candidate(s = \"aaabbb\") == 4\n assert candidate(s = \"aaaa\") == 2\n assert candidate(s = \"aabbccddeeffgghh\") == 16\n assert candidate(s = \"aabbccddeeff\") == 12\n assert candidate(s = \"abcdeabcde\") == 10\n assert candidate(s = \"aabbcc\") == 6\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 52\n assert candidate(s = \"aabbccddeeffgghhiijj\") == 20\n assert candidate(s = \"abacaba\") == 5\n assert candidate(s = \"abcdefg\") == 7\n assert candidate(s = \"aaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbb\") == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzz\") == 52\n assert candidate(s = \"aabbaaabbbaaaabbbaaaa\") == 4\n assert candidate(s = \"abacabadabacabadabacaba\") == 5\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 20\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"aaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbcccc\") == 4\n assert candidate(s = \"mnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrs\") == 14\n assert candidate(s = \"abcdabcdeabcdabcdeabcdabcdeabcdabcdeabcdabcdeabcdabcdeabcdabcdeabcdabcdabcdabcd\") == 10\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabb\") == 4\n assert candidate(s = \"abcdefghijklaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 52\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 52\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 20\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyxwvutsrqponmlkjihgfedcba\") == 52\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 2\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\") == 4\n assert candidate(s = \"xyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzzyxyzzz\") == 5\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabad\") == 5\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnoooppqqrrrsssttuuvvwwxxyyzz\") == 16\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzz\") == 27\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 52\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 52\n assert candidate(s = \"zzzzzyzyzyzyzyzyzy\") == 4\n assert candidate(s = \"abcabcbacbacbabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef\") == 12\n assert candidate(s = \"abcabcabcabcabcabc\") == 6\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 2\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 52\n assert candidate(s = \"aabccddeeffaabbccddeeffaabbccddeeff\") == 12\n assert candidate(s = \"abcdefghijklmnopqrstuvabcdefghijklmnopqrstuv\") == 44\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba\") == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzz\") == 52\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzz\") == 52\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"abcabcabcabcabc\") == 6\n assert candidate(s = \"abcdaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 52\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 8\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 6\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 20\n", "comparison": "exact"}, "public_tests": ["\"bcbbbcba\"", "\"aaaa\""], "hints": ["We can try all substrings by brute-force since the constraints are very small."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maximumLengthSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:40+00:00", "tests_total": 78, "tests_dropped": 3, "flags": [], "topic_tags": ["hash-table", "string", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length_substring(s)", "container": null, "callable": "maximum_length_substring", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3091, "task_id": "apply-operations-to-make-sum-of-array-greater-than-or-equal-to-k", "difficulty": "Medium", "problem_description": "You are given a positive integer k. Initially, you have an array nums = [1].\n\nYou can perform any of the following operations on the array any number of times (possibly zero):\n\n- Choose any element in the array and increase its value by 1.\n- Duplicate any element in the array and add it to the end of the array.\n\nReturn the minimum number of operations required to make the sum of elements of the final array greater than or equal to k.\n\nExample 1:\n\nInput: k = 11\nOutput: 5\nExplanation:\nWe can do the following operations on the array nums = [1]:\n- Increase the element by 1 three times. The resulting array is nums = [4].\n- Duplicate the element two times. The resulting array is nums = [4,4,4].\n\nThe sum of the final array is 4 + 4 + 4 = 12 which is greater than or equal to k = 11.\nThe total number of operations performed is 3 + 2 = 5.\n\nExample 2:\n\nInput: k = 1\nOutput: 0\nExplanation:\nThe sum of the original array is already greater than or equal to 1, so no operations are needed.\n\nConstraints:\n\n- 1 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(k = 100) == 18\n assert candidate(k = 20) == 7\n assert candidate(k = 1) == 0\n assert candidate(k = 15) == 6\n assert candidate(k = 11) == 5\n assert candidate(k = 3) == 2\n assert candidate(k = 100000) == 631\n assert candidate(k = 5) == 3\n assert candidate(k = 10) == 5\n assert candidate(k = 29) == 9\n assert candidate(k = 30) == 9\n assert candidate(k = 101) == 19\n assert candidate(k = 2048) == 89\n assert candidate(k = 1024) == 62\n assert candidate(k = 9999) == 198\n assert candidate(k = 999) == 62\n assert candidate(k = 500) == 43\n assert candidate(k = 49) == 12\n assert candidate(k = 8192) == 180\n assert candidate(k = 50) == 13\n assert candidate(k = 127) == 21\n assert candidate(k = 64) == 14\n assert candidate(k = 17) == 7\n assert candidate(k = 6) == 3\n assert candidate(k = 63) == 14\n assert candidate(k = 7) == 4\n assert candidate(k = 99) == 18\n assert candidate(k = 31) == 10\n assert candidate(k = 13) == 6\n assert candidate(k = 65536) == 510\n assert candidate(k = 16384) == 254\n assert candidate(k = 2) == 1\n assert candidate(k = 12345) == 221\n assert candidate(k = 42) == 11\n assert candidate(k = 67890) == 520\n assert candidate(k = 200) == 27\n assert candidate(k = 99999) == 631\n assert candidate(k = 250) == 30\n assert candidate(k = 87500) == 590\n assert candidate(k = 37) == 11\n assert candidate(k = 255) == 30\n assert candidate(k = 256) == 30\n assert candidate(k = 512) == 44\n assert candidate(k = 85) == 17\n assert candidate(k = 32768) == 361\n assert candidate(k = 62500) == 498\n assert candidate(k = 1023) == 62\n assert candidate(k = 75000) == 546\n assert candidate(k = 23) == 8\n assert candidate(k = 4096) == 126\n assert candidate(k = 10000) == 198\n assert candidate(k = 511) == 44\n assert candidate(k = 28) == 9\n assert candidate(k = 1000) == 62\n assert candidate(k = 19) == 7\n assert candidate(k = 32) == 10\n assert candidate(k = 128) == 21\n assert candidate(k = 50000) == 446\n", "comparison": "exact"}, "public_tests": ["11", "1"], "hints": ["It is optimal to make all the increase operations first and all the duplicate operations last.", "Iterate over all possible number of increase operations that can be done and find the corresponding number of duplicate operations."], "metadata": {"canonical_parameter_names": ["k"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:42+00:00", "tests_total": 58, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "greedy", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(k)", "container": null, "callable": "min_operations", "parameters": [{"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3092, "task_id": "most-frequent-ids", "difficulty": "Medium", "problem_description": "The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, nums and freq, of equal length n. Each element in nums represents an ID, and the corresponding element in freq indicates how many times that ID should be added to or removed from the collection at each step.\n\n- Addition of IDs: If freq[i] is positive, it means freq[i] IDs with the value nums[i] are added to the collection at step i.\n- Removal of IDs: If freq[i] is negative, it means -freq[i] IDs with the value nums[i] are removed from the collection at step i.\n\nReturn an array ans of length n, where ans[i] represents the count of the most frequent ID in the collection after the i^th step. If the collection is empty at any step, ans[i] should be 0 for that step.\n\nExample 1:\n\nInput: nums = [2,3,2,1], freq = [3,2,-3,1]\nOutput: [3,3,2,2]\nExplanation:\nAfter step 0, we have 3 IDs with the value of 2. So ans[0] = 3.\nAfter step 1, we have 3 IDs with the value of 2 and 2 IDs with the value of 3. So ans[1] = 3.\nAfter step 2, we have 2 IDs with the value of 3. So ans[2] = 2.\nAfter step 3, we have 2 IDs with the value of 3 and 1 ID with the value of 1. So ans[3] = 2.\n\nExample 2:\n\nInput: nums = [5,5,3], freq = [2,-2,1]\nOutput: [2,0,1]\nExplanation:\nAfter step 0, we have 2 IDs with the value of 5. So ans[0] = 2.\nAfter step 1, there are no IDs. So ans[1] = 0.\nAfter step 2, we have 1 ID with the value of 3. So ans[2] = 1.\n\nConstraints:\n\n- 1 <= nums.length == freq.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- -10^5 <= freq[i] <= 10^5\n- freq[i] != 0\n- The input is generated such that the occurrences of an ID will not be negative in any step.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3],freq = [1, 1, 1, -1, -1, -1]) == [1, 1, 2, 2, 2, 2]\n assert candidate(nums = [1, 1, 1, 1, 1],freq = [-1, -1, -1, -1, -1]) == [-1, -2, -3, -4, -5]\n assert candidate(nums = [2, 3, 2, 1],freq = [3, 2, -3, 1]) == [3, 3, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5],freq = [1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, 10, 10, 10, 10],freq = [5, -2, 3, -6, 2]) == [5, 3, 6, 0, 2]\n assert candidate(nums = [5, 5, 3],freq = [2, -2, 1]) == [2, 0, 1]\n assert candidate(nums = [1, 2, 2, 3, 3, 3],freq = [1, 1, -1, 1, -1, 1]) == [1, 1, 1, 1, 1, 1]\n assert candidate(nums = [10, 10, 10, 10, 10],freq = [5, -1, -1, -1, -3]) == [5, 4, 3, 2, -1]\n assert candidate(nums = [1, 2, 2, 3, 3, 3],freq = [1, 2, 1, -1, -2, 3]) == [1, 2, 3, 3, 3, 3]\n assert candidate(nums = [1, 1, 1, 2, 2, 3],freq = [1, 1, -2, 1, 1, 1]) == [1, 2, 0, 1, 2, 2]\n assert candidate(nums = [1, 1, 2, 2, 3, 3],freq = [2, -1, 2, -1, 2, -1]) == [2, 1, 2, 1, 2, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],freq = [1, 1, 1, 1, 1, 1, 1, 1, 1, -10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, -1]\n assert candidate(nums = [10, 20, 10, 30, 20, 30],freq = [1, 1, -1, 1, -1, 1]) == [1, 1, 1, 1, 1, 2]\n assert candidate(nums = [100000, 100000, 100000, 100000],freq = [100000, -50000, -50000, 1]) == [100000, 50000, 0, 1]\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1],freq = [1, 1, -1, 1, -1, -1, 1, -1, -1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],freq = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000]) == [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],freq = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == [1, 3, 6, 10, 15, 15, 15, 15, 15, 15]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],freq = [10, -5, 20, -10, 30, -15, 40, -20, 50, -25]) == [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],freq = [1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2]) == [1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]\n assert candidate(nums = [1, 3, 5, 7, 9],freq = [1, -1, 1, -1, 1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3],freq = [1, -1, 1, 1, -1, 1, 1, 1, -3]) == [1, 0, 1, 2, 1, 1, 2, 3, 1]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 3],freq = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [10, 30, 60, 60, 90, 150, 150, 150, 240, 340]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, -9, 8, -7, 6, -5, 4, -3, 2, -1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50]) == [10, 20, 30, 40, 50, 50, 50, 50, 50, 50]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, 10, 10, 10, 10, -5, -5, -5, -5, -5]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == [-1, 2, 2, 4, 4, 6, 6, 8, 8, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == [-10, 20, 20, 40, 40, 60, 60, 80, 80, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],freq = [100000, -100000, 100000, -100000, 100000]) == [100000, 100000, 100000, 100000, 100000]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],freq = [1, -1, 2, -2, 3, -3, 4]) == [1, 0, 2, 0, 3, 0, 4]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],freq = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 2, 3, 4, 5, -6, -7, -8, -9, -10]) == [1, 2, 3, 4, 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],freq = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [5, 4, 3, 2, 1],freq = [-1, -2, -3, -4, -5]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],freq = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 10, 15, 20, 25, 30],freq = [100, -50, 200, -100, 300, -150]) == [100, 100, 200, 200, 300, 300]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 4, 3, 2, 1]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250],freq = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == [1, 2, 3, 4, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],freq = [2, -2, 3, -3, 4, -4, 5, -5, 6, -6]) == [2, 0, 3, 0, 4, 0, 5, 0, 6, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == [1, 1, 3, 3, 5, 5, 7, 7, 9, 9]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],freq = [1, 1, -1, 1, 1, -2, 1, 1, 1, -3]) == [1, 1, 1, 1, 2, 1, 1, 2, 3, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1],freq = [10, 20, 30, -5, -10, -15, 5, 10, 15, -25]) == [10, 20, 30, 30, 30, 15, 15, 20, 30, 30]\n assert candidate(nums = [1, 2, 3, 4, 5],freq = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-1, -2, -3, -4, -5, 5, 4, 3, 2, 1]) == [-1, -1, -1, -1, -1, 5, 5, 5, 5, 5]\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],freq = [10, -5, 7, -3, 2, 8, -2, 4, -1, 6, -4, 3, -2, 1]) == [10, 5, 7, 5, 6, 8, 6, 10, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],freq = [100, -50, 50, -25, 25, -12, -6, -3, -1, 1]) == [100, 100, 150, 150, 175, 175, 169, 169, 168, 168]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],freq = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],freq = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == [1, 2, 3, 4, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],freq = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [100000, -50000, 100000, -50000, 100000, -50000, 100000, -50000, 100000, -50000]) == [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],freq = [100000, -50000, 50000, -25000, 25000]) == [100000, 50000, 100000, 75000, 100000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, -2, 5, -3, 7, -1, 4, -6, 2, -8]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1000, 1000, 1000, 1000, 1000, -1000, -1000, -1000, -1000, -1000]) == [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\n assert candidate(nums = [10, 20, 30, 40, 50],freq = [1000, 2000, 3000, 4000, 5000]) == [1000, 2000, 3000, 4000, 5000]\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [100000, -50000, 50000, -25000, 25000, -12500, 12500, -6250, 6250, -3125]) == [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [100, -50, 200, -100, 300, -150, 400, -200, 500, -250]) == [100, 100, 200, 200, 300, 300, 400, 400, 500, 500]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],freq = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == [1, 3, 6, 10, 15, 15, 15, 15, 15, 15]\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300, 100],freq = [10, -5, 20, -10, 15, -20, 25, -15, 30, -30]) == [10, 10, 20, 20, 20, 10, 25, 25, 30, 30]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]\n assert candidate(nums = [100, 200, 300, 400, 500],freq = [1000, -500, 1500, -2000, 2500]) == [1000, 1000, 1500, 1500, 2500]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],freq = [50000, -50000, 30000, -30000, 20000]) == [50000, 50000, 50000, 50000, 50000]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],freq = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],freq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],freq = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]\n assert candidate(nums = [5, 10, 15, 20, 25],freq = [2, 2, 2, 2, 2]) == [2, 2, 2, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5],freq = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],freq = [50000, -25000, 12500, -6250, 3125, -1562, 781, -390, 195, -97]) == [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4],freq = [2, 2, 2, -1, -1, -1, 1, 1, 1]) == [2, 4, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],freq = [100, -100, 50, 200, -200, 100, 300, -300, 150]) == [100, 0, 50, 200, 50, 100, 300, 100, 150]\n assert candidate(nums = [10, 20, 30, 40, 50],freq = [10, -10, 20, -20, 30]) == [10, 10, 20, 20, 30]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],freq = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == [1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500]) == [100, 100, 200, 200, 300, 300, 400, 400, 500, 500]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],freq = [100, -10, -10, -10, -10, -10, -10, -10, -10, -100]) == [100, 90, 80, 70, 60, 50, 40, 30, 20, -80]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 2, 3, 4, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3],freq = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == [1, 2, 3, 3, 4, 6, 6, 6, 9]\n assert candidate(nums = [100, 200, 300, 400, 500],freq = [50, 100, -50, -100, 50]) == [50, 100, 100, 100, 100]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],freq = [10, 20, -30, 15, 25, -40, 20, 30, -50, 10, 20, -30]) == [10, 30, 0, 15, 40, 0, 20, 50, 0, 10, 30, 0]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],freq = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [100, 200, 300, 400, 500],freq = [-1, -2, -3, -4, -5]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],freq = [10, 20, 30, -10, -20, -30, 40, 50, -40, -50]) == [10, 30, 60, 50, 30, 0, 40, 90, 50, 0]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1],freq = [1, -1, 1, -1, 1, -1, 1]) == [1, 1, 2, 2, 3, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3],freq = [1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, 1, 1, 1]) == [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [10, -10, 10, -10, 10, -10, 10, -10, 10, -10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],freq = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [10, 30, 30, 70, 70, 110, 110, 150, 150, 190]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [-10, 9, -8, 7, -6, 5, -4, 3, -2, 1]) == [-10, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],freq = [1, 1, 1, 1, 1, 1, 1, 1, 1, -5]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],freq = [100000, 99999, 99998, 99997, 99996]) == [100000, 100000, 100000, 100000, 100000]\n", "comparison": "exact"}, "public_tests": ["[2,3,2,1]\n[3,2,-3,1]", "[5,5,3]\n[2,-2,1]"], "hints": ["Use an ordered set for maintaining the occurrences of each ID.", "After step i find the occurrences of nums[i].", "Change the occurrences of nums[i] in the ordered set."], "metadata": {"canonical_parameter_names": ["nums", "freq"], "leetcode_dataset_entry_point": "Solution().mostFrequentIDs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:44+00:00", "tests_total": 108, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "heap-priority-queue", "ordered-set"]}, "language": "ruby", "interface": {"raw_signature": "def most_frequent_i_ds(nums, freq)", "container": null, "callable": "most_frequent_i_ds", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "freq", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3093, "task_id": "longest-common-suffix-queries", "difficulty": "Hard", "problem_description": "You are given two arrays of strings wordsContainer and wordsQuery.\n\nFor each wordsQuery[i], you need to find a string from wordsContainer that has the longest common suffix with wordsQuery[i]. If there are two or more strings in wordsContainer that share the longest common suffix, find the string that is the smallest in length. If there are two or more such strings that have the same smallest length, find the one that occurred earlier in wordsContainer.\n\nReturn an array of integers ans, where ans[i] is the index of the string in wordsContainer that has the longest common suffix with wordsQuery[i].\n\nExample 1:\n\nInput: wordsContainer = [\"abcd\",\"bcd\",\"xbcd\"], wordsQuery = [\"cd\",\"bcd\",\"xyz\"]\nOutput: [1,1,1]\nExplanation:\nLet's look at each wordsQuery[i] separately:\n- For wordsQuery[0] = \"cd\", strings from wordsContainer that share the longest common suffix \"cd\" are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.\n- For wordsQuery[1] = \"bcd\", strings from wordsContainer that share the longest common suffix \"bcd\" are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.\n- For wordsQuery[2] = \"xyz\", there is no string from wordsContainer that shares a common suffix. Hence the longest common suffix is \"\", that is shared with strings at index 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.\n\nExample 2:\n\nInput: wordsContainer = [\"abcdefgh\",\"poiuygh\",\"ghghgh\"], wordsQuery = [\"gh\",\"acbfgh\",\"acbfegh\"]\nOutput: [2,0,2]\nExplanation:\nLet's look at each wordsQuery[i] separately:\n- For wordsQuery[0] = \"gh\", strings from wordsContainer that share the longest common suffix \"gh\" are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.\n- For wordsQuery[1] = \"acbfgh\", only the string at index 0 shares the longest common suffix \"fgh\". Hence it is the answer, even though the string at index 2 is shorter.\n- For wordsQuery[2] = \"acbfegh\", strings from wordsContainer that share the longest common suffix \"gh\" are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.\n\nConstraints:\n\n- 1 <= wordsContainer.length, wordsQuery.length <= 10^4\n- 1 <= wordsContainer[i].length <= 5 * 10^3\n- 1 <= wordsQuery[i].length <= 5 * 10^3\n- wordsContainer[i] consists only of lowercase English letters.\n- wordsQuery[i] consists only of lowercase English letters.\n- Sum of wordsContainer[i].length is at most 5 * 10^5.\n- Sum of wordsQuery[i].length is at most 5 * 10^5.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(wordsContainer = ['banana', 'mango', 'papaya'],wordsQuery = ['ana', 'ango', 'aya']) == [0, 1, 2]\n assert candidate(wordsContainer = ['abcde', 'bcde', 'cde', 'de', 'e'],wordsQuery = ['cde', 'de', 'e', 'a', 'b']) == [2, 3, 4, 4, 4]\n assert candidate(wordsContainer = ['xyz', 'zyx', 'zxy'],wordsQuery = ['x', 'y', 'z']) == [1, 2, 0]\n assert candidate(wordsContainer = ['zzzzz', 'zzzz', 'zzz', 'zz', 'z'],wordsQuery = ['zzzz', 'zzz', 'zz', 'z', 'a']) == [1, 2, 3, 4, 4]\n assert candidate(wordsContainer = ['a', 'ab', 'abc'],wordsQuery = ['a', 'ab', 'abc']) == [0, 1, 2]\n assert candidate(wordsContainer = ['unique', 'suffix', 'words'],wordsQuery = ['fix', 'ffix', 'uffix']) == [1, 1, 1]\n assert candidate(wordsContainer = ['abcd', 'bcd', 'xbcd'],wordsQuery = ['cd', 'bcd', 'xyz']) == [1, 1, 1]\n assert candidate(wordsContainer = ['hello', 'world', 'python'],wordsQuery = ['lo', 'rld', 'on']) == [0, 1, 2]\n assert candidate(wordsContainer = ['a', 'b', 'c'],wordsQuery = ['d', 'e', 'f']) == [0, 0, 0]\n assert candidate(wordsContainer = ['abcdefgh', 'poiuygh', 'ghghgh'],wordsQuery = ['gh', 'acbfgh', 'acbfegh']) == [2, 0, 2]\n assert candidate(wordsContainer = ['abcde', 'bcde', 'cde'],wordsQuery = ['cde', 'de', 'e']) == [2, 2, 2]\n assert candidate(wordsContainer = ['same', 'same', 'same'],wordsQuery = ['same', 'same', 'same']) == [0, 0, 0]\n assert candidate(wordsContainer = ['longestword', 'short', 'word'],wordsQuery = ['word', 'short', 'longestword']) == [2, 1, 0]\n assert candidate(wordsContainer = ['apple', 'maple', 'orange'],wordsQuery = ['le', 'ple', 'range']) == [0, 0, 2]\n assert candidate(wordsContainer = ['a', 'b', 'c'],wordsQuery = ['a', 'b', 'c']) == [0, 1, 2]\n assert candidate(wordsContainer = ['abc', 'def', 'ghi'],wordsQuery = ['abc', 'def', 'ghi']) == [0, 1, 2]\n assert candidate(wordsContainer = ['a', 'b', 'c', 'd'],wordsQuery = ['a', 'b', 'c', 'd']) == [0, 1, 2, 3]\n assert candidate(wordsContainer = ['aaaaa', 'bbbbb', 'ccccc', 'abcde', 'bcdef', 'cdefg'],wordsQuery = ['abcde', 'bcdef', 'cdefg', 'de', 'ef', 'f']) == [3, 4, 5, 3, 4, 4]\n assert candidate(wordsContainer = ['abcdef', 'defabc', 'abc', 'def', 'efg', 'fg', 'g'],wordsQuery = ['abc', 'def', 'efg', 'fg', 'g', 'a', 'bcd', 'cde']) == [2, 3, 4, 5, 6, 6, 6, 6]\n assert candidate(wordsContainer = ['abcdefghijk', 'ghijklmno', 'ijklmnopq', 'jklmnopqr', 'klmnopqrs', 'lmnopqrst'],wordsQuery = ['ijkl', 'mnop', 'nopq', 'opqr', 'pqrs', 'qrstu', 'rstuv', 'stuvw', 'tuvwx', 'uvwxy', 'vwxyz', 'wxyz', 'xyz', 'yz', 'z']) == [1, 1, 2, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(wordsContainer = ['aabbcc', 'bbcc', 'bcc', 'cc', 'c', 'aabbccdd', 'bbccdd', 'bccdd', 'ccdd', 'cdd', 'dd', 'd'],wordsQuery = ['cc', 'dd', 'cdd', 'bcc', 'bbcc', 'aabbcc', 'xyz', 'abc', 'd', 'ccdd', 'aabbccdd']) == [3, 10, 9, 2, 1, 0, 4, 4, 11, 8, 5]\n assert candidate(wordsContainer = ['aaaaa', 'aaabaaa', 'aaacaaa', 'aaad', 'aa', 'a', 'aaeaaa'],wordsQuery = ['aa', 'aaa', 'aaaa', 'aaaaa', 'aaab', 'aaac', 'aaad', 'aae']) == [4, 0, 0, 0, 5, 5, 3, 5]\n assert candidate(wordsContainer = ['apple', 'pple', 'ple', 'le', 'e', 'orange', 'range', 'ange', 'nge', 'ge', 'e'],wordsQuery = ['ple', 'le', 'e', 'apple', 'orange', 'range', 'nge', 'ge']) == [2, 3, 4, 0, 5, 6, 8, 9]\n assert candidate(wordsContainer = ['ababab', 'bababa', 'abab', 'bab', 'ab', 'b', 'a'],wordsQuery = ['ab', 'bab', 'abab', 'bababa', 'ababab', 'ba', 'a']) == [4, 3, 2, 1, 0, 1, 6]\n assert candidate(wordsContainer = ['longestword', 'longest', 'long', 'lo', 'l'],wordsQuery = ['word', 'st', 'ng', 'g', 'o', 'wordd', 'ngggg']) == [0, 1, 2, 2, 3, 0, 2]\n assert candidate(wordsContainer = ['abcd', 'bcd', 'bcd', 'cd', 'cd', 'd'],wordsQuery = ['cd', 'bcd', 'd', 'a', 'ab', 'abcd']) == [3, 1, 5, 5, 5, 0]\n assert candidate(wordsContainer = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],wordsQuery = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa']) == [0, 1, 2, 3, 4, 4, 4]\n assert candidate(wordsContainer = ['prefix', 'prefixx', 'prefixxx', 'prefixxxx'],wordsQuery = ['fix', 'xfix', 'xxfix', 'xxxfix', 'xxxxfix', 'prefix']) == [0, 0, 0, 0, 0, 0]\n assert candidate(wordsContainer = ['abcd', 'bcd', 'cd', 'd', 'abcdabcd', 'bcdbcd', 'cdcd', 'dd', 'abcdabcde'],wordsQuery = ['abcd', 'bcd', 'cd', 'd', 'abcdabcd', 'bcdbcd', 'cdcd', 'dd', 'e', 'abcdabcde', 'de', 'cde', 'bcde']) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8]\n assert candidate(wordsContainer = ['abcdexyz', 'bcdexyz', 'cdexyz', 'dexyz', 'exyz', 'xyz'],wordsQuery = ['xyz', 'exyz', 'dexyz', 'cdexyz', 'bcdexyz', 'abcdexyz', 'z']) == [5, 4, 3, 2, 1, 0, 5]\n assert candidate(wordsContainer = ['abcdexyz', 'bcdexyz', 'xbcdexyz', 'abcdexyz'],wordsQuery = ['cdexyz', 'bcdexyz', 'xyz', 'abcdexyz']) == [1, 1, 1, 0]\n assert candidate(wordsContainer = ['apple', 'orange', 'banana', 'grape', 'pineapple'],wordsQuery = ['apple', 'orange', 'banana', 'grape', 'pineapple', 'pe', 'e']) == [0, 1, 2, 3, 4, 3, 0]\n assert candidate(wordsContainer = ['xyz', 'yz', 'z', 'wxyz', 'vwxyz'],wordsQuery = ['z', 'yz', 'xyz', 'wxyz', 'vwxyz', 'wxyzz']) == [2, 1, 0, 3, 4, 2]\n assert candidate(wordsContainer = ['aaaa', 'aaab', 'aaac', 'aaba', 'aabb', 'aabc', 'aaca', 'aacc', 'abaa', 'abab', 'abac', 'abba', 'abbb', 'abbc', 'abca', 'abcb', 'abcc', 'acaa', 'acab', 'acac', 'acba', 'acbb', 'acbc', 'acca', 'accb', 'accc'],wordsQuery = ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc', 'a', 'b', 'c', 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 1, 2, 0, 1, 2, 3, 4, 5, 6, 15, 7]\n assert candidate(wordsContainer = ['example', 'samples', 'examples', 'sampless'],wordsQuery = ['ple', 'les', 'ample', 'sample', 'samples', 'examples', 'sampless']) == [0, 1, 0, 0, 1, 2, 3]\n assert candidate(wordsContainer = ['abcdefghij', 'abcdefghijk', 'abcdefgh', 'abcdefg', 'abcde', 'abcd'],wordsQuery = ['defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl']) == [3, 2, 5, 0, 1, 5]\n assert candidate(wordsContainer = ['abcdefghij', 'bcdefghij', 'cdefghij', 'defghij', 'efghij', 'fghij', 'ghij', 'hij', 'ij', 'j'],wordsQuery = ['ghij', 'hij', 'ij', 'j', 'k', 'abcdefghij', 'bcdefghij', 'cdefghij', 'defghij']) == [6, 7, 8, 9, 9, 0, 1, 2, 3]\n assert candidate(wordsContainer = ['aabbcc', 'bbaacc', 'ccaabb', 'aabb', 'bbaa', 'ccaac', 'aac', 'ac', 'c'],wordsQuery = ['aabbcc', 'bbaacc', 'ccaabb', 'aabb', 'bbaa', 'ccaac', 'aac', 'ac', 'c', 'aa', 'bb', 'cc']) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 4, 3, 0]\n assert candidate(wordsContainer = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],wordsQuery = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(wordsContainer = ['banana', 'anana', 'nana', 'ana', 'na', 'a'],wordsQuery = ['ana', 'na', 'a', 'anana', 'nana', 'banana', 'bana', 'ananaa']) == [3, 4, 5, 1, 2, 0, 3, 5]\n assert candidate(wordsContainer = ['abcdefg', 'defg', 'efg', 'fg', 'g'],wordsQuery = ['defg', 'efg', 'fg', 'g', 'abcdefg']) == [1, 2, 3, 4, 0]\n assert candidate(wordsContainer = ['suffix', 'fix', 'suffixfix', 'suffixsuffix', 'ffix', 'fixfix', 'suffixfixfix'],wordsQuery = ['suffix', 'fix', 'suffixfix', 'suffixsuffix', 'ffix', 'fixfix', 'suffixfixfix', 'ff', 'ix', 'x']) == [0, 1, 2, 3, 4, 5, 6, 1, 1, 1]\n assert candidate(wordsContainer = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijk', 'lmnopqr', 'stuvwxyz'],wordsQuery = ['mnopqr', 'lmnopqr', 'stuv', 'xyz', 'pqrs']) == [3, 3, 3, 4, 3]\n assert candidate(wordsContainer = ['unique', 'uniq', 'un', 'u'],wordsQuery = ['ue', 'iq', 'n', 'u', 'uniq', 'unique', 'nique']) == [0, 1, 2, 3, 1, 0, 0]\n assert candidate(wordsContainer = ['short', 'shorter', 'shortest', 'shortestest'],wordsQuery = ['est', 'test', 'st', 'rtest', 'shortestestest', 'shorter', 'shortest']) == [2, 2, 2, 2, 3, 1, 2]\n assert candidate(wordsContainer = ['hello', 'world', 'programming', 'worldwide', 'program'],wordsQuery = ['gram', 'ing', 'world', 'hello', 'pro', 'gramming']) == [4, 2, 1, 0, 0, 2]\n assert candidate(wordsContainer = ['suffix', 'prefix', 'suffixprefix', 'prefixsuffix'],wordsQuery = ['fix', 'fixx', 'suffix', 'prefix', 'uffix', 'frefix', 'sufix']) == [0, 0, 0, 1, 0, 1, 0]\n assert candidate(wordsContainer = ['xyz', 'zyx', 'yxz', 'zxz', 'xzy', 'zyy'],wordsQuery = ['xyz', 'zyx', 'yz', 'zx', 'xz', 'yy']) == [0, 1, 0, 1, 2, 5]\n assert candidate(wordsContainer = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],wordsQuery = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa']) == [0, 1, 2, 3, 4, 4]\n assert candidate(wordsContainer = ['abcdefg', 'defghij', 'efghijk', 'fghijkl', 'ghijklm'],wordsQuery = ['fgh', 'ghijk', 'ijkl', 'jklm', 'mnop']) == [0, 2, 3, 4, 0]\n assert candidate(wordsContainer = ['suffix', 'suffixx', 'suffixxx', 'suffixxxx'],wordsQuery = ['ffix', 'xffix', 'xxffix', 'xxxffix', 'xxxxffix', 'suffix']) == [0, 0, 0, 0, 0, 0]\n assert candidate(wordsContainer = ['abcdefghij', 'bcdefghij', 'cdefghij', 'defghij', 'efghij', 'fghij', 'ghij', 'hij', 'ij', 'j'],wordsQuery = (['abcdefghij', 'efghij', 'fghij', 'ghij', 'hij', 'ij', 'j', 'abcdefghijk', 'defghijk', 'fghijk', 'ghijk', 'hijk', 'ijk', 'jk', 'k'],)) == [9]\n assert candidate(wordsContainer = ['sameprefixsame', 'sameprefix', 'same', 'different'],wordsQuery = ['sameprefixsame', 'sameprefix', 'same', 'different', 'sameprefixsame', 'sameprefix', 'same', 'different']) == [0, 1, 2, 3, 0, 1, 2, 3]\n assert candidate(wordsContainer = ['suffix', 'suffixes', 'suffices', 'suffixing', 'suffixied'],wordsQuery = ['fix', 'fixes', 'fices', 'fixing', 'fixied', 'suffix', 'suffixes']) == [0, 1, 2, 3, 4, 0, 1]\n assert candidate(wordsContainer = ['longestword', 'longword', 'long', 'lon', 'lo', 'l'],wordsQuery = ['ongestword', 'ongword', 'ong', 'on', 'o', 'l', 'x']) == [0, 1, 2, 3, 4, 5, 5]\n assert candidate(wordsContainer = ['one', 'two', 'three', 'four', 'five'],wordsQuery = ['ne', 'wo', 'ree', 'our', 'ive', 'ven', 'on']) == [0, 1, 2, 3, 4, 0, 0]\n assert candidate(wordsContainer = ['abcabcabc', 'bcabcabc', 'cabcabc', 'abcabc', 'bcabc', 'cabc', 'abc', 'bc', 'c', 'a', 'b', 'c'],wordsQuery = ['abc', 'bc', 'c', 'a', 'b', 'c', 'abcabc', 'bcabc', 'cabc', 'abcabcabc', 'xyz', 'zzz', 'aaaaa', 'bbbbb', 'ccccc', 'dddd', 'eeeee', 'ffffff', 'gggg', 'hhhhh', 'iiiii', 'jjjjj', 'kkkkk', 'lllll', 'mmmmm', 'nnnnn', 'ooooo', 'ppppp', 'qqqqq', 'rrrrr', 'sssss', 'ttttt', 'uuuuu', 'vvvvv', 'wwwww', 'xxxxx', 'yyyyy', 'zzzzz']) == [6, 7, 8, 9, 10, 8, 3, 4, 5, 0, 8, 8, 9, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]\n assert candidate(wordsContainer = ['aabbcc', 'bbcc', 'bcc', 'cc', 'c'],wordsQuery = ['aabbcc', 'bbcc', 'bcc', 'cc', 'c', 'd', 'e', 'f']) == [0, 1, 2, 3, 4, 4, 4, 4]\n assert candidate(wordsContainer = ['apple', 'banana', 'grape', 'pineapple', 'orange'],wordsQuery = ['apple', 'banana', 'grape', 'pineapple', 'orange', 'le', 'ane', 'e']) == [0, 1, 2, 3, 4, 0, 0, 0]\n assert candidate(wordsContainer = ['longstring', 'longstr', 'longs', 'long', 'lo', 'l'],wordsQuery = ['longstr', 'longs', 'long', 'lo', 'l', 'o', 'ongstr', 'ngstr', 'gstr', 'str']) == [1, 2, 3, 4, 5, 4, 1, 1, 1, 1]\n assert candidate(wordsContainer = ['xyzabc', 'yabc', 'xabc', 'abc', 'bc', 'c'],wordsQuery = ['abc', 'c', 'bc', 'xyzabc', 'yabc', 'xabc']) == [3, 5, 4, 0, 1, 2]\n assert candidate(wordsContainer = ['aabbcc', 'bbaa', 'ccaa', 'aab', 'bb', 'cc'],wordsQuery = ['aabbcc', 'bbaa', 'ccaa', 'aab', 'bb', 'cc', 'aabb', 'bbcc', 'aa', 'b', 'c']) == [0, 1, 2, 3, 4, 5, 4, 0, 1, 4, 5]\n assert candidate(wordsContainer = ['abcdefghij', 'bcdefghij', 'cdefghij', 'defghij', 'efghij', 'fghij', 'ghij', 'hij', 'ij', 'j'],wordsQuery = ['ij', 'fghij', 'ghij', 'hij', 'ij', 'j', 'abcdef', 'xyz', 'zzz', 'abcdefghij']) == [8, 5, 6, 7, 8, 9, 9, 9, 9, 0]\n assert candidate(wordsContainer = ['abcabcabcabc', 'bcabcabcabc', 'cabcabcabc', 'abcabcabc', 'bcabcabc', 'cabcabc', 'abcabc', 'bcabc', 'cabc', 'abc', 'bc', 'c'],wordsQuery = ['abcabcabcabc', 'bcabcabcabc', 'cabcabcabc', 'abcabcabc', 'bcabcabc', 'cabcabc', 'abcabc', 'bcabc', 'cabc', 'abc', 'bc', 'c', 'd', 'e', 'f']) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11]\n assert candidate(wordsContainer = ['suffix', 'suffixmatch', 'suffixmatchlong', 'suffixmatchlongest'],wordsQuery = ['suffix', 'match', 'long', 'longest', 'suffixmatch', 'suffixmatchlong', 'suffixmatchlongest']) == [0, 1, 2, 3, 1, 2, 3]\n assert candidate(wordsContainer = ['racecar', 'civic', 'level', 'rotor', 'deified'],wordsQuery = ['car', 'civic', 'vel', 'rotor', 'deified', 'cara', 'ivic']) == [0, 1, 2, 3, 4, 1, 1]\n assert candidate(wordsContainer = ['abcdefgh', 'abcdefg', 'abcde', 'abcd', 'abc', 'ab', 'a'],wordsQuery = ['abcd', 'abc', 'ab', 'a', 'z', 'bcd', 'cde']) == [3, 4, 5, 6, 6, 3, 2]\n assert candidate(wordsContainer = ['xyzabc', 'yzabc', 'zabc', 'abc', 'c'],wordsQuery = ['zabc', 'abc', 'c', 'xyzabc', 'y']) == [2, 3, 4, 0, 4]\n assert candidate(wordsContainer = ['abcdexyz', 'bcdexyz', 'cdexyz', 'dexyz', 'exyz', 'xyz', 'yz', 'z'],wordsQuery = ['abcdexyz', 'bcdexyz', 'cdexyz', 'dexyz', 'exyz', 'xyz', 'yz', 'z', 'xyz', 'exyz', 'dexyz', 'cdexyz', 'bcdexyz', 'abcdexyz']) == [0, 1, 2, 3, 4, 5, 6, 7, 5, 4, 3, 2, 1, 0]\n assert candidate(wordsContainer = ['apple', 'bpple', 'cppla', 'dppla', 'epple'],wordsQuery = ['pple', 'apple', 'bpple', 'cppla', 'dppla', 'epple']) == [0, 0, 1, 2, 3, 4]\n assert candidate(wordsContainer = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee'],wordsQuery = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'aaa', 'bbb', 'ccc', 'ddd', 'eee', 'aa', 'bb', 'cc', 'dd', 'ee', 'a', 'b', 'c', 'd', 'e']) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n assert candidate(wordsContainer = ['abcd', 'bcd', 'cd', 'd'],wordsQuery = ['abcd', 'bcd', 'cd', 'd', 'abcd', 'bcd', 'cd', 'd']) == [0, 1, 2, 3, 0, 1, 2, 3]\n assert candidate(wordsContainer = ['zzzzz', 'zzzz', 'zzz', 'zz', 'z'],wordsQuery = ['zzzzz', 'zzzz', 'zzz', 'zz', 'z', 'a', 'b', 'c']) == [0, 1, 2, 3, 4, 4, 4, 4]\n assert candidate(wordsContainer = ['thisisatest', 'isisatest', 'sisatest', 'isatest', 'satest', 'atest', 'test', 'est', 'st', 't'],wordsQuery = ['test', 'est', 'st', 't', 'a', 'b', 'c', 'd', 'e', 'f']) == [6, 7, 8, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(wordsContainer = ['longword', 'longerword', 'longestword', 'shortword', 'tinyword'],wordsQuery = ['word', 'longword', 'longerword', 'longestword', 'shortword', 'tinyword', 'long', 'longer', 'longest', 'short', 'tiny', 'o', 'r', 't', 'w', 'd']) == [0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(wordsContainer = ['unique', 'distinct', 'separate', 'different', 'uniquely'],wordsQuery = ['unique', 'distinct', 'separate', 'different', 'uniquely', 'un']) == [0, 1, 2, 3, 4, 0]\n assert candidate(wordsContainer = ['longwordwithsuffix', 'wordwithsuffix', 'withsuffix', 'suffix', 'fix', 'ix', 'x'],wordsQuery = ['suffix', 'fix', 'ix', 'x', 'y', 'z', 'wordwithsuffix', 'longwordwithsuffix']) == [3, 4, 5, 6, 6, 6, 1, 0]\n assert candidate(wordsContainer = ['longestword', 'longest', 'long', 'lon', 'lo', 'l'],wordsQuery = ['longestword', 'longest', 'longestword', 'lon', 'lo', 'xyz']) == [0, 1, 0, 3, 4, 5]\n assert candidate(wordsContainer = ['uniqueword', 'anotherword', 'commonword', 'similarword', 'dissimilarword'],wordsQuery = ['word', 'similar', 'dissimilar', 'unique', 'another', 'common']) == [0, 0, 0, 0, 0, 0]\n", "comparison": "exact"}, "public_tests": ["[\"abcd\",\"bcd\",\"xbcd\"]\n[\"cd\",\"bcd\",\"xyz\"]", "[\"abcdefgh\",\"poiuygh\",\"ghghgh\"]\n[\"gh\",\"acbfgh\",\"acbfegh\"]"], "hints": ["If we reverse the strings, the problem changes to finding the longest common prefix.", "Build a Trie, each node is a letter and only saves the best word’s index in each node, based on the criteria."], "metadata": {"canonical_parameter_names": ["wordsContainer", "wordsQuery"], "leetcode_dataset_entry_point": "Solution().stringIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:47+00:00", "tests_total": 84, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "string", "trie"]}, "language": "ruby", "interface": {"raw_signature": "def string_indices(words_container, words_query)", "container": null, "callable": "string_indices", "parameters": [{"name": "words_container", "type": "String[]"}, {"name": "words_query", "type": "String[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3095, "task_id": "shortest-subarray-with-or-at-least-k-i", "difficulty": "Easy", "problem_description": "You are given an array nums of non-negative integers and an integer k.\n\nAn array is called special if the bitwise OR of all of its elements is at least k.\n\nReturn the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.\n\nExample 1:\n\nInput: nums = [1,2,3], k = 2\nOutput: 1\nExplanation:\nThe subarray [3] has OR value of 3. Hence, we return 1.\nNote that [2] is also a special subarray.\n\nExample 2:\n\nInput: nums = [2,1,8], k = 10\nOutput: 3\nExplanation:\nThe subarray [2,1,8] has OR value of 11. Hence, we return 3.\n\nExample 3:\n\nInput: nums = [1,2], k = 0\nOutput: 1\nExplanation:\nThe subarray [1] has OR value of 1. Hence, we return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 0 <= nums[i] <= 50\n- 0 <= k < 64\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0],k = 1) == -1\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [1, 2],k = 0) == 1\n assert candidate(nums = [4, 5, 6, 7],k = 12) == -1\n assert candidate(nums = [1, 2, 3],k = 2) == 1\n assert candidate(nums = [30, 1, 4, 3, 2, 5],k = 6) == 1\n assert candidate(nums = [7, 14, 21, 28, 35],k = 21) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],k = 15) == 2\n assert candidate(nums = [30, 1, 4, 3],k = 7) == 1\n assert candidate(nums = [3, 3, 3, 3, 3],k = 2) == 1\n assert candidate(nums = [0, 0, 0, 0],k = 1) == -1\n assert candidate(nums = [32, 16, 8, 4, 2, 1],k = 31) == 1\n assert candidate(nums = [2, 1, 8],k = 10) == 3\n assert candidate(nums = [30, 1, 4, 2],k = 31) == 2\n assert candidate(nums = [42, 24, 8, 16],k = 48) == 2\n assert candidate(nums = [2, 4, 6, 8, 10],k = 30) == -1\n assert candidate(nums = [42, 21, 17, 8, 2],k = 42) == 1\n assert candidate(nums = [31, 31, 31, 31],k = 31) == 1\n assert candidate(nums = [16, 8, 4, 2, 1],k = 31) == 5\n assert candidate(nums = [31, 15, 7, 3, 1],k = 31) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],k = 15) == 2\n assert candidate(nums = [5, 13, 7, 2, 8],k = 20) == -1\n assert candidate(nums = [5, 3, 1, 4, 2, 8, 16, 32],k = 31) == 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],k = 1) == 1\n assert candidate(nums = [25, 12, 6, 3, 1, 0],k = 25) == 1\n assert candidate(nums = [32, 16, 8, 4, 2, 1],k = 63) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 15) == 1\n assert candidate(nums = [48, 24, 12, 6, 3, 1],k = 50) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 31) == 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],k = 1) == 1\n assert candidate(nums = [3, 5, 6, 9, 12, 15, 18],k = 30) == 2\n assert candidate(nums = [42, 21, 10, 5, 2, 1],k = 42) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0],k = 0) == 1\n assert candidate(nums = [32, 16, 8, 4, 2, 1],k = 31) == 1\n assert candidate(nums = [31, 14, 7, 3, 1],k = 30) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 1\n assert candidate(nums = [5, 7, 11, 13, 17, 19, 23, 29],k = 40) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 55) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30],k = 45) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 60) == 2\n assert candidate(nums = [6, 12, 18, 24, 30],k = 30) == 1\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 = 50) == -1\n assert candidate(nums = [50, 25, 12, 6, 3, 1],k = 49) == 1\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21],k = 60) == -1\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31],k = 31) == 1\n assert candidate(nums = [3, 5, 7, 9, 11, 13],k = 13) == 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],k = 1) == 1\n assert candidate(nums = [31, 14, 7, 3, 1],k = 31) == 1\n assert candidate(nums = [7, 14, 21, 28, 35],k = 35) == 1\n assert candidate(nums = [31, 31, 31, 31, 31],k = 15) == 1\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 31) == -1\n assert candidate(nums = [7, 14, 21, 28, 35, 42],k = 42) == 1\n assert candidate(nums = [45, 35, 25, 15, 5],k = 60) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 31) == 1\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],k = 60) == 2\n assert candidate(nums = [31, 15, 7, 3, 1, 0, 0, 0, 0, 0, 1, 3, 7, 15, 31],k = 31) == 1\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],k = 44) == 2\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32],k = 31) == 1\n assert candidate(nums = [45, 35, 25, 15, 5],k = 40) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],k = 31) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30],k = 40) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 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],k = 1) == 1\n assert candidate(nums = [31, 14, 7, 3, 1, 0, 0, 0, 0, 0],k = 31) == 1\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36],k = 50) == 1\n assert candidate(nums = [29, 15, 7, 3, 1],k = 31) == 2\n assert candidate(nums = [4, 6, 8, 10, 12, 14],k = 14) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35],k = 35) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30],k = 30) == 1\n assert candidate(nums = [31, 14, 7, 3, 1, 0, 15, 28, 16],k = 31) == 1\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n2", "[2,1,8]\n10", "[1,2]\n0"], "hints": ["The constraints are small. Brute force checking all the subarrays."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minimumSubarrayLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:49+00:00", "tests_total": 109, "tests_dropped": 36, "flags": [], "topic_tags": ["array", "bit-manipulation", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_subarray_length(nums, k)", "container": null, "callable": "minimum_subarray_length", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3096, "task_id": "minimum-levels-to-gain-more-points", "difficulty": "Medium", "problem_description": "You are given a binary array possible of length n.\n\nAlice and Bob are playing a game that consists of n levels. Some of the levels in the game are impossible to clear while others can always be cleared. In particular, if possible[i] == 0, then the i^th level is impossible to clear for both the players. A player gains 1 point on clearing a level and loses 1 point if the player fails to clear it.\n\nAt the start of the game, Alice will play some levels in the given order starting from the 0^th level, after which Bob will play for the rest of the levels.\n\nAlice wants to know the minimum number of levels she should play to gain more points than Bob, if both players play optimally to maximize their points.\n\nReturn the minimum number of levels Alice should play to gain more points. If this is not possible, return -1.\n\nNote that each player must play at least 1 level.\n\nExample 1:\n\nInput: possible = [1,0,1,0]\nOutput: 1\nExplanation:\nLet's look at all the levels that Alice can play up to:\n- If Alice plays only level 0 and Bob plays the rest of the levels, Alice has 1 point, while Bob has -1 + 1 - 1 = -1 point.\n- If Alice plays till level 1 and Bob plays the rest of the levels, Alice has 1 - 1 = 0 points, while Bob has 1 - 1 = 0 points.\n- If Alice plays till level 2 and Bob plays the rest of the levels, Alice has 1 - 1 + 1 = 1 point, while Bob has -1 point.\n\nAlice must play a minimum of 1 level to gain more points.\n\nExample 2:\n\nInput: possible = [1,1,1,1,1]\nOutput: 3\nExplanation:\nLet's look at all the levels that Alice can play up to:\n- If Alice plays only level 0 and Bob plays the rest of the levels, Alice has 1 point, while Bob has 4 points.\n- If Alice plays till level 1 and Bob plays the rest of the levels, Alice has 2 points, while Bob has 3 points.\n- If Alice plays till level 2 and Bob plays the rest of the levels, Alice has 3 points, while Bob has 2 points.\n- If Alice plays till level 3 and Bob plays the rest of the levels, Alice has 4 points, while Bob has 1 point.\n\nAlice must play a minimum of 3 levels to gain more points.\n\nExample 3:\n\nInput: possible = [0,0]\nOutput: -1\nExplanation:\nThe only possible way is for both players to play 1 level each. Alice plays level 0 and loses 1 point. Bob plays level 1 and loses 1 point. As both players have equal points, Alice can't gain more points than Bob.\n\nConstraints:\n\n- 2 <= n == possible.length <= 10^5\n- possible[i] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [0, 0, 0, 0, 1, 1, 1, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 0, 1, 0]) == 1\n assert candidate(possible = [0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [0, 0]) == -1\n assert candidate(possible = [1, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(possible = [1, 1, 0, 0, 1, 1]) == 2\n assert candidate(possible = [1, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1]) == 3\n assert candidate(possible = [1, 1, 1, 0, 0, 0, 1]) == 1\n assert candidate(possible = [1, 1, 1, 0, 0, 0, 1, 1, 1]) == 2\n assert candidate(possible = [1, 1, 1, 1, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [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]) == 1\n assert candidate(possible = [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, 1, 0, 1]) == 1\n assert candidate(possible = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == 9\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(possible = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 2\n assert candidate(possible = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 16\n assert candidate(possible = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(possible = [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 2\n assert candidate(possible = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(possible = [0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 3\n assert candidate(possible = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(possible = [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(possible = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1]) == 2\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(possible = [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == 10\n assert candidate(possible = [1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(possible = [1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1]) == 1\n assert candidate(possible = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]) == 1\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [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]) == 1\n assert candidate(possible = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 2\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 3\n assert candidate(possible = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == 1\n assert candidate(possible = [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]) == 2\n assert candidate(possible = [1, 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, 1]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(possible = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 23\n assert candidate(possible = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(possible = [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]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 14\n assert candidate(possible = [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, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 2\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 2\n assert candidate(possible = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]) == 1\n assert candidate(possible = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 1\n assert candidate(possible = [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, 1, 0, 1, 0]) == 1\n assert candidate(possible = [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, 1, 1, 1]) == 1\n assert candidate(possible = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]) == 1\n assert candidate(possible = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(possible = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(possible = [0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1]) == 6\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 14\n assert candidate(possible = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(possible = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == 18\n assert candidate(possible = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 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\n assert candidate(possible = [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\n assert candidate(possible = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0]) == 6\n assert candidate(possible = [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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 2\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 6\n assert candidate(possible = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == -1\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 2\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 12\n assert candidate(possible = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == -1\n assert candidate(possible = [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, 1, 0, 1]) == -1\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 40\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 16\n assert candidate(possible = [1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1]) == 12\n assert candidate(possible = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(possible = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0]) == 8\n assert candidate(possible = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 13\n assert candidate(possible = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 1\n assert candidate(possible = [1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(possible = [0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0]) == 22\n assert candidate(possible = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 1\n assert candidate(possible = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0]) == 10\n assert candidate(possible = [1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 3\n assert candidate(possible = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) == 1\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(possible = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 3\n assert candidate(possible = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1]) == 1\n assert candidate(possible = [1, 1, 0, 0, 1, 1, 1, 0, 1, 0]) == 2\n assert candidate(possible = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(possible = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(possible = [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, 1, 0]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,0,1,0]", "[1,1,1,1,1]", "[0,0]"], "hints": ["Change all 0 in possible array into -1.", "We need to find the shortest non-empty prefix of the new possible array such that the sum of elements in it is strictly larger than the remaining part."], "metadata": {"canonical_parameter_names": ["possible"], "leetcode_dataset_entry_point": "Solution().minimumLevels", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:52+00:00", "tests_total": 114, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_levels(possible)", "container": null, "callable": "minimum_levels", "parameters": [{"name": "possible", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3097, "task_id": "shortest-subarray-with-or-at-least-k-ii", "difficulty": "Medium", "problem_description": "You are given an array nums of non-negative integers and an integer k.\n\nAn array is called special if the bitwise OR of all of its elements is at least k.\n\nReturn the length of the shortest special non-empty subarray of nums, or return -1 if no special subarray exists.\n\nExample 1:\n\nInput: nums = [1,2,3], k = 2\nOutput: 1\nExplanation:\nThe subarray [3] has OR value of 3. Hence, we return 1.\n\nExample 2:\n\nInput: nums = [2,1,8], k = 10\nOutput: 3\nExplanation:\nThe subarray [2,1,8] has OR value of 11. Hence, we return 3.\n\nExample 3:\n\nInput: nums = [1,2], k = 0\nOutput: 1\nExplanation:\nThe subarray [1] has OR value of 1. Hence, we return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 2 * 10^5\n- 0 <= nums[i] <= 10^9\n- 0 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [0, 0, 0],k = 1) == -1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 10) == 2\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [5, 3, 1, 1, 1],k = 8) == -1\n assert candidate(nums = [1, 2],k = 0) == 1\n assert candidate(nums = [1, 2, 3],k = 2) == 1\n assert candidate(nums = [3, 5, 7, 9],k = 15) == 2\n assert candidate(nums = [1, 0, 1, 0, 1],k = 1) == 1\n assert candidate(nums = [1, 3, 7, 15, 31],k = 31) == 1\n assert candidate(nums = [7, 10, 4, 3, 15],k = 14) == 1\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [3, 3, 3, 3],k = 3) == 1\n assert candidate(nums = [5, 9, 1, 8],k = 15) == -1\n assert candidate(nums = [4, 7, 1, 9, 3, 8],k = 11) == 2\n assert candidate(nums = [1, 3, 4, 8, 16],k = 15) == 1\n assert candidate(nums = [1000000000],k = 1000000000) == 1\n assert candidate(nums = [30, 1, 4, 3],k = 31) == 2\n assert candidate(nums = [0, 0, 0, 0],k = 1) == -1\n assert candidate(nums = [2, 1, 8],k = 10) == 3\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 7) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [1024, 512, 256],k = 1024) == 1\n assert candidate(nums = [3, 5, 7, 9, 11],k = 15) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1023) == -1\n assert candidate(nums = [31, 15, 7, 3, 1],k = 31) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 1048575) == 20\n assert candidate(nums = [31, 15, 7, 3, 1, 1, 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 = 31) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 1) == 1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0],k = 255) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 511) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 45) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 32767) == 15\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 512) == 1\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1],k = 255) == 8\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543, 98765432],k = 987654321) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 16383) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1023) == 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],k = 0) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575],k = 1048575) == 1\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 1) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],k = 2047) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 1000000000) == 1\n assert candidate(nums = [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, 1],k = 1) == 1\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1],k = 31) == 1\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 = 20) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 100) == 2\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000],k = 15625000) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 30) == 2\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 2047) == 11\n assert candidate(nums = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048],k = 2097151) == -1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 1023) == 1\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 1000000000) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000) == 1\n assert candidate(nums = [31, 15, 7, 3, 1, 63, 127, 255, 511, 1023],k = 1023) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1023) == 10\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 1953125) == 1\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023],k = 1023) == 1\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333],k = 123456789) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767],k = 32767) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 1) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 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],k = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1023) == -1\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072],k = 262143) == -1\n assert candidate(nums = [9, 5, 3, 7, 11, 13, 17, 19, 23, 29],k = 50) == -1\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],k = 31) == 1\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 255) == 8\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 1048576) == -1\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047],k = 1048575) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 2047) == 11\n assert candidate(nums = [500000000, 500000000, 500000000, 500000000, 500000000, 500000000, 500000000],k = 500000000) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],k = 2048) == 1\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],k = 255) == 1\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 1000000000) == 1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 1023) == 1\n assert candidate(nums = [31, 15, 7, 3, 1, 0, 0, 0, 0, 0],k = 31) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == -1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047],k = 2047) == 1\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 256, 128, 64, 32, 16, 8, 4, 2, 1, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 1023) == 10\n assert candidate(nums = [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, 1, 0, 1, 0],k = 1) == 1\n assert candidate(nums = [256, 128, 64, 32, 16, 8, 4, 2, 1],k = 511) == 9\n assert candidate(nums = [31, 15, 7, 3, 1],k = 31) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 1000000000) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 500) == -1\n assert candidate(nums = [31, 7, 5, 9, 20, 15, 8, 2],k = 25) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 2) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0],k = 1) == -1\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n2", "[2,1,8]\n10", "[1,2]\n0"], "hints": ["For each nums[i], we can maintain each subarray’s bitwise OR result ending with it.", "The property of bitwise OR is that it never unsets any bits and only sets new bits", "So the number of different results for each nums[i] is at most the number of bits 32."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minimumSubarrayLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:54+00:00", "tests_total": 95, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "bit-manipulation", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_subarray_length(nums, k)", "container": null, "callable": "minimum_subarray_length", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3098, "task_id": "find-the-sum-of-subsequence-powers", "difficulty": "Hard", "problem_description": "You are given an integer array nums of length n, and a positive integer k.\n\nThe power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence.\n\nReturn the sum of powers of all subsequences of nums which have length equal to k.\n\nSince the answer may be large, return it modulo 10^9+ 7.\n\nExample 1:\n\nInput: nums = [1,2,3,4], k = 3\nOutput: 4\nExplanation:\nThere are 4 subsequences in nums which have length 3: [1,2,3], [1,3,4], [1,2,4], and [2,3,4]. The sum of powers is |2 - 3| + |3 - 4| + |2 - 1| + |3 - 4| = 4.\n\nExample 2:\n\nInput: nums = [2,2], k = 2\nOutput: 0\nExplanation:\nThe only subsequence in nums which has length 2 is [2,2]. The sum of powers is |2 - 2| = 0.\n\nExample 3:\n\nInput: nums = [4,3,-1], k = 2\nOutput: 10\nExplanation:\nThere are 3 subsequences in nums which have length 2: [4,3], [4,-1], and [3,-1]. The sum of powers is |4 - 3| + |4 - (-1)| + |3 - (-1)| = 10.\n\nConstraints:\n\n- 2 <= n == nums.length <= 50\n- -10^8 <= nums[i] <= 10^8\n- 2 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 3) == 110\n assert candidate(nums = [100, 200, 300, 400, 500, 600],k = 6) == 100\n assert candidate(nums = [1, 2, 3, 4],k = 3) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 0\n assert candidate(nums = [1, 3, 6, 10, 15],k = 5) == 2\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],k = 6) == 463\n assert candidate(nums = [100, -100, 200, -200],k = 2) == 1400\n assert candidate(nums = [100000000, -100000000, 50000000, -50000000],k = 3) == 200000000\n assert candidate(nums = [-10, -5, 0, 5, 10],k = 3) == 55\n assert candidate(nums = [4, 3, -1],k = 2) == 10\n assert candidate(nums = [0, 0, 0, 0, 0],k = 2) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 5) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 258\n assert candidate(nums = [1, 3, 5, 7, 9],k = 3) == 22\n assert candidate(nums = [2, 2],k = 2) == 0\n assert candidate(nums = [1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(nums = [1, 5, 9, 13, 17],k = 4) == 20\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],k = 4) == 50\n assert candidate(nums = [1, 5, 8, 10, 12],k = 4) == 11\n assert candidate(nums = [-10, -5, 0, 5, 10],k = 4) == 25\n assert candidate(nums = [10, 20, 30, 40, 50],k = 3) == 110\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3],k = 5) == 21\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],k = 15) == 310235072\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 2580\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 246\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],k = 3) == 27\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 6) == 2100\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 10) == 184792\n assert candidate(nums = [-100, -50, 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600],k = 8) == 321800\n assert candidate(nums = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10],k = 7) == 1200\n assert candidate(nums = [-100000000, -99999999, -99999998, -99999997, -99999996, -99999995, -99999994, -99999993, -99999992],k = 5) == 127\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81],k = 15) == 15504\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996],k = 4) == 5\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 = 12) == 125970\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 11) == 352717\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 4) == 2460\n assert candidate(nums = [-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50],k = 6) == 4630\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],k = 5) == 753\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 7) == 1200\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -110, -120, -130, -140, -150, -160, -170, -180, -190, -200],k = 15) == 155040\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130],k = 15) == 300540331\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],k = 7) == 330\n assert candidate(nums = [-100000000, -99999999, -99999998, -99999997, -99999996],k = 3) == 11\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],k = 10) == 60795594\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],k = 20) == 53130\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9],k = 10) == 92379\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 5) == 2580\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 10) == 300300\n assert candidate(nums = [10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10011, 10012, 10013, 10014],k = 12) == 455\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 6) == 2100\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000],k = 5) == 677430\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500, 781250, 390625, 195312],k = 5) == 370703188\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130],k = 7) == 17170\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 10) == 44999097\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 2460\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 7726160\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 15) == 155040\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100],k = 7) == 153600\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 120\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 = 25) == 0\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],k = 25) == 0\n assert candidate(nums = [-50000000, -25000000, 0, 25000000, 50000000, 75000000, 100000000],k = 5) == 525000000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 30030\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 6) == 874\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29],k = 20) == 30045015\n assert candidate(nums = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],k = 8) == 64360\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 = 18) == 86493225\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 6471\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],k = 25) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 15) == 155117536\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 1024\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],k = 20) == 128935568\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35],k = 15) == 16\n assert candidate(nums = [1, 5, 10, 20, 30, 50, 70, 100, 150, 200, 300, 500, 700, 1000, 1500, 2000, 3000, 5000, 7000, 10000],k = 10) == 2513422\n assert candidate(nums = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10],k = 4) == 2460\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 18) == 19000\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 = 10) == 0\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 7) == 1524\n assert candidate(nums = [100000000, 50000000, 0, -50000000, -100000000, 25000000, 75000000],k = 4) == 74999993\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500],k = 4) == 218750000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 12) == 629850\n assert candidate(nums = [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],k = 10) == 7286383\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],k = 15) == 15504\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 16) == 20349\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15],k = 8) == 22673\n assert candidate(nums = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50, -55, -60, -65, -70, -75, -80, -85, -90, -95, -100],k = 10) == 923835\n assert candidate(nums = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000],k = 5) == 579999986\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 258\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],k = 15) == 108528\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],k = 6) == 430\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, 2],k = 25) == 0\n assert candidate(nums = [-100000000, -99999999, -99999998, -99999997, -99999996, -99999995, -99999994, -99999993, -99999992, -99999991],k = 7) == 120\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 = 20) == 30045015\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 12) == 125970\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991],k = 8) == 45\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 9) == 3865518\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100],k = 10) == 10240\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 = 10) == 184767\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],k = 25) == 605552908\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == 3003\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 11) == 167960\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994],k = 5) == 21\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],k = 7) == 3162380\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 8) == 0\n assert candidate(nums = [100000000, -100000000, 0, 50000000, -50000000],k = 3) == 550000000\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],k = 20) == 30045015\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 8) == 64360\n assert candidate(nums = [100000000, 100000000, 99999999, 99999998, 99999997],k = 3) == 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],k = 8) == 127867\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 15) == 77520\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n3", "[2,2]\n2", "[4,3,-1]\n2"], "hints": ["Sort nums.", "There are at most n^2 distinct differences.", "For a particular difference d, let dp[len][i][j] be the number of subsequences of length len in the subarray nums[0..i] where the last element picked was at index j.", "For each index, we can check if it can be picked if nums[i] - nums[j] <= d."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().sumOfPowers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:56+00:00", "tests_total": 120, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "dynamic-programming", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_powers(nums, k)", "container": null, "callable": "sum_of_powers", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3099, "task_id": "harshad-number", "difficulty": "Easy", "problem_description": "An integer divisible by the sum of its digits is said to be a Harshad number. You are given an integer x. Return the sum of the digits of x if x is a Harshad number, otherwise, return -1.\n\nExample 1:\n\nInput: x = 18\nOutput: 9\nExplanation:\nThe sum of digits of x is 9. 18 is divisible by 9. So 18 is a Harshad number and the answer is 9.\n\nExample 2:\n\nInput: x = 23\nOutput: -1\nExplanation:\nThe sum of digits of x is 5. 23 is not divisible by 5. So 23 is not a Harshad number and the answer is -1.\n\nConstraints:\n\n- 1 <= x <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(x = 50) == 5\n assert candidate(x = 23) == -1\n assert candidate(x = 10) == 1\n assert candidate(x = 18) == 9\n assert candidate(x = 1) == 1\n assert candidate(x = 90) == 9\n assert candidate(x = 57) == -1\n assert candidate(x = 99) == -1\n assert candidate(x = 81) == 9\n assert candidate(x = 45) == 9\n assert candidate(x = 13) == -1\n assert candidate(x = 100) == 1\n assert candidate(x = 12) == 3\n assert candidate(x = 54) == 9\n assert candidate(x = 72) == 9\n assert candidate(x = 42) == 6\n assert candidate(x = 27) == 9\n assert candidate(x = 70) == 7\n assert candidate(x = 36) == 9\n assert candidate(x = 49) == -1\n assert candidate(x = 75) == -1\n assert candidate(x = 63) == 9\n", "comparison": "exact"}, "public_tests": ["18", "23"], "hints": ["Use a while loop and divide x by 10 to find the sum of the digits of x."], "metadata": {"canonical_parameter_names": ["x"], "leetcode_dataset_entry_point": "Solution().sumOfTheDigitsOfHarshadNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:12:58+00:00", "tests_total": 53, "tests_dropped": 31, "flags": [], "topic_tags": ["math"]}, "language": "ruby", "interface": {"raw_signature": "def sum_of_the_digits_of_harshad_number(x)", "container": null, "callable": "sum_of_the_digits_of_harshad_number", "parameters": [{"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3100, "task_id": "water-bottles-ii", "difficulty": "Medium", "problem_description": "You are given two integers numBottles and numExchange.\n\nnumBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations:\n\n- Drink any number of full water bottles turning them into empty bottles.\n- Exchange numExchange empty bottles with one full water bottle. Then, increase numExchange by one.\n\nNote that you cannot exchange multiple batches of empty bottles for the same value of numExchange. For example, if numBottles == 3 and numExchange == 1, you cannot exchange 3 empty water bottles for 3 full bottles.\n\nReturn the maximum number of water bottles you can drink.\n\nExample 1:\n\nInput: numBottles = 13, numExchange = 6\nOutput: 15\nExplanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.\n\nExample 2:\n\nInput: numBottles = 10, numExchange = 3\nOutput: 13\nExplanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.\n\nConstraints:\n\n- 1 <= numBottles <= 100\n- 1 <= numExchange <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(numBottles = 10,numExchange = 3) == 13\n assert candidate(numBottles = 2,numExchange = 3) == 2\n assert candidate(numBottles = 13,numExchange = 6) == 15\n assert candidate(numBottles = 100,numExchange = 1) == 114\n assert candidate(numBottles = 5,numExchange = 5) == 6\n assert candidate(numBottles = 1,numExchange = 1) == 2\n assert candidate(numBottles = 20,numExchange = 4) == 24\n assert candidate(numBottles = 50,numExchange = 10) == 54\n assert candidate(numBottles = 1,numExchange = 100) == 1\n assert candidate(numBottles = 1,numExchange = 10) == 1\n assert candidate(numBottles = 99,numExchange = 2) == 112\n assert candidate(numBottles = 70,numExchange = 6) == 78\n assert candidate(numBottles = 60,numExchange = 2) == 70\n assert candidate(numBottles = 45,numExchange = 20) == 47\n assert candidate(numBottles = 60,numExchange = 8) == 66\n assert candidate(numBottles = 90,numExchange = 9) == 97\n assert candidate(numBottles = 80,numExchange = 8) == 87\n assert candidate(numBottles = 90,numExchange = 18) == 94\n assert candidate(numBottles = 75,numExchange = 15) == 79\n assert candidate(numBottles = 40,numExchange = 50) == 40\n assert candidate(numBottles = 30,numExchange = 2) == 37\n assert candidate(numBottles = 90,numExchange = 5) == 100\n assert candidate(numBottles = 55,numExchange = 8) == 60\n assert candidate(numBottles = 15,numExchange = 15) == 16\n assert candidate(numBottles = 40,numExchange = 7) == 44\n assert candidate(numBottles = 55,numExchange = 6) == 61\n assert candidate(numBottles = 80,numExchange = 3) == 91\n assert candidate(numBottles = 60,numExchange = 15) == 63\n assert candidate(numBottles = 60,numExchange = 7) == 66\n assert candidate(numBottles = 30,numExchange = 5) == 34\n assert candidate(numBottles = 80,numExchange = 10) == 86\n assert candidate(numBottles = 80,numExchange = 20) == 83\n assert candidate(numBottles = 95,numExchange = 5) == 105\n assert candidate(numBottles = 40,numExchange = 12) == 43\n assert candidate(numBottles = 40,numExchange = 25) == 41\n assert candidate(numBottles = 50,numExchange = 5) == 57\n assert candidate(numBottles = 85,numExchange = 4) == 95\n assert candidate(numBottles = 45,numExchange = 12) == 48\n assert candidate(numBottles = 25,numExchange = 3) == 30\n assert candidate(numBottles = 80,numExchange = 5) == 89\n assert candidate(numBottles = 45,numExchange = 6) == 50\n assert candidate(numBottles = 30,numExchange = 7) == 33\n assert candidate(numBottles = 7,numExchange = 8) == 7\n assert candidate(numBottles = 70,numExchange = 8) == 76\n assert candidate(numBottles = 75,numExchange = 5) == 84\n assert candidate(numBottles = 75,numExchange = 7) == 82\n assert candidate(numBottles = 85,numExchange = 5) == 94\n assert candidate(numBottles = 45,numExchange = 10) == 49\n assert candidate(numBottles = 30,numExchange = 30) == 31\n assert candidate(numBottles = 90,numExchange = 4) == 101\n assert candidate(numBottles = 40,numExchange = 30) == 41\n assert candidate(numBottles = 75,numExchange = 10) == 81\n assert candidate(numBottles = 100,numExchange = 2) == 113\n assert candidate(numBottles = 35,numExchange = 18) == 36\n assert candidate(numBottles = 55,numExchange = 12) == 59\n assert candidate(numBottles = 100,numExchange = 50) == 102\n assert candidate(numBottles = 8,numExchange = 4) == 10\n assert candidate(numBottles = 80,numExchange = 15) == 84\n assert candidate(numBottles = 60,numExchange = 20) == 62\n assert candidate(numBottles = 99,numExchange = 3) == 111\n assert candidate(numBottles = 99,numExchange = 20) == 103\n assert candidate(numBottles = 100,numExchange = 20) == 104\n assert candidate(numBottles = 3,numExchange = 3) == 4\n assert candidate(numBottles = 50,numExchange = 1) == 60\n assert candidate(numBottles = 70,numExchange = 25) == 72\n assert candidate(numBottles = 6,numExchange = 6) == 7\n assert candidate(numBottles = 65,numExchange = 12) == 69\n assert candidate(numBottles = 55,numExchange = 20) == 57\n assert candidate(numBottles = 25,numExchange = 2) == 31\n assert candidate(numBottles = 95,numExchange = 7) == 104\n assert candidate(numBottles = 45,numExchange = 2) == 53\n assert candidate(numBottles = 90,numExchange = 25) == 93\n assert candidate(numBottles = 95,numExchange = 15) == 100\n assert candidate(numBottles = 45,numExchange = 4) == 52\n assert candidate(numBottles = 99,numExchange = 9) == 107\n assert candidate(numBottles = 25,numExchange = 7) == 28\n assert candidate(numBottles = 30,numExchange = 3) == 36\n assert candidate(numBottles = 5,numExchange = 2) == 7\n assert candidate(numBottles = 60,numExchange = 3) == 69\n assert candidate(numBottles = 45,numExchange = 3) == 53\n assert candidate(numBottles = 25,numExchange = 9) == 27\n assert candidate(numBottles = 90,numExchange = 6) == 99\n assert candidate(numBottles = 90,numExchange = 10) == 97\n assert candidate(numBottles = 70,numExchange = 7) == 77\n assert candidate(numBottles = 90,numExchange = 15) == 95\n assert candidate(numBottles = 50,numExchange = 2) == 59\n", "comparison": "exact"}, "public_tests": ["13\n6", "10\n3"], "hints": ["Simulate the process step by step. At each step, drink numExchange bottles of water then exchange them for a full bottle. Keep repeating this step until you cannot exchange bottles anymore."], "metadata": {"canonical_parameter_names": ["numBottles", "numExchange"], "leetcode_dataset_entry_point": "Solution().maxBottlesDrunk", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:01+00:00", "tests_total": 86, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["math", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def max_bottles_drunk(num_bottles, num_exchange)", "container": null, "callable": "max_bottles_drunk", "parameters": [{"name": "num_bottles", "type": "Integer"}, {"name": "num_exchange", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3101, "task_id": "count-alternating-subarrays", "difficulty": "Medium", "problem_description": "You are given a binary array nums.\n\nWe call a subarray alternating if no two adjacent elements in the subarray have the same value.\n\nReturn the number of alternating subarrays in nums.\n\nExample 1:\n\nInput: nums = [0,1,1,1]\nOutput: 5\nExplanation:\nThe following subarrays are alternating: [0], [1], [1], [1], and [0,1].\n\nExample 2:\n\nInput: nums = [1,0,1,0]\nOutput: 10\nExplanation:\nEvery subarray of the array is alternating. There are 10 possible subarrays that we can choose.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- nums[i] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 0, 0]) == 8\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 21\n assert candidate(nums = [1, 0, 1, 0, 1]) == 15\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 1, 0]) == 16\n assert candidate(nums = [0, 1, 0, 1, 0]) == 15\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [0, 1]) == 3\n assert candidate(nums = [0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [0, 1, 1, 1]) == 5\n assert candidate(nums = [1, 0]) == 3\n assert candidate(nums = [1, 0, 0, 1, 0, 1]) == 13\n assert candidate(nums = [1, 1, 0, 1, 0, 1]) == 16\n assert candidate(nums = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == 21\n assert candidate(nums = [0, 0, 0, 0]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1]) == 36\n assert candidate(nums = [1, 1, 0, 0, 1, 1]) == 8\n assert candidate(nums = [0, 1, 1, 0, 1, 0]) == 13\n assert candidate(nums = [0, 0, 1, 0, 1, 0]) == 16\n assert candidate(nums = [1, 0, 1, 0]) == 10\n assert candidate(nums = [0, 1, 1, 0, 0, 1]) == 9\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 15\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1]) == 33\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 66\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 120\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 27\n assert candidate(nums = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == 18\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0]) == 17\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 16\n assert candidate(nums = [1, 1, 0, 1, 0, 1, 0, 1, 1, 0]) == 32\n assert candidate(nums = [0, 1, 0, 1, 1, 0, 1, 0, 1]) == 25\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 91\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 16\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 253\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 29\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 19\n assert candidate(nums = [1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1]) == 34\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 14\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 22\n assert candidate(nums = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 84\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(nums = [1, 1, 0, 0, 1, 0, 1, 1, 0]) == 17\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1]) == 28\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 18\n assert candidate(nums = [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0]) == 18\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 105\n assert candidate(nums = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 106\n assert candidate(nums = [1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1]) == 48\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 15\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 1, 0, 1, 0]) == 31\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 121\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 190\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 29\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 15\n assert candidate(nums = [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, 1, 0, 1, 0, 1]) == 528\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 11\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 0, 1, 0, 1]) == 31\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 41\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 136\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1]) == 44\n assert candidate(nums = [1, 0, 1, 0, 0, 1, 0, 1, 0, 0]) == 26\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1]) == 12\n assert candidate(nums = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 51\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]) == 22\n assert candidate(nums = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1]) == 34\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 19\n assert candidate(nums = [1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1]) == 46\n assert candidate(nums = [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1]) == 48\n assert candidate(nums = [0, 1, 0, 1, 1, 0, 1, 0, 1, 1]) == 26\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1]) == 13\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 34\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0]) == 11\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 136\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1]) == 49\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 210\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 55\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 11\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 78\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 171\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == 13\n assert candidate(nums = [0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1]) == 35\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1]) == 33\n assert candidate(nums = [0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 46\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1]) == 38\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 1, 0, 0, 1]) == 24\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 14\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 19\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 18\n assert candidate(nums = [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]) == 351\n assert candidate(nums = [1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0]) == 52\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 19\n assert candidate(nums = [0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0]) == 38\n assert candidate(nums = [0, 0, 1, 1, 1, 0, 1, 0, 0, 1]) == 18\n assert candidate(nums = [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]) == 325\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 23\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 17\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0, 1]) == 595\n assert candidate(nums = [0, 1, 1, 0, 1, 0, 1, 1, 0, 0]) == 22\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 19\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1]) == 13\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 15\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 19\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 55\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 210\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0]) == 44\n assert candidate(nums = [1, 0, 1, 1, 0, 1, 0, 0, 1, 0]) == 22\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == 45\n assert candidate(nums = [0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1]) == 49\n", "comparison": "exact"}, "public_tests": ["[0,1,1,1]", "[1,0,1,0]"], "hints": ["Try using dynamic programming.", "Let dp[i] be the number of alternating subarrays ending at index i.", "The final answer is the sum of dp[i] over all indices i from 0 to n - 1."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countAlternatingSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:03+00:00", "tests_total": 110, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math"]}, "language": "ruby", "interface": {"raw_signature": "def count_alternating_subarrays(nums)", "container": null, "callable": "count_alternating_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3102, "task_id": "minimize-manhattan-distances", "difficulty": "Hard", "problem_description": "You are given an array points representing integer coordinates of some points on a 2D plane, where points[i] = [x_i, y_i].\n\nThe distance between two points is defined as their Manhattan distance.\n\nReturn the minimum possible value for maximum distance between any two points by removing exactly one point.\n\nExample 1:\n\nInput: points = [[3,10],[5,15],[10,2],[4,4]]\nOutput: 12\nExplanation:\nThe maximum distance after removing each point is the following:\n- After removing the 0^th point the maximum distance is between points (5, 15) and (10, 2), which is |5 - 10| + |15 - 2| = 18.\n- After removing the 1^st point the maximum distance is between points (3, 10) and (10, 2), which is |3 - 10| + |10 - 2| = 15.\n- After removing the 2^nd point the maximum distance is between points (5, 15) and (4, 4), which is |5 - 4| + |15 - 4| = 12.\n- After removing the 3^rd point the maximum distance is between points (5, 15) and (10, 2), which is |5 - 10| + |15 - 2| = 18.\n\n12 is the minimum possible maximum distance between any two points after removing exactly one point.\n\nExample 2:\n\nInput: points = [[1,1],[1,1],[1,1]]\nOutput: 0\nExplanation:\nRemoving any of the points results in the maximum distance between any two points of 0.\n\nConstraints:\n\n- 3 <= points.length <= 10^5\n- points[i].length == 2\n- 1 <= points[i][0], points[i][1] <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(points = [[1, 9], [9, 1], [2, 8], [8, 2], [3, 7], [7, 3], [4, 6], [6, 4], [5, 5]]) == 14\n assert candidate(points = [[1, 2], [4, 6], [8, 10], [15, 18]]) == 15\n assert candidate(points = [[1, 3], [2, 2], [3, 1], [6, 6], [7, 7], [8, 8]]) == 10\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 6\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 14\n assert candidate(points = [[1, 100000000], [100000000, 1], [1, 1], [100000000, 100000000]]) == 199999998\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 1]]) == 8\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]) == 60\n assert candidate(points = [[1, 1], [1, 1], [1, 1]]) == 0\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 7], [3, 3], [5, 5]]) == 10\n assert candidate(points = [[3, 10], [5, 15], [10, 2], [4, 4]]) == 12\n assert candidate(points = [[1, 1], [10, 10], [1, 10], [10, 1], [1, 5], [5, 1], [5, 5], [2, 2], [8, 8], [3, 3], [7, 7], [4, 4], [6, 6], [9, 9], [2, 9], [8, 2], [3, 7], [7, 3], [4, 6], [6, 4]]) == 18\n assert candidate(points = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100], [110, 120], [130, 140], [150, 160]]) == 240\n assert candidate(points = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == 0\n assert candidate(points = [[1, 1], [10, 1], [1, 10], [10, 10], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [2, 2], [3, 3], [4, 4]]) == 18\n assert candidate(points = [[1, 1], [1, 100000000], [100000000, 1], [100000000, 100000000], [50000000, 50000000], [50000000, 49999999], [50000000, 50000001], [49999999, 50000000], [50000001, 50000000]]) == 199999998\n assert candidate(points = [[1, 1], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100], [110, 110], [120, 120]]) == 218\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [100, 100], [200, 200], [300, 300], [400, 400], [500, 500]]) == 798\n assert candidate(points = [[50000000, 50000000], [1, 1], [100000000, 1], [1, 100000000], [100000000, 100000000]]) == 199999998\n assert candidate(points = [[1, 1], [100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000], [1, 1000], [1000, 1], [500, 500], [500, 1], [1, 500], [1000, 500], [500, 1000], [500, 1], [500, 1000]]) == 1998\n assert candidate(points = [[1, 1], [100000000, 1], [100000000, 100000000], [1, 100000000], [50000000, 50000000]]) == 199999998\n assert candidate(points = [[1, 1], [1, 100000000], [100000000, 1], [100000000, 100000000], [2, 2], [99999999, 99999999]]) == 199999998\n assert candidate(points = [[1, 100000000], [100000000, 1], [100000000, 100000000], [1, 1], [50000000, 50000000], [25000000, 25000000], [75000000, 75000000], [50000000, 1], [1, 50000000], [1, 75000000], [50000000, 100000000], [75000000, 100000000], [100000000, 50000000], [100000000, 25000000], [75000000, 25000000], [25000000, 50000000], [25000000, 75000000], [50000000, 25000000], [50000000, 75000000], [75000000, 50000000]]) == 199999998\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 7], [3, 3], [5, 5], [9, 11], [12, 14], [15, 15], [18, 18]]) == 27\n assert candidate(points = [[1, 100000000], [2, 100000000], [3, 100000000], [4, 100000000], [5, 100000000], [6, 100000000], [7, 100000000], [8, 100000000], [9, 100000000], [10, 100000000]]) == 8\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]]) == 10\n assert candidate(points = [[1, 100000000], [100000000, 1], [1, 1], [100000000, 100000000], [50000000, 50000000], [60000000, 60000000], [40000000, 40000000]]) == 199999998\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 10], [10, 1], [5, 5], [1, 5], [5, 1], [10, 10]]) == 18\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 16\n assert candidate(points = [[10, 10], [20, 10], [10, 20], [20, 20], [15, 15], [12, 12], [18, 18], [12, 18], [18, 12], [15, 20], [20, 15]]) == 20\n assert candidate(points = [[1, 100000000], [2, 99999999], [3, 99999998], [4, 99999997], [5, 99999996], [6, 99999995], [7, 99999994], [8, 99999993], [9, 99999992], [10, 99999991], [50, 95000001], [90, 91000001], [15, 98500001], [30, 97500001], [45, 96500001], [60, 95500001], [75, 94500001], [85, 93500001], [95, 92500001]]) == 7500093\n assert candidate(points = [[1, 1], [100000000, 1], [1, 100000000], [100000000, 100000000], [2, 2], [99999999, 2], [2, 99999999], [99999999, 99999999]]) == 199999998\n assert candidate(points = [[3, 3], [6, 6], [9, 9], [12, 12], [15, 15], [18, 18], [21, 21], [24, 24], [27, 27], [30, 30]]) == 48\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 17\n assert candidate(points = [[100000000, 100000000], [50000000, 50000000], [25000000, 25000000], [12500000, 12500000], [6250000, 6250000], [3125000, 3125000], [1562500, 1562500], [781250, 781250], [390625, 390625], [195312, 195312]]) == 99609376\n assert candidate(points = [[1, 100000000], [100000000, 1], [50000000, 50000000], [25000000, 75000000], [75000000, 25000000], [100000000, 100000000], [1, 1], [100000000, 100000000], [1, 100000000], [100000000, 1]]) == 199999998\n assert candidate(points = [[1, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == 160\n assert candidate(points = [[1, 99999999], [99999999, 1], [50000000, 50000000], [1, 50000000], [50000000, 1], [99999999, 50000000], [50000000, 99999999], [1, 1], [99999999, 99999999], [50000000, 50000000]]) == 199999996\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 50], [100000000, 100000000]]) == 49\n assert candidate(points = [[1, 1], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == 178\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]]) == 26\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], [51, 52], [53, 54], [55, 56], [57, 58], [59, 60], [61, 62], [63, 64], [65, 66], [67, 68], [69, 70]]) == 132\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]]) == 6\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20]]) == 18\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [50, 50], [90, 90], [15, 15], [30, 30], [45, 45], [60, 60], [75, 75], [85, 85], [95, 95]]) == 178\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]]) == 0\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], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25]]) == 46\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]]) == 6\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 5], [5, 1], [3, 1], [1, 3], [3, 5], [5, 3]]) == 8\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], [100, 100]]) == 38\n assert candidate(points = [[50000000, 1], [50000000, 2], [50000000, 3], [50000000, 4], [50000000, 5], [50000000, 6], [50000000, 7], [50000000, 8], [50000000, 9], [50000000, 10]]) == 8\n assert candidate(points = [[1, 1], [100000000, 1], [1, 100000000], [100000000, 100000000], [50000000, 50000000]]) == 199999998\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [1, 3], [2, 3], [3, 1], [3, 2], [1, 4], [2, 4], [3, 4], [4, 1], [4, 2], [4, 3], [4, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 8\n assert candidate(points = [[1, 1], [1, 10], [10, 1], [10, 10], [5, 5], [5, 1], [1, 5], [10, 5], [5, 10], [5, 1]]) == 18\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [1, 3], [3, 1], [2, 3], [3, 2], [1, 4], [4, 1], [2, 4], [4, 2], [3, 3], [1, 5], [5, 1], [2, 5], [5, 2], [3, 4], [4, 3], [3, 5], [5, 3], [4, 4], [4, 5], [5, 4]]) == 7\n assert candidate(points = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]]) == 808\n assert candidate(points = [[1, 1], [100000000, 100000000], [50000000, 50000000], [25000000, 25000000], [75000000, 75000000]]) == 149999998\n assert candidate(points = [[1, 1], [1, 100000000], [100000000, 1], [100000000, 100000000], [50000000, 50000000]]) == 199999998\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90]]) == 140\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [10, 10], [10, 11], [11, 10], [11, 11]]) == 19\n assert candidate(points = [[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]]) == 26\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]]) == 36\n assert candidate(points = [[1, 1], [100000000, 100000000], [50000000, 50000000], [25000000, 25000000], [75000000, 75000000], [12500000, 12500000], [87500000, 87500000], [99999999, 99999999], [1, 99999999], [99999999, 1]]) == 199999996\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]]) == 36\n assert candidate(points = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [1, 1], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]) == 90\n assert candidate(points = [[1, 1], [100000000, 100000000], [50000000, 50000000], [25000000, 25000000], [75000000, 75000000], [12500000, 12500000], [87500000, 87500000]]) == 174999998\n assert candidate(points = [[2, 3], [5, 7], [11, 15], [14, 17], [18, 21], [22, 25], [26, 29], [30, 33], [34, 37], [38, 41]]) == 66\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9], [11, 12], [12, 11]]) == 20\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9]]) == 18\n assert candidate(points = [[100000000, 1], [1, 100000000], [50000000, 50000000], [1, 1], [100000000, 100000000], [2, 2], [99999999, 99999999]]) == 199999998\n assert candidate(points = [[1, 1], [100000000, 1], [1, 100000000], [100000000, 100000000], [50000000, 50000000], [60000000, 60000000], [70000000, 70000000], [80000000, 80000000], [90000000, 90000000]]) == 199999998\n assert candidate(points = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20], [11, 22], [12, 24], [13, 26], [14, 28], [15, 30], [16, 32], [17, 34], [18, 36], [19, 38], [20, 40], [21, 42], [22, 44], [23, 46], [24, 48], [25, 50], [26, 52], [27, 54], [28, 56], [29, 58], [30, 60], [31, 62], [32, 64], [33, 66], [34, 68], [35, 70], [36, 72], [37, 74], [38, 76], [39, 78], [40, 80], [41, 82], [42, 84], [43, 86], [44, 88], [45, 90], [46, 92], [47, 94], [48, 96], [49, 98], [50, 100]]) == 144\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 8\n assert candidate(points = [[3, 3], [6, 6], [9, 9], [12, 12], [15, 15], [18, 18], [21, 21], [24, 24], [27, 27], [30, 30], [33, 33], [36, 36], [39, 39], [42, 42], [45, 45], [48, 48], [51, 51], [54, 54], [57, 57], [60, 60]]) == 108\n assert candidate(points = [[1, 1], [100000000, 1], [1, 100000000], [100000000, 100000000], [50000000, 50000000], [25000000, 25000000], [75000000, 75000000], [37500000, 37500000], [62500000, 62500000], [87500000, 87500000]]) == 199999998\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]]) == 0\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45], [50, 50], [55, 55], [60, 60], [65, 65], [70, 70], [75, 75], [80, 80], [85, 85], [90, 90], [95, 95], [100, 100]]) == 180\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [100000000, 100000000], [100000000, 99999999], [99999999, 100000000], [99999999, 99999999]]) == 199999997\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 16\n assert candidate(points = [[50000000, 50000000], [100000000, 100000000], [50000000, 1], [1, 50000000], [99999999, 99999999], [1, 1], [99999999, 1], [1, 99999999]]) == 199999996\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [100000000, 100000000]]) == 18\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 16\n assert candidate(points = [[50000000, 50000000], [49999999, 49999999], [50000001, 50000001], [50000002, 50000002], [50000003, 50000003], [50000004, 50000004], [50000005, 50000005], [50000006, 50000006], [50000007, 50000007], [50000008, 50000008], [50000009, 50000009]]) == 18\n assert candidate(points = [[1, 100000000], [100000000, 1], [1, 1], [100000000, 100000000], [2, 2], [50, 50], [100, 100]]) == 199999998\n assert candidate(points = [[1, 100000000], [2, 99999999], [3, 99999998], [100000000, 1], [99999999, 2], [99999998, 3]]) == 199999996\n assert candidate(points = [[50000000, 50000000], [50000000, 40000000], [50000000, 30000000], [50000000, 20000000], [50000000, 10000000], [40000000, 50000000], [30000000, 50000000], [20000000, 50000000], [10000000, 50000000]]) == 70000000\n assert candidate(points = [[1, 1], [100000000, 1], [100000000, 100000000], [1, 100000000], [50000000, 50000000], [25000000, 25000000]]) == 199999998\n assert candidate(points = [[1, 100000000], [2, 99999998], [3, 99999996], [100000000, 1], [99999998, 2], [99999996, 3], [50000000, 50000000], [60000000, 60000000], [70000000, 70000000]]) == 199999995\n assert candidate(points = [[1, 1], [1, 100000000], [100000000, 1], [100000000, 100000000], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 199999998\n assert candidate(points = [[1, 2], [1, 4], [1, 6], [1, 8], [1, 10], [2, 1], [2, 3], [2, 5], [2, 7], [2, 9], [3, 1], [3, 3], [3, 5], [3, 7], [3, 9], [4, 1], [4, 3], [4, 5], [4, 7], [4, 9]]) == 10\n assert candidate(points = [[1, 1], [2, 3], [4, 6], [8, 12], [16, 24], [32, 48], [64, 96], [128, 192], [256, 384], [512, 768]]) == 638\n assert candidate(points = [[100000000, 100000000], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 8\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60]]) == 80\n assert candidate(points = [[1000000, 1000000], [2000000, 2000000], [3000000, 3000000]]) == 2000000\n assert candidate(points = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [1, 1], [2, 2], [3, 3], [4, 4], [10, 10]]) == 16\n assert candidate(points = [[1, 1], [100000000, 100000000], [50000000, 50000000]]) == 99999998\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]) == 16\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 9], [3, 5]]) == 8\n assert candidate(points = [[1, 2], [4, 6], [8, 3], [3, 1], [5, 5]]) == 7\n assert candidate(points = [[100000000, 100000000], [1, 1], [2, 2]]) == 2\n assert candidate(points = [[100000000, 100000000], [1, 1], [50000000, 50000000]]) == 99999998\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5]]) == 8\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [100, 100], [200, 200]]) == 198\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [1, 10]]) == 14\n assert candidate(points = [[1, 99999999], [99999999, 1], [49999999, 50000000], [50000000, 49999999]]) == 99999999\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 7], [10, 10]]) == 10\n assert candidate(points = [[1, 1], [2, 2], [1, 2], [2, 1], [3, 3]]) == 2\n assert candidate(points = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]]) == 12\n assert candidate(points = [[1, 10], [10, 1], [5, 5], [3, 3], [8, 8], [2, 2], [7, 7], [4, 4], [6, 6], [9, 9]]) == 14\n assert candidate(points = [[1, 2], [4, 6], [8, 3], [3, 1], [7, 9]]) == 8\n assert candidate(points = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [1, 1], [2, 2], [3, 3], [4, 4]]) == 14\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 6\n assert candidate(points = [[5, 5], [5, 10], [10, 5], [10, 10], [15, 15]]) == 10\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25]]) == 30\n assert candidate(points = [[1, 2], [4, 6], [7, 8], [2, 1], [5, 5]]) == 7\n assert candidate(points = [[1, 2], [4, 6], [5, 3], [3, 1], [7, 5]]) == 7\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [100000000, 100000000]]) == 8\n assert candidate(points = [[100000000, 100000000], [1, 1], [50000000, 50000000], [99999999, 99999999]]) == 100000000\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 14\n assert candidate(points = [[100000000, 1], [2, 100000000], [100000000, 100000000]]) == 99999998\n assert candidate(points = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == 14\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30]]) == 40\n assert candidate(points = [[1, 100000000], [100000000, 1], [100000000, 100000000], [1, 1]]) == 199999998\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [100000000, 100000000], [5, 5]]) == 8\n assert candidate(points = [[1, 100000000], [100000000, 1], [50000000, 50000000], [25000000, 75000000]]) == 99999999\n assert candidate(points = [[1, 2], [4, 6], [7, 8], [2, 10], [9, 2]]) == 12\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [100000000, 100000000], [4, 4], [5, 5]]) == 8\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [7, 8]]) == 8\n assert candidate(points = [[100000000, 100000000], [1, 1], [2, 2], [3, 3]]) == 4\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16]]) == 28\n assert candidate(points = [[1, 5], [2, 3], [3, 8], [4, 2], [5, 7]]) == 7\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 7], [3, 3]]) == 10\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 14\n assert candidate(points = [[1, 1], [100000000, 100000000], [2, 2], [3, 3], [4, 4], [5, 5]]) == 8\n assert candidate(points = [[100000000, 100000000], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 16\n assert candidate(points = [[1, 2], [4, 6], [8, 8], [7, 4], [6, 1]]) == 8\n assert candidate(points = [[1, 1], [2, 2], [3, 1], [2, 3], [1, 2], [2, 1]]) == 3\n assert candidate(points = [[5, 5], [6, 6], [7, 7], [8, 8], [1, 1], [2, 2], [3, 3], [4, 4]]) == 12\n assert candidate(points = [[100000000, 100000000], [1, 1], [2, 2], [3, 3], [4, 4]]) == 6\n assert candidate(points = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70]]) == 80\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4]]) == 4\n assert candidate(points = [[1, 2], [4, 6], [5, 3], [2, 8]]) == 7\n assert candidate(points = [[1, 2], [4, 6], [5, 3], [3, 1], [8, 9]]) == 7\n assert candidate(points = [[1, 2], [4, 6], [7, 8], [2, 1], [5, 5], [8, 4]]) == 9\n assert candidate(points = [[1, 2], [4, 6], [5, 1], [8, 3], [3, 8], [7, 7], [9, 4]]) == 10\n assert candidate(points = [[1, 3], [2, 5], [5, 8], [6, 7], [8, 10], [9, 12]]) == 14\n assert candidate(points = [[1, 1], [2, 2], [100000000, 100000000], [3, 3], [4, 4], [5, 5]]) == 8\n assert candidate(points = [[100000, 100000], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 8\n assert candidate(points = [[1, 99999999], [99999999, 1], [50000000, 50000000], [25000000, 25000000], [75000000, 75000000]]) == 100000000\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == 10\n assert candidate(points = [[1, 100000000], [100000000, 1], [1, 1], [100000000, 100000000], [50000000, 50000000]]) == 199999998\n", "comparison": "exact"}, "public_tests": ["[[3,10],[5,15],[10,2],[4,4]]", "[[1,1],[1,1],[1,1]]"], "hints": ["Notice that the Manhattan distance between two points [x_i, y_i] and [x_j, y_j] is max({x_i - x_j + y_i - y_j, x_i - x_j - y_i + y_j, - x_i + x_j + y_i - y_j, - x_i + x_j - y_i + y_j}).", "If you replace points as [x_i - y_i, x_i + y_i] then the Manhattan distance is max(max(x_i) - min(x_i), max(y_i) - min(y_i)) over all i.", "After those observations, the problem just becomes a simulation. Create multiset of points [x_i - y_i, x_i + y_i], you can iterate on a point you might remove and get the maximum Manhattan distance over all other points."], "metadata": {"canonical_parameter_names": ["points"], "leetcode_dataset_entry_point": "Solution().minimumDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:06+00:00", "tests_total": 155, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "math", "geometry", "sorting", "ordered-set"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_distance(points)", "container": null, "callable": "minimum_distance", "parameters": [{"name": "points", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3105, "task_id": "longest-strictly-increasing-or-strictly-decreasing-subarray", "difficulty": "Easy", "problem_description": "You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing.\n\nExample 1:\n\nInput: nums = [1,4,3,3,2]\nOutput: 2\nExplanation:\nThe strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4].\nThe strictly decreasing subarrays of nums are [1], [2], [3], [3], [4], [3,2], and [4,3].\nHence, we return 2.\n\nExample 2:\n\nInput: nums = [3,3,3,3]\nOutput: 1\nExplanation:\nThe strictly increasing subarrays of nums are [3], [3], [3], and [3].\nThe strictly decreasing subarrays of nums are [3], [3], [3], and [3].\nHence, we return 1.\n\nExample 3:\n\nInput: nums = [3,2,1]\nOutput: 3\nExplanation:\nThe strictly increasing subarrays of nums are [3], [2], and [1].\nThe strictly decreasing subarrays of nums are [3], [2], [1], [3,2], [2,1], and [3,2,1].\nHence, we return 3.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 4, 7, 8, 6, 9]) == 3\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == 4\n assert candidate(nums = [10, 9, 4, 3, 3, 2, 1]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [3, 3, 3, 3]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [10, 9, 4, 3, 5, 7, 6, 8, 1]) == 4\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 3, 2, 4, 3, 5]) == 2\n assert candidate(nums = [1, 3, 5, 4, 7]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [4, 5, 6, 3, 2, 1, 2, 3]) == 4\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6]) == 4\n assert candidate(nums = [1, 4, 3, 3, 2]) == 2\n assert candidate(nums = [1, 3, 5, 4, 2]) == 3\n assert candidate(nums = [3, 2, 1]) == 3\n assert candidate(nums = [4, 3, 3, 2, 1]) == 3\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 3, 2, 4, 3]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9]) == 6\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 2\n assert candidate(nums = [3, 2, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 5, 5, 4, 3, 2]) == 5\n assert candidate(nums = [10, 9, 8, 7, 8, 9, 10, 9, 8, 7, 8, 9, 10, 9, 8, 7]) == 4\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 8\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2]) == 4\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 3]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 3, 4, 5, 6, 7, 5, 4, 3, 2, 1, 2, 3]) == 6\n assert candidate(nums = [2, 1, 3, 2, 4, 3, 5, 4, 6, 5]) == 2\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]) == 50\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 4, 3, 2, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3]) == 5\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 9\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 5, 6, 7, 8]) == 5\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [10, 20, 15, 10, 5, 10, 15, 20, 25, 20, 15, 10, 5]) == 5\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\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]) == 5\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 2\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5]) == 10\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 5, 6, 7, 8, 9]) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 2\n assert candidate(nums = [10, 9, 9, 9, 9, 9, 9, 9, 9, 8]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 5, 4, 5, 6]) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 6, 4, 2, 1, 3, 5, 7, 9, 8, 6, 4, 2, 1]) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 2\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 3, 2, 1, 2, 3, 4, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1, 3, 5, 7]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\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, 50]) == 26\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [9, 8, 7, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 8, 5, 9]) == 4\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 10]) == 4\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 10\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9]) == 2\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 5, 8]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [10, 20, 15, 10, 5, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 2\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9, 10]) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 14, 12, 10, 8, 6, 4, 2, 4, 6, 8, 10, 12, 14, 16, 18]) == 9\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1]) == 6\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, 2, 3, 4, 5]) == 5\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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, 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]) == 50\n assert candidate(nums = [10, 9, 8, 7, 7, 6, 5, 4, 3, 2]) == 6\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8]) == 9\n assert candidate(nums = [5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9, 10, 9]) == 3\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 6\n assert candidate(nums = [2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2]) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 10, 8, 6, 4, 2]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [50, 49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 26\n assert candidate(nums = [10, 20, 30, 25, 20, 15, 10, 5, 1, 2, 3, 4, 5, 6]) == 7\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [2, 3, 1, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 8, 7, 6, 5, 6]) == 5\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,4,3,3,2]", "[3,3,3,3]", "[3,2,1]"], "hints": [], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().longestMonotonicSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:10+00:00", "tests_total": 139, "tests_dropped": 1, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def longest_monotonic_subarray(nums)", "container": null, "callable": "longest_monotonic_subarray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3106, "task_id": "lexicographically-smallest-string-after-operations-with-constraint", "difficulty": "Medium", "problem_description": "You are given a string s and an integer k.\n\nDefine a function distance(s_1, s_2) between two strings s_1 and s_2 of the same length n as:\n\n- The sum of the minimum distance between s_1[i] and s_2[i] when the characters from 'a' to 'z' are placed in a cyclic order, for all i in the range [0, n - 1].\n\nFor example, distance(\"ab\", \"cd\") == 4, and distance(\"a\", \"z\") == 1.\n\nYou can change any letter of s to any other lowercase English letter, any number of times.\n\nReturn a string denoting the lexicographically smallest string t you can get after some changes, such that distance(s, t) <= k.\n\nExample 1:\n\nInput: s = \"zbbz\", k = 3\nOutput: \"aaaz\"\nExplanation:\nChange s to \"aaaz\". The distance between \"zbbz\" and \"aaaz\" is equal to k = 3.\n\nExample 2:\n\nInput: s = \"xaxcd\", k = 4\nOutput: \"aawcd\"\nExplanation:\nThe distance between \"xaxcd\" and \"aawcd\" is equal to k = 4.\n\nExample 3:\n\nInput: s = \"lol\", k = 0\nOutput: \"lol\"\nExplanation:\nIt's impossible to change any character as k = 0.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- 0 <= k <= 2000\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zbbz\",k = 3) == \"aaaz\"\n assert candidate(s = \"abc\",k = 1) == \"aac\"\n assert candidate(s = \"abc\",k = 0) == \"abc\"\n assert candidate(s = \"zzz\",k = 9) == \"aaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 50) == \"aaaaaaaaalponmlkjihgfedcba\"\n assert candidate(s = \"xyz\",k = 10) == \"aaa\"\n assert candidate(s = \"aaa\",k = 5) == \"aaa\"\n assert candidate(s = \"abc\",k = 2) == \"aab\"\n assert candidate(s = \"vwxyz\",k = 25) == \"aaaaa\"\n assert candidate(s = \"hello\",k = 7) == \"aello\"\n assert candidate(s = \"abcd\",k = 10) == \"aaaa\"\n assert candidate(s = \"aaaa\",k = 10) == \"aaaa\"\n assert candidate(s = \"qrst\",k = 20) == \"aart\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 26) == \"aaaaaaacijklmnopqrstuvwxyz\"\n assert candidate(s = \"xaxcd\",k = 4) == \"aawcd\"\n assert candidate(s = \"abc\",k = 26) == \"aaa\"\n assert candidate(s = \"zzzz\",k = 25) == \"aaaa\"\n assert candidate(s = \"abcdef\",k = 10) == \"aaaaaf\"\n assert candidate(s = \"zzzz\",k = 1) == \"azzz\"\n assert candidate(s = \"mnop\",k = 15) == \"akop\"\n assert candidate(s = \"lol\",k = 0) == \"lol\"\n assert candidate(s = \"zzz\",k = 6) == \"aaa\"\n assert candidate(s = \"zzzz\",k = 26) == \"aaaa\"\n assert candidate(s = \"aaaa\",k = 1) == \"aaaa\"\n assert candidate(s = \"abcdef\",k = 26) == \"aaaaaa\"\n assert candidate(s = \"abcdefg\",k = 0) == \"abcdefg\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 100) == \"aaaaaaaaaaaaadlkjihgfedcba\"\n assert candidate(s = \"aaaabbbbcccc\",k = 12) == \"aaaaaaaaaaaa\"\n assert candidate(s = \"zzzz\",k = 16) == \"aaaa\"\n assert candidate(s = \"abcdabcdabcd\",k = 30) == \"aaaaaaaaaaaa\"\n assert candidate(s = \"abcdef\",k = 30) == \"aaaaaa\"\n assert candidate(s = \"xyzabc\",k = 12) == \"aaaaaa\"\n assert candidate(s = \"qrstuv\",k = 50) == \"aaaaaa\"\n assert candidate(s = \"aabbcc\",k = 12) == \"aaaaaa\"\n assert candidate(s = \"qrstuvwxyz\",k = 26) == \"aaltuvwxyz\"\n assert candidate(s = \"mnopqr\",k = 15) == \"akopqr\"\n assert candidate(s = \"programming\",k = 50) == \"aaaaaajming\"\n assert candidate(s = \"mnop\",k = 25) == \"aaop\"\n assert candidate(s = \"qqqqqqqqqqqq\",k = 50) == \"aaaaaqqqqqqq\"\n assert candidate(s = \"cryptography\",k = 100) == \"aaaaaaaaaaaa\"\n assert candidate(s = \"nopqrs\",k = 100) == \"aaaaaa\"\n assert candidate(s = \"abcde\",k = 50) == \"aaaaa\"\n assert candidate(s = \"abcdef\",k = 18) == \"aaaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 2000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 2000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaa\",k = 2000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 52) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"qwerasdfzxcv\",k = 15) == \"aadrasdfzxcv\"\n assert candidate(s = \"aaaaaaaaaa\",k = 9) == \"aaaaaaaaaa\"\n assert candidate(s = \"qrstuv\",k = 30) == \"aaaquv\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",k = 26) == \"aaaaaaacijklmnopqrstuvwxyza\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 25) == \"aaaaaaadijklmnopqrstuvwxyz\"\n assert candidate(s = \"vutsrqponmlkjihgfedcba\",k = 500) == \"aaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"zzzzzzzzzz\",k = 25) == \"aaaaaaaaaa\"\n assert candidate(s = \"abcdefg\",k = 5) == \"aaabefg\"\n assert candidate(s = \"abcdefghijklm\",k = 39) == \"aaaaaaaaagklm\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 400) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",k = 150) == \"aaaaaaaaaaaaaaaaaaaaaaaahm\"\n assert candidate(s = \"zzzzzzzzzz\",k = 9) == \"aaaaaaaaaz\"\n assert candidate(s = \"abcdef\",k = 25) == \"aaaaaa\"\n assert candidate(s = \"abcdefg\",k = 20) == \"aaaaaab\"\n assert candidate(s = \"abcdef\",k = 0) == \"abcdef\"\n assert candidate(s = \"wxyz\",k = 8) == \"aaxz\"\n assert candidate(s = \"zzzzzzzzzz\",k = 260) == \"aaaaaaaaaa\"\n assert candidate(s = \"mmmm\",k = 15) == \"ajmm\"\n assert candidate(s = \"abcabcabcabc\",k = 12) == \"aaaaaaaaaaaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 1000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"zzzz\",k = 15) == \"aaaa\"\n assert candidate(s = \"zzzzzz\",k = 50) == \"aaaaaa\"\n assert candidate(s = \"abcdefghij\",k = 35) == \"aaaaaaaabj\"\n assert candidate(s = \"mnopqr\",k = 30) == \"aajpqr\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 2000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 1300) == \"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",k = 500) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"abcdabcd\",k = 16) == \"aaaaaaaa\"\n assert candidate(s = \"nopqrstuvwxyz\",k = 78) == \"aaaaaaaatwxyz\"\n assert candidate(s = \"xyzzxyzzxyzz\",k = 18) == \"aaaaaaaaaxzz\"\n assert candidate(s = \"wxyz\",k = 11) == \"aaaa\"\n assert candidate(s = \"abcdabcdabcd\",k = 26) == \"aaaaaaaaaaaa\"\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",k = 1000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"abcdefghij\",k = 26) == \"aaaaaaacij\"\n assert candidate(s = \"abcdefghij\",k = 15) == \"aaaaaaghij\"\n assert candidate(s = \"aaaabbbb\",k = 7) == \"aaaaaaaa\"\n assert candidate(s = \"zzzz\",k = 8) == \"aaaa\"\n assert candidate(s = \"qrst\",k = 100) == \"aaaa\"\n assert candidate(s = \"mnopqr\",k = 10) == \"cnopqr\"\n assert candidate(s = \"hello\",k = 15) == \"aahlo\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 1000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 50) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabdabcd\"\n assert candidate(s = \"qqqqqqqq\",k = 64) == \"aaaaaamq\"\n assert candidate(s = \"zzzzzzzzzz\",k = 100) == \"aaaaaaaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"abcdxyz\",k = 50) == \"aaaaaaa\"\n assert candidate(s = \"aquickbrownfoxjumps\",k = 50) == \"aaaaaaaakwnfoxjumps\"\n assert candidate(s = \"abcxyz\",k = 12) == \"aaaaaa\"\n assert candidate(s = \"abcdef\",k = 13) == \"aaaaac\"\n assert candidate(s = \"wxyz\",k = 5) == \"awyz\"\n assert candidate(s = \"abcd\",k = 100) == \"aaaa\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 1300) == \"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewq\",k = 50) == \"aaaaaaaaijhgfdsapoiuytrewq\"\n assert candidate(s = \"vwxyz\",k = 30) == \"aaaaa\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",k = 200) == \"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"qrstuv\",k = 10) == \"arstuv\"\n assert candidate(s = \"mnopqr\",k = 20) == \"afopqr\"\n assert candidate(s = \"jklmno\",k = 15) == \"aelmno\"\n assert candidate(s = \"qzab\",k = 5) == \"lzab\"\n assert candidate(s = \"abcdefghij\",k = 45) == \"aaaaaaaaaa\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 500) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"mnop\",k = 20) == \"afop\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 26) == \"aaaaaaosrqponmlkjihgfedcba\"\n", "comparison": "exact"}, "public_tests": ["\"zbbz\"\n3", "\"xaxcd\"\n4", "\"lol\"\n0"], "hints": ["The problem can be approached greedily.", "For each index in order from 0 to n - 1, we try all letters from 'a' to 'z', selecting the first one as long as the current total distance accumulated is not larger than k."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:12+00:00", "tests_total": 110, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def get_smallest_string(s, k)", "container": null, "callable": "get_smallest_string", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3107, "task_id": "minimum-operations-to-make-median-of-array-equal-to-k", "difficulty": "Medium", "problem_description": "You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1.\n\nReturn the minimum number of operations needed to make the median of nums equal to k.\n\nThe median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.\n\nExample 1:\n\nInput: nums = [2,5,6,8,5], k = 4\nOutput: 2\nExplanation:\nWe can subtract one from nums[1] and nums[4] to obtain [2, 4, 6, 8, 4]. The median of the resulting array is equal to k.\n\nExample 2:\n\nInput: nums = [2,5,6,8,5], k = 7\nOutput: 3\nExplanation:\nWe can add one to nums[1] twice and add one to nums[2] once to obtain [2, 7, 7, 8, 5].\n\nExample 3:\n\nInput: nums = [1,2,3,4,5,6], k = 4\nOutput: 0\nExplanation:\nThe median of the array is already equal to k.\n\nConstraints:\n\n- 1 <= nums.length <= 2 * 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 3, 3, 7, 7, 9],k = 3) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3],k = 500000000) == 499999997\n assert candidate(nums = [2, 5, 6, 8, 5],k = 7) == 3\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 4) == 0\n assert candidate(nums = [2, 5, 6, 8, 5],k = 4) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 0\n assert candidate(nums = [1, 2, 3, 100, 101],k = 3) == 0\n assert candidate(nums = [1, 3, 3, 3, 7],k = 3) == 0\n assert candidate(nums = [1, 3, 3, 3, 7, 7, 9],k = 5) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],k = 30) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],k = 35) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 8\n assert candidate(nums = [2, 3, 1, 5, 4, 6, 8, 7, 9],k = 6) == 1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 20) == 100\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],k = 5) == 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],k = 5) == 40\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999],k = 1000000000) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 6) == 0\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],k = 4) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],k = 8) == 1\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],k = 5) == 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, 21],k = 11) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 4) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 14\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 = 2) == 15\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 = 2) == 10\n assert candidate(nums = [5, 1, 9, 3, 7, 11, 13, 15, 17, 19],k = 10) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100],k = 600) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70],k = 40) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 15) == 0\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000],k = 500000000) == 500000000\n assert candidate(nums = [1000000000, 500000000, 750000000, 250000000, 1000],k = 500000000) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 105) == 5\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],k = 11) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 10) == 0\n assert candidate(nums = [1, 3, 3, 6, 7, 8, 9, 10, 11],k = 8) == 1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 2],k = 10) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 5, 5, 6],k = 3) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000],k = 6500) == 500\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 = 15) == 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],k = 6) == 0\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996],k = 500000000) == 499999996\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 1000000000) == 3062500000\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 = 10) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 3) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 50) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],k = 7) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 80) == 0\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 95) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4],k = 2) == 0\n assert candidate(nums = [9, 3, 5, 7, 1, 8, 2, 4, 6],k = 5) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 5) == 1\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],k = 10) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1) == 5999999994\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 11) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 20\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 12\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],k = 30) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 500000000) == 1500000000\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70],k = 35) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5],k = 6) == 4\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 29) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 6) == 1\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],k = 10) == 65\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 25\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130],k = 65) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],k = 7) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 20) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 500) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 999999999) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70],k = 45) == 5\n", "comparison": "exact"}, "public_tests": ["[2,5,6,8,5]\n4", "[2,5,6,8,5]\n7", "[1,2,3,4,5,6]\n4"], "hints": ["Sort nums in non-descending order.", "For all the smaller values on the left side of the median, change them to k if they are larger than k.", "For all the larger values on the right side of the median, change them to k if they are smaller than k."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minOperationsToMakeMedianK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:15+00:00", "tests_total": 87, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations_to_make_median_k(nums, k)", "container": null, "callable": "min_operations_to_make_median_k", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3108, "task_id": "minimum-cost-walk-in-weighted-graph", "difficulty": "Hard", "problem_description": "There is an undirected weighted graph with n vertices labeled from 0 to n - 1.\n\nYou are given the integer n and an array edges, where edges[i] = [u_i, v_i, w_i] indicates that there is an edge between vertices u_i and v_i with a weight of w_i.\n\nA walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that comes before it and the vertex that comes after it. It's important to note that a walk may visit the same edge or vertex more than once.\n\nThe cost of a walk starting at node u and ending at node v is defined as the bitwise AND of the weights of the edges traversed during the walk. In other words, if the sequence of edge weights encountered during the walk is w_0, w_1, w_2, ..., w_k, then the cost is calculated as w_0 & w_1 & w_2 & ... & w_k, where & denotes the bitwise AND operator.\n\nYou are also given a 2D array query, where query[i] = [s_i, t_i]. For each query, you need to find the minimum cost of the walk starting at vertex s_i and ending at vertex t_i. If there exists no such walk, the answer is -1.\n\nReturn the array answer, where answer[i] denotes the minimum cost of a walk for query i.\n\nExample 1:\n\nInput: n = 5, edges = [[0,1,7],[1,3,7],[1,2,1]], query = [[0,3],[3,4]]\nOutput: [1,-1]\nExplanation:\nTo achieve the cost of 1 in the first query, we need to move on the following edges: 0->1 (weight 7), 1->2 (weight 1), 2->1 (weight 1), 1->3 (weight 7).\nIn the second query, there is no walk between nodes 3 and 4, so the answer is -1.\nExample 2:\n\nInput: n = 3, edges = [[0,2,7],[0,1,15],[1,2,6],[1,2,1]], query = [[1,2]]\nOutput: [0]\nExplanation:\nTo achieve the cost of 0 in the first query, we need to move on the following edges: 1->2 (weight 1), 2->1 (weight 6), 1->2 (weight 1).\n\nConstraints:\n\n- 2 <= n <= 10^5\n- 0 <= edges.length <= 10^5\n- edges[i].length == 3\n- 0 <= u_i, v_i <= n - 1\n- u_i != v_i\n- 0 <= w_i <= 10^5\n- 1 <= query.length <= 10^5\n- query[i].length == 2\n- 0 <= s_i, t_i <= n - 1\n- s_i != t_i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,edges = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 9, 5]],query = [[0, 9], [1, 8]]) == [-1, -1]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 1]],query = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(n = 10,edges = [[0, 1, 100], [1, 2, 50], [2, 3, 25], [3, 4, 10], [4, 5, 5], [5, 6, 2], [6, 7, 1], [7, 8, 4], [8, 9, 8]],query = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(n = 3,edges = [[0, 2, 7], [0, 1, 15], [1, 2, 6], [1, 2, 1]],query = [[1, 2]]) == [0]\n assert candidate(n = 4,edges = [[0, 1, 12], [1, 2, 10], [2, 3, 8], [3, 0, 6]],query = [[0, 2], [1, 3]]) == [0, 0]\n assert candidate(n = 8,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70]],query = [[0, 7], [1, 6], [2, 5]]) == [0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 4], [3, 4, 8], [4, 5, 16]],query = [[0, 5], [2, 3]]) == [0, 0]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]],query = [[0, 6], [1, 5], [2, 4]]) == [0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]],query = [[0, 5], [2, 4], [1, 3]]) == [0, 0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 2], [2, 3, 1], [3, 0, 4]],query = [[0, 2], [1, 3]]) == [0, 0]\n assert candidate(n = 5,edges = [],query = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [-1, -1, -1, -1]\n assert candidate(n = 4,edges = [],query = [[0, 1], [1, 2], [2, 3], [3, 0]]) == [-1, -1, -1, -1]\n assert candidate(n = 6,edges = [[0, 1, 8], [1, 2, 4], [2, 3, 2], [3, 4, 1], [4, 5, 6], [5, 0, 3]],query = [[0, 3], [2, 5], [1, 4]]) == [0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 12], [1, 2, 11], [2, 3, 10], [3, 4, 9], [4, 5, 8], [5, 0, 7]],query = [[0, 5], [1, 4], [2, 3], [3, 2], [4, 1], [5, 0]]) == [0, 0, 0, 0, 0, 0]\n assert candidate(n = 8,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7]],query = [[0, 7], [1, 6]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2], [3, 0, 4]],query = [[0, 2], [1, 3], [0, 3]]) == [0, 0, 0]\n assert candidate(n = 7,edges = [[0, 1, 7], [1, 2, 5], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 6]],query = [[0, 6], [2, 4]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2]],query = [[0, 3], [1, 2], [2, 0]]) == [0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 4], [1, 2, 3], [2, 3, 2], [3, 4, 1], [4, 5, 5]],query = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2]],query = [[0, 2], [1, 3]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 3], [2, 3, 3]],query = [[0, 2], [1, 3]]) == [3, 3]\n assert candidate(n = 7,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]],query = [[0, 6], [1, 5]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2], [3, 0, 4]],query = [[0, 2], [1, 3], [2, 0]]) == [0, 0, 0]\n assert candidate(n = 10,edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10], [6, 7, 10], [7, 8, 10], [8, 9, 10]],query = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [10, 10, 10, 10, 10]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 1]],query = [[0, 5], [1, 4], [2, 3]]) == [0, 0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 8]],query = [[0, 2], [1, 3], [2, 0]]) == [0, 0, 0]\n assert candidate(n = 7,edges = [[0, 1, 10], [1, 2, 11], [2, 3, 12], [3, 4, 13], [4, 5, 14], [5, 6, 15], [6, 0, 16]],query = [[0, 6], [1, 3]]) == [0, 0]\n assert candidate(n = 8,edges = [[0, 1, 8], [1, 2, 4], [2, 3, 2], [3, 4, 1], [4, 5, 16], [5, 6, 8], [6, 7, 4]],query = [[0, 7], [1, 6], [2, 5], [3, 4]]) == [0, 0, 0, 0]\n assert candidate(n = 7,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]],query = [[0, 6], [1, 5], [2, 4]]) == [0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 3], [2, 3, 1], [3, 4, 2], [4, 5, 6]],query = [[0, 5], [2, 4], [1, 3]]) == [0, 0, 0]\n assert candidate(n = 7,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60]],query = [[0, 6], [2, 5]]) == [0, 0]\n assert candidate(n = 3,edges = [[0, 1, 10], [1, 2, 5]],query = [[0, 2], [1, 0]]) == [0, 0]\n assert candidate(n = 7,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 5, 2], [5, 6, 2]],query = [[0, 6], [1, 5]]) == [2, 2]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 3], [2, 3, 3]],query = [[0, 3], [1, 2]]) == [3, 3]\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5]],query = [[0, 1], [0, 2], [0, 3], [0, 4]]) == [0, 0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 2], [1, 2, 4], [2, 3, 8], [3, 4, 16], [4, 5, 32]],query = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(n = 8,edges = [],query = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [-1, -1, -1, -1]\n assert candidate(n = 10,edges = [[0, 1, 10], [1, 2, 9], [2, 3, 8], [3, 4, 7], [4, 5, 6], [5, 6, 5], [6, 7, 4], [7, 8, 3], [8, 9, 2], [9, 0, 1]],query = [[0, 9], [1, 8]]) == [0, 0]\n assert candidate(n = 10,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1]],query = [[0, 9], [3, 6]]) == [1, 1]\n assert candidate(n = 12,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 5, 2], [5, 6, 2], [6, 7, 2], [7, 8, 2], [8, 9, 2], [9, 10, 2], [10, 11, 2]],query = [[0, 11], [3, 8]]) == [2, 2]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]],query = [[0, 6], [1, 4]]) == [0, 0]\n assert candidate(n = 5,edges = [[0, 1, 31], [1, 2, 29], [2, 3, 33], [3, 4, 35]],query = [[0, 4], [1, 3], [2, 0], [3, 1], [4, 2]]) == [1, 1, 1, 1, 1]\n assert candidate(n = 4,edges = [[0, 1, 8], [1, 2, 4], [2, 3, 2]],query = [[0, 3], [1, 2]]) == [0, 0]\n assert candidate(n = 9,edges = [[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 0, 5]],query = [[0, 8], [1, 2], [3, 4], [5, 6], [7, 0]]) == [1, -1, -1, -1, -1]\n assert candidate(n = 7,edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10]],query = [[0, 6], [1, 5]]) == [10, 10]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 3], [2, 3, 1], [3, 4, 4], [4, 5, 2]],query = [[0, 5], [1, 4]]) == [0, 0]\n assert candidate(n = 9,edges = [[0, 1, 100], [1, 2, 200], [2, 3, 300], [3, 4, 400], [4, 5, 500], [5, 6, 600], [6, 7, 700], [7, 8, 800]],query = [[0, 8], [4, 7]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 3], [1, 2, 2], [2, 3, 1], [3, 4, 4], [4, 5, 5]],query = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(n = 9,edges = [[0, 1, 9], [1, 2, 8], [2, 3, 7], [3, 4, 6], [4, 5, 5], [5, 6, 4], [6, 7, 3], [7, 8, 2], [8, 0, 1]],query = [[0, 8], [1, 7]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 2], [2, 3, 1]],query = [[0, 2], [1, 3], [2, 0]]) == [0, 0, 0]\n assert candidate(n = 3,edges = [],query = [[0, 1], [1, 2], [2, 0]]) == [-1, -1, -1]\n assert candidate(n = 4,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30]],query = [[0, 3], [1, 2], [2, 0]]) == [0, 0, 0]\n assert candidate(n = 10,edges = [[0, 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]],query = [[0, 9], [1, 8], [2, 7]]) == [0, 0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 2], [2, 3, 1]],query = [[0, 2], [1, 3], [0, 3]]) == [0, 0, 0]\n assert candidate(n = 4,edges = [[0, 1, 15], [1, 2, 25], [2, 3, 35], [3, 0, 45]],query = [[0, 3], [1, 2], [2, 1], [3, 0]]) == [1, 1, 1, 1]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 0, 7]],query = [[0, 6], [2, 4]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 0, 7]],query = [[0, 5], [1, 4]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 3], [2, 3, 4], [3, 4, 2], [4, 5, 1]],query = [[0, 5], [1, 4]]) == [0, 0]\n assert candidate(n = 11,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5], [5, 6, 5], [6, 7, 5], [7, 8, 5], [8, 9, 5], [9, 10, 5]],query = [[0, 10], [2, 7]]) == [5, 5]\n assert candidate(n = 4,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 0, 5]],query = [[0, 2], [1, 3]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 1], [2, 4, 7], [3, 4, 3]],query = [[0, 4], [2, 5]]) == [0, -1]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]],query = [[0, 6], [1, 5]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2], [3, 0, 4]],query = [[0, 2], [1, 3]]) == [0, 0]\n assert candidate(n = 8,edges = [[0, 1, 8], [1, 2, 7], [2, 3, 6], [3, 4, 5], [4, 5, 4], [5, 6, 3], [6, 7, 2], [7, 0, 1]],query = [[0, 7], [1, 6], [2, 5]]) == [0, 0, 0]\n assert candidate(n = 12,edges = [[0, 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]],query = [[0, 11], [1, 10]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]],query = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2], [3, 4, 8], [4, 5, 4]],query = [[0, 5], [1, 4]]) == [0, 0]\n assert candidate(n = 7,edges = [[0, 1, 6], [1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1]],query = [[0, 6], [2, 5]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 0, 10]],query = [[0, 3], [1, 2], [0, 2]]) == [10, 10, 10]\n assert candidate(n = 7,edges = [],query = [[0, 1], [2, 3], [4, 5]]) == [-1, -1, -1]\n assert candidate(n = 5,edges = [],query = [[0, 4], [1, 3]]) == [-1, -1]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]],query = [[0, 6], [1, 5], [2, 4], [3, 0]]) == [0, 0, 0, 0]\n assert candidate(n = 6,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 2], [3, 4, 6], [4, 5, 4]],query = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 2], [1, 2, 4], [2, 3, 6], [3, 4, 8], [4, 5, 10], [5, 0, 1]],query = [[0, 5], [1, 4], [2, 3]]) == [0, 0, 0]\n assert candidate(n = 8,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7]],query = [[0, 7], [3, 6]]) == [0, 0]\n assert candidate(n = 5,edges = [[0, 1, 7], [1, 3, 7], [1, 2, 1]],query = [[0, 3], [3, 4]]) == [1, -1]\n assert candidate(n = 4,edges = [[0, 1, 12], [1, 2, 8], [2, 3, 10]],query = [[0, 3], [1, 2], [2, 3]]) == [8, 8, 8]\n assert candidate(n = 4,edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 0, 10]],query = [[0, 2], [1, 3]]) == [10, 10]\n assert candidate(n = 11,edges = [[0, 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]],query = [[0, 10], [1, 9]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5]],query = [[0, 5], [2, 4]]) == [5, 5]\n assert candidate(n = 4,edges = [[0, 1, 8], [1, 2, 4], [2, 3, 2], [3, 0, 1]],query = [[0, 2], [1, 3]]) == [0, 0]\n assert candidate(n = 4,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4]],query = [[0, 3], [1, 2]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 7], [1, 2, 7], [2, 0, 7], [3, 4, 1], [4, 5, 1], [5, 3, 1]],query = [[0, 3], [1, 4], [2, 5]]) == [-1, -1, -1]\n assert candidate(n = 7,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 0, 70]],query = [[0, 3], [1, 5], [2, 4]]) == [0, 0, 0]\n assert candidate(n = 9,edges = [[0, 1, 8], [1, 2, 9], [2, 3, 10], [3, 4, 11], [4, 5, 12], [5, 6, 13], [6, 7, 14], [7, 8, 15]],query = [[0, 8], [1, 7]]) == [8, 8]\n assert candidate(n = 10,edges = [[0, 1, 10], [1, 2, 9], [2, 3, 8], [3, 4, 7], [4, 5, 6], [5, 6, 5], [6, 7, 4], [7, 8, 3], [8, 9, 2], [9, 0, 1]],query = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(n = 4,edges = [[0, 1, 3], [1, 2, 5], [2, 3, 7]],query = [[0, 2], [1, 3]]) == [1, 1]\n assert candidate(n = 6,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5]],query = [[0, 5], [1, 4], [2, 3]]) == [5, 5, 5]\n assert candidate(n = 8,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8]],query = [[0, 7], [1, 6]]) == [0, 0]\n assert candidate(n = 6,edges = [[0, 1, 2], [1, 2, 4], [2, 3, 8], [3, 4, 16], [4, 5, 32]],query = [[0, 5], [1, 4], [2, 3]]) == [0, 0, 0]\n", "comparison": "exact"}, "public_tests": ["5\n[[0,1,7],[1,3,7],[1,2,1]]\n[[0,3],[3,4]]", "3\n[[0,2,7],[0,1,15],[1,2,6],[1,2,1]]\n[[1,2]]"], "hints": ["The intended solution uses Disjoint Set Union.", "Notice that, if u and v are not connected then the answer is -1, otherwise we can use all the edges from the connected component where both belong to."], "metadata": {"canonical_parameter_names": ["n", "edges", "query"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:18+00:00", "tests_total": 95, "tests_dropped": 5, "flags": ["has_images"], "topic_tags": ["array", "bit-manipulation", "union-find", "graph"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(n, edges, query)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "query", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3110, "task_id": "score-of-a-string", "difficulty": "Easy", "problem_description": "You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.\n\nReturn the score of s.\n\nExample 1:\n\nInput: s = \"hello\"\nOutput: 13\nExplanation:\nThe ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, the score of s would be |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13.\n\nExample 2:\n\nInput: s = \"zaz\"\nOutput: 50\nExplanation:\nThe ASCII values of the characters in s are: 'z' = 122, 'a' = 97. So, the score of s would be |122 - 97| + |97 - 122| = 25 + 25 = 50.\n\nConstraints:\n\n- 2 <= s.length <= 100\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"abracadabra\") == 78\n assert candidate(s = \"zzzz\") == 0\n assert candidate(s = \"zyx\") == 2\n assert candidate(s = \"mnopqr\") == 5\n assert candidate(s = \"python\") == 34\n assert candidate(s = \"aaa\") == 0\n assert candidate(s = \"abcdabcd\") == 9\n assert candidate(s = \"zzz\") == 0\n assert candidate(s = \"xyz\") == 2\n assert candidate(s = \"zaz\") == 50\n assert candidate(s = \"zyxwvut\") == 6\n assert candidate(s = \"abc\") == 2\n assert candidate(s = \"hello\") == 13\n assert candidate(s = \"aabbcc\") == 2\n assert candidate(s = \"mississippi\") == 58\n assert candidate(s = \"qpqpqpqp\") == 7\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"qwerty\") == 44\n assert candidate(s = \"aaaabbbbccccdddd\") == 3\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyui\") == 276\n assert candidate(s = \"abcdabcdabcdabcdabcd\") == 27\n assert candidate(s = \"lkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkj\") == 50\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 63\n assert candidate(s = \"learning\") == 49\n assert candidate(s = \"helloalibaba\") == 51\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz\") == 25\n assert candidate(s = \"thisisaverylongstringwithavarietyofcharacters\") == 447\n assert candidate(s = \"abacabadabacaba\") == 22\n assert candidate(s = \"code\") == 24\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzyxwvutsrqponmlkjihgfedcba\") == 50\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 38\n assert candidate(s = \"hellohellohellohellohello\") == 93\n assert candidate(s = \"abcdabcda\") == 12\n assert candidate(s = \"data\") == 41\n assert candidate(s = \"challenge\") == 48\n assert candidate(s = \"artificial\") == 67\n assert candidate(s = \"abcabcabcabc\") == 14\n assert candidate(s = \"mnopqrstmnopqrstmnopqr\") == 33\n assert candidate(s = \"hellotherefriends\") == 119\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\") == 282\n assert candidate(s = \"qrstuvpqponmlkjihgfedcba\") == 28\n assert candidate(s = \"aaaabbbbccccddddeeeeffff\") == 5\n assert candidate(s = \"abczzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 25\n assert candidate(s = \"science\") == 48\n assert candidate(s = \"thefiveboxingwizardsjumpquickly\") == 295\n assert candidate(s = \"aaaaabbbbbcccccdddddee\") == 4\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == 212\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewq\") == 428\n assert candidate(s = \"zazazazazazazazazazazazazazazazazazazazazazazazaza\") == 1225\n assert candidate(s = \"ejhjhehjhejhejhejhejhej\") == 69\n assert candidate(s = \"developer\") == 70\n assert candidate(s = \"abababababababab\") == 15\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\") == 50\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 75\n assert candidate(s = \"noon\") == 2\n assert candidate(s = \"solution\") == 35\n assert candidate(s = \"lkjasdlfkjsadlkfjasdlkfjasdlkfjasdlkfjsadlkfj\") == 340\n assert candidate(s = \"qpwoeirutyalskdjfhgzmxcvbnm\") == 234\n assert candidate(s = \"abcabcabcabcabcabc\") == 22\n assert candidate(s = \"algorithm\") == 64\n assert candidate(s = \"sdjfnwiehfuiwehfiuhweihufew\") == 242\n assert candidate(s = \"thisisaverylongstringwithvariouscharacters\") == 417\n assert candidate(s = \"jfkienfehndsjdfhienfhisodfns\") == 151\n assert candidate(s = \"intelligence\") == 62\n assert candidate(s = \"qwen\") == 33\n assert candidate(s = \"alibabacloud\") == 61\n assert candidate(s = \"fun\") == 22\n assert candidate(s = \"hellothereitisacoldwinter\") == 210\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmmnnnnooopppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 25\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 25\n assert candidate(s = \"asciiisawesome\") == 136\n assert candidate(s = \"programming\") == 69\n assert candidate(s = \"qwertypoiuytrewq\") == 120\n assert candidate(s = \"abczabcyabcbabczabcyabcbabcz\") == 229\n assert candidate(s = \"level\") == 48\n assert candidate(s = \"thisisaverylongstringthatcontainsmanycharacters\") == 461\n assert candidate(s = \"qazwsxedcrfvtgbyhnujmiklop\") == 215\n assert candidate(s = \"thisisaverylongstringwithmanycharacters\") == 389\n assert candidate(s = \"azbycxdwevfugthsijrkqlponm\") == 314\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\") == 309\n assert candidate(s = \"mnopqrstmnopqrst\") == 21\n assert candidate(s = \"abcdefg\") == 6\n assert candidate(s = \"expert\") == 53\n", "comparison": "exact"}, "public_tests": ["\"hello\"", "\"zaz\""], "hints": ["Sum the difference between all the adjacent characters by just taking the absolute difference of their ASCII values."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().scoreOfString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:23+00:00", "tests_total": 87, "tests_dropped": 2, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def score_of_string(s)", "container": null, "callable": "score_of_string", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3111, "task_id": "minimum-rectangles-to-cover-points", "difficulty": "Medium", "problem_description": "You are given a 2D integer array points, where points[i] = [x_i, y_i]. You are also given an integer w. Your task is to cover all the given points with rectangles.\n\nEach rectangle has its lower end at some point (x_1, 0) and its upper end at some point (x_2, y_2), where x_1 <= x_2, y_2 >= 0, and the condition x_2 - x_1 <= w must be satisfied for each rectangle.\n\nA point is considered covered by a rectangle if it lies within or on the boundary of the rectangle.\n\nReturn an integer denoting the minimum number of rectangles needed so that each point is covered by at least one rectangle.\n\nNote: A point may be covered by more than one rectangle.\n\nExample 1:\n\nInput: points = [[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]], w = 1\nOutput: 2\nExplanation:\nThe image above shows one possible placement of rectangles to cover the points:\n- A rectangle with a lower end at (1, 0) and its upper end at (2, 8)\n- A rectangle with a lower end at (3, 0) and its upper end at (4, 8)\n\nExample 2:\n\nInput: points = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]], w = 2\nOutput: 3\nExplanation:\nThe image above shows one possible placement of rectangles to cover the points:\n- A rectangle with a lower end at (0, 0) and its upper end at (2, 2)\n- A rectangle with a lower end at (3, 0) and its upper end at (5, 5)\n- A rectangle with a lower end at (6, 0) and its upper end at (6, 6)\n\nExample 3:\n\nInput: points = [[2,3],[1,2]], w = 0\nOutput: 2\nExplanation:\nThe image above shows one possible placement of rectangles to cover the points:\n- A rectangle with a lower end at (1, 0) and its upper end at (1, 2)\n- A rectangle with a lower end at (2, 0) and its upper end at (2, 3)\n\nConstraints:\n\n- 1 <= points.length <= 10^5\n- points[i].length == 2\n- 0 <= x_i == points[i][0] <= 10^9\n- 0 <= y_i == points[i][1] <= 10^9\n- 0 <= w <= 10^9\n- All pairs (x_i, y_i) are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],w = 1) == 3\n assert candidate(points = [[5, 5], [10, 10], [15, 15]],w = 5) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],w = 3) == 3\n assert candidate(points = [[2, 3], [1, 2]],w = 0) == 2\n assert candidate(points = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],w = 2) == 2\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],w = 2) == 3\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],w = 10) == 1\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],w = 4) == 1\n assert candidate(points = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],w = 2) == 3\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],w = 150) == 3\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],w = 1) == 5\n assert candidate(points = [[10, 10], [20, 20], [30, 30]],w = 10) == 2\n assert candidate(points = [[100, 100], [101, 101], [102, 102], [103, 103]],w = 2) == 2\n assert candidate(points = [[2, 1], [1, 0], [1, 4], [1, 8], [3, 5], [4, 6]],w = 1) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],w = 2) == 4\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20]],w = 5) == 2\n assert candidate(points = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15]],w = 2) == 4\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],w = 0) == 1\n assert candidate(points = [[5, 10], [6, 20], [7, 30], [8, 40], [9, 50], [10, 60], [11, 70], [12, 80], [13, 90], [14, 100], [15, 110], [16, 120], [17, 130]],w = 2) == 5\n assert candidate(points = [[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]],w = 3) == 4\n assert candidate(points = [[1, 5], [2, 3], [4, 8], [6, 10], [7, 6], [9, 12]],w = 3) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],w = 1) == 5\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [11, 10], [12, 9], [13, 8], [14, 7], [15, 6], [16, 5], [17, 4], [18, 3], [19, 2], [20, 1]],w = 2) == 7\n assert candidate(points = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],w = 1) == 5\n assert candidate(points = [[1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]],w = 1) == 5\n assert candidate(points = [[5, 5], [10, 15], [15, 25], [20, 35], [25, 45], [30, 55], [35, 65], [40, 75], [45, 85], [50, 95]],w = 10) == 4\n assert candidate(points = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]],w = 1) == 5\n assert candidate(points = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45], [50, 50], [55, 55], [60, 60], [65, 65], [70, 70], [75, 75], [80, 80], [85, 85], [90, 90], [95, 95], [100, 100]],w = 15) == 5\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],w = 0) == 1\n assert candidate(points = [[100, 100], [101, 101], [102, 102], [103, 103], [104, 104], [105, 105], [106, 106], [107, 107], [108, 108], [109, 109]],w = 3) == 3\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [5, 1], [5, 2], [5, 3]],w = 1) == 3\n assert candidate(points = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],w = 1) == 1\n assert candidate(points = [[1000000000, 1], [999999999, 2], [999999998, 3], [999999997, 4], [999999996, 5], [999999995, 6]],w = 1) == 3\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],w = 3) == 3\n assert candidate(points = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 0], [7, 1], [8, 2], [9, 3], [10, 4]],w = 1) == 5\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],w = 2) == 1\n assert candidate(points = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],w = 5) == 2\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1]],w = 4) == 3\n assert candidate(points = [[1, 9], [3, 8], [5, 7], [7, 6], [9, 5], [11, 4], [13, 3], [15, 2], [17, 1], [19, 0]],w = 2) == 5\n assert candidate(points = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],w = 0) == 2\n assert candidate(points = [[1, 5], [3, 6], [5, 7], [7, 8], [9, 9], [11, 10], [13, 11], [15, 12], [17, 13], [19, 14]],w = 5) == 4\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]],w = 3) == 4\n assert candidate(points = [[0, 10], [1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]],w = 2) == 4\n assert candidate(points = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]],w = 2) == 4\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1], [20, 1], [21, 1], [22, 1], [23, 1], [24, 1], [25, 1]],w = 3) == 7\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], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30]],w = 3) == 8\n assert candidate(points = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19]],w = 4) == 2\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]],w = 5) == 4\n assert candidate(points = [[10, 5], [12, 7], [14, 9], [16, 11], [18, 13], [20, 15]],w = 5) == 2\n assert candidate(points = [[1, 1], [1, 10], [1, 20], [1, 30], [1, 40], [1, 50], [1, 60], [1, 70], [1, 80], [1, 90], [1, 100]],w = 1) == 1\n assert candidate(points = [[0, 10], [1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]],w = 4) == 2\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],w = 1) == 1\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]],w = 4) == 3\n assert candidate(points = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2]],w = 2) == 2\n assert candidate(points = [[0, 0], [2, 2], [4, 4], [6, 6], [8, 8], [10, 10], [12, 12], [14, 14], [16, 16]],w = 3) == 5\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],w = 1) == 5\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1], [20, 1], [21, 1], [22, 1], [23, 1], [24, 1], [25, 1], [26, 1], [27, 1], [28, 1], [29, 1], [30, 1]],w = 2) == 10\n assert candidate(points = [[1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]],w = 5) == 2\n assert candidate(points = [[1, 1], [3, 1], [5, 1], [7, 1], [9, 1], [11, 1], [13, 1], [15, 1], [17, 1], [19, 1], [21, 1], [23, 1], [25, 1]],w = 4) == 5\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],w = 1) == 5\n assert candidate(points = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]],w = 4) == 2\n assert candidate(points = [[1000000000, 1000000000], [500000000, 500000000], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],w = 500000000) == 2\n assert candidate(points = [[0, 0], [1, 1], [2, 1], [3, 2], [4, 2], [5, 3], [6, 3], [7, 4], [8, 4], [9, 5], [10, 5]],w = 2) == 4\n assert candidate(points = [[10, 5], [15, 8], [20, 12], [25, 15], [30, 20], [35, 25], [40, 30], [45, 35], [50, 40]],w = 5) == 5\n assert candidate(points = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]],w = 0) == 1\n assert candidate(points = [[1, 1], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],w = 10) == 6\n assert candidate(points = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19]],w = 5) == 2\n assert candidate(points = [[1000000000, 1000000000], [999999999, 999999999], [999999998, 999999998], [999999997, 999999997]],w = 3) == 1\n assert candidate(points = [[1, 10], [1, 20], [1, 30], [1, 40], [1, 50], [1, 60], [1, 70], [1, 80], [1, 90], [1, 100], [1, 110]],w = 0) == 1\n assert candidate(points = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]],w = 2) == 2\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],w = 5) == 2\n assert candidate(points = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],w = 2) == 2\n assert candidate(points = [[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]],w = 2) == 9\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20]],w = 2) == 1\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1], [20, 1]],w = 3) == 5\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1]],w = 3) == 4\n assert candidate(points = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10], [11, 10], [12, 10], [13, 10], [14, 10], [15, 10]],w = 2) == 5\n assert candidate(points = [[1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35]],w = 2) == 2\n assert candidate(points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],w = 2) == 4\n assert candidate(points = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],w = 10) == 5\n assert candidate(points = [[1, 5], [3, 10], [5, 15], [7, 20], [9, 25], [11, 30], [13, 35], [15, 40], [17, 45], [19, 50], [21, 55], [23, 60], [25, 65]],w = 5) == 5\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15]],w = 2) == 1\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]],w = 7) == 2\n assert candidate(points = [[0, 10], [5, 20], [10, 30], [15, 40], [20, 50], [25, 60]],w = 5) == 3\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18]],w = 2) == 5\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2], [11, 2], [12, 2], [13, 2], [14, 2], [15, 2]],w = 2) == 5\n assert candidate(points = [[1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [10, 55]],w = 5) == 2\n assert candidate(points = [[1, 1], [10, 2], [19, 3], [28, 4], [37, 5], [46, 6], [55, 7], [64, 8], [73, 9], [82, 10], [91, 11], [100, 12], [109, 13], [118, 14], [127, 15], [136, 16], [145, 17], [154, 18], [163, 19], [172, 20]],w = 9) == 10\n assert candidate(points = [[5, 10], [10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80], [45, 90], [50, 100]],w = 10) == 4\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],w = 1) == 2\n assert candidate(points = [[1, 10], [5, 5], [10, 1], [20, 20], [25, 25], [30, 30], [35, 35]],w = 15) == 2\n assert candidate(points = [[10, 1], [11, 2], [12, 3], [13, 4], [14, 5], [15, 6], [16, 7]],w = 3) == 2\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],w = 5) == 1\n assert candidate(points = [[100, 200], [105, 210], [110, 220], [115, 230], [120, 240], [125, 250], [130, 260]],w = 5) == 4\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5]],w = 1) == 1\n assert candidate(points = [[0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10]],w = 2) == 4\n assert candidate(points = [[10, 5], [15, 15], [20, 25], [25, 35], [30, 45], [35, 55], [40, 65], [45, 75], [50, 85], [55, 95]],w = 10) == 4\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]],w = 5) == 1\n assert candidate(points = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]],w = 3) == 3\n assert candidate(points = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20]],w = 5) == 4\n assert candidate(points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1]],w = 3) == 4\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],w = 2) == 4\n assert candidate(points = [[5, 5], [10, 15], [15, 25], [20, 35], [25, 45], [30, 55], [35, 65], [40, 75], [45, 85], [50, 95]],w = 15) == 3\n assert candidate(points = [[10, 10], [11, 10], [12, 10], [13, 10], [14, 10], [15, 10], [16, 10], [17, 10], [18, 10], [19, 10]],w = 1) == 5\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]],w = 1) == 1\n assert candidate(points = [[1, 100], [2, 150], [3, 200], [4, 250], [5, 300], [6, 350], [7, 400], [8, 450], [9, 500], [10, 550]],w = 300) == 1\n assert candidate(points = [[1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]],w = 15) == 1\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]],w = 2) == 5\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]],w = 2) == 5\n assert candidate(points = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],w = 3) == 3\n assert candidate(points = [[5, 1], [6, 2], [7, 3], [8, 4], [9, 5], [10, 6], [11, 7], [12, 8], [13, 9], [14, 10]],w = 2) == 4\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],w = 10) == 1\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]],w = 5) == 4\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], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25]],w = 5) == 5\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]],w = 4) == 3\n assert candidate(points = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50]],w = 10) == 3\n assert candidate(points = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19]],w = 4) == 2\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]],w = 3) == 3\n", "comparison": "exact"}, "public_tests": ["[[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]]\n1", "[[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]\n2", "[[2,3],[1,2]]\n0"], "hints": ["The y values don't matter; only the x values matter.", "Sort all the points by x_i.", "Each time, select the smallest x value, x_0, from the unselected points, and then select all the points with x values not larger than x_0 + w."], "metadata": {"canonical_parameter_names": ["points", "w"], "leetcode_dataset_entry_point": "Solution().minRectanglesToCoverPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:25+00:00", "tests_total": 118, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def min_rectangles_to_cover_points(points, w)", "container": null, "callable": "min_rectangles_to_cover_points", "parameters": [{"name": "points", "type": "Integer[][]"}, {"name": "w", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3112, "task_id": "minimum-time-to-visit-disappearing-nodes", "difficulty": "Medium", "problem_description": "There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [u_i, v_i, length_i] describes an edge between node u_i and node v_i with a traversal time of length_i units.\n\nAdditionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the graph and you won't be able to visit it.\n\nNote that the graph might be disconnected and might contain multiple edges.\n\nReturn the array answer, with answer[i] denoting the minimum units of time required to reach node i from node 0. If node i is unreachable from node 0 then answer[i] is -1.\n\nExample 1:\n\nInput: n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]\nOutput: [0,-1,4]\nExplanation:\nWe are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.\n- For node 0, we don't need any time as it is our starting point.\n- For node 1, we need at least 2 units of time to traverse edges[0]. Unfortunately, it disappears at that moment, so we won't be able to visit it.\n- For node 2, we need at least 4 units of time to traverse edges[2].\n\nExample 2:\n\nInput: n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]\nOutput: [0,2,3]\nExplanation:\nWe are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.\n- For node 0, we don't need any time as it is the starting point.\n- For node 1, we need at least 2 units of time to traverse edges[0].\n- For node 2, we need at least 3 units of time to traverse edges[0] and edges[1].\n\nExample 3:\n\nInput: n = 2, edges = [[0,1,1]], disappear = [1,1]\nOutput: [0,-1]\nExplanation:\nExactly when we reach node 1, it disappears.\n\nConstraints:\n\n- 1 <= n <= 5 * 10^4\n- 0 <= edges.length <= 10^5\n- edges[i] == [u_i, v_i, length_i]\n- 0 <= u_i, v_i <= n - 1\n- 1 <= length_i <= 10^5\n- disappear.length == n\n- 1 <= disappear[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,edges = [[0, 1, 1]],disappear = [1, 1]) == [0, -1]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]],disappear = [1, 2, 3, 4, 5, 6]) == [0, 1, -1, -1, -1, -1]\n assert candidate(n = 4,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 0, 4]],disappear = [10, 10, 10, 10]) == [0, 1, 3, 4]\n assert candidate(n = 1,edges = [],disappear = [1]) == [0]\n assert candidate(n = 5,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]],disappear = [5, 6, 7, 8, 9]) == [0, 2, 5, -1, -1]\n assert candidate(n = 5,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 1], [2, 3, 2], [2, 4, 6]],disappear = [10, 5, 4, 8, 7]) == [0, -1, 3, 5, -1]\n assert candidate(n = 4,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3]],disappear = [2, 3, 4, 5]) == [0, 1, 2, 3]\n assert candidate(n = 5,edges = [[0, 1, 5], [1, 2, 3], [2, 3, 4], [3, 4, 2], [4, 0, 6]],disappear = [10, 20, 30, 40, 50]) == [0, 5, 8, 8, 6]\n assert candidate(n = 3,edges = [[0, 1, 2], [1, 2, 1], [0, 2, 4]],disappear = [1, 3, 5]) == [0, 2, 3]\n assert candidate(n = 5,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 1], [3, 4, 3]],disappear = [1, 2, 3, 4, 5]) == [0, -1, -1, -1, -1]\n assert candidate(n = 6,edges = [[0, 1, 10], [0, 2, 15], [1, 3, 5], [2, 3, 20], [3, 4, 10], [4, 5, 5]],disappear = [100, 200, 300, 400, 500, 600]) == [0, 10, 15, 15, 25, 30]\n assert candidate(n = 4,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 1], [0, 3, 3]],disappear = [1, 5, 4, 6]) == [0, 2, -1, 3]\n assert candidate(n = 3,edges = [[0, 1, 2], [1, 2, 1], [0, 2, 4]],disappear = [1, 1, 5]) == [0, -1, 4]\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 1], [2, 4, 4]],disappear = [10, 5, 6, 7, 8]) == [0, 2, 3, 3, 7]\n assert candidate(n = 4,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 1], [0, 3, 4]],disappear = [1, 2, 3, 4]) == [0, -1, -1, -1]\n assert candidate(n = 6,edges = [[0, 1, 1], [0, 2, 1], [1, 3, 1], [2, 4, 1], [3, 5, 1], [4, 5, 1]],disappear = [10, 10, 10, 10, 10, 10]) == [0, 1, 1, 2, 2, 3]\n assert candidate(n = 4,edges = [[0, 1, 5], [1, 2, 3], [2, 3, 2]],disappear = [10, 10, 10, 10]) == [0, 5, 8, -1]\n assert candidate(n = 4,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3]],disappear = [5, 6, 7, 8]) == [0, 1, 3, 6]\n assert candidate(n = 7,edges = [[0, 1, 3], [0, 2, 4], [1, 3, 1], [1, 4, 2], [2, 4, 3], [2, 5, 5], [3, 6, 6], [4, 6, 7]],disappear = [20, 25, 30, 35, 40, 45, 50]) == [0, 3, 4, 4, 5, 9, 10]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [0, 6, 6]],disappear = [2, 3, 4, 5, 6, 7, 8]) == [0, 1, 2, 3, 4, 5, 6]\n assert candidate(n = 6,edges = [[0, 1, 10], [0, 2, 5], [0, 3, 3], [1, 2, 2], [2, 3, 1], [3, 4, 4], [4, 5, 6]],disappear = [100, 150, 200, 250, 300, 350]) == [0, 6, 4, 3, 7, 13]\n assert candidate(n = 9,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8]],disappear = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [0, 1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 9,edges = [[0, 1, 5], [0, 2, 8], [1, 3, 6], [2, 4, 3], [3, 5, 2], [4, 6, 4], [5, 7, 7], [6, 8, 10], [7, 8, 5], [0, 8, 12], [1, 5, 4], [2, 6, 9]],disappear = [30, 40, 50, 60, 70, 80, 90, 100, 110]) == [0, 5, 8, 11, 11, 9, 15, 16, 12]\n assert candidate(n = 9,edges = [[0, 1, 5], [0, 2, 4], [1, 3, 3], [1, 4, 2], [2, 5, 1], [2, 6, 6], [3, 7, 7], [4, 8, 8], [5, 8, 9], [6, 8, 10]],disappear = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == [0, 5, 4, 8, 7, 5, 10, 15, 14]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [3, 8, 8], [4, 9, 9], [4, 10, 10], [5, 11, 11], [5, 12, 12], [6, 13, 13], [6, 14, 14]],disappear = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == [0, 1, 2, 4, 5, 7, 8, 11, 12, 14, -1, -1, -1, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 2], [0, 2, 4], [1, 2, 1], [1, 3, 3], [2, 4, 5], [3, 5, 2], [3, 6, 7], [5, 7, 8]],disappear = [10, 9, 8, 7, 6, 5, 4, 3]) == [0, 2, 3, 5, -1, -1, -1, -1]\n assert candidate(n = 5,edges = [[0, 1, 10], [0, 2, 5], [1, 2, 2], [2, 3, 3], [3, 4, 1]],disappear = [1, 10, 15, 20, 25]) == [0, 7, 5, 8, 9]\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 1], [0, 3, 1], [1, 4, 1], [1, 5, 1], [2, 6, 1], [2, 7, 1], [3, 8, 1]],disappear = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == [0, 1, 1, 1, 2, 2, 2, 2, 2]\n assert candidate(n = 10,edges = [[0, 1, 10], [0, 2, 15], [1, 3, 5], [2, 3, 20], [3, 4, 10], [4, 5, 5], [5, 6, 10], [6, 7, 5], [7, 8, 3], [8, 9, 4]],disappear = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [0, 10, 15, 15, 25, 30, 40, 45, 48, 52]\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 1], [1, 2, 1], [1, 3, 2], [2, 3, 2], [3, 4, 3], [3, 5, 3], [4, 5, 4], [4, 6, 5], [5, 6, 5], [5, 7, 6], [6, 7, 6]],disappear = [1, 2, 3, 4, 5, 6, 7, 8]) == [0, 1, 1, 3, -1, -1, -1, -1]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [3, 6, 6], [4, 7, 7], [5, 8, 8], [6, 9, 9]],disappear = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == [0, 1, 2, -1, -1, 7, -1, -1, -1, -1]\n assert candidate(n = 12,edges = [[0, 1, 10], [0, 2, 20], [0, 3, 30], [0, 4, 40], [1, 5, 50], [1, 6, 60], [2, 7, 70], [2, 8, 80], [3, 9, 90], [4, 10, 100], [5, 11, 110], [6, 11, 110], [7, 11, 110], [8, 11, 110], [9, 11, 110], [10, 11, 110]],disappear = [120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120]) == [0, 10, 20, 30, 40, 60, 70, 90, 100, -1, -1, -1]\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 2], [1, 3, 2], [1, 4, 2], [2, 5, 2], [2, 6, 2], [3, 4, 2], [5, 6, 2]],disappear = [10, 20, 30, 40, 50, 60, 70]) == [0, 2, 2, 4, 4, 4, 4]\n assert candidate(n = 15,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 5, 6], [2, 6, 7], [3, 7, 8], [3, 8, 9], [4, 8, 10], [4, 9, 11], [5, 9, 12], [5, 10, 13], [6, 10, 14], [6, 11, 15], [7, 11, 16], [7, 12, 17], [8, 12, 18], [8, 13, 19], [9, 13, 20], [9, 14, 21], [10, 14, 22]],disappear = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [0, 2, 3, 6, 7, 9, 10, 14, 15, 18, 22, 25, 31, 34, 39]\n assert candidate(n = 5,edges = [[0, 1, 1], [0, 2, 2], [1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 0, 3]],disappear = [1, 2, 3, 4, 5]) == [0, 1, 2, -1, 3]\n assert candidate(n = 6,edges = [[0, 1, 5], [0, 2, 5], [1, 2, 10], [1, 3, 10], [2, 3, 1], [2, 4, 15], [3, 5, 10], [4, 5, 1]],disappear = [10, 20, 30, 40, 50, 60]) == [0, 5, 5, 6, 17, 16]\n assert candidate(n = 8,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [0, 3, 15], [3, 6, 10]],disappear = [5, 6, 7, 8, 9, 10, 11, 12]) == [0, 1, 3, 6, -1, -1, -1, -1]\n assert candidate(n = 10,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 5], [2, 4, 15], [3, 5, 25], [4, 6, 30], [5, 7, 35], [6, 8, 40], [7, 9, 45]],disappear = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550]) == [0, 10, 20, 15, 35, 40, 65, 75, 105, 120]\n assert candidate(n = 15,edges = [[0, 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, 0, 15]],disappear = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == [0, 1, 3, 6, 10, 15, 21, -1, -1, -1, -1, -1, -1, -1, 15]\n assert candidate(n = 12,edges = [[0, 1, 10], [0, 2, 10], [1, 3, 15], [2, 4, 15], [3, 5, 20], [4, 6, 20], [5, 7, 25], [6, 8, 25], [7, 9, 30], [8, 10, 30], [9, 11, 35], [10, 11, 35]],disappear = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125]) == [0, 10, 10, 25, 25, 45, 45, 70, 70, 100, 100, -1]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 4, 4], [3, 5, 5], [4, 6, 6], [5, 7, 7], [6, 8, 8], [7, 9, 9], [8, 0, 10], [9, 1, 11]],disappear = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == [0, 1, 2, 4, 6, 9, 12, 16, 10, 12]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [4, 8, 8], [5, 9, 9], [6, 7, 10], [7, 8, 11], [8, 9, 12]],disappear = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 4, 5, -1, -1, -1, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [2, 4, 4], [3, 4, 6], [4, 5, 1], [5, 6, 3], [6, 7, 2]],disappear = [30, 40, 50, 60, 70, 80, 90, 100]) == [0, 5, 3, 7, 7, 8, 11, 13]\n assert candidate(n = 20,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 12, 1], [12, 13, 1], [13, 14, 1], [14, 15, 1], [15, 16, 1], [16, 17, 1], [17, 18, 1], [18, 19, 1]],disappear = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(n = 7,edges = [[0, 1, 10], [1, 2, 5], [2, 3, 3], [3, 4, 8], [4, 5, 7], [5, 6, 2], [0, 6, 15], [1, 3, 12], [2, 5, 9], [3, 6, 10]],disappear = [20, 30, 40, 50, 60, 70, 80]) == [0, 10, 15, 18, 24, 17, 15]\n assert candidate(n = 20,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 10, 11], [10, 11, 12], [11, 12, 13], [12, 13, 14], [13, 14, 15], [14, 15, 16], [15, 16, 17], [16, 17, 18], [17, 18, 19], [18, 19, 20], [0, 19, 100]],disappear = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == [0, 2, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 10,edges = [[0, 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]],disappear = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [0, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 6,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [2, 4, 5], [3, 5, 6], [4, 5, 7], [0, 5, 1], [1, 4, 2], [2, 3, 3]],disappear = [5, 6, 7, 8, 9, 10]) == [0, 2, 3, 6, 4, 1]\n assert candidate(n = 12,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [4, 8, 8], [5, 9, 9], [6, 10, 10], [7, 11, 11], [8, 11, 12], [0, 11, 5], [1, 10, 4], [2, 9, 3], [3, 8, 2], [4, 7, 1], [5, 6, 6]],disappear = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == [0, 1, 2, 4, 5, 7, 8, 6, 6, 5, 5, 5]\n assert candidate(n = 12,edges = [[0, 1, 5], [0, 2, 5], [1, 3, 5], [1, 4, 5], [2, 5, 5], [2, 6, 5], [3, 7, 5], [3, 8, 5], [4, 9, 5], [4, 10, 5], [5, 11, 5], [6, 11, 5], [7, 8, 5], [9, 10, 5]],disappear = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 5]) == [0, 5, 5, 10, 10, 10, 10, 15, 15, -1, -1, -1]\n assert candidate(n = 7,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]],disappear = [7, 8, 9, 10, 11, 12, 13]) == [0, 1, 3, 6, 10, -1, -1]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 5], [1, 3, 5], [1, 4, 5], [2, 5, 5], [2, 6, 5], [3, 7, 5], [4, 8, 5], [5, 9, 5], [6, 8, 5], [7, 9, 5]],disappear = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [0, 5, 5, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 7,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 4, 7], [5, 6, 8]],disappear = [2, 4, 6, 8, 10, 12, 14]) == [0, 1, 2, 4, 5, 7, 8]\n assert candidate(n = 9,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 0, 9]],disappear = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [0, 1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 1], [1, 3, 1], [1, 4, 1], [2, 5, 1], [2, 6, 1], [3, 7, 1], [4, 8, 1], [5, 8, 1], [6, 8, 1]],disappear = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == [0, 1, 1, 2, 2, 2, 2, 3, 3]\n assert candidate(n = 10,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [0, 9, 100]],disappear = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28]) == [0, 2, 5, 9, 14, -1, -1, -1, -1, -1]\n assert candidate(n = 12,edges = [[0, 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, 0, 12]],disappear = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == [0, 1, 3, 6, 10, 15, -1, -1, -1, -1, -1, 12]\n assert candidate(n = 5,edges = [[0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [2, 3, 1], [2, 4, 1], [3, 4, 1]],disappear = [2, 3, 4, 5, 6]) == [0, 1, 1, 1, 1]\n assert candidate(n = 7,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 0, 8]],disappear = [3, 4, 5, 6, 7, 8, 9]) == [0, 2, -1, -1, -1, -1, 8]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 0, 1]],disappear = [2, 3, 4, 5, 6, 7]) == [0, 1, 2, 3, 2, 1]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 10], [1, 3, 2], [2, 3, 1], [3, 4, 3], [4, 5, 1], [5, 6, 4], [6, 7, 2], [7, 8, 3], [8, 9, 1]],disappear = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [0, 5, 8, 7, 10, 11, 15, 17, 20, 21]\n assert candidate(n = 11,edges = [[0, 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]],disappear = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 4], [2, 5, 5], [3, 6, 6], [4, 7, 7], [5, 8, 8], [6, 9, 9], [7, 10, 10], [8, 11, 11], [9, 12, 12], [10, 13, 13], [11, 14, 14]],disappear = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 6,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 0, 60]],disappear = [15, 25, 35, 45, 55, 65]) == [0, 10, 30, -1, -1, 60]\n assert candidate(n = 10,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 5], [1, 4, 50], [2, 5, 15], [2, 6, 25], [3, 7, 5], [4, 8, 10], [5, 9, 20], [6, 9, 15]],disappear = [100, 110, 120, 130, 140, 150, 160, 170, 180, 190]) == [0, 10, 20, 15, 60, 35, 45, 20, 70, 55]\n assert candidate(n = 5,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 0, 50], [0, 3, 15], [2, 4, 25]],disappear = [25, 30, 35, 40, 45]) == [0, 10, 30, 15, -1]\n assert candidate(n = 8,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 1], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [0, 7, 10]],disappear = [3, 4, 5, 6, 7, 8, 9, 10]) == [0, 2, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 20,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5], [0, 6, 5], [1, 7, 5], [2, 8, 5], [3, 9, 5], [4, 10, 5], [5, 11, 5], [6, 7, 5], [7, 8, 5], [8, 9, 5], [9, 10, 5], [10, 11, 5], [11, 12, 5], [12, 13, 5], [13, 14, 5], [14, 15, 5], [15, 16, 5], [16, 17, 5], [17, 18, 5], [18, 19, 5]],disappear = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6]) == [0, 5, 10, 15, 20, -1, 5, 10, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 1], [1, 3, 1], [1, 4, 1], [2, 5, 1], [2, 6, 1], [3, 7, 1], [4, 7, 1], [5, 7, 1], [6, 7, 1]],disappear = [10, 9, 8, 7, 6, 5, 4, 3]) == [0, 1, 1, 2, 2, 2, 2, -1]\n assert candidate(n = 12,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1]],disappear = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 5,edges = [[0, 1, 2], [1, 2, 3], [1, 3, 1], [2, 4, 4], [3, 4, 5]],disappear = [10, 10, 10, 10, 10]) == [0, 2, 5, 3, 8]\n assert candidate(n = 15,edges = [[0, 1, 5], [0, 2, 10], [0, 3, 15], [1, 4, 20], [2, 5, 25], [3, 6, 30], [4, 7, 35], [5, 8, 40], [6, 9, 45], [7, 10, 50], [8, 11, 55], [9, 12, 60], [10, 13, 65], [11, 14, 70], [12, 13, 5], [13, 14, 10]],disappear = [30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170]) == [0, 5, 10, 15, 25, 35, 45, 60, 75, 90, 110, 130, -1, -1, -1]\n assert candidate(n = 5,edges = [[0, 1, 5], [0, 2, 3], [1, 2, 10], [1, 3, 6], [2, 4, 7], [3, 4, 8]],disappear = [15, 20, 25, 30, 35]) == [0, 5, 3, 11, 10]\n assert candidate(n = 15,edges = [[0, 1, 2], [0, 4, 5], [1, 2, 3], [1, 3, 2], [2, 3, 1], [3, 4, 2], [4, 5, 2], [5, 6, 1], [6, 7, 3], [7, 8, 4], [8, 9, 2], [9, 10, 1], [10, 11, 5], [11, 12, 6], [12, 13, 3], [13, 14, 2]],disappear = [15, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1]) == [0, 2, 5, 4, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 12,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1], [9, 10, 1], [10, 11, 1], [11, 0, 1]],disappear = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 15], [1, 4, 25], [2, 3, 30], [2, 5, 25], [3, 6, 10], [4, 6, 5], [5, 7, 5], [6, 7, 15]],disappear = [100, 200, 150, 250, 300, 350, 400, 450]) == [0, 10, 20, 25, 35, 45, 35, 50]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [2, 4, 2], [3, 5, 1], [4, 6, 2], [5, 7, 1], [6, 8, 2], [7, 9, 1]],disappear = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == [0, 1, 2, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7]],disappear = [2, 4, 6, 8, 10, 12, 14, 16]) == [0, 1, 3, 6, -1, -1, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [4, 7, 8]],disappear = [1, 2, 3, 4, 5, 6, 7, 8]) == [0, 1, 2, -1, -1, -1, -1, -1]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [4, 8, 8], [5, 9, 9], [6, 10, 10], [7, 11, 11], [8, 12, 12], [9, 13, 13], [10, 14, 14]],disappear = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == [0, 1, 2, 4, 5, 7, 8, 11, 13, 16, 18, -1, -1, -1, -1]\n assert candidate(n = 5,edges = [[0, 1, 1], [0, 2, 1], [0, 3, 1], [1, 2, 1], [1, 3, 1], [2, 3, 1], [2, 4, 1], [3, 4, 1]],disappear = [5, 5, 5, 5, 5]) == [0, 1, 1, 1, 2]\n assert candidate(n = 10,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70], [7, 8, 80], [8, 9, 90], [9, 0, 100], [0, 2, 15], [1, 3, 25]],disappear = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == [0, 10, 15, 35, 75, 125, 185, 255, 190, 100]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 7], [2, 5, 1], [3, 6, 4], [4, 7, 3], [5, 8, 6], [6, 9, 5]],disappear = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [0, 5, 3, 7, 12, 4, 11, 15, 10, 16]\n assert candidate(n = 12,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 4], [1, 5, 5], [2, 6, 6], [2, 7, 7], [3, 8, 8], [3, 9, 9], [4, 10, 10], [5, 11, 11], [6, 11, 12], [7, 10, 13], [8, 11, 14], [9, 10, 15]],disappear = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == [0, 1, 2, 3, 5, 6, 8, 9, 11, 12, 15, 17]\n assert candidate(n = 10,edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40], [8, 9, 45]],disappear = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [0, 5, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 0, 1]],disappear = [10, 20, 30, 40, 50, 60]) == [0, 1, 2, 3, 2, 1]\n assert candidate(n = 12,edges = [[0, 1, 10], [0, 5, 50], [1, 2, 20], [1, 3, 30], [2, 4, 40], [3, 7, 50], [4, 6, 60], [5, 6, 10], [5, 8, 20], [6, 9, 30], [7, 10, 40], [8, 10, 50], [9, 11, 60]],disappear = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == [0, 10, 30, 40, 70, 50, 60, 90, 70, 90, 120, 150]\n assert candidate(n = 6,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [0, 2, 4], [1, 3, 5], [2, 4, 6], [3, 5, 7]],disappear = [6, 7, 8, 9, 10, 11]) == [0, 1, 3, 6, 9, -1]\n assert candidate(n = 7,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 4, 4], [3, 4, 1], [4, 5, 2], [5, 6, 3]],disappear = [5, 6, 7, 8, 9, 10, 11]) == [0, 1, 2, 4, 5, 7, 10]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 10], [1, 3, 3], [2, 4, 7], [3, 4, 2], [3, 5, 6], [4, 6, 8], [5, 7, 1], [6, 8, 4], [7, 9, 9]],disappear = [20, 25, 30, 35, 40, 45, 50, 55, 60, 65]) == [0, 5, 10, 8, 10, 14, 18, 15, 22, 24]\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 4, 4], [3, 5, 5], [4, 6, 6], [5, 7, 7]],disappear = [1, 1, 1, 1, 1, 1, 1, 1]) == [0, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 20,edges = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 9], [0, 9, 10], [0, 10, 11], [0, 11, 12], [0, 12, 13], [0, 13, 14], [0, 14, 15], [0, 15, 16], [0, 16, 17], [0, 17, 18], [0, 18, 19], [0, 19, 20]],disappear = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [0, 4, 4], [0, 5, 5], [0, 6, 6], [0, 7, 7], [0, 8, 8], [0, 9, 9]],disappear = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 15,edges = [[0, 1, 10], [0, 2, 10], [1, 3, 5], [1, 4, 5], [2, 5, 5], [2, 6, 5], [3, 7, 2], [3, 8, 2], [4, 9, 2], [4, 10, 2], [5, 11, 2], [5, 12, 2], [6, 13, 2], [6, 14, 2], [7, 8, 1], [9, 10, 1], [11, 12, 1], [13, 14, 1]],disappear = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 4, 3, 2, 1]) == [0, 10, 10, 15, 15, 15, 15, 17, 17, -1, -1, -1, -1, -1, -1]\n assert candidate(n = 7,edges = [[0, 1, 5], [0, 2, 10], [1, 3, 15], [1, 4, 20], [2, 5, 25], [2, 6, 30], [3, 4, 5], [4, 5, 10], [5, 6, 15], [6, 3, 20], [0, 3, 35]],disappear = [20, 30, 40, 50, 60, 70, 80]) == [0, 5, 10, 20, 25, 35, 40]\n assert candidate(n = 5,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 4, 4]],disappear = [5, 6, 7, 8, 9]) == [0, 1, 2, 4, 6]\n assert candidate(n = 7,edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 4, 10], [5, 6, 10]],disappear = [50, 50, 50, 50, 50, 50, 50]) == [0, 10, 10, 20, 20, 20, 20]\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 2], [1, 3, 3], [1, 4, 3], [2, 5, 3], [2, 6, 3], [3, 4, 2], [5, 6, 2], [0, 3, 5], [0, 5, 5]],disappear = [10, 15, 20, 25, 30, 35, 40]) == [0, 2, 2, 5, 5, 5, 5]\n assert candidate(n = 20,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [3, 8, 8], [4, 9, 9], [4, 10, 10], [5, 11, 11], [5, 12, 12], [6, 13, 13], [6, 14, 14], [7, 15, 15], [7, 16, 16], [8, 17, 17], [8, 18, 18], [9, 19, 19], [10, 19, 20]],disappear = [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == [0, 1, 2, 4, 5, 7, 8, 11, 12, 14, 15, 18, 19, 21, 22, 26, 27, 29, -1, -1]\n assert candidate(n = 8,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [0, 7, 1]],disappear = [2, 3, 4, 5, 6, 7, 8, 9]) == [0, 1, 2, 3, 4, 3, 2, 1]\n assert candidate(n = 10,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 8, 1], [8, 9, 1]],disappear = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(n = 8,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 1], [2, 3, 2], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1]],disappear = [10, 12, 13, 14, 15, 16, 17, 18]) == [0, 2, 3, 3, 4, 5, 6, 7]\n assert candidate(n = 25,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 5, 6], [2, 6, 7], [3, 7, 8], [3, 8, 9], [4, 8, 10], [4, 9, 11], [5, 9, 12], [5, 10, 13], [6, 10, 14], [6, 11, 15], [7, 11, 16], [7, 12, 17], [8, 12, 18], [8, 13, 19], [9, 13, 20], [9, 14, 21], [10, 14, 22], [10, 15, 23], [11, 15, 24], [11, 16, 25], [12, 16, 26], [12, 17, 27], [13, 17, 28], [13, 18, 29], [14, 18, 30], [14, 19, 31], [15, 19, 32], [15, 20, 33], [16, 20, 34], [16, 21, 35], [17, 21, 36], [17, 22, 37], [18, 22, 38], [18, 23, 39], [19, 23, 40], [19, 24, 41]],disappear = [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]) == [0, 2, 3, 6, 7, 9, 10, 14, 15, 18, 22, 25, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n", "comparison": "exact"}, "public_tests": ["3\n[[0,1,2],[1,2,1],[0,2,4]]\n[1,1,5]", "3\n[[0,1,2],[1,2,1],[0,2,4]]\n[1,3,5]", "2\n[[0,1,1]]\n[1,1]"], "hints": ["Use Dijkstra’s algorithm, but only visit nodes if you can reach them before disappearance."], "metadata": {"canonical_parameter_names": ["n", "edges", "disappear"], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:28+00:00", "tests_total": 103, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "graph", "heap-priority-queue", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_time(n, edges, disappear)", "container": null, "callable": "minimum_time", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "disappear", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3113, "task_id": "find-the-number-of-subarrays-where-boundary-elements-are-maximum", "difficulty": "Hard", "problem_description": "You are given an array of positive integers nums.\n\nReturn the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray.\n\nExample 1:\n\nInput: nums = [1,4,3,3,2]\nOutput: 6\nExplanation:\nThere are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:\n- subarray [1,4,3,3,2], with its largest element 1. The first element is 1 and the last element is also 1.\n- subarray [1,4,3,3,2], with its largest element 4. The first element is 4 and the last element is also 4.\n- subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [1,4,3,3,2], with its largest element 2. The first element is 2 and the last element is also 2.\n- subarray [1,4,3,3,2], with its largest element 3. The first element is 3 and the last element is also 3.\n\nHence, we return 6.\n\nExample 2:\n\nInput: nums = [3,3,3]\nOutput: 6\nExplanation:\nThere are 6 subarrays which have the first and the last elements equal to the largest element of the subarray:\n- subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n- subarray [3,3,3], with its largest element 3. The first element is 3 and the last element is also 3.\n\nHence, we return 6.\n\nExample 3:\n\nInput: nums = [1]\nOutput: 1\nExplanation:\nThere is a single subarray of nums which is [1], with its largest element 1. The first element is 1 and the last element is also 1.\nHence, we return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 5, 4, 5]) == 8\n assert candidate(nums = [2, 1, 2, 1, 2]) == 8\n assert candidate(nums = [1, 3, 2, 3, 1, 3]) == 9\n assert candidate(nums = [1, 2, 2, 1]) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 55\n assert candidate(nums = [5, 1, 5, 2, 5, 5]) == 12\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [2, 1, 2]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [10, 20, 10, 30, 20, 10]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [1, 2, 2, 2, 1]) == 8\n assert candidate(nums = [2, 1, 2, 3, 2, 1, 2]) == 9\n assert candidate(nums = [1, 4, 3, 3, 2]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1]) == 11\n assert candidate(nums = [3, 3, 3]) == 6\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [2, 2, 1, 2, 2]) == 11\n assert candidate(nums = [2, 2, 1, 1, 2, 2, 1, 1, 2, 2]) == 27\n assert candidate(nums = [1, 3, 2, 3, 1, 3, 1]) == 10\n assert candidate(nums = [1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [7, 1, 5, 3, 6, 4, 7]) == 8\n assert candidate(nums = [10, 10, 10, 10, 10]) == 15\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]) == 496\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, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 84\n assert candidate(nums = [15, 10, 15, 5, 15, 20, 15, 5, 15, 10, 15, 25, 15, 5, 15, 10, 15]) == 26\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]) == 37\n assert candidate(nums = [8, 5, 8, 9, 8, 5, 8, 9, 8]) == 12\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 21\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 27\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]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 2, 1]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 21\n assert candidate(nums = [2, 4, 6, 8, 10, 8, 6, 4, 2]) == 9\n assert candidate(nums = [1, 1, 1, 1, 2, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1]) == 48\n assert candidate(nums = [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]) == 135\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 210\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]) == 30\n assert candidate(nums = [7, 8, 9, 9, 8, 7, 9, 8, 7]) == 12\n assert candidate(nums = [1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1]) == 40\n assert candidate(nums = [3, 5, 2, 5, 3, 3, 5, 2, 3, 5, 5, 5, 5, 5, 3, 2, 5, 3, 5, 5, 3, 2, 3, 5, 3, 5, 5, 3, 2, 3]) == 124\n assert candidate(nums = [2, 2, 3, 3, 3, 3, 3, 2, 2, 2]) == 24\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 20\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]) == 21\n assert candidate(nums = [2, 1, 4, 4, 4, 1, 4, 2, 4, 1]) == 20\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, 1, 1, 1]) == 60\n assert candidate(nums = [9, 10, 11, 10, 10, 9, 11, 10, 9]) == 11\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 26\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 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, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 39\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]) == 21\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 13\n assert candidate(nums = [5, 6, 5, 7, 5, 6, 5, 8, 5, 9, 5, 10, 5, 11, 5, 12, 5, 13, 5, 14, 5]) == 21\n assert candidate(nums = [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, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 97\n assert candidate(nums = [7, 2, 7, 3, 7, 7, 7, 3, 7, 2, 7]) == 32\n assert candidate(nums = [100, 90, 80, 70, 60, 70, 80, 90, 100]) == 13\n assert candidate(nums = [5, 5, 1, 5, 5, 2, 5, 5, 3, 5, 5, 4, 5, 5, 5]) == 70\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 55\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 27\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 57\n assert candidate(nums = [100, 200, 100, 300, 200, 100, 400, 300, 200, 100, 500, 400, 300, 200, 100]) == 15\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]) == 136\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 30\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 33\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == 18\n assert candidate(nums = [7, 5, 7, 8, 7, 5, 7, 8, 7]) == 12\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 210\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 8, 5, 5, 5, 5, 5]) == 63\n assert candidate(nums = [2, 4, 6, 8, 10, 8, 6, 4, 2, 12, 2, 4, 6, 8, 10, 8, 6, 4, 2, 12]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 58\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 33\n assert candidate(nums = [8, 1, 8, 9, 8, 9, 8, 10, 8, 9, 8, 1]) == 14\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 47\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 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, 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]) == 77\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 28\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 58\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 27\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]) == 33\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 43\n assert candidate(nums = [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]) == 42\n assert candidate(nums = [6, 1, 6, 6, 6, 1, 6, 1, 6]) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 39\n assert candidate(nums = [2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2]) == 103\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 21\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 30\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 210\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]) == 528\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 33\n assert candidate(nums = [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]) == 15\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7]) == 36\n assert candidate(nums = [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]) == 44\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 25\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, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [7, 8, 8, 7, 9, 8, 7, 8, 7]) == 11\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 30\n assert candidate(nums = [2, 1, 4, 4, 4, 1, 2]) == 10\n assert candidate(nums = [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, 4, 4]) == 465\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 1]) == 89\n assert candidate(nums = [100, 200, 300, 400, 500, 400, 300, 200, 100, 200, 300, 400, 500, 400, 300, 200, 100]) == 21\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 120\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 6, 4, 7, 3, 8, 2, 9, 1]) == 23\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 50\n", "comparison": "exact"}, "public_tests": ["[1,4,3,3,2]", "[3,3,3]", "[1]"], "hints": ["For each element nums[i], we can count the number of valid subarrays ending with it.", "For each index i, find the nearest index j on its left (j < i) such that nums[j] < nums[i]. This can be done via a monotonic stack.", "For each index i, find the number of indices k in the window [j + 1, i] such that nums[k] == nums[i], this is the number of the valid subarrays ending with nums[i]. This can be done by sliding window.", "Sum the answer of all the indices i to get the final result.", "Is it possible to use DSU as an alternate solution?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().numberOfSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:31+00:00", "tests_total": 110, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "stack", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_subarrays(nums)", "container": null, "callable": "number_of_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3114, "task_id": "latest-time-you-can-obtain-after-replacing-characters", "difficulty": "Easy", "problem_description": "You are given a string s representing a 12-hour format time where some of the digits (possibly none) are replaced with a \"?\".\n\n12-hour times are formatted as \"HH:MM\", where HH is between 00 and 11, and MM is between 00 and 59. The earliest 12-hour time is 00:00, and the latest is 11:59.\n\nYou have to replace all the \"?\" characters in s with digits such that the time we obtain by the resulting string is a valid 12-hour format time and is the latest possible.\n\nReturn the resulting string.\n\nExample 1:\n\nInput: s = \"1?:?4\"\nOutput: \"11:54\"\nExplanation: The latest 12-hour format time we can achieve by replacing \"?\" characters is \"11:54\".\n\nExample 2:\n\nInput: s = \"0?:5?\"\nOutput: \"09:59\"\nExplanation: The latest 12-hour format time we can achieve by replacing \"?\" characters is \"09:59\".\n\nConstraints:\n\n- s.length == 5\n- s[2] is equal to the character \":\".\n- All characters except s[2] are digits or \"?\" characters.\n- The input is generated such that there is at least one time between \"00:00\" and \"11:59\" that you can obtain after replacing the \"?\" characters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"10:?5\") == \"10:55\"\n assert candidate(s = \"??:5?\") == \"11:59\"\n assert candidate(s = \"1?:4?\") == \"11:49\"\n assert candidate(s = \"1?:?4\") == \"11:54\"\n assert candidate(s = \"11:?9\") == \"11:59\"\n assert candidate(s = \"?1:59\") == \"11:59\"\n assert candidate(s = \"1?:30\") == \"11:30\"\n assert candidate(s = \"0?:5?\") == \"09:59\"\n assert candidate(s = \"0?:??\") == \"09:59\"\n assert candidate(s = \"?9:5?\") == \"09:59\"\n assert candidate(s = \"??:?0\") == \"11:50\"\n assert candidate(s = \"00:?1\") == \"00:51\"\n assert candidate(s = \"1?:3?\") == \"11:39\"\n assert candidate(s = \"1?:??\") == \"11:59\"\n assert candidate(s = \"11:5?\") == \"11:59\"\n assert candidate(s = \"09:5?\") == \"09:59\"\n assert candidate(s = \"00:??\") == \"00:59\"\n assert candidate(s = \"1?:?0\") == \"11:50\"\n assert candidate(s = \"?1:?2\") == \"11:52\"\n assert candidate(s = \"0?:0?\") == \"09:09\"\n assert candidate(s = \"??:59\") == \"11:59\"\n assert candidate(s = \"11:??\") == \"11:59\"\n assert candidate(s = \"09:?1\") == \"09:51\"\n assert candidate(s = \"01:?7\") == \"01:57\"\n assert candidate(s = \"?0:??\") == \"10:59\"\n assert candidate(s = \"10:?0\") == \"10:50\"\n assert candidate(s = \"12:?9\") == None\n assert candidate(s = \"??:??\") == \"11:59\"\n assert candidate(s = \"0?:?0\") == \"09:50\"\n assert candidate(s = \"08:?5\") == \"08:55\"\n assert candidate(s = \"0?:?1\") == \"09:51\"\n assert candidate(s = \"09:?8\") == \"09:58\"\n assert candidate(s = \"??:?9\") == \"11:59\"\n assert candidate(s = \"1?:?1\") == \"11:51\"\n assert candidate(s = \"1?:50\") == \"11:50\"\n assert candidate(s = \"10:?8\") == \"10:58\"\n assert candidate(s = \"11:?5\") == \"11:55\"\n assert candidate(s = \"0?:59\") == \"09:59\"\n assert candidate(s = \"0?:50\") == \"09:50\"\n assert candidate(s = \"09:??\") == \"09:59\"\n assert candidate(s = \"?1:??\") == \"11:59\"\n assert candidate(s = \"1?:?3\") == \"11:53\"\n assert candidate(s = \"0?:2?\") == \"09:29\"\n assert candidate(s = \"??:0?\") == \"11:09\"\n assert candidate(s = \"?0:?8\") == \"10:58\"\n assert candidate(s = \"09:?9\") == \"09:59\"\n assert candidate(s = \"10:?9\") == \"10:59\"\n assert candidate(s = \"??:45\") == \"11:45\"\n assert candidate(s = \"0?:00\") == \"09:00\"\n assert candidate(s = \"11:?1\") == \"11:51\"\n assert candidate(s = \"??:4?\") == \"11:49\"\n assert candidate(s = \"1?:?5\") == \"11:55\"\n assert candidate(s = \"01:?9\") == \"01:59\"\n assert candidate(s = \"0?:?5\") == \"09:55\"\n assert candidate(s = \"1?:00\") == \"11:00\"\n assert candidate(s = \"1?:0?\") == \"11:09\"\n assert candidate(s = \"1?:1?\") == \"11:19\"\n assert candidate(s = \"1?:?8\") == \"11:58\"\n assert candidate(s = \"1?:59\") == \"11:59\"\n assert candidate(s = \"??:00\") == \"11:00\"\n assert candidate(s = \"0?:3?\") == \"09:39\"\n assert candidate(s = \"10:5?\") == \"10:59\"\n assert candidate(s = \"11:?0\") == \"11:50\"\n assert candidate(s = \"1?:55\") == \"11:55\"\n assert candidate(s = \"?9:?9\") == \"09:59\"\n assert candidate(s = \"?8:?8\") == \"08:58\"\n assert candidate(s = \"09:?0\") == \"09:50\"\n assert candidate(s = \"0?:58\") == \"09:58\"\n assert candidate(s = \"1?:5?\") == \"11:59\"\n assert candidate(s = \"0?:1?\") == \"09:19\"\n assert candidate(s = \"0?:4?\") == \"09:49\"\n assert candidate(s = \"09:?5\") == \"09:55\"\n assert candidate(s = \"1?:?9\") == \"11:59\"\n", "comparison": "exact"}, "public_tests": ["\"1?:?4\"", "\"0?:5?\""], "hints": ["Try using a brute force approach.", "Iterate over all possible times that can be generated from the string and find the latest one."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().findLatestTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:33+00:00", "tests_total": 121, "tests_dropped": 48, "flags": [], "topic_tags": ["string", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def find_latest_time(s)", "container": null, "callable": "find_latest_time", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3115, "task_id": "maximum-prime-difference", "difficulty": "Medium", "problem_description": "You are given an integer array nums.\n\nReturn an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums.\n\nExample 1:\n\nInput: nums = [4,2,9,5,3]\nOutput: 3\nExplanation: nums[1], nums[3], and nums[4] are prime. So the answer is |4 - 1| = 3.\n\nExample 2:\n\nInput: nums = [4,8,2,8]\nOutput: 0\nExplanation: nums[2] is prime. Because there is just one prime number, the answer is |2 - 2| = 0.\n\nConstraints:\n\n- 1 <= nums.length <= 3 * 10^5\n- 1 <= nums[i] <= 100\n- The input is generated such that the number of prime numbers in the nums is at least one.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [97, 1, 97, 1, 97]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 9\n assert candidate(nums = [100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 13, 10, 7, 4, 1]) == 30\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 9\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94]) == 0\n assert candidate(nums = [3, 3, 3, 3]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [71, 71, 71, 71, 71, 71, 71]) == 6\n assert candidate(nums = [4, 2, 9, 5, 3]) == 3\n assert candidate(nums = [2]) == 0\n assert candidate(nums = [2, 100, 50, 25, 75]) == 0\n assert candidate(nums = [11, 13, 17, 19, 23, 29, 31]) == 6\n assert candidate(nums = [79, 15, 29, 53, 79, 79, 79]) == 6\n assert candidate(nums = [11, 13, 17, 19, 23, 29]) == 5\n assert candidate(nums = [29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 0\n assert candidate(nums = [71, 73, 79, 71, 73, 79, 71, 73, 79, 71]) == 9\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 6\n assert candidate(nums = [83, 67, 89, 53, 61]) == 4\n assert candidate(nums = [29, 29, 29, 29, 29, 29, 29, 29, 29, 29]) == 9\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 9\n assert candidate(nums = [11, 11, 11, 11, 11, 11, 11, 11, 11, 11]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [4, 8, 2, 8]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3]) == 4\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19]) == 6\n assert candidate(nums = [1, 4, 6, 8, 10]) == None\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 17\n assert candidate(nums = [10, 15, 20, 25, 30]) == None\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]) == 45\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]) == 95\n assert candidate(nums = [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]) == 45\n assert candidate(nums = [89, 97, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2, 89, 97, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == 49\n assert candidate(nums = [84, 71, 83, 35, 29, 68, 51, 47, 92, 79, 60, 59, 46, 53, 61, 15, 73, 74, 87, 45, 40, 73, 84, 70, 83, 32, 57, 94, 48, 43, 30, 47, 76, 90, 51, 39, 28, 88, 22, 53, 59, 46, 53, 61, 15, 73, 74, 87, 45, 40, 73, 84, 70, 83, 32, 57, 94, 48, 43, 30, 47, 76, 90, 51, 39, 28, 88, 22, 53, 59, 46, 53, 61, 15, 73, 74, 87, 45, 40, 73, 84, 70, 83, 32, 57, 94, 48, 43, 30, 47, 76, 90, 51, 39, 28, 88, 22, 53, 59, 46, 53, 61, 15, 73, 74, 87, 45, 40, 73, 84, 70, 83, 32, 57, 94, 48, 43, 30, 47, 76, 90, 51, 39, 28, 88, 22, 53, 59, 46, 53, 61]) == 129\n assert candidate(nums = [46, 67, 41, 89, 29, 97, 73, 31, 61, 37, 79, 83, 7, 53, 59, 8, 5, 3, 2, 97, 43, 47, 11, 19, 60, 88, 23, 71, 13, 5, 17, 19, 67, 73, 11, 89, 59, 71, 79, 31, 7, 37, 97, 2, 29, 19, 61, 13, 19, 67, 73, 11, 89, 59, 71, 79, 31, 7, 37, 97, 2, 29, 19, 61, 13, 19, 67, 73, 11, 89, 59, 71, 79, 31, 7, 37, 97, 2, 29, 19, 61, 13, 19, 67, 73, 11, 89, 59, 71, 79, 31, 7, 37]) == 91\n assert candidate(nums = [97, 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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 97\n", "comparison": "exact"}, "public_tests": ["[4,2,9,5,3]", "[4,8,2,8]"], "hints": ["Find all prime numbers in the nums.", "Find the first and the last prime number in the nums."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumPrimeDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:36+00:00", "tests_total": 53, "tests_dropped": 14, "flags": [], "topic_tags": ["array", "math", "number-theory", "primality-test"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_prime_difference(nums)", "container": null, "callable": "maximum_prime_difference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3116, "task_id": "kth-smallest-amount-with-single-denomination-combination", "difficulty": "Hard", "problem_description": "You are given an integer array coins representing coins of different denominations and an integer k.\n\nYou have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations.\n\nReturn the k^th smallest amount that can be made using these coins.\n\nExample 1:\n\nInput: coins = [3,6,9], k = 3\nOutput: 9\nExplanation: The given coins can make the following amounts:\nCoin 3 produces multiples of 3: 3, 6, 9, 12, 15, etc.\nCoin 6 produces multiples of 6: 6, 12, 18, 24, etc.\nCoin 9 produces multiples of 9: 9, 18, 27, 36, etc.\nAll of the coins combined produce: 3, 6, 9, 12, 15, etc.\n\nExample 2:\n\nInput: coins = [5,2], k = 7\nOutput: 12\nExplanation: The given coins can make the following amounts:\nCoin 5 produces multiples of 5: 5, 10, 15, 20, etc.\nCoin 2 produces multiples of 2: 2, 4, 6, 8, 10, 12, etc.\nAll of the coins combined produce: 2, 4, 5, 6, 8, 10, 12, 14, 15, etc.\n\nConstraints:\n\n- 1 <= coins.length <= 15\n- 1 <= coins[i] <= 25\n- 1 <= k <= 2 * 10^9\n- coins contains pairwise distinct integers.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(coins = [15, 20, 25],k = 15) == 125\n assert candidate(coins = [4, 8, 12],k = 10) == 40\n assert candidate(coins = [2, 3, 5, 7],k = 12) == 15\n assert candidate(coins = [7, 11, 13],k = 15) == 52\n assert candidate(coins = [3, 6, 9],k = 3) == 9\n assert candidate(coins = [7, 11, 13],k = 10) == 35\n assert candidate(coins = [15, 20, 25],k = 8) == 60\n assert candidate(coins = [2, 3, 5],k = 30) == 40\n assert candidate(coins = [1, 2, 3],k = 10) == 10\n assert candidate(coins = [5, 2],k = 7) == 12\n assert candidate(coins = [1, 2, 3],k = 5) == 5\n assert candidate(coins = [8, 16, 24],k = 12) == 96\n assert candidate(coins = [17, 19, 23],k = 8) == 57\n assert candidate(coins = [3, 5, 7],k = 20) == 36\n assert candidate(coins = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 75) == 150\n assert candidate(coins = [2, 5, 7, 10],k = 30) == 46\n assert candidate(coins = [1, 3, 6, 9, 12, 15],k = 100) == 100\n assert candidate(coins = [2, 5, 10, 20],k = 25) == 42\n assert candidate(coins = [1, 3, 5, 7, 9],k = 100) == 100\n assert candidate(coins = [3, 5, 7, 9, 11, 13],k = 100) == 165\n assert candidate(coins = [2, 5, 10, 20],k = 30) == 50\n assert candidate(coins = [3, 5, 7, 9],k = 20) == 36\n assert candidate(coins = [2, 3, 5, 7, 11, 13, 17, 19],k = 150) == 185\n assert candidate(coins = [2, 5, 10, 20, 25],k = 200) == 334\n assert candidate(coins = [1, 3, 5, 7, 9, 11],k = 100) == 100\n assert candidate(coins = [4, 6, 8, 10, 12, 14],k = 60) == 156\n assert candidate(coins = [1, 4, 9, 16, 25],k = 100) == 100\n assert candidate(coins = [2, 3, 5, 7],k = 50) == 65\n assert candidate(coins = [13, 17, 19],k = 30) == 169\n assert candidate(coins = [3, 5, 7],k = 15) == 27\n assert candidate(coins = [11, 13, 17, 19],k = 50) == 190\n assert candidate(coins = [1, 3, 7, 9, 11, 13],k = 40) == 40\n assert candidate(coins = [11, 13, 17],k = 15) == 68\n assert candidate(coins = [4, 7, 10, 13, 16],k = 75) == 169\n assert candidate(coins = [11, 13, 17],k = 20) == 91\n assert candidate(coins = [2, 3, 5, 7, 11],k = 100) == 126\n assert candidate(coins = [1, 3, 5, 7, 9, 11, 13],k = 50) == 50\n assert candidate(coins = [2, 3, 5, 7, 11],k = 50) == 64\n assert candidate(coins = [6, 9, 12, 18],k = 50) == 225\n assert candidate(coins = [3, 5, 7, 9, 11],k = 30) == 50\n assert candidate(coins = [3, 5, 15],k = 25) == 54\n assert candidate(coins = [6, 12, 18, 24],k = 100) == 600\n assert candidate(coins = [5, 10, 15, 20, 25],k = 250) == 1250\n assert candidate(coins = [19, 21, 23, 25],k = 40) == 228\n assert candidate(coins = [2, 3, 5, 7, 11, 13, 17, 19],k = 300) == 365\n assert candidate(coins = [7, 11, 13],k = 15) == 52\n assert candidate(coins = [7, 11, 13, 17, 19],k = 35) == 91\n assert candidate(coins = [3, 6, 9, 12, 15],k = 50) == 150\n assert candidate(coins = [1, 4, 9, 16, 25],k = 150) == 150\n assert candidate(coins = [3, 5, 7, 9],k = 20) == 36\n assert candidate(coins = [17, 19, 23],k = 20) == 136\n assert candidate(coins = [7, 14, 21],k = 15) == 105\n assert candidate(coins = [3, 6, 9, 12, 15],k = 30) == 90\n assert candidate(coins = [6, 10, 14],k = 30) == 110\n assert candidate(coins = [2, 4, 6, 8, 10],k = 30) == 60\n assert candidate(coins = [15, 20, 25],k = 50) == 420\n assert candidate(coins = [2, 3, 5, 7],k = 25) == 33\n assert candidate(coins = [2, 5, 10, 25],k = 50) == 84\n", "comparison": "exact"}, "public_tests": ["[3,6,9]\n3", "[5,2]\n7"], "hints": ["Binary search the answer x.", "Use the inclusion-exclusion principle to count the number of distinct amounts that can be made up to x."], "metadata": {"canonical_parameter_names": ["coins", "k"], "leetcode_dataset_entry_point": "Solution().findKthSmallest", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:38+00:00", "tests_total": 110, "tests_dropped": 52, "flags": [], "topic_tags": ["array", "math", "binary-search", "bit-manipulation", "combinatorics", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def find_kth_smallest(coins, k)", "container": null, "callable": "find_kth_smallest", "parameters": [{"name": "coins", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3117, "task_id": "minimum-sum-of-values-by-dividing-array", "difficulty": "Hard", "problem_description": "You are given two arrays nums and andValues of length n and m respectively.\n\nThe value of an array is equal to the last element of that array.\n\nYou have to divide nums into m disjoint contiguous subarrays such that for the i^th subarray [l_i, r_i], the bitwise AND of the subarray elements is equal to andValues[i], in other words, nums[l_i] & nums[l_i + 1] & ... & nums[r_i] == andValues[i] for all 1 <= i <= m, where & represents the bitwise AND operator.\n\nReturn the minimum possible sum of the values of the m subarrays nums is divided into. If it is not possible to divide nums into m subarrays satisfying these conditions, return -1.\n\nExample 1:\n\nInput: nums = [1,4,3,3,2], andValues = [0,3,3,2]\nOutput: 12\nExplanation:\nThe only possible way to divide nums is:\n1. [1,4] as 1 & 4 == 0.\n2. [3] as the bitwise AND of a single element subarray is that element itself.\n3. [3] as the bitwise AND of a single element subarray is that element itself.\n4. [2] as the bitwise AND of a single element subarray is that element itself.\n\nThe sum of the values for these subarrays is 4 + 3 + 3 + 2 = 12.\n\nExample 2:\n\nInput: nums = [2,3,5,7,7,7,5], andValues = [0,7,5]\nOutput: 17\nExplanation:\nThere are three ways to divide nums:\n1. [[2,3,5],[7,7,7],[5]] with the sum of the values 5 + 7 + 5 == 17.\n2. [[2,3,5,7],[7,7],[5]] with the sum of the values 7 + 7 + 5 == 19.\n3. [[2,3,5,7,7],[7],[5]] with the sum of the values 7 + 7 + 5 == 19.\n\nThe minimum possible sum of the values is 17.\n\nExample 3:\n\nInput: nums = [1,2,3,4], andValues = [2]\nOutput: -1\nExplanation:\nThe bitwise AND of the entire array nums is 0. As there is no possible way to divide nums into a single subarray to have the bitwise AND of elements 2, return -1.\n\nConstraints:\n\n- 1 <= n == nums.length <= 10^4\n- 1 <= m == andValues.length <= min(n, 10)\n- 1 <= nums[i] < 10^5\n- 0 <= andValues[j] < 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5],andValues = [5, 5]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16],andValues = [0, 0, 0]) == 28\n assert candidate(nums = [8, 12, 10, 14],andValues = [8, 14]) == 24\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],andValues = [10, 10, 10, 10]) == 40\n assert candidate(nums = [15, 11, 13, 14, 12],andValues = [15, 11, 12]) == 38\n assert candidate(nums = [10, 20, 30, 40, 50],andValues = [10, 20, 30]) == -1\n assert candidate(nums = [9, 18, 27, 36],andValues = [9, 18, 27]) == -1\n assert candidate(nums = [1, 2, 3, 4],andValues = [2]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [1]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16],andValues = [0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],andValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22],andValues = [31]) == -1\n assert candidate(nums = [8, 4, 2, 1],andValues = [8, 4, 2, 1]) == 15\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],andValues = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [1, 4, 3, 3, 2],andValues = [0, 3, 3, 2]) == 12\n assert candidate(nums = [10, 20, 30, 40, 50],andValues = [10, 20, 30, 40, 50]) == 150\n assert candidate(nums = [1, 2, 4, 8, 16],andValues = [1, 2, 4, 8, 16]) == 31\n assert candidate(nums = [1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [10, 15, 7, 3],andValues = [10, 7]) == -1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2],andValues = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 2046\n assert candidate(nums = [7, 7, 7, 7, 7, 7],andValues = [7, 7]) == 14\n assert candidate(nums = [15, 15, 15, 15],andValues = [15]) == 15\n assert candidate(nums = [31, 15, 7, 3],andValues = [31, 15, 7, 3]) == 56\n assert candidate(nums = [31, 31, 31, 31],andValues = [31, 31]) == 62\n assert candidate(nums = [1, 1, 1, 1],andValues = [1, 1, 1, 1]) == 4\n assert candidate(nums = [2, 3, 5, 7, 7, 7, 5],andValues = [0, 7, 5]) == 17\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7]) == 21\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],andValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 100\n assert candidate(nums = [8, 8, 8, 8, 8],andValues = [8, 8, 8]) == 24\n assert candidate(nums = [15, 15, 15, 15, 15],andValues = [15]) == 15\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6],andValues = [6, 6, 6, 6]) == 24\n assert candidate(nums = [5, 5, 5, 5, 5],andValues = [5, 5]) == 10\n assert candidate(nums = [5, 3, 1, 4, 8, 7],andValues = [5, 3, 1]) == -1\n assert candidate(nums = [9, 10, 11, 12, 13, 14],andValues = [9, 10, 11]) == -1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3],andValues = [3, 3, 3]) == 9\n assert candidate(nums = [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],andValues = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22]) == -1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],andValues = [7, 14, 21, 28, 35]) == -1\n assert candidate(nums = [63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63],andValues = [63, 63, 63, 63]) == 252\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7, 7, 7, 7]) == 42\n assert candidate(nums = [123, 456, 789, 1011, 1213, 1415, 1617, 1819, 2021],andValues = [123, 789, 1617]) == -1\n assert candidate(nums = [64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64],andValues = [64, 64, 64, 64, 64]) == 320\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31],andValues = [31, 31, 31, 31, 31]) == 155\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],andValues = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 2036\n assert candidate(nums = [5, 3, 7, 15, 9, 6, 12],andValues = [3, 7, 12]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],andValues = [0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],andValues = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],andValues = [8, 8, 8, 8, 8]) == 40\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [0, 1, 2, 4, 8, 16, 32, 64, 128]) == -1\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],andValues = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],andValues = [8, 8, 8, 8, 8]) == 40\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 70\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],andValues = [5, 10, 15, 20]) == -1\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30],andValues = [6, 14, 22, 30]) == -1\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60],andValues = [6, 12, 18, 24, 30, 36, 42, 48, 54]) == -1\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17],andValues = [17, 17, 17]) == 51\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],andValues = [5, 10, 15, 20, 25]) == -1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],andValues = [8, 8, 8, 8]) == 32\n assert candidate(nums = [15, 7, 3, 1, 8, 4, 2, 1],andValues = [1, 3, 2, 8]) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [127, 63, 31, 15, 7, 3, 1],andValues = [63, 15, 3]) == -1\n assert candidate(nums = [15, 7, 3, 1, 1, 2, 4, 8],andValues = [1, 3, 3, 0, 2]) == -1\n assert candidate(nums = [15, 7, 3, 1, 15, 3, 7, 1],andValues = [1, 3, 3, 1]) == -1\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],andValues = [9, 9, 9, 9, 9]) == 45\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],andValues = [3, 3, 3, 3, 3]) == 15\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],andValues = [255, 255, 255, 255, 255]) == 1275\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],andValues = [127, 31, 7, 1]) == 166\n assert candidate(nums = [31, 15, 7, 3, 1],andValues = [31, 15, 7, 3, 1]) == 57\n assert candidate(nums = [15, 7, 3, 1, 1, 1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48],andValues = [6, 18, 30, 42]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],andValues = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],andValues = [5, 15, 35, 50]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],andValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],andValues = [0, 9, 18, 27, 36, 45, 54, 63, 72]) == -1\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],andValues = [9, 9, 9, 9]) == 36\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],andValues = [3, 7, 15, 31, 63, 127, 255, 511, 1023]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7, 7]) == 28\n assert candidate(nums = [127, 63, 31, 15, 7, 3, 1],andValues = [127, 63, 31, 15, 7, 3, 1]) == 247\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],andValues = [15, 12, 8, 4, 0]) == 40\n assert candidate(nums = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246],andValues = [255, 246]) == -1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],andValues = [10, 10, 10, 10, 10]) == 50\n assert candidate(nums = [8, 4, 2, 1, 1, 2, 4, 8],andValues = [0, 0, 0, 0]) == 15\n assert candidate(nums = [9, 5, 3, 1, 3, 5, 9, 1, 3, 5],andValues = [1, 3, 5, 9]) == -1\n assert candidate(nums = [8, 4, 2, 1, 8, 4, 2, 1],andValues = [8, 4, 2, 1, 8, 4]) == -1\n assert candidate(nums = [63, 62, 61, 60, 59, 58, 57, 56, 55, 54],andValues = [63, 60, 57]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7, 7]) == 28\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700],andValues = [0, 100, 500]) == -1\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 10, 11, 12, 13],andValues = [10, 14, 10]) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [1, 4, 16, 64, 256]) == -1\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15],andValues = [15, 15, 15, 15, 15]) == 75\n assert candidate(nums = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],andValues = [0, 0, 0, 0, 0]) == 21824\n assert candidate(nums = [5, 7, 15, 9, 13, 8, 6],andValues = [3, 7, 13, 6]) == -1\n assert candidate(nums = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15],andValues = [31, 30, 29, 28, 27, 26, 25]) == -1\n assert candidate(nums = [31, 15, 7, 3, 1, 3, 7, 15, 31],andValues = [1, 3, 7, 15, 31]) == 57\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],andValues = [2, 3, 2, 3]) == 10\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],andValues = [0, 255, 0, 255, 0]) == -1\n assert candidate(nums = [8, 12, 14, 15, 9, 10, 12],andValues = [8, 14, 10]) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256],andValues = [0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1],andValues = [128, 64, 32, 16, 8, 4, 2, 1]) == 255\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],andValues = [5, 5, 5, 5, 5]) == 25\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16],andValues = [31, 30, 29, 28, 27]) == -1\n assert candidate(nums = [32, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1],andValues = [32, 16, 8, 4, 2, 1, 32, 16]) == -1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],andValues = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == -1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],andValues = [8, 8, 8, 8, 8, 8, 8]) == 56\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900],andValues = [100, 200, 300]) == -1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049],andValues = [3, 27, 729, 19683]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],andValues = [10, 30, 60, 100]) == -1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],andValues = [255, 127, 63, 31, 15, 7, 3, 1]) == 502\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [0, 2, 8, 32, 128]) == -1\n assert candidate(nums = [15, 10, 7, 8, 4, 6, 5],andValues = [10, 8, 4]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],andValues = [10, 10, 10, 10]) == 40\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],andValues = [0, 3, 0, 3, 0]) == -1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],andValues = [0, 8, 16, 24, 32]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],andValues = [5, 10, 15, 50]) == -1\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],andValues = [15, 14, 13, 12]) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],andValues = [1, 3, 7, 15]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [1, 5, 3, 7, 9, 11, 13, 15],andValues = [1, 3, 15]) == -1\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17],andValues = [29, 21, 17]) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7, 7, 7]) == 35\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],andValues = [5, 5, 5, 5]) == 20\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],andValues = [29, 19, 11, 5]) == -1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],andValues = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 2036\n assert candidate(nums = [123, 456, 789, 1011, 1213, 1314, 1415],andValues = [123, 456, 789, 1415]) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],andValues = [7, 7, 7, 7, 7]) == 35\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],andValues = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 2036\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047],andValues = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 3060\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],andValues = [7, 14, 21, 28, 35, 42, 49, 56, 63]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],andValues = [0, 10, 30, 40, 50, 60, 70, 80, 90, 100]) == -1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35],andValues = [5, 15, 35]) == -1\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],andValues = [255, 255, 255, 255, 255]) == 1275\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29],andValues = [21, 23, 27]) == -1\n assert candidate(nums = [33, 33, 33, 33, 33, 33, 33],andValues = [33, 33, 33, 33]) == 132\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == -1\n assert candidate(nums = [31, 14, 7, 3, 1, 1, 1, 1],andValues = [31, 14, 7, 3, 1]) == 56\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],andValues = [1, 2, 4, 8, 16]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],andValues = [0, 5, 0, 5, 0]) == -1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56],andValues = [8, 16, 24, 32]) == 104\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],andValues = [1, 1, 1, 1, 1, 1, 1]) == 7\n", "comparison": "exact"}, "public_tests": ["[1,4,3,3,2]\n[0,3,3,2]", "[2,3,5,7,7,7,5]\n[0,7,5]", "[1,2,3,4]\n[2]"], "hints": ["Let dp[i][j] be the optimal answer to split nums[0..(i - 1)] into the first j andValues.", "dp[i][j] = min(dp[(i - z)][j - 1]) + nums[i - 1] over all x <= z <= y and dp[0][0] = 0, where x and y are the longest and shortest subarrays ending with nums[i - 1] and the bitwise-and of all the values in it is andValues[j - 1].", "The answer is dp[n][m].", "To calculate x and y, we can use binary search (or sliding window). Note that the more values we have, the smaller the AND value is.", "To calculate the result, we need to support RMQ (range minimum query). Segment tree is one way to do it in O(log(n)). But we can use Monotonic Queue since the ranges are indeed “sliding to right” which can be reduced to the classical minimum value in sliding window problem, for a O(n) solution."], "metadata": {"canonical_parameter_names": ["nums", "andValues"], "leetcode_dataset_entry_point": "Solution().minimumValueSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:40+00:00", "tests_total": 170, "tests_dropped": 26, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "bit-manipulation", "segment-tree", "queue"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_value_sum(nums, and_values)", "container": null, "callable": "minimum_value_sum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "and_values", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3120, "task_id": "count-the-number-of-special-characters-i", "difficulty": "Easy", "problem_description": "You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word.\n\nReturn the number of special letters in word.\n\nExample 1:\n\nInput: word = \"aaAbcBC\"\nOutput: 3\nExplanation:\nThe special characters in word are 'a', 'b', and 'c'.\n\nExample 2:\n\nInput: word = \"abc\"\nOutput: 0\nExplanation:\nNo character in word appears in uppercase.\n\nExample 3:\n\nInput: word = \"abBCab\"\nOutput: 1\nExplanation:\nThe only special character in word is 'b'.\n\nConstraints:\n\n- 1 <= word.length <= 50\n- word consists of only lowercase and uppercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"xyzXYZ\") == 3\n assert candidate(word = \"aabbcc\") == 0\n assert candidate(word = \"AABBCC\") == 0\n assert candidate(word = \"cCcCc\") == 1\n assert candidate(word = \"AaBbCc\") == 3\n assert candidate(word = \"abBCab\") == 1\n assert candidate(word = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == 0\n assert candidate(word = \"XyZxYz\") == 3\n assert candidate(word = \"a\") == 0\n assert candidate(word = \"A\") == 0\n assert candidate(word = \"aaAbcBC\") == 3\n assert candidate(word = \"bBbB\") == 1\n assert candidate(word = \"aA\") == 1\n assert candidate(word = \"MixedCASEwithSPECIALSspecial\") == 7\n assert candidate(word = \"nestedLoopNESTED\") == 5\n assert candidate(word = \"LongStringWithNoSpecials\") == 3\n assert candidate(word = \"abcdefABCDEF\") == 6\n assert candidate(word = \"SpecialLettersTest\") == 3\n assert candidate(word = \"MixedCASEwithSpecials\") == 4\n assert candidate(word = \"UniqueSpecialsABCDabcd\") == 6\n assert candidate(word = \"aAbBcC\") == 3\n assert candidate(word = \"abcABC\") == 3\n assert candidate(word = \"abcdefGHIJKLmnopQRstUVWxyz\") == 0\n assert candidate(word = \"aAbBC\") == 2\n assert candidate(word = \"worldWORLD\") == 5\n assert candidate(word = \"xylophoneXYZ\") == 2\n assert candidate(word = \"nestedCASECASEnested\") == 2\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaA\") == 1\n assert candidate(word = \"AbCdefGhIjkLmnopQrstUVwXyZ\") == 0\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 1\n assert candidate(word = \"UPPERlower\") == 2\n assert candidate(word = \"zZyYxXwWvVuUtTsSrRpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == 25\n assert candidate(word = \"NoSpecial\") == 0\n assert candidate(word = \"OneSpecialA\") == 1\n assert candidate(word = \"SingleSpeciala\") == 0\n assert candidate(word = \"AbcDeEfGhIjKlMnOpQrStUvWxYz\") == 1\n assert candidate(word = \"helloHELLO\") == 4\n assert candidate(word = \"HelloWorld\") == 0\n assert candidate(word = \"MultipleUUppercases\") == 1\n assert candidate(word = \"TrailingSpecialsAaBbCc\") == 4\n assert candidate(word = \"abcABCabcABCabcABC\") == 3\n assert candidate(word = \"JustOneSpecialCharacterb\") == 2\n assert candidate(word = \"noSpecial\") == 0\n assert candidate(word = \"NoSpecialCharacters\") == 2\n assert candidate(word = \"SpecialCharacters\") == 2\n assert candidate(word = \"lowerCASEuppercase\") == 4\n assert candidate(word = \"UniqueUniqueUniqueUnique\") == 1\n assert candidate(word = \"CASEsensitive\") == 2\n assert candidate(word = \"OneSpecialAa\") == 1\n assert candidate(word = \"SingleSpecialA\") == 1\n assert candidate(word = \"MultipleMultipleMultiple\") == 0\n assert candidate(word = \"TestCase\") == 1\n assert candidate(word = \"NestedSpecialsAaBBbbCCcc\") == 4\n assert candidate(word = \"abcdEFGHijKLMnopQRSTuvWXyz\") == 0\n assert candidate(word = \"JustOneAa\") == 1\n assert candidate(word = \"StartingWithSpecialsAaBbCc\") == 4\n assert candidate(word = \"uniqueUnique\") == 1\n assert candidate(word = \"specialCharSPECIAL\") == 7\n assert candidate(word = \"AlphabetSoup\") == 1\n assert candidate(word = \"AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == 1\n assert candidate(word = \"RepeatRepeatREPEAT\") == 4\n assert candidate(word = \"specialCharacters\") == 1\n assert candidate(word = \"aAaAaA\") == 1\n assert candidate(word = \"JustOneZz\") == 1\n assert candidate(word = \"Zebra\") == 0\n assert candidate(word = \"EndingWithSpecialsAaBbCc\") == 5\n assert candidate(word = \"bbbbbbbbBBBBBBB\") == 1\n assert candidate(word = \"RePeAtInGChaRaCtErS\") == 3\n assert candidate(word = \"repeatedCHARactersCHARacters\") == 3\n assert candidate(word = \"UniqueCASE\") == 2\n assert candidate(word = \"doubleDOUBLEtrouble\") == 6\n assert candidate(word = \"PythonIsAwesome\") == 0\n assert candidate(word = \"QwErTyUiOpAsDfGhJkLzXcVbNm\") == 0\n assert candidate(word = \"abCDefGHijKLmnopQRstUVwxYZ\") == 0\n assert candidate(word = \"abcABCdefDEFghiGHI\") == 9\n assert candidate(word = \"pythonPYTHON\") == 6\n assert candidate(word = \"OverlapOverlap\") == 0\n assert candidate(word = \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 0\n assert candidate(word = \"CASEcase\") == 4\n assert candidate(word = \"testCaseTestCase\") == 1\n assert candidate(word = \"specialCHARSareHERE\") == 5\n assert candidate(word = \"SingleSpecialAa\") == 1\n assert candidate(word = \"SsEeCcIiAaLlTtCcHaArAcCtTeErsRsS\") == 8\n assert candidate(word = \"JustOneSpecialCharacterB\") == 2\n assert candidate(word = \"bBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbB\") == 1\n assert candidate(word = \"NoRepeatsJustSpecialsAaBbCc\") == 4\n assert candidate(word = \"MiXeDcAsEwItHiSmOvEs\") == 4\n assert candidate(word = \"HelloWORLD\") == 2\n assert candidate(word = \"SpecialCharactersTEST\") == 4\n assert candidate(word = \"SpecialCHARacters\") == 4\n assert candidate(word = \"MultiplELowercases\") == 2\n assert candidate(word = \"OverlapAaBbCcAaBbCc\") == 3\n assert candidate(word = \"uniqueUnIQUE\") == 4\n assert candidate(word = \"helloWorldHELLO\") == 4\n assert candidate(word = \"specialSPECIAL\") == 7\n assert candidate(word = \"PythonProgramming\") == 0\n assert candidate(word = \"Mississippi\") == 0\n assert candidate(word = \"MixedCASEWithSOMEspecial\") == 4\n assert candidate(word = \"NoSpecialHere\") == 0\n assert candidate(word = \"aaaaaaaaaAAAAAA\") == 1\n", "comparison": "exact"}, "public_tests": ["\"aaAbcBC\"", "\"abc\"", "\"abBCab\""], "hints": ["The constraints are small. For all 52 characters, check if they are present in word."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().numberOfSpecialChars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:45+00:00", "tests_total": 159, "tests_dropped": 58, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_special_chars(word)", "container": null, "callable": "number_of_special_chars", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3121, "task_id": "count-the-number-of-special-characters-ii", "difficulty": "Medium", "problem_description": "You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c.\n\nReturn the number of special letters in word.\n\nExample 1:\n\nInput: word = \"aaAbcBC\"\nOutput: 3\nExplanation:\nThe special characters are 'a', 'b', and 'c'.\n\nExample 2:\n\nInput: word = \"abc\"\nOutput: 0\nExplanation:\nThere are no special characters in word.\n\nExample 3:\n\nInput: word = \"AbBCab\"\nOutput: 0\nExplanation:\nThere are no special characters in word.\n\nConstraints:\n\n- 1 <= word.length <= 2 * 10^5\n- word consists of only lowercase and uppercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aAbBcCdDeEfFgG\") == 7\n assert candidate(word = \"AaBbCc\") == 0\n assert candidate(word = \"aabbCC\") == 0\n assert candidate(word = \"Aabbcc\") == 0\n assert candidate(word = \"abABcdCD\") == 4\n assert candidate(word = \"zZaA\") == 2\n assert candidate(word = \"aAbBcC\") == 3\n assert candidate(word = \"aAb\") == 1\n assert candidate(word = \"abcABC\") == 3\n assert candidate(word = \"ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa\") == 0\n assert candidate(word = \"AbBCab\") == 0\n assert candidate(word = \"ZzYyXx\") == 0\n assert candidate(word = \"ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjiIhHgGfFeEdDcCbBaA\") == 9\n assert candidate(word = \"aA\") == 1\n assert candidate(word = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 0\n assert candidate(word = \"abcdefgHIJKLmnopqrstuvwxyz\") == 0\n assert candidate(word = \"aaAbcBC\") == 3\n assert candidate(word = \"aabB\") == 1\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"Aa\") == 0\n assert candidate(word = \"aabbccAABBCC\") == 3\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 26\n assert candidate(word = \"AaBbCcDdEeFf\") == 0\n assert candidate(word = \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 0\n assert candidate(word = \"AaBbCcDd\") == 0\n assert candidate(word = \"zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == 26\n assert candidate(word = \"aabbccAAABBBCCC\") == 3\n assert candidate(word = \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == 26\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(word = \"aaaaaAAAAAaaaaaAAAAA\") == 0\n assert candidate(word = \"abcXYZabcXYZ\") == 0\n assert candidate(word = \"zzzzZ\") == 1\n assert candidate(word = \"abcdEFGhijklmNOPqrSTuvWXYZ\") == 0\n assert candidate(word = \"aAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 0\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(word = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == 0\n assert candidate(word = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == 0\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(word = \"aAbBcCddeEfffGggHhhIiiJjjKkkLllMmmNnnOooPppQqqRrrSssTttUuuVvvWwwXxxYyyZzz\") == 4\n assert candidate(word = \"Zabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(word = \"zZyYxXwWvVuUtTsSrRpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == 25\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(word = \"aBcD\") == 0\n assert candidate(word = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAbB\") == 24\n assert candidate(word = \"AbCdeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 2\n assert candidate(word = \"xyzXYZabcABC\") == 6\n assert candidate(word = \"zzzzZzzzZzzzzzzz\") == 0\n assert candidate(word = \"AbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUvWxYz\") == 0\n assert candidate(word = \"AbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == 25\n assert candidate(word = \"abcABCabcABCabcABC\") == 0\n assert candidate(word = \"abABcdCDefEfghGhijIJklKLmMnopNOPqrstQRstUVuvwVwxWXyzYZ\") == 20\n assert candidate(word = \"AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYZZZ\") == 0\n assert candidate(word = \"aAAAbBBBcCCCCdDDDD\") == 4\n assert candidate(word = \"AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 25\n assert candidate(word = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 0\n assert candidate(word = \"abCDcdEFefGHghIJijKLklMNmnOPopQRqrSTstUVuvWXwxYZyz\") == 0\n assert candidate(word = \"abcdefABCDEFghijklGHJKLmnopQRStuTUvwVWXyYZ\") == 16\n assert candidate(word = \"AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ\") == 0\n assert candidate(word = \"aAAaBBBbcccC\") == 1\n assert candidate(word = \"aBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 0\n assert candidate(word = \"aaaBBBcccDDD\") == 0\n assert candidate(word = \"abABcdE\") == 2\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(word = \"aBcDDefFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == 21\n assert candidate(word = \"aAbBcCdefGhIjKlMnopQrstUvwXyz\") == 3\n assert candidate(word = \"aaaBBBcccDDDeeeFFFgggHHHiiiJJJkkkLLLmmmNNNoooPPPqqqRRRsssTTTuuuVVVwwwXXXyyyZZZ\") == 0\n assert candidate(word = \"aBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(word = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCc\") == 0\n assert candidate(word = \"ZZZZzzzzYYYYyyyyXXXXXXXXxxWWWWwwwwVVVVvvvvUUUUuuuuTTTTttttSSSSssssRRRRrrrrQQQQqqqqPPPPppppOOOOooooNNNNnnnnMMMMmmmmLLLLllllKKKKkkkkJJJJjjjjIIIIiiiiHHHHhhhhGGGGggggFFFFFFffffEEEEeeeeDDDDddddCCCCccccBBBBbbbbAAAAAAAAaaaa\") == 0\n assert candidate(word = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 0\n assert candidate(word = \"abcdefgHIJKLMNopqrstuvwxyz\") == 0\n assert candidate(word = \"AbCdEfGhIjKlMnOpQrStUvWxYzABCD\") == 2\n assert candidate(word = \"zZyYxXwWvVuUtTrRsSqQpPnNmMlLkKiIhHgGfFeEdDcCbBaA\") == 24\n assert candidate(word = \"aAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzAA\") == 1\n assert candidate(word = \"aB\") == 0\n assert candidate(word = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaA\") == 1\n assert candidate(word = \"aBcDEfGHiJKlMNopQRsTuVwXyZ\") == 0\n assert candidate(word = \"aaaAAAaaaAAAaaaAAA\") == 0\n assert candidate(word = \"aBbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\") == 0\n assert candidate(word = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == 0\n assert candidate(word = \"zzzZZZyyyYYYxxxXXXwwwWWWvvvVVVuuuUUUtttTTTsssSSSrrrRRRqqqQQQpppPPPoooOOOnnnNNNmmmMMMlllLLLkkkKKKjjjJJJiiiIIIhhhHHHgggGGGfffFFFeeeEEEdddDDDcccCCCbbbBBBaaaAAA\") == 26\n assert candidate(word = \"aBcDefGhiJklMnoPqrStuVwxYz\") == 0\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(word = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 0\n assert candidate(word = \"aaBBccDDeeFFggHHiiJJkkLLmmNNooPPqqRRssTTuuVVwwXXyyZZ\") == 0\n assert candidate(word = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 0\n assert candidate(word = \"aaBBccDDeeFFggHHiiJjkkLLmmNNooPPqqRRssTTuuVVwwXXyyZZ\") == 0\n assert candidate(word = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzZ\") == 1\n assert candidate(word = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == 0\n assert candidate(word = \"mnopqrstuNOPQRS\") == 6\n assert candidate(word = \"aAbC\") == 1\n assert candidate(word = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == 0\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzZ\") == 1\n assert candidate(word = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == 26\n assert candidate(word = \"aAbCdeFghIjKlmNoPqRsTuVwXyZ\") == 1\n assert candidate(word = \"aaAaabBBccCCCd\") == 2\n", "comparison": "exact"}, "public_tests": ["\"aaAbcBC\"", "\"abc\"", "\"AbBCab\""], "hints": ["For each character c, store the first occurrence of its uppercase and the last occurrence of its lowercase."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().numberOfSpecialChars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:48+00:00", "tests_total": 100, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_special_chars(word)", "container": null, "callable": "number_of_special_chars", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3122, "task_id": "minimum-number-of-operations-to-satisfy-conditions", "difficulty": "Medium", "problem_description": "You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is:\n\n- Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).\n- Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).\n\nReturn the minimum number of operations needed.\n\nExample 1:\n\nInput: grid = [[1,0,2],[1,0,2]]\nOutput: 0\nExplanation:\nAll the cells in the matrix already satisfy the properties.\n\nExample 2:\n\nInput: grid = [[1,1,1],[0,0,0]]\nOutput: 3\nExplanation:\nThe matrix becomes [[1,0,1],[1,0,1]] which satisfies the properties, by doing these 3 operations:\n- Change grid[1][0] to 1.\n- Change grid[0][1] to 0.\n- Change grid[1][2] to 1.\n\nExample 3:\n\nInput: grid = [[1],[2],[3]]\nOutput: 2\nExplanation:\nThere is a single column. We can change the value to 1 in each cell using 2 operations.\n\nConstraints:\n\n- 1 <= n, m <= 1000\n- 0 <= grid[i][j] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1], [2], [3]]) == 2\n assert candidate(grid = [[1, 1, 1], [0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 2], [2, 1, 0], [0, 1, 2]]) == 2\n assert candidate(grid = [[9, 9], [9, 9], [9, 9]]) == 3\n assert candidate(grid = [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]) == 0\n assert candidate(grid = [[1, 1], [2, 2], [3, 3]]) == 4\n assert candidate(grid = [[9, 9, 9], [9, 9, 9], [9, 9, 9]]) == 3\n assert candidate(grid = [[7, 8, 9], [7, 8, 9], [7, 8, 9], [7, 8, 9]]) == 0\n assert candidate(grid = [[1, 1, 2, 2], [2, 2, 1, 1], [1, 1, 2, 2]]) == 6\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 6\n assert candidate(grid = [[1, 2, 3], [3, 4, 5], [5, 6, 7]]) == 6\n assert candidate(grid = [[1, 2, 3, 4], [4, 3, 2, 1], [1, 2, 3, 4]]) == 4\n assert candidate(grid = [[0]]) == 0\n assert candidate(grid = [[1, 2], [2, 1]]) == 2\n assert candidate(grid = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]) == 6\n assert candidate(grid = [[1, 2], [3, 4]]) == 2\n assert candidate(grid = [[1, 0, 2], [1, 0, 2]]) == 0\n assert candidate(grid = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2]]) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 18\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 4\n assert candidate(grid = [[1, 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, 3, 3, 3, 3]]) == 24\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == 12\n assert candidate(grid = [[9, 9, 9, 9, 9], [8, 8, 8, 8, 8], [7, 7, 7, 7, 7]]) == 10\n assert candidate(grid = [[1, 1, 2, 2, 3, 3], [1, 1, 2, 2, 3, 3], [4, 4, 5, 5, 6, 6], [4, 4, 5, 5, 6, 6]]) == 12\n assert candidate(grid = [[1, 1, 2, 2, 3, 3], [1, 1, 2, 2, 3, 3], [1, 1, 2, 2, 3, 3]]) == 9\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 9\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 6\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]]) == 18\n assert candidate(grid = [[1, 2, 2, 3], [1, 2, 2, 3], [1, 2, 2, 3]]) == 3\n assert candidate(grid = [[9, 9, 9, 9], [8, 8, 8, 8], [7, 7, 7, 7], [6, 6, 6, 6]]) == 12\n assert candidate(grid = [[1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1]]) == 12\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 10\n assert candidate(grid = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]) == 0\n assert candidate(grid = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) == 9\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 10\n assert candidate(grid = [[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]]) == 12\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]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2]]) == 10\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3]]) == 15\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 0\n assert candidate(grid = [[1, 2, 1, 2, 1], [2, 1, 2, 1, 2], [1, 2, 1, 2, 1]]) == 5\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 18\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 16\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [0, 1, 2, 3, 4]]) == 5\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == 5\n assert candidate(grid = [[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]]) == 30\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 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]]) == 10\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]]) == 14\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]]) == 15\n assert candidate(grid = [[1, 1, 2, 2, 3], [1, 1, 2, 2, 3], [1, 1, 2, 2, 3], [1, 1, 2, 2, 3]]) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]) == 18\n assert candidate(grid = [[1, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 3\n assert candidate(grid = [[1, 1, 2, 2, 3, 3, 4, 4, 5, 5], [1, 1, 2, 2, 3, 3, 4, 4, 5, 5], [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]]) == 15\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1], [0, 9, 8], [7, 6, 5]]) == 12\n assert candidate(grid = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]) == 0\n assert candidate(grid = [[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]]) == 0\n assert candidate(grid = [[9, 9, 9, 9], [8, 8, 8, 8], [7, 7, 7, 7]]) == 8\n assert candidate(grid = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3]]) == 10\n assert candidate(grid = [[9, 8, 7, 6], [9, 8, 7, 6], [9, 8, 7, 6]]) == 0\n assert candidate(grid = [[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4], [5, 5, 5, 6, 6, 6]]) == 12\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [1, 1, 1, 1]]) == 10\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 20\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]]) == 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]]) == 8\n assert candidate(grid = [[1, 2, 1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]]) == 10\n assert candidate(grid = [[9, 8, 7, 6, 5], [4, 3, 2, 1, 0], [9, 8, 7, 6, 5]]) == 5\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]) == 16\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]]) == 5\n assert candidate(grid = [[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]]) == 20\n assert candidate(grid = [[4, 3, 2, 1], [4, 3, 2, 1], [4, 3, 2, 1], [4, 3, 2, 1]]) == 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]]) == 10\n assert candidate(grid = [[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], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]]) == 32\n assert candidate(grid = [[1, 1, 2, 2, 1, 1], [2, 2, 1, 1, 2, 2], [1, 1, 2, 2, 1, 1]]) == 9\n assert candidate(grid = [[1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2]]) == 6\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 2, 1, 2, 1, 2], [2, 2, 2, 2, 2, 2], [2, 1, 2, 1, 2, 1], [1, 1, 1, 1, 1, 1]]) == 15\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]]) == 10\n assert candidate(grid = [[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) == 12\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]]) == 10\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]]) == 15\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 18\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0]]) == 4\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 2, 4, 5]]) == 6\n assert candidate(grid = [[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]]) == 21\n assert candidate(grid = [[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]]) == 20\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 5\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [1, 0, 0, 0, 1]]) == 10\n assert candidate(grid = [[1, 2, 2, 3, 3, 4, 4, 5, 5, 6], [1, 2, 2, 3, 3, 4, 4, 5, 5, 6], [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 10\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 0\n assert candidate(grid = [[3, 3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1]]) == 14\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == 8\n assert candidate(grid = [[1, 2, 1, 2, 1], [2, 1, 2, 1, 2], [1, 2, 1, 2, 1], [2, 1, 2, 1, 2]]) == 10\n assert candidate(grid = [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]]) == 20\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 10\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], [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, 2, 2, 2, 2, 2, 2, 2]]) == 32\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 20\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 6\n assert candidate(grid = [[0, 0, 1, 1, 2, 2, 3, 3], [0, 0, 1, 1, 2, 2, 3, 3], [0, 0, 1, 1, 2, 2, 3, 3]]) == 12\n assert candidate(grid = [[9, 8, 7, 6, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]]) == 8\n assert candidate(grid = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]]) == 18\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 20\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]) == 0\n", "comparison": "exact"}, "public_tests": ["[[1,0,2],[1,0,2]]", "[[1,1,1],[0,0,0]]", "[[1],[2],[3]]"], "hints": [], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:50+00:00", "tests_total": 108, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations(grid)", "container": null, "callable": "minimum_operations", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3123, "task_id": "find-edges-in-shortest-paths", "difficulty": "Hard", "problem_description": "You are given an undirected weighted graph of n nodes numbered from 0 to n - 1. The graph consists of m edges represented by a 2D array edges, where edges[i] = [a_i, b_i, w_i] indicates that there is an edge between nodes a_i and b_i with weight w_i.\n\nConsider all the shortest paths from node 0 to node n - 1 in the graph. You need to find a boolean array answer where answer[i] is true if the edge edges[i] is part of at least one shortest path. Otherwise, answer[i] is false.\n\nReturn the array answer.\n\nNote that the graph may not be connected.\n\nExample 1:\n\nInput: n = 6, edges = [[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]\nOutput: [true,true,true,false,true,true,true,false]\nExplanation:\nThe following are all the shortest paths between nodes 0 and 5:\n- The path 0 -> 1 -> 5: The sum of weights is 4 + 1 = 5.\n- The path 0 -> 2 -> 3 -> 5: The sum of weights is 1 + 1 + 3 = 5.\n- The path 0 -> 2 -> 3 -> 1 -> 5: The sum of weights is 1 + 1 + 2 + 1 = 5.\n\nExample 2:\n\nInput: n = 4, edges = [[2,0,1],[0,1,1],[0,3,4],[3,2,2]]\nOutput: [true,false,false,true]\nExplanation:\nThere is one shortest path between nodes 0 and 3, which is the path 0 -> 2 -> 3 with the sum of weights 1 + 2 = 3.\n\nConstraints:\n\n- 2 <= n <= 5 * 10^4\n- m == edges.length\n- 1 <= m <= min(5 * 10^4, n * (n - 1) / 2)\n- 0 <= a_i, b_i < n\n- a_i != b_i\n- 1 <= w_i <= 10^5\n- There are no repeated edges.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 2, 2], [1, 2, 3], [1, 3, 2], [2, 3, 1], [2, 4, 4], [3, 4, 2]]) == [False, True, False, False, True, False, True]\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 5], [1, 2, 1], [1, 3, 4], [2, 3, 2], [3, 4, 1], [4, 5, 3], [5, 6, 2]]) == [True, False, True, False, True, True, True, True]\n assert candidate(n = 5,edges = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 4], [2, 3, 2], [3, 4, 1]]) == [True, True, True, False, True, True]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 1], [0, 3, 1], [1, 4, 1], [1, 5, 1], [2, 6, 1], [2, 7, 1], [3, 8, 1], [3, 9, 1], [4, 5, 1], [6, 7, 1], [8, 9, 1]]) == [False, False, True, False, False, False, False, False, True, False, False, False]\n assert candidate(n = 7,edges = [[0, 1, 3], [1, 2, 2], [2, 3, 1], [3, 4, 1], [4, 5, 2], [5, 6, 3]]) == [True, True, True, True, True, True]\n assert candidate(n = 5,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [0, 4, 10]]) == [True, True, True, True, True]\n assert candidate(n = 3,edges = [[0, 1, 1], [0, 2, 5], [1, 2, 2]]) == [True, False, True]\n assert candidate(n = 4,edges = [[2, 0, 1], [0, 1, 1], [0, 3, 4], [3, 2, 2]]) == [True, False, False, True]\n assert candidate(n = 6,edges = [[0, 1, 4], [0, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 1], [2, 3, 1], [3, 5, 3], [4, 5, 2]]) == [True, True, True, False, True, True, True, False]\n assert candidate(n = 3,edges = [[0, 1, 1], [1, 2, 1], [0, 2, 4]]) == [True, True, False]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 1], [1, 3, 1], [1, 4, 1], [2, 5, 1], [2, 6, 1], [3, 7, 1], [3, 8, 1], [4, 9, 1], [4, 10, 1], [5, 11, 1], [5, 12, 1], [6, 13, 1], [6, 14, 1], [7, 8, 1], [9, 10, 1], [11, 12, 1], [13, 14, 1]]) == [False, True, False, False, False, True, False, False, False, False, False, False, False, True, False, False, False, False]\n assert candidate(n = 25,edges = [[0, 1, 5], [0, 2, 5], [1, 3, 3], [1, 4, 2], [2, 5, 3], [2, 6, 4], [3, 7, 1], [3, 8, 2], [4, 9, 1], [5, 10, 2], [5, 11, 3], [6, 12, 1], [6, 13, 4], [7, 14, 1], [7, 15, 2], [8, 16, 1], [8, 17, 2], [9, 18, 2], [10, 19, 1], [10, 20, 2], [11, 21, 2], [11, 22, 1], [12, 23, 1], [12, 24, 2], [13, 23, 2], [13, 24, 3]]) == [False, True, False, False, False, True, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, True, False, False]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 2], [1, 3, 1], [1, 4, 6], [2, 5, 3], [3, 6, 2], [4, 7, 4], [5, 8, 5], [6, 9, 1], [7, 9, 3], [8, 9, 2]]) == [True, False, True, False, False, True, False, False, True, False, False]\n assert candidate(n = 15,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 5], [1, 4, 10], [2, 5, 15], [3, 6, 20], [4, 7, 25], [5, 8, 30], [6, 9, 35], [7, 10, 40], [8, 11, 45], [9, 12, 50], [10, 13, 55], [11, 14, 60], [0, 6, 65], [1, 7, 70], [2, 8, 75], [3, 9, 80], [4, 10, 85], [5, 11, 90], [6, 12, 95], [7, 13, 100], [8, 14, 105]]) == [False, True, False, False, True, False, False, True, False, False, True, False, False, True, False, False, False, False, False, False, False, False, True]\n assert candidate(n = 12,edges = [[0, 1, 3], [0, 2, 2], [1, 3, 1], [2, 4, 4], [3, 5, 2], [4, 6, 3], [5, 7, 1], [6, 8, 5], [7, 9, 2], [8, 10, 1], [9, 11, 3], [10, 11, 2], [0, 5, 7], [1, 6, 8], [2, 7, 9], [3, 8, 10], [4, 9, 11]]) == [True, False, True, False, True, False, True, False, True, False, True, False, False, False, False, False, False]\n assert candidate(n = 10,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 1], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 7, 2], [7, 8, 3], [8, 9, 2], [0, 9, 10]]) == [False, False, False, False, False, False, False, False, False, True]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [1, 4, 2], [2, 5, 3], [2, 6, 4], [3, 7, 2], [3, 8, 3], [4, 9, 1], [4, 10, 4], [5, 11, 2], [5, 12, 3], [6, 13, 4], [6, 14, 5], [7, 8, 1], [9, 10, 2], [11, 12, 3], [13, 14, 4]]) == [False, True, False, False, False, True, False, False, False, False, False, False, False, True, False, False, False, False]\n assert candidate(n = 10,edges = [[0, 1, 2], [0, 2, 4], [0, 3, 1], [1, 4, 3], [1, 5, 1], [2, 3, 2], [2, 6, 5], [3, 7, 1], [4, 8, 2], [5, 8, 3], [6, 9, 4], [7, 9, 3], [8, 9, 1]]) == [False, False, True, False, False, False, False, True, False, False, False, True, False]\n assert candidate(n = 7,edges = [[0, 1, 5], [0, 2, 10], [1, 2, 1], [1, 3, 4], [2, 3, 2], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 0, 3]]) == [False, False, False, False, False, False, False, False, True]\n assert candidate(n = 12,edges = [[0, 1, 2], [0, 2, 4], [1, 3, 3], [1, 4, 1], [2, 4, 2], [2, 5, 5], [3, 6, 2], [4, 6, 1], [4, 7, 4], [5, 8, 3], [6, 9, 2], [7, 10, 1], [8, 10, 3], [9, 11, 2], [10, 11, 1]]) == [True, False, False, True, False, False, False, True, False, False, True, False, False, True, False]\n assert candidate(n = 7,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 2, 4], [1, 3, 5], [2, 4, 6], [2, 5, 7], [3, 4, 8], [3, 5, 9], [4, 6, 10], [5, 6, 11]]) == [False, True, False, False, False, True, False, False, False, True, False]\n assert candidate(n = 7,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [2, 3, 1], [3, 4, 4], [4, 5, 2], [5, 6, 1], [2, 4, 6], [0, 5, 7], [1, 6, 8]]) == [False, False, False, False, False, False, True, False, True, False]\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 4], [1, 5, 5], [2, 6, 6], [2, 7, 7], [3, 8, 8], [4, 5, 9], [4, 6, 10], [5, 7, 11], [6, 8, 12], [7, 8, 13]]) == [False, False, True, False, False, False, False, True, False, False, False, False, False]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 6], [2, 5, 4], [2, 6, 2], [3, 7, 3], [4, 8, 1], [5, 8, 3], [6, 9, 5], [7, 9, 2], [8, 9, 4]]) == [False, True, False, False, False, True, False, False, False, True, False, False]\n assert candidate(n = 8,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 2], [1, 4, 1], [2, 3, 3], [2, 4, 7], [3, 5, 1], [4, 6, 4], [5, 7, 2], [6, 7, 1]]) == [False, True, False, False, True, False, True, False, True, False]\n assert candidate(n = 8,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 5], [1, 4, 15], [2, 3, 20], [2, 5, 10], [3, 6, 15], [4, 6, 5], [5, 7, 5], [6, 7, 10]]) == [False, True, False, False, False, True, False, False, True, False]\n assert candidate(n = 10,edges = [[0, 1, 3], [0, 2, 1], [1, 3, 2], [1, 4, 4], [2, 5, 2], [3, 6, 1], [4, 6, 1], [5, 7, 2], [6, 8, 3], [7, 9, 1], [8, 9, 2]]) == [False, True, False, False, True, False, False, True, False, True, False]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 2], [3, 6, 5], [4, 7, 1], [5, 8, 3], [6, 9, 4], [7, 10, 2], [8, 11, 1], [9, 12, 3], [10, 13, 4], [11, 14, 2], [12, 14, 5]]) == [False, True, False, False, True, False, False, True, False, False, True, False, False, True, False]\n assert candidate(n = 7,edges = [[0, 1, 5], [0, 2, 3], [1, 2, 2], [1, 3, 6], [2, 3, 4], [2, 4, 3], [3, 4, 1], [3, 5, 2], [4, 5, 3], [4, 6, 4], [5, 6, 2]]) == [False, True, False, False, False, True, False, False, False, True, False]\n assert candidate(n = 8,edges = [[0, 1, 5], [0, 2, 10], [1, 3, 2], [1, 4, 3], [2, 3, 1], [2, 5, 4], [3, 6, 3], [4, 6, 2], [5, 6, 1], [6, 7, 5]]) == [True, False, True, True, False, False, True, True, False, True]\n assert candidate(n = 20,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 4], [1, 4, 2], [2, 5, 1], [2, 6, 3], [3, 7, 2], [3, 8, 4], [4, 9, 2], [5, 10, 3], [5, 11, 1], [6, 12, 4], [6, 13, 1], [7, 14, 2], [7, 15, 3], [8, 16, 1], [8, 17, 4], [9, 18, 2], [10, 19, 3], [11, 12, 2], [13, 14, 1], [15, 16, 2], [17, 18, 3], [18, 19, 4]]) == [False, True, False, False, True, False, False, False, False, True, False, False, False, False, False, False, False, False, True, False, False, False, False, False]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 1], [2, 5, 2], [3, 6, 3], [4, 7, 1], [5, 8, 2], [6, 9, 3], [7, 8, 1], [7, 9, 2], [8, 9, 3]]) == [True, False, False, True, False, False, True, False, False, False, True, False]\n assert candidate(n = 11,edges = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 4], [1, 4, 5], [2, 5, 2], [2, 6, 3], [3, 6, 1], [3, 7, 4], [4, 8, 2], [4, 9, 3], [5, 9, 1], [5, 10, 2], [6, 10, 3], [7, 8, 1], [8, 9, 2], [8, 10, 1], [9, 10, 2]]) == [True, True, True, False, False, True, False, False, False, False, False, False, True, False, False, False, False, False]\n assert candidate(n = 12,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 3, 6], [2, 4, 7], [3, 5, 8], [4, 5, 9], [5, 6, 10], [5, 7, 11], [5, 8, 12], [6, 9, 13], [7, 10, 14], [8, 11, 15], [9, 10, 16], [10, 11, 17]]) == [True, False, True, False, False, False, True, False, False, False, True, False, False, True, False, False]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 5, 5], [2, 6, 6], [3, 7, 7], [4, 8, 8], [5, 9, 9], [6, 9, 9], [7, 8, 10]]) == [False, True, False, False, True, False, False, False, True, False, False]\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 1], [2, 4, 1], [3, 4, 1], [4, 5, 2], [5, 6, 1], [6, 7, 2], [4, 7, 3]]) == [True, False, False, True, False, False, False, False, False, True]\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 1], [0, 3, 1], [1, 4, 1], [1, 5, 1], [2, 4, 1], [2, 6, 1], [3, 5, 1], [3, 7, 1], [4, 8, 1], [5, 8, 1], [6, 9, 1], [7, 9, 1], [8, 9, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1]]) == [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True]\n assert candidate(n = 20,edges = [[0, 1, 2], [0, 2, 4], [1, 3, 1], [1, 4, 3], [2, 5, 2], [2, 6, 4], [3, 7, 1], [4, 8, 1], [5, 9, 2], [6, 10, 1], [7, 11, 3], [8, 12, 2], [9, 13, 3], [10, 14, 1], [11, 15, 2], [12, 16, 1], [13, 17, 3], [14, 18, 2], [15, 19, 1], [16, 18, 2], [17, 19, 3]]) == [True, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False]\n assert candidate(n = 7,edges = [[0, 1, 1], [0, 2, 2], [1, 2, 1], [1, 3, 3], [2, 3, 1], [2, 4, 2], [3, 4, 1], [3, 5, 3], [4, 5, 1], [4, 6, 2], [5, 6, 1]]) == [True, True, True, False, True, True, True, False, True, True, True]\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [0, 4, 4], [1, 5, 1], [2, 5, 2], [3, 5, 3], [4, 5, 4], [5, 6, 5], [5, 7, 6], [5, 8, 7], [6, 8, 8], [7, 8, 9]]) == [True, False, False, False, True, False, False, False, False, False, True, False, False]\n assert candidate(n = 12,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 5, 6], [2, 6, 7], [3, 7, 8], [3, 8, 9], [4, 8, 10], [4, 9, 11], [5, 10, 12], [5, 11, 13], [6, 10, 14], [6, 11, 15], [7, 11, 16], [8, 11, 17], [9, 11, 18]]) == [False, True, False, False, True, False, False, False, False, False, False, True, False, False, False, False, False]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [2, 4, 1], [3, 5, 4], [4, 6, 2], [5, 7, 3], [6, 8, 1], [7, 9, 2], [8, 9, 4]]) == [False, True, False, True, False, True, False, True, False, True]\n assert candidate(n = 8,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 1], [1, 4, 4], [2, 5, 2], [3, 6, 3], [4, 7, 2], [5, 6, 1], [6, 7, 4]]) == [True, False, False, True, False, False, True, False, False]\n assert candidate(n = 9,edges = [[0, 1, 2], [0, 2, 1], [0, 3, 3], [1, 4, 2], [1, 5, 4], [2, 4, 1], [2, 6, 3], [3, 7, 2], [3, 8, 1], [4, 5, 2], [5, 6, 3], [6, 7, 2], [7, 8, 1], [8, 5, 1]]) == [False, False, True, False, False, False, False, False, True, False, False, False, False, False]\n assert candidate(n = 12,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 5, 2], [5, 6, 2], [6, 7, 2], [7, 8, 2], [8, 9, 2], [9, 10, 2], [10, 11, 2]]) == [True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 12,edges = [[0, 1, 3], [0, 2, 5], [0, 3, 4], [1, 4, 2], [1, 5, 6], [2, 4, 3], [2, 6, 4], [3, 7, 5], [3, 8, 7], [4, 9, 2], [5, 9, 1], [6, 9, 3], [7, 10, 2], [8, 10, 3], [9, 11, 2]]) == [True, False, False, True, False, False, False, False, False, True, False, False, False, False, True]\n assert candidate(n = 8,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 4], [1, 4, 6], [2, 3, 3], [2, 4, 5], [3, 5, 2], [4, 5, 1], [5, 6, 7], [5, 7, 8], [6, 7, 9]]) == [False, True, False, False, True, False, True, False, False, True, False]\n assert candidate(n = 7,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 1], [2, 4, 1], [2, 5, 4], [3, 6, 3], [4, 6, 2], [5, 6, 1]]) == [False, True, False, False, True, False, False, True, False]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 2], [1, 3, 3], [1, 4, 7], [2, 3, 1], [2, 4, 6], [3, 5, 4], [3, 6, 2], [4, 7, 5], [5, 8, 3], [6, 8, 2], [7, 9, 1], [8, 9, 4]]) == [False, True, False, False, True, False, False, True, False, False, True, False, True]\n assert candidate(n = 20,edges = [[0, 1, 10], [0, 2, 20], [1, 2, 5], [1, 3, 15], [2, 3, 10], [2, 4, 20], [3, 4, 5], [3, 5, 15], [4, 5, 10], [4, 6, 20], [5, 6, 5], [5, 7, 15], [6, 7, 10], [6, 8, 20], [7, 8, 5], [7, 9, 15], [8, 9, 10], [8, 10, 20], [9, 10, 5], [9, 11, 15], [10, 11, 10], [10, 12, 20], [11, 12, 5], [11, 13, 15], [12, 13, 10], [12, 14, 20], [13, 14, 5], [14, 15, 10], [14, 16, 20], [15, 16, 5], [15, 17, 15], [16, 17, 10], [16, 18, 20], [17, 18, 5], [17, 19, 15], [18, 19, 10]]) == [True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, False, True, True, True, False, True, True, True]\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [1, 4, 2], [2, 5, 1], [2, 6, 2], [3, 7, 1], [4, 7, 2], [5, 8, 1], [6, 8, 2], [7, 8, 1]]) == [True, True, True, False, True, False, True, False, True, False, True]\n assert candidate(n = 12,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 2], [1, 4, 8], [2, 5, 3], [3, 6, 4], [4, 7, 3], [5, 8, 2], [6, 9, 5], [7, 10, 4], [8, 11, 3], [9, 11, 2]]) == [False, True, False, False, True, False, False, True, False, False, True, False]\n assert candidate(n = 30,edges = [[0, 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, 25, 25], [25, 26, 26], [26, 27, 27], [27, 28, 28], [28, 29, 29], [0, 29, 100]]) == [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True]\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 4], [1, 4, 6], [2, 4, 5], [2, 5, 3], [3, 5, 1], [3, 6, 2], [4, 6, 3], [5, 6, 4]]) == [True, False, False, True, False, False, False, False, True, False, False]\n assert candidate(n = 8,edges = [[0, 1, 4], [0, 2, 3], [1, 3, 2], [1, 4, 5], [2, 5, 1], [3, 6, 3], [4, 6, 2], [5, 7, 4], [6, 7, 1], [0, 3, 6], [1, 2, 7]]) == [False, True, False, False, True, False, False, True, False, False, False]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [1, 4, 3], [2, 5, 2], [2, 6, 4], [3, 7, 1], [4, 8, 1], [5, 9, 2], [6, 10, 1], [7, 11, 3], [8, 12, 2], [9, 13, 3], [10, 14, 1], [11, 12, 2], [12, 13, 1], [13, 14, 2]]) == [False, True, False, False, False, True, False, False, False, True, False, False, False, True, False, False, False]\n assert candidate(n = 15,edges = [[0, 1, 10], [0, 2, 15], [1, 2, 5], [1, 3, 20], [2, 3, 10], [2, 4, 15], [3, 4, 5], [3, 5, 25], [4, 5, 10], [4, 6, 15], [5, 6, 5], [5, 7, 20], [6, 7, 10], [6, 8, 15], [7, 8, 5], [7, 9, 25], [8, 9, 10], [8, 10, 15], [9, 10, 5], [9, 11, 20], [10, 11, 10], [10, 12, 15], [11, 12, 5], [11, 13, 20], [12, 13, 10], [12, 14, 15], [13, 14, 5]]) == [True, True, True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, True, False, True, True, True]\n assert candidate(n = 7,edges = [[0, 1, 10], [0, 2, 5], [0, 3, 20], [1, 4, 2], [2, 4, 15], [2, 5, 1], [3, 6, 5], [4, 6, 10], [5, 6, 2]]) == [False, True, False, False, False, True, False, False, True]\n assert candidate(n = 8,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 3, 1], [2, 4, 6], [3, 5, 7], [3, 6, 8], [4, 5, 9], [4, 6, 10], [5, 7, 11], [6, 7, 12]]) == [False, True, False, False, True, False, True, False, False, False, True, False]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 2, 2], [1, 3, 6], [2, 3, 1], [2, 4, 4], [3, 4, 2], [3, 5, 3], [4, 5, 1], [5, 6, 2], [6, 7, 3], [7, 8, 4], [8, 9, 5], [6, 9, 7]]) == [False, True, False, False, True, False, True, True, True, True, False, False, False, True]\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 4], [1, 2, 2], [1, 3, 5], [2, 3, 1], [2, 4, 2], [3, 4, 3], [3, 5, 6], [4, 5, 1], [4, 6, 4], [5, 6, 2], [5, 7, 3], [6, 7, 1]]) == [True, False, True, False, False, True, False, False, True, False, True, True, True]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 1], [1, 5, 2], [2, 6, 1], [2, 7, 2], [3, 8, 1], [3, 9, 2], [4, 10, 1], [5, 11, 1], [6, 12, 1], [7, 13, 1], [8, 14, 1], [9, 14, 2], [10, 11, 1], [11, 12, 1], [12, 13, 1], [13, 14, 1]]) == [False, False, True, False, False, False, False, True, False, False, False, False, False, True, False, False, False, False, False]\n assert candidate(n = 15,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [1, 4, 1], [2, 4, 2], [2, 5, 2], [3, 6, 1], [4, 6, 1], [4, 7, 1], [5, 8, 2], [6, 9, 1], [7, 9, 1], [8, 10, 2], [9, 11, 1], [10, 12, 1], [11, 13, 2], [12, 13, 1], [13, 14, 1]]) == [True, False, True, True, False, False, True, True, True, False, True, True, False, True, False, True, False, True]\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 10], [1, 3, 3], [1, 4, 7], [2, 3, 2], [2, 5, 8], [3, 4, 1], [3, 6, 4], [4, 7, 6], [5, 6, 1], [6, 7, 2], [6, 8, 3], [7, 9, 5], [8, 9, 1]]) == [True, False, True, False, False, False, False, True, False, False, False, True, False, True]\n assert candidate(n = 7,edges = [[0, 1, 10], [0, 2, 20], [0, 3, 30], [1, 4, 10], [2, 4, 10], [3, 4, 10], [4, 5, 10], [4, 6, 20], [5, 6, 10]]) == [True, False, False, True, False, False, True, True, True]\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 1], [2, 4, 2], [2, 5, 2], [3, 6, 4], [4, 6, 3], [4, 7, 2], [5, 8, 3], [6, 8, 2], [7, 8, 1]]) == [True, False, False, True, False, False, False, False, True, False, False, True]\n assert candidate(n = 6,edges = [[0, 1, 1], [0, 2, 1], [1, 3, 1], [1, 4, 1], [2, 3, 1], [2, 4, 1], [3, 5, 1], [4, 5, 1]]) == [True, True, True, True, True, True, True, True]\n", "comparison": "exact"}, "public_tests": ["6\n[[0,1,4],[0,2,1],[1,3,2],[1,4,3],[1,5,1],[2,3,1],[3,5,3],[4,5,2]]", "4\n[[2,0,1],[0,1,1],[0,3,4],[3,2,2]]"], "hints": ["Find all the shortest paths starting from nodes 0 and n - 1 to all other nodes.", "How to use the above calculated shortest paths to check if an edge is part of at least one shortest path from 0 to n - 1?"], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().findAnswer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:53+00:00", "tests_total": 67, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "graph", "heap-priority-queue", "shortest-path"]}, "language": "ruby", "interface": {"raw_signature": "def find_answer(n, edges)", "container": null, "callable": "find_answer", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3127, "task_id": "make-a-square-with-the-same-color", "difficulty": "Easy", "problem_description": "You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color, and character 'B' represents the black color.\n\nYour task is to change the color of at most one cell so that the matrix has a 2 x 2 square where all cells are of the same color.\n\nReturn true if it is possible to create a 2 x 2 square of the same color, otherwise, return false.\n\nExample 1:\n\nInput: grid = [[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"B\"]]\nOutput: true\nExplanation:\nIt can be done by changing the color of the grid[0][2].\n\nExample 2:\n\nInput: grid = [[\"B\",\"W\",\"B\"],[\"W\",\"B\",\"W\"],[\"B\",\"W\",\"B\"]]\nOutput: false\nExplanation:\nIt cannot be done by changing at most one cell.\n\nExample 3:\n\nInput: grid = [[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"W\"]]\nOutput: true\nExplanation:\nThe grid already contains a 2 x 2 square of the same color.\n\nConstraints:\n\n- grid.length == 3\n- grid[i].length == 3\n- grid[i][j] is either 'W' or 'B'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [['B', 'W', 'B'], ['W', 'B', 'W'], ['B', 'W', 'B']]) == False\n assert candidate(grid = [['B', 'B', 'W'], ['B', 'B', 'W'], ['B', 'B', 'W']]) == True\n assert candidate(grid = [['B', 'W', 'B'], ['B', 'W', 'W'], ['B', 'W', 'B']]) == True\n assert candidate(grid = [['B', 'B', 'B'], ['B', 'W', 'B'], ['B', 'B', 'B']]) == True\n assert candidate(grid = [['W', 'W', 'B'], ['W', 'W', 'B'], ['W', 'W', 'B']]) == True\n assert candidate(grid = [['W', 'W', 'W'], ['W', 'B', 'W'], ['W', 'W', 'W']]) == True\n assert candidate(grid = [['B', 'W', 'W'], ['W', 'W', 'W'], ['W', 'W', 'B']]) == True\n assert candidate(grid = [['W', 'B', 'W'], ['B', 'W', 'B'], ['W', 'B', 'W']]) == False\n assert candidate(grid = [['B', 'W', 'B'], ['B', 'W', 'W'], ['B', 'W', 'W']]) == True\n assert candidate(grid = [['W', 'B', 'B'], ['B', 'B', 'B'], ['B', 'B', 'W']]) == True\n", "comparison": "exact"}, "public_tests": ["[[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"B\"]]", "[[\"B\",\"W\",\"B\"],[\"W\",\"B\",\"W\"],[\"B\",\"W\",\"B\"]]", "[[\"B\",\"W\",\"B\"],[\"B\",\"W\",\"W\"],[\"B\",\"W\",\"W\"]]"], "hints": ["It is impossible to create 2 x 2 square with the same color by changing the color of at most one cell when the number of ‘W' or 'B’ in all squares is 2."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().canMakeSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:13:57+00:00", "tests_total": 10, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "matrix", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def can_make_square(grid)", "container": null, "callable": "can_make_square", "parameters": [{"name": "grid", "type": "Character[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3128, "task_id": "right-triangles", "difficulty": "Medium", "problem_description": "You are given a 2D boolean matrix grid.\n\nA collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each other.\n\nReturn an integer that is the number of right triangles that can be made with 3 elements of grid such that all of them have a value of 1.\n\nExample 1:\n\n0 | 1 | 0\n0 | 1 | 1\n0 | 1 | 0\n\n0 | 1 | 0\n0 | 1 | 1\n0 | 1 | 0\n\n0 | 1 | 0\n0 | 1 | 1\n0 | 1 | 0\n\nInput: grid = [[0,1,0],[0,1,1],[0,1,0]]\nOutput: 2\nExplanation:\nThere are two right triangles with elements of the value 1. Notice that the blue ones do not form a right triangle because the 3 elements are in the same column.\n\nExample 2:\n\n1 | 0 | 0 | 0\n0 | 1 | 0 | 1\n1 | 0 | 0 | 0\n\nInput: grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]]\nOutput: 0\nExplanation:\nThere are no right triangles with elements of the value 1. Notice that the blue ones do not form a right triangle.\n\nExample 3:\n\n1 | 0 | 1\n1 | 0 | 0\n1 | 0 | 0\n\n1 | 0 | 1\n1 | 0 | 0\n1 | 0 | 0\n\nInput: grid = [[1,0,1],[1,0,0],[1,0,0]]\nOutput: 2\nExplanation:\nThere are two right triangles with elements of the value 1.\n\nConstraints:\n\n- 1 <= grid.length <= 1000\n- 1 <= grid[i].length <= 1000\n- 0 <= grid[i][j] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 36\n assert candidate(grid = [[0, 1, 0], [0, 1, 1], [0, 1, 0]]) == 2\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 8\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 1], [1, 0, 0], [1, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 0, 1], [1, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1]]) == 8\n assert candidate(grid = [[0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1]]) == 18\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1]]) == 5\n assert candidate(grid = [[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, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 144\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]]) == 40\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 72\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]]) == 288\n assert candidate(grid = [[0, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [1, 0, 0, 1, 0]]) == 18\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]) == 60\n assert candidate(grid = [[1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1]]) == 39\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [0, 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], [1, 0, 0, 0, 1, 0, 1]]) == 109\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, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 4\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) == 24\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1]]) == 12\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 0]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 0, 1]]) == 28\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[1, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 1]]) == 10\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 0, 0, 1], [1, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 82\n assert candidate(grid = [[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]]) == 24\n assert candidate(grid = [[1, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 1, 0, 0, 1], [0, 0, 1, 0, 1, 0, 0], [1, 0, 0, 0, 0, 1, 0]]) == 8\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], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1]]) == 180\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 48\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1]]) == 44\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0]]) == 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], [1, 1, 1, 1, 1]]) == 400\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 0, 1, 1, 0, 1], [1, 0, 1, 1, 0, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1]]) == 296\n assert candidate(grid = [[0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1]]) == 28\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 160\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 0, 0, 1]]) == 8\n assert candidate(grid = [[1, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 1]]) == 8\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == 36\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 60\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [1, 1, 1, 1], [0, 1, 1, 0], [0, 0, 0, 0]]) == 20\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [1, 0, 0, 0, 1]]) == 4\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, 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]]) == 192\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 0, 0], [0, 1, 1, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]]) == 7\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1]]) == 12\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0], [1, 0, 0, 0, 0, 1]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1]]) == 36\n assert candidate(grid = [[0, 0, 1, 1, 0], [0, 1, 0, 0, 1], [1, 0, 0, 1, 0], [1, 0, 1, 0, 0], [0, 1, 0, 0, 1]]) == 10\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 144\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0], [1, 0, 0, 0, 0, 1]]) == 8\n assert candidate(grid = [[0, 0, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 0, 0, 1], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0]]) == 10\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == 12\n assert candidate(grid = [[1, 0, 0, 1], [0, 1, 1, 0], [1, 0, 0, 1], [0, 1, 1, 0]]) == 8\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 800\n assert candidate(grid = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 1]]) == 8\n assert candidate(grid = [[1, 1, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 50\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0, 1]]) == 12\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, 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, 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]]) == 544\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1]]) == 108\n assert candidate(grid = [[1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 36\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 1, 0, 0], [0, 0, 0, 1, 0], [1, 0, 0, 0, 1]]) == 7\n", "comparison": "exact"}, "public_tests": ["[[0,1,0],[0,1,1],[0,1,0]]", "[[1,0,0,0],[0,1,0,1],[1,0,0,0]]", "[[1,0,1],[1,0,0],[1,0,0]]"], "hints": ["If grid[x][y] is 1, it can form a right triangle with an element of grid with value 1 in the same row and an element of grid with value 1 in the same column.", "So we just need to count the number of 1s in each row and column.", "For each x, y with grid[x][y] = 1 if there are row[x] 1s in the row x and col[y] 1s in column y, the answer should be added by (row[x] - 1) * (col[y] - 1)."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().numberOfRightTriangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:00+00:00", "tests_total": 67, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "math", "combinatorics", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_right_triangles(grid)", "container": null, "callable": "number_of_right_triangles", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3129, "task_id": "find-all-possible-stable-binary-arrays-i", "difficulty": "Medium", "problem_description": "You are given 3 positive integers num_zeros, num_ones, and limit.\n\nA binary array arr is called stable if:\n\n- The number of occurrences of 0 in arr is exactly num_zeros.\n- The number of occurrences of 1 in arr is exactly num_ones.\n- Each subarray of arr with a size greater than limit must contain at least one occurrence of both 0 and 1.\n\nReturn an integer denoting the total number of stable binary arrays.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: zero = 1, one = 1, limit = 2\nOutput: 2\nExplanation:\nThe two possible stable binary arrays are [1,0] and [0,1], as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.\n\nExample 2:\n\nInput: zero = 1, one = 2, limit = 1\nOutput: 1\nExplanation:\nThe only possible stable binary array is [1,0,1].\nNote that the binary arrays [1,1,0] and [0,1,1] have subarrays of length 2 with identical elements, hence, they are not stable.\n\nExample 3:\n\nInput: zero = 3, one = 3, limit = 2\nOutput: 14\nExplanation:\nAll the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].\n\nConstraints:\n\n- 1 <= zero, one, limit <= 200\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(zero = 3,one = 5,limit = 3) == 40\n assert candidate(zero = 5,one = 5,limit = 4) == 242\n assert candidate(zero = 5,one = 5,limit = 2) == 84\n assert candidate(zero = 1,one = 1,limit = 1) == 2\n assert candidate(zero = 2,one = 2,limit = 3) == 6\n assert candidate(zero = 1,one = 5,limit = 1) == 0\n assert candidate(zero = 200,one = 200,limit = 200) == 587893473\n assert candidate(zero = 4,one = 4,limit = 2) == 34\n assert candidate(zero = 5,one = 4,limit = 2) == 45\n assert candidate(zero = 3,one = 4,limit = 2) == 18\n assert candidate(zero = 2,one = 3,limit = 3) == 10\n assert candidate(zero = 10,one = 10,limit = 5) == 165114\n assert candidate(zero = 4,one = 4,limit = 4) == 70\n assert candidate(zero = 2,one = 2,limit = 2) == 6\n assert candidate(zero = 6,one = 3,limit = 2) == 10\n assert candidate(zero = 1,one = 1,limit = 2) == 2\n assert candidate(zero = 2,one = 5,limit = 2) == 3\n assert candidate(zero = 4,one = 5,limit = 3) == 99\n assert candidate(zero = 3,one = 3,limit = 2) == 14\n assert candidate(zero = 5,one = 5,limit = 3) == 194\n assert candidate(zero = 7,one = 7,limit = 6) == 3418\n assert candidate(zero = 4,one = 3,limit = 2) == 18\n assert candidate(zero = 20,one = 20,limit = 10) == 431683431\n assert candidate(zero = 2,one = 3,limit = 2) == 7\n assert candidate(zero = 1,one = 2,limit = 1) == 1\n assert candidate(zero = 3,one = 4,limit = 3) == 31\n assert candidate(zero = 6,one = 6,limit = 5) == 912\n assert candidate(zero = 3,one = 2,limit = 2) == 7\n assert candidate(zero = 100,one = 100,limit = 50) == 375840050\n assert candidate(zero = 190,one = 10,limit = 2) == 0\n assert candidate(zero = 180,one = 120,limit = 15) == 662485902\n assert candidate(zero = 190,one = 10,limit = 5) == 0\n assert candidate(zero = 10,one = 15,limit = 5) == 2249276\n assert candidate(zero = 120,one = 180,limit = 15) == 662485902\n assert candidate(zero = 100,one = 150,limit = 5) == 357829666\n assert candidate(zero = 175,one = 125,limit = 30) == 482940468\n assert candidate(zero = 10,one = 20,limit = 2) == 66\n assert candidate(zero = 100,one = 200,limit = 10) == 796458380\n assert candidate(zero = 100,one = 50,limit = 15) == 814679806\n assert candidate(zero = 100,one = 50,limit = 2) == 1326\n assert candidate(zero = 200,one = 1,limit = 1) == 0\n assert candidate(zero = 100,one = 150,limit = 30) == 462327057\n assert candidate(zero = 100,one = 1,limit = 2) == 0\n assert candidate(zero = 200,one = 100,limit = 25) == 672942188\n assert candidate(zero = 15,one = 15,limit = 2) == 860142\n assert candidate(zero = 190,one = 10,limit = 4) == 0\n assert candidate(zero = 3,one = 7,limit = 4) == 80\n assert candidate(zero = 50,one = 50,limit = 1) == 2\n assert candidate(zero = 200,one = 200,limit = 2) == 609176335\n assert candidate(zero = 150,one = 50,limit = 10) == 701105470\n assert candidate(zero = 200,one = 1,limit = 200) == 201\n assert candidate(zero = 5,one = 4,limit = 4) == 121\n assert candidate(zero = 20,one = 180,limit = 4) == 0\n assert candidate(zero = 199,one = 199,limit = 199) == 387943228\n assert candidate(zero = 7,one = 3,limit = 4) == 80\n assert candidate(zero = 50,one = 50,limit = 2) == 642129773\n assert candidate(zero = 100,one = 100,limit = 2) == 572804009\n assert candidate(zero = 50,one = 50,limit = 10) == 430250984\n assert candidate(zero = 2,one = 100,limit = 3) == 0\n assert candidate(zero = 150,one = 50,limit = 1) == 0\n assert candidate(zero = 20,one = 10,limit = 4) == 3741210\n assert candidate(zero = 150,one = 100,limit = 50) == 746397052\n assert candidate(zero = 101,one = 100,limit = 3) == 922524303\n assert candidate(zero = 10,one = 190,limit = 2) == 0\n assert candidate(zero = 150,one = 150,limit = 5) == 670611061\n assert candidate(zero = 1,one = 200,limit = 200) == 201\n assert candidate(zero = 199,one = 200,limit = 100) == 287809711\n assert candidate(zero = 150,one = 200,limit = 75) == 592136303\n assert candidate(zero = 200,one = 200,limit = 10) == 346661055\n assert candidate(zero = 4,one = 4,limit = 3) == 62\n assert candidate(zero = 200,one = 199,limit = 100) == 287809711\n assert candidate(zero = 150,one = 120,limit = 10) == 860251283\n assert candidate(zero = 150,one = 150,limit = 10) == 966001232\n assert candidate(zero = 15,one = 15,limit = 4) == 77607590\n assert candidate(zero = 100,one = 100,limit = 200) == 407336795\n assert candidate(zero = 1,one = 200,limit = 1) == 0\n assert candidate(zero = 150,one = 150,limit = 1) == 2\n assert candidate(zero = 15,one = 10,limit = 5) == 2249276\n assert candidate(zero = 150,one = 5,limit = 10) == 0\n assert candidate(zero = 190,one = 10,limit = 10) == 0\n assert candidate(zero = 20,one = 20,limit = 3) == 702925689\n assert candidate(zero = 10,one = 20,limit = 1) == 0\n assert candidate(zero = 1,one = 1,limit = 200) == 2\n assert candidate(zero = 200,one = 100,limit = 10) == 796458380\n assert candidate(zero = 80,one = 20,limit = 5) == 666262799\n assert candidate(zero = 100,one = 101,limit = 3) == 922524303\n assert candidate(zero = 150,one = 50,limit = 8) == 139177940\n assert candidate(zero = 20,one = 20,limit = 6) == 140887996\n assert candidate(zero = 50,one = 50,limit = 200) == 538992043\n assert candidate(zero = 100,one = 100,limit = 10) == 474184186\n assert candidate(zero = 10,one = 10,limit = 1) == 2\n assert candidate(zero = 20,one = 20,limit = 5) == 89895606\n assert candidate(zero = 50,one = 50,limit = 20) == 644307023\n assert candidate(zero = 180,one = 20,limit = 4) == 0\n assert candidate(zero = 199,one = 199,limit = 198) == 387942830\n assert candidate(zero = 199,one = 199,limit = 100) == 541514263\n assert candidate(zero = 50,one = 150,limit = 2) == 0\n assert candidate(zero = 100,one = 10,limit = 3) == 0\n assert candidate(zero = 100,one = 50,limit = 150) == 713790273\n assert candidate(zero = 180,one = 150,limit = 60) == 850799592\n assert candidate(zero = 100,one = 100,limit = 1) == 2\n assert candidate(zero = 120,one = 80,limit = 6) == 885202743\n assert candidate(zero = 5,one = 150,limit = 10) == 0\n assert candidate(zero = 200,one = 200,limit = 3) == 894330409\n assert candidate(zero = 15,one = 15,limit = 3) == 24857864\n assert candidate(zero = 10,one = 190,limit = 10) == 0\n assert candidate(zero = 1,one = 100,limit = 2) == 0\n assert candidate(zero = 100,one = 100,limit = 5) == 20078082\n assert candidate(zero = 180,one = 20,limit = 200) == 680498188\n assert candidate(zero = 180,one = 20,limit = 2) == 0\n assert candidate(zero = 10,one = 15,limit = 4) == 1360424\n assert candidate(zero = 50,one = 150,limit = 5) == 245337662\n assert candidate(zero = 125,one = 175,limit = 80) == 30909440\n assert candidate(zero = 100,one = 1,limit = 50) == 1\n assert candidate(zero = 10,one = 190,limit = 5) == 0\n assert candidate(zero = 150,one = 50,limit = 5) == 245337662\n assert candidate(zero = 80,one = 120,limit = 9) == 674949759\n assert candidate(zero = 50,one = 150,limit = 10) == 701105470\n assert candidate(zero = 15,one = 10,limit = 4) == 1360424\n assert candidate(zero = 150,one = 100,limit = 5) == 357829666\n assert candidate(zero = 150,one = 50,limit = 2) == 0\n assert candidate(zero = 100,one = 100,limit = 20) == 294133308\n assert candidate(zero = 50,one = 100,limit = 10) == 10967566\n assert candidate(zero = 150,one = 200,limit = 199) == 777184933\n assert candidate(zero = 50,one = 150,limit = 7) == 536640420\n assert candidate(zero = 5,one = 200,limit = 4) == 0\n assert candidate(zero = 50,one = 200,limit = 20) == 192149064\n assert candidate(zero = 180,one = 180,limit = 50) == 911610311\n", "comparison": "exact"}, "public_tests": ["1\n1\n2", "1\n2\n1", "3\n3\n2"], "hints": ["Let dp[a][b][c = 0/1][d] be the number of stable arrays with exactly a 0s, b 1s and consecutive d value of c’s at the end.", "Try each case by appending a 0/1 at last to get the inductions."], "metadata": {"canonical_parameter_names": ["zero", "one", "limit"], "leetcode_dataset_entry_point": "Solution().numberOfStableArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:02+00:00", "tests_total": 128, "tests_dropped": 0, "flags": [], "topic_tags": ["dynamic-programming", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_stable_arrays(zero, one, limit)", "container": null, "callable": "number_of_stable_arrays", "parameters": [{"name": "zero", "type": "Integer"}, {"name": "one", "type": "Integer"}, {"name": "limit", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3130, "task_id": "find-all-possible-stable-binary-arrays-ii", "difficulty": "Hard", "problem_description": "You are given 3 positive integers num_zeros, num_ones, and limit.\n\nA binary array arr is called stable if:\n\n- The number of occurrences of 0 in arr is exactly num_zeros.\n- The number of occurrences of 1 in arr is exactly num_ones.\n- Each subarray of arr with a size greater than limit must contain at least one occurrence of both 0 and 1.\n\nReturn an integer denoting the total number of stable binary arrays.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: zero = 1, one = 1, limit = 2\nOutput: 2\nExplanation:\nThe two possible stable binary arrays are [1,0] and [0,1].\n\nExample 2:\n\nInput: zero = 1, one = 2, limit = 1\nOutput: 1\nExplanation:\nThe only possible stable binary array is [1,0,1].\n\nExample 3:\n\nInput: zero = 3, one = 3, limit = 2\nOutput: 14\nExplanation:\nAll the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].\n\nConstraints:\n\n- 1 <= zero, one, limit <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(zero = 5,one = 5,limit = 4) == 242\n assert candidate(zero = 100,one = 100,limit = 50) == 375840050\n assert candidate(zero = 5,one = 5,limit = 2) == 84\n assert candidate(zero = 4,one = 4,limit = 3) == 62\n assert candidate(zero = 2,one = 2,limit = 3) == 6\n assert candidate(zero = 3,one = 2,limit = 1) == 1\n assert candidate(zero = 5,one = 4,limit = 2) == 45\n assert candidate(zero = 4,one = 4,limit = 4) == 70\n assert candidate(zero = 10,one = 10,limit = 5) == 165114\n assert candidate(zero = 1,one = 1,limit = 2) == 2\n assert candidate(zero = 4,one = 5,limit = 3) == 99\n assert candidate(zero = 3,one = 3,limit = 2) == 14\n assert candidate(zero = 5,one = 5,limit = 3) == 194\n assert candidate(zero = 100,one = 100,limit = 10) == 474184186\n assert candidate(zero = 4,one = 3,limit = 4) == 35\n assert candidate(zero = 2,one = 3,limit = 2) == 7\n assert candidate(zero = 1,one = 2,limit = 1) == 1\n assert candidate(zero = 7,one = 8,limit = 4) == 5250\n assert candidate(zero = 100,one = 50,limit = 10) == 10967566\n assert candidate(zero = 75,one = 25,limit = 3) == 3276\n assert candidate(zero = 7,one = 10,limit = 4) == 12948\n assert candidate(zero = 9,one = 7,limit = 3) == 4848\n assert candidate(zero = 20,one = 15,limit = 4) == 30552957\n assert candidate(zero = 100,one = 100,limit = 100) == 407336795\n assert candidate(zero = 10,one = 15,limit = 3) == 378412\n assert candidate(zero = 9,one = 11,limit = 2) == 5344\n assert candidate(zero = 150,one = 150,limit = 25) == 469749347\n assert candidate(zero = 12,one = 9,limit = 4) == 174530\n assert candidate(zero = 10,one = 10,limit = 3) == 66486\n assert candidate(zero = 12,one = 12,limit = 10) == 2703832\n assert candidate(zero = 50,one = 50,limit = 10) == 430250984\n assert candidate(zero = 50,one = 50,limit = 5) == 256686735\n assert candidate(zero = 20,one = 10,limit = 4) == 3741210\n assert candidate(zero = 20,one = 18,limit = 6) == 378141764\n assert candidate(zero = 10,one = 5,limit = 3) == 546\n assert candidate(zero = 8,one = 6,limit = 4) == 2386\n assert candidate(zero = 20,one = 20,limit = 10) == 431683431\n assert candidate(zero = 14,one = 14,limit = 4) == 21533230\n assert candidate(zero = 15,one = 12,limit = 5) == 13147531\n assert candidate(zero = 20,one = 10,limit = 2) == 66\n assert candidate(zero = 200,one = 150,limit = 15) == 120261210\n assert candidate(zero = 150,one = 150,limit = 15) == 416993889\n assert candidate(zero = 75,one = 25,limit = 5) == 769798783\n assert candidate(zero = 15,one = 10,limit = 5) == 2249276\n assert candidate(zero = 7,one = 5,limit = 2) == 114\n assert candidate(zero = 13,one = 10,limit = 5) == 914333\n assert candidate(zero = 25,one = 25,limit = 1) == 2\n assert candidate(zero = 17,one = 15,limit = 7) == 539683360\n assert candidate(zero = 8,one = 12,limit = 2) == 1391\n assert candidate(zero = 20,one = 20,limit = 5) == 89895606\n assert candidate(zero = 12,one = 12,limit = 6) == 2555112\n assert candidate(zero = 20,one = 15,limit = 7) == 957788108\n assert candidate(zero = 8,one = 7,limit = 3) == 3296\n assert candidate(zero = 7,one = 5,limit = 1) == 0\n assert candidate(zero = 50,one = 50,limit = 4) == 507669790\n assert candidate(zero = 7,one = 8,limit = 2) == 720\n assert candidate(zero = 15,one = 20,limit = 5) == 983489078\n assert candidate(zero = 6,one = 8,limit = 2) == 300\n assert candidate(zero = 7,one = 5,limit = 4) == 664\n assert candidate(zero = 6,one = 6,limit = 1) == 2\n assert candidate(zero = 15,one = 15,limit = 5) == 119126132\n assert candidate(zero = 15,one = 8,limit = 5) == 277298\n assert candidate(zero = 9,one = 15,limit = 3) == 112216\n assert candidate(zero = 10,one = 8,limit = 3) == 16025\n assert candidate(zero = 12,one = 8,limit = 6) == 114332\n assert candidate(zero = 18,one = 12,limit = 5) == 52051889\n", "comparison": "exact"}, "public_tests": ["1\n1\n2", "1\n2\n1", "3\n3\n2"], "hints": ["Let dp[x][y][z = 0/1] be the number of stable arrays with exactly x zeros, y ones, and the last element is z. (0 or 1). dp[x][y][0] + dp[x][y][1] is the answer for given (x, y).", "If we have already placed x 1 and y 0, if we place a group of k 0, the number of ways is dp[x-k][y][1]. We can place a group with size i, where i varies from 1 to min(limit, zero - x). Similarly, we can solve by placing a group of ones.", "Speed up the calculation using prefix arrays to store the sum of dp states."], "metadata": {"canonical_parameter_names": ["zero", "one", "limit"], "leetcode_dataset_entry_point": "Solution().numberOfStableArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:05+00:00", "tests_total": 66, "tests_dropped": 0, "flags": [], "topic_tags": ["dynamic-programming", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_stable_arrays(zero, one, limit)", "container": null, "callable": "number_of_stable_arrays", "parameters": [{"name": "zero", "type": "Integer"}, {"name": "one", "type": "Integer"}, {"name": "limit", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3131, "task_id": "find-the-integer-added-to-array-i", "difficulty": "Easy", "problem_description": "You are given two arrays of equal length, nums1 and nums2.\n\nEach element in nums1 has been increased (or decreased in the case of negative) by an integer, represented by the variable x.\n\nAs a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.\n\nReturn the integer x.\n\nExample 1:\n\nInput: nums1 = [2,6,4], nums2 = [9,7,5]\nOutput: 3\nExplanation:\nThe integer added to each element of nums1 is 3.\n\nExample 2:\n\nInput: nums1 = [10], nums2 = [5]\nOutput: -5\nExplanation:\nThe integer added to each element of nums1 is -5.\n\nExample 3:\n\nInput: nums1 = [1,1,1,1], nums2 = [1,1,1,1]\nOutput: 0\nExplanation:\nThe integer added to each element of nums1 is 0.\n\nConstraints:\n\n- 1 <= nums1.length == nums2.length <= 100\n- 0 <= nums1[i], nums2[i] <= 1000\n- The test cases are generated in a way that there is an integer x such that nums1 can become equal to nums2 by adding x to each element of nums1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10],nums2 = [5]) == -5\n assert candidate(nums1 = [100, 200, 300],nums2 = [150, 250, 350]) == 50\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == 5\n assert candidate(nums1 = [7, 7, 7],nums2 = [10, 10, 10]) == 3\n assert candidate(nums1 = [50, 50, 50, 50],nums2 = [55, 55, 55, 55]) == 5\n assert candidate(nums1 = [1000, 0, 500],nums2 = [900, 1000, 400]) == 400\n assert candidate(nums1 = [500, 500, 500],nums2 = [500, 500, 500]) == 0\n assert candidate(nums1 = [5, 10, 15],nums2 = [8, 13, 18]) == 3\n assert candidate(nums1 = [0, 0, 0],nums2 = [3, 3, 3]) == 3\n assert candidate(nums1 = [2, 6, 4],nums2 = [9, 7, 5]) == 3\n assert candidate(nums1 = [999, 999, 999],nums2 = [1000, 1000, 1000]) == 1\n assert candidate(nums1 = [500, 500, 500],nums2 = [400, 400, 400]) == -100\n assert candidate(nums1 = [1000, 0, 500],nums2 = [900, 100, 400]) == 100\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 0\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == 3\n assert candidate(nums1 = [999, 999, 999, 999],nums2 = [899, 899, 899, 899]) == -100\n assert candidate(nums1 = [999, 999, 999, 999],nums2 = [994, 994, 994, 994]) == -5\n assert candidate(nums1 = [500, 500, 500, 500, 500],nums2 = [450, 450, 450, 450, 450]) == -50\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [7, 9, 11, 13, 15]) == 5\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0],nums2 = [7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(nums1 = [999, 998, 997, 996, 995],nums2 = [994, 993, 992, 991, 990]) == -5\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [20, 30, 40, 50, 60]) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900],nums2 = [90, 190, 290, 390, 490, 590, 690, 790, 890]) == -10\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60],nums2 = [15, 25, 35, 45, 55, 65]) == 5\n assert candidate(nums1 = [500, 500, 500, 500, 500],nums2 = [0, 0, 0, 0, 0]) == -500\n assert candidate(nums1 = [123, 456, 789],nums2 = [126, 459, 792]) == 3\n assert candidate(nums1 = [5, 15, 25, 35, 45],nums2 = [5, 15, 25, 35, 45]) == 0\n assert candidate(nums1 = [500, 600, 700, 800, 900],nums2 = [450, 550, 650, 750, 850]) == -50\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 11, 21, 31, 41]) == -9\n assert candidate(nums1 = [999, 998, 997, 996],nums2 = [900, 899, 898, 897]) == -99\n assert candidate(nums1 = [7, 14, 21, 28, 35],nums2 = [12, 19, 26, 33, 40]) == 5\n assert candidate(nums1 = [100, 100, 100, 100],nums2 = [200, 200, 200, 200]) == 100\n assert candidate(nums1 = [990, 980, 970, 960, 950],nums2 = [1000, 990, 980, 970, 960]) == 10\n assert candidate(nums1 = [50, 25, 12, 6, 3, 1],nums2 = [100, 75, 62, 56, 53, 51]) == 50\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30],nums2 = [10, 15, 20, 25, 30, 35]) == 5\n assert candidate(nums1 = [123, 456, 789],nums2 = [128, 461, 794]) == 5\n assert candidate(nums1 = [800, 700, 600, 500, 400, 300],nums2 = [900, 800, 700, 600, 500, 400]) == 100\n assert candidate(nums1 = [2, 4, 6, 8, 10, 12, 14],nums2 = [7, 9, 11, 13, 15, 17, 19]) == 5\n assert candidate(nums1 = [999, 998, 997, 996],nums2 = [994, 993, 992, 991]) == -5\n assert candidate(nums1 = [250, 350, 450, 550, 650],nums2 = [245, 345, 445, 545, 645]) == -5\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30],nums2 = [0, 5, 10, 15, 20, 25]) == -5\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(nums1 = [999, 998, 997, 996, 995],nums2 = [1000, 999, 998, 997, 996]) == 1\n assert candidate(nums1 = [300, 300, 300, 300, 300, 300],nums2 = [200, 200, 200, 200, 200, 200]) == -100\n assert candidate(nums1 = [7, 7, 7, 7, 7, 7],nums2 = [12, 12, 12, 12, 12, 12]) == 5\n assert candidate(nums1 = [123, 456, 789],nums2 = [130, 463, 796]) == 7\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [0, 0, 0, 0, 0]) == -5\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [50, 150, 250, 350]) == -50\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [200, 300, 400, 500, 600]) == 100\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [50, 150, 250, 350, 450]) == -50\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 10\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == -50\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [6, 8, 10, 12, 14]) == 5\n assert candidate(nums1 = [450, 440, 430],nums2 = [400, 390, 380]) == -50\n assert candidate(nums1 = [0, 2, 4, 6, 8, 10],nums2 = [100, 102, 104, 106, 108, 110]) == 100\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == -5\n assert candidate(nums1 = [100, 200, 300],nums2 = [50, 150, 250]) == -50\n assert candidate(nums1 = [0, 100, 200, 300, 400],nums2 = [1, 101, 201, 301, 401]) == 1\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [101, 101, 102, 102, 103, 103]) == 100\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 1\n assert candidate(nums1 = [999, 998, 997, 996],nums2 = [996, 995, 994, 993]) == -3\n assert candidate(nums1 = [50, 100, 150, 200, 250],nums2 = [40, 90, 140, 190, 240]) == -10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900],nums2 = [105, 205, 305, 405, 505, 605, 705, 805, 905]) == 5\n assert candidate(nums1 = [50, 100, 150, 200, 250, 300],nums2 = [50, 100, 150, 200, 250, 300]) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [0, 10, 20, 30, 40]) == -10\n assert candidate(nums1 = [50, 150, 250, 350, 450, 550],nums2 = [100, 200, 300, 400, 500, 600]) == 50\n assert candidate(nums1 = [50, 100, 150, 200, 250],nums2 = [45, 95, 145, 195, 245]) == -5\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [101, 101, 101, 101, 101]) == 100\n assert candidate(nums1 = [500, 400, 300, 200, 100],nums2 = [510, 410, 310, 210, 110]) == 10\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums1 = [200, 400, 600, 800, 1000],nums2 = [150, 350, 550, 750, 950]) == -50\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 5\n assert candidate(nums1 = [999, 998, 997, 996, 995, 994, 993],nums2 = [1000, 999, 998, 997, 996, 995, 994]) == 1\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [0, 5, 10, 15, 20]) == -5\n assert candidate(nums1 = [250, 250, 250, 250],nums2 = [300, 300, 300, 300]) == 50\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100],nums2 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 105]) == 5\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [90, 190, 290, 390, 490]) == -10\n assert candidate(nums1 = [7, 14, 21, 28, 35],nums2 = [0, 7, 14, 21, 28]) == -7\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [150, 250, 350, 450, 550]) == 50\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == 5\n assert candidate(nums1 = [250, 300, 350, 400, 450, 500],nums2 = [200, 250, 300, 350, 400, 450]) == -50\n assert candidate(nums1 = [123, 456, 789],nums2 = [223, 556, 889]) == 100\n assert candidate(nums1 = [999, 998, 997, 996],nums2 = [1000, 999, 998, 997]) == 1\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [6, 6, 7, 7, 8, 8]) == 5\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [15, 20, 25, 30, 35]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [11, 12, 13, 14, 15]) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [15, 25, 35, 45, 55]) == 5\n assert candidate(nums1 = [500, 400, 300, 200, 100],nums2 = [400, 300, 200, 100, 0]) == -100\n assert candidate(nums1 = [250, 300, 350, 400],nums2 = [300, 350, 400, 450]) == 50\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10]) == 9\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [4, 4, 5, 5, 6, 6]) == 3\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600],nums2 = [95, 195, 295, 395, 495, 595]) == -5\n assert candidate(nums1 = [0, 100, 200, 300, 400],nums2 = [100, 200, 300, 400, 500]) == 100\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 5\n assert candidate(nums1 = [999, 888, 777, 666, 555],nums2 = [1000, 889, 778, 667, 556]) == 1\n", "comparison": "exact"}, "public_tests": ["[2,6,4]\n[9,7,5]", "[10]\n[5]", "[1,1,1,1]\n[1,1,1,1]"], "hints": ["Notice that, after sorting both arrays, there should be a one-to-one correspondence between every element.", "Thus x = min(nums2) - min(nums1)."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().addedInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:07+00:00", "tests_total": 100, "tests_dropped": 3, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def added_integer(nums1, nums2)", "container": null, "callable": "added_integer", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3132, "task_id": "find-the-integer-added-to-array-ii", "difficulty": "Medium", "problem_description": "You are given two integer arrays nums1 and nums2.\n\nWe say that nums2 is reachable from nums1 with an integer x if there exist two elements in nums1 that, when removed, and x is added to all the remaining elements of nums1 (or subtracted in the case of a negative x), the resulting array becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.\n\nReturn the minimum possible integer x that makes nums2 reachable from nums1.\n\nIt is guaranteed that nums2 is reachable from nums1 with at least one x.\n\nExample 1:\n\nInput: nums1 = [4,20,16,12,8], nums2 = [14,18,10]\nOutput: -2\nExplanation:\nAfter removing elements at indices [0,4] and adding -2, nums1 becomes [18,14,10].\n\nExample 2:\n\nInput: nums1 = [3,5,5,3], nums2 = [7,7]\nOutput: 2\nExplanation:\nAfter removing elements at indices [0,3] and adding 2, nums1 becomes [7,7].\n\nConstraints:\n\n- 3 <= nums1.length <= 200\n- nums2.length == nums1.length - 2\n- 0 <= nums1[i], nums2[i] <= 1000\n-\nIt is guaranteed that nums2 is reachable from nums1 with at least one x.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [20, 30, 40]) == -10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [12, 22, 32]) == -18\n assert candidate(nums1 = [4, 20, 16, 12, 8],nums2 = [14, 18, 10]) == -2\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [2, 2]) == 2\n assert candidate(nums1 = [3, 5, 5, 3],nums2 = [7, 7]) == 2\n assert candidate(nums1 = [0, 1, 2, 3, 4],nums2 = [2, 3, 4]) == 0\n assert candidate(nums1 = [15, 25, 35, 45, 55, 65, 75],nums2 = [25, 35, 45, 55, 65]) == -10\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600],nums2 = [110, 210, 310, 410]) == -190\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [200, 300, 400]) == -100\n assert candidate(nums1 = [3, 6, 9, 12, 15, 18, 21],nums2 = [6, 9, 12, 15, 18]) == -3\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [3, 4, 5]) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600],nums2 = [150, 250, 350, 450]) == -150\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [4, 6, 8]) == -2\n assert candidate(nums1 = [50, 70, 90, 110, 130, 150],nums2 = [90, 110, 130, 150]) == 0\n assert candidate(nums1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],nums2 = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]) == -2\n assert candidate(nums1 = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90],nums2 = [10, 20, 30, 40, 50, 60, 70, 80]) == -10\n assert candidate(nums1 = [50, 55, 60, 65, 70],nums2 = [55, 60, 65]) == -5\n assert candidate(nums1 = [8, 15, 10, 20, 25],nums2 = [13, 18, 23]) == -2\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [3, 5, 7]) == -2\n assert candidate(nums1 = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],nums2 = [18, 27, 36, 45, 54, 63, 72, 81, 90]) == -9\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30],nums2 = [10, 15, 20, 25]) == -5\n assert candidate(nums1 = [12, 18, 24, 30, 36],nums2 = [18, 24, 30]) == -6\n assert candidate(nums1 = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500],nums2 = [510, 510, 510, 510, 510, 510, 510, 510]) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70],nums2 = [15, 25, 35, 45, 55]) == -15\n assert candidate(nums1 = [7, 14, 21, 28, 35],nums2 = [9, 16, 23]) == -12\n assert candidate(nums1 = [15, 18, 21, 24, 27, 30],nums2 = [12, 15, 18, 21]) == -9\n assert candidate(nums1 = [3, 6, 9, 12, 15],nums2 = [6, 9, 12]) == -3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [2, 3, 4, 5, 6, 7, 8]) == -1\n assert candidate(nums1 = [45, 47, 49, 51, 53, 55, 57],nums2 = [46, 48, 50, 52, 54]) == -3\n", "comparison": "exact"}, "public_tests": ["[4,20,16,12,8]\n[14,18,10]", "[3,5,5,3]\n[7,7]"], "hints": ["Try all possibilities to remove 2 elements from nums1.", "x should be equal to min(nums2) - min(nums1), check it naively."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minimumAddedInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:09+00:00", "tests_total": 165, "tests_dropped": 136, "flags": [], "topic_tags": ["array", "two-pointers", "sorting", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_added_integer(nums1, nums2)", "container": null, "callable": "minimum_added_integer", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3133, "task_id": "minimum-array-end", "difficulty": "Medium", "problem_description": "You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x.\n\nReturn the minimum possible value of nums[n - 1].\n\nExample 1:\n\nInput: n = 3, x = 4\nOutput: 6\nExplanation:\nnums can be [4,5,6] and its last element is 6.\n\nExample 2:\n\nInput: n = 2, x = 7\nOutput: 15\nExplanation:\nnums can be [7,15] and its last element is 15.\n\nConstraints:\n\n- 1 <= n, x <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,x = 8) == 11\n assert candidate(n = 5,x = 1) == 9\n assert candidate(n = 10,x = 1) == 19\n assert candidate(n = 5,x = 3) == 19\n assert candidate(n = 2,x = 7) == 15\n assert candidate(n = 1,x = 10) == 10\n assert candidate(n = 10,x = 16) == 25\n assert candidate(n = 1,x = 5) == 5\n assert candidate(n = 1,x = 32) == 32\n assert candidate(n = 3,x = 4) == 6\n assert candidate(n = 500000,x = 256) == 1000223\n assert candidate(n = 30,x = 2048) == 2077\n assert candidate(n = 500000,x = 2047) == 1023999999\n assert candidate(n = 50,x = 512) == 561\n assert candidate(n = 100,x = 128) == 227\n assert candidate(n = 8,x = 4096) == 4103\n assert candidate(n = 20,x = 8) == 43\n assert candidate(n = 100000,x = 65535) == 6553599999\n assert candidate(n = 512,x = 32768) == 33279\n assert candidate(n = 7,x = 12) == 30\n assert candidate(n = 15,x = 8) == 30\n assert candidate(n = 4,x = 3) == 15\n assert candidate(n = 20,x = 16) == 51\n assert candidate(n = 8,x = 3) == 31\n assert candidate(n = 12,x = 3) == 47\n assert candidate(n = 1000,x = 512) == 2023\n assert candidate(n = 8,x = 1023) == 8191\n assert candidate(n = 100,x = 16) == 211\n assert candidate(n = 30,x = 17) == 123\n assert candidate(n = 30,x = 64) == 93\n assert candidate(n = 15,x = 31) == 479\n assert candidate(n = 100,x = 255) == 25599\n assert candidate(n = 4,x = 63) == 255\n assert candidate(n = 5,x = 1023) == 5119\n assert candidate(n = 10,x = 1024) == 1033\n assert candidate(n = 8,x = 7) == 63\n assert candidate(n = 5,x = 8) == 12\n assert candidate(n = 50000,x = 31) == 1599999\n assert candidate(n = 9,x = 512) == 520\n assert candidate(n = 4,x = 15) == 63\n assert candidate(n = 6,x = 2048) == 2053\n assert candidate(n = 7,x = 10) == 30\n assert candidate(n = 15,x = 100) == 126\n assert candidate(n = 6,x = 10) == 27\n assert candidate(n = 3,x = 16) == 18\n assert candidate(n = 50,x = 2048) == 2097\n assert candidate(n = 1000,x = 4096) == 5095\n assert candidate(n = 10,x = 1048575) == 10485759\n assert candidate(n = 15,x = 1024) == 1038\n assert candidate(n = 50,x = 128) == 177\n assert candidate(n = 20,x = 2047) == 40959\n assert candidate(n = 25,x = 2048) == 2072\n assert candidate(n = 6,x = 24) == 29\n assert candidate(n = 7,x = 128) == 134\n assert candidate(n = 100,x = 1047552) == 1047651\n assert candidate(n = 15,x = 512) == 526\n assert candidate(n = 3,x = 12) == 14\n assert candidate(n = 20,x = 512) == 531\n assert candidate(n = 1,x = 1023) == 1023\n assert candidate(n = 100000,x = 1023) == 102399999\n assert candidate(n = 3,x = 31) == 95\n assert candidate(n = 5,x = 31) == 159\n assert candidate(n = 50,x = 31) == 1599\n assert candidate(n = 500,x = 512) == 1011\n assert candidate(n = 10000000,x = 4095) == 40959999999\n assert candidate(n = 64,x = 2048) == 2111\n assert candidate(n = 8,x = 32) == 39\n assert candidate(n = 3,x = 13) == 29\n assert candidate(n = 8,x = 31) == 255\n assert candidate(n = 7,x = 64) == 70\n assert candidate(n = 1,x = 1024) == 1024\n assert candidate(n = 1024,x = 65535) == 67108863\n assert candidate(n = 100,x = 4096) == 4195\n assert candidate(n = 7,x = 1024) == 1030\n assert candidate(n = 9,x = 256) == 264\n assert candidate(n = 1000,x = 2048) == 3047\n assert candidate(n = 10,x = 32) == 41\n assert candidate(n = 50,x = 255) == 12799\n assert candidate(n = 100000,x = 128) == 200095\n assert candidate(n = 100000,x = 1) == 199999\n assert candidate(n = 8,x = 255) == 2047\n assert candidate(n = 5,x = 15) == 79\n assert candidate(n = 100,x = 256) == 355\n assert candidate(n = 25,x = 128) == 152\n assert candidate(n = 6,x = 64) == 69\n assert candidate(n = 7,x = 32) == 38\n assert candidate(n = 5,x = 12) == 28\n assert candidate(n = 1,x = 2048) == 2048\n assert candidate(n = 14,x = 1023) == 14335\n assert candidate(n = 50,x = 1024) == 1073\n assert candidate(n = 200,x = 8192) == 8391\n assert candidate(n = 128,x = 16383) == 2097151\n assert candidate(n = 20,x = 3) == 79\n assert candidate(n = 11,x = 512) == 522\n assert candidate(n = 10,x = 256) == 265\n assert candidate(n = 1,x = 8191) == 8191\n assert candidate(n = 1,x = 1048575) == 1048575\n assert candidate(n = 30,x = 8191) == 245759\n assert candidate(n = 4,x = 17) == 23\n assert candidate(n = 5,x = 10) == 26\n assert candidate(n = 30,x = 512) == 541\n assert candidate(n = 15,x = 7) == 119\n assert candidate(n = 9,x = 255) == 2303\n", "comparison": "exact"}, "public_tests": ["3\n4", "2\n7"], "hints": ["Each element of the array should be obtained by “merging” x and v where v = 0, 1, 2, …(n - 1).", "To merge x with another number v, keep the set bits of x untouched, for all the other bits, fill the set bits of v from right to left in order one by one.", "So the final answer is the “merge” of x and n - 1."], "metadata": {"canonical_parameter_names": ["n", "x"], "leetcode_dataset_entry_point": "Solution().minEnd", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:11+00:00", "tests_total": 106, "tests_dropped": 3, "flags": [], "topic_tags": ["bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_end(n, x)", "container": null, "callable": "min_end", "parameters": [{"name": "n", "type": "Integer"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3134, "task_id": "find-the-median-of-the-uniqueness-array", "difficulty": "Hard", "problem_description": "You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j < nums.length.\n\nHere, distinct(nums[i..j]) denotes the number of distinct elements in the subarray that starts at index i and ends at index j.\n\nReturn the median of the uniqueness array of nums.\n\nNote that the median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the smaller of the two values is taken.\n\nExample 1:\n\nInput: nums = [1,2,3]\nOutput: 1\nExplanation:\nThe uniqueness array of nums is [distinct(nums[0..0]), distinct(nums[1..1]), distinct(nums[2..2]), distinct(nums[0..1]), distinct(nums[1..2]), distinct(nums[0..2])] which is equal to [1, 1, 1, 2, 2, 3]. The uniqueness array has a median of 1. Therefore, the answer is 1.\n\nExample 2:\n\nInput: nums = [3,4,3,4,5]\nOutput: 2\nExplanation:\nThe uniqueness array of nums is [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]. The uniqueness array has a median of 2. Therefore, the answer is 2.\n\nExample 3:\n\nInput: nums = [4,3,5,4]\nOutput: 2\nExplanation:\nThe uniqueness array of nums is [1, 1, 1, 1, 2, 2, 2, 3, 3, 3]. The uniqueness array has a median of 2. Therefore, the answer is 2.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 2\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4]) == 2\n assert candidate(nums = [1, 2, 3]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 2\n assert candidate(nums = [1, 2, 3, 2, 1]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50]) == 2\n assert candidate(nums = [4, 3, 5, 4]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996]) == 2\n assert candidate(nums = [3, 4, 3, 4, 5]) == 2\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]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 1\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]) == 3\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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]) == 1\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]) == 5\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 1, 2, 1, 2, 2, 3, 1, 2, 3, 2, 3, 3, 4, 1, 2, 3, 4, 2, 3, 4, 3, 4, 4, 5, 1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 5, 4, 5, 5, 6]) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 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]) == 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]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 4\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 4\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]) == 4\n assert candidate(nums = [1, 3, 2, 3, 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, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 2\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 3\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980]) == 7\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 4\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 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]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 4\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1, 6, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 3\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 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]) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == 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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [100000, 100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997, 99996]) == 2\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14, 16, 15, 17, 16, 18, 17, 19, 18, 20]) == 7\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]) == 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]) == 4\n assert candidate(nums = [1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 2\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4]) == 2\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 2, 1, 5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 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, 5, 5, 5, 5, 5]) == 2\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, 2, 3, 4, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\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]) == 2\n assert candidate(nums = [100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == 5\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 10, 1, 2, 9, 3, 8, 4, 7, 5, 6]) == 6\n assert candidate(nums = [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]) == 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]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,2,3]", "[3,4,3,4,5]", "[4,3,5,4]"], "hints": ["Binary search over the answer.", "For a given x, you need to check if x is the median, to the left of the median, or to the right of the median. You can do that by counting the number of sub-arrays nums[i…j] such that distinct(num[i…j]) <= x.", "Use the sliding window to solve the counting problem in the hint above."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().medianOfUniquenessArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:14+00:00", "tests_total": 101, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def median_of_uniqueness_array(nums)", "container": null, "callable": "median_of_uniqueness_array", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3137, "task_id": "minimum-number-of-operations-to-make-word-k-periodic", "difficulty": "Medium", "problem_description": "You are given a string word of size n, and an integer k such that k divides n.\n\nIn one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of length k starting at j. That is, replace the substring word[i..i + k - 1] with the substring word[j..j + k - 1].\n\nReturn the minimum number of operations required to make word k-periodic.\n\nWe say that word is k-periodic if there is some string s of length k such that word can be obtained by concatenating s an arbitrary number of times. For example, if word == “ababab”, then word is 2-periodic for s = \"ab\".\n\nExample 1:\n\nInput: word = \"leetcodeleet\", k = 4\nOutput: 1\nExplanation:\nWe can obtain a 4-periodic string by picking i = 4 and j = 0. After this operation, word becomes equal to \"leetleetleet\".\n\nExample 2:\n\nInput: word = \"leetcoleet\", k = 2\nOutput: 3\nExplanation:\nWe can obtain a 2-periodic string by applying the operations in the table below.\n\ni | j | word\n0 | 2 | etetcoleet\n4 | 0 | etetetleet\n6 | 0 | etetetetet\n\nConstraints:\n\n- 1 <= n == word.length <= 10^5\n- 1 <= k <= word.length\n- k divides word.length.\n- word consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"xyzxyzxyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"xyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"abcdefghijabcdefghij\",k = 5) == 2\n assert candidate(word = \"abcabcabc\",k = 3) == 0\n assert candidate(word = \"aaaaaaa\",k = 1) == 0\n assert candidate(word = \"aaaa\",k = 1) == 0\n assert candidate(word = \"xyzxyzxyzxyzxyzxyz\",k = 6) == 0\n assert candidate(word = \"abcdabcdabcd\",k = 4) == 0\n assert candidate(word = \"mnopqrsmnopqrsmnopqrs\",k = 7) == 0\n assert candidate(word = \"leetcodeleet\",k = 4) == 1\n assert candidate(word = \"abababab\",k = 2) == 0\n assert candidate(word = \"zzzzzzzzzzzz\",k = 6) == 0\n assert candidate(word = \"abcdefabcdefabcdef\",k = 3) == 3\n assert candidate(word = \"leetcoleet\",k = 2) == 3\n assert candidate(word = \"abcabcabcabc\",k = 3) == 0\n assert candidate(word = \"abcdabcdabcdabcd\",k = 4) == 0\n assert candidate(word = \"abababababab\",k = 2) == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 16) == 0\n assert candidate(word = \"aaaabbbbccccddddeeeeffff\",k = 4) == 5\n assert candidate(word = \"hellohellohellohellohellohellohellohello\",k = 5) == 0\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 4) == 0\n assert candidate(word = \"qwertyqwertyqwertyqwertyqwertyqwerty\",k = 5) == 5\n assert candidate(word = \"abcdefabcdefabcdefabcdef\",k = 6) == 0\n assert candidate(word = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef\",k = 6) == 0\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 4) == 0\n assert candidate(word = \"abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh\",k = 8) == 0\n assert candidate(word = \"mnopqrstuqponmlkjihgfedcbamnopqrstuqponmlkjihgfedcba\",k = 10) == 4\n assert candidate(word = \"abcdefgabcdefgabcdefgabcdefgabcdefg\",k = 7) == 0\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",k = 10) == 0\n assert candidate(word = \"mnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnop\",k = 10) == 6\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop\",k = 10) == 0\n assert candidate(word = \"abcdefghabcdefghabcdefgh\",k = 8) == 0\n assert candidate(word = \"racecaracecaracecaracecaracecaracecaracecaracecaracecaracecaracecaracecaracecaracecaracecaracecar\",k = 7) == 10\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 2) == 25\n assert candidate(word = \"mnopqrsmnopqrsmnopqrsmnopqrs\",k = 10) == 1\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbbcccccccccc\",k = 9) == 2\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\",k = 1) == 25\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiopqwertyuiop\",k = 12) == 2\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 26) == 0\n assert candidate(word = \"abacabadabacabadabacabadabacaba\",k = 3) == 7\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 3) == 0\n assert candidate(word = \"racecaracecaracecaracecaracecar\",k = 7) == 3\n assert candidate(word = \"aabbccddeeaabbccddee\",k = 5) == 2\n assert candidate(word = \"zyxwvutrsrqponmlkjihgfedcba\",k = 5) == 4\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 6) == 0\n assert candidate(word = \"abcdefabcdefabcdefabcdefabcdefabcdef\",k = 9) == 2\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 3) == 0\n assert candidate(word = \"mnopqrstmnopqrstmnopqrstmnopqrst\",k = 10) == 2\n assert candidate(word = \"abcdefghijklmnopqrstabcdefghijklmnopqrst\",k = 5) == 6\n assert candidate(word = \"mnopmnopmnopmnopmnopmnopmnopmnop\",k = 8) == 0\n assert candidate(word = \"abracadabraabracadabraabracadabra\",k = 9) == 2\n assert candidate(word = \"mnopqrsmnopqrsmnopqrsmnopqrsmnopqrs\",k = 7) == 0\n assert candidate(word = \"abacabadabacabadabacaba\",k = 5) == 3\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 20) == 3\n assert candidate(word = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\",k = 9) == 0\n assert candidate(word = \"abcdefabcdefabcdefabcdefabcdefabcdef\",k = 3) == 6\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 12) == 0\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabc\",k = 9) == 0\n assert candidate(word = \"xyzxyzxyzxyzxyzxyzxyzxyz\",k = 3) == 0\n assert candidate(word = \"mississippimississippimississippimississippi\",k = 4) == 9\n assert candidate(word = \"aaaaabbbbbcccccddddd\",k = 5) == 3\n assert candidate(word = \"abcabcabcabcabcabc\",k = 3) == 0\n assert candidate(word = \"aaaaaabbbbccccddddeeeeffff\",k = 4) == 5\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 7) == 0\n assert candidate(word = \"thisisaverylongstringthatrepeatseveryfivethis\",k = 5) == 8\n assert candidate(word = \"mississippiissippimississippi\",k = 4) == 6\n assert candidate(word = \"abacabadabacabad\",k = 4) == 2\n assert candidate(word = \"aabbccddeeffgghhaabbccddeeffgghh\",k = 6) == 4\n assert candidate(word = \"aabbccddeeffaabbccddeeffaabbccddeeff\",k = 6) == 3\n assert candidate(word = \"aabbccddeeffaabbccddeeff\",k = 6) == 2\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiop\",k = 12) == 1\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 5) == 0\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\",k = 10) == 4\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",k = 10) == 0\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghij\",k = 10) == 0\n assert candidate(word = \"qqrqqqrqqqrqqqrqqqrqqqrqqqr\",k = 3) == 6\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 5\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",k = 15) == 1\n assert candidate(word = \"baaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaa\",k = 10) == 1\n assert candidate(word = \"mississippiissippiissippiissipp\",k = 4) == 6\n assert candidate(word = \"mississippimississippimississippimississippi\",k = 11) == 0\n assert candidate(word = \"aabbccddaabbccddaabbccdd\",k = 4) == 3\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",k = 3) == 0\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabc\",k = 3) == 0\n assert candidate(word = \"qwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwerty\",k = 6) == 0\n assert candidate(word = \"abababababababababababababababab\",k = 2) == 0\n assert candidate(word = \"mnopqrstmnopqrstmnopqrstmnopqrst\",k = 8) == 0\n assert candidate(word = \"zyxwvutrsrqponmlkjihgfedcbazyxwvut\",k = 5) == 5\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 26) == 0\n assert candidate(word = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\",k = 3) == 0\n assert candidate(word = \"mnopqrstmnopqrstmnopqrst\",k = 10) == 1\n assert candidate(word = \"aaaaabaaaabaaaabaaaabaaaabaaaabaaaab\",k = 5) == 1\n assert candidate(word = \"lkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjhlkjh\",k = 11) == 3\n assert candidate(word = \"zzzzyyyxxxyyyzzzzxxxxyyyy\",k = 5) == 4\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",k = 5) == 0\n assert candidate(word = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef\",k = 7) == 5\n assert candidate(word = \"aaaaabbbbbccccddddeeeeffffgggghhhh\",k = 4) == 7\n assert candidate(word = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\",k = 11) == 2\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",k = 12) == 0\n assert candidate(word = \"qwertyuiopqwertyuiopqwertyuiopqwertyuiop\",k = 10) == 0\n assert candidate(word = \"abcdefabcdefabcdefabcdefabcdefabcdef\",k = 6) == 0\n assert candidate(word = \"ababababababababababababababab\",k = 2) == 0\n assert candidate(word = \"hellohellohellohellohellohellohellohellohellohello\",k = 5) == 0\n assert candidate(word = \"abababababababababababababababababababab\",k = 4) == 0\n", "comparison": "exact"}, "public_tests": ["\"leetcodeleet\"\n4", "\"leetcoleet\"\n2"], "hints": ["Calculate the frequency of each substring of length k that starts at an index that is divisible by k.", "The period of the final string will be the substring with the highest frequency."], "metadata": {"canonical_parameter_names": ["word", "k"], "leetcode_dataset_entry_point": "Solution().minimumOperationsToMakeKPeriodic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:22+00:00", "tests_total": 105, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations_to_make_k_periodic(word, k)", "container": null, "callable": "minimum_operations_to_make_k_periodic", "parameters": [{"name": "word", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3138, "task_id": "minimum-length-of-anagram-concatenation", "difficulty": "Medium", "problem_description": "You are given a string s, which is known to be a concatenation of anagrams of some string t.\n\nReturn the minimum possible length of the string t.\n\nAn anagram is formed by rearranging the letters of a string. For example, \"aab\", \"aba\", and, \"baa\" are anagrams of \"aab\".\n\nExample 1:\n\nInput: s = \"abba\"\nOutput: 2\nExplanation:\nOne possible string t could be \"ba\".\n\nExample 2:\n\nInput: s = \"cdef\"\nOutput: 4\nExplanation:\nOne possible string t could be \"cdef\", notice that t can be equal to s.\n\nExample 2:\n\nInput: s = \"abcbcacabbaccba\"\nOutput: 3\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abababab\") == 2\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abcabcabcabc\") == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"aa\") == 1\n assert candidate(s = \"xyzxyzxyz\") == 3\n assert candidate(s = \"abba\") == 2\n assert candidate(s = \"abcdeedcba\") == 5\n assert candidate(s = \"abcdabcdabcd\") == 4\n assert candidate(s = \"abacabadabacabad\") == 8\n assert candidate(s = \"aabbccddeeffgghh\") == 16\n assert candidate(s = \"aaaa\") == 1\n assert candidate(s = \"abcbcacabbaccba\") == 3\n assert candidate(s = \"aabbcc\") == 6\n assert candidate(s = \"cdef\") == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 52\n assert candidate(s = \"xyzxyzxyzxyz\") == 3\n assert candidate(s = \"abcdabcdabcdabcd\") == 4\n assert candidate(s = \"abcdefg\") == 7\n assert candidate(s = \"thisisaverylongstringthatwillrequireauniquestringtobeformedanditshouldbechecked\") == 79\n assert candidate(s = \"abacabadabacabadabacabadabacaba\") == 31\n assert candidate(s = \"abracadabrabracadabrabracadabrabracadabrabracadabraca\") == 53\n assert candidate(s = \"ninnininnininnininininininininininininininininininininininininin\") == 64\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 10\n assert candidate(s = \"mnopqrstmnopqrstmnopqrstmnopqrstmnopqrstmnopqrstmnopqrst\") == 8\n assert candidate(s = \"abcabcabcabcaa\") == 7\n assert candidate(s = \"tomatotomatotomatotomatotomatotomatotomatotomatotomato\") == 6\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 3\n assert candidate(s = \"xyxxyxyxxyxxyxyxxyxxyxyxxyxxyxyxxyxxyxyxxyxxyxyxxyxxyxyxxyxxyxyxxyxxyxyx\") == 8\n assert candidate(s = \"mamamamamamamamamamamamamamamamamamamamamama\") == 2\n assert candidate(s = \"abracadabraacarbadrabracadabraacarbadrabracadabraacarbadrabracadabra\") == 68\n assert candidate(s = \"racecarracecarracecar\") == 7\n assert candidate(s = \"shortyetuniquestringwithanagramstestcase\") == 40\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 26\n assert candidate(s = \"lollipoplollipoplollipoplollipoplollipoplollipoplollipoplollipop\") == 8\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefgabcdefgabcdefg\") == 7\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 4\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcd\") == 4\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 66\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdef\") == 58\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefg\") == 7\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"mnopqrstmnopqrstmnopqrstmnopqrstmnopqrstmnopqrstmnopqrstmnopqrstmnopqrstu\") == 73\n assert candidate(s = \"ppppeeeaaaallllllaaaabbbbcccdddd\") == 32\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\") == 27\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\") == 10\n assert candidate(s = \"zyxzyxzyxzyxzyx\") == 3\n assert candidate(s = \"elephantelephantelephantelephantelephantelephant\") == 8\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdef\") == 6\n assert candidate(s = \"xyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyz\") == 63\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 10\n assert candidate(s = \"aaabbbcccdddaa\") == 14\n assert candidate(s = \"mmnnooppqqrrssttuuvvwwxxyyzz\") == 28\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 56\n assert candidate(s = \"qqwweerrttyyuuiiooppaassddffgg\") == 30\n assert candidate(s = \"abcabcabcabccbaabccbaabc\") == 3\n assert candidate(s = \"xyzxyzxyzxyzxyz\") == 3\n assert candidate(s = \"abcdefghijlmnopqrstuvwxyzmnopqrstuvwxyzabcdefghij\") == 49\n assert candidate(s = \"aaaaabbbbccccddddeeeeeffffffggggghhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\") == 72\n assert candidate(s = \"mississippimississippi\") == 11\n assert candidate(s = \"mnopqrstmnopqrstmnopqrstmnopqrst\") == 8\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabc\") == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijkabcdefghijk\") == 11\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"bananaananabanana\") == 17\n", "comparison": "exact"}, "public_tests": ["\"abba\"", "\"cdef\"", "\"abcbcacabbaccba\""], "hints": ["The answer should be a divisor of s.length.", "Check each candidate naively."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minAnagramLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:26+00:00", "tests_total": 73, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def min_anagram_length(s)", "container": null, "callable": "min_anagram_length", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3139, "task_id": "minimum-cost-to-equalize-array", "difficulty": "Hard", "problem_description": "You are given an integer array nums and two integers cost1 and cost2. You are allowed to perform either of the following operations any number of times:\n\n- Choose an index i from nums and increase nums[i] by 1 for a cost of cost1.\n- Choose two different indices i, j, from nums and increase nums[i] and nums[j] by 1 for a cost of cost2.\n\nReturn the minimum cost required to make all elements in the array equal.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: nums = [4,1], cost1 = 5, cost2 = 2\nOutput: 15\nExplanation:\nThe following operations can be performed to make the values equal:\n- Increase nums[1] by 1 for a cost of 5. nums becomes [4,2].\n- Increase nums[1] by 1 for a cost of 5. nums becomes [4,3].\n- Increase nums[1] by 1 for a cost of 5. nums becomes [4,4].\n\nThe total cost is 15.\n\nExample 2:\n\nInput: nums = [2,3,3,3,5], cost1 = 2, cost2 = 1\nOutput: 6\nExplanation:\nThe following operations can be performed to make the values equal:\n- Increase nums[0] and nums[1] by 1 for a cost of 1. nums becomes [3,4,3,3,5].\n- Increase nums[0] and nums[2] by 1 for a cost of 1. nums becomes [4,4,4,3,5].\n- Increase nums[0] and nums[3] by 1 for a cost of 1. nums becomes [5,4,4,4,5].\n- Increase nums[1] and nums[2] by 1 for a cost of 1. nums becomes [5,5,5,4,5].\n- Increase nums[3] by 1 for a cost of 2. nums becomes [5,5,5,5,5].\n\nThe total cost is 6.\n\nExample 3:\n\nInput: nums = [3,5,3], cost1 = 1, cost2 = 3\nOutput: 4\nExplanation:\nThe following operations can be performed to make the values equal:\n- Increase nums[0] by 1 for a cost of 1. nums becomes [4,5,3].\n- Increase nums[0] by 1 for a cost of 1. nums becomes [5,5,3].\n- Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,4].\n- Increase nums[2] by 1 for a cost of 1. nums becomes [5,5,5].\n\nThe total cost is 4.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n- 1 <= cost1 <= 10^6\n- 1 <= cost2 <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 1],cost1 = 5,cost2 = 2) == 15\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 2,cost2 = 4) == 40\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [10, 10, 10, 10],cost1 = 100,cost2 = 50) == 0\n assert candidate(nums = [2, 3, 3, 3, 5],cost1 = 2,cost2 = 1) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],cost1 = 1,cost2 = 2) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 7,cost2 = 3) == 0\n assert candidate(nums = [10, 10, 10, 10, 10],cost1 = 100,cost2 = 50) == 0\n assert candidate(nums = [1, 1, 1, 1],cost1 = 10,cost2 = 5) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],cost1 = 3,cost2 = 2) == 10\n assert candidate(nums = [1, 2, 3, 4, 5],cost1 = 10,cost2 = 5) == 25\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 1000000,cost2 = 500000) == 0\n assert candidate(nums = [1, 1000000],cost1 = 1,cost2 = 1000000) == 999999\n assert candidate(nums = [1, 1000000],cost1 = 1,cost2 = 1) == 999999\n assert candidate(nums = [1, 1000000],cost1 = 1,cost2 = 2) == 999999\n assert candidate(nums = [1000000, 1000000, 1000000],cost1 = 1000000,cost2 = 500000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 5,cost2 = 2) == 49\n assert candidate(nums = [5, 5, 5, 5, 5],cost1 = 1,cost2 = 1) == 0\n assert candidate(nums = [1, 2],cost1 = 2,cost2 = 1) == 2\n assert candidate(nums = [100000, 100000, 100000],cost1 = 1,cost2 = 1) == 0\n assert candidate(nums = [3, 5, 3],cost1 = 1,cost2 = 3) == 4\n assert candidate(nums = [1, 2, 3],cost1 = 3,cost2 = 2) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],cost1 = 3,cost2 = 2) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],cost1 = 100000,cost2 = 50000) == 10950000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2],cost1 = 1,cost2 = 3) == 9\n assert candidate(nums = [1, 3, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15],cost1 = 1,cost2 = 1) == 55\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],cost1 = 1,cost2 = 1) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],cost1 = 1,cost2 = 2) == 72\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],cost1 = 7,cost2 = 10) == 527\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 3,cost2 = 5) == 50\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986, 999985],cost1 = 1000,cost2 = 500) == 27000\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000],cost1 = 123456,cost2 = 654321) == 18675295\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost1 = 10,cost2 = 5) == 1125\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost1 = 7,cost2 = 3) == 135\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],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],cost1 = 3,cost2 = 5) == 50\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 2,cost2 = 3) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 1000000,cost2 = 500000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 100000,cost2 = 50000) == 1200000\n assert candidate(nums = [1, 5, 9, 13, 17],cost1 = 3,cost2 = 5) == 100\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5],cost1 = 1,cost2 = 3) == 40\n assert candidate(nums = [100, 200, 300, 400, 500],cost1 = 10,cost2 = 7) == 3500\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost1 = 2,cost2 = 3) == 135\n assert candidate(nums = [5, 2, 3, 7, 1],cost1 = 3,cost2 = 5) == 43\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 1000,cost2 = 500) == 12000\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 7,cost2 = 3) == 30\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000],cost1 = 1000000,cost2 = 500000) == 0\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],cost1 = 1,cost2 = 1) == 5\n assert candidate(nums = [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],cost1 = 10,cost2 = 5) == 1170\n assert candidate(nums = [100, 200, 300, 400, 500],cost1 = 10,cost2 = 20) == 10000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],cost1 = 2,cost2 = 4) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],cost1 = 5,cost2 = 3) == 285\n assert candidate(nums = [5, 4, 3, 2, 1],cost1 = 5,cost2 = 10) == 50\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],cost1 = 50,cost2 = 20) == 45000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 100,cost2 = 50) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 100,cost2 = 200) == 4500\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625],cost1 = 2,cost2 = 4) == 10031250\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],cost1 = 1000,cost2 = 500) == 12000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],cost1 = 20,cost2 = 10) == 950\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],cost1 = 7,cost2 = 11) == 110\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 1000000,cost2 = 500000) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],cost1 = 5,cost2 = 10) == 5250\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 4, 5, 6],cost1 = 5,cost2 = 2) == 32\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 10,cost2 = 20) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],cost1 = 500000,cost2 = 1000000) == 52500000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],cost1 = 2,cost2 = 1) == 105\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],cost1 = 2,cost2 = 1) == 10\n assert candidate(nums = [5, 3, 1, 2, 4],cost1 = 7,cost2 = 3) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],cost1 = 10,cost2 = 20) == 1900\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 3,cost2 = 5) == 113\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3],cost1 = 4,cost2 = 8) == 64\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost1 = 1,cost2 = 2) == 90\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],cost1 = 1000,cost2 = 500) == 2500\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],cost1 = 2,cost2 = 4) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],cost1 = 1,cost2 = 1) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 10,cost2 = 5) == 120\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost1 = 50,cost2 = 25) == 5625\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],cost1 = 3,cost2 = 5) == 180\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 2,cost2 = 4) == 40\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost1 = 1000,cost2 = 500) == 112500\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],cost1 = 1,cost2 = 2) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],cost1 = 1000,cost2 = 500) == 250000\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],cost1 = 1000000,cost2 = 500000) == 12000000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],cost1 = 4,cost2 = 8) == 760\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost1 = 1,cost2 = 1) == 225\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],cost1 = 10,cost2 = 5) == 120\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],cost1 = 7,cost2 = 6) == 60\n assert candidate(nums = [1, 1000000, 1, 1000000, 1, 1000000],cost1 = 500000,cost2 = 250000) == 999997382\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],cost1 = 7,cost2 = 3) == 45\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],cost1 = 10,cost2 = 15) == 7500\n assert candidate(nums = [1, 3, 5, 7, 9],cost1 = 1000000,cost2 = 500000) == 5000000\n assert candidate(nums = [500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000],cost1 = 1000,cost2 = 500) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 1000,cost2 = 500) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],cost1 = 10,cost2 = 3) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost1 = 5,cost2 = 2) == 450\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],cost1 = 1,cost2 = 1) == 105\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],cost1 = 1,cost2 = 1) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],cost1 = 10,cost2 = 20) == 300\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost1 = 1,cost2 = 2) == 45\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],cost1 = 100,cost2 = 50) == 30700\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],cost1 = 2,cost2 = 1) == 525\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],cost1 = 10,cost2 = 5) == 50\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],cost1 = 1,cost2 = 2) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],cost1 = 1000000,cost2 = 500000) == 27000000\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],cost1 = 6,cost2 = 3) == 207\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],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],cost1 = 3,cost2 = 5) == 100\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost1 = 2,cost2 = 4) == 0\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000],cost1 = 10000,cost2 = 5000) == 499999986\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],cost1 = 100,cost2 = 50) == 0\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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],cost1 = 1,cost2 = 1) == 83\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],cost1 = 10,cost2 = 5) == 2625\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],cost1 = 1000,cost2 = 500) == 4500\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],cost1 = 1,cost2 = 2) == 0\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000],cost1 = 100,cost2 = 50) == 112500000\n assert candidate(nums = [7, 7, 8, 8, 8, 9, 9, 9, 9, 9],cost1 = 5,cost2 = 3) == 14\n", "comparison": "exact"}, "public_tests": ["[4,1]\n5\n2", "[2,3,3,3,5]\n2\n1", "[3,5,3]\n1\n3"], "hints": ["How can you determine the minimum cost if you know the maximum value in the array once all values are made equal?", "If cost2 > cost1 * 2, we should just use cost1 to change all the values to the maximum one.", "Otherwise, it's optimal to choose the smallest two values and use cost2 to increase both of them.", "Since the maximum value is known, calculate the required increases to equalize all values, instead of naively simulating the operations.", "There are not a lot of candidates for the maximum; we can try all of them and choose which uses the minimum number of operations."], "metadata": {"canonical_parameter_names": ["nums", "cost1", "cost2"], "leetcode_dataset_entry_point": "Solution().minCostToEqualizeArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:29+00:00", "tests_total": 122, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "greedy", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def min_cost_to_equalize_array(nums, cost1, cost2)", "container": null, "callable": "min_cost_to_equalize_array", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "cost1", "type": "Integer"}, {"name": "cost2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3142, "task_id": "check-if-grid-satisfies-conditions", "difficulty": "Easy", "problem_description": "You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is:\n\n- Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).\n- Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).\n\nReturn true if all the cells satisfy these conditions, otherwise, return false.\n\nExample 1:\n\nInput: grid = [[1,0,2],[1,0,2]]\nOutput: true\nExplanation:\nAll the cells in the grid satisfy the conditions.\n\nExample 2:\n\nInput: grid = [[1,1,1],[0,0,0]]\nOutput: false\nExplanation:\nAll cells in the first row are equal.\n\nExample 3:\n\nInput: grid = [[1],[2],[3]]\nOutput: false\nExplanation:\nCells in the first column have different values.\n\nConstraints:\n\n- 1 <= n, m <= 10\n- 0 <= grid[i][j] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1], [2], [3]]) == False\n assert candidate(grid = [[5, 4, 3], [5, 4, 3], [5, 4, 3]]) == True\n assert candidate(grid = [[5, 4, 3, 2, 1], [5, 4, 3, 2, 1]]) == True\n assert candidate(grid = [[5, 4], [5, 3]]) == False\n assert candidate(grid = [[1, 1, 1], [0, 0, 0]]) == False\n assert candidate(grid = [[9, 8], [9, 8], [9, 8], [9, 8]]) == True\n assert candidate(grid = [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]) == True\n assert candidate(grid = [[6]]) == True\n assert candidate(grid = [[8, 8], [8, 8]]) == False\n assert candidate(grid = [[7]]) == True\n assert candidate(grid = [[7, 8, 9], [7, 8, 9], [7, 8, 9]]) == True\n assert candidate(grid = [[9, 8, 7], [9, 8, 7], [9, 8, 7], [9, 8, 7]]) == True\n assert candidate(grid = [[1, 2], [1, 2], [1, 2]]) == True\n assert candidate(grid = [[0, 0], [1, 1], [2, 2]]) == False\n assert candidate(grid = [[0, 1, 0], [0, 1, 0]]) == True\n assert candidate(grid = [[6], [6]]) == True\n assert candidate(grid = [[1, 1], [1, 1], [1, 1]]) == False\n assert candidate(grid = [[4, 4], [5, 5], [4, 4]]) == False\n assert candidate(grid = [[9, 8], [9, 8], [9, 7]]) == False\n assert candidate(grid = [[1, 2], [3, 4], [1, 2]]) == False\n assert candidate(grid = [[0, 1, 2, 3], [0, 1, 2, 3]]) == True\n assert candidate(grid = [[1, 0, 2], [1, 0, 2]]) == True\n assert candidate(grid = [[6, 5], [6, 4], [6, 3]]) == False\n assert candidate(grid = [[1, 2], [1, 3]]) == False\n assert candidate(grid = [[0, 1, 2], [0, 1, 2], [0, 1, 3]]) == False\n assert candidate(grid = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == False\n assert candidate(grid = [[7, 8, 9, 0], [7, 8, 9, 0], [7, 8, 9, 0], [7, 8, 9, 0]]) == True\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]) == False\n assert candidate(grid = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]) == True\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == False\n assert candidate(grid = [[4, 5, 6, 7, 8], [4, 5, 6, 7, 9]]) == False\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == True\n assert candidate(grid = [[2, 3, 2], [2, 3, 2], [2, 3, 2]]) == True\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == False\n assert candidate(grid = [[1, 0, 1, 0, 1], [1, 0, 1, 0, 1]]) == True\n assert candidate(grid = [[5, 6, 7], [6, 7, 8], [7, 8, 9]]) == False\n assert candidate(grid = [[1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1]]) == True\n assert candidate(grid = [[9, 9, 9, 9], [8, 8, 8, 8], [7, 7, 7, 7], [6, 6, 6, 6]]) == False\n assert candidate(grid = [[4, 5, 6, 7], [4, 5, 6, 7], [4, 5, 6, 7], [4, 5, 6, 7]]) == True\n assert candidate(grid = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]]) == False\n assert candidate(grid = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == False\n assert candidate(grid = [[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]]) == True\n assert candidate(grid = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]) == True\n assert candidate(grid = [[1, 2, 1, 2], [1, 2, 1, 2], [1, 2, 1, 2]]) == True\n assert candidate(grid = [[9, 0, 1, 2], [9, 0, 1, 2], [9, 0, 1, 2]]) == True\n assert candidate(grid = [[7, 6, 5, 4, 3, 2, 1], [7, 6, 5, 4, 3, 2, 1]]) == True\n assert candidate(grid = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]) == True\n assert candidate(grid = [[1, 0], [0, 1], [1, 0], [0, 1]]) == False\n assert candidate(grid = [[1, 0, 1], [1, 0, 1], [1, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 2, 3], [1, 0, 2, 3], [1, 0, 2, 3], [1, 0, 2, 3]]) == True\n assert candidate(grid = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]) == True\n assert candidate(grid = [[0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1]]) == True\n assert candidate(grid = [[4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5]]) == True\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == False\n assert candidate(grid = [[1, 2, 1, 2], [3, 4, 3, 4], [1, 2, 1, 2], [3, 4, 3, 4]]) == False\n assert candidate(grid = [[1, 0, 1], [1, 0, 1], [1, 0, 1]]) == True\n assert candidate(grid = [[3, 2, 3, 2, 3, 2, 3, 2, 3, 2], [3, 2, 3, 2, 3, 2, 3, 2, 3, 2], [3, 2, 3, 2, 3, 2, 3, 2, 3, 2], [3, 2, 3, 2, 3, 2, 3, 2, 3, 2]]) == True\n assert candidate(grid = [[5, 6, 7], [5, 6, 8], [5, 9, 7]]) == False\n assert candidate(grid = [[4, 5, 6], [4, 5, 6], [7, 8, 9]]) == False\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0]]) == True\n assert candidate(grid = [[9, 0, 9, 0], [9, 0, 9, 0], [9, 0, 9, 0]]) == True\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == True\n assert candidate(grid = [[1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2]]) == True\n assert candidate(grid = [[1, 1], [2, 2], [3, 3], [4, 4]]) == False\n assert candidate(grid = [[7, 8, 9], [7, 8, 9], [7, 8, 9], [7, 8, 9]]) == True\n assert candidate(grid = [[1, 0, 1, 0], [1, 0, 1, 0], [0, 1, 0, 1]]) == False\n assert candidate(grid = [[3, 2, 1], [2, 1, 0], [1, 0, 9], [0, 9, 8]]) == False\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == False\n assert candidate(grid = [[0, 0, 0], [1, 1, 1], [0, 0, 0], [1, 1, 1]]) == False\n assert candidate(grid = [[1], [1], [1], [1], [1]]) == True\n assert candidate(grid = [[0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]]) == True\n assert candidate(grid = [[1, 1, 2, 2], [1, 1, 2, 2], [3, 3, 4, 4]]) == False\n assert candidate(grid = [[5, 6, 5, 6], [5, 6, 5, 6], [5, 6, 5, 6]]) == True\n assert candidate(grid = [[1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [0, 1, 0, 1, 0]]) == False\n assert candidate(grid = [[7, 6, 5], [7, 8, 9], [7, 6, 5]]) == False\n assert candidate(grid = [[1, 2, 3], [1, 0, 2], [1, 1, 1]]) == False\n assert candidate(grid = [[9, 8, 7, 6, 5], [9, 8, 7, 6, 5], [9, 8, 7, 6, 5], [9, 8, 7, 6, 5]]) == True\n assert candidate(grid = [[0, 1, 0, 1], [0, 1, 0, 1], [1, 0, 1, 0]]) == False\n assert candidate(grid = [[3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1], [3, 2, 1]]) == True\n assert candidate(grid = [[4, 5, 6], [7, 8, 9], [4, 5, 6]]) == False\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, 1, 0]]) == True\n assert candidate(grid = [[9, 9, 9, 9], [8, 8, 8, 8], [7, 7, 7, 7]]) == False\n assert candidate(grid = [[3, 4, 5, 6, 7], [3, 4, 5, 6, 7], [3, 4, 5, 6, 7]]) == True\n assert candidate(grid = [[0, 1, 0, 1, 0], [0, 1, 0, 1, 0]]) == True\n assert candidate(grid = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]) == True\n assert candidate(grid = [[1, 1, 2, 2, 3, 3], [1, 1, 2, 2, 3, 3]]) == False\n assert candidate(grid = [[9, 8, 7, 6], [9, 8, 7, 6], [9, 8, 7, 6]]) == True\n assert candidate(grid = [[3, 2, 1], [2, 1, 0], [1, 0, 3]]) == False\n assert candidate(grid = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == False\n assert candidate(grid = [[3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2]]) == True\n assert candidate(grid = [[5, 5, 5, 5, 5], [5, 4, 4, 4, 4], [5, 4, 3, 3, 3], [5, 4, 3, 2, 2], [5, 4, 3, 2, 1]]) == False\n assert candidate(grid = [[1, 1, 0], [2, 2, 0], [3, 3, 0]]) == False\n assert candidate(grid = [[4, 5, 6], [4, 5, 6], [4, 5, 6], [4, 5, 6]]) == True\n assert candidate(grid = [[1, 0, 1, 0], [2, 1, 2, 1], [1, 0, 1, 0], [2, 1, 2, 1]]) == False\n assert candidate(grid = [[7, 8, 9], [7, 8, 9], [7, 8, 9], [7, 8, 9]]) == True\n assert candidate(grid = [[1, 2, 3, 4], [1, 2, 3, 4]]) == True\n assert candidate(grid = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]) == True\n assert candidate(grid = [[9, 0, 9, 0], [9, 0, 9, 0], [9, 0, 9, 0]]) == True\n assert candidate(grid = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2]]) == False\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5]]) == False\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3]]) == False\n assert candidate(grid = [[3, 3, 3], [2, 2, 2], [1, 1, 1], [0, 0, 0]]) == False\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5]]) == False\n assert candidate(grid = [[1, 2], [2, 1], [1, 2], [2, 1]]) == False\n assert candidate(grid = [[1, 2, 3], [1, 4, 5], [1, 6, 7], [1, 8, 9]]) == False\n assert candidate(grid = [[5, 5, 5, 5, 5], [4, 4, 4, 4, 4]]) == False\n assert candidate(grid = [[5, 6, 7], [5, 6, 7], [5, 6, 8]]) == False\n assert candidate(grid = [[1, 1, 2], [1, 2, 1], [2, 1, 2]]) == False\n assert candidate(grid = [[1, 2, 3, 4], [1, 5, 6, 7], [1, 8, 9, 0]]) == False\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]]) == True\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]) == True\n assert candidate(grid = [[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]]) == True\n assert candidate(grid = [[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7]]) == False\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == False\n assert candidate(grid = [[1, 2, 3], [1, 2, 3], [4, 5, 6]]) == False\n", "comparison": "exact"}, "public_tests": ["[[1,0,2],[1,0,2]]", "[[1,1,1],[0,0,0]]", "[[1],[2],[3]]"], "hints": ["Check if each column has same value in each cell.", "If the previous condition is satisfied, we can simply check the first cells in adjacent columns."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().satisfiesConditions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:35+00:00", "tests_total": 116, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def satisfies_conditions(grid)", "container": null, "callable": "satisfies_conditions", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3143, "task_id": "maximum-points-inside-the-square", "difficulty": "Medium", "problem_description": "You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i.\n\nA valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and does not contain two points with the same tag.\n\nReturn the maximum number of points contained in a valid square.\n\nNote:\n\n- A point is considered to be inside the square if it lies on or within the square's boundaries.\n- The side length of the square can be zero.\n\nExample 1:\n\nInput: points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = \"abdca\"\nOutput: 2\nExplanation:\nThe square of side length 4 covers two points points[0] and points[1].\n\nExample 2:\n\nInput: points = [[1,1],[-2,-2],[-2,2]], s = \"abb\"\nOutput: 1\nExplanation:\nThe square of side length 2 covers one point, which is points[0].\n\nExample 3:\n\nInput: points = [[1,1],[-1,-1],[2,-2]], s = \"ccd\"\nOutput: 0\nExplanation:\nIt's impossible to make any valid squares centered at the origin such that it covers only one point among points[0] and points[1].\n\nConstraints:\n\n- 1 <= s.length, points.length <= 10^5\n- points[i].length == 2\n- -10^9 <= points[i][0], points[i][1] <= 10^9\n- s.length == points.length\n- points consists of distinct coordinates.\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 1], [-1, -1], [2, -2]],s = \"ccd\") == 0\n assert candidate(points = [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]],s = \"abcde\") == 5\n assert candidate(points = [[0, 1], [1, 0], [1, 1]],s = \"abc\") == 3\n assert candidate(points = [[10, 10], [-10, -10], [10, -10], [-10, 10]],s = \"abcd\") == 4\n assert candidate(points = [[0, 0], [0, 1], [1, 0], [1, 1]],s = \"abcd\") == 4\n assert candidate(points = [[1, 2], [2, 1], [3, 4], [4, 3]],s = \"abcd\") == 4\n assert candidate(points = [[3, 0], [-3, 0], [0, 3], [0, -3], [1, 1], [-1, -1]],s = \"abcdef\") == 6\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4]],s = \"abcd\") == 4\n assert candidate(points = [[0, 0], [1, 1], [2, 2]],s = \"abc\") == 3\n assert candidate(points = [[1, 2], [2, 1], [1, -2], [-2, 1], [-1, -2], [2, -1]],s = \"abcdef\") == 6\n assert candidate(points = [[0, 0], [1, 0], [0, 1], [-1, 0], [0, -1]],s = \"abcde\") == 5\n assert candidate(points = [[1, 2], [2, 1], [-1, -2], [-2, -1]],s = \"abcd\") == 4\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],s = \"abcde\") == 5\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1]],s = \"abcd\") == 4\n assert candidate(points = [[1, 1], [1, -1], [-1, 1], [-1, -1]],s = \"abcd\") == 4\n assert candidate(points = [[1, 1], [-2, -2], [-2, 2]],s = \"abb\") == 1\n assert candidate(points = [[0, 0], [1, 0], [0, 1]],s = \"abc\") == 3\n assert candidate(points = [[2, 2], [-1, -2], [-4, 4], [-3, 1], [3, -3]],s = \"abdca\") == 2\n assert candidate(points = [[5, 5], [5, -5], [-5, 5], [-5, -5]],s = \"abcd\") == 4\n assert candidate(points = [[5, 0], [0, 5], [-5, 0], [0, -5]],s = \"abcd\") == 4\n assert candidate(points = [[0, 0]],s = \"a\") == 1\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40]],s = \"abcd\") == 4\n assert candidate(points = [[0, 0], [1, 1], [-1, -1]],s = \"aaa\") == 1\n assert candidate(points = [[0, 0], [1, 1], [-1, -1], [2, 2], [-2, -2]],s = \"abcde\") == 5\n assert candidate(points = [[5, 5], [-5, -5], [0, 0]],s = \"aaa\") == 1\n assert candidate(points = [[1, 1], [2, 2], [3, 3]],s = \"abc\") == 3\n assert candidate(points = [[10, 0], [-10, 0], [0, 10], [0, -10]],s = \"abcd\") == 4\n assert candidate(points = [[-1, -1], [-2, -2], [-3, -3], [-4, -4]],s = \"abcd\") == 4\n assert candidate(points = [[5, 5], [-5, -5], [5, -5], [-5, 5]],s = \"abcd\") == 4\n assert candidate(points = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [0, 0]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1], [2, 0], [0, 2], [-2, 0], [0, -2], [3, 0], [0, 3], [-3, 0], [0, -3], [4, 0], [0, 4], [-4, 0], [0, -4]],s = \"abcdefghijklmnop\") == 16\n assert candidate(points = [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, -1], [1, -1], [-1, 1], [2, 2]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 1], [1, -1], [-1, 1], [-1, -1], [2, 2], [2, -2], [-2, 2], [-2, -2], [3, 3], [3, -3], [-3, 3], [-3, -3]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[0, 1], [1, 0], [0, -1], [-1, 0], [2, 0], [0, 2], [-2, 0], [0, -2], [3, 0], [0, 3], [-3, 0], [0, -3]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 1], [-1, -1], [2, 2], [-2, -2], [3, 3], [-3, -3], [4, 4], [-4, -4], [5, 5], [-5, -5]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 2], [2, 1], [-1, -2], [-2, -1], [3, 3], [-3, -3], [4, 4], [-4, -4], [5, 5], [-5, -5]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 2], [2, 1], [-1, -2], [-2, -1], [1, -1], [-1, 1], [2, 2], [-2, -2], [2, -2], [-2, 2]],s = \"abcdefghij\") == 10\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]],s = \"abcdefghijklmno\") == 15\n assert candidate(points = [[0, 0], [1, 0], [0, 1], [1, 1], [-1, 0], [0, -1], [-1, -1], [-1, 1], [1, -1]],s = \"abcdefghi\") == 9\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4]],s = \"abcdefgh\") == 8\n assert candidate(points = [[10, 10], [-10, -10], [5, 0], [-5, 0], [0, 5], [0, -5], [3, 4], [-3, -4], [4, -3], [-4, 3]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1], [2, 2], [-2, -2]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1000000000, 1000000000], [-1000000000, -1000000000], [500000000, 0], [-500000000, 0], [0, 500000000], [0, -500000000], [300000000, 400000000], [-300000000, -400000000], [400000000, -300000000], [-400000000, 300000000]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 1], [1, -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]],s = \"abcdefghijklmnop\") == 16\n assert candidate(points = [[999999999, 999999999], [-999999999, -999999999], [999999999, -999999999], [-999999999, 999999999]],s = \"abcd\") == 4\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1], [2, 0], [0, 2], [-2, 0], [0, -2], [1, 1], [1, -1], [-1, 1], [-1, -1]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, -1], [1, -1], [-1, 1], [2, 0], [-2, 0], [0, 2], [0, -2], [3, 0], [-3, 0], [0, 3], [0, -3]],s = \"abcdefghijklmnop\") == 16\n assert candidate(points = [[1000000000, 1000000000], [-1000000000, -1000000000], [1000000000, -1000000000], [-1000000000, 1000000000], [500000000, 500000000], [-500000000, -500000000]],s = \"abcdef\") == 6\n assert candidate(points = [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [10, 0]],s = \"abcdefghij\") == 10\n assert candidate(points = [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1], [2, 0], [0, 2], [-2, 0], [0, -2], [3, 0], [0, 3], [-3, 0], [0, -3]],s = \"abcdefghijklm\") == 13\n assert candidate(points = [[0, 0], [1, 0], [0, 1], [-1, 0], [0, -1], [2, 2], [-2, -2], [2, -2], [-2, 2]],s = \"abcdefghi\") == 9\n assert candidate(points = [[1, 1], [1, -1], [-1, 1], [-1, -1], [2, 2], [2, -2], [-2, 2], [-2, -2], [3, 3], [3, -3], [-3, 3], [-3, -3], [0, 0]],s = \"abcdefghijklm\") == 13\n assert candidate(points = [[0, 0], [1, 1], [-1, -1], [2, 2], [-2, -2], [3, 3], [-3, -3], [4, 4], [-4, -4]],s = \"abcdefghi\") == 9\n assert candidate(points = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5], [5, 6], [6, 5], [6, 6]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],s = \"abcdefghijk\") == 11\n assert candidate(points = [[1, 0], [-1, 0], [0, 1], [0, -1], [2, 0], [0, 2], [-2, 0], [0, -2], [3, 0], [0, 3], [-3, 0], [0, -3], [4, 0], [0, 4], [-4, 0], [0, -4]],s = \"abcdefghijklmnop\") == 16\n assert candidate(points = [[10, 10], [-10, -10], [10, -10], [-10, 10], [0, 0]],s = \"abcde\") == 5\n assert candidate(points = [[100, 0], [0, 100], [-100, 0], [0, -100], [50, 50], [50, -50], [-50, 50], [-50, -50], [25, 25], [25, -25], [-25, 25], [-25, -25]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[1000000000, 0], [-1000000000, 0], [0, 1000000000], [0, -1000000000], [500000000, 500000000]],s = \"abcde\") == 5\n assert candidate(points = [[10, 0], [0, 10], [-10, 0], [0, -10], [20, 0], [0, 20], [-20, 0], [0, -20], [10, 10], [10, -10], [-10, 10], [-10, -10]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[0, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]],s = \"abcde\") == 5\n assert candidate(points = [[5, 5], [-5, -5], [4, 4], [-4, -4], [3, 3], [-3, -3], [2, 2], [-2, -2], [1, 1], [-1, -1]],s = \"abcdefghij\") == 10\n assert candidate(points = [[1, 1], [1, -1], [-1, 1], [-1, -1], [0, 0], [0, 1], [0, -1], [1, 0], [-1, 0]],s = \"abcdefghi\") == 9\n assert candidate(points = [[1000000000, 0], [0, 1000000000], [-1000000000, 0], [0, -1000000000]],s = \"abcd\") == 4\n assert candidate(points = [[5, 0], [0, 5], [-5, 0], [0, -5], [3, 4], [4, 3], [-3, -4], [-4, -3]],s = \"abcdefgh\") == 8\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1], [2, 2], [2, -2], [-2, 2], [-2, -2]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],s = \"abcdefghij\") == 10\n assert candidate(points = [[-10, 10], [10, -10], [10, 10], [-10, -10], [5, 5], [-5, -5], [5, -5], [-5, 5]],s = \"abcdefgh\") == 8\n assert candidate(points = [[5, 0], [-5, 0], [0, 5], [0, -5], [2, 2], [-2, -2], [3, 3], [-3, -3]],s = \"abcdefgh\") == 8\n assert candidate(points = [[1000000000, 1000000000], [-1000000000, -1000000000], [1000000000, -1000000000], [-1000000000, 1000000000]],s = \"abcd\") == 4\n assert candidate(points = [[0, 0], [1, 1], [1, -1], [-1, 1], [-1, -1], [2, 2], [2, -2], [-2, 2], [-2, -2]],s = \"abcdefghi\") == 9\n assert candidate(points = [[5, 5], [5, -5], [-5, 5], [-5, -5], [1, 1], [1, -1], [-1, 1], [-1, -1]],s = \"abcdefgh\") == 8\n assert candidate(points = [[1, 0], [0, 1], [-1, 0], [0, -1], [2, 0], [0, 2], [-2, 0], [0, -2], [3, 0], [0, 3], [-3, 0], [0, -3]],s = \"abcdefghijkl\") == 12\n assert candidate(points = [[1000000000, 1000000000], [1000000000, -1000000000], [-1000000000, 1000000000], [-1000000000, -1000000000], [0, 0]],s = \"abcde\") == 5\n assert candidate(points = [[1, 1], [1, -1], [-1, 1], [-1, -1], [2, 2], [2, -2], [-2, 2], [-2, -2], [3, 3], [3, -3]],s = \"abcdefghij\") == 10\n", "comparison": "exact"}, "public_tests": ["[[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]]\n\"abdca\"", "[[1,1],[-2,-2],[-2,2]]\n\"abb\"", "[[1,1],[-1,-1],[2,-2]]\n\"ccd\""], "hints": ["The smallest edge length of a square to include point (x, y) is max(abs(x), abs(y)) * 2.", "Sort the points by max(abs(x), abs(y)) and try each edge length, check the included point tags."], "metadata": {"canonical_parameter_names": ["points", "s"], "leetcode_dataset_entry_point": "Solution().maxPointsInsideSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:39+00:00", "tests_total": 100, "tests_dropped": 24, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "string", "binary-search", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_points_inside_square(points, s)", "container": null, "callable": "max_points_inside_square", "parameters": [{"name": "points", "type": "Integer[][]"}, {"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3144, "task_id": "minimum-substring-partition-of-equal-character-frequency", "difficulty": "Medium", "problem_description": "Given a string s, you need to partition it into one or more balanced substrings. For example, if s == \"ababcc\" then (\"abab\", \"c\", \"c\"), (\"ab\", \"abc\", \"c\"), and (\"ababcc\") are all valid partitions, but (\"a\", \"bab\", \"cc\"), (\"aba\", \"bc\", \"c\"), and (\"ab\", \"abcc\") are not. The unbalanced substrings are bolded.\n\nReturn the minimum number of substrings that you can partition s into.\n\nNote: A balanced string is a string where each character in the string occurs the same number of times.\n\nExample 1:\n\nInput: s = \"fabccddg\"\nOutput: 3\nExplanation:\nWe can partition the string s into 3 substrings in one of the following ways: (\"fab, \"ccdd\", \"g\"), or (\"fabc\", \"cd\", \"dg\").\n\nExample 2:\n\nInput: s = \"abababaccddb\"\nOutput: 2\nExplanation:\nWe can partition the string s into 2 substrings like so: (\"abab\", \"abaccddb\").\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s consists only of English lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"aaabbbccc\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"aabbaabbccddccdd\") == 1\n assert candidate(s = \"abcdef\") == 1\n assert candidate(s = \"abababab\") == 1\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abcdefghi\") == 1\n assert candidate(s = \"abacabadabacaba\") == 8\n assert candidate(s = \"abab\") == 1\n assert candidate(s = \"abcabcabc\") == 1\n assert candidate(s = \"ab\") == 1\n assert candidate(s = \"aa\") == 1\n assert candidate(s = \"abcdefabcdef\") == 1\n assert candidate(s = \"abcde\") == 1\n assert candidate(s = \"abcabc\") == 1\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == 1\n assert candidate(s = \"abababaccddb\") == 2\n assert candidate(s = \"zzzzzzzzzz\") == 1\n assert candidate(s = \"abcdabcdabcd\") == 1\n assert candidate(s = \"fabccddg\") == 3\n assert candidate(s = \"aabbcc\") == 1\n assert candidate(s = \"abcdefghij\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijj\") == 1\n assert candidate(s = \"abcdabcdabcdabcd\") == 1\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abacabadabacabadabacabad\") == 12\n assert candidate(s = \"aabbaabbaabbaabbaabb\") == 1\n assert candidate(s = \"abcdefggfedcbafedcbafedcba\") == 2\n assert candidate(s = \"aabbcdeefgghhijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 6\n assert candidate(s = \"aabbaabbccddeeffgg\") == 2\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaaa\") == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(s = \"abcdefghijklaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzyyyyxxxxwwwwvvvuuutttsssrqqppoonnmmllkkjjiihhhgggfffeeedddcccbbaa\") == 9\n assert candidate(s = \"aaabbbcccdddcccbbbbaaa\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 1\n assert candidate(s = \"zzzzzyyyyxxxxwwwwvvvuuutttsssrqqppoonnmmllkkjjiihhhgggfffeeedddcccbbaa\") == 7\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdef\") == 1\n assert candidate(s = \"abcdefghabcdefghabcdefghabcdefgh\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyz\") == 1\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"aabbaaabbbaaaabbbcccdddeeefffggg\") == 3\n assert candidate(s = \"ababababababababababababababababab\") == 1\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefg\") == 1\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 1\n assert candidate(s = \"aabbbccccddddeeeeeffffffgggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\") == 6\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabb\") == 2\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 2\n assert candidate(s = \"abcdefabcdefabcdefabcdef\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"qqwweerrttyyuuuuummmiiiinnnngggg\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 1\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefg\") == 2\n assert candidate(s = \"abcabcabcabcabcabc\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzyyyyxxxxwwwwvvvuuutttsssrqqppoonnmmllkkjjiihhhgggfffeeedddcccbbaa\") == 8\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 3\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyxwvutsrqponmlkjihgfedcba\") == 2\n assert candidate(s = \"xyzzzyxzzzyxzzzyxzzzyxzzz\") == 10\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(s = \"aaabbbcccddd\") == 1\n assert candidate(s = \"abcabcababcabc\") == 2\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabc\") == 1\n assert candidate(s = \"aaaaaaaaaaabbbbbbbbbc\") == 3\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == 3\n assert candidate(s = \"aabbccddeeffaabbccddeeff\") == 1\n assert candidate(s = \"abcabcdabcabcdeabcdefabcdefg\") == 5\n", "comparison": "exact"}, "public_tests": ["\"fabccddg\"", "\"abababaccddb\""], "hints": ["Let dp[i] be the minimum number of partitions for the prefix ending at index i + 1.", "dp[i] can be calculated as the min(dp[j]) over all j such that j < i and word[j+1…i] is valid."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumSubstringsInPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:41+00:00", "tests_total": 72, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_substrings_in_partition(s)", "container": null, "callable": "minimum_substrings_in_partition", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3146, "task_id": "permutation-difference-between-two-strings", "difficulty": "Easy", "problem_description": "You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s.\n\nThe permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character in s and the index of the occurrence of the same character in t.\n\nReturn the permutation difference between s and t.\n\nExample 1:\n\nInput: s = \"abc\", t = \"bac\"\nOutput: 2\nExplanation:\nFor s = \"abc\" and t = \"bac\", the permutation difference of s and t is equal to the sum of:\n- The absolute difference between the index of the occurrence of \"a\" in s and the index of the occurrence of \"a\" in t.\n- The absolute difference between the index of the occurrence of \"b\" in s and the index of the occurrence of \"b\" in t.\n- The absolute difference between the index of the occurrence of \"c\" in s and the index of the occurrence of \"c\" in t.\n\nThat is, the permutation difference between s and t is equal to |0 - 1| + |1 - 0| + |2 - 2| = 2.\n\nExample 2:\n\nInput: s = \"abcde\", t = \"edbac\"\nOutput: 12\nExplanation: The permutation difference between s and t is equal to |0 - 3| + |1 - 2| + |2 - 4| + |3 - 1| + |4 - 0| = 12.\n\nConstraints:\n\n- 1 <= s.length <= 26\n- Each character occurs at most once in s.\n- t is a permutation of s.\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 338\n assert candidate(s = \"mnopqr\",t = \"qrpmno\") == 18\n assert candidate(s = \"abcde\",t = \"edbac\") == 12\n assert candidate(s = \"abcxyz\",t = \"xyzabc\") == 18\n assert candidate(s = \"qrstuv\",t = \"vutsrq\") == 18\n assert candidate(s = \"abc\",t = \"bac\") == 2\n assert candidate(s = \"mnopqr\",t = \"rqponm\") == 18\n assert candidate(s = \"uvwxy\",t = \"yxuvw\") == 12\n assert candidate(s = \"mnopqr\",t = \"qrponm\") == 18\n assert candidate(s = \"a\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = \"dcba\") == 8\n assert candidate(s = \"xyz\",t = \"zyx\") == 4\n assert candidate(s = \"ab\",t = \"ba\") == 2\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijkl\",t = \"qrstuvwxyzabcdefghijklmno\") == 154\n assert candidate(s = \"abcdpqrs\",t = \"srqpdcba\") == 32\n assert candidate(s = \"qazwsxedcrfvtgbyhnujmiklop\",t = \"plokmijnuhbygvtfcrdxeszwaq\") == 338\n assert candidate(s = \"fedcba\",t = \"abcdef\") == 18\n assert candidate(s = \"lkjhgfedcba\",t = \"abcdefghjkl\") == 60\n assert candidate(s = \"abcdefg\",t = \"gfedcba\") == 24\n assert candidate(s = \"lmnopqrstuvwxy\",t = \"yxwvutsrqponml\") == 98\n assert candidate(s = \"mnopqrstu\",t = \"tusrqpmon\") == 40\n assert candidate(s = \"ijklmnopqr\",t = \"rqponmlkji\") == 50\n assert candidate(s = \"abcdefghijl\",t = \"ljihgfedcba\") == 60\n assert candidate(s = \"hijklmnop\",t = \"ponmlkjih\") == 40\n assert candidate(s = \"qzjrwbyfc\",t = \"bfywzcrjq\") == 38\n assert candidate(s = \"xyzabcdefghijklmnopqrstuvw\",t = \"wvutsrqponmlkjihgfedcbazyx\") == 338\n assert candidate(s = \"abcdefghijklmnop\",t = \"ponmlkjihgfedcba\") == 128\n assert candidate(s = \"abcdefghij\",t = \"ghijabcdfe\") == 48\n assert candidate(s = \"abcdefghijk\",t = \"kjihgfedcba\") == 60\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxy\",t = \"yzxwvutsrqponmlkjihgfedcba\") == 314\n assert candidate(s = \"jklmnopqrabcdefghistuvwxy\",t = \"tuvxyabcdefghistuvwklmnoj\") == 267\n assert candidate(s = \"abcdefghij\",t = \"jabcdefghi\") == 18\n assert candidate(s = \"pqrstuv\",t = \"vutsrqp\") == 24\n assert candidate(s = \"vwxyzabcdefghijklmnopqrst\",t = \"rstqponmlkjihgfedcbazyxwv\") == 312\n assert candidate(s = \"asdfghjkl\",t = \"lkjhgfdsa\") == 40\n assert candidate(s = \"abcdefghij\",t = \"ihgfedcbaj\") == 40\n assert candidate(s = \"abcdefghij\",t = \"jihgfedcba\") == 50\n assert candidate(s = \"abcdef\",t = \"fedcba\") == 18\n assert candidate(s = \"pqrstuvw\",t = \"vutsrqwp\") == 26\n assert candidate(s = \"abcdefghijk\",t = \"fedcbaghijk\") == 18\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"abcdefghijklmnopqrstuvwxyza\") == 26\n assert candidate(s = \"xyzabcdefghijklmnopqrstuvw\",t = \"vutsrqponmlkjihgfedcbazyxw\") == 312\n assert candidate(s = \"thequickbrown\",t = \"nkbrohwiqctue\") == 82\n assert candidate(s = \"lmnopqrt\",t = \"tqrponml\") == 32\n assert candidate(s = \"abcdefghijkmnopqrstuvwxyzl\",t = \"lmnopqrstuvwxyzabcdefghijk\") == 330\n assert candidate(s = \"xyzuvw\",t = \"uvwzyx\") == 18\n assert candidate(s = \"abcdefghilmnopqrstuvwxyzjk\",t = \"jklmnopqrstuvwxyzabcdefghi\") == 306\n assert candidate(s = \"abc\",t = \"cba\") == 4\n assert candidate(s = \"abcdefghijkmnopqrstvuwxyz\",t = \"xyzuvwtpqrsmnkjihgfedcba\") == 297\n assert candidate(s = \"acdefghijklmnopqrstuvwxyzb\",t = \"bzabcdefghijklmnopqrstuvwxy\") == 141\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"qpjohuxivtnrckdsmgflweazyb\") == 246\n assert candidate(s = \"abcdxyz\",t = \"zyxcba\") == 21\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"qrstuvwxyabcdefghijklmnop\") == 288\n assert candidate(s = \"abcdefghijkmnopqrstuvwxyzl\",t = \"lnopqrstuvwxyzabcdefghijkml\") == 337\n assert candidate(s = \"qrstuv\",t = \"tvusqr\") == 18\n assert candidate(s = \"abcdefghijk\",t = \"kabcdefghij\") == 20\n assert candidate(s = \"rplumabc\",t = \"mucrlpba\") == 22\n assert candidate(s = \"mnopqrstuvwxyzabcde\",t = \"edcbamnopqrstuvwxyz\") == 140\n assert candidate(s = \"aeiouy\",t = \"uyioea\") == 16\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"bacdefghijklmnopqrstuvwxyza\") == 28\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy\",t = \"yxwvutsrqponmlkjihgfedcba\") == 312\n assert candidate(s = \"zxcvbnm\",t = \"mnbvcxz\") == 24\n assert candidate(s = \"lkjhgfdsapoiuytrewqmnbvcxz\",t = \"xcvbnmqwertypoiuytsdfghjkl\") == 318\n assert candidate(s = \"xyzxyz\",t = \"zzzyyx\") == 15\n assert candidate(s = \"xyzabcdefghijklmnopqrstuvw\",t = \"stuvwxabcdefghijklmnopqrzy\") == 210\n assert candidate(s = \"abcdefghij\",t = \"ijhgfedcba\") == 50\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",t = \"mnbvcxzlkjhgfdsapoiuytrewq\") == 338\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"bcazdefghijklmnopqrstuvwxy\") == 48\n assert candidate(s = \"abcxyz\",t = \"zyxcba\") == 18\n assert candidate(s = \"qwertyuiop\",t = \"poiuytrewq\") == 50\n assert candidate(s = \"abcdefghijk\",t = \"kijhgfedcba\") == 60\n assert candidate(s = \"abcdefghijlm\",t = \"mljihgfedcba\") == 72\n assert candidate(s = \"mnopqrstu\",t = \"ustqrpmno\") == 40\n assert candidate(s = \"abcdefgh\",t = \"hgfedcba\") == 32\n assert candidate(s = \"qrstuvw\",t = \"tuvwsrq\") == 24\n assert candidate(s = \"abcdefghijklm\",t = \"mlkjihgfedcba\") == 84\n assert candidate(s = \"abcdefghij\",t = \"abcdefghij\") == 0\n assert candidate(s = \"ghijklmn\",t = \"nmlkjihg\") == 32\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n\"bac\"", "\"abcde\"\n\"edbac\""], "hints": ["For each character, find the indices of its occurrences in string s then in string t."], "metadata": {"canonical_parameter_names": ["s", "t"], "leetcode_dataset_entry_point": "Solution().findPermutationDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:43+00:00", "tests_total": 80, "tests_dropped": 2, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "ruby", "interface": {"raw_signature": "def find_permutation_difference(s, t)", "container": null, "callable": "find_permutation_difference", "parameters": [{"name": "s", "type": "String"}, {"name": "t", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3147, "task_id": "taking-maximum-energy-from-the-mystic-dungeon", "difficulty": "Medium", "problem_description": "In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you.\n\nYou have been cursed in such a way that after absorbing energy from magician i, you will be instantly transported to magician (i + k). This process will be repeated until you reach the magician where (i + k) does not exist.\n\nIn other words, you will choose a starting point and then teleport with k jumps until you reach the end of the magicians' sequence, absorbing all the energy during the journey.\n\nYou are given an array energy and an integer k. Return the maximum possible energy you can gain.\n\nNote that when you reach a magician, you must take energy from them, whether it is negative or positive energy.\n\nExample 1:\n\nInput: energy = [5,2,-10,-5,1], k = 3\nOutput: 3\nExplanation: We can gain a total energy of 3 by starting from magician 1 absorbing 2 + 1 = 3.\n\nExample 2:\n\nInput: energy = [-2,-3,-1], k = 2\nOutput: -1\nExplanation: We can gain a total energy of -1 by starting from magician 2.\n\nConstraints:\n\n- 1 <= energy.length <= 10^5\n- -1000 <= energy[i] <= 1000\n- 1 <= k <= energy.length - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(energy = [100, -100, 100, -100, 100, 100],k = 2) == 300\n assert candidate(energy = [-1, -2, -3, -4, -5],k = 3) == -3\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 30\n assert candidate(energy = [1, 2, 3, 4, 5],k = 1) == 15\n assert candidate(energy = [100, -100, 100, -100, 100],k = 1) == 100\n assert candidate(energy = [1, 2, 3, 4, 5, 6],k = 2) == 12\n assert candidate(energy = [-1, -2, -3, -4, -5],k = 2) == -4\n assert candidate(energy = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 4) == -7\n assert candidate(energy = [-2, -3, -1],k = 2) == -1\n assert candidate(energy = [100, -100, 50, -50, 25, -25, 10, -10, 5, -5],k = 2) == 190\n assert candidate(energy = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == 0\n assert candidate(energy = [5, 2, -10, -5, 1],k = 3) == 3\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 18\n assert candidate(energy = [100, -50, 200, -100, 300],k = 2) == 600\n assert candidate(energy = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 5) == -6\n assert candidate(energy = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 6) == -1\n assert candidate(energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 14) == 2\n assert candidate(energy = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100, 110, -120, 130, -140, 150],k = 4) == 360\n assert candidate(energy = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],k = 5) == 10\n assert candidate(energy = [1000, -500, 250, -125, 62, -31, 15, -7, 3, -1, 0, 1, -3, 7, -15, 31, -62, 125, -250, 500],k = 5) == 1000\n assert candidate(energy = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15],k = 3) == 15\n assert candidate(energy = [5, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19],k = 2) == 95\n assert candidate(energy = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 7) == 1\n assert candidate(energy = [100, -10, 50, -20, 30, -40, 20, -30, 10, -5],k = 4) == 140\n assert candidate(energy = [50, -20, 30, -10, 40, -30, 20],k = 3) == 60\n assert candidate(energy = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 4) == 55\n assert candidate(energy = [10, 20, -30, 40, -50, 60, -70, 80],k = 3) == 80\n assert candidate(energy = [-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 = 11) == -100\n assert candidate(energy = [50, -50, 50, -50, 50, -50, 50, -50, 50, -50],k = 5) == 50\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 150\n assert candidate(energy = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -1000, -900, -800, -700, -600, -500, -400, -300, -200, -100],k = 8) == 900\n assert candidate(energy = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100],k = 3) == 100\n assert candidate(energy = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 2) == 150\n assert candidate(energy = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 0\n assert candidate(energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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) == 12\n assert candidate(energy = [2, 3, 5, 8, 13, 21, -34, 55, -89, 144, -233, 377],k = 4) == 440\n assert candidate(energy = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],k = 4) == 15\n assert candidate(energy = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50, -55, -60, -65, -70, -75, -80, -85, -90, -95, -100],k = 5) == -80\n assert candidate(energy = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],k = 3) == 90\n assert candidate(energy = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 100\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 18\n assert candidate(energy = [-10, 50, -30, 20, -10, 40, -50, 60, -70, 80],k = 5) == 80\n assert candidate(energy = [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5],k = 2) == 9\n assert candidate(energy = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100, 110, -120, 130, -140, 150],k = 7) == 150\n assert candidate(energy = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 8) == 1192\n assert candidate(energy = [10, -20, 30, -40, 50, -60, 70, -80],k = 3) == 70\n assert candidate(energy = [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],k = 10) == 15\n assert candidate(energy = [500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500],k = 5) == 300\n assert candidate(energy = [10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110, 120, -130, 140, -150, 160, -170, 180, -190, 200],k = 9) == 200\n assert candidate(energy = [50, -20, 30, -10, 40, -30, 20, -10, 50],k = 3) == 60\n assert candidate(energy = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, 10, 20, 30, 40, 50],k = 6) == 50\n assert candidate(energy = [500, -100, 200, -300, 400, -500, 600, -700, 800, -900],k = 6) == 1100\n assert candidate(energy = [3, 4, -2, 5, -7, 10, -15, 20],k = 3) == 20\n assert candidate(energy = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],k = 9) == 10\n assert candidate(energy = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],k = 2) == -900\n assert candidate(energy = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000],k = 8) == 2000\n assert candidate(energy = [100, -50, 200, -100, 300, 400, -200, 500, -300, 600, 700, -400, 800, 900, -500, 1000],k = 8) == 1500\n assert candidate(energy = [5, 10, -20, 15, -10, 5, 25, -20, 30],k = 3) == 45\n assert candidate(energy = [1000, -900, 800, -700, 600, -500, 400, -300, 200, -100],k = 7) == 700\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == 110\n assert candidate(energy = [-1, 1, -1, 1, -1, 1, -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 = 9) == 1\n assert candidate(energy = [50, 20, -10, 5, -30, 25, 15, -5, 10, 5, -15],k = 6) == 65\n assert candidate(energy = [100, 0, -100, 200, 0, -200, 300, 0, -300, 400, 0, -400, 500, 0, -500, 600, 0, -600, 700, 0],k = 10) == 700\n assert candidate(energy = [10, -5, 15, -10, 20, -25, 30],k = 2) == 75\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 7) == 39\n assert candidate(energy = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500],k = 3) == 500\n assert candidate(energy = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 9) == 1100\n assert candidate(energy = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15],k = 6) == 27\n assert candidate(energy = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80, 90, -90, 100, -100],k = 3) == 100\n assert candidate(energy = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000],k = 2) == 5000\n assert candidate(energy = [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],k = 10) == 600\n assert candidate(energy = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1) == 5500\n assert candidate(energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 10) == 5\n assert candidate(energy = [1000, -500, 250, -125, 62, -31, 15, -7, 3, -1, 0, 1, -2, 3, -4, 5, -6, 7, -8, 9],k = 7) == 989\n assert candidate(energy = [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 = 7) == 80\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 180\n assert candidate(energy = [1000, -500, 250, -125, 62, -31, 15, -7, 3, -1, 0, 1, -2, 4, -8],k = 5) == 969\n assert candidate(energy = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 3) == 1\n assert candidate(energy = [5, -1, 4, -2, 3, -3, 2, -1, 1, -2],k = 2) == 15\n assert candidate(energy = [-100, 200, -300, 400, -500, 600, -700, 800, -900, 1000],k = 5) == 1000\n assert candidate(energy = [1000, -1000, 500, -500, 250, -250, 125, -125],k = 2) == 1875\n assert candidate(energy = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 4) == 4\n assert candidate(energy = [900, 800, 700, 600, 500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500],k = 5) == 1200\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1],k = 7) == 9\n assert candidate(energy = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 2) == 10\n assert candidate(energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 4\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 9) == 330\n assert candidate(energy = [1000, -1000, 500, -500, 250, -250, 125, -125, 63, -63, 32, -32, 16, -16, 8, -8, 4, -4, 2, -2, 1, -1],k = 5) == 775\n assert candidate(energy = [1000, -1000, 500, -500, 250, -250, 125, -125, 62, -62, 31, -31, 15, -15, 7, -7, 3, -3, 1, -1],k = 7) == 882\n assert candidate(energy = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 3) == -80\n assert candidate(energy = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 5) == 60\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 19) == 21\n assert candidate(energy = [-100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100],k = 6) == 300\n assert candidate(energy = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20],k = 10) == -11\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 15\n assert candidate(energy = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 5) == 50\n assert candidate(energy = [500, -500, 500, -500, 500, -500, 500, -500, 500],k = 2) == 2500\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 6) == 440\n assert candidate(energy = [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 = 10) == 57\n assert candidate(energy = [-500, -400, -300, -200, -100, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900],k = 6) == 1200\n assert candidate(energy = [1, -1, 1, -1, 1, -1, 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 = 9) == 1\n assert candidate(energy = [100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100],k = 7) == 100\n assert candidate(energy = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 1) == 1500\n assert candidate(energy = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 4) == 5\n assert candidate(energy = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 5) == -60\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 180\n assert candidate(energy = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 1) == -100\n assert candidate(energy = [5, 15, -25, 35, -45, 55, -65, 75, -85, 95, -105],k = 5) == 95\n assert candidate(energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 6) == 44\n assert candidate(energy = [-5, 5, -10, 10, -15, 15, -20, 20, -25, 25, -30, 30, -35, 35, -40],k = 5) == 35\n assert candidate(energy = [-5, 10, -15, 20, -25, 30, -35, 40, -45, 50, -55, 60, -65, 70, -75, 80, -85, 90, -95, 100],k = 5) == 100\n assert candidate(energy = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],k = 4) == 150\n assert candidate(energy = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],k = 9) == -200\n assert candidate(energy = [-10, 20, -30, 40, -50, 60, -70, 80],k = 4) == 120\n assert candidate(energy = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17, 18, -18, 19, -19, 20, -20],k = 12) == 44\n assert candidate(energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5) == 300\n assert candidate(energy = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20],k = 7) == 19\n assert candidate(energy = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20],k = 8) == 36\n", "comparison": "exact"}, "public_tests": ["[5,2,-10,-5,1]\n3", "[-2,-3,-1]\n2"], "hints": ["Let dp[i] denote the energy we gain starting from index i.", "We can notice, that dp[i] = dp[i + k] + energy[i]."], "metadata": {"canonical_parameter_names": ["energy", "k"], "leetcode_dataset_entry_point": "Solution().maximumEnergy", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:46+00:00", "tests_total": 120, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_energy(energy, k)", "container": null, "callable": "maximum_energy", "parameters": [{"name": "energy", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3148, "task_id": "maximum-difference-score-in-a-grid", "difficulty": "Medium", "problem_description": "You are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value c1 to a cell with the value c2 is c2 - c1.\n\nYou can start at any cell, and you have to make at least one move.\n\nReturn the maximum total score you can achieve.\n\nExample 1:\n\nInput: grid = [[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]\nOutput: 9\nExplanation: We start at the cell (0, 1), and we perform the following moves:\n- Move from the cell (0, 1) to (2, 1) with a score of 7 - 5 = 2.\n- Move from the cell (2, 1) to (2, 2) with a score of 14 - 7 = 7.\nThe total score is 2 + 7 = 9.\n\nExample 2:\n\nInput: grid = [[4,3,2],[3,2,1]]\nOutput: -1\nExplanation: We start at the cell (0, 0), and we perform one move: (0, 0) to (0, 1). The score is 3 - 4 = -1.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 1000\n- 4 <= m * n <= 10^5\n- 1 <= grid[i][j] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == 6\n assert candidate(grid = [[4, 3, 2], [3, 2, 1]]) == -1\n assert candidate(grid = [[100, 90, 80], [70, 60, 50], [40, 30, 20]]) == -10\n assert candidate(grid = [[9, 5, 7, 3], [8, 9, 6, 1], [6, 7, 14, 3], [2, 5, 3, 1]]) == 9\n assert candidate(grid = [[5, 1, 3], [4, 1, 5], [7, 9, 3]]) == 8\n assert candidate(grid = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15]]) == 14\n assert candidate(grid = [[10, 15, 20], [5, 9, 12], [3, 6, 8]]) == 10\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == 80\n assert candidate(grid = [[5, 3, 6, 2], [9, 1, 8, 4], [7, 10, 11, 5]]) == 10\n assert candidate(grid = [[1, 10, 3, 8], [12, 2, 9, 6], [5, 7, 1, 11], [3, 4, 13, 4]]) == 12\n assert candidate(grid = [[5, 3, 11, 12], [9, 10, 13, 14], [1, 2, 4, 8]]) == 11\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8]]) == 7\n assert candidate(grid = [[5, 3, 10, 7], [6, 4, 8, 2], [7, 5, 9, 3]]) == 7\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]]) == 19\n assert candidate(grid = [[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]]) == -1\n assert candidate(grid = [[99999, 99998, 99997, 99996], [99995, 99994, 99993, 99992], [99991, 99990, 99989, 99988], [99987, 99986, 99985, 99984], [99983, 99982, 99981, 99980]]) == -1\n assert candidate(grid = [[1, 100000], [100000, 1], [1, 100000], [100000, 1], [1, 100000], [100000, 1]]) == 99999\n assert candidate(grid = [[1, 1, 1, 1, 1000], [1, 1, 1, 1000, 1], [1, 1, 1000, 1, 1], [1, 1000, 1, 1, 1], [1000, 1, 1, 1, 1]]) == 999\n assert candidate(grid = [[8, 2, 10, 14, 11], [13, 5, 12, 3, 18], [9, 7, 15, 17, 6], [4, 16, 1, 19, 20]]) == 19\n assert candidate(grid = [[100, 99, 98, 97], [96, 95, 94, 93], [92, 91, 90, 89], [88, 87, 86, 85], [84, 83, 82, 81]]) == -1\n assert candidate(grid = [[100, 90, 80, 70, 60], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50], [95, 85, 75, 65, 55], [5, 15, 25, 35, 45]]) == 85\n assert candidate(grid = [[99, 98, 97, 96, 95, 94, 93, 92, 91, 90], [90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 9\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17], [17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18], [18, 16, 14, 12, 10, 8, 6, 4, 2]]) == 17\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13], [2, 4, 6, 8, 10, 12, 14], [15, 17, 19, 21, 23, 25, 27], [16, 18, 20, 22, 24, 26, 28]]) == 27\n assert candidate(grid = [[1, 100000, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 100000]]) == 99999\n assert candidate(grid = [[100, 90, 80, 70, 60, 50], [95, 85, 75, 65, 55, 45], [92, 82, 72, 62, 52, 42], [89, 79, 69, 59, 49, 39], [86, 76, 66, 56, 46, 36], [83, 73, 63, 53, 43, 33]]) == -3\n assert candidate(grid = [[10, 20, 30, 40], [40, 30, 20, 10], [10, 20, 30, 40], [40, 30, 20, 10]]) == 30\n assert candidate(grid = [[5, 1, 2, 3], [4, 6, 1, 5], [7, 1, 8, 9], [3, 2, 6, 4]]) == 8\n assert candidate(grid = [[5, 15, 25, 35, 45], [45, 35, 25, 15, 5], [10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [15, 25, 35, 45, 55]]) == 50\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1000], [1, 1, 1, 1000, 1], [1, 1, 1000, 1, 1], [1, 1000, 1, 1, 1], [1000, 1, 1, 1, 1]]) == 999\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]]) == 19\n assert candidate(grid = [[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]]) == 39\n assert candidate(grid = [[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]]) == 49\n assert candidate(grid = [[5, 2, 3, 8, 1], [9, 6, 7, 4, 10], [15, 12, 13, 14, 11], [1, 8, 5, 2, 6], [7, 4, 3, 9, 12]]) == 12\n assert candidate(grid = [[50, 40, 30, 20, 10], [5, 15, 25, 35, 45], [60, 70, 80, 90, 100], [10, 20, 30, 40, 50], [15, 25, 35, 45, 55]]) == 95\n assert candidate(grid = [[30, 25, 20, 15, 10, 5], [29, 24, 19, 14, 9, 4], [28, 23, 18, 13, 8, 3], [27, 22, 17, 12, 7, 2], [26, 21, 16, 11, 6, 1]]) == -1\n assert candidate(grid = [[1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12], [3, 6, 9, 12, 15, 18], [4, 8, 12, 16, 20, 24], [5, 10, 15, 20, 25, 30], [6, 12, 18, 24, 30, 36]]) == 35\n assert candidate(grid = [[25, 15, 5, 30, 20], [10, 40, 60, 50, 55], [5, 1, 2, 3, 4], [22, 28, 24, 18, 26], [19, 30, 21, 27, 33]]) == 55\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 19\n assert candidate(grid = [[1, 1, 1, 1000], [1, 1, 1000, 1], [1, 1000, 1, 1], [1000, 1, 1, 1], [1, 1, 1, 1]]) == 999\n assert candidate(grid = [[100, 200, 150, 250, 300], [120, 170, 220, 180, 230], [130, 160, 210, 240, 190], [140, 150, 200, 260, 210], [160, 140, 190, 270, 220]]) == 200\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]) == 2\n assert candidate(grid = [[10, 10, 10, 10], [10, 20, 30, 40], [10, 30, 50, 70], [10, 40, 70, 100], [10, 50, 100, 150]]) == 140\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 100], [1, 1, 1, 1, 1, 1, 1, 1, 100, 1], [1, 1, 1, 1, 1, 1, 1, 100, 1, 1], [1, 1, 1, 1, 1, 1, 100, 1, 1, 1], [1, 1, 1, 1, 1, 100, 1, 1, 1, 1], [1, 1, 1, 1, 100, 1, 1, 1, 1, 1], [1, 1, 1, 100, 1, 1, 1, 1, 1, 1], [1, 1, 100, 1, 1, 1, 1, 1, 1, 1], [1, 100, 1, 1, 1, 1, 1, 1, 1, 1], [100, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 99\n assert candidate(grid = [[3, 2, 1, 5, 4], [6, 5, 4, 3, 2], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16], [17, 18, 19, 20, 21]]) == 20\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 3, 4, 5, 6, 7, 8, 9, 10, 1], [3, 4, 5, 6, 7, 8, 9, 10, 1, 2], [4, 5, 6, 7, 8, 9, 10, 1, 2, 3]]) == 9\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]]) == 9\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 1, 9, 1, 9, 1, 9, 1, 9]]) == 8\n assert candidate(grid = [[5, 8, 6, 2, 9], [4, 1, 7, 10, 3], [12, 11, 14, 13, 15], [6, 7, 5, 8, 1], [9, 3, 2, 4, 10]]) == 14\n assert candidate(grid = [[100, 200, 150, 300, 100], [50, 250, 350, 500, 400], [450, 550, 600, 650, 700], [350, 250, 300, 350, 400], [400, 450, 500, 550, 600]]) == 650\n assert candidate(grid = [[1, 2, 3], [2, 1, 3], [3, 2, 1], [1, 3, 2], [2, 1, 3], [3, 2, 1]]) == 2\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [10, 9, 8, 7, 6, 5, 4, 3, 2], [11, 10, 9, 8, 7, 6, 5, 4, 3], [12, 11, 10, 9, 8, 7, 6, 5, 4], [13, 12, 11, 10, 9, 8, 7, 6, 5], [14, 13, 12, 11, 10, 9, 8, 7, 6]]) == 5\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [20, 18, 16, 14, 12, 10, 8, 6, 4, 2], [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]]) == 29\n assert candidate(grid = [[1000, 100, 10, 1], [999, 99, 9, 2], [998, 98, 8, 3], [997, 97, 7, 4], [996, 96, 6, 5], [995, 95, 5, 6], [994, 94, 4, 7], [993, 93, 3, 8], [992, 92, 2, 9], [991, 91, 1, 10]]) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [1, 2, 3, 4, 5]]) == 8\n assert candidate(grid = [[90, 85, 70, 65, 55, 50, 45], [80, 75, 60, 50, 40, 35, 30], [70, 65, 60, 50, 45, 40, 35], [60, 55, 50, 45, 40, 35, 30], [50, 45, 40, 35, 30, 25, 20]]) == 5\n assert candidate(grid = [[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], [3, 3, 3, 3, 3, 3, 3, 3, 3, 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, 4, 4]]) == 3\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [3, 4, 5, 6, 7]]) == 6\n assert candidate(grid = [[100, 200, 300, 400], [200, 100, 400, 300], [300, 400, 100, 200], [400, 300, 200, 100]]) == 300\n assert candidate(grid = [[5, 15, 25, 35, 45], [10, 20, 30, 40, 50], [5, 10, 15, 20, 25], [45, 40, 35, 30, 25], [50, 45, 40, 35, 30]]) == 45\n assert candidate(grid = [[5, 3, 10, 6, 7], [1, 4, 8, 9, 2], [7, 6, 5, 4, 3], [10, 9, 8, 7, 6], [1, 2, 3, 4, 5]]) == 9\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, 3, 5, 7, 9, 11, 13, 15, 17, 19]]) == 18\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 3, 4, 5, 6, 7, 8, 9, 10, 1], [3, 4, 5, 6, 7, 8, 9, 10, 1, 2], [4, 5, 6, 7, 8, 9, 10, 1, 2, 3], [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]]) == 9\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]]) == 19\n assert candidate(grid = [[50, 40, 30, 20, 10], [90, 80, 70, 60, 50], [130, 120, 110, 100, 90], [170, 160, 150, 140, 130], [210, 200, 190, 180, 170]]) == 160\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2]]) == 9\n assert candidate(grid = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65], [30, 40, 50, 60, 70]]) == 60\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 9, 1, 9, 1, 9, 1, 9, 1, 9], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [9, 1, 9, 1, 9, 1, 9, 1, 9, 1]]) == 8\n assert candidate(grid = [[1, 1000, 2, 1000, 3, 1000, 4, 1000, 5, 1000], [1000, 1, 1000, 2, 1000, 3, 1000, 4, 1000, 5], [5, 1000, 4, 1000, 3, 1000, 2, 1000, 1, 1000]]) == 999\n assert candidate(grid = [[4, 1, 9, 13, 17, 20], [5, 2, 11, 14, 18, 21], [6, 3, 12, 15, 19, 22], [7, 4, 10, 16, 23, 24]]) == 23\n assert candidate(grid = [[1000, 999, 998, 997, 996, 995, 994, 993, 992, 991], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]]) == 999\n assert candidate(grid = [[5, 10, 15, 20, 25, 30], [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [7, 14, 21, 28, 35, 42], [8, 16, 24, 32, 40, 48], [9, 18, 27, 36, 45, 54]]) == 53\n assert candidate(grid = [[23, 18, 15, 25, 16], [20, 5, 9, 11, 21], [30, 3, 14, 22, 24], [28, 27, 26, 29, 31], [19, 17, 13, 8, 7]]) == 28\n assert candidate(grid = [[1, 100, 2, 99, 3, 98, 4, 97, 5, 96], [95, 94, 93, 92, 91, 90, 89, 88, 87, 86], [101, 102, 103, 104, 105, 106, 107, 108, 109, 110], [85, 84, 83, 82, 81, 80, 79, 78, 77, 76], [111, 112, 113, 114, 115, 116, 117, 118, 119, 120]]) == 119\n assert candidate(grid = [[100, 90, 80, 70, 60, 50, 40], [95, 85, 75, 65, 55, 45, 35], [90, 80, 70, 60, 50, 40, 30], [85, 75, 65, 55, 45, 35, 25], [80, 70, 60, 50, 40, 30, 20], [75, 65, 55, 45, 35, 25, 15]]) == -5\n assert candidate(grid = [[25, 17, 11, 22, 5, 3], [2, 18, 14, 23, 7, 16], [8, 20, 9, 21, 12, 10]]) == 21\n", "comparison": "exact"}, "public_tests": ["[[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]", "[[4,3,2],[3,2,1]]"], "hints": ["Any path from a cell (x1, y1) to another cell (x2, y2) will always have a score of grid[x2][y2] - grid[x1][y1].", "Let’s say we fix the starting cell (x1, y1), how to the find a cell (x2, y2) such that the value grid[x2][y2] - grid[x1][y1] is the maximum possible?"], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:49+00:00", "tests_total": 83, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def max_score(grid)", "container": null, "callable": "max_score", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3149, "task_id": "find-the-minimum-cost-array-permutation", "difficulty": "Hard", "problem_description": "You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as:\n\nscore(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|\n\nReturn the permutation perm which has the minimum possible score. If multiple permutations exist with this score, return the one that is lexicographically smallest among them.\n\nExample 1:\n\nInput: nums = [1,0,2]\nOutput: [0,1,2]\nExplanation:\nThe lexicographically smallest permutation with minimum cost is [0,1,2]. The cost of this permutation is |0 - 0| + |1 - 2| + |2 - 1| = 2.\n\nExample 2:\n\nInput: nums = [0,2,1]\nOutput: [0,2,1]\nExplanation:\nThe lexicographically smallest permutation with minimum cost is [0,2,1]. The cost of this permutation is |0 - 1| + |2 - 2| + |1 - 0| = 2.\n\nConstraints:\n\n- 2 <= n == nums.length <= 14\n- nums is a permutation of [0, 1, 2, ..., n - 1].\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13]\n assert candidate(nums = [2, 0, 1, 3]) == [0, 1, 2, 3]\n assert candidate(nums = [0, 2, 1]) == [0, 2, 1]\n assert candidate(nums = [1, 2, 0, 3]) == [0, 2, 3, 1]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, 13, 12, 11, 10, 9, 8]) == [0, 4, 3, 5, 2, 6, 1, 7, 11, 10, 12, 9, 13, 8]\n assert candidate(nums = [3, 1, 2, 0]) == [0, 1, 2, 3]\n assert candidate(nums = [2, 0, 3, 1]) == [0, 1, 3, 2]\n assert candidate(nums = [1, 0, 2]) == [0, 1, 2]\n assert candidate(nums = [3, 2, 0, 1]) == [0, 2, 1, 3]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(nums = [3, 0, 2, 1, 7, 4, 6, 5, 11, 8, 10, 9, 13, 12]) == [0, 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 12, 8, 4]\n assert candidate(nums = [6, 10, 1, 13, 2, 3, 11, 4, 9, 5, 0, 12, 8, 7]) == [0, 10, 1, 2, 4, 7, 13, 3, 5, 9, 8, 12, 11, 6]\n assert candidate(nums = [11, 0, 9, 1, 8, 2, 7, 3, 6, 4, 5, 12, 13, 10]) == [0, 1, 3, 7, 6, 8, 4, 9, 2, 5, 10, 13, 12, 11]\n assert candidate(nums = [12, 10, 8, 6, 4, 2, 0, 14, 1, 3, 5, 7, 9, 11]) == [0, 6, 2, 5, 4, 10, 1, 8, 11, 13, 7, 3, 9, 12]\n assert candidate(nums = [11, 7, 8, 5, 6, 2, 4, 10, 3, 0, 9, 1, 12, 13]) == [0, 9, 2, 5, 3, 6, 4, 8, 10, 7, 1, 11, 12, 13]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 12, 13]) == [0, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10, 11, 12, 13]\n assert candidate(nums = [1, 3, 2, 0, 7, 5, 6, 4, 13, 11, 12, 10, 8, 9]) == [0, 3, 2, 5, 6, 7, 12, 10, 11, 9, 13, 8, 4, 1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12]) == [0, 7, 2, 8, 4, 9, 11, 5, 10, 12, 13, 6, 3, 1]\n assert candidate(nums = [13, 11, 9, 7, 5, 3, 1, 12, 10, 8, 6, 4, 2, 0]) == [0, 6, 10, 8, 9, 2, 12, 7, 3, 5, 4, 11, 1, 13]\n assert candidate(nums = [12, 0, 7, 9, 5, 10, 2, 13, 6, 3, 11, 4, 8, 1]) == [0, 1, 13, 7, 2, 6, 4, 9, 3, 11, 10, 5, 8, 12]\n assert candidate(nums = [10, 0, 9, 1, 8, 2, 7, 3, 6, 4, 5, 13, 12, 11]) == [0, 1, 3, 7, 6, 8, 4, 9, 2, 5, 10, 12, 13, 11]\n assert candidate(nums = [6, 12, 4, 8, 0, 10, 13, 2, 3, 9, 7, 1, 5, 11]) == [0, 4, 2, 7, 3, 8, 9, 10, 5, 12, 1, 11, 13, 6]\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12]) == [0, 1, 3, 5, 7, 9, 11, 13, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [2, 11, 8, 0, 7, 10, 3, 6, 13, 1, 9, 5, 12, 4]) == [0, 3, 6, 7, 4, 11, 1, 9, 10, 5, 13, 12, 8, 2]\n assert candidate(nums = [5, 7, 10, 1, 13, 3, 9, 0, 6, 4, 2, 8, 11, 12]) == [0, 7, 1, 3, 5, 8, 11, 2, 10, 12, 13, 4, 9, 6]\n assert candidate(nums = [1, 3, 2, 0, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12]) == [0, 3, 2, 5, 7, 9, 11, 13, 12, 10, 8, 6, 4, 1]\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 1, 3, 5, 7, 9, 11, 13]) == [0, 7, 10, 5, 9, 11, 12, 13, 6, 3, 8, 4, 2, 1]\n assert candidate(nums = [13, 9, 3, 2, 6, 1, 0, 12, 5, 4, 8, 7, 11, 10]) == [0, 6, 4, 2, 3, 9, 1, 5, 8, 10, 12, 7, 11, 13]\n assert candidate(nums = [12, 8, 5, 0, 7, 2, 9, 13, 1, 10, 4, 6, 11, 3]) == [0, 3, 5, 2, 8, 1, 13, 7, 4, 10, 9, 6, 11, 12]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 0, 3, 5, 7, 9, 11, 13, 1]) == [0, 6, 2, 7, 9, 10, 4, 1, 13, 12, 11, 5, 8, 3]\n assert candidate(nums = [13, 8, 10, 12, 2, 3, 5, 9, 4, 0, 6, 7, 11, 1]) == [0, 9, 7, 11, 12, 3, 5, 6, 10, 2, 4, 8, 1, 13]\n assert candidate(nums = [3, 2, 13, 9, 1, 10, 8, 7, 12, 6, 5, 4, 0, 11]) == [0, 4, 10, 5, 11, 13, 2, 1, 12, 8, 6, 7, 9, 3]\n assert candidate(nums = [10, 13, 3, 5, 9, 1, 6, 11, 0, 8, 7, 12, 4, 2]) == [0, 5, 3, 2, 13, 1, 8, 9, 4, 12, 11, 7, 6, 10]\n assert candidate(nums = [13, 0, 11, 2, 9, 4, 7, 6, 1, 10, 3, 8, 5, 12]) == [0, 1, 8, 6, 7, 11, 2, 3, 10, 9, 4, 5, 12, 13]\n assert candidate(nums = [3, 6, 13, 7, 11, 0, 8, 12, 2, 1, 4, 9, 5, 10]) == [0, 5, 1, 9, 11, 4, 10, 13, 2, 8, 6, 12, 7, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 13, 12, 11]) == [0, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10, 12, 13, 11]\n assert candidate(nums = [4, 0, 8, 2, 12, 6, 10, 3, 1, 7, 13, 5, 11, 9]) == [0, 1, 8, 2, 3, 7, 9, 13, 10, 6, 5, 11, 12, 4]\n assert candidate(nums = [4, 5, 13, 0, 2, 7, 10, 9, 12, 6, 11, 3, 1, 8]) == [0, 3, 11, 10, 6, 9, 7, 5, 1, 12, 8, 13, 2, 4]\n assert candidate(nums = [0, 3, 7, 2, 5, 13, 8, 10, 4, 6, 11, 9, 1, 12]) == [0, 12, 13, 5, 4, 8, 6, 9, 11, 10, 7, 2, 3, 1]\n assert candidate(nums = [10, 8, 13, 11, 1, 9, 0, 2, 4, 3, 7, 5, 6, 12]) == [0, 4, 8, 1, 6, 11, 3, 9, 5, 12, 13, 2, 7, 10]\n assert candidate(nums = [5, 0, 11, 3, 8, 10, 7, 4, 2, 12, 9, 13, 1, 6]) == [0, 1, 3, 8, 4, 7, 6, 13, 11, 2, 12, 9, 10, 5]\n assert candidate(nums = [2, 5, 1, 6, 3, 4, 0, 13, 10, 11, 8, 9, 7, 12]) == [0, 6, 10, 8, 11, 9, 12, 13, 7, 3, 4, 5, 1, 2]\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13]) == [0, 1, 3, 5, 7, 9, 11, 13, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [4, 7, 11, 1, 13, 2, 8, 0, 10, 9, 12, 3, 6, 5]) == [0, 7, 1, 3, 11, 2, 5, 12, 10, 8, 9, 6, 13, 4]\n assert candidate(nums = [11, 12, 13, 0, 7, 10, 2, 9, 3, 1, 6, 5, 8, 4]) == [0, 3, 8, 12, 1, 9, 7, 4, 13, 2, 6, 10, 5, 11]\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10, 11, 12, 13]) == [0, 3, 4, 2, 5, 1, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(nums = [13, 11, 9, 7, 5, 3, 1, 0, 2, 4, 6, 8, 10, 12]) == [0, 7, 3, 5, 4, 9, 2, 8, 11, 1, 6, 10, 12, 13]\n assert candidate(nums = [1, 3, 0, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12]) == [0, 2, 3, 5, 7, 9, 11, 13, 12, 10, 8, 6, 4, 1]\n assert candidate(nums = [9, 5, 1, 3, 0, 4, 7, 11, 2, 8, 6, 12, 10, 13]) == [0, 4, 3, 5, 1, 2, 8, 6, 10, 12, 13, 11, 7, 9]\n assert candidate(nums = [9, 3, 0, 7, 6, 13, 10, 4, 8, 1, 12, 5, 11, 2]) == [0, 2, 13, 5, 11, 12, 10, 6, 4, 7, 3, 1, 9, 8]\n assert candidate(nums = [12, 11, 7, 9, 4, 6, 0, 3, 1, 8, 13, 10, 5, 2]) == [0, 6, 2, 13, 10, 11, 1, 8, 9, 3, 4, 7, 5, 12]\n assert candidate(nums = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12]) == [0, 7, 2, 8, 4, 9, 11, 5, 10, 12, 13, 6, 3, 1]\n assert candidate(nums = [13, 11, 12, 10, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1]) == [0, 12, 2, 10, 3, 6, 7, 9, 5, 8, 4, 11, 1, 13]\n assert candidate(nums = [12, 1, 4, 8, 3, 7, 10, 5, 2, 11, 9, 6, 0, 13]) == [0, 1, 8, 3, 4, 2, 12, 9, 10, 6, 5, 7, 11, 13]\n assert candidate(nums = [1, 4, 2, 13, 7, 9, 12, 5, 3, 11, 6, 0, 8, 10]) == [0, 11, 6, 10, 13, 3, 2, 8, 12, 9, 5, 7, 4, 1]\n assert candidate(nums = [6, 0, 3, 5, 2, 8, 1, 7, 9, 13, 10, 4, 11, 12]) == [0, 1, 4, 11, 10, 12, 13, 9, 8, 5, 3, 2, 6, 7]\n assert candidate(nums = [2, 4, 1, 6, 12, 0, 3, 9, 10, 13, 5, 8, 7, 11]) == [0, 5, 3, 6, 10, 8, 11, 13, 9, 7, 12, 4, 1, 2]\n assert candidate(nums = [1, 12, 6, 3, 7, 2, 0, 9, 5, 8, 13, 10, 4, 11]) == [0, 6, 2, 3, 5, 8, 9, 7, 4, 12, 10, 11, 13, 1]\n assert candidate(nums = [10, 8, 6, 4, 2, 0, 13, 11, 9, 7, 5, 3, 1, 12]) == [0, 5, 2, 4, 3, 11, 7, 9, 8, 1, 12, 13, 6, 10]\n assert candidate(nums = [9, 7, 13, 5, 1, 0, 6, 2, 12, 3, 11, 4, 8, 10]) == [0, 4, 11, 8, 12, 10, 13, 2, 7, 1, 5, 6, 3, 9]\n assert candidate(nums = [1, 2, 0, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 13]) == [0, 2, 4, 6, 8, 10, 12, 13, 11, 9, 7, 5, 3, 1]\n assert candidate(nums = [1, 7, 0, 12, 9, 3, 11, 5, 8, 2, 6, 13, 4, 10]) == [0, 2, 9, 4, 12, 3, 5, 7, 8, 10, 13, 11, 6, 1]\n assert candidate(nums = [11, 1, 6, 13, 4, 10, 3, 8, 0, 9, 5, 7, 2, 12]) == [0, 1, 8, 5, 2, 12, 13, 3, 4, 6, 10, 9, 7, 11]\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 0, 1, 2, 3, 4, 5, 6]) == [0, 7, 1, 8, 2, 9, 3, 10, 4, 11, 5, 12, 6, 13]\n assert candidate(nums = [7, 1, 6, 2, 5, 3, 4, 0, 13, 12, 11, 10, 9, 8]) == [0, 1, 3, 5, 4, 6, 2, 7, 11, 10, 12, 9, 13, 8]\n assert candidate(nums = [0, 3, 2, 1, 5, 4, 7, 6, 10, 9, 12, 11, 14, 13]) == [0, 2, 3, 5, 7, 9, 11, 13, 12, 10, 8, 6, 4, 1]\n assert candidate(nums = [3, 0, 1, 2, 7, 4, 5, 6, 11, 8, 9, 10, 13, 12]) == [0, 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 12, 8, 4]\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11]) == [0, 8, 3, 9, 5, 10, 12, 6, 11, 13, 7, 4, 2, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 13, 12]) == [0, 3, 2, 4, 1, 5, 9, 8, 10, 7, 11, 13, 12, 6]\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 0, 2, 1, 3, 5, 7, 9, 11]) == [0, 6, 1, 8, 2, 7, 11, 13, 5, 10, 3, 9, 12, 4]\n assert candidate(nums = [8, 0, 4, 3, 2, 1, 7, 5, 13, 6, 9, 12, 10, 11]) == [0, 1, 3, 4, 2, 5, 7, 6, 9, 10, 12, 11, 13, 8]\n assert candidate(nums = [2, 0, 3, 1, 6, 4, 5, 8, 10, 12, 7, 9, 13, 11]) == [0, 1, 3, 5, 6, 10, 8, 11, 13, 12, 9, 7, 4, 2]\n assert candidate(nums = [11, 9, 8, 7, 13, 12, 0, 3, 2, 1, 6, 5, 4, 10]) == [0, 6, 1, 9, 2, 8, 3, 7, 10, 13, 4, 12, 5, 11]\n assert candidate(nums = [6, 0, 13, 7, 2, 8, 1, 5, 10, 12, 4, 3, 11, 9]) == [0, 1, 4, 10, 8, 5, 7, 3, 11, 12, 9, 13, 2, 6]\n assert candidate(nums = [13, 2, 6, 10, 9, 8, 5, 11, 0, 3, 12, 7, 4, 1]) == [0, 8, 4, 12, 7, 11, 10, 3, 9, 5, 6, 2, 1, 13]\n assert candidate(nums = [1, 5, 3, 7, 9, 2, 8, 0, 6, 4, 13, 11, 10, 12]) == [0, 7, 3, 2, 5, 8, 4, 9, 11, 12, 13, 10, 6, 1]\n assert candidate(nums = [4, 10, 6, 2, 0, 7, 1, 8, 11, 5, 3, 9, 13, 12]) == [0, 4, 2, 3, 10, 1, 6, 9, 11, 13, 12, 8, 7, 5]\n assert candidate(nums = [8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 11, 13, 10, 12]) == [0, 4, 2, 3, 6, 1, 5, 7, 8, 9, 12, 13, 11, 10]\n assert candidate(nums = [5, 3, 4, 1, 2, 0, 13, 11, 12, 10, 8, 9, 6, 7]) == [0, 3, 1, 4, 2, 5, 12, 8, 10, 9, 11, 7, 13, 6]\n assert candidate(nums = [12, 10, 8, 6, 4, 2, 0, 13, 11, 9, 7, 5, 3, 1]) == [0, 5, 4, 11, 8, 2, 13, 7, 10, 9, 1, 6, 3, 12]\n assert candidate(nums = [5, 4, 10, 11, 7, 12, 6, 0, 13, 2, 1, 8, 9, 3]) == [0, 7, 4, 1, 10, 2, 9, 11, 3, 13, 8, 12, 5, 6]\n assert candidate(nums = [6, 4, 2, 0, 1, 3, 8, 5, 7, 10, 12, 9, 14, 11]) == [0, 2, 4, 1, 3, 5, 7, 8, 11, 13, 12, 10, 9, 6]\n assert candidate(nums = [0, 11, 1, 9, 3, 5, 2, 7, 12, 4, 10, 6, 8, 13]) == [0, 2, 4, 5, 9, 3, 6, 7, 11, 8, 12, 13, 10, 1]\n assert candidate(nums = [2, 9, 13, 0, 6, 11, 7, 4, 12, 5, 8, 3, 10, 1]) == [0, 3, 7, 6, 4, 11, 5, 9, 1, 13, 8, 10, 12, 2]\n assert candidate(nums = [2, 0, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 13]) == [0, 1, 2, 4, 6, 8, 10, 12, 13, 11, 9, 7, 5, 3]\n assert candidate(nums = [6, 0, 13, 1, 11, 5, 3, 4, 9, 7, 2, 12, 10, 8]) == [0, 1, 3, 5, 7, 9, 8, 13, 2, 10, 12, 11, 4, 6]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 7, 6, 9, 8, 11, 10, 13, 12]) == [0, 3, 2, 4, 1, 5, 7, 9, 11, 13, 12, 10, 8, 6]\n assert candidate(nums = [13, 1, 5, 2, 9, 6, 3, 7, 11, 8, 10, 0, 12, 4]) == [0, 1, 3, 6, 5, 2, 11, 8, 7, 9, 10, 4, 13, 12]\n assert candidate(nums = [12, 13, 6, 10, 1, 9, 3, 5, 7, 11, 2, 4, 8, 0]) == [0, 13, 1, 4, 6, 2, 10, 3, 11, 9, 5, 7, 8, 12]\n assert candidate(nums = [13, 0, 1, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6, 7]) == [0, 1, 2, 4, 6, 12, 3, 8, 9, 11, 5, 10, 7, 13]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 0]) == [0, 5, 6, 4, 7, 3, 8, 2, 9, 1, 13, 10, 12, 11]\n assert candidate(nums = [9, 4, 6, 0, 7, 5, 3, 2, 1, 8]) == [0, 3, 6, 2, 7, 4, 5, 1, 8, 9]\n assert candidate(nums = [1, 12, 7, 4, 10, 6, 13, 3, 5, 8, 2, 11, 0, 9]) == [0, 12, 1, 10, 11, 4, 3, 7, 5, 8, 9, 13, 6, 2]\n assert candidate(nums = [3, 12, 1, 5, 11, 8, 0, 13, 6, 10, 4, 7, 9, 2]) == [0, 2, 13, 7, 11, 4, 10, 9, 12, 1, 6, 8, 5, 3]\n assert candidate(nums = [12, 0, 1, 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == [0, 1, 2, 13, 3, 8, 7, 9, 6, 10, 5, 11, 4, 12]\n", "comparison": "exact"}, "public_tests": ["[1,0,2]", "[0,2,1]"], "hints": ["The score function is cyclic, so we can always set perm[0] = 0 for the smallest lexical order.", "It’s similar to the Traveling Salesman Problem. Use Dynamic Programming.", "Use a bitmask to track which elements have been assigned to perm."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findPermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:51+00:00", "tests_total": 113, "tests_dropped": 17, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "bitmask"]}, "language": "ruby", "interface": {"raw_signature": "def find_permutation(nums)", "container": null, "callable": "find_permutation", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3151, "task_id": "special-array-i", "difficulty": "Easy", "problem_description": "An array is considered special if the parity of every pair of adjacent elements is different. In other words, one element in each pair must be even, and the other must be odd.\n\nYou are given an array of integers nums. Return true if nums is a special array, otherwise, return false.\n\nExample 1:\n\nInput: nums = [1]\nOutput: true\nExplanation:\nThere is only one element. So the answer is true.\n\nExample 2:\n\nInput: nums = [2,1,4]\nOutput: true\nExplanation:\nThere is only two pairs: (2,1) and (1,4), and both of them contain numbers with different parity. So the answer is true.\n\nExample 3:\n\nInput: nums = [4,3,1,6]\nOutput: false\nExplanation:\nnums[1] and nums[2] are both odd. So the answer is false.\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 = [100, 99, 100]) == True\n assert candidate(nums = [5, 2, 7, 8]) == True\n assert candidate(nums = [20, 30, 40, 50, 60]) == False\n assert candidate(nums = [3, 8, 3, 8, 3, 8]) == True\n assert candidate(nums = [2, 3, 4, 5]) == True\n assert candidate(nums = [10, 11, 12, 13]) == True\n assert candidate(nums = [3, 6, 3, 6]) == True\n assert candidate(nums = [2, 4, 6, 8, 10]) == False\n assert candidate(nums = [1, 3, 5, 7, 9]) == False\n assert candidate(nums = [1]) == True\n assert candidate(nums = [2, 3]) == True\n assert candidate(nums = [100]) == True\n assert candidate(nums = [10, 11, 10, 11]) == True\n assert candidate(nums = [1, 2, 3, 4, 5]) == True\n assert candidate(nums = [4, 3, 1, 6]) == False\n assert candidate(nums = [50, 51, 50, 51, 50]) == True\n assert candidate(nums = [15, 14, 13, 12, 11]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [2, 1, 4]) == True\n assert candidate(nums = [20, 19, 18, 17, 16]) == True\n assert candidate(nums = [5, 8, 7, 2]) == True\n assert candidate(nums = [15]) == True\n assert candidate(nums = [50, 51, 50, 51]) == True\n assert candidate(nums = [2, 3, 2, 3]) == True\n assert candidate(nums = [1, 2]) == True\n assert candidate(nums = [1, 3, 5, 7]) == False\n assert candidate(nums = [98, 99]) == True\n assert candidate(nums = [100, 99, 100, 99]) == True\n assert candidate(nums = [5]) == True\n assert candidate(nums = [2, 4, 6, 8]) == False\n assert candidate(nums = [7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2]) == True\n assert candidate(nums = [37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]) == True\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [7, 2, 9, 4, 11, 6, 13, 8, 15, 10]) == True\n assert candidate(nums = [60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50]) == True\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == False\n assert candidate(nums = [89, 90, 91, 92, 93, 94, 95, 96, 97, 98]) == True\n assert candidate(nums = [89, 90, 89, 90, 89, 90, 89, 90, 89, 90]) == True\n assert candidate(nums = [25, 50, 25, 50, 25, 50, 25, 50, 25]) == True\n assert candidate(nums = [99, 2, 97, 4, 95, 6, 93, 8, 91, 10]) == True\n assert candidate(nums = [61, 62, 63, 64, 65, 66, 67, 68, 69, 70]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6]) == False\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == True\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == True\n assert candidate(nums = [10, 1, 20, 3, 40, 5, 60, 7, 80, 9]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == False\n assert candidate(nums = [10, 20, 30, 40, 50, 51, 52, 53, 54, 55]) == False\n assert candidate(nums = [1, 4, 3, 8, 5, 12, 7, 16, 9, 20]) == True\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65]) == False\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == True\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]) == True\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == False\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == False\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == False\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == True\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 51]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == False\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == False\n assert candidate(nums = [2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == True\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == True\n assert candidate(nums = [61, 62, 63, 64, 65, 66, 67, 68, 69]) == True\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16]) == False\n assert candidate(nums = [83, 84, 85, 86, 87, 88, 89, 90, 91, 92]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]) == True\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == True\n assert candidate(nums = [25, 26, 27, 28, 29, 30]) == True\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == True\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5]) == True\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == False\n assert candidate(nums = [100, 99, 100, 99, 100, 99]) == True\n assert candidate(nums = [23, 22, 25, 24, 27, 26, 29, 28, 31, 30]) == True\n assert candidate(nums = [31, 22, 33, 24, 35, 26, 37, 28, 39, 20]) == True\n assert candidate(nums = [100, 99, 98, 97, 96]) == True\n assert candidate(nums = [47, 48, 49, 50, 51, 52, 53, 54, 55, 56]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [5, 4, 3, 2, 1]) == True\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == True\n assert candidate(nums = [97, 98, 95, 96, 93, 94]) == True\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == True\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 100]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == False\n assert candidate(nums = [99, 100, 99, 100, 99, 100, 99, 100, 99, 100]) == True\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == True\n assert candidate(nums = [100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99]) == True\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]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14]) == False\n assert candidate(nums = [49, 50, 49, 50, 49, 50, 49, 50, 49, 50]) == True\n assert candidate(nums = [42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30]) == True\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == True\n assert candidate(nums = [99, 2, 99, 2, 99, 2, 99, 2, 99, 2]) == True\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13]) == False\n assert candidate(nums = [97, 98, 99, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(nums = [3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == False\n assert candidate(nums = [51, 52, 51, 52, 51, 52, 51, 52, 51, 52, 51, 52]) == True\n assert candidate(nums = [5, 8, 3, 12, 7, 14, 9, 16, 11, 18]) == True\n assert candidate(nums = [7, 8, 7, 8, 7, 8, 7]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == False\n assert candidate(nums = [97, 98, 99, 100, 1, 2, 3, 4]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [82, 81, 82, 83, 82, 81, 82, 83, 82, 81]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == False\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == True\n assert candidate(nums = [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == True\n assert candidate(nums = [50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51]) == True\n", "comparison": "exact"}, "public_tests": ["[1]", "[2,1,4]", "[4,3,1,6]"], "hints": ["Try to check the parity of each element and its previous element."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().isArraySpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:53+00:00", "tests_total": 127, "tests_dropped": 9, "flags": [], "topic_tags": ["array"]}, "language": "ruby", "interface": {"raw_signature": "def is_array_special(nums)", "container": null, "callable": "is_array_special", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3152, "task_id": "special-array-ii", "difficulty": "Medium", "problem_description": "An array is considered special if every pair of its adjacent elements contains two numbers with different parity.\n\nYou are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [from_i, to_i] your task is to check that subarray nums[from_i..to_i] is special or not.\n\nReturn an array of booleans answer such that answer[i] is true if nums[from_i..to_i] is special.\n\nExample 1:\n\nInput: nums = [3,4,1,2,6], queries = [[0,4]]\nOutput: [false]\nExplanation:\nThe subarray is [3,4,1,2,6]. 2 and 6 are both even.\n\nExample 2:\n\nInput: nums = [4,3,1,6], queries = [[0,2],[2,3]]\nOutput: [false,true]\nExplanation:\n1. The subarray is [4,3,1]. 3 and 1 are both odd. So the answer to this query is false.\n2. The subarray is [1,6]. There is only one pair: (1,6) and it contains numbers with different parity. So the answer to this query is true.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- 1 <= queries.length <= 10^5\n- queries[i].length == 2\n- 0 <= queries[i][0] <= queries[i][1] <= nums.length - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2],queries = [[0, 4]]) == [False]\n assert candidate(nums = [2, 4, 6, 8, 10],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 4]]) == [True, True, True, True, True, False]\n assert candidate(nums = [1, 3, 5, 7, 9],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [False, False, False, False]\n assert candidate(nums = [1, 3, 5, 7, 9],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 4]]) == [True, True, True, True, True, False]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [True, True, True, True]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 0], [1, 2], [2, 4]]) == [True, True, True]\n assert candidate(nums = [3, 4, 1, 2, 6],queries = [[0, 4]]) == [False]\n assert candidate(nums = [1, 3, 5, 7, 9],queries = [[0, 4]]) == [False]\n assert candidate(nums = [4, 3, 1, 6],queries = [[0, 2], [2, 3]]) == [False, True]\n assert candidate(nums = [10, 15, 20, 25, 30],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4]]) == [True, True, True, True, True]\n assert candidate(nums = [2, 2, 2, 2],queries = [[0, 1], [1, 2], [2, 3]]) == [False, False, False]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [True, True, True, True, True]\n assert candidate(nums = [2, 4, 6, 8, 10],queries = [[0, 4]]) == [False]\n assert candidate(nums = [1, 2, 3, 4, 5, 6],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [True, True, True, True, True]\n assert candidate(nums = [1, 2, 1, 2, 1],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 4]]) == [True, True, True, True, True, True]\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164, 175, 186, 197, 208, 219],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [True, True, True, True, True]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11],queries = [[0, 9], [2, 7], [4, 5], [1, 8], [3, 6]]) == [False, True, True, True, True]\n assert candidate(nums = [42, 23, 17, 34, 19, 28, 39, 44, 27, 56, 65, 74, 83, 92, 101],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 7], [8, 14]]) == [False, False, True, True, True, True, True, False, True]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 13], [2, 5], [6, 8], [10, 12]]) == [True, True, True, True]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115],queries = [[0, 15], [0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 7], [0, 0], [15, 15]]) == [True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1],queries = [[0, 4], [5, 9], [10, 14], [2, 8]]) == [False, False, False, False]\n assert candidate(nums = [2, 3, 5, 8, 10, 13, 17, 20, 22, 25],queries = [[0, 9], [1, 3], [5, 7], [8, 9]]) == [False, False, False, True]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [0, 15], [1, 4], [2, 9]]) == [False, False, False, False, False, False, False, False, False, False, False]\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],queries = [[0, 5], [5, 10], [10, 15], [15, 20], [20, 25], [0, 29]]) == [True, True, True, True, True, True]\n assert candidate(nums = [8, 10, 12, 14, 16, 18, 20, 22, 24],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [0, 8], [1, 6]]) == [False, False, False, False, False, False]\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 10, 11, 10, 11],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [True, True, True, True, True]\n assert candidate(nums = [2, 5, 8, 3, 6, 7, 9, 10],queries = [[0, 3], [1, 5], [4, 7], [0, 7]]) == [True, True, False, False]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [False, False, False, False, False]\n assert candidate(nums = [100000, 99999, 100000, 99999, 100000, 99999, 100000, 99999, 100000, 99999],queries = [[0, 4], [5, 9], [0, 9]]) == [True, True, True]\n assert candidate(nums = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9],queries = [[0, 9], [0, 2], [4, 5], [6, 8]]) == [False, False, True, False]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 9], [2, 7], [4, 5], [1, 8]]) == [True, True, True, True]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14]]) == [False, False, False, False, False, False]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [True, True, True, True, True]\n assert candidate(nums = [2, 3, 5, 7, 11, 13],queries = [[0, 5], [1, 4], [2, 3], [0, 1], [3, 5]]) == [False, False, False, True, False]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 19], [5, 15], [10, 14], [0, 0], [19, 19]]) == [True, True, True, True, True]\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14],queries = [[0, 19], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19]]) == [False, False, True, True, False, True, True, False, True, True, True, True, False, True, True, False, True, True, False, True]\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == [True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]]) == [True, True, True, True, True, True, True]\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],queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25], [5, 24], [6, 23], [7, 22], [8, 21], [9, 20]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32],queries = [[0, 15], [1, 14], [2, 13], [3, 12], [4, 11], [5, 10], [6, 9], [7, 8], [0, 7], [7, 14], [1, 6], [8, 15]]) == [False, False, False, False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [[0, 21], [1, 20], [2, 19], [3, 18], [4, 17]]) == [False, False, False, False, False]\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],queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25]]) == [True, True, True, True, True]\n assert candidate(nums = [99999, 1, 99998, 2, 99997, 3, 99996, 4, 99995, 5],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [False, False, False, False, False, False, False]\n assert candidate(nums = [2, 3, 4, 3, 2, 3, 4, 3, 2, 3],queries = [[0, 9], [2, 7], [4, 5], [1, 8]]) == [True, True, True, True]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 7], [8, 14]]) == [True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],queries = [[0, 9], [1, 8], [3, 7], [5, 9]]) == [True, True, True, True]\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],queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25], [5, 24], [6, 23], [7, 22], [8, 21], [9, 20]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9]]) == [False, False, False, False, False, False]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [True, True, True, True, True]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19],queries = [[0, 1], [1, 2], [0, 3], [3, 7], [0, 7]]) == [True, False, False, False, False]\n assert candidate(nums = [100, 201, 102, 203, 104, 205, 106, 207, 108, 209, 110],queries = [[0, 10], [1, 9], [2, 8], [3, 7], [4, 6], [0, 1], [5, 5]]) == [True, True, True, True, True, True, True]\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],queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25]]) == [True, True, True, True, True]\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [0, 7]]) == [True, True, True, True, True, True, True, True]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[0, 9], [1, 3], [2, 5], [3, 7], [4, 9]]) == [False, False, False, False, False]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 9]]) == [False, False, False, False, False, False]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],queries = [[0, 9], [1, 3], [4, 7], [6, 8]]) == [False, False, True, True]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [False, False, False, False, False]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[0, 3], [4, 7], [5, 9], [1, 8]]) == [False, False, False, False]\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],queries = [[0, 9], [5, 14], [10, 19], [0, 19], [1, 18]]) == [True, True, True, True, True]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],queries = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == [False, False, False, False, False, False, False, False]\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],queries = [[0, 9], [2, 7], [4, 5], [1, 8]]) == [True, True, True, True]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]]) == [True, True, True, True, True, True, True]\n assert candidate(nums = [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],queries = [[0, 29], [10, 29], [1, 28], [2, 27], [3, 26]]) == [True, True, True, True, True]\n assert candidate(nums = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 5], [5, 9]]) == [True, True, True, True, True, True, True]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2],queries = [[0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == [True, True, True, True, True, True]\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [False, False, False, False, False, False, False, False, False]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],queries = [[0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14]]) == [False, False, False, False, False, False, False]\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7],queries = [[0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14]]) == [True, True, True, True, True, True, True]\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],queries = [[0, 9], [5, 14], [10, 19], [0, 19], [1, 18]]) == [True, True, True, True, True]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 3], [4, 7], [5, 9], [1, 8]]) == [False, False, False, False]\n", "comparison": "exact"}, "public_tests": ["[3,4,1,2,6]\n[[0,4]]", "[4,3,1,6]\n[[0,2],[2,3]]"], "hints": ["Try to split the array into some non-intersected continuous special subarrays.", "For each query check that the first and the last elements of that query are in the same subarray or not."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().isArraySpecial", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:56+00:00", "tests_total": 83, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "binary-search", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def is_array_special(nums, queries)", "container": null, "callable": "is_array_special", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3153, "task_id": "sum-of-digit-differences-of-all-pairs", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of positive integers where all integers have the same number of digits.\n\nThe digit difference between two integers is the count of different digits that are in the same position in the two integers.\n\nReturn the sum of the digit differences between all pairs of integers in nums.\n\nExample 1:\n\nInput: nums = [13,23,12]\nOutput: 4\nExplanation:\nWe have the following:\n- The digit difference between 13 and 23 is 1.\n- The digit difference between 13 and 12 is 1.\n- The digit difference between 23 and 12 is 2.\nSo the total sum of digit differences between all pairs of integers is 1 + 1 + 2 = 4.\n\nExample 2:\n\nInput: nums = [10,10,10,10]\nOutput: 0\nExplanation:\nAll the integers in the array are the same. So the total sum of digit differences between all pairs of integers will be 0.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] < 10^9\n- All integers in nums have the same number of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [12345, 54321, 13245]) == 11\n assert candidate(nums = [10, 10, 10, 10]) == 0\n assert candidate(nums = [123, 234, 345]) == 9\n assert candidate(nums = [123, 456, 789]) == 9\n assert candidate(nums = [987, 876, 765, 654]) == 18\n assert candidate(nums = [99999, 99999, 99999]) == 0\n assert candidate(nums = [13, 23, 12]) == 4\n assert candidate(nums = [123, 321, 213]) == 7\n assert candidate(nums = [987, 876, 765, 654, 543]) == 30\n assert candidate(nums = [111, 222, 333, 444]) == 18\n assert candidate(nums = [5678, 6789, 7890]) == 12\n assert candidate(nums = [123456, 234561, 345612, 456123, 561234, 612345]) == 90\n assert candidate(nums = [191919191, 282828282, 373737373, 464646464, 555555555]) == 90\n assert candidate(nums = [123, 456, 789, 987, 654, 321, 111, 222, 333, 444, 555, 666, 777, 888, 999]) == 294\n assert candidate(nums = [56789, 98765, 58679, 67985]) == 24\n assert candidate(nums = [1234, 2345, 3456, 4567, 5678]) == 40\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210, 432109, 321098, 210987, 109876]) == 216\n assert candidate(nums = [1000001, 2000002, 3000003, 4000004, 5000005, 6000006, 7000007]) == 42\n assert candidate(nums = [55555, 55554, 55545, 55455, 54555, 45555, 55555, 55555, 55555, 55555, 55555, 55555]) == 55\n assert candidate(nums = [101010, 202020, 303030, 404040, 505050, 606060, 707070, 808080, 909090]) == 108\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 324\n assert candidate(nums = [121212, 212121, 121211, 212112, 112121, 221212, 122121, 211221]) == 95\n assert candidate(nums = [56789, 56788, 56787, 56786, 56785]) == 10\n assert candidate(nums = [1999999, 2999998, 3999997, 4999996, 5999995, 6999994, 7999993, 8999992, 9999991]) == 72\n assert candidate(nums = [1234567, 7654321, 1357924, 8642035, 9876543, 3210987]) == 96\n assert candidate(nums = [123456789, 111222333, 222333444, 333444555, 444555666]) == 85\n assert candidate(nums = [112233, 223344, 334455, 445566, 556677, 667788, 778899, 889900, 990011]) == 216\n assert candidate(nums = [55555, 54445, 53335, 52225, 51115, 50005, 49995, 48885, 47775, 46665]) == 159\n assert candidate(nums = [123456789, 987654321, 111222333, 333222111]) == 46\n assert candidate(nums = [123123123, 234234234, 345345345, 456456456, 567567567, 678678678, 789789789, 890890890, 901901901]) == 324\n assert candidate(nums = [101010, 202020, 303030, 404040, 505050]) == 30\n assert candidate(nums = [1001, 1100, 1110, 1111, 1011, 1101]) == 25\n assert candidate(nums = [100000000, 99999999, 88888888, 77777777, 66666666, 55555555]) == 125\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000]) == 10\n assert candidate(nums = [987654321, 876543219, 765432198, 654321987, 543219876, 432198765, 321987654, 219876543, 198765432]) == 324\n assert candidate(nums = [999999999, 111111111, 222222222, 333333333, 444444444]) == 90\n assert candidate(nums = [900000, 899999, 889998, 879997, 869996, 859995, 849994, 839993, 829992]) == 104\n assert candidate(nums = [11122, 22233, 33344, 44455, 55566]) == 50\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 123456789]) == 396\n assert candidate(nums = [555555555, 444444444, 333333333, 222222222, 111111111]) == 90\n assert candidate(nums = [123123, 321321, 213213, 132132, 312312, 231231, 123123]) == 96\n assert candidate(nums = [98765, 87654, 76543, 65432, 54321, 43210, 32109, 21098, 10987]) == 180\n assert candidate(nums = [123, 321, 213, 132, 231, 312, 456, 654, 564, 546, 465, 645, 789, 987, 897, 879, 798, 978]) == 432\n assert candidate(nums = [11112222, 22223333, 33334444, 44445555]) == 48\n assert candidate(nums = [199991, 299992, 399993, 499994, 599995, 699996, 799997, 899998, 999999]) == 72\n assert candidate(nums = [123456, 234567, 345678, 456789, 567890]) == 60\n assert candidate(nums = [123123, 234234, 345345, 456456, 567567, 678678, 789789, 890890, 901901]) == 216\n assert candidate(nums = [9876543, 8765432, 7654321, 6543210, 5432109, 4321098, 3210987, 2109876, 1098765]) == 252\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210, 432109, 321098, 210987, 109876]) == 216\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210, 432109, 321098, 210987]) == 168\n assert candidate(nums = [989898989, 878787878, 767676767, 656565656, 545454545, 434343434, 323232323, 212121212, 101010101]) == 324\n assert candidate(nums = [123123123, 234234234, 345345345, 456456456, 567567567]) == 90\n assert candidate(nums = [1234567, 2345671, 3456712, 4567123, 5671234, 6712345, 7123456, 1234567]) == 189\n assert candidate(nums = [987654321, 123456789, 876543219, 918273645]) == 50\n assert candidate(nums = [111222333, 222333444, 333444555, 444555666, 555666777]) == 90\n assert candidate(nums = [1212121, 2323232, 3434343, 4545454, 5656565, 6767676, 7878787, 8989898, 9090909]) == 252\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444]) == 90\n assert candidate(nums = [5555555, 5555554, 5555553, 5555552, 5555551, 5555550]) == 15\n assert candidate(nums = [101010101, 202020202, 303030303, 404040404, 505050505]) == 50\n assert candidate(nums = [1234, 2345, 3456, 4567, 5678, 6789]) == 60\n assert candidate(nums = [1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919]) == 90\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000]) == 36\n assert candidate(nums = [100000001, 200000002, 300000003, 400000004, 500000005, 600000006, 700000007, 800000008, 900000009]) == 72\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 123, 234, 345, 456, 567, 678, 789, 890, 901]) == 432\n assert candidate(nums = [1001, 1010, 1100, 1110, 10011]) == 22\n assert candidate(nums = [987654321, 123456789, 876543219, 912345678]) == 50\n assert candidate(nums = [918273645, 827364591, 736459182, 645918273, 591827364]) == 90\n assert candidate(nums = [2345678, 3456789, 4567890, 5678901, 6789012, 7890123, 8901234]) == 147\n assert candidate(nums = [121212121, 212121212, 323232323, 434343434, 545454545, 656565656, 767676767, 878787878, 989898989]) == 320\n assert candidate(nums = [1010101, 2020202, 3030303, 4040404, 5050505, 6060606, 7070707, 8080808, 9090909]) == 144\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555, 666666, 777777]) == 126\n assert candidate(nums = [987654321, 987654320, 987654319, 987654318, 987654317, 987654316, 987654315, 987654314, 987654313]) == 50\n assert candidate(nums = [123456789, 987654321, 135792468, 864208642, 246802468]) == 83\n assert candidate(nums = [11111111, 22222222, 33333333, 44444444, 55555555, 66666666, 77777777, 88888888, 99999999]) == 288\n assert candidate(nums = [121212121, 212121212, 323232323, 434343434, 545454545]) == 86\n assert candidate(nums = [987654321, 876543210, 765432109, 654321098, 543210987, 432109876, 321098765, 210987654, 109876543]) == 324\n assert candidate(nums = [1234567, 1234568, 1234569, 1234570, 1234571, 1234572, 1234573, 1234574, 1234575]) == 54\n assert candidate(nums = [101010, 110110, 101101, 111000]) == 18\n assert candidate(nums = [80808, 80807, 80806, 80805, 80804, 80803, 80802]) == 21\n assert candidate(nums = [123456, 654321, 111111, 999999]) == 34\n assert candidate(nums = [223344, 443322, 332244, 224433]) == 30\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 144\n assert candidate(nums = [101010101, 202020202, 303030303, 404040404, 505050505, 606060606]) == 75\n assert candidate(nums = [112233, 445566, 778899, 332211, 665544]) == 56\n assert candidate(nums = [9876543, 8765432, 7654321, 6543210, 5432109, 4321098, 3210987, 2109876, 1098765]) == 252\n assert candidate(nums = [123456789, 123456788, 123456787, 123456786, 123456785, 123456784, 123456783]) == 21\n assert candidate(nums = [555555, 555555, 555555, 555555, 555555, 555555]) == 0\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210]) == 60\n assert candidate(nums = [112233, 113322, 121233, 122133, 123123, 123312, 131223, 132123, 132213, 132312]) == 150\n assert candidate(nums = [1234, 2341, 3412, 4123, 1324, 2413, 3241, 4312, 1423, 2134]) == 148\n assert candidate(nums = [123456789, 987654321, 234567891, 891234567, 345678912, 789123456, 456789123, 654321987, 567891234]) == 310\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006]) == 30\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555]) == 90\n assert candidate(nums = [987654321, 123456789, 987654321, 123456789]) == 32\n assert candidate(nums = [555555555, 444444444, 333333333, 222222222, 111111111, 123456789]) == 130\n assert candidate(nums = [111222, 222333, 333444, 444555]) == 36\n assert candidate(nums = [100100100, 110110110, 120120120, 130130130, 140140140]) == 30\n assert candidate(nums = [123456789, 987654321, 564738291]) == 25\n assert candidate(nums = [1010101, 2020202, 3030303, 4040404, 5050505, 6060606, 7070707, 8080808, 9090909]) == 144\n assert candidate(nums = [123456, 654321, 234561, 165432, 345612, 432165]) == 82\n assert candidate(nums = [555555555, 666666666, 777777777, 888888888, 999999999, 111111111, 222222222, 333333333, 444444444, 123456789, 987654321]) == 476\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000]) == 15\n assert candidate(nums = [123456789, 987654321, 112233445, 554433221]) == 47\n", "comparison": "exact"}, "public_tests": ["[13,23,12]", "[10,10,10,10]"], "hints": ["You can solve the problem for digits that are on the same position separately, and then sum up all the answers.", "For each position, count the number of occurences of each digit from 0 to 9 that appear on that position.", "Let c be the number of occurences of a digit on a position, that will contribute with c * (n - c) to the final answer, where n is the number of integers in nums."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumDigitDifferences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:14:59+00:00", "tests_total": 105, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def sum_digit_differences(nums)", "container": null, "callable": "sum_digit_differences", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3154, "task_id": "find-number-of-ways-to-reach-the-k-th-stair", "difficulty": "Hard", "problem_description": "You are given a non-negative integer k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0.\n\nAlice has an integer jump, with an initial value of 0. She starts on stair 1 and wants to reach stair k using any number of operations. If she is on stair i, in one operation she can:\n\n- Go down to stair i - 1. This operation cannot be used consecutively or on stair 0.\n- Go up to stair i + 2^jump. And then, jump becomes jump + 1.\n\nReturn the total number of ways Alice can reach stair k.\n\nNote that it is possible that Alice reaches the stair k, and performs some operations to reach the stair k again.\n\nExample 1:\n\nInput: k = 0\nOutput: 2\nExplanation:\nThe 2 possible ways of reaching stair 0 are:\n- Alice starts at stair 1.\n - Using an operation of the first type, she goes down 1 stair to reach stair 0.\n- Alice starts at stair 1.\n - Using an operation of the first type, she goes down 1 stair to reach stair 0.\n - Using an operation of the second type, she goes up 2^0 stairs to reach stair 1.\n - Using an operation of the first type, she goes down 1 stair to reach stair 0.\n\nExample 2:\n\nInput: k = 1\nOutput: 4\nExplanation:\nThe 4 possible ways of reaching stair 1 are:\n- Alice starts at stair 1. Alice is at stair 1.\n- Alice starts at stair 1.\n - Using an operation of the first type, she goes down 1 stair to reach stair 0.\n - Using an operation of the second type, she goes up 2^0 stairs to reach stair 1.\n- Alice starts at stair 1.\n - Using an operation of the second type, she goes up 2^0 stairs to reach stair 2.\n - Using an operation of the first type, she goes down 1 stair to reach stair 1.\n- Alice starts at stair 1.\n - Using an operation of the first type, she goes down 1 stair to reach stair 0.\n - Using an operation of the second type, she goes up 2^0 stairs to reach stair 1.\n - Using an operation of the first type, she goes down 1 stair to reach stair 0.\n - Using an operation of the second type, she goes up 2^1 stairs to reach stair 2.\n - Using an operation of the first type, she goes down 1 stair to reach stair 1.\n\nConstraints:\n\n- 0 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(k = 1000) == 0\n assert candidate(k = 100) == 0\n assert candidate(k = 20) == 0\n assert candidate(k = 1000000000) == 0\n assert candidate(k = 1) == 4\n assert candidate(k = 10) == 0\n assert candidate(k = 10000) == 0\n assert candidate(k = 500) == 0\n assert candidate(k = 1000000) == 0\n assert candidate(k = 10000000) == 0\n assert candidate(k = 3) == 3\n assert candidate(k = 100000000) == 0\n assert candidate(k = 0) == 2\n assert candidate(k = 2) == 4\n assert candidate(k = 100000) == 0\n assert candidate(k = 5) == 4\n assert candidate(k = 4) == 2\n assert candidate(k = 50) == 0\n assert candidate(k = 127) == 8\n assert candidate(k = 8388608) == 1\n assert candidate(k = 63) == 7\n assert candidate(k = 65536) == 1\n assert candidate(k = 16384) == 1\n assert candidate(k = 5000) == 0\n assert candidate(k = 60000000) == 0\n assert candidate(k = 4194304) == 1\n assert candidate(k = 8191) == 14\n assert candidate(k = 30000000) == 0\n assert candidate(k = 750000) == 0\n assert candidate(k = 4096) == 1\n assert candidate(k = 65535) == 17\n assert candidate(k = 536870912) == 1\n assert candidate(k = 2048) == 1\n assert candidate(k = 1000001) == 0\n assert candidate(k = 8192) == 1\n assert candidate(k = 20000000) == 0\n assert candidate(k = 5000000) == 0\n assert candidate(k = 32767) == 16\n assert candidate(k = 1000100) == 0\n assert candidate(k = 524288) == 1\n assert candidate(k = 1000010) == 0\n assert candidate(k = 9) == 0\n assert candidate(k = 32768) == 1\n assert candidate(k = 23) == 0\n assert candidate(k = 500000) == 0\n assert candidate(k = 131072) == 1\n assert candidate(k = 268435456) == 1\n assert candidate(k = 4095) == 13\n assert candidate(k = 15) == 5\n assert candidate(k = 33554432) == 1\n assert candidate(k = 999999) == 0\n assert candidate(k = 64) == 1\n assert candidate(k = 70000000) == 0\n assert candidate(k = 31) == 6\n assert candidate(k = 1100000) == 0\n assert candidate(k = 50000000) == 0\n assert candidate(k = 16) == 1\n assert candidate(k = 2097152) == 1\n assert candidate(k = 999999999) == 0\n assert candidate(k = 256) == 1\n assert candidate(k = 262144) == 1\n assert candidate(k = 134217728) == 1\n assert candidate(k = 1001000) == 0\n assert candidate(k = 90000000) == 0\n assert candidate(k = 2047) == 12\n assert candidate(k = 30) == 15\n assert candidate(k = 1024) == 1\n assert candidate(k = 67108864) == 1\n assert candidate(k = 7) == 4\n assert candidate(k = 1048576) == 1\n assert candidate(k = 255) == 9\n assert candidate(k = 512) == 1\n assert candidate(k = 80000000) == 0\n assert candidate(k = 1023) == 11\n assert candidate(k = 16777216) == 1\n assert candidate(k = 40000000) == 0\n assert candidate(k = 511) == 10\n assert candidate(k = 1010000) == 0\n", "comparison": "exact"}, "public_tests": ["0", "1"], "hints": ["On using x operations of the second type and y operations of the first type, the stair 2^x - y is reached.", "Since first operations cannot be consecutive, there are exactly x + 1 positions (before and after each power of 2) to perform the second operation.", "Using combinatorics, we have ^{x + 1}C_y number of ways to select the positions of second operations."], "metadata": {"canonical_parameter_names": ["k"], "leetcode_dataset_entry_point": "Solution().waysToReachStair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:01+00:00", "tests_total": 79, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "dynamic-programming", "bit-manipulation", "memoization", "combinatorics"]}, "language": "ruby", "interface": {"raw_signature": "def ways_to_reach_stair(k)", "container": null, "callable": "ways_to_reach_stair", "parameters": [{"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3158, "task_id": "find-the-xor-of-numbers-which-appear-twice", "difficulty": "Easy", "problem_description": "You are given an array nums, where each number in the array appears either once or twice.\n\nReturn the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice.\n\nExample 1:\n\nInput: nums = [1,2,1,3]\nOutput: 1\nExplanation:\nThe only number that appears twice in nums is 1.\n\nExample 2:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation:\nNo number appears twice in nums.\n\nExample 3:\n\nInput: nums = [1,2,2,1]\nOutput: 3\nExplanation:\nNumbers 1 and 2 appeared twice. 1 XOR 2 == 3.\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 50\n- Each number in nums appears either once or twice.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 20, 30, 30, 40, 50]) == 20\n assert candidate(nums = [8, 8, 9, 9, 10, 10, 11]) == 11\n assert candidate(nums = [10, 10, 20, 20, 30]) == 30\n assert candidate(nums = [5, 5, 6, 7, 7, 8, 8, 9]) == 10\n assert candidate(nums = [4, 5, 6, 7, 8, 8, 7]) == 15\n assert candidate(nums = [30, 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]) == 30\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 7]) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 4\n assert candidate(nums = [1, 2, 2, 1]) == 3\n assert candidate(nums = [1, 2, 1, 3]) == 1\n assert candidate(nums = [4, 5, 6, 4, 5, 7]) == 1\n assert candidate(nums = [42]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [15, 15, 25, 25, 35]) == 22\n assert candidate(nums = [10, 10, 11, 11, 12]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(nums = [10, 10, 20, 30, 20, 30, 40]) == 0\n assert candidate(nums = [4, 5, 6, 7, 8, 8, 9, 9]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [4, 5, 6, 7, 4, 5]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 5]) == 0\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [49, 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]) == 49\n assert candidate(nums = [7]) == 0\n assert candidate(nums = [4, 5, 6, 7, 5, 4]) == 1\n assert candidate(nums = [10, 10, 20, 30, 30, 40]) == 20\n assert candidate(nums = [2, 2]) == 2\n assert candidate(nums = [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, 1]) == 23\n assert candidate(nums = [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]) == 24\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]) == 20\n assert candidate(nums = [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, 5, 6, 7, 8]) == 12\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 7\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, 1, 3, 5]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 26\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 33, 36, 39, 42, 45, 48]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16]) == 26\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 50, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]) == 0\n assert candidate(nums = [5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45, 45, 50, 50, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 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 = [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, 15, 30]) == 17\n assert candidate(nums = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 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, 30, 31]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 50, 7, 14, 21, 28, 35, 42, 49]) == 56\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]) == 0\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [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, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]) == 59\n assert candidate(nums = [1, 1, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 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 = [5, 10, 15, 20, 25, 30, 5, 10, 15, 20, 35, 40, 45, 50, 35, 40, 45]) == 50\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\n assert candidate(nums = [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, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 3, 6, 9, 12, 15]) == 15\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 7, 14, 21, 28, 35, 42, 49, 5, 10, 15, 20, 25, 30, 35, 5, 10, 15, 20, 25, 30]) == 8\n assert candidate(nums = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 15, 16, 17, 18, 19]) == 15\n assert candidate(nums = [1, 3, 3, 5, 7, 7, 9, 11, 11, 13, 15, 15, 17, 19, 19, 21, 21, 23, 25, 25]) == 31\n assert candidate(nums = [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, 7, 30, 40]) == 49\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [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, 25, 26, 27, 28, 29, 30]) == 7\n assert candidate(nums = [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, 2, 4, 6, 8, 10]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 45, 46, 47, 48, 49, 50]) == 31\n assert candidate(nums = [42, 42, 24, 24, 36, 36, 18, 18, 30, 30, 21, 21, 9, 9, 27, 27, 33, 33, 15, 15]) == 51\n assert candidate(nums = [45, 45, 30, 30, 25, 25, 20, 15, 10, 5, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19]) == 42\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 1, 3]) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 2, 4, 6]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 22\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 2, 4, 6, 8, 10]) == 2\n assert candidate(nums = [5, 5, 10, 15, 15, 20, 25, 25, 30, 35, 35, 40, 45, 45, 50, 50]) == 47\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]) == 20\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]) == 1\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 31\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 27\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 7, 14, 21, 28, 35, 42, 49, 1, 2, 3, 4, 5]) == 56\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, 1, 3, 5]) == 7\n assert candidate(nums = [23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50]) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 1, 3, 5, 7]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 11, 12, 13, 14, 15]) == 1\n assert candidate(nums = [3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, 19, 19, 21, 21, 23, 23, 25, 25, 27, 27, 29, 29, 31, 31, 33, 33, 35, 35, 37, 37, 39, 39, 41, 41, 43, 43, 45, 45, 47, 47, 49, 49]) == 48\n assert candidate(nums = [5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45, 45, 50, 50]) == 7\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 2, 4, 6, 8, 10]) == 2\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50, 15, 20, 25, 30, 35, 40, 45, 50]) == 8\n assert candidate(nums = [10, 20, 10, 30, 40, 40, 50, 20]) == 54\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 50, 8, 16, 24, 32, 40, 48]) == 56\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, 50, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 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, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [42, 24, 13, 24, 42, 35, 13, 47, 50, 40, 47, 35, 40, 50]) == 41\n", "comparison": "exact"}, "public_tests": ["[1,2,1,3]", "[1,2,3]", "[1,2,2,1]"], "hints": ["The constraints are small. Brute force checking each value in the array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().duplicateNumbersXOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:09+00:00", "tests_total": 120, "tests_dropped": 33, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def duplicate_numbers_xor(nums)", "container": null, "callable": "duplicate_numbers_xor", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3159, "task_id": "find-occurrences-of-an-element-in-an-array", "difficulty": "Medium", "problem_description": "You are given an integer array nums, an integer array queries, and an integer x.\n\nFor each queries[i], you need to find the index of the queries[i]^th occurrence of x in the nums array. If there are fewer than queries[i] occurrences of x, the answer should be -1 for that query.\n\nReturn an integer array answer containing the answers to all queries.\n\nExample 1:\n\nInput: nums = [1,3,1,7], queries = [1,3,2,4], x = 1\nOutput: [0,-1,2,-1]\nExplanation:\n- For the 1^st query, the first occurrence of 1 is at index 0.\n- For the 2^nd query, there are only two occurrences of 1 in nums, so the answer is -1.\n- For the 3^rd query, the second occurrence of 1 is at index 2.\n- For the 4^th query, there are only two occurrences of 1 in nums, so the answer is -1.\n\nExample 2:\n\nInput: nums = [1,2,3], queries = [10], x = 5\nOutput: [-1]\nExplanation:\n- For the 1^st query, 5 doesn't exist in nums, so the answer is -1.\n\nConstraints:\n\n- 1 <= nums.length, queries.length <= 10^5\n- 1 <= queries[i] <= 10^5\n- 1 <= nums[i], x <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1]\n assert candidate(nums = [3, 2, 1],queries = [1, 1, 1],x = 3) == [0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [1, 1, 1, 1, 1],x = 3) == [2, 2, 2, 2, 2]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 1) == [0, 1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 5, 3, 5],queries = [1, 2, 3, 4, 5, 6],x = 5) == [0, 2, 4, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [1, 2, 3, 4, 5],x = 10) == [0, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [1, 1, 1, 1, 1],x = 6) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500],queries = [1, 2, 3, 4, 5],x = 300) == [2, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3],queries = [10],x = 5) == [-1]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],queries = [5, 5, 5, 5, 5],x = 3) == [4, 4, 4, 4, 4]\n assert candidate(nums = [2, 4, 2, 4, 2, 4, 2, 4],queries = [1, 2, 3, 4, 5, 6, 7, 8],x = 2) == [0, 2, 4, 6, -1, -1, -1, -1]\n assert candidate(nums = [4, 4, 4, 4],queries = [1, 2, 3, 4, 5],x = 4) == [0, 1, 2, 3, -1]\n assert candidate(nums = [1, 3, 1, 7],queries = [1, 3, 2, 4],x = 1) == [0, -1, 2, -1]\n assert candidate(nums = [5, 5, 5, 5, 5],queries = [1, 2, 3, 4, 5, 6],x = 5) == [0, 1, 2, 3, 4, -1]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [1, 2, 3, 4, 5, 6],x = 30) == [2, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [1],x = 10) == [0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 10) == [9, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [3, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],x = 3) == [0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -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],queries = [5, 10, 15, 20, 25, 30],x = 1) == [4, 9, 14, 19, 24, 29]\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, 9, 9],queries = [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],x = 9) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1, -1, -1, -1, -1, -1, -1, -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],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [1],x = 500) == [4]\n assert candidate(nums = [7, 11, 13, 11, 7, 17, 19, 23, 11, 13, 11],queries = [1, 2, 3, 4, 5],x = 11) == [1, 3, 8, 10, -1]\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],x = 8) == [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\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, 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, 3, 3, 3, 3],queries = [1, 10, 20, 30, 40],x = 3) == [0, 9, 19, 29, 39]\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 9990) == [10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, -1]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 1) == [0, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [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, 4],queries = [1, 5, 10, 15, 25, 30],x = 4) == [0, 4, 9, 14, 24, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 21) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500],queries = [1, 2, 3, 4, 5, 6],x = 500) == [4, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],x = 10) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 5) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],x = 15) == [14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],queries = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],x = 7) == [0, 9, 19, 29, 39, 49, 59, -1, -1, -1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],x = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1]\n assert candidate(nums = [5, 3, 8, 5, 2, 5, 8, 5, 9, 5],queries = [1, 2, 3, 4, 5, 6],x = 5) == [0, 3, 5, 7, 9, -1]\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],queries = [1, 11, 21, 31, 41, 51],x = 1) == [0, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 20) == [-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, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 20) == [-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, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1, 5, 10, 15],x = 1) == [0, 4, 9, -1]\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 10000) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 2, 3, 1, 3, 5, 3, 2],queries = [1, 2, 3, 4, 5, 6, 7, 8],x = 3) == [1, 3, 5, 7, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 700) == [6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],x = 1) == [0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 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],queries = [1, 10, 20, 30, 40],x = 1) == [0, 9, 19, -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],queries = [1, 10, 20, 15, 5, 25, 30, 35],x = 1) == [0, 9, 19, 14, 4, 24, 29, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 1000) == [9, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],queries = [1, 5, 10, 15, 20],x = 7) == [0, 4, 9, -1, -1]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 2) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\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],queries = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 5) == [0, 9, 19, 29, 39, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],x = 10) == [9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 20) == [19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],queries = [1, 5, 10, 15, 20, 25],x = 3) == [0, 4, 9, 14, 19, -1]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 20) == [9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [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],x = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 6, 5, 6, 5, 5, 6, 5, 6, 6, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 5) == [0, 2, 4, 5, 7, 10, -1, -1, -1, -1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],queries = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],x = 10) == [18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 80) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 5, 2, 5, 3, 5, 3, 5, 3, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 5) == [0, 2, 4, 6, 8, 10, -1, -1, -1, -1, -1]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],queries = [1, 5, 10, 15],x = 7) == [0, 4, 9, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 9) == [0, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],x = 3) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],x = 1) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, 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],queries = [25, 26, 27, 28, 29, 30],x = 1) == [24, 25, 26, 27, 28, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 10) == [0, 5, 10, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 1) == [0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 20) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],x = 1) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, -1, -1, -1]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],x = 7) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1]\n assert candidate(nums = [5, 3, 5, 2, 5, 3, 5, 1, 5, 5, 5],queries = [1, 5, 7, 3, 9, 11, 12],x = 5) == [0, 8, 10, 4, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],queries = [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],x = 15) == [14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],queries = [1, 10, 20, 30],x = 4) == [0, 9, 19, -1]\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],queries = [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],x = 25) == [18, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [1, 5, 9, 10, 11],x = 5) == [0, 4, 8, 9, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 100) == [0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n", "comparison": "exact"}, "public_tests": ["[1,3,1,7]\n[1,3,2,4]\n1", "[1,2,3]\n[10]\n5"], "hints": ["Compress the array nums and save all the occurrences of each element in the separate arrays."], "metadata": {"canonical_parameter_names": ["nums", "queries", "x"], "leetcode_dataset_entry_point": "Solution().occurrencesOfElement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:11+00:00", "tests_total": 81, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def occurrences_of_element(nums, queries, x)", "container": null, "callable": "occurrences_of_element", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3160, "task_id": "find-the-number-of-distinct-colors-among-the-balls", "difficulty": "Medium", "problem_description": "You are given an integer limit and a 2D array queries of size n x 2.\n\nThere are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of colors among the balls.\n\nReturn an array result of length n, where result[i] denotes the number of colors after i^th query.\n\nNote that when answering a query, lack of a color will not be considered as a color.\n\nExample 1:\n\nInput: limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]]\nOutput: [1,2,2,3]\nExplanation:\n- After query 0, ball 1 has color 4.\n- After query 1, ball 1 has color 4, and ball 2 has color 5.\n- After query 2, ball 1 has color 3, and ball 2 has color 5.\n- After query 3, ball 1 has color 3, ball 2 has color 5, and ball 3 has color 4.\n\nExample 2:\n\nInput: limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]]\nOutput: [1,2,2,3,4]\nExplanation:\n- After query 0, ball 0 has color 1.\n- After query 1, ball 0 has color 1, and ball 1 has color 2.\n- After query 2, ball 0 has color 1, and balls 1 and 2 have color 2.\n- After query 3, ball 0 has color 1, balls 1 and 2 have color 2, and ball 3 has color 4.\n- After query 4, ball 0 has color 1, balls 1 and 2 have color 2, ball 3 has color 4, and ball 4 has color 5.\n\nConstraints:\n\n- 1 <= limit <= 10^9\n- 1 <= n == queries.length <= 10^5\n- queries[i].length == 2\n- 0 <= queries[i][0] <= limit\n- 1 <= queries[i][1] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(limit = 3,queries = [[0, 1], [1, 2], [2, 3], [0, 1]]) == [1, 2, 3, 3]\n assert candidate(limit = 1,queries = [[0, 1], [1, 2]]) == [1, 2]\n assert candidate(limit = 4,queries = [[0, 1], [1, 2], [2, 2], [3, 4], [4, 5]]) == [1, 2, 2, 3, 4]\n assert candidate(limit = 10,queries = [[0, 10], [1, 10], [2, 10], [3, 10], [4, 10]]) == [1, 1, 1, 1, 1]\n assert candidate(limit = 5,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == [1, 2, 3, 4, 5, 6]\n assert candidate(limit = 1,queries = [[0, 1], [0, 2], [0, 3], [0, 4]]) == [1, 1, 1, 1]\n assert candidate(limit = 3,queries = [[0, 1], [1, 1], [2, 1], [3, 1]]) == [1, 1, 1, 1]\n assert candidate(limit = 5,queries = [[0, 2], [1, 2], [2, 3], [3, 4], [4, 5]]) == [1, 1, 2, 3, 4]\n assert candidate(limit = 4,queries = [[1, 4], [2, 5], [1, 3], [3, 4]]) == [1, 2, 2, 3]\n assert candidate(limit = 10,queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(limit = 100,queries = [[0, 1], [50, 2], [100, 3]]) == [1, 2, 3]\n assert candidate(limit = 10,queries = [[0, 1], [2, 2], [4, 3], [6, 4], [8, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(limit = 10,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(limit = 10,queries = [[0, 10], [1, 9], [2, 8], [3, 7], [4, 6], [5, 5]]) == [1, 2, 3, 4, 5, 6]\n assert candidate(limit = 5,queries = [[0, 10], [1, 20], [2, 10], [3, 30], [4, 40], [5, 50]]) == [1, 2, 2, 3, 4, 5]\n assert candidate(limit = 9,queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 4], [6, 3], [7, 2], [8, 1], [9, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 9]\n assert candidate(limit = 10,queries = [[1, 5], [2, 6], [1, 6], [3, 7], [4, 8], [2, 8], [5, 9], [6, 9], [7, 10], [8, 10], [9, 11]]) == [1, 2, 1, 2, 3, 3, 4, 4, 5, 5, 6]\n assert candidate(limit = 50,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 2], [7, 3], [8, 4], [9, 5], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]) == [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6]\n assert candidate(limit = 10,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 2], [2, 3]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]\n assert candidate(limit = 5,queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [1, 1, 1, 1, 1, 2, 3, 4, 5, 5]\n assert candidate(limit = 20,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1], [16, 1], [17, 1], [18, 1], [19, 1]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 10,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 20,queries = [[5, 2], [5, 3], [10, 4], [15, 5], [15, 6], [10, 7], [5, 8], [5, 9], [10, 10], [15, 11]]) == [1, 1, 2, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(limit = 10,queries = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 10,queries = [[0, 1], [1, 2], [2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6], [8, 7], [9, 8], [10, 9]]) == [1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(limit = 20,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [3, 5], [5, 2], [2, 4]]) == [1, 2, 3, 4, 5, 5, 4, 3, 4, 5]\n assert candidate(limit = 10,queries = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 10,queries = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 10,queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 5,queries = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == [1, 1, 1, 1, 1]\n assert candidate(limit = 20,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(limit = 9,queries = [[9, 10], [8, 10], [7, 10], [6, 10], [5, 10], [4, 10], [3, 10], [2, 10], [1, 10], [0, 10]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 100,queries = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50]]) == [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]\n assert candidate(limit = 10,queries = [[0, 1], [0, 2], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(limit = 9,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 8, 8, 8, 8, 8, 8, 8]\n assert candidate(limit = 10,queries = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 3], [2, 4], [3, 4], [3, 5], [4, 5], [4, 6], [5, 6]]) == [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]\n assert candidate(limit = 50,queries = [[10, 1], [15, 2], [20, 3], [25, 4], [30, 5], [35, 6], [40, 7], [45, 8], [50, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(limit = 50,queries = [[10, 100], [20, 100], [30, 100], [40, 100], [50, 100], [0, 101], [5, 102], [15, 103], [25, 104], [35, 105], [45, 106]]) == [1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(limit = 100,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(limit = 10,queries = [[0, 10], [1, 20], [2, 10], [3, 30], [4, 10], [5, 20], [6, 30], [7, 40], [8, 50], [9, 60], [10, 70]]) == [1, 2, 2, 3, 3, 3, 3, 4, 5, 6, 7]\n assert candidate(limit = 10,queries = [[0, 10], [1, 2], [2, 3], [3, 10], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [1, 2, 3, 3, 4, 5, 6, 7, 8, 8]\n assert candidate(limit = 20,queries = [[0, 1], [1, 1], [2, 2], [2, 3], [3, 3], [3, 2], [4, 4], [4, 5], [5, 5], [5, 6], [6, 6], [6, 7], [7, 7], [7, 8], [8, 8], [8, 9]]) == [1, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8]\n assert candidate(limit = 10,queries = [[0, 1], [1, 2], [1, 1], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == [1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(limit = 1,queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(limit = 10,queries = [[0, 10], [1, 20], [2, 10], [3, 30], [4, 10], [5, 50], [6, 10], [7, 70], [8, 10], [9, 90], [10, 100]]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7]\n assert candidate(limit = 10,queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10]]) == [1, 2, 3, 4, 5, 5, 5, 5, 5, 5]\n assert candidate(limit = 10,queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [3, 5], [5, 2], [2, 4], [0, 10], [1, 10], [2, 10], [3, 10], [4, 10]]) == [1, 2, 3, 4, 5, 5, 4, 3, 4, 5, 5, 4, 3, 3, 2]\n", "comparison": "exact"}, "public_tests": ["4\n[[1,4],[2,5],[1,3],[3,4]]", "4\n[[0,1],[1,2],[2,2],[3,4],[4,5]]"], "hints": ["Use two HashMaps to maintain the color of each ball and the set of balls with each color."], "metadata": {"canonical_parameter_names": ["limit", "queries"], "leetcode_dataset_entry_point": "Solution().queryResults", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:13+00:00", "tests_total": 47, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def query_results(limit, queries)", "container": null, "callable": "query_results", "parameters": [{"name": "limit", "type": "Integer"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3161, "task_id": "block-placement-queries", "difficulty": "Hard", "problem_description": "There exists an infinite number line, with its origin at 0 and extending towards the positive x-axis.\n\nYou are given a 2D array queries, which contains two types of queries:\n\n1. For a query of type 1, queries[i] = [1, x]. Build an obstacle at distance x from the origin. It is guaranteed that there is no obstacle at distance x when the query is asked.\n2. For a query of type 2, queries[i] = [2, x, sz]. Check if it is possible to place a block of size sz anywhere in the range [0, x] on the line, such that the block entirely lies in the range [0, x]. A block cannot be placed if it intersects with any obstacle, but it may touch it. Note that you do not actually place the block. Queries are separate.\n\nReturn a boolean array results, where results[i] is true if you can place the block specified in the i^th query of type 2, and false otherwise.\n\nExample 1:\n\nInput: queries = [[1,2],[2,3,3],[2,3,1],[2,2,2]]\nOutput: [false,true,true]\nExplanation:\nFor query 0, place an obstacle at x = 2. A block of size at most 2 can be placed before x = 3.\n\nExample 2:\n\nInput: queries = [[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]\nOutput: [true,true,false]\nExplanation:\n- Place an obstacle at x = 7 for query 0. A block of size at most 7 can be placed before x = 7.\n- Place an obstacle at x = 2 for query 2. Now, a block of size at most 5 can be placed before x = 7, and a block of size at most 2 before x = 2.\n\nConstraints:\n\n- 1 <= queries.length <= 15 * 10^4\n- 2 <= queries[i].length <= 3\n- 1 <= queries[i][0] <= 2\n- 1 <= x, sz <= min(5 * 10^4, 3 * queries.length)\n- The input is generated such that for queries of type 1, no obstacle exists at distance x when the query is asked.\n- The input is generated such that there is at least one query of type 2.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(queries = [[2, 5, 2], [1, 3], [2, 5, 3], [1, 4], [2, 5, 1]]) == [True, True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [2, 5, 2], [1, 10], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 7], [2, 7, 6], [1, 2], [2, 7, 5], [2, 7, 6]]) == [True, True, False]\n assert candidate(queries = [[1, 1], [2, 2, 2], [1, 3], [2, 4, 1], [2, 4, 2]]) == [False, True, True]\n assert candidate(queries = [[1, 5], [1, 10], [1, 15], [2, 20, 10], [2, 12, 3]]) == [False, True]\n assert candidate(queries = [[2, 5, 1], [1, 3], [1, 4], [2, 5, 1]]) == [True, True]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [2, 10, 5]]) == [False]\n assert candidate(queries = [[2, 5, 3], [1, 2], [2, 5, 2], [1, 4], [2, 5, 3]]) == [True, True, False]\n assert candidate(queries = [[1, 1], [1, 5], [1, 10], [2, 10, 3], [2, 10, 7]]) == [True, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 4, 2]]) == [False]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [2, 6, 2], [2, 6, 4]]) == [True, False]\n assert candidate(queries = [[1, 5], [1, 10], [2, 10, 4], [1, 15], [2, 15, 7]]) == [True, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 5], [2, 5, 2], [2, 10, 8]]) == [True, True, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 3], [2, 5, 2]]) == [True, True]\n assert candidate(queries = [[1, 10], [1, 5], [2, 10, 3], [2, 5, 2]]) == [True, True]\n assert candidate(queries = [[1, 2], [2, 3, 3], [2, 3, 1], [2, 2, 2]]) == [False, True, True]\n assert candidate(queries = [[1, 1], [1, 5], [1, 10], [2, 12, 3], [2, 12, 7], [2, 12, 10]]) == [True, False, False]\n assert candidate(queries = [[1, 1], [2, 2, 1], [1, 3], [2, 4, 2], [1, 5], [2, 6, 3], [1, 7], [2, 8, 4], [1, 9], [2, 10, 5]]) == [True, True, False, False, False]\n assert candidate(queries = [[1, 2], [1, 4], [1, 6], [1, 8], [1, 10], [2, 10, 5], [2, 10, 4], [2, 10, 3], [2, 10, 2], [2, 10, 1], [1, 12], [2, 12, 6], [2, 12, 5], [2, 12, 4], [2, 12, 3], [2, 12, 2], [2, 12, 1]]) == [False, False, False, True, True, False, False, False, False, True, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5, 5], [2, 5, 4], [2, 5, 3], [2, 5, 2], [2, 5, 1]]) == [False, False, False, False, True]\n assert candidate(queries = [[1, 2], [1, 4], [1, 6], [1, 8], [1, 10], [2, 10, 9], [2, 10, 3], [2, 10, 5]]) == [False, False, False]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9], [2, 10, 9], [2, 10, 8], [2, 10, 7], [2, 10, 6], [2, 10, 5], [2, 10, 4], [2, 10, 3], [2, 10, 2], [2, 10, 1]]) == [False, False, False, False, False, False, False, True, True]\n assert candidate(queries = [[1, 2], [1, 4], [1, 6], [1, 8], [2, 10, 8], [2, 8, 4], [2, 6, 2]]) == [False, False, True]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9], [2, 10, 8], [2, 10, 4], [2, 10, 2]]) == [False, False, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5, 2], [2, 5, 3], [2, 5, 4], [2, 5, 5]]) == [False, False, False, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5, 1], [2, 5, 2], [2, 5, 3], [2, 5, 4], [2, 5, 5]]) == [True, False, False, False, False]\n assert candidate(queries = [[1, 1], [1, 10], [2, 5, 4], [2, 10, 8], [1, 15], [2, 20, 5], [2, 20, 10], [2, 20, 15], [2, 20, 20]]) == [True, True, True, False, False, False]\n assert candidate(queries = [[1, 2], [1, 4], [1, 6], [1, 8], [1, 10], [1, 12], [1, 14], [1, 16], [1, 18], [1, 20], [2, 21, 10], [2, 21, 20], [2, 21, 30], [2, 21, 40], [2, 21, 50]]) == [False, False, False, False, False]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9], [1, 11], [1, 13], [1, 15], [1, 17], [1, 19], [2, 20, 1], [2, 20, 2], [2, 20, 3], [2, 20, 4], [2, 20, 5], [2, 20, 6], [2, 20, 7], [2, 20, 8], [2, 20, 9], [2, 20, 10]]) == [True, True, False, False, False, False, False, False, False, False]\n assert candidate(queries = [[1, 1], [2, 2, 1], [2, 3, 2], [1, 4], [2, 5, 3], [1, 6], [2, 7, 4], [1, 8], [2, 9, 5]]) == [True, True, True, False, False]\n assert candidate(queries = [[1, 1], [2, 2, 2], [1, 3], [1, 4], [1, 5], [2, 5, 4], [2, 5, 1]]) == [False, False, True]\n assert candidate(queries = [[1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [2, 10, 5], [2, 9, 4], [2, 8, 3], [2, 7, 2], [2, 6, 1]]) == [False, False, False, False, True]\n assert candidate(queries = [[1, 2], [2, 3, 1], [1, 4], [2, 5, 2], [1, 6], [2, 7, 3], [1, 8], [2, 9, 4], [1, 10], [2, 11, 5], [1, 12], [2, 13, 6]]) == [True, True, False, False, False, False]\n assert candidate(queries = [[1, 5], [1, 10], [2, 12, 3], [1, 7], [2, 10, 6], [2, 8, 2]]) == [True, False, True]\n assert candidate(queries = [[1, 1], [1, 2], [2, 2, 1], [2, 2, 2], [1, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3], [1, 4], [2, 4, 1], [2, 4, 2], [2, 4, 3], [2, 4, 4]]) == [True, False, True, False, False, True, False, False, False]\n assert candidate(queries = [[1, 2], [1, 4], [1, 6], [1, 8], [1, 10], [1, 12], [1, 14], [2, 16, 12], [2, 16, 8], [2, 16, 4], [2, 16, 6], [2, 16, 10], [2, 16, 14]]) == [False, False, False, False, False, False]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [1, 9], [2, 10, 2], [2, 10, 4], [2, 10, 6], [2, 10, 8], [2, 10, 10]]) == [True, False, False, False, False]\n assert candidate(queries = [[1, 1], [2, 2, 1], [2, 3, 2], [1, 4], [1, 5], [2, 6, 3], [2, 7, 4], [2, 8, 5]]) == [True, True, True, False, False]\n assert candidate(queries = [[1, 1], [2, 2, 1], [1, 3], [2, 4, 2], [1, 5], [2, 6, 3], [1, 7], [2, 8, 4], [1, 9], [2, 10, 5], [1, 11], [2, 12, 6], [1, 13], [2, 14, 7], [1, 14], [2, 15, 8], [1, 16], [2, 17, 9], [1, 17], [2, 18, 10]]) == [True, True, False, False, False, False, False, False, False, False]\n assert candidate(queries = [[1, 1], [2, 3, 1], [2, 3, 2], [1, 4], [1, 5], [2, 6, 3], [2, 6, 5], [1, 7], [2, 8, 4]]) == [True, True, True, False, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 10, 1], [2, 10, 2], [2, 10, 3], [2, 10, 4], [2, 10, 5], [2, 10, 6], [2, 10, 7], [2, 10, 8], [2, 10, 9], [2, 10, 10]]) == [True, False, False, False, False, False, False, False, False, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 6, 1], [2, 6, 2], [2, 6, 3], [2, 6, 4], [2, 6, 5], [2, 6, 6]]) == [True, False, False, False, False, False]\n assert candidate(queries = [[1, 1], [2, 2, 2], [1, 3], [2, 4, 1], [2, 4, 2], [1, 5], [2, 6, 1], [2, 6, 2], [2, 6, 3], [2, 6, 4], [2, 6, 5]]) == [False, True, True, True, True, False, False, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 11, 10], [2, 11, 9], [2, 11, 8], [2, 11, 7], [2, 11, 6], [2, 11, 5], [2, 11, 4], [2, 11, 3], [2, 11, 2], [2, 11, 1]]) == [False, False, False, False, False, False, False, False, False, True]\n assert candidate(queries = [[1, 5], [2, 10, 4], [1, 15], [2, 15, 6], [1, 20], [2, 20, 8], [2, 20, 9]]) == [True, True, True, True]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [2, 10, 2], [2, 8, 2], [2, 6, 2], [2, 4, 2], [2, 2, 2]]) == [True, True, True, True, False]\n assert candidate(queries = [[1, 1], [2, 1, 1], [1, 2], [2, 2, 2], [1, 3], [2, 3, 3], [1, 4], [2, 4, 4], [1, 5], [2, 5, 5], [1, 6], [2, 6, 6], [1, 7], [2, 7, 7], [1, 8], [2, 8, 8], [1, 9], [2, 9, 9], [1, 10], [2, 10, 10]]) == [True, False, False, False, False, False, False, False, False, False]\n assert candidate(queries = [[1, 10], [2, 20, 5], [1, 15], [2, 25, 10], [1, 20], [2, 30, 15], [1, 25], [2, 40, 20], [1, 30], [2, 50, 25]]) == [True, True, False, False, False]\n assert candidate(queries = [[1, 5], [1, 10], [1, 15], [2, 20, 10], [2, 20, 5], [2, 20, 15]]) == [False, True, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 10, 5]]) == [False]\n assert candidate(queries = [[1, 20], [2, 20, 10], [1, 5], [2, 20, 15], [1, 15], [2, 20, 12], [2, 20, 18]]) == [True, True, False, False]\n assert candidate(queries = [[2, 10, 1], [1, 5], [2, 10, 4], [2, 10, 5], [2, 10, 6]]) == [True, True, True, False]\n assert candidate(queries = [[1, 5], [2, 10, 3], [1, 6], [2, 10, 3], [2, 10, 4]]) == [True, True, True]\n assert candidate(queries = [[1, 3], [1, 6], [2, 6, 3], [2, 6, 4]]) == [True, False]\n assert candidate(queries = [[1, 3], [1, 6], [2, 10, 4], [1, 1], [2, 10, 9]]) == [True, False]\n assert candidate(queries = [[2, 10, 1], [1, 5], [2, 10, 5], [2, 10, 6]]) == [True, True, False]\n assert candidate(queries = [[1, 5], [1, 10], [2, 12, 7], [1, 8], [2, 15, 9]]) == [False, False]\n assert candidate(queries = [[1, 3], [1, 6], [2, 8, 4], [1, 5], [2, 10, 3]]) == [False, True]\n assert candidate(queries = [[1, 5], [2, 5, 4], [1, 15], [2, 15, 10], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 3], [1, 6], [1, 9], [2, 12, 7], [2, 12, 5]]) == [False, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5, 3]]) == [False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [2, 3, 2], [2, 4, 2]]) == [False, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 5], [2, 10, 3], [2, 5, 4]]) == [True, True, True]\n assert candidate(queries = [[1, 5], [1, 10], [2, 15, 4], [2, 15, 6], [1, 8], [2, 15, 7]]) == [True, False, False]\n assert candidate(queries = [[2, 10, 10], [1, 5], [2, 10, 4], [1, 3], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[2, 10, 3], [1, 5], [2, 10, 5], [1, 8], [2, 10, 2]]) == [True, True, True]\n assert candidate(queries = [[2, 5, 4], [1, 3], [2, 4, 1], [1, 4], [2, 5, 2]]) == [True, True, True]\n assert candidate(queries = [[1, 5], [1, 10], [1, 15], [2, 10, 3], [2, 20, 8]]) == [True, False]\n assert candidate(queries = [[2, 10, 5], [1, 5], [2, 5, 2], [1, 10], [2, 10, 5]]) == [True, True, True]\n assert candidate(queries = [[2, 5, 2], [1, 3], [1, 7], [2, 9, 4]]) == [True, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [2, 3, 2], [2, 3, 3]]) == [False, False]\n assert candidate(queries = [[1, 10], [2, 15, 10], [1, 5], [2, 8, 3]]) == [True, True]\n assert candidate(queries = [[1, 5], [1, 10], [1, 15], [2, 15, 5], [2, 15, 10], [2, 15, 20]]) == [True, False, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 5], [2, 10, 3], [2, 10, 6]]) == [True, True, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [2, 4, 3], [2, 3, 1], [2, 5, 4]]) == [False, True, False]\n assert candidate(queries = [[1, 10], [2, 10, 9], [2, 10, 10], [2, 10, 11]]) == [True, True, False]\n assert candidate(queries = [[2, 5, 1], [1, 3], [2, 5, 2], [1, 4], [2, 5, 2]]) == [True, True, True]\n assert candidate(queries = [[2, 5, 2], [1, 2], [1, 3], [2, 5, 2], [2, 4, 2]]) == [True, True, True]\n assert candidate(queries = [[1, 10], [2, 15, 5], [2, 15, 10], [1, 5], [2, 15, 4]]) == [True, True, True]\n assert candidate(queries = [[1, 5], [2, 5, 4], [1, 3], [2, 3, 2], [2, 5, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 5], [2, 10, 4]]) == [True, True]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [2, 4, 2], [2, 6, 3]]) == [True, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 5], [2, 10, 5], [2, 5, 1]]) == [True, True, True]\n assert candidate(queries = [[2, 10, 1], [1, 5], [2, 10, 2], [1, 7], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 8], [2, 10, 7], [1, 6], [2, 10, 8]]) == [True, True, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [2, 10, 10], [1, 5], [2, 10, 5], [2, 10, 1], [2, 10, 9]]) == [True, True, True, True, False]\n assert candidate(queries = [[1, 5], [1, 3], [2, 6, 2], [2, 6, 4]]) == [True, False]\n assert candidate(queries = [[1, 5], [1, 10], [2, 8, 3], [1, 15], [2, 20, 5]]) == [True, True]\n assert candidate(queries = [[1, 10], [1, 5], [2, 10, 4], [2, 10, 5], [1, 3], [2, 10, 2]]) == [True, True, True]\n assert candidate(queries = [[2, 5, 2], [1, 3], [2, 4, 2], [1, 7], [2, 8, 6]]) == [True, True, False]\n assert candidate(queries = [[1, 5], [1, 10], [1, 15], [2, 20, 10], [2, 20, 15], [2, 20, 20]]) == [False, False, False]\n assert candidate(queries = [[2, 10, 5], [1, 5], [1, 10], [2, 10, 5]]) == [True, True]\n assert candidate(queries = [[1, 3], [1, 5], [2, 5, 2], [1, 7], [2, 10, 4]]) == [True, False]\n assert candidate(queries = [[1, 10], [2, 10, 5], [1, 3], [2, 10, 2], [2, 5, 3]]) == [True, True, True]\n assert candidate(queries = [[2, 5, 3], [1, 2], [1, 4], [2, 5, 2], [1, 3], [2, 5, 1]]) == [True, True, True]\n assert candidate(queries = [[1, 1], [1, 3], [1, 5], [1, 7], [2, 8, 2], [2, 8, 3], [2, 8, 4]]) == [True, False, False]\n assert candidate(queries = [[1, 3], [1, 5], [1, 7], [2, 8, 2]]) == [True]\n assert candidate(queries = [[1, 5], [1, 10], [2, 10, 4], [2, 10, 5]]) == [True, True]\n assert candidate(queries = [[1, 1], [2, 10, 1], [1, 5], [2, 10, 4], [1, 10], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 5], [1, 10], [2, 15, 4], [2, 15, 6], [2, 15, 5]]) == [True, False, True]\n assert candidate(queries = [[1, 10], [1, 5], [2, 8, 2], [1, 3], [2, 6, 2]]) == [True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [2, 10, 2], [1, 7], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 1], [2, 2, 1], [2, 3, 2], [1, 2], [2, 3, 1]]) == [True, True, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 4, 3], [2, 4, 2], [2, 4, 1]]) == [False, False, True]\n assert candidate(queries = [[1, 10], [2, 10, 5], [2, 10, 10], [1, 5], [2, 5, 2]]) == [True, True, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3]]) == [True, False, False]\n assert candidate(queries = [[2, 15, 1], [1, 5], [2, 10, 5], [1, 10], [2, 15, 5]]) == [True, True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [1, 7], [2, 10, 3], [1, 5], [2, 10, 2]]) == [True, True, True]\n assert candidate(queries = [[1, 5], [1, 8], [2, 8, 4], [1, 6], [2, 8, 3]]) == [True, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 5, 3], [2, 5, 1]]) == [False, True]\n assert candidate(queries = [[2, 5, 3], [1, 3], [2, 5, 2]]) == [True, True]\n assert candidate(queries = [[1, 5], [1, 10], [2, 7, 3], [1, 15], [2, 15, 6]]) == [True, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [2, 3, 3], [2, 5, 2], [1, 4], [2, 4, 2]]) == [False, True, False]\n assert candidate(queries = [[1, 5], [1, 3], [2, 4, 2], [2, 6, 3]]) == [True, True]\n assert candidate(queries = [[1, 2], [1, 5], [1, 8], [2, 10, 3], [2, 10, 2], [2, 10, 1]]) == [True, True, True]\n assert candidate(queries = [[1, 2], [1, 4], [1, 6], [1, 8], [2, 10, 3]]) == [False]\n assert candidate(queries = [[1, 4], [2, 6, 3], [1, 2], [2, 8, 6], [1, 6], [2, 10, 5]]) == [True, False, False]\n assert candidate(queries = [[1, 5], [1, 10], [2, 9, 3], [1, 15], [2, 14, 5]]) == [True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [1, 7], [2, 10, 5], [2, 10, 2]]) == [True, False, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [1, 7], [2, 10, 6], [1, 5], [2, 10, 4]]) == [True, False, False]\n assert candidate(queries = [[1, 10], [1, 5], [2, 12, 4], [2, 8, 3]]) == [True, True]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [2, 3, 1], [2, 3, 2]]) == [True, False]\n assert candidate(queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5, 4], [2, 10, 5]]) == [False, True]\n assert candidate(queries = [[1, 3], [1, 5], [1, 7], [2, 8, 2], [2, 8, 4], [2, 8, 6]]) == [True, False, False]\n assert candidate(queries = [[2, 10, 5], [1, 5], [2, 10, 4], [1, 8], [2, 10, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 10], [1, 5], [2, 15, 5], [2, 10, 3], [1, 12], [2, 15, 4]]) == [True, True, True]\n assert candidate(queries = [[2, 5, 4], [1, 3], [2, 3, 2], [1, 5], [2, 5, 3]]) == [True, True, True]\n assert candidate(queries = [[1, 5], [1, 10], [2, 15, 6], [2, 15, 10], [2, 15, 11]]) == [False, False, False]\n assert candidate(queries = [[2, 1, 1], [1, 1], [2, 1, 1]]) == [True, True]\n assert candidate(queries = [[1, 5], [1, 10], [2, 8, 3], [2, 12, 5]]) == [True, True]\n assert candidate(queries = [[2, 10, 5], [1, 3], [2, 10, 3], [1, 7], [2, 10, 4]]) == [True, True, True]\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,3,3],[2,3,1],[2,2,2]]", "[[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]"], "hints": ["Let d[x] be the distance of the next obstacle after x.", "For each query of type 2, we just need to check if max(d[0], d[1], d[2], …d[x - sz]) > sz.", "Use segment tree to maintain d[x]."], "metadata": {"canonical_parameter_names": ["queries"], "leetcode_dataset_entry_point": "Solution().getResults", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:16+00:00", "tests_total": 131, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "binary-indexed-tree", "segment-tree", "ordered-set"]}, "language": "ruby", "interface": {"raw_signature": "def get_results(queries)", "container": null, "callable": "get_results", "parameters": [{"name": "queries", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3162, "task_id": "find-the-number-of-good-pairs-i", "difficulty": "Easy", "problem_description": "You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k.\n\nA pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).\n\nReturn the total number of good pairs.\n\nExample 1:\n\nInput: nums1 = [1,3,4], nums2 = [1,3,4], k = 1\nOutput: 5\nExplanation:\nThe 5 good pairs are (0, 0), (1, 0), (1, 1), (2, 0), and (2, 2).\n\nExample 2:\n\nInput: nums1 = [1,2,4,12], nums2 = [2,4], k = 3\nOutput: 2\nExplanation:\nThe 2 good pairs are (3, 0) and (3, 1).\n\nConstraints:\n\n- 1 <= n, m <= 50\n- 1 <= nums1[i], nums2[j] <= 50\n- 1 <= k <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7],k = 3) == 2\n assert candidate(nums1 = [1, 3, 4],nums2 = [1, 3, 4],k = 1) == 5\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 1) == 7\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 3) == 2\n assert candidate(nums1 = [7, 14, 21],nums2 = [7, 14],k = 1) == 4\n assert candidate(nums1 = [5, 10, 15],nums2 = [1, 2, 3],k = 5) == 5\n assert candidate(nums1 = [10, 20, 30],nums2 = [2, 5, 10],k = 1) == 9\n assert candidate(nums1 = [5, 10, 15],nums2 = [1, 5],k = 2) == 2\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 10],k = 2) == 4\n assert candidate(nums1 = [1, 2, 4, 12],nums2 = [2, 4],k = 3) == 2\n assert candidate(nums1 = [8, 16, 24, 32],nums2 = [2, 4, 8],k = 2) == 10\n assert candidate(nums1 = [8, 16, 24, 32, 40],nums2 = [2, 4, 8],k = 4) == 8\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [2, 4, 5, 10],k = 5) == 9\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [2, 4, 5, 10],k = 2) == 10\n assert candidate(nums1 = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],nums2 = [2, 4, 8],k = 4) == 8\n assert candidate(nums1 = [6, 12, 18, 24, 30],nums2 = [1, 2, 3, 4, 5],k = 2) == 14\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [2, 5, 10],k = 2) == 9\n assert candidate(nums1 = [6, 12, 18, 24, 30, 36],nums2 = [1, 2, 3, 4, 6],k = 2) == 19\n assert candidate(nums1 = [12, 18, 24, 36, 48],nums2 = [1, 3, 4, 6, 12],k = 2) == 18\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [2, 5, 10],k = 5) == 7\n assert candidate(nums1 = [24, 36, 48],nums2 = [2, 3, 6, 12],k = 4) == 8\n assert candidate(nums1 = [12, 18, 24, 30, 36, 42],nums2 = [2, 3, 4],k = 6) == 6\n assert candidate(nums1 = [9, 18, 27, 36, 45],nums2 = [3, 6, 9],k = 3) == 8\n assert candidate(nums1 = [8, 16, 24, 32, 40],nums2 = [2, 4, 8],k = 2) == 12\n assert candidate(nums1 = [7, 14, 21, 28, 35, 42, 49],nums2 = [1, 7, 14],k = 7) == 8\n assert candidate(nums1 = [9, 18, 27, 36, 45],nums2 = [1, 3, 9],k = 3) == 11\n", "comparison": "exact"}, "public_tests": ["[1,3,4]\n[1,3,4]\n1", "[1,2,4,12]\n[2,4]\n3"], "hints": ["The constraints are small. Check all pairs."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "k"], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:19+00:00", "tests_total": 106, "tests_dropped": 80, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_pairs(nums1, nums2, k)", "container": null, "callable": "number_of_pairs", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3163, "task_id": "string-compression-iii", "difficulty": "Medium", "problem_description": "Given a string word, compress it using the following algorithm:\n\n- Begin with an empty string comp. While word is not empty, use the following operation:\n - Remove a maximum length prefix of word made of a single character c repeating at most 9 times.\n - Append the length of the prefix followed by c to comp.\n\nReturn the string comp.\n\nExample 1:\n\nInput: word = \"abcde\"\nOutput: \"1a1b1c1d1e\"\nExplanation:\nInitially, comp = \"\". Apply the operation 5 times, choosing \"a\", \"b\", \"c\", \"d\", and \"e\" as the prefix in each operation.\nFor each prefix, append \"1\" followed by the character to comp.\n\nExample 2:\n\nInput: word = \"aaaaaaaaaaaaaabb\"\nOutput: \"9a5a2b\"\nExplanation:\nInitially, comp = \"\". Apply the operation 3 times, choosing \"aaaaaaaaa\", \"aaaaa\", and \"bb\" as the prefix in each operation.\n- For prefix \"aaaaaaaaa\", append \"9\" followed by \"a\" to comp.\n- For prefix \"aaaaa\", append \"5\" followed by \"a\" to comp.\n- For prefix \"bb\", append \"2\" followed by \"b\" to comp.\n\nConstraints:\n\n- 1 <= word.length <= 2 * 10^5\n- word consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"pppppppppppppppppppppppppppppppppppppp\") == \"9p9p9p9p2p\"\n assert candidate(word = \"abcde\") == \"1a1b1c1d1e\"\n assert candidate(word = \"aabbcc\") == \"2a2b2c\"\n assert candidate(word = \"aaaaaaaaaaaaaabb\") == \"9a5a2b\"\n assert candidate(word = \"ababababab\") == \"1a1b1a1b1a1b1a1b1a1b\"\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbccccccccddddddddd\") == \"9a1a9b8c9d\"\n assert candidate(word = \"aabcccccaaa\") == \"2a1b5c3a\"\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"2a2b2c2d2e2f2g2h2i2j2k2l2m2n2o2p2q2r2s2t2u2v2w2x2y2z\"\n assert candidate(word = \"aabbccddeeffgghhiijj\") == \"2a2b2c2d2e2f2g2h2i2j\"\n assert candidate(word = \"zzzzzzzzzz\") == \"9z1z\"\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"9z9z9z9z9z5z\"\n assert candidate(word = \"a\") == \"1a\"\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzz\") == \"2a2b2c2d2e2f2g2h2i2j2k2l2m2n2o2p2q2r2s2t2u2v2w2x2y9z1z\"\n assert candidate(word = \"mmmmmmmmmmnnnnnnnnnnoooooooooollllllllkkkkkkkkkjjjjjjjjjiiiiiiiii\") == \"9m1m9n1n9o1o8l9k9j9i\"\n assert candidate(word = \"abcdefghijklmnopqrstuvwxzyz\") == \"1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1z1y1z\"\n assert candidate(word = \"abababababababababab\") == \"1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b\"\n assert candidate(word = \"zzzzyyyyxxxxwwwwvvvvuuuuttttssssrrrrqqqqppppllllkkkkjjjjiiggggffffeeeeddddccccbbbbaaa\") == \"4z4y4x4w4v4u4t4s4r4q4p4l4k4j2i4g4f4e4d4c4b3a\"\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbccccccccddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnooooooooooppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxxyyyyyyyyyyzzzzzzzzzz\") == \"9a1a9b8c8d9e1e9f1f9g1g9h1h9i1i9j1j9k1k9l1l9m1m9n1n9o1o9p1p9q1q9r1r9s1s9t1t9u1u9v1v9w1w9x2x9y1y9z1z\"\n assert candidate(word = \"aaaaaabbccccddeeeeeeffffgggghhhhiiiiiijjjjkkkkklllllmmmmmnnnnooooo\") == \"6a2b4c2d6e4f4g4h6i4j5k5l5m4n5o\"\n assert candidate(word = \"abababababababababababababababababababab\") == \"1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b1a1b\"\n assert candidate(word = \"aaabbbcccddd\") == \"3a3b3c3d\"\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhh\") == \"9a1a9b1b9c1c9d9e1e9f1f9g1g9h1h\"\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == \"9a9a9a9a9a9a9a9a\"\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == \"1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z\"\n", "comparison": "exact"}, "public_tests": ["\"abcde\"", "\"aaaaaaaaaaaaaabb\""], "hints": ["Each time, just cut the same character in prefix up to at max 9 times. It’s always better to cut a bigger prefix."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().compressedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:21+00:00", "tests_total": 25, "tests_dropped": 1, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def compressed_string(word)", "container": null, "callable": "compressed_string", "parameters": [{"name": "word", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3164, "task_id": "find-the-number-of-good-pairs-ii", "difficulty": "Medium", "problem_description": "You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k.\n\nA pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).\n\nReturn the total number of good pairs.\n\nExample 1:\n\nInput: nums1 = [1,3,4], nums2 = [1,3,4], k = 1\nOutput: 5\nExplanation:\nThe 5 good pairs are (0, 0), (1, 0), (1, 1), (2, 0), and (2, 2).\n\nExample 2:\n\nInput: nums1 = [1,2,4,12], nums2 = [2,4], k = 3\nOutput: 2\nExplanation:\nThe 2 good pairs are (3, 0) and (3, 1).\n\nConstraints:\n\n- 1 <= n, m <= 10^5\n- 1 <= nums1[i], nums2[j] <= 10^6\n- 1 <= k <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [7, 14, 21],nums2 = [1, 7, 14],k = 7) == 3\n assert candidate(nums1 = [1, 3, 4],nums2 = [1, 3, 4],k = 1) == 5\n assert candidate(nums1 = [100, 200, 300],nums2 = [10, 20, 30],k = 10) == 5\n assert candidate(nums1 = [5, 10, 15],nums2 = [1, 5, 10],k = 1) == 7\n assert candidate(nums1 = [7, 14, 28],nums2 = [1, 2, 4],k = 7) == 6\n assert candidate(nums1 = [1, 2, 4, 12],nums2 = [2, 4],k = 3) == 2\n assert candidate(nums1 = [100, 200, 300],nums2 = [5, 10, 15],k = 5) == 7\n assert candidate(nums1 = [5, 10, 15, 20],nums2 = [1, 2, 5],k = 2) == 5\n assert candidate(nums1 = [999999, 999998, 999997, 999996, 999995],nums2 = [1, 2, 3, 4, 5],k = 100) == 0\n assert candidate(nums1 = [7, 14, 21, 28, 35],nums2 = [1, 2, 3, 4, 5, 6, 7],k = 7) == 10\n assert candidate(nums1 = [7, 14, 21, 28, 35],nums2 = [1, 7, 14, 21, 28, 35],k = 1) == 15\n assert candidate(nums1 = [6, 12, 18, 24, 30],nums2 = [2, 3, 6],k = 2) == 9\n assert candidate(nums1 = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 100) == 0\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [5, 10, 15, 20, 25, 30],k = 10) == 22\n assert candidate(nums1 = [12, 24, 36, 48, 60],nums2 = [1, 2, 3, 4, 5, 6],k = 2) == 23\n assert candidate(nums1 = [100000, 200000, 300000, 400000],nums2 = [100, 200, 300, 400],k = 10) == 13\n assert candidate(nums1 = [120, 180, 240, 300],nums2 = [5, 10, 15, 20, 25, 30],k = 6) == 13\n assert candidate(nums1 = [72, 144, 216, 288, 360],nums2 = [8, 12, 24, 36],k = 3) == 16\n assert candidate(nums1 = [810, 1620, 2430, 3240, 4050, 4860, 5490, 6120, 6840, 7560],nums2 = [5, 10, 15, 18, 20, 25, 30, 45, 60, 90],k = 5) == 16\n assert candidate(nums1 = [987654, 876543, 765432, 654321, 543210],nums2 = [98765, 87654, 76543, 65432, 54321],k = 10) == 1\n assert candidate(nums1 = [210, 330, 450, 570],nums2 = [3, 6, 9, 12],k = 5) == 9\n assert candidate(nums1 = [101, 202, 303, 404, 505],nums2 = [1, 101, 202, 303, 404],k = 1) == 14\n assert candidate(nums1 = [333, 666, 999, 1332, 1665],nums2 = [3, 6, 9, 12, 15],k = 3) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 1) == 50\n assert candidate(nums1 = [999999, 999998, 999997],nums2 = [999, 998, 997],k = 1) == 1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 1) == 25\n assert candidate(nums1 = [999999, 999998, 999997, 999996, 999995],nums2 = [999, 998, 997, 996, 995],k = 1000) == 0\n assert candidate(nums1 = [104729, 209458, 314187, 418916, 523645, 628374, 733103, 837832, 942561],nums2 = [104729, 209458, 314187],k = 1) == 16\n assert candidate(nums1 = [120, 150, 180, 210],nums2 = [3, 5, 6, 7],k = 4) == 5\n assert candidate(nums1 = [333, 666, 999, 1332, 1665],nums2 = [3, 9, 27, 81],k = 3) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 100\n assert candidate(nums1 = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],nums2 = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],k = 10) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 55\n assert candidate(nums1 = [1000000, 999999, 999998],nums2 = [1, 2, 3, 4, 5],k = 1000) == 4\n assert candidate(nums1 = [500, 1000, 1500, 2000, 2500],nums2 = [5, 10, 25],k = 4) == 12\n assert candidate(nums1 = [1000000, 1000000, 1000000, 1000000],nums2 = [1, 2, 4, 5],k = 1000) == 16\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [10, 20, 30, 40, 50],k = 5) == 14\n assert candidate(nums1 = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],nums2 = [1, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 11\n assert candidate(nums1 = [500, 1000, 1500, 2000, 2500],nums2 = [25, 50, 75],k = 2) == 11\n assert candidate(nums1 = [987654, 321456, 789123, 123456, 456789],nums2 = [123, 321, 654, 456, 789],k = 23) == 0\n assert candidate(nums1 = [111111, 222222, 333333, 444444, 555555],nums2 = [11, 22, 33, 44, 55],k = 11) == 0\n assert candidate(nums1 = [555555, 666666, 777777, 888888, 999999],nums2 = [5, 6, 7, 8, 9, 55, 66, 77, 88, 99],k = 111) == 18\n assert candidate(nums1 = [101, 202, 303, 404, 505, 606, 707, 808, 909],nums2 = [1, 10, 100, 1000],k = 1) == 9\n assert candidate(nums1 = [999999, 888888, 777777, 666666, 555555],nums2 = [111111, 222222, 333333, 444444, 555555],k = 111) == 0\n assert candidate(nums1 = [1024, 2048, 4096, 8192],nums2 = [32, 64, 128],k = 16) == 11\n assert candidate(nums1 = [123456, 234567, 345678, 456789],nums2 = [123, 234, 345, 456],k = 7) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 100\n assert candidate(nums1 = [999999, 888888, 777777, 666666],nums2 = [333333, 222222, 111111],k = 3) == 4\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [10, 20, 30, 40, 50],k = 10) == 18\n assert candidate(nums1 = [1000000, 500000, 250000, 125000, 62500],nums2 = [125, 250, 500],k = 2) == 14\n assert candidate(nums1 = [210, 420, 630, 840, 1050],nums2 = [1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210],k = 2) == 56\n assert candidate(nums1 = [100000, 200000, 300000, 400000, 500000],nums2 = [50000, 100000, 150000, 200000, 250000],k = 1000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 1) == 25\n assert candidate(nums1 = [123456, 234567, 345678, 456789, 567890],nums2 = [123, 456, 789],k = 12) == 0\n assert candidate(nums1 = [12345, 67890, 11111, 22222, 33333],nums2 = [3, 9, 27, 81, 243],k = 3) == 0\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [1, 2, 5, 10, 20],k = 25) == 25\n assert candidate(nums1 = [101, 202, 303, 404, 505],nums2 = [1, 2, 3, 4, 5, 6],k = 101) == 10\n assert candidate(nums1 = [1000000, 1000000, 1000000],nums2 = [1, 10, 100, 1000],k = 100) == 12\n assert candidate(nums1 = [500000, 600000, 700000, 800000],nums2 = [50000, 60000, 70000, 80000],k = 10) == 4\n assert candidate(nums1 = [987654, 456789, 123456, 654321],nums2 = [6, 12, 18, 24, 30, 36, 42],k = 7) == 0\n assert candidate(nums1 = [97, 194, 291, 388, 485],nums2 = [1, 97, 194],k = 1) == 12\n assert candidate(nums1 = [77, 143, 209, 275],nums2 = [7, 11, 13, 17],k = 1) == 6\n assert candidate(nums1 = [21, 42, 63, 84, 105],nums2 = [3, 7, 21],k = 1) == 15\n assert candidate(nums1 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],nums2 = [1, 2, 4, 5, 10, 20, 25, 50, 100],k = 1) == 90\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5],k = 1) == 22\n assert candidate(nums1 = [7, 14, 21, 28, 35, 42, 49],nums2 = [1, 2, 3, 4, 5, 6, 7],k = 7) == 16\n assert candidate(nums1 = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],nums2 = [5, 10, 15, 20, 25],k = 50) == 21\n assert candidate(nums1 = [123456, 234567, 345678, 456789],nums2 = [123, 234, 345, 456],k = 3) == 0\n assert candidate(nums1 = [123456, 234567, 345678, 456789],nums2 = [123, 234, 345],k = 6) == 0\n assert candidate(nums1 = [12, 24, 36, 48, 60],nums2 = [1, 2, 3, 4, 5, 6],k = 2) == 23\n assert candidate(nums1 = [123456, 654321, 111111, 222222],nums2 = [123, 321, 111, 222, 444],k = 3) == 0\n assert candidate(nums1 = [1024, 2048, 4096, 8192, 16384],nums2 = [16, 32, 64, 128, 256],k = 32) == 19\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 100) == 67\n assert candidate(nums1 = [100000, 200000, 300000, 400000],nums2 = [1, 2, 3, 4, 5],k = 100) == 17\n assert candidate(nums1 = [1000000, 900000, 800000, 700000],nums2 = [100, 200, 300, 400],k = 25) == 13\n assert candidate(nums1 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 40\n assert candidate(nums1 = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],nums2 = [1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18, 30],k = 4) == 6\n assert candidate(nums1 = [123456, 234567, 345678, 456789, 567890],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 123) == 0\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30],nums2 = [1, 5, 10, 15, 20, 25, 30],k = 5) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 3, 5, 7, 9],k = 1) == 17\n assert candidate(nums1 = [111111, 222222, 333333, 444444, 555555],nums2 = [111, 222, 333, 444, 555],k = 111) == 0\n assert candidate(nums1 = [100000, 200000, 300000, 400000, 500000, 600000],nums2 = [100, 200, 300, 400, 500, 600],k = 1000) == 14\n assert candidate(nums1 = [777777, 888888, 999999],nums2 = [7, 8, 9, 77, 88, 99, 777, 888, 999],k = 11) == 10\n", "comparison": "exact"}, "public_tests": ["[1,3,4]\n[1,3,4]\n1", "[1,2,4,12]\n[2,4]\n3"], "hints": ["Let f[v] be the number of occurrences of v/k in nums2.", "For each value v in nums1, enumerating all its factors d (in sqrt(v) time) and sum up all the f[d] to get the final answer.", "It is also possible to improve the complexity from len(nums1) * sqrt(v) to len(nums1) * log(v) - How?"], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "k"], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:24+00:00", "tests_total": 93, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_pairs(nums1, nums2, k)", "container": null, "callable": "number_of_pairs", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3165, "task_id": "maximum-sum-of-subsequence-with-non-adjacent-elements", "difficulty": "Hard", "problem_description": "You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [pos_i, x_i].\n\nFor query i, we first set nums[pos_i] equal to x_i, then we calculate the answer to query i which is the maximum sum of a subsequence of nums where no two adjacent elements are selected.\n\nReturn the sum of the answers to all queries.\n\nSince the final answer may be very large, return it modulo 10^9 + 7.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [3,5,9], queries = [[1,-2],[0,-3]]\nOutput: 21\nExplanation:\nAfter the 1^st query, nums = [3,-2,9] and the maximum sum of a subsequence with non-adjacent elements is 3 + 9 = 12.\nAfter the 2^nd query, nums = [-3,-2,9] and the maximum sum of a subsequence with non-adjacent elements is 9.\n\nExample 2:\n\nInput: nums = [0,-1], queries = [[0,-5]]\nOutput: 0\nExplanation:\nAfter the 1^st query, nums = [-5,-1] and the maximum sum of a subsequence with non-adjacent elements is 0 (choosing an empty subsequence).\n\nConstraints:\n\n- 1 <= nums.length <= 5 * 10^4\n- -10^5 <= nums[i] <= 10^5\n- 1 <= queries.length <= 5 * 10^4\n- queries[i] == [pos_i, x_i]\n- 0 <= pos_i <= nums.length - 1\n- -10^5 <= x_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 200, 300, 400, 500],queries = [[0, -100], [2, -200], [4, -300]]) == 2100\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 10], [4, -10], [2, 0]]) == 46\n assert candidate(nums = [-1, -2, -3, -4, -5],queries = [[1, 2], [3, 4], [4, 5]]) == 15\n assert candidate(nums = [3, 5, 9],queries = [[1, -2], [0, -3]]) == 21\n assert candidate(nums = [0, -1],queries = [[0, -5]]) == 0\n assert candidate(nums = [100000, -100000, 100000, -100000, 100000],queries = [[0, -100000], [2, -100000], [4, -100000]]) == 300000\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 5], [2, 1], [4, -1]]) == 33\n assert candidate(nums = [100000, -100000, 50000, -50000],queries = [[0, 50000], [1, -50000], [2, 100000], [3, -100000]]) == 500000\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 5], [2, -1], [4, 10]]) == 38\n assert candidate(nums = [-10, -20, -30, -40],queries = [[1, 10], [3, 20]]) == 40\n assert candidate(nums = [-5, -4, -3, -2, -1],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 22\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, -100000], [1, -99999], [2, -99998], [3, -99997], [4, -99996], [5, -99995], [6, -99994], [7, -99993], [8, -99992], [9, -99991]]) == 1900\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],queries = [[0, -100000], [1, -100000], [2, -100000], [3, -100000], [4, -100000]]) == 1900000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],queries = [[0, 30], [1, 28], [2, 26], [3, 24], [4, 22], [5, 20], [6, 18], [7, 16], [8, 14], [9, 12], [10, 10], [11, 8], [12, 6], [13, 4], [14, 2]]) == 2536\n assert candidate(nums = [1, 3, 2, 1, 100, 1, 1, 1, 1, 1],queries = [[4, 200], [4, 300], [4, 400], [4, 500], [4, 600]]) == 2025\n assert candidate(nums = [-100000, -90000, -80000, -70000, -60000, -50000, -40000, -30000, -20000, -10000],queries = [[0, -50000], [2, -30000], [4, -10000]]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 0], [3, 0], [5, 0], [7, 0], [9, 0]]) == 1350\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 153\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, -1], [1, -2], [2, -3], [3, -4], [4, -5], [5, -6], [6, -7], [7, -8], [8, -9], [9, -10]]) == 190\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 0], [2, 0], [4, 0], [6, 0], [8, 0]]) == 15000\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 80\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],queries = [[0, 99995], [4, 99994], [2, 99993], [1, 99992], [3, 99991]]) == 1499922\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 125\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 10], [0, 20], [0, 30], [0, 40], [0, 50]]) == 190\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],queries = [[0, 10], [1, -10], [2, 10], [3, -10], [4, 10], [5, -10], [6, 10], [7, -10], [8, 10], [9, -10]]) == 440\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],queries = [[0, 100], [1, -100], [2, 200], [3, -200], [4, 300], [5, -300], [6, 400], [7, -400], [8, 500], [9, -500]]) == 7800\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, -1], [2, -1], [4, -1], [6, -1], [8, -1]]) == 150\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1],queries = [[0, 100000], [1, 100000], [2, 100000], [3, 100000], [4, 100000], [5, 100000], [6, 100000], [7, 100000], [8, 100000], [9, 100000]]) == 3000020\n assert candidate(nums = [-99999, 99999, -99998, 99998, -99997, 99997, -99996, 99996, -99995, 99995],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 2499905\n assert candidate(nums = [-100000, -100000, -100000, -100000, -100000],queries = [[0, 100000], [1, 100000], [2, 100000], [3, 100000], [4, 100000]]) == 900000\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 125\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10]]) == 460\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 430\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 165\n assert candidate(nums = [100000, -100000, 90000, -90000, 80000, -80000, 70000, -70000, 60000, -60000],queries = [[0, 100000], [1, -100000], [2, 90000], [3, -90000], [4, 80000], [5, -80000], [6, 70000], [7, -70000], [8, 60000], [9, -60000]]) == 4000000\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 125\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, -100], [1, 100], [2, -200], [3, 200], [4, -300], [5, 300], [6, -400], [7, 400], [8, -500], [9, 500]]) == 7400\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) == 150\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 5], [1, 15], [2, 25], [3, 35], [4, 45], [5, 55], [6, 65], [7, 75], [8, 85], [9, 95]]) == 2875\n assert candidate(nums = [100000, -100000, 50000, -50000, 25000, -25000],queries = [[0, 100000], [1, 0], [2, -50000], [3, 0], [4, 25000], [5, 0]]) == 850000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 1000], [1, 900], [2, 800], [3, 700], [4, 600], [5, 500], [6, 400], [7, 300], [8, 200], [9, 100]]) == 39200\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 10], [1, -10], [2, 20], [3, -20], [4, 30], [5, -30]]) == 364\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, -1], [9, -10], [5, -6], [2, -3]]) == 101\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],queries = [[0, -100000], [1, -100000], [2, -100000], [3, -100000], [4, -100000]]) == 600000\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],queries = [[0, 1], [2, 2], [4, 3], [6, 4], [8, 5], [1, 5], [3, 4], [5, 3], [7, 2], [9, 1]]) == 124\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100]]) == 1410\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],queries = [[0, 0], [2, 0], [4, 0], [6, 0], [8, 0]]) == 2499875\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, 5], [1, 4], [2, 3], [3, 2], [4, 1], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 92\n assert candidate(nums = [50000, -50000, 50000, -50000, 50000],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0]]) == 300000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2]]) == 80\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [[0, -1], [1, -2], [2, -3], [3, -4], [4, -5], [0, 5], [1, 4], [2, 3], [3, 2], [4, 1]]) == 61\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 19000\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],queries = [[0, 1000], [1, 1000], [2, 1000], [3, 1000], [4, 1000]]) == 9016\n assert candidate(nums = [5, 8, 2, 7, 10, 1, 5, 3, 4, 6],queries = [[0, -5], [1, -8], [2, -2], [3, -7], [4, -10], [5, -1], [6, -5], [7, -3], [8, -4], [9, -6]]) == 137\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, -100], [1, -200], [2, -300], [3, -400], [4, -500], [5, -600], [6, -700], [7, -800], [8, -900], [9, -1000]]) == 19000\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],queries = [[1, 1], [3, 1], [5, 1], [7, 1], [9, 1]]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 2370\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 10], [2, 20], [4, 30], [6, 40], [8, 50], [9, 60]]) == 590\n assert candidate(nums = [10000, -20000, 30000, -40000, 50000, -60000, 70000, -80000, 90000, -100000],queries = [[0, 10000], [1, -10000], [2, 10000], [3, -10000], [4, 10000], [5, -10000], [6, 10000], [7, -10000], [8, 10000], [9, -10000]]) == 1700000\n assert candidate(nums = [100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000],queries = [[0, -1], [1, 1], [2, -1], [3, 1], [4, -1], [5, 1], [6, -1], [7, 1]]) == 1200013\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, -1], [2, -3], [4, -5], [6, -7], [8, -9]]) == 150\n assert candidate(nums = [50000, -50000, 50000, -50000, 50000, -50000, 50000, -50000, 50000, -50000],queries = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 1000000\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],queries = [[0, 50000], [1, 50000], [2, 50000], [3, 50000], [4, 50000], [5, 50000], [6, 50000], [7, 50000], [8, 50000], [9, 50000]]) == 1500800\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [[0, 15], [1, 10], [2, 5], [3, 0], [4, -5], [5, -10], [6, -15], [7, -20], [8, -25], [9, -30]]) == 1125\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 100], [2, 200], [4, 300], [6, 400], [8, 500]]) == 3580\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],queries = [[0, -100000], [1, -90000], [2, -80000], [3, -70000], [4, -60000], [5, -50000], [6, -40000], [7, -30000], [8, -20000], [9, -10000]]) == 950000\n assert candidate(nums = [1, 2, 3, -1, -2, -3, 4, 5, 6, -4, -5, -6],queries = [[0, 10], [3, 20], [6, 30], [9, 40], [11, 50]]) == 379\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000],queries = [[0, -1000], [1, 200], [2, -300], [3, 400], [4, -500], [5, 600], [6, -700], [7, 800], [8, -900], [9, 1000]]) == 23000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 20], [1, 18], [2, 16], [3, 14], [4, 12], [5, 10], [6, 8], [7, 6], [8, 4], [9, 2]]) == 762\n assert candidate(nums = [1, -10, 2, -20, 3, -30, 4, -40, 5, -50],queries = [[0, 10], [2, 20], [4, 30], [6, 40], [8, 50]]) == 390\n assert candidate(nums = [-100000, -99999, -99998, -99997, -99996],queries = [[0, -99995], [4, -99994], [2, -99993], [1, -99992], [3, -99991]]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, -1], [1, 0], [2, -1], [3, 0], [4, -1], [5, 0], [6, -1], [7, 0], [8, -1], [9, 0], [10, -1], [11, 0], [12, -1], [13, 0], [14, -1]]) == 616\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],queries = [[0, 10], [1, -10], [2, 20], [3, -20], [4, 30], [5, -30], [6, 40], [7, -40], [8, 50], [9, -50]]) == 840\n assert candidate(nums = [-100, 200, -300, 400, -500, 600, -700, 800, -900, 1000],queries = [[1, -1000], [3, 1000], [5, -1000], [7, 1000], [9, -1000]]) == 14000\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100]]) == 1331\n assert candidate(nums = [0, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5],queries = [[0, -100], [1, 100], [2, -200], [3, 200], [4, -300], [5, 300], [6, -400], [7, 400], [8, -500], [9, 500], [10, -600]]) == 7095\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [[0, -5], [1, -10], [2, -15], [3, -20], [4, -25], [5, -30], [6, -35], [7, -40], [8, -45], [9, -50]]) == 950\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],queries = [[0, 1], [1, 0], [2, 1], [3, 0], [4, 1], [5, 0], [6, 1], [7, 0], [8, 1], [9, 0]]) == 50\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50]]) == 300\n assert candidate(nums = [0, 1, 0, -1, 0, 1, 0, -1, 0, 1],queries = [[0, 1], [2, 1], [4, 1], [6, 1], [8, 1]]) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, -10], [2, 0], [4, 20], [6, -20], [8, 30]]) == 192\n assert candidate(nums = [5, -1, 4, 2, 3],queries = [[1, 100], [2, -5], [0, 0], [3, 300]]) == 709\n assert candidate(nums = [5, -5, 5, -5, 5, -5, 5, -5, 5, -5],queries = [[0, 10], [1, -10], [2, 10], [3, -10], [4, 10], [5, -10], [6, 10], [7, -10], [8, 10], [9, -10]]) == 400\n", "comparison": "exact"}, "public_tests": ["[3,5,9]\n[[1,-2],[0,-3]]", "[0,-1]\n[[0,-5]]"], "hints": ["Can you solve each query in O(nums.length) with dynamic programming?", "In order to optimize, we will use segment tree where each node contains the maximum value of (front element has been chosen or not, back element has been chosen or not)."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().maximumSumSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:26+00:00", "tests_total": 87, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "divide-and-conquer", "dynamic-programming", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_sum_subsequence(nums, queries)", "container": null, "callable": "maximum_sum_subsequence", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3168, "task_id": "minimum-number-of-chairs-in-a-waiting-room", "difficulty": "Easy", "problem_description": "You are given a string s. Simulate events at each second i:\n\n- If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it.\n- If s[i] == 'L', a person leaves the waiting room, freeing up a chair.\n\nReturn the minimum number of chairs needed so that a chair is available for every person who enters the waiting room given that it is initially empty.\n\nExample 1:\n\nInput: s = \"EEEEEEE\"\nOutput: 7\nExplanation:\nAfter each second, a person enters the waiting room and no person leaves it. Therefore, a minimum of 7 chairs is needed.\n\nExample 2:\n\nInput: s = \"ELELEEL\"\nOutput: 2\nExplanation:\nLet's consider that there are 2 chairs in the waiting room. The table below shows the state of the waiting room at each second.\n\nSecond | Event | People in the Waiting Room | Available Chairs\n0 | Enter | 1 | 1\n1 | Leave | 0 | 2\n2 | Enter | 1 | 1\n3 | Leave | 0 | 2\n4 | Enter | 1 | 1\n5 | Enter | 2 | 0\n6 | Leave | 1 | 1\n\nExample 3:\n\nInput: s = \"ELEELEELLL\"\nOutput: 3\nExplanation:\nLet's consider that there are 3 chairs in the waiting room. The table below shows the state of the waiting room at each second.\n\nSecond | Event | People in the Waiting Room | Available Chairs\n0 | Enter | 1 | 2\n1 | Leave | 0 | 3\n2 | Enter | 1 | 2\n3 | Enter | 2 | 1\n4 | Leave | 1 | 2\n5 | Enter | 2 | 1\n6 | Enter | 3 | 0\n7 | Leave | 2 | 1\n8 | Leave | 1 | 2\n9 | Leave | 0 | 3\n\nConstraints:\n\n- 1 <= s.length <= 50\n- s consists only of the letters 'E' and 'L'.\n- s represents a valid sequence of entries and exits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"ELEELEELLL\") == 3\n assert candidate(s = \"EEEEEEE\") == 7\n assert candidate(s = \"EELLEELLL\") == 2\n assert candidate(s = \"E\") == 1\n assert candidate(s = \"EELLEL\") == 2\n assert candidate(s = \"ELE\") == 1\n assert candidate(s = \"LE\") == 0\n assert candidate(s = \"ELEEL\") == 2\n assert candidate(s = \"ELELEEL\") == 2\n assert candidate(s = \"ELLEEL\") == 1\n assert candidate(s = \"EEEEELLLL\") == 5\n assert candidate(s = \"EEEELEEL\") == 5\n assert candidate(s = \"ELLEELLEELLE\") == 1\n assert candidate(s = \"LELELEL\") == 0\n assert candidate(s = \"LELELELEL\") == 0\n assert candidate(s = \"ELELELELEL\") == 1\n assert candidate(s = \"EL\") == 1\n assert candidate(s = \"EEELLLL\") == 3\n assert candidate(s = \"ELEELLEL\") == 2\n assert candidate(s = \"ELLELE\") == 1\n assert candidate(s = \"ELLEELLEEL\") == 1\n assert candidate(s = \"LEELLEEL\") == 1\n assert candidate(s = \"EEEELEEEE\") == 7\n assert candidate(s = \"L\") == 0\n assert candidate(s = \"LLL\") == 0\n assert candidate(s = \"EELEEL\") == 3\n assert candidate(s = \"ELLELELEL\") == 1\n assert candidate(s = \"LEELLEELEELLELEEL\") == 2\n assert candidate(s = \"EEEEEEEEEELLLLLLLLLLLL\") == 10\n assert candidate(s = \"EEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLL\") == 19\n assert candidate(s = \"EEEEEEEEEEEEEEEEEEEE\") == 20\n assert candidate(s = \"EELLEELLEE\") == 2\n assert candidate(s = \"ELEELLEELLEELLLL\") == 2\n assert candidate(s = \"ELLEELLEEELLEELLE\") == 2\n assert candidate(s = \"EEEEEEELEELLLLEEEE\") == 8\n assert candidate(s = \"ELEELLEELLEELLEELLEELLE\") == 2\n assert candidate(s = \"LEELEELLEELEELLEELEELLEELEELLEELEEL\") == 6\n assert candidate(s = \"EEEEELLEELLEELLEELLEEE\") == 6\n assert candidate(s = \"ELELELELELELEL\") == 1\n assert candidate(s = \"LEEELLLLLEEEEEE\") == 3\n assert candidate(s = \"EEEEEELLLLLL\") == 6\n assert candidate(s = \"EEEELEEEEELEEEEELEEEEELEEEEELEEEEELEEEEELEEE\") == 30\n assert candidate(s = \"EEEEELLLLEELLL\") == 5\n assert candidate(s = \"LLELELELELELELEE\") == 0\n assert candidate(s = \"EEEEEEEEEELELELELELELE\") == 10\n assert candidate(s = \"ELELLELLELLELLELLE\") == 1\n assert candidate(s = \"EEEEELEELLLLLE\") == 6\n assert candidate(s = \"ELELELLELELLEL\") == 1\n assert candidate(s = \"ELEELLEELLEELLEELLEELLEELLEELLEELLEELL\") == 2\n assert candidate(s = \"EEEELELEELLEEEE\") == 7\n assert candidate(s = \"ELEELLEELLEELLEL\") == 2\n assert candidate(s = \"EEELLLLLLEELEELLEEL\") == 3\n assert candidate(s = \"EEEEEEEEEEEEEEEEEEEEEELE\") == 22\n assert candidate(s = \"LEEEEELELELEEL\") == 5\n assert candidate(s = \"ELLEEELLEELLEELLEELLEELLE\") == 2\n assert candidate(s = \"EEEELELELELELELEL\") == 4\n assert candidate(s = \"EEEEEEEEELLLL\") == 9\n assert candidate(s = \"ELLEELLEELLEELLE\") == 1\n assert candidate(s = \"ELEELLEELLEELLEELLEELLEELLEELLEELLE\") == 2\n assert candidate(s = \"EELEELEELEELEE\") == 6\n assert candidate(s = \"EEEEELLLLEEEEEELLLLLEEE\") == 7\n assert candidate(s = \"LEELLEELLEELLEELL\") == 1\n assert candidate(s = \"EEEEEEEELELLELLE\") == 8\n assert candidate(s = \"LELELELELELELELELE\") == 0\n assert candidate(s = \"LEELLEELLEELLEEL\") == 1\n assert candidate(s = \"LLEELLELLEELLE\") == 0\n assert candidate(s = \"ELELELELELELE\") == 1\n assert candidate(s = \"EEEEEEEEEEELELELELELELELELELELELELELELELEEEE\") == 14\n assert candidate(s = \"EEEEELLEELLEELLEELLE\") == 5\n assert candidate(s = \"EELLEELLEELE\") == 2\n assert candidate(s = \"LEELLEELLEELLEELLEEL\") == 1\n assert candidate(s = \"ELLEEELLEEELLEEELLEEELLEEELLEE\") == 6\n assert candidate(s = \"ELELELELELEL\") == 1\n assert candidate(s = \"EEEEELLEELLELLLL\") == 5\n assert candidate(s = \"EELEELLEELLEEELLEELLE\") == 4\n assert candidate(s = \"EEEEEELLLLLLLL\") == 6\n assert candidate(s = \"ELLLLLLEEEEEEL\") == 1\n assert candidate(s = \"EEEEELLLLEELLLLL\") == 5\n assert candidate(s = \"LEEEEEEEEEEEEEEEEEEEEEEE\") == 22\n assert candidate(s = \"ELLEELLEEELLEEELLEEELLEEEL\") == 5\n assert candidate(s = \"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\") == 40\n assert candidate(s = \"EEEEEEEEEEELLL\") == 11\n assert candidate(s = \"EELEEEELLLLLLLEELLLL\") == 5\n assert candidate(s = \"ELEELEELLELEEELLELEL\") == 4\n assert candidate(s = \"EEEEELLLLLEELLLLLEEEE\") == 5\n assert candidate(s = \"EEEELLLLLLLLEEE\") == 4\n assert candidate(s = \"EELEEELEEELEEELEEELEEELEEELE\") == 14\n assert candidate(s = \"EEEEELLEELLLEELL\") == 5\n assert candidate(s = \"EEEEELLLLLEEEE\") == 5\n assert candidate(s = \"EEEEEEEEEEEEEEEELLLLLLLLLLLLLLL\") == 16\n assert candidate(s = \"LELLELELLELELLELELLELLEL\") == 0\n assert candidate(s = \"ELLEELLEELLEELLEELLEEEEE\") == 4\n assert candidate(s = \"ELLEELLEELLEELLEELLEELLEELLEELLEELLEELLEELLE\") == 1\n assert candidate(s = \"ELELELELELELELELEL\") == 1\n assert candidate(s = \"ELLEELLEELLEELLL\") == 1\n assert candidate(s = \"EEEEELLLLEEEEE\") == 6\n assert candidate(s = \"EEEELELLLL\") == 4\n assert candidate(s = \"LEEELEEELEEELEEELEEELEEELEEELEEELEEELEEEEE\") == 22\n assert candidate(s = \"EEEEEEEEEEEEEEEEEEEEE\") == 21\n assert candidate(s = \"LELELELELELELELELELELELELELELELELELELELELELE\") == 0\n assert candidate(s = \"EEEEELLEEEEEEELLLLEEEE\") == 10\n assert candidate(s = \"LLEELLELLEELLEELLEELLEELLE\") == 0\n assert candidate(s = \"EEELLEELLEELLEELLEELLEEL\") == 3\n assert candidate(s = \"LELELELELELELELELELELEL\") == 0\n assert candidate(s = \"LEELLEELLEELLELL\") == 1\n assert candidate(s = \"ELLEELLEELLEELLLLL\") == 1\n assert candidate(s = \"EEEEEEEEEELEEEEEEEEELEEEEEEEEEEELEEEEEEEEE\") == 36\n assert candidate(s = \"LELELELELELELELELELELELELELELELELELELELELELELE\") == 0\n assert candidate(s = \"ELLEELLEELLEELLEELLEELLEELLEELLE\") == 1\n assert candidate(s = \"ELLEELLEELLEELLEELLEELLEELLEELLEELLEEL\") == 1\n assert candidate(s = \"ELLELELLELLEELLE\") == 1\n assert candidate(s = \"ELELLELLELLELLEL\") == 1\n assert candidate(s = \"EEEEEEEEELLLLLLLLL\") == 9\n assert candidate(s = \"EEEEEEEEELLLLLLLLLLLL\") == 9\n assert candidate(s = \"LELELELELELELELELELELELELELELELELELELELELELELELEL\") == 0\n assert candidate(s = \"ELLEELLELLEE\") == 1\n assert candidate(s = \"ELLEELLEELLEELLEELLEELL\") == 1\n assert candidate(s = \"EEELLEELLEELLE\") == 3\n assert candidate(s = \"LELELELELELELELELELE\") == 0\n assert candidate(s = \"ELEELLEELLEELLEELLEELLEELLEELLEELLEELLEELLEEL\") == 2\n assert candidate(s = \"ELEELLEELLEELLEELLEELLEELLEELLEELLEELLEELLEELL\") == 2\n assert candidate(s = \"EELLEELEELLEELEELLEELEELLEELEELLEE\") == 6\n assert candidate(s = \"LEELLEELLEELLEELLEELLEELLEELLEEL\") == 1\n assert candidate(s = \"EEEEEEELLLLLLLELLL\") == 7\n assert candidate(s = \"ELLEELLEELLEELLEELLE\") == 1\n assert candidate(s = \"LLLLLLLLLLEEEEEEEEEE\") == 0\n assert candidate(s = \"EEEEEEELLLLLLLEEEE\") == 7\n assert candidate(s = \"LEELLEELLEELLEELLEELLEEL\") == 1\n assert candidate(s = \"EEEEELLEELLEELLEELLEELLEELLEELLEELLEEL\") == 5\n assert candidate(s = \"ELLEELLEELLEEL\") == 1\n assert candidate(s = \"ELLELEELLELEELLELEELLELEEL\") == 1\n assert candidate(s = \"LEELLEEELLEL\") == 2\n assert candidate(s = \"EEEEELLLLLLLEEELLLLLEEELLLLLLLEEEEE\") == 5\n assert candidate(s = \"ELEELLEEL\") == 2\n assert candidate(s = \"LEEEEEELLEEEEEELLEEEEEELLE\") == 13\n assert candidate(s = \"EELLEELLLEELL\") == 2\n assert candidate(s = \"EELLEELLLLEEEL\") == 2\n assert candidate(s = \"LELELELELELELELELELELELE\") == 0\n assert candidate(s = \"ELEELEELEELEELEELEE\") == 7\n", "comparison": "exact"}, "public_tests": ["\"EEEEEEE\"", "\"ELELEEL\"", "\"ELEELEELLL\""], "hints": ["Iterate from left to right over the string and keep track of the number of people in the waiting room using a variable that you will increment on every occurrence of ‘E’ and decrement on every occurrence of ‘L’.", "The answer is the maximum number of people in the waiting room at any instance."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumChairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:31+00:00", "tests_total": 144, "tests_dropped": 5, "flags": [], "topic_tags": ["string", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_chairs(s)", "container": null, "callable": "minimum_chairs", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3169, "task_id": "count-days-without-meetings", "difficulty": "Medium", "problem_description": "You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive).\n\nReturn the count of days when the employee is available for work but no meetings are scheduled.\n\nNote: The meetings may overlap.\n\nExample 1:\n\nInput: days = 10, meetings = [[5,7],[1,3],[9,10]]\nOutput: 2\nExplanation:\nThere is no meeting scheduled on the 4^th and 8^th days.\n\nExample 2:\n\nInput: days = 5, meetings = [[2,4],[1,3]]\nOutput: 1\nExplanation:\nThere is no meeting scheduled on the 5^thday.\n\nExample 3:\n\nInput: days = 6, meetings = [[1,6]]\nOutput: 0\nExplanation:\nMeetings are scheduled for all working days.\n\nConstraints:\n\n- 1 <= days <= 10^9\n- 1 <= meetings.length <= 10^5\n- meetings[i].length == 2\n- 1 <= meetings[i][0] <= meetings[i][1] <= days\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(days = 15,meetings = [[5, 6], [6, 7], [7, 8]]) == 11\n assert candidate(days = 10,meetings = [[5, 7], [1, 3], [9, 10]]) == 2\n assert candidate(days = 15,meetings = [[1, 2], [3, 5], [6, 8], [10, 12], [14, 15]]) == 2\n assert candidate(days = 20,meetings = [[5, 10], [15, 20]]) == 8\n assert candidate(days = 5,meetings = [[2, 4], [1, 3]]) == 1\n assert candidate(days = 7,meetings = [[1, 2], [3, 4], [5, 6], [7, 7]]) == 0\n assert candidate(days = 30,meetings = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30]]) == 0\n assert candidate(days = 10,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 5\n assert candidate(days = 20,meetings = [[1, 10], [15, 20]]) == 4\n assert candidate(days = 20,meetings = [[1, 5], [10, 15], [5, 10]]) == 5\n assert candidate(days = 6,meetings = [[1, 6]]) == 0\n assert candidate(days = 15,meetings = [[1, 2], [3, 5], [6, 7], [8, 10], [11, 13], [14, 15]]) == 0\n assert candidate(days = 100,meetings = [[1, 10], [20, 30], [40, 50], [60, 70], [80, 90]]) == 46\n assert candidate(days = 7,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == 0\n assert candidate(days = 100,meetings = [[10, 20], [30, 40], [50, 60]]) == 67\n assert candidate(days = 25,meetings = [[5, 15], [10, 20]]) == 9\n assert candidate(days = 15,meetings = [[2, 5], [6, 9], [12, 13]]) == 5\n assert candidate(days = 7,meetings = [[1, 2], [3, 4], [5, 6]]) == 1\n assert candidate(days = 1,meetings = [[1, 1]]) == 0\n assert candidate(days = 30,meetings = [[5, 10], [15, 20], [25, 30]]) == 12\n assert candidate(days = 20,meetings = [[1, 2], [3, 5], [8, 10], [15, 20]]) == 6\n assert candidate(days = 100,meetings = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50]]) == 50\n assert candidate(days = 50,meetings = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50]]) == 0\n assert candidate(days = 1000,meetings = [[1, 500], [501, 1000], [250, 750]]) == 0\n assert candidate(days = 100,meetings = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55], [55, 60], [60, 65], [65, 70], [70, 75], [75, 80], [80, 85], [85, 90], [90, 95], [95, 100]]) == 4\n assert candidate(days = 1000,meetings = [[100, 200], [300, 400], [500, 600], [700, 800], [900, 1000]]) == 495\n assert candidate(days = 1000000,meetings = [[1, 1000000]]) == 0\n assert candidate(days = 100,meetings = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]]) == 0\n assert candidate(days = 100,meetings = [[1, 3], [2, 5], [3, 7], [4, 9], [5, 11], [6, 13], [7, 15], [8, 17], [9, 19], [10, 21], [11, 23], [12, 25], [13, 27], [14, 29], [15, 31], [16, 33], [17, 35], [18, 37], [19, 39], [20, 41], [21, 43], [22, 45], [23, 47], [24, 49], [25, 51], [26, 53], [27, 55], [28, 57], [29, 59], [30, 61], [31, 63], [32, 65], [33, 67], [34, 69], [35, 71], [36, 73], [37, 75], [38, 77], [39, 79], [40, 81], [41, 83], [42, 85], [43, 87], [44, 89], [45, 91], [46, 93], [47, 95], [48, 97], [49, 99]]) == 1\n assert candidate(days = 200,meetings = [[1, 50], [51, 100], [101, 150], [151, 200], [50, 100], [100, 150], [150, 200], [1, 100], [100, 200], [1, 200], [10, 90], [20, 80], [30, 70], [40, 60], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90]]) == 0\n assert candidate(days = 100,meetings = [[1, 99], [2, 98], [3, 97], [4, 96]]) == 1\n assert candidate(days = 1000,meetings = [[1, 200], [201, 400], [401, 600], [601, 800], [801, 1000]]) == 0\n assert candidate(days = 100,meetings = [[1, 100]]) == 0\n assert candidate(days = 1000000,meetings = [[1, 1000000], [100000, 200000], [200000, 300000], [300000, 400000], [400000, 500000], [500000, 600000], [600000, 700000], [700000, 800000], [800000, 900000], [900000, 1000000]]) == 0\n assert candidate(days = 50,meetings = [[5, 10], [8, 12], [15, 20], [18, 22], [25, 30], [28, 32], [35, 40], [38, 42], [45, 50]]) == 12\n assert candidate(days = 1000,meetings = [[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], [155, 160], [165, 170], [175, 180], [185, 190], [195, 200], [205, 210], [215, 220], [225, 230], [235, 240], [245, 250], [255, 260], [265, 270], [275, 280], [285, 290], [295, 300], [305, 310], [315, 320], [325, 330], [335, 340], [345, 350], [355, 360], [365, 370], [375, 380], [385, 390], [395, 400], [405, 410], [415, 420], [425, 430], [435, 440], [445, 450], [455, 460], [465, 470], [475, 480], [485, 490], [495, 500], [505, 510], [515, 520], [525, 530], [535, 540], [545, 550], [555, 560], [565, 570], [575, 580], [585, 590], [595, 600], [605, 610], [615, 620], [625, 630], [635, 640], [645, 650], [655, 660], [665, 670], [675, 680], [685, 690], [695, 700], [705, 710], [715, 720], [725, 730], [735, 740], [745, 750], [755, 760], [765, 770], [775, 780], [785, 790], [795, 800], [805, 810], [815, 820], [825, 830], [835, 840], [845, 850], [855, 860], [865, 870], [875, 880], [885, 890], [895, 900], [905, 910], [915, 920], [925, 930], [935, 940], [945, 950], [955, 960], [965, 970], [975, 980], [985, 990], [995, 1000]]) == 400\n assert candidate(days = 200,meetings = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20], [22, 23], [25, 26], [28, 29], [31, 32], [34, 35], [37, 38], [40, 41], [43, 44], [46, 47], [49, 50], [52, 53], [55, 56], [58, 59], [61, 62], [64, 65], [67, 68], [70, 71], [73, 74], [76, 77], [79, 80], [82, 83], [85, 86], [88, 89], [91, 92], [94, 95], [97, 98], [99, 100], [101, 102], [103, 104], [105, 106], [107, 108], [109, 110], [111, 112], [113, 114], [115, 116], [117, 118], [119, 120], [121, 122], [123, 124], [125, 126], [127, 128], [129, 130], [131, 132], [133, 134], [135, 136], [137, 138], [139, 140], [141, 142], [143, 144], [145, 146], [147, 148], [149, 150], [151, 152], [153, 154], [155, 156], [157, 158], [159, 160], [161, 162], [163, 164], [165, 166], [167, 168], [169, 170], [171, 172], [173, 174], [175, 176], [177, 178], [179, 180], [181, 182], [183, 184], [185, 186], [187, 188], [189, 190], [191, 192], [193, 194], [195, 196], [197, 198], [199, 200]]) == 32\n assert candidate(days = 1000000,meetings = [[1, 500000], [500001, 1000000]]) == 0\n assert candidate(days = 1000,meetings = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 980\n assert candidate(days = 500,meetings = [[1, 10], [100, 200], [300, 400], [490, 500]]) == 277\n assert candidate(days = 100,meetings = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [47, 48], [48, 49], [49, 50], [50, 51], [51, 52], [52, 53], [53, 54], [54, 55], [55, 56], [56, 57], [57, 58], [58, 59], [59, 60], [60, 61], [61, 62], [62, 63], [63, 64], [64, 65], [65, 66], [66, 67], [67, 68], [68, 69], [69, 70], [70, 71], [71, 72], [72, 73], [73, 74], [74, 75], [75, 76], [76, 77], [77, 78], [78, 79], [79, 80], [80, 81], [81, 82], [82, 83], [83, 84], [84, 85], [85, 86], [86, 87], [87, 88], [88, 89], [89, 90], [90, 91], [91, 92], [92, 93], [93, 94], [94, 95], [95, 96], [96, 97], [97, 98], [98, 99], [99, 100]]) == 0\n assert candidate(days = 500,meetings = [[1, 250], [200, 300], [400, 500]]) == 99\n assert candidate(days = 1000000000,meetings = [[1, 500000000], [500000001, 1000000000]]) == 0\n assert candidate(days = 100,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31], [32, 32], [33, 33], [34, 34], [35, 35], [36, 36], [37, 37], [38, 38], [39, 39], [40, 40], [41, 41], [42, 42], [43, 43], [44, 44], [45, 45], [46, 46], [47, 47], [48, 48], [49, 49], [50, 50], [51, 51], [52, 52], [53, 53], [54, 54], [55, 55], [56, 56], [57, 57], [58, 58], [59, 59], [60, 60], [61, 61], [62, 62], [63, 63], [64, 64], [65, 65], [66, 66], [67, 67], [68, 68], [69, 69], [70, 70], [71, 71], [72, 72], [73, 73], [74, 74], [75, 75], [76, 76], [77, 77], [78, 78], [79, 79], [80, 80], [81, 81], [82, 82], [83, 83], [84, 84], [85, 85], [86, 86], [87, 87], [88, 88], [89, 89], [90, 90], [91, 91], [92, 92], [93, 93], [94, 94], [95, 95], [96, 96], [97, 97], [98, 98], [99, 99], [100, 100]]) == 0\n assert candidate(days = 50,meetings = [[1, 2], [3, 5], [6, 8], [9, 11], [12, 14], [15, 17], [18, 20], [21, 23], [24, 26], [27, 29], [30, 32], [33, 35], [36, 38], [39, 41], [42, 44], [45, 47], [48, 49]]) == 1\n assert candidate(days = 1000000,meetings = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]]) == 999979\n assert candidate(days = 10,meetings = [[1, 10], [2, 3], [4, 5], [6, 7], [8, 9], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 0\n assert candidate(days = 1000,meetings = [[1, 1000], [100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000]]) == 0\n assert candidate(days = 20,meetings = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15], [12, 16], [13, 17], [14, 18], [15, 19], [16, 20]]) == 0\n assert candidate(days = 50,meetings = [[1, 10], [5, 15], [10, 20], [15, 25], [20, 30]]) == 20\n assert candidate(days = 10,meetings = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 0\n assert candidate(days = 500,meetings = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350], [300, 400], [350, 450], [400, 500]]) == 0\n assert candidate(days = 1000000,meetings = [[1, 1000000]]) == 0\n assert candidate(days = 1000,meetings = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 986\n assert candidate(days = 365,meetings = [[1, 10], [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, 155], [160, 165], [170, 175], [180, 185], [190, 195], [200, 205], [210, 215], [220, 225], [230, 235], [240, 245], [250, 255], [260, 265], [270, 275], [280, 285], [290, 295], [300, 305], [310, 315], [320, 325], [330, 335], [340, 345], [350, 355], [360, 365]]) == 145\n assert candidate(days = 10,meetings = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 10]]) == 0\n assert candidate(days = 1000000000,meetings = [[1, 1000000000]]) == 0\n assert candidate(days = 50,meetings = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [5, 15], [10, 25], [20, 35], [30, 45], [40, 50]]) == 0\n assert candidate(days = 1000,meetings = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]]) == 979\n assert candidate(days = 365,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31], [32, 32], [33, 33], [34, 34], [35, 35], [36, 36], [37, 37], [38, 38], [39, 39], [40, 40], [41, 41], [42, 42], [43, 43], [44, 44], [45, 45], [46, 46], [47, 47], [48, 48], [49, 49], [50, 50], [51, 51], [52, 52], [53, 53], [54, 54], [55, 55], [56, 56], [57, 57], [58, 58], [59, 59], [60, 60], [61, 61], [62, 62], [63, 63], [64, 64], [65, 65], [66, 66], [67, 67], [68, 68], [69, 69], [70, 70], [71, 71], [72, 72], [73, 73], [74, 74], [75, 75], [76, 76], [77, 77], [78, 78], [79, 79], [80, 80], [81, 81], [82, 82], [83, 83], [84, 84], [85, 85], [86, 86], [87, 87], [88, 88], [89, 89], [90, 90], [91, 91], [92, 92], [93, 93], [94, 94], [95, 95], [96, 96], [97, 97], [98, 98], [99, 99], [100, 100], [101, 101], [102, 102], [103, 103], [104, 104], [105, 105], [106, 106], [107, 107], [108, 108], [109, 109], [110, 110], [111, 111], [112, 112], [113, 113], [114, 114], [115, 115], [116, 116], [117, 117], [118, 118], [119, 119], [120, 120], [121, 121], [122, 122], [123, 123], [124, 124], [125, 125], [126, 126], [127, 127], [128, 128], [129, 129], [130, 130], [131, 131], [132, 132], [133, 133], [134, 134], [135, 135], [136, 136], [137, 137], [138, 138], [139, 139], [140, 140], [141, 141], [142, 142], [143, 143], [144, 144], [145, 145], [146, 146], [147, 147], [148, 148], [149, 149], [150, 150], [151, 151], [152, 152], [153, 153], [154, 154], [155, 155], [156, 156], [157, 157], [158, 158], [159, 159], [160, 160], [161, 161], [162, 162], [163, 163], [164, 164], [165, 165], [166, 166], [167, 167], [168, 168], [169, 169], [170, 170], [171, 171], [172, 172], [173, 173], [174, 174], [175, 175], [176, 176], [177, 177], [178, 178], [179, 179], [180, 180], [181, 181], [182, 182], [183, 183], [184, 184], [185, 185], [186, 186], [187, 187], [188, 188], [189, 189], [190, 190], [191, 191], [192, 192], [193, 193], [194, 194], [195, 195], [196, 196], [197, 197], [198, 198], [199, 199], [200, 200], [201, 201], [202, 202], [203, 203], [204, 204], [205, 205], [206, 206], [207, 207], [208, 208], [209, 209], [210, 210], [211, 211], [212, 212], [213, 213], [214, 214], [215, 215], [216, 216], [217, 217], [218, 218], [219, 219], [220, 220], [221, 221], [222, 222], [223, 223], [224, 224], [225, 225], [226, 226], [227, 227], [228, 228], [229, 229], [230, 230], [231, 231], [232, 232], [233, 233], [234, 234], [235, 235], [236, 236], [237, 237], [238, 238], [239, 239], [240, 240], [241, 241], [242, 242], [243, 243], [244, 244], [245, 245], [246, 246], [247, 247], [248, 248], [249, 249], [250, 250], [251, 251], [252, 252], [253, 253], [254, 254], [255, 255], [256, 256], [257, 257], [258, 258], [259, 259], [260, 260], [261, 261], [262, 262], [263, 263], [264, 264], [265, 265], [266, 266], [267, 267], [268, 268], [269, 269], [270, 270], [271, 271], [272, 272], [273, 273], [274, 274], [275, 275], [276, 276], [277, 277], [278, 278], [279, 279], [280, 280], [281, 281], [282, 282], [283, 283], [284, 284], [285, 285], [286, 286], [287, 287], [288, 288], [289, 289], [290, 290], [291, 291], [292, 292], [293, 293], [294, 294], [295, 295], [296, 296], [297, 297], [298, 298], [299, 299], [300, 300], [301, 301], [302, 302], [303, 303], [304, 304], [305, 305], [306, 306], [307, 307], [308, 308], [309, 309], [310, 310], [311, 311], [312, 312], [313, 313], [314, 314], [315, 315], [316, 316], [317, 317], [318, 318], [319, 319], [320, 320], [321, 321], [322, 322], [323, 323], [324, 324], [325, 325], [326, 326], [327, 327], [328, 328], [329, 329], [330, 330], [331, 331], [332, 332], [333, 333], [334, 334], [335, 335], [336, 336], [337, 337], [338, 338], [339, 339], [340, 340], [341, 341], [342, 342], [343, 343], [344, 344], [345, 345], [346, 346], [347, 347], [348, 348], [349, 349], [350, 350], [351, 351], [352, 352], [353, 353], [354, 354], [355, 355], [356, 356], [357, 357], [358, 358], [359, 359], [360, 360], [361, 361], [362, 362], [363, 363], [364, 364], [365, 365]]) == 0\n assert candidate(days = 100,meetings = [[1, 10], [5, 15], [10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50], [45, 55], [50, 60], [55, 65], [60, 70], [65, 75], [70, 80], [75, 85], [80, 90], [85, 95], [90, 100]]) == 0\n assert candidate(days = 100,meetings = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15], [12, 16], [13, 17], [14, 18], [15, 19], [16, 20], [17, 21], [18, 22], [19, 23], [20, 24], [21, 25], [22, 26], [23, 27], [24, 28], [25, 29], [26, 30], [27, 31], [28, 32], [29, 33], [30, 34], [31, 35], [32, 36], [33, 37], [34, 38], [35, 39], [36, 40], [37, 41], [38, 42], [39, 43], [40, 44], [41, 45], [42, 46], [43, 47], [44, 48], [45, 49], [46, 50], [47, 51], [48, 52], [49, 53], [50, 54], [51, 55], [52, 56], [53, 57], [54, 58], [55, 59], [56, 60], [57, 61], [58, 62], [59, 63], [60, 64], [61, 65], [62, 66], [63, 67], [64, 68], [65, 69], [66, 70], [67, 71], [68, 72], [69, 73], [70, 74], [71, 75], [72, 76], [73, 77], [74, 78], [75, 79], [76, 80], [77, 81], [78, 82], [79, 83], [80, 84], [81, 85], [82, 86], [83, 87], [84, 88], [85, 89], [86, 90], [87, 91], [88, 92], [89, 93], [90, 94], [91, 95], [92, 96], [93, 97], [94, 98], [95, 99], [96, 100]]) == 0\n assert candidate(days = 100,meetings = [[20, 30], [25, 35], [30, 40], [35, 45], [40, 50]]) == 69\n assert candidate(days = 100,meetings = [[1, 50], [51, 100]]) == 0\n assert candidate(days = 500,meetings = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 490\n assert candidate(days = 500,meetings = [[1, 500]]) == 0\n assert candidate(days = 2,meetings = [[1, 1]]) == 1\n assert candidate(days = 100,meetings = [[1, 50], [51, 100], [25, 75], [76, 100], [1, 25]]) == 0\n assert candidate(days = 1000000,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31], [32, 32], [33, 33], [34, 34], [35, 35], [36, 36], [37, 37], [38, 38], [39, 39], [40, 40], [41, 41], [42, 42], [43, 43], [44, 44], [45, 45], [46, 46], [47, 47], [48, 48], [49, 49], [50, 50]]) == 999950\n assert candidate(days = 10,meetings = [[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]]) == 0\n assert candidate(days = 10,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 0\n assert candidate(days = 100,meetings = [[1, 50], [51, 100], [25, 75], [76, 100], [1, 25], [76, 100]]) == 0\n assert candidate(days = 200,meetings = [[1, 50], [25, 75], [50, 100], [75, 125], [100, 150], [125, 175], [150, 200]]) == 0\n assert candidate(days = 100,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 90\n assert candidate(days = 999999999,meetings = [[1, 999999999]]) == 0\n assert candidate(days = 200,meetings = [[1, 50], [51, 100], [101, 150], [151, 200]]) == 0\n assert candidate(days = 100,meetings = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 90\n assert candidate(days = 500,meetings = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100], [101, 110], [111, 120], [121, 130], [131, 140], [141, 150], [151, 160], [161, 170], [171, 180], [181, 190], [191, 200], [201, 210], [211, 220], [221, 230], [231, 240], [241, 250], [251, 260], [261, 270], [271, 280], [281, 290], [291, 300], [301, 310], [311, 320], [321, 330], [331, 340], [341, 350], [351, 360], [361, 370], [371, 380], [381, 390], [391, 400], [401, 410], [411, 420], [421, 430], [431, 440], [441, 450], [451, 460], [461, 470], [471, 480], [481, 490], [491, 500]]) == 0\n assert candidate(days = 50,meetings = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15], [12, 16], [13, 17], [14, 18], [15, 19], [16, 20]]) == 30\n assert candidate(days = 1000000,meetings = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 999980\n assert candidate(days = 100,meetings = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91], [11, 90], [12, 89], [13, 88], [14, 87], [15, 86], [16, 85], [17, 84], [18, 83], [19, 82], [20, 81], [21, 80], [22, 79], [23, 78], [24, 77], [25, 76], [26, 75], [27, 74], [28, 73], [29, 72], [30, 71], [31, 70], [32, 69], [33, 68], [34, 67], [35, 66], [36, 65], [37, 64], [38, 63], [39, 62], [40, 61], [41, 60], [42, 59], [43, 58], [44, 57], [45, 56], [46, 55], [47, 54], [48, 53], [49, 52], [50, 51]]) == 0\n assert candidate(days = 365,meetings = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31], [32, 32], [33, 33], [34, 34], [35, 35], [36, 36], [37, 37], [38, 38], [39, 39], [40, 40], [41, 41], [42, 42], [43, 43], [44, 44], [45, 45], [46, 46], [47, 47], [48, 48], [49, 49], [50, 50]]) == 315\n assert candidate(days = 1000000,meetings = [[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], [61, 62], [63, 64], [65, 66], [67, 68], [69, 70], [71, 72], [73, 74], [75, 76], [77, 78], [79, 80], [81, 82], [83, 84], [85, 86], [87, 88], [89, 90], [91, 92], [93, 94], [95, 96], [97, 98], [99, 100]]) == 999900\n assert candidate(days = 10,meetings = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == 0\n assert candidate(days = 1000,meetings = [[1, 100], [200, 300], [400, 500], [600, 700], [800, 900]]) == 496\n assert candidate(days = 2,meetings = [[1, 2]]) == 0\n assert candidate(days = 50,meetings = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30]]) == 24\n assert candidate(days = 100,meetings = [[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], [61, 62], [63, 64], [65, 66], [67, 68], [69, 70], [71, 72], [73, 74], [75, 76], [77, 78], [79, 80], [81, 82], [83, 84], [85, 86], [87, 88], [89, 90], [91, 92], [93, 94], [95, 96], [97, 98], [99, 100]]) == 0\n assert candidate(days = 100,meetings = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45], [50, 50]]) == 90\n", "comparison": "exact"}, "public_tests": ["10\n[[5,7],[1,3],[9,10]]", "5\n[[2,4],[1,3]]", "6\n[[1,6]]"], "hints": ["Merge the overlapping meetings and sort the new meetings timings.", "Return the sum of difference between the end time of a meeting and the start time of the next meeting for all adjacent pairs."], "metadata": {"canonical_parameter_names": ["days", "meetings"], "leetcode_dataset_entry_point": "Solution().countDays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:34+00:00", "tests_total": 90, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def count_days(days, meetings)", "container": null, "callable": "count_days", "parameters": [{"name": "days", "type": "Integer"}, {"name": "meetings", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3170, "task_id": "lexicographically-minimum-string-after-removing-stars", "difficulty": "Medium", "problem_description": "You are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters.\n\nWhile there is a '*', do the following operation:\n\n- Delete the leftmost '*' and the smallest non-'*' character to its left. If there are several smallest characters, you can delete any of them.\n\nReturn the lexicographically smallest resulting string after removing all '*' characters.\n\nExample 1:\n\nInput: s = \"aaba*\"\nOutput: \"aab\"\nExplanation:\nWe should delete one of the 'a' characters with '*'. If we choose s[3], s becomes the lexicographically smallest.\n\nExample 2:\n\nInput: s = \"abc\"\nOutput: \"abc\"\nExplanation:\nThere is no '*' in the string.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists only of lowercase English letters and '*'.\n- The input is generated such that it is possible to delete all '*' characters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"z\"\n assert candidate(s = \"*a*b*c\") == \"c\"\n assert candidate(s = \"aaba*\") == \"aab\"\n assert candidate(s = \"z*z*z*z\") == \"z\"\n assert candidate(s = \"a*b*c*a*b*c\") == \"c\"\n assert candidate(s = \"zzzzzzzzz***zzzzz\") == \"zzzzzzzzzzz\"\n assert candidate(s = \"abc***\") == \"\"\n assert candidate(s = \"a*a*a*a*a*a*a*a*a*a\") == \"a\"\n assert candidate(s = \"aaabbbccc***\") == \"bbbccc\"\n assert candidate(s = \"ab*c*d*e\") == \"de\"\n assert candidate(s = \"ab*ac*\") == \"bc\"\n assert candidate(s = \"aaa*bbb*ccc\") == \"abbbccc\"\n assert candidate(s = \"abcde*****fghij\") == \"fghij\"\n assert candidate(s = \"a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"z\"\n assert candidate(s = \"a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*a\") == \"a\"\n assert candidate(s = \"leetcode*e*et*c*o*\") == \"leetoeto\"\n assert candidate(s = \"abcabcabc***abc\") == \"bcbcbcabc\"\n assert candidate(s = \"a*a*a*a*a\") == \"a\"\n assert candidate(s = \"abc\") == \"abc\"\n assert candidate(s = \"z*z*z\") == \"z\"\n assert candidate(s = \"aa*bb*c\") == \"bbc\"\n assert candidate(s = \"abcdef*ghij*k*l*m*\") == \"fghijklm\"\n assert candidate(s = \"*a*a*a*a*a*a*a*a*a*a\") == \"a\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba*\") == \"zyxwvutsrqponmlkjihgfedcb\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz*\") == \"bcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"abc*def*ghi*\") == \"defghi\"\n assert candidate(s = \"*a*b*c*\") == \"\"\n assert candidate(s = \"ab*cd*ef*gh*ij*kl*mn*op*qr*st*uv*wx*yz*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"tuvwxyztuvwxyz\"\n assert candidate(s = \"aaabbbccc*bbb*aaa*\") == \"abbbcccbbbaa\"\n assert candidate(s = \"abc*d*efg*h*ijk*lmn*opq*rst*u*v*w*x*y*z*\") == \"opqrstuvwxyz\"\n assert candidate(s = \"aabbaa*bb*a*aa*\") == \"aabbbba\"\n assert candidate(s = \"aaabbbccc***bbb***aaa\") == \"bbbcccaaa\"\n assert candidate(s = \"abracadabra*bra*bra*cad*a\") == \"abracadabrbrbrcda\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz*zyxwvutsrqponmlkjihgfedcba*\") == \"bcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcb\"\n assert candidate(s = \"a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"z\"\n assert candidate(s = \"a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*\") == \"\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz*\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"banana*na*na\") == \"banannna\"\n assert candidate(s = \"abcabcabcabcabcabcabc*abc*abc*abc*\") == \"abcabcabcabcabcabcbcbcbcbc\"\n assert candidate(s = \"*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*\") == \"\"\n assert candidate(s = \"mno*pqr*stu*vwx*yz*abc*def*ghi*jkl\") == \"rstuvwxyzdefghijkl\"\n assert candidate(s = \"abcabcabcabc*abc*abc*abc*abc*abc*abc*abc*abc*\") == \"abcabcabcbcbcbcbcbcbcbcbcbc\"\n assert candidate(s = \"abcdefghijk*lmnopqrst*uvwxyz*\") == \"defghijklmnopqrstuvwxyz\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz***\") == \"bccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"a*a*b*b*c*c*d*d*e*e*f*f*g*g*h*h*i*i*j*j*k*k*l*l*m*m*n*n*o*o*p*p*q*q*r*r*s*s*t*t*u*u*v*v*w*w*x*x*y*y*z*z\") == \"z\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz*\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"abc*def*ghi*jkl*mno*pqr*stu*vwx*yz*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"rstuvwxyzrstuvwxyz\"\n assert candidate(s = \"zzzzz*yyyyy*xxxxx*wwwww*vvvvv*uuuuu*ttttt*sssss*rrrrr*qqqqq*ppppp*ooooo*nnnnn*mmmmm*lllll*kkkkk*jjjjj*iiiii*h*\") == \"zzzzyyyyxxxxwwwwvvvvuuuuttttssssrrrrqqqqppppoooonnnnmmmmllllkkkkjjjjiiii\"\n assert candidate(s = \"zzzzzzzzzzz*a*zzzzzzzzzz*b*zzzzzzzzzz*c*zzzzzzzzzz*d*zzzzzzzzzz*e*zzzzzzzzzz*f*zzzzzzzzzz*g*zzzzzzzzzz*h*zzzzzzzzzz*i*zzzzzzzzzz*j*zzzzzzzzzz*k*zzzzzzzzzz*l*zzzzzzzzzz*m*zzzzzzzzzz*n*zzzzzzzzzz*o*zzzzzzzzzz*p*zzzzzzzzzz*q*zzzzzzzzzz*r*zzzzzzzzzz*s*zzzzzzzzzz*t*zzzzzzzzzz*u*zzzzzzzzzz*v*zzzzzzzzzz*w*zzzzzzzzzz*x*zzzzzzzzzz*y*zzzzzzzzzz*z*\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"a*z*y*x*z*y*x*\") == \"\"\n assert candidate(s = \"a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z\") == \"z\"\n assert candidate(s = \"aaabbbccc*aa*bb*cc*\") == \"abbbcccbbcc\"\n assert candidate(s = \"z*yz*yz*yz*y*z\") == \"zzzz\"\n assert candidate(s = \"xyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx***zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx***zyxzyxzyxzyxzyxzyxzyxzyxzyxzyx***\") == \"xyxzyxzyxzyxzyxzyxzyxzyxzyxzyzyzyzyxzyxzyxzyxzyxzyxzyxzyxzyxzyzyzyzyxzyxzyxzyxzyxzyxzyxzyzyzy\"\n assert candidate(s = \"abc***def***ghi***jkl***mno***pqr***stu***vwx***yz*\") == \"z\"\n assert candidate(s = \"zyxwvu*utsrqponmlkjihgfedcba*\") == \"zyxwvutsrqponmlkjihgfedcb\"\n assert candidate(s = \"abcd*efgh*i*jklm*no*pqrst*uvw*x*y*z\") == \"jklmnopqrstuvwxyz\"\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaab*aaaaaaaaaaaaaaaaaaaaaa\") == \"aaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(s = \"z*z*z*z*z*z*z*z*z*z\") == \"z\"\n assert candidate(s = \"z*z*z*z*z*z*z*z*z*z*z*z*z*z*z*z\") == \"z\"\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz*\") == \"aaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\"\n assert candidate(s = \"zzzzzzzzzzz*zzzzzzzzzz*zzzzzzzzzz*\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"*abcdefghijklmnopqrstuvwxyz*\") == \"bcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"mississippi*m*m*m*s*s*s*i*i*i*p*p*p\") == \"ssssppssspp\"\n assert candidate(s = \"aabbccddeee***f***\") == \"ddeeef\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz*\") == \"abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"b*a*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*\") == \"\"\n assert candidate(s = \"le*etco*de***\") == \"lto\"\n assert candidate(s = \"zyxzyxzyx***\") == \"zyzyzy\"\n assert candidate(s = \"zyx*zyx*zyx*\") == \"zyzyzy\"\n", "comparison": "exact"}, "public_tests": ["\"aaba*\"", "\"abc\""], "hints": [], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().clearStars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:36+00:00", "tests_total": 70, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "stack", "greedy", "heap-priority-queue"]}, "language": "ruby", "interface": {"raw_signature": "def clear_stars(s)", "container": null, "callable": "clear_stars", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3171, "task_id": "find-subarray-with-bitwise-or-closest-to-k", "difficulty": "Hard", "problem_description": "You are given an array nums and an integer k. You need to find a subarray of nums such that the absolute difference between k and the bitwise OR of the subarray elements is as small as possible. In other words, select a subarray nums[l..r] such that |k - (nums[l] OR nums[l + 1] ... OR nums[r])| is minimum.\n\nReturn the minimum possible value of the absolute difference.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,4,5], k = 3\nOutput: 0\nExplanation:\nThe subarray nums[0..1] has OR value 3, which gives the minimum absolute difference |3 - 3| = 0.\n\nExample 2:\n\nInput: nums = [1,3,1,3], k = 2\nOutput: 1\nExplanation:\nThe subarray nums[1..1] has OR value 3, which gives the minimum absolute difference |3 - 2| = 1.\n\nExample 3:\n\nInput: nums = [1], k = 10\nOutput: 9\nExplanation:\nThere is a single subarray with OR value 1, which gives the minimum absolute difference |10 - 1| = 9.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],k = 500000000) == 500000000\n assert candidate(nums = [10, 20, 30, 40],k = 25) == 5\n assert candidate(nums = [1],k = 10) == 9\n assert candidate(nums = [5, 6, 7, 8, 9],k = 7) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 0\n assert candidate(nums = [3, 5, 7, 9],k = 8) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],k = 25) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 2) == 1\n assert candidate(nums = [7, 8, 9],k = 5) == 2\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 0\n assert candidate(nums = [5, 3, 6, 7, 9],k = 4) == 1\n assert candidate(nums = [2, 4, 6, 8, 10],k = 7) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 0\n assert candidate(nums = [1000000000],k = 1000000000) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 65) == 3\n assert candidate(nums = [1, 3, 1, 3],k = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(nums = [3, 3, 3, 3, 3],k = 3) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 255) == 0\n assert candidate(nums = [2, 4, 8, 16, 32],k = 31) == 1\n assert candidate(nums = [5, 7, 9, 11, 13],k = 8) == 1\n assert candidate(nums = [1, 2, 4, 5],k = 3) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431],k = 10000000) == 1611393\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 500) == 11\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 100) == 27\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 3) == 2\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000],k = 1000000000) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1000) == 8\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1) == 1\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180],k = 110) == 1\n assert candidate(nums = [31, 15, 7, 3, 1, 128, 64, 32, 16, 8, 4, 2, 1],k = 127) == 0\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728],k = 268435456) == 256\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 511) == 0\n assert candidate(nums = [1048575, 1048575, 1048575, 1048575, 1048575],k = 1048574) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1023) == 0\n assert candidate(nums = [3, 5, 7, 10, 15, 20],k = 12) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 25) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 3) == 1\n assert candidate(nums = [1, 5, 10, 20, 40, 80, 160, 320, 640, 1280],k = 1000) == 8\n assert candidate(nums = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048],k = 100000) == 1696\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 14) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 3\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995],k = 999999994) == 1\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39],k = 20) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216],k = 10000000) == 1611392\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 3\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 500) == 11\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 64) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 1000000000) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 40) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 16) == 1\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35],k = 20) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 45) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 25) == 3\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 100) == 27\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1024) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 4\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 30) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 3\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 1],k = 10) == 2\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 500) == 4\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995],k = 999999994) == 1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 256, 512, 1024, 2048, 4096],k = 1000) == 23\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1000) == 8\n assert candidate(nums = [3, 7, 2, 5, 10, 14],k = 6) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 1) == 6\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 512) == 1\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39],k = 25) == 2\n assert candidate(nums = [8, 16, 32, 64, 128, 256],k = 200) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 750) == 14\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],k = 50) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 20) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1023) == 1\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 10) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61],k = 42) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 77) == 2\n assert candidate(nums = [3, 6, 1, 8, 9, 10, 5],k = 7) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 0\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],k = 1048576) == 1024\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256],k = 127) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 33) == 2\n assert candidate(nums = [9, 3, 15, 8, 5, 2, 7, 11, 6, 4],k = 13) == 0\n assert candidate(nums = [3, 7, 2, 5, 6, 1, 4, 8, 9],k = 12) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 550) == 42\n assert candidate(nums = [31, 15, 7, 3, 1],k = 4) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 500) == 4\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 500) == 4\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 42) == 3\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 85) == 6\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 1000000000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21],k = 10) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1024) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],k = 2048) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 25) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 28) == 1\n assert candidate(nums = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],k = 20) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],k = 16384) == 0\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 9) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128],k = 100) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1023) == 1022\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 1\n assert candidate(nums = [13, 21, 34, 55, 89, 144, 233, 377, 610, 987],k = 159) == 15\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 27, 29, 30, 31],k = 28) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,4,5]\n3", "[1,3,1,3]\n2", "[1]\n10"], "hints": ["Let dp[i] be the set of all the bitwise OR of all the subarrays ending at index i.", "We start from nums[i], taking the bitwise OR result by including elements one by one from i towards left. Notice that only unset bits can become set on adding an element, and set bits never become unset again.", "Hence dp[i] can contain at most 30 elements."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minimumDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:39+00:00", "tests_total": 124, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "binary-search", "bit-manipulation", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_difference(nums, k)", "container": null, "callable": "minimum_difference", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3174, "task_id": "clear-digits", "difficulty": "Easy", "problem_description": "You are given a string s.\n\nYour task is to remove all digits by doing this operation repeatedly:\n\n- Delete the first digit and the closest non-digit character to its left.\n\nReturn the resulting string after removing all digits.\n\nNote that the operation cannot be performed on a digit that does not have any non-digit character to its left.\n\nExample 1:\n\nInput: s = \"abc\"\nOutput: \"abc\"\nExplanation:\nThere is no digit in the string.\n\nExample 2:\n\nInput: s = \"cb34\"\nOutput: \"\"\nExplanation:\nFirst, we apply the operation on s[2], and s becomes \"c4\".\nThen we apply the operation on s[1], and s becomes \"\".\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists only of lowercase English letters and digits.\n- The input is generated such that it is possible to delete all digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdef\") == \"abcdef\"\n assert candidate(s = \"a1b2c3d4e5\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6\") == \"\"\n assert candidate(s = \"a1b2c3\") == \"\"\n assert candidate(s = \"abcd1234\") == \"\"\n assert candidate(s = \"abcd1\") == \"abc\"\n assert candidate(s = \"cb34\") == \"\"\n assert candidate(s = \"a1b1c1\") == \"\"\n assert candidate(s = \"a1b2c3d4\") == \"\"\n assert candidate(s = \"a1b\") == \"b\"\n assert candidate(s = \"a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1\") == \"\"\n assert candidate(s = \"abc\") == \"abc\"\n assert candidate(s = \"abc1d2e3\") == \"ab\"\n assert candidate(s = \"abcd\") == \"abcd\"\n assert candidate(s = \"abc123\") == \"\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0p1o2n3m4l5k6j7i8h9g0f1e2d3c4b5a6\") == \"\"\n assert candidate(s = \"abc123d4ef5\") == \"e\"\n assert candidate(s = \"z1y2x3w4v5u6t7s8r9q0p1o2n3m4l5k6j7i8h9g0f1e2d3c4b5a6\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0\") == \"\"\n assert candidate(s = \"xyz765mno432lmn109pqr876\") == \"\"\n assert candidate(s = \"hello2world1\") == \"hellworl\"\n assert candidate(s = \"zz9yy8xx7ww6vv5uu4tt3ss2rr1qqppooonnmmllkkjjiihhggffeedcba1\") == \"zyxwvutsrqqppooonnmmllkkjjiihhggffeedcb\"\n assert candidate(s = \"mnbv1234cvbnm5678mnbvc90\") == \"cmnb\"\n assert candidate(s = \"abcdefghij1klmnopqr2stuv3wxyz4abcd5efg6hij7klmno8pqr9stu0vwx1yz2\") == \"abcdefghiklmnopqstuwxyabcefhiklmnpqstvwy\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz1234567890\") == \"abcdefghijklmnop\"\n assert candidate(s = \"q1w2e3r4t5y6u7i8o9p0\") == \"\"\n assert candidate(s = \"abcdefghij1234567890klmnopqrstuvwxyz\") == \"klmnopqrstuvwxyz\"\n assert candidate(s = \"abcdefgh12345678ijkl90mnopqrstu12345678vwxyz0\") == \"ijmvwxy\"\n assert candidate(s = \"abcd1234abcd5678abcd90abcd\") == \"ababcd\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1\") == \"\"\n assert candidate(s = \"x1y2z3a4b5c6d7e8f9g0\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6\") == \"\"\n assert candidate(s = \"a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0c1c2c3c4c5c6c7c8c9c0\") == \"\"\n assert candidate(s = \"abcdefgh1ijklm2nopqr3stuv4wxyz5\") == \"abcdefgijklnopqstuwxy\"\n assert candidate(s = \"m1n2o3p4q5r6s7t8u9v0w1x2y3z4\") == \"\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0\") == \"\"\n assert candidate(s = \"abcdefghij0987654321klmnopqrstuvwxyz\") == \"klmnopqrstuvwxyz\"\n assert candidate(s = \"abcdef123ghijkl456mnopq789rstuv0\") == \"abcghimnrstu\"\n assert candidate(s = \"x1y2z3x1y2z3\") == \"\"\n assert candidate(s = \"xyz123abc456def789ghi0\") == \"gh\"\n assert candidate(s = \"abcdefghi1jklmnopq2rstuvwxy3z\") == \"abcdefghjklmnoprstuvwxz\"\n assert candidate(s = \"aaa1bbb2ccc3ddd4eee5fff6ggg7hhh8iii9jjj\") == \"aabbccddeeffgghhiijjj\"\n assert candidate(s = \"abcdef1ghijkl2mnopqr3stuv4wxyz5\") == \"abcdeghijkmnopqstuwxy\"\n assert candidate(s = \"mno4pqr5stu6vwx7yz8\") == \"mnpqstvwy\"\n assert candidate(s = \"p1q2r3s4t5u6v7w8x9y0z1a2b3c4d5e6f7g8h9i0\") == \"\"\n assert candidate(s = \"abc123def456ghi789jkl0mno1pqr2stu3vwx4yz5\") == \"jkmnpqstvwy\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz0123456789\") == \"abcdefghijklmnop\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4\") == \"\"\n assert candidate(s = \"x9y8z7w6v5u4t3s2r1q0p\") == \"p\"\n assert candidate(s = \"x9y8z7\") == \"\"\n assert candidate(s = \"abcdefghi1jklmnopq2rstuv3wxyz4\") == \"abcdefghjklmnoprstuwxy\"\n assert candidate(s = \"m9n8o7p6q5r4s3t2u1\") == \"\"\n assert candidate(s = \"abc123def456ghi789jkl012mno345pqr678stu90\") == \"s\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q\") == \"q\"\n assert candidate(s = \"abcdefghij1klmnopqr2stuv3wxyz4\") == \"abcdefghiklmnopqstuwxy\"\n assert candidate(s = \"abcdef123ghijkl456mno789pqr12stu34vwxy5z\") == \"abcghipsvwxz\"\n assert candidate(s = \"abcdefghij1234567890\") == \"\"\n assert candidate(s = \"xyz123\") == \"\"\n assert candidate(s = \"abcd1234efgh5678ijkl90\") == \"ij\"\n assert candidate(s = \"abc1def2ghi3jkl4mno5pqr6stu7vwx8yz9\") == \"abdeghjkmnpqstvwy\"\n assert candidate(s = \"x9y8z7x6y5z4x3y2z1\") == \"\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0ponmlkjihgfedcba\") == \"ponmlkjihgfedcba\"\n assert candidate(s = \"xyz7uvw8mno9\") == \"xyuvmn\"\n assert candidate(s = \"abcdefghij1klmnopq2rstuv3wxyz4\") == \"abcdefghiklmnoprstuwxy\"\n assert candidate(s = \"p1q2r3s4t5u6v7w8x9y0z\") == \"z\"\n assert candidate(s = \"z1y2x3w4v5u6t7s8r9q0\") == \"\"\n assert candidate(s = \"abcdefghij1klmnopq2rstuvwx3yz\") == \"abcdefghiklmnoprstuvwyz\"\n assert candidate(s = \"abcdef1ghijkl2mnopqr3stuv4wxyz5abcdef6ghijkl7mnopqr8stuv9wxyz0\") == \"abcdeghijkmnopqstuwxyabcdeghijkmnopqstuwxy\"\n", "comparison": "exact"}, "public_tests": ["\"abc\"", "\"cb34\""], "hints": ["Process string s from left to right, if s[i] is a digit, mark the nearest unmarked non-digit index to its left.", "Delete all digits and all marked characters."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().clearDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:43+00:00", "tests_total": 72, "tests_dropped": 3, "flags": [], "topic_tags": ["string", "stack", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def clear_digits(s)", "container": null, "callable": "clear_digits", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3175, "task_id": "find-the-first-player-to-win-k-games-in-a-row", "difficulty": "Medium", "problem_description": "A competition consists of n players numbered from 0 to n - 1.\n\nYou are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique.\n\nAll players are standing in a queue in order from player 0 to player n - 1.\n\nThe competition process is as follows:\n\n- The first two players in the queue play a game, and the player with the higher skill level wins.\n- After the game, the winner stays at the beginning of the queue, and the loser goes to the end of it.\n\nThe winner of the competition is the first player who wins k games in a row.\n\nReturn the initial index of the winning player.\n\nExample 1:\n\nInput: skills = [4,2,6,3,9], k = 2\nOutput: 2\nExplanation:\nInitially, the queue of players is [0,1,2,3,4]. The following process happens:\n- Players 0 and 1 play a game, since the skill of player 0 is higher than that of player 1, player 0 wins. The resulting queue is [0,2,3,4,1].\n- Players 0 and 2 play a game, since the skill of player 2 is higher than that of player 0, player 2 wins. The resulting queue is [2,3,4,1,0].\n- Players 2 and 3 play a game, since the skill of player 2 is higher than that of player 3, player 2 wins. The resulting queue is [2,4,1,0,3].\n\nPlayer 2 won k = 2 games in a row, so the winner is player 2.\n\nExample 2:\n\nInput: skills = [2,5,4], k = 3\nOutput: 1\nExplanation:\nInitially, the queue of players is [0,1,2]. The following process happens:\n- Players 0 and 1 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is [1,2,0].\n- Players 1 and 2 play a game, since the skill of player 1 is higher than that of player 2, player 1 wins. The resulting queue is [1,0,2].\n- Players 1 and 0 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is [1,2,0].\n\nPlayer 1 won k = 3 games in a row, so the winner is player 1.\n\nConstraints:\n\n- n == skills.length\n- 2 <= n <= 10^5\n- 1 <= k <= 10^9\n- 1 <= skills[i] <= 10^6\n- All integers in skills are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(skills = [5, 1, 9, 2, 8, 3, 7, 4, 6],k = 3) == 2\n assert candidate(skills = [1000000, 999999, 999998, 999997],k = 4) == 0\n assert candidate(skills = [2, 5, 4],k = 3) == 1\n assert candidate(skills = [1, 3, 2, 5, 4],k = 1) == 1\n assert candidate(skills = [10, 20, 30, 40, 50],k = 5) == 4\n assert candidate(skills = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(skills = [1000000, 1, 2, 3, 4],k = 4) == 0\n assert candidate(skills = [5, 10, 15, 20, 25, 30],k = 2) == 5\n assert candidate(skills = [50, 40, 30, 20, 10],k = 4) == 0\n assert candidate(skills = [4, 2, 6, 3, 9],k = 2) == 2\n assert candidate(skills = [5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(skills = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 9\n assert candidate(skills = [1, 3, 5, 7, 9],k = 1) == 1\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == 9\n assert candidate(skills = [3, 1, 2, 5, 4, 6, 7],k = 3) == 6\n assert candidate(skills = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 0\n assert candidate(skills = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],k = 3) == 4\n assert candidate(skills = [2, 1, 5, 4, 3, 6],k = 2) == 2\n assert candidate(skills = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9],k = 2) == 4\n assert candidate(skills = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10],k = 3) == 0\n assert candidate(skills = [500, 400, 300, 200, 100, 600, 700, 800, 900, 1000],k = 4) == 0\n assert candidate(skills = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 19) == 0\n assert candidate(skills = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],k = 10) == 8\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 14\n assert candidate(skills = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 9\n assert candidate(skills = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 100000) == 9\n assert candidate(skills = [1000, 100, 10, 1],k = 100) == 0\n assert candidate(skills = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10],k = 5) == 2\n assert candidate(skills = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 0\n assert candidate(skills = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 7) == 9\n assert candidate(skills = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(skills = [5, 3, 1, 4, 2],k = 3) == 0\n assert candidate(skills = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 0\n assert candidate(skills = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019],k = 10) == 19\n assert candidate(skills = [1, 10, 3, 4, 7, 5, 6, 9, 8, 2],k = 4) == 1\n assert candidate(skills = [8, 4, 6, 2, 7, 3, 9, 1, 5, 10],k = 9) == 9\n assert candidate(skills = [1, 10, 3, 8, 5, 6, 7, 2, 4, 9],k = 7) == 1\n assert candidate(skills = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],k = 4) == 8\n assert candidate(skills = [50, 51, 48, 49, 46, 47, 44, 45, 42, 43, 40, 41, 38, 39, 36, 37, 34, 35, 32, 33],k = 10) == 1\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 9\n assert candidate(skills = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 9\n assert candidate(skills = [3, 1, 2, 5, 4, 7, 6, 9, 8, 10],k = 3) == 9\n assert candidate(skills = [100000, 99999, 99998, 99997, 99996],k = 100000) == 0\n assert candidate(skills = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 0\n assert candidate(skills = [1000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1000000) == 0\n assert candidate(skills = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 0\n assert candidate(skills = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 5) == 9\n assert candidate(skills = [23, 45, 12, 56, 89, 43, 21, 67, 8, 90],k = 5) == 4\n assert candidate(skills = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],k = 2) == 9\n assert candidate(skills = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],k = 5) == 0\n assert candidate(skills = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 10) == 0\n assert candidate(skills = [10, 2, 15, 3, 20, 5, 25, 7, 30, 9],k = 5) == 8\n assert candidate(skills = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],k = 5) == 0\n assert candidate(skills = [1, 1000000],k = 1000000) == 1\n assert candidate(skills = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 100) == 0\n assert candidate(skills = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 9) == 0\n assert candidate(skills = [500000, 500001, 500002, 500003, 500004, 500005, 500006, 500007, 500008, 500009],k = 5) == 9\n assert candidate(skills = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 9\n assert candidate(skills = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],k = 5) == 4\n assert candidate(skills = [8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 0\n assert candidate(skills = [7, 6, 5, 4, 3, 2, 1],k = 6) == 0\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 14\n assert candidate(skills = [2, 3, 1, 5, 4],k = 4) == 3\n assert candidate(skills = [20, 30, 10, 40, 50, 60, 70, 80, 90, 100],k = 3) == 9\n assert candidate(skills = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],k = 8) == 0\n assert candidate(skills = [999999, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 9) == 0\n assert candidate(skills = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 10) == 0\n assert candidate(skills = [9, 1, 2, 8, 3, 7, 4, 6, 5, 10],k = 4) == 0\n assert candidate(skills = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 50, 40, 30, 20, 10],k = 5) == 9\n assert candidate(skills = [1, 3, 2, 4, 6, 5, 7, 9, 8, 10],k = 7) == 9\n assert candidate(skills = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 12) == 13\n assert candidate(skills = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32],k = 8) == 14\n assert candidate(skills = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10],k = 5) == 9\n assert candidate(skills = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15) == 19\n assert candidate(skills = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6],k = 8) == 5\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10) == 19\n assert candidate(skills = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 999990) == 0\n assert candidate(skills = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 14\n assert candidate(skills = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95],k = 6) == 1\n assert candidate(skills = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 9\n assert candidate(skills = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 19\n assert candidate(skills = [500, 250, 750, 125, 875, 375, 625, 687, 937, 187, 437, 787, 287, 1125, 1062],k = 7) == 13\n assert candidate(skills = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 0\n assert candidate(skills = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5],k = 5) == 0\n assert candidate(skills = [1000000, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 1) == 0\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1) == 1\n assert candidate(skills = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6],k = 6) == 5\n assert candidate(skills = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 20) == 19\n assert candidate(skills = [3, 1, 2, 5, 4, 8, 7, 10, 9, 6],k = 3) == 7\n assert candidate(skills = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 10) == 9\n assert candidate(skills = [5, 3, 8, 1, 9, 2, 7, 4, 6, 10],k = 7) == 9\n assert candidate(skills = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91],k = 90) == 1\n assert candidate(skills = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991],k = 6) == 0\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1) == 1\n assert candidate(skills = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1],k = 9) == 8\n assert candidate(skills = [32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4],k = 7) == 0\n assert candidate(skills = [9, 3, 1, 7, 5, 2, 8, 6, 4, 10],k = 5) == 0\n assert candidate(skills = [3, 1, 2, 5, 4, 6],k = 3) == 5\n assert candidate(skills = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 4) == 1\n assert candidate(skills = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],k = 6) == 13\n assert candidate(skills = [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 = 25) == 29\n assert candidate(skills = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 9) == 0\n assert candidate(skills = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 1) == 0\n assert candidate(skills = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 19) == 19\n assert candidate(skills = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 9\n assert candidate(skills = [4, 1, 3, 2, 5, 7, 6, 8, 10, 9],k = 4) == 8\n assert candidate(skills = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],k = 9) == 9\n assert candidate(skills = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],k = 8) == 1\n assert candidate(skills = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250],k = 8) == 9\n assert candidate(skills = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 0\n assert candidate(skills = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],k = 5) == 1\n assert candidate(skills = [7, 3, 9, 2, 8, 4, 6, 1, 5],k = 3) == 2\n assert candidate(skills = [200, 150, 300, 100, 250, 400, 50, 350, 500],k = 5) == 8\n assert candidate(skills = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 9\n assert candidate(skills = [100, 101, 99, 102, 98, 103, 97, 104, 96, 105],k = 5) == 9\n assert candidate(skills = [10, 2, 8, 4, 6, 1, 3, 5, 7, 9],k = 3) == 0\n assert candidate(skills = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 9\n assert candidate(skills = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 0\n assert candidate(skills = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29],k = 15) == 9\n assert candidate(skills = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],k = 10) == 9\n assert candidate(skills = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 14\n assert candidate(skills = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 3) == 1\n", "comparison": "exact"}, "public_tests": ["[4,2,6,3,9]\n2", "[2,5,4]\n3"], "hints": ["Suppose that k ≥ n, there is exactly one player who can win k games in a row. Who is it?", "In case k < n, you can simulate the competition process described."], "metadata": {"canonical_parameter_names": ["skills", "k"], "leetcode_dataset_entry_point": "Solution().findWinningPlayer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:46+00:00", "tests_total": 128, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def find_winning_player(skills, k)", "container": null, "callable": "find_winning_player", "parameters": [{"name": "skills", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3176, "task_id": "find-the-maximum-length-of-a-good-subsequence-i", "difficulty": "Medium", "problem_description": "You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].\n\nReturn the maximum possible length of a good subsequence of nums.\n\nExample 1:\n\nInput: nums = [1,2,1,1,3], k = 2\nOutput: 4\nExplanation:\nThe maximum length subsequence is [1,2,1,1,3].\n\nExample 2:\n\nInput: nums = [1,2,3,4,5,1], k = 0\nOutput: 2\nExplanation:\nThe maximum length subsequence is [1,2,3,4,5,1].\n\nConstraints:\n\n- 1 <= nums.length <= 500\n- 1 <= nums[i] <= 10^9\n- 0 <= k <= min(nums.length, 25)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 2, 1],k = 1) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 0) == 1\n assert candidate(nums = [1, 2, 1, 1, 3],k = 2) == 4\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 2) == 9\n assert candidate(nums = [1, 2],k = 1) == 2\n assert candidate(nums = [1, 2, 1, 3, 1, 2, 1],k = 2) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 4\n assert candidate(nums = [1, 2, 2, 2, 1, 2],k = 1) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 1) == 3\n assert candidate(nums = [1, 3, 2, 3, 1, 4, 1, 2, 3, 4],k = 2) == 5\n assert candidate(nums = [5, 4, 3, 2, 1],k = 1) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 5\n assert candidate(nums = [5, 5, 5, 5, 5],k = 1) == 5\n assert candidate(nums = [1],k = 0) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3],k = 4) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 0) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 1],k = 0) == 2\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 6\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],k = 3) == 8\n assert candidate(nums = [10, 20, 30, 40, 50],k = 3) == 4\n assert candidate(nums = [1, 2, 2, 2, 1, 2, 1],k = 2) == 6\n assert candidate(nums = [5, 5, 5, 5, 5],k = 0) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 0) == 5\n assert candidate(nums = [10, 20, 30, 20, 10, 5, 5, 5, 5],k = 3) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 5) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 3\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1],k = 3) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],k = 0) == 1\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 0) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 10) == 20\n assert candidate(nums = [1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3],k = 5) == 13\n assert candidate(nums = [1, 2, 1, 3, 2, 3, 1, 4, 1, 2, 3, 4, 1, 2, 3, 1, 4, 1, 2, 3, 4],k = 5) == 12\n assert candidate(nums = [5, 1, 3, 5, 7, 5, 3, 1, 5],k = 4) == 6\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 2) == 9\n assert candidate(nums = [1, 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 = 15) == 24\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 3) == 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, 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 = 10) == 28\n assert candidate(nums = [100, 200, 100, 300, 100, 400, 100, 500, 100, 600, 100, 700, 100, 800, 100, 900, 100, 1000, 100, 1100, 100, 1200, 100, 1300, 100],k = 15) == 20\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],k = 12) == 16\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 = 15) == 16\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],k = 2) == 15\n assert candidate(nums = [100, 200, 100, 300, 200, 400, 300, 500, 400, 600, 500, 700, 600, 800, 700],k = 7) == 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],k = 5) == 8\n assert candidate(nums = [100, 200, 300, 200, 100, 300, 200, 100, 300, 200, 100],k = 6) == 8\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],k = 7) == 16\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 5) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500],k = 5) == 7\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],k = 20) == 24\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 0) == 2\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],k = 1) == 20\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],k = 7) == 21\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],k = 20) == 21\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 3) == 7\n assert candidate(nums = [1000000000, 999999999, 1000000000, 999999999, 1000000000, 999999999],k = 2) == 4\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],k = 0) == 88\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 = 5) == 7\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],k = 20) == 32\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 4) == 7\n assert candidate(nums = [100, 200, 100, 300, 100, 200, 300, 400, 500, 100, 200],k = 4) == 7\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 5) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2],k = 3) == 5\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 = 9) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],k = 3) == 15\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3],k = 5) == 12\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, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10],k = 10) == 40\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],k = 5) == 7\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 0) == 10\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],k = 10) == 11\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],k = 10) == 12\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],k = 5) == 9\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 = 0) == 20\n assert candidate(nums = [10, 20, 30, 20, 10, 20, 30, 20, 10],k = 2) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 13\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],k = 7) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 0) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7],k = 2) == 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],k = 5) == 12\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8],k = 4) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 3) == 4\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3],k = 10) == 17\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 25\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],k = 10) == 16\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 3) == 8\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 20\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9],k = 10) == 14\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 15) == 19\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2],k = 8) == 17\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 9) == 20\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 = 5) == 13\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3],k = 10) == 33\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10],k = 3) == 8\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 = 3) == 8\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5],k = 4) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 3) == 10\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1],k = 15) == 20\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 20) == 61\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == 6\n", "comparison": "exact"}, "public_tests": ["[1,2,1,1,3]\n2", "[1,2,3,4,5,1]\n0"], "hints": ["The absolute values in nums don’t really matter. So we can remap the set of values to the range [0, n - 1].", "Let dp[i][j] be the length of the longest subsequence till index j with at most i positions such that seq[i] != seq[i + 1].", "For each value x from left to right, update dp[i][x] = max(dp[i][x] + 1, dp[i - 1][y] + 1), where y != x."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:48+00:00", "tests_total": 109, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(nums, k)", "container": null, "callable": "maximum_length", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3177, "task_id": "find-the-maximum-length-of-a-good-subsequence-ii", "difficulty": "Hard", "problem_description": "You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].\n\nReturn the maximum possible length of a good subsequence of nums.\n\nExample 1:\n\nInput: nums = [1,2,1,1,3], k = 2\nOutput: 4\nExplanation:\nThe maximum length subsequence is [1,2,1,1,3].\n\nExample 2:\n\nInput: nums = [1,2,3,4,5,1], k = 0\nOutput: 2\nExplanation:\nThe maximum length subsequence is [1,2,3,4,5,1].\n\nConstraints:\n\n- 1 <= nums.length <= 5 * 10^3\n- 1 <= nums[i] <= 10^9\n- 0 <= k <= min(50, nums.length)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 2, 1],k = 1) == 3\n assert candidate(nums = [1, 2, 1, 1, 3],k = 2) == 4\n assert candidate(nums = [1, 3, 5, 3, 1, 3, 5, 3, 1],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3) == 8\n assert candidate(nums = [10, 20, 20, 10, 10, 20, 10, 20, 10],k = 1) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1],k = 4) == 6\n assert candidate(nums = [5, 5, 5, 5, 5],k = 1) == 5\n assert candidate(nums = [1],k = 0) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],k = 3) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 0) == 10\n assert candidate(nums = [10, 20, 10, 30, 10, 20, 30],k = 1) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 1],k = 0) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 6\n assert candidate(nums = [1, 2, 2, 2, 1, 2, 1],k = 1) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1],k = 2) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 0) == 2\n assert candidate(nums = [1, 1, 1, 1, 1],k = 0) == 5\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 0) == 5\n assert candidate(nums = [10, 20, 30, 20, 10, 10, 20, 30],k = 2) == 5\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1],k = 2) == 5\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 1],k = 2) == 5\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 3) == 8\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],k = 15) == 28\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 = 0) == 1\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, 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],k = 20) == 50\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 12) == 13\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, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2],k = 25) == 41\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5],k = 3) == 11\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2],k = 6) == 13\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 18\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 9) == 20\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 4) == 15\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],k = 10) == 31\n assert candidate(nums = [1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3],k = 5) == 16\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 = 0) == 15\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],k = 10) == 16\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, 1, 2, 3, 4, 5],k = 5) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 10\n assert candidate(nums = [9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8],k = 8) == 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, 1, 2, 1, 2, 1, 2, 1, 2],k = 10) == 19\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],k = 4) == 15\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],k = 15) == 32\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 15) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 15) == 17\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 20) == 28\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4],k = 5) == 13\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 7) == 12\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 = 9) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 6\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1],k = 5) == 20\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 15) == 23\n assert candidate(nums = [4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 4, 3, 2, 1],k = 4) == 8\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, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2],k = 10) == 28\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],k = 5) == 21\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],k = 5) == 16\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],k = 10) == 21\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2],k = 10) == 17\n assert candidate(nums = [1, 1, 2, 3, 2, 3, 1, 2, 3, 4, 3, 4, 1, 2, 3, 4, 5, 4, 5, 6],k = 9) == 15\n assert candidate(nums = [5, 6, 7, 8, 7, 8, 7, 6, 5],k = 3) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 7) == 16\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 7\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5],k = 5) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 20\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 1) == 9\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20],k = 10) == 24\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 5) == 12\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30],k = 7) == 12\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 = 8) == 14\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 10) == 17\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 5) == 9\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],k = 4) == 9\n assert candidate(nums = [10, 20, 30, 20, 10, 20, 30, 20, 10, 20, 30, 20, 10],k = 6) == 10\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110],k = 10) == 14\n assert candidate(nums = [5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1],k = 4) == 12\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 = 9) == 14\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 2, 2, 1, 1, 1],k = 5) == 13\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50],k = 0) == 2\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],k = 7) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 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, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 15) == 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 = 10) == 11\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 6, 7, 8, 8, 9],k = 3) == 11\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 = 10) == 11\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 11\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1],k = 3) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 3) == 7\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2],k = 5) == 13\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, 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],k = 0) == 142\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\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],k = 10) == 14\n assert candidate(nums = [2, 2, 3, 3, 2, 2, 3, 3, 2, 2],k = 1) == 6\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],k = 5) == 8\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],k = 10) == 11\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 = 0) == 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],k = 0) == 2\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],k = 10) == 21\n", "comparison": "exact"}, "public_tests": ["[1,2,1,1,3]\n2", "[1,2,3,4,5,1]\n0"], "hints": ["The absolute values in nums don’t really matter. So we can remap the set of values to the range [0, n - 1].", "Let dp[i][j] be the length of the longest subsequence till index j with at most i positions such that seq[i] != seq[i + 1].", "For each value x from left to right, update dp[i][x] = max(dp[i][x] + 1, dp[i - 1][y] + 1), where y != x."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:51+00:00", "tests_total": 107, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(nums, k)", "container": null, "callable": "maximum_length", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3178, "task_id": "find-the-child-who-has-the-ball-after-k-seconds", "difficulty": "Easy", "problem_description": "You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from left to right.\n\nInitially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to them. Once the ball reaches either end of the line, i.e. child 0 or child n - 1, the direction of passing is reversed.\n\nReturn the number of the child who receives the ball after k seconds.\n\nExample 1:\n\nInput: n = 3, k = 5\nOutput: 1\nExplanation:\n\nTime elapsed | Children\n0 | [0, 1, 2]\n1 | [0, 1, 2]\n2 | [0, 1, 2]\n3 | [0, 1, 2]\n4 | [0, 1, 2]\n5 | [0, 1, 2]\n\nExample 2:\n\nInput: n = 5, k = 6\nOutput: 2\nExplanation:\n\nTime elapsed | Children\n0 | [0, 1, 2, 3, 4]\n1 | [0, 1, 2, 3, 4]\n2 | [0, 1, 2, 3, 4]\n3 | [0, 1, 2, 3, 4]\n4 | [0, 1, 2, 3, 4]\n5 | [0, 1, 2, 3, 4]\n6 | [0, 1, 2, 3, 4]\n\nExample 3:\n\nInput: n = 4, k = 2\nOutput: 2\nExplanation:\n\nTime elapsed | Children\n0 | [0, 1, 2, 3]\n1 | [0, 1, 2, 3]\n2 | [0, 1, 2, 3]\n\nConstraints:\n\n- 2 <= n <= 50\n- 1 <= k <= 50\n\nNote: This question is the same as 2582: Pass the Pillow.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 50,k = 50) == 48\n assert candidate(n = 3,k = 5) == 1\n assert candidate(n = 2,k = 1) == 1\n assert candidate(n = 40,k = 20) == 20\n assert candidate(n = 5,k = 6) == 2\n assert candidate(n = 10,k = 15) == 3\n assert candidate(n = 2,k = 2) == 0\n assert candidate(n = 2,k = 50) == 0\n assert candidate(n = 4,k = 2) == 2\n assert candidate(n = 25,k = 50) == 2\n assert candidate(n = 18,k = 36) == 2\n assert candidate(n = 15,k = 47) == 9\n assert candidate(n = 35,k = 49) == 19\n assert candidate(n = 49,k = 49) == 47\n assert candidate(n = 49,k = 48) == 48\n assert candidate(n = 50,k = 49) == 49\n assert candidate(n = 20,k = 49) == 11\n assert candidate(n = 50,k = 25) == 25\n", "comparison": "exact"}, "public_tests": ["3\n5", "5\n6", "4\n2"], "hints": ["The ball will go back to child 0 after 2 * (n - 1) seconds and everything is the same as time 0.", "So the answer for k is the same as the answer for k % (2 * (n - 1))."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().numberOfChild", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:53+00:00", "tests_total": 82, "tests_dropped": 64, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_child(n, k)", "container": null, "callable": "number_of_child", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3179, "task_id": "find-the-n-th-value-after-k-seconds", "difficulty": "Medium", "problem_description": "You are given two integers n and k.\n\nInitially, you start with an array a of n integers where a[i] = 1 for all 0 <= i <= n - 1. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, a[0] remains the same, a[1] becomes a[0] + a[1], a[2] becomes a[0] + a[1] + a[2], and so on.\n\nReturn the value of a[n - 1] after k seconds.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 4, k = 5\nOutput: 56\nExplanation:\n\nSecond | State After\n0 | [1,1,1,1]\n1 | [1,2,3,4]\n2 | [1,3,6,10]\n3 | [1,4,10,20]\n4 | [1,5,15,35]\n5 | [1,6,21,56]\n\nExample 2:\n\nInput: n = 5, k = 3\nOutput: 35\nExplanation:\n\nSecond | State After\n0 | [1,1,1,1,1]\n1 | [1,2,3,4,5]\n2 | [1,3,6,10,15]\n3 | [1,4,10,20,35]\n\nConstraints:\n\n- 1 <= n, k <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 7,k = 4) == 210\n assert candidate(n = 2,k = 4) == 5\n assert candidate(n = 2,k = 5) == 6\n assert candidate(n = 8,k = 4) == 330\n assert candidate(n = 2,k = 1) == 2\n assert candidate(n = 1,k = 1) == 1\n assert candidate(n = 3,k = 2) == 6\n assert candidate(n = 6,k = 2) == 21\n assert candidate(n = 4,k = 5) == 56\n assert candidate(n = 3,k = 7) == 36\n assert candidate(n = 10,k = 10) == 92378\n assert candidate(n = 5,k = 3) == 35\n assert candidate(n = 3,k = 100) == 5151\n assert candidate(n = 9,k = 4) == 495\n assert candidate(n = 200,k = 200) == 793946740\n assert candidate(n = 6,k = 8) == 1287\n assert candidate(n = 200,k = 100) == 824578740\n assert candidate(n = 15,k = 15) == 77558760\n assert candidate(n = 9,k = 18) == 1562275\n assert candidate(n = 7,k = 3) == 84\n assert candidate(n = 15,k = 3) == 680\n assert candidate(n = 15,k = 1) == 15\n assert candidate(n = 30,k = 20) == 527148437\n assert candidate(n = 20,k = 20) == 923263934\n assert candidate(n = 10,k = 1) == 10\n assert candidate(n = 2,k = 1000) == 1001\n assert candidate(n = 7,k = 15) == 54264\n assert candidate(n = 8,k = 1) == 8\n assert candidate(n = 100,k = 50) == 475860182\n assert candidate(n = 250,k = 500) == 540818587\n assert candidate(n = 999,k = 999) == 482800871\n assert candidate(n = 30,k = 25) == 462115415\n assert candidate(n = 10,k = 5) == 2002\n assert candidate(n = 5,k = 10) == 1001\n assert candidate(n = 8,k = 3) == 120\n assert candidate(n = 15,k = 10) == 1961256\n assert candidate(n = 6,k = 15) == 15504\n assert candidate(n = 30,k = 30) == 368504682\n assert candidate(n = 75,k = 75) == 133231804\n assert candidate(n = 8,k = 7) == 3432\n assert candidate(n = 7,k = 7) == 1716\n assert candidate(n = 500,k = 500) == 579917918\n assert candidate(n = 20,k = 5) == 42504\n assert candidate(n = 5,k = 5) == 126\n assert candidate(n = 20,k = 15) == 855967513\n assert candidate(n = 4,k = 20) == 1771\n assert candidate(n = 7,k = 5) == 462\n assert candidate(n = 50,k = 50) == 769496025\n assert candidate(n = 1000,k = 1000) == 36237869\n assert candidate(n = 6,k = 3) == 56\n assert candidate(n = 15,k = 7) == 116280\n assert candidate(n = 250,k = 50) == 46410598\n assert candidate(n = 6,k = 6) == 462\n assert candidate(n = 1000,k = 1) == 1000\n assert candidate(n = 8,k = 8) == 6435\n assert candidate(n = 300,k = 250) == 244556185\n assert candidate(n = 11,k = 25) == 183579396\n assert candidate(n = 7,k = 20) == 230230\n assert candidate(n = 12,k = 12) == 1352078\n assert candidate(n = 50,k = 40) == 280099481\n assert candidate(n = 1,k = 1000) == 1\n assert candidate(n = 100,k = 100) == 703668401\n assert candidate(n = 500,k = 250) == 81637167\n", "comparison": "exact"}, "public_tests": ["4\n5", "5\n3"], "hints": ["Calculate the prefix sum array of nums, k times."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().valueAfterKSeconds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:55+00:00", "tests_total": 63, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "simulation", "combinatorics", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def value_after_k_seconds(n, k)", "container": null, "callable": "value_after_k_seconds", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3180, "task_id": "maximum-total-reward-using-operations-i", "difficulty": "Medium", "problem_description": "You are given an integer array rewardValues of length n, representing the values of rewards.\n\nInitially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times:\n\n- Choose an unmarked index i from the range [0, n - 1].\n- If rewardValues[i] is greater than your current total reward x, then add rewardValues[i] to x (i.e., x = x + rewardValues[i]), and mark the index i.\n\nReturn an integer denoting the maximum total reward you can collect by performing the operations optimally.\n\nExample 1:\n\nInput: rewardValues = [1,1,3,3]\nOutput: 4\nExplanation:\nDuring the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.\n\nExample 2:\n\nInput: rewardValues = [1,6,4,3,2]\nOutput: 11\nExplanation:\nMark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.\n\nConstraints:\n\n- 1 <= rewardValues.length <= 2000\n- 1 <= rewardValues[i] <= 2000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rewardValues = [1, 1, 3, 3]) == 4\n assert candidate(rewardValues = [2000, 1]) == 2001\n assert candidate(rewardValues = [1, 6, 4, 3, 2]) == 11\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 37\n assert candidate(rewardValues = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 38\n assert candidate(rewardValues = [1]) == 1\n assert candidate(rewardValues = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991]) == 3999\n assert candidate(rewardValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(rewardValues = [10, 20, 30, 40, 50]) == 90\n assert candidate(rewardValues = [1, 2000]) == 2001\n assert candidate(rewardValues = [1500, 1000, 500, 100, 50, 25, 10, 5, 1]) == 2691\n assert candidate(rewardValues = [5, 5, 5, 5, 5]) == 5\n assert candidate(rewardValues = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 11\n assert candidate(rewardValues = [1000, 1000, 1000]) == 1000\n assert candidate(rewardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 19\n assert candidate(rewardValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(rewardValues = [5, 4, 3, 2, 1]) == 9\n assert candidate(rewardValues = [2000, 1999, 1998, 1997, 1996]) == 3999\n assert candidate(rewardValues = [1000, 1000, 1000, 1000, 1000]) == 1000\n assert candidate(rewardValues = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1900\n assert candidate(rewardValues = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(rewardValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(rewardValues = [2000, 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]) == 2059\n assert candidate(rewardValues = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990]) == 3999\n assert candidate(rewardValues = [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]) == 99\n assert candidate(rewardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 39\n assert candidate(rewardValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(rewardValues = [1800, 1700, 1600, 1500, 1400, 1300, 1200, 1100, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 50, 25]) == 3575\n assert candidate(rewardValues = [1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]) == 1500\n assert candidate(rewardValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 290\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 57\n assert candidate(rewardValues = [500, 200, 800, 100, 600, 300, 700, 400, 900, 500, 1100, 600, 1200, 700, 1300, 800, 1400, 900, 1500, 1000]) == 2900\n assert candidate(rewardValues = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 1000\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 77\n assert candidate(rewardValues = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100]) == 190\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128]) == 255\n assert candidate(rewardValues = [3, 6, 2, 8, 5, 10, 4, 12, 7, 14, 1, 16, 9, 18, 11, 20, 13, 22, 15, 24]) == 47\n assert candidate(rewardValues = [2000, 1, 2000, 2, 2000, 3, 2000, 4, 2000, 5]) == 2009\n assert candidate(rewardValues = [100, 50, 25, 125, 75, 150]) == 275\n assert candidate(rewardValues = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 141\n assert candidate(rewardValues = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 19\n assert candidate(rewardValues = [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, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 200]) == 399\n assert candidate(rewardValues = [1, 3, 2, 6, 5, 4, 9, 8, 7, 12, 11, 10]) == 23\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 77\n assert candidate(rewardValues = [500, 1000, 1500, 2000, 1000, 500, 1500, 1000]) == 3500\n assert candidate(rewardValues = [200, 150, 100, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 381\n assert candidate(rewardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 19\n assert candidate(rewardValues = [100, 200, 300, 250, 150, 400, 350, 500, 450, 550]) == 1050\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 57\n assert candidate(rewardValues = [1500, 500, 1500, 500, 1500, 500, 1500, 500, 1500, 500, 1500, 500, 1500, 500, 1500, 500, 1500, 500, 1500, 500]) == 2000\n assert candidate(rewardValues = [1500, 1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 2999\n assert candidate(rewardValues = [2000, 1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3994\n assert candidate(rewardValues = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 30\n assert candidate(rewardValues = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 58\n assert candidate(rewardValues = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500]) == 900\n assert candidate(rewardValues = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 19\n assert candidate(rewardValues = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1994\n assert candidate(rewardValues = [2000, 1, 2000, 2, 2000, 3, 2000, 4, 2000, 5, 2000, 6, 2000, 7, 2000, 8, 2000, 9, 2000, 10]) == 2019\n assert candidate(rewardValues = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 90\n assert candidate(rewardValues = [1000, 1500, 500, 2000, 1000]) == 3500\n assert candidate(rewardValues = [71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == 141\n assert candidate(rewardValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(rewardValues = [1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985]) == 3997\n assert candidate(rewardValues = [1500, 500, 250, 750, 1000, 1250, 1750, 2000, 2000, 2000]) == 3750\n assert candidate(rewardValues = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40]) == 79\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(rewardValues = [1, 10, 100, 1000, 100, 10, 1, 1000, 100, 10]) == 1111\n assert candidate(rewardValues = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981]) == 3999\n assert candidate(rewardValues = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 25, 26, 27, 28, 29, 30]) == 59\n assert candidate(rewardValues = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 17\n assert candidate(rewardValues = [1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980]) == 3997\n assert candidate(rewardValues = [100, 50, 200, 150, 250, 300, 100]) == 550\n assert candidate(rewardValues = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 419\n assert candidate(rewardValues = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1, 2, 3, 4, 6, 7, 8, 9, 11, 12]) == 99\n assert candidate(rewardValues = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 49\n assert candidate(rewardValues = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 11\n assert candidate(rewardValues = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2047\n assert candidate(rewardValues = [2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991]) == 3999\n assert candidate(rewardValues = [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]) == 59\n assert candidate(rewardValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 195\n assert candidate(rewardValues = [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]) == 98\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2047\n assert candidate(rewardValues = [1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980]) == 3997\n assert candidate(rewardValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 390\n assert candidate(rewardValues = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 93\n assert candidate(rewardValues = [500, 1000, 1500, 2000, 1000, 500, 1500, 2000, 1000, 500]) == 3500\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992]) == 3999\n assert candidate(rewardValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(rewardValues = [2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000]) == 2000\n assert candidate(rewardValues = [2, 1, 5, 6, 3, 4, 7]) == 13\n assert candidate(rewardValues = [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]) == 49\n assert candidate(rewardValues = [200, 100, 300, 150, 400, 250, 500, 350, 600, 450, 700, 550, 800, 650, 900, 750, 1000, 850, 1100, 950]) == 2150\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(rewardValues = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(rewardValues = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 19\n assert candidate(rewardValues = [2000, 1500, 1000, 500, 250, 125, 62, 31, 15, 7, 3, 1]) == 3994\n assert candidate(rewardValues = [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]) == 79\n assert candidate(rewardValues = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 41\n assert candidate(rewardValues = [1, 10, 100, 1000, 10, 100, 1000, 10, 100, 1000]) == 1111\n assert candidate(rewardValues = [2000, 1, 1999, 2, 1998, 3, 1997, 4, 1996, 5, 1995, 6, 1994, 7, 1993, 8, 1992, 9, 1991, 10]) == 3999\n assert candidate(rewardValues = [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]) == 193\n assert candidate(rewardValues = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 1900\n", "comparison": "exact"}, "public_tests": ["[1,1,3,3]", "[1,6,4,3,2]"], "hints": ["Sort the rewards array first.", "If we decide to apply some rewards, it's always optimal to apply them in order.", "Let dp[i][j] (true/false) be the state after the first i rewards, indicating whether we can get exactly j points.", "The transition is given by: dp[i][j] = dp[i - 1][j - rewardValues[i]] if j - rewardValues[i] < rewardValues[i]."], "metadata": {"canonical_parameter_names": ["rewardValues"], "leetcode_dataset_entry_point": "Solution().maxTotalReward", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:15:57+00:00", "tests_total": 104, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_total_reward(reward_values)", "container": null, "callable": "max_total_reward", "parameters": [{"name": "reward_values", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3181, "task_id": "maximum-total-reward-using-operations-ii", "difficulty": "Hard", "problem_description": "You are given an integer array rewardValues of length n, representing the values of rewards.\n\nInitially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times:\n\n- Choose an unmarked index i from the range [0, n - 1].\n- If rewardValues[i] is greater than your current total reward x, then add rewardValues[i] to x (i.e., x = x + rewardValues[i]), and mark the index i.\n\nReturn an integer denoting the maximum total reward you can collect by performing the operations optimally.\n\nExample 1:\n\nInput: rewardValues = [1,1,3,3]\nOutput: 4\nExplanation:\nDuring the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.\n\nExample 2:\n\nInput: rewardValues = [1,6,4,3,2]\nOutput: 11\nExplanation:\nMark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.\n\nConstraints:\n\n- 1 <= rewardValues.length <= 5 * 10^4\n- 1 <= rewardValues[i] <= 5 * 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rewardValues = [1, 2, 3, 4, 5]) == 9\n assert candidate(rewardValues = [1, 1, 3, 3]) == 4\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000]) == 90000\n assert candidate(rewardValues = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2]) == 3\n assert candidate(rewardValues = [1, 6, 4, 3, 2]) == 11\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 37\n assert candidate(rewardValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(rewardValues = [10000, 10000, 10000, 10000, 10000]) == 10000\n assert candidate(rewardValues = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 17\n assert candidate(rewardValues = [10, 9, 8, 7, 6]) == 19\n assert candidate(rewardValues = [1]) == 1\n assert candidate(rewardValues = [10, 20, 30, 40, 50]) == 90\n assert candidate(rewardValues = [50000, 25000, 12500, 6250, 3125]) == 96875\n assert candidate(rewardValues = [5, 5, 5, 5, 5]) == 5\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000]) == 90000\n assert candidate(rewardValues = [1, 5, 1, 5, 1]) == 6\n assert candidate(rewardValues = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(rewardValues = [50000, 50000, 50000, 50000, 50000]) == 50000\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(rewardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 19\n assert candidate(rewardValues = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 19000\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(rewardValues = [1, 1, 1, 1, 1]) == 1\n assert candidate(rewardValues = [5, 4, 3, 2, 1]) == 9\n assert candidate(rewardValues = [42, 35, 18, 27, 5, 14, 8, 23, 9, 22]) == 83\n assert candidate(rewardValues = [3, 6, 2, 8, 5, 10, 4, 12, 7, 14, 1, 9, 11, 13, 15]) == 29\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000, 9000, 8000, 7000, 6000, 5000]) == 99000\n assert candidate(rewardValues = [50000, 10000, 20000, 30000, 40000, 5000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == 99000\n assert candidate(rewardValues = [50000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 50019\n assert candidate(rewardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 29\n assert candidate(rewardValues = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 3900\n assert candidate(rewardValues = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 99\n assert candidate(rewardValues = [4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13]) == 31\n assert candidate(rewardValues = [5, 3, 8, 6, 2, 7, 4, 1, 9, 10]) == 19\n assert candidate(rewardValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 190\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000, 5000, 1000, 500, 100, 50]) == 96650\n assert candidate(rewardValues = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 10000\n assert candidate(rewardValues = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 39\n assert candidate(rewardValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(rewardValues = [2, 3, 7, 8, 10, 14, 15, 18, 20, 22, 25, 28, 30]) == 59\n assert candidate(rewardValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(rewardValues = [25000, 24000, 23000, 22000, 21000, 20000, 19000, 18000, 17000, 16000, 15000, 14000, 13000, 12000, 11000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 49000\n assert candidate(rewardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 39\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128]) == 255\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 2, 1]) == 99995\n assert candidate(rewardValues = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120]) == 239\n assert candidate(rewardValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 290\n assert candidate(rewardValues = [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, 2, 2, 2, 2, 2]) == 2\n assert candidate(rewardValues = [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]) == 49\n assert candidate(rewardValues = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 10000\n assert candidate(rewardValues = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 17\n assert candidate(rewardValues = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 19999\n assert candidate(rewardValues = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 17\n assert candidate(rewardValues = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]) == 287\n assert candidate(rewardValues = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 6\n assert candidate(rewardValues = [1, 3, 2, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 41\n assert candidate(rewardValues = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 11\n assert candidate(rewardValues = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 65535\n assert candidate(rewardValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 77\n assert candidate(rewardValues = [1, 10000, 2, 9999, 3, 9998, 4, 9997, 5, 9996, 6, 9995, 7, 9994, 8, 9993]) == 19999\n assert candidate(rewardValues = [50000, 45000, 40000, 35000, 30000, 25000, 20000, 15000, 10000, 5000]) == 95000\n assert candidate(rewardValues = [10000, 20000, 15000, 5000, 2500, 7500, 30000, 1000, 500, 1500]) == 59500\n assert candidate(rewardValues = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(rewardValues = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 19999\n assert candidate(rewardValues = [20000, 18000, 16000, 14000, 12000, 10000, 8000, 6000, 4000, 2000, 1000, 500, 250, 125, 62, 31]) == 39968\n assert candidate(rewardValues = [50000, 40000, 30000, 20000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 99990\n assert candidate(rewardValues = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 50000\n assert candidate(rewardValues = [25000, 20000, 15000, 10000, 5000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45019\n assert candidate(rewardValues = [100, 200, 300, 400, 500, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 990\n assert candidate(rewardValues = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 65534\n assert candidate(rewardValues = [10, 15, 20, 25, 30, 35, 40, 45, 50]) == 95\n assert candidate(rewardValues = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 11\n assert candidate(rewardValues = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 17\n assert candidate(rewardValues = [50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 99\n assert candidate(rewardValues = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 141\n assert candidate(rewardValues = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 10000\n assert candidate(rewardValues = [10000, 20000, 30000, 40000, 50000, 50000, 40000, 30000, 20000, 10000]) == 90000\n assert candidate(rewardValues = [10000, 20000, 30000, 40000, 50000, 1, 2, 3, 4, 5]) == 90009\n", "comparison": "exact"}, "public_tests": ["[1,1,3,3]", "[1,6,4,3,2]"], "hints": ["Sort the rewards array first.", "If we decide to apply some rewards, it's always optimal to apply them in order.", "The transition is given by: dp[i][j] = dp[i - 1][j - rewardValues[i]] if j - rewardValues[i] < rewardValues[i].", "Note that the dp array is a boolean array. We just need 1 bit per element, so we can use a bitset or something similar. We just need a \"stream\" of bits and apply bitwise operations to optimize the computations by a constant factor."], "metadata": {"canonical_parameter_names": ["rewardValues"], "leetcode_dataset_entry_point": "Solution().maxTotalReward", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:00+00:00", "tests_total": 87, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def max_total_reward(reward_values)", "container": null, "callable": "max_total_reward", "parameters": [{"name": "reward_values", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3184, "task_id": "count-pairs-that-form-a-complete-day-i", "difficulty": "Easy", "problem_description": "Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day.\n\nA complete day is defined as a time duration that is an exact multiple of 24 hours.\n\nFor example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.\n\nExample 1:\n\nInput: hours = [12,12,30,24,24]\nOutput: 2\nExplanation:\nThe pairs of indices that form a complete day are (0, 1) and (3, 4).\n\nExample 2:\n\nInput: hours = [72,48,24,3]\nOutput: 3\nExplanation:\nThe pairs of indices that form a complete day are (0, 1), (0, 2), and (1, 2).\n\nConstraints:\n\n- 1 <= hours.length <= 100\n- 1 <= hours[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(hours = [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(hours = [24, 48, 72, 96, 120]) == 10\n assert candidate(hours = [1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(hours = [10, 14, 10, 14, 48]) == 4\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]) == 11\n assert candidate(hours = [24, 48, 72, 96]) == 6\n assert candidate(hours = [1, 2, 3, 4, 5]) == 0\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(hours = [12, 12, 30, 24, 24]) == 2\n assert candidate(hours = [1, 2, 3, 23]) == 1\n assert candidate(hours = [24, 24, 24, 24]) == 6\n assert candidate(hours = [24, 24, 24, 24, 24]) == 10\n assert candidate(hours = [72, 48, 24, 3]) == 3\n assert candidate(hours = [23, 1, 23, 1]) == 4\n assert candidate(hours = [23, 1, 22, 2, 21, 3, 20, 4, 19, 5]) == 5\n assert candidate(hours = [23, 1, 23, 1, 23]) == 6\n assert candidate(hours = [12, 36, 60, 84]) == 6\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96]) == 12\n assert candidate(hours = [5, 5, 5, 5, 5]) == 0\n assert candidate(hours = [10, 14, 10, 14]) == 4\n assert candidate(hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 6\n assert candidate(hours = [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24]) == 435\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168]) == 21\n assert candidate(hours = [23, 1, 47, 25, 71, 49, 95, 73, 119, 97, 143, 121]) == 36\n assert candidate(hours = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 12\n assert candidate(hours = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240]) == 145\n assert candidate(hours = [20, 44, 68, 92, 116, 140, 164, 188, 212, 236]) == 0\n assert candidate(hours = [23, 23, 23, 23, 23, 1, 1, 1, 1, 1, 47, 47, 47, 47, 47, 71, 71, 71, 71, 71]) == 75\n assert candidate(hours = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23]) == 200\n assert candidate(hours = [5, 19, 10, 34, 15, 29, 20, 24, 25, 19]) == 4\n assert candidate(hours = [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]) == 12\n assert candidate(hours = [23, 1, 23, 1, 23, 1, 23, 1, 23, 1]) == 25\n assert candidate(hours = [23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 287]) == 0\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96]) == 12\n assert candidate(hours = [10, 34, 58, 82, 106, 130, 154, 178, 202, 226]) == 0\n assert candidate(hours = [24, 48, 72, 96, 120, 144]) == 15\n assert candidate(hours = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 20\n assert candidate(hours = [120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576]) == 190\n assert candidate(hours = [2, 22, 46, 68, 94, 120, 146, 172, 198, 224, 250, 276, 302, 328, 354, 380, 406, 432]) == 14\n assert candidate(hours = [23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 287, 311, 335, 359, 383, 407, 431, 455, 479]) == 0\n assert candidate(hours = [5, 19, 33, 47, 61, 75, 89, 103, 117, 131, 145, 159, 173, 187, 201, 215, 229, 243, 257, 271]) == 16\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216]) == 36\n assert candidate(hours = [5, 19, 33, 47, 61, 75, 89, 103, 117, 131, 145, 159, 173, 187, 201, 215, 229]) == 12\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480]) == 190\n assert candidate(hours = [12, 36, 48, 60, 84, 108, 132, 156, 180]) == 28\n assert candidate(hours = [11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]) == 16\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240]) == 45\n assert candidate(hours = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(hours = [2, 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]) == 17\n assert candidate(hours = [23, 47, 71, 95, 119, 143, 167, 191, 215, 239]) == 0\n assert candidate(hours = [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24]) == 190\n assert candidate(hours = [1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 53, 59, 61, 65, 67, 71, 73, 77, 79, 83, 85, 89, 91, 95, 97, 101, 103, 107, 109, 113, 115, 119, 121, 125, 127, 131, 133, 137, 139, 143, 145, 149, 151, 155, 157, 161, 163, 167, 169, 173, 175, 179, 181, 185, 187, 191, 193, 197, 199]) == 264\n assert candidate(hours = [10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86]) == 34\n assert candidate(hours = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12]) == 435\n assert candidate(hours = [48, 96, 144, 192, 240, 288, 336, 384, 432, 480, 528, 576, 624, 672, 720, 768, 816, 864, 912, 960]) == 190\n assert candidate(hours = [11, 13, 35, 47, 59, 71, 83, 95, 107, 119]) == 5\n assert candidate(hours = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12]) == 66\n assert candidate(hours = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(hours = [144, 168, 192, 216, 240, 264, 288, 312, 336, 360]) == 45\n assert candidate(hours = [23, 1, 47, 24, 25, 48, 49, 23, 1, 24, 24, 24]) == 22\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 11\n assert candidate(hours = [13, 11, 25, 19, 49, 23, 35, 17, 55, 15]) == 5\n assert candidate(hours = [5, 19, 29, 43, 53, 67, 77, 91, 101, 115]) == 25\n assert candidate(hours = [15, 9, 27, 3, 39, 51, 63, 75, 87, 99, 111, 123, 135, 147, 159, 171, 183, 195, 207, 219]) == 9\n assert candidate(hours = [23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 1]) == 29\n assert candidate(hours = [15, 9, 27, 39, 51, 63, 75, 87, 99, 111, 123, 135]) == 6\n assert candidate(hours = [123456789, 987654321, 123456789, 987654321, 123456789, 987654321]) == 0\n assert candidate(hours = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 56\n assert candidate(hours = [5, 19, 9, 15, 9, 15, 9, 15, 29, 11, 13, 21, 23, 47, 71, 95, 119, 143, 167, 191]) == 12\n assert candidate(hours = [3, 21, 39, 57, 75, 93, 111, 129, 147, 165, 183, 201, 219, 237, 255, 273, 291, 309, 327, 345]) == 50\n assert candidate(hours = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12]) == 45\n assert candidate(hours = [24, 24, 24, 24, 24, 24, 24, 24, 24, 24]) == 45\n assert candidate(hours = [3, 21, 6, 18, 9, 15, 12, 12, 12, 12]) == 9\n assert candidate(hours = [3, 9, 21, 39, 57, 75, 93, 111, 129, 147, 165, 183, 201, 219, 237, 255, 273, 291]) == 40\n assert candidate(hours = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160]) == 64\n assert candidate(hours = [100, 144, 48, 24, 72, 96, 120]) == 15\n assert candidate(hours = [60, 108, 156, 204, 252, 300, 348, 396, 444, 492, 540, 588, 636, 684, 732, 780]) == 120\n assert candidate(hours = [6, 18, 30, 42, 54, 66, 78, 90, 102, 114, 126, 138]) == 36\n assert candidate(hours = [48, 24, 72, 96, 120, 24, 48]) == 21\n assert candidate(hours = [59, 119, 179, 239, 299, 359, 419, 479, 539, 599, 659, 719, 779, 839, 899, 959]) == 0\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360]) == 210\n assert candidate(hours = [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, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120]) == 145\n assert candidate(hours = [240, 480, 720, 960, 1200, 1440, 1680, 1920, 2160, 2400, 2640, 2880, 3120, 3360, 3600, 3840, 4080, 4320, 4560, 4800, 5040, 5280, 5520, 5760, 6000, 6240, 6480, 6720, 6960, 7200]) == 435\n", "comparison": "exact"}, "public_tests": ["[12,12,30,24,24]", "[72,48,24,3]"], "hints": ["Brute force all pairs (i, j) and check if they form a valid complete day. It is considered a complete day if (hours[i] + hours[j]) % 24 == 0."], "metadata": {"canonical_parameter_names": ["hours"], "leetcode_dataset_entry_point": "Solution().countCompleteDayPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:04+00:00", "tests_total": 83, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def count_complete_day_pairs(hours)", "container": null, "callable": "count_complete_day_pairs", "parameters": [{"name": "hours", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3185, "task_id": "count-pairs-that-form-a-complete-day-ii", "difficulty": "Medium", "problem_description": "Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day.\n\nA complete day is defined as a time duration that is an exact multiple of 24 hours.\n\nFor example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.\n\nExample 1:\n\nInput: hours = [12,12,30,24,24]\nOutput: 2\nExplanation: The pairs of indices that form a complete day are (0, 1) and (3, 4).\n\nExample 2:\n\nInput: hours = [72,48,24,3]\nOutput: 3\nExplanation: The pairs of indices that form a complete day are (0, 1), (0, 2), and (1, 2).\n\nConstraints:\n\n- 1 <= hours.length <= 5 * 10^5\n- 1 <= hours[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(hours = [5, 19, 15, 1, 23, 7, 17, 11, 3, 21, 9, 13, 20, 18, 4, 16, 8, 12, 6, 22, 14, 2, 10, 10, 10]) == 13\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576, 600]) == 300\n assert candidate(hours = [24, 48, 72, 96, 120]) == 10\n assert candidate(hours = [1, 2, 3, 23, 47, 71]) == 3\n assert candidate(hours = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(hours = [12, 12, 30, 24, 24]) == 2\n assert candidate(hours = [1, 23, 2, 22, 3, 21, 4, 20, 5, 19]) == 5\n assert candidate(hours = [24]) == 0\n assert candidate(hours = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 4\n assert candidate(hours = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(hours = [72, 48, 24, 3]) == 3\n assert candidate(hours = [5, 19, 29, 39, 49, 59, 69, 79, 89, 99, 109, 119, 129, 139, 149, 159, 169, 179, 189, 199]) == 16\n assert candidate(hours = [10, 14, 16, 8, 12]) == 2\n assert candidate(hours = [1, 2, 3, 4, 5, 23, 22, 21, 20, 19]) == 5\n assert candidate(hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]) == 11\n assert candidate(hours = [24, 48, 72, 96]) == 6\n assert candidate(hours = [48, 24, 96, 72, 144, 120, 192, 168, 240, 216, 336, 312, 384, 360, 456, 432, 528, 504, 600, 576, 768, 744, 840, 816, 912, 888]) == 325\n assert candidate(hours = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500, 520, 540, 560, 580, 600]) == 70\n assert candidate(hours = [1, 5, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 107, 113, 119, 125, 131, 137, 143, 149, 155, 161, 167, 173, 179, 185]) == 7\n assert candidate(hours = [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, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 1110, 1120, 1130, 1140, 1150, 1160, 1170, 1180, 1190, 1200]) == 590\n assert candidate(hours = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240]) == 145\n assert candidate(hours = [240, 480, 720, 960, 1200, 1440, 1680, 1920, 2160, 2400, 2640, 2880, 3120, 3360, 3600, 3840, 4080, 4320, 4560, 4800, 5040, 5280, 5520, 5760, 6000, 6240, 6480, 6720, 6960, 7200, 7440, 7680, 7920, 8160, 8400, 8640, 8880, 9120, 9360, 9600, 9840, 10080, 10320, 10560, 10800, 11040, 11280, 11520, 11760, 12000, 12240, 12480, 12720, 12960, 13200, 13440, 13680, 13920, 14160, 14400, 14640, 14880, 15120, 15360, 15600, 15840, 16080, 16320, 16560, 16800, 17040, 17280, 17520, 17760, 18000, 18240, 18480, 18720, 18960, 19200, 19440, 19680, 19920, 20160]) == 3486\n assert candidate(hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 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, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127]) == 117\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600, 612, 624, 636, 648, 660, 672, 684, 696, 708, 720, 732, 744, 756, 768, 780, 792, 804, 816, 828, 840, 852, 864, 876, 888, 900, 912, 924, 936, 948, 960, 972, 984, 996, 1008, 1020, 1032, 1044, 1056, 1068, 1080, 1092, 1104, 1116, 1128, 1140, 1152, 1164, 1176, 1188, 1200, 1212, 1224, 1236, 1248, 1260, 1272, 1284, 1296, 1308, 1320, 1332, 1344, 1356, 1368, 1380, 1392, 1404, 1416, 1428, 1440]) == 3540\n assert candidate(hours = [1, 2, 3, 23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 287, 311, 335, 359, 383, 407, 431, 455, 479, 503, 527, 551, 575, 599, 623, 647, 671, 695, 719, 743, 767, 791, 815, 839, 863, 887, 911, 935, 959, 983, 1007, 1031, 1055, 1079, 1103, 1127, 1151, 1175, 1199, 1223, 1247, 1271, 1295, 1319, 1343, 1367, 1391, 1415, 1439, 1463, 1487, 1511, 1535, 1559, 1583, 1607, 1631, 1655, 1679, 1703, 1727, 1751, 1775, 1799, 1823, 1847, 1871, 1895, 1919, 1943, 1967, 1991, 2015, 2039, 2063, 2087, 2111, 2135, 2159, 2183, 2207, 2231, 2255, 2279, 2303, 2327, 2351, 2375, 2399]) == 100\n assert candidate(hours = [23, 49, 73, 97, 121, 145, 169, 193, 217, 241, 265, 289, 313, 337, 361, 385, 409, 433, 457, 481, 505, 529, 553, 577, 601]) == 24\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576, 600, 624, 648, 672, 696, 720, 744, 768, 792, 816, 840, 864, 888, 912, 936, 960, 984, 1008, 1032, 1056, 1080]) == 990\n assert candidate(hours = [123456789, 123456789, 246913578, 246913578, 370370370, 370370370, 493826958, 493826958, 617283546, 617283546, 740740134, 740740134]) == 24\n assert candidate(hours = [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, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300]) == 70\n assert candidate(hours = [22, 46, 70, 94, 118, 142, 166, 190, 214, 238, 262, 286, 310, 334, 358, 382, 406, 430, 454, 478, 502, 526, 550, 574, 598]) == 0\n assert candidate(hours = [1, 23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 287, 311, 335, 359, 383, 407, 431, 455, 479, 503, 527, 551, 575, 599, 623, 647, 671, 695, 719, 743, 767, 791, 815, 839, 863, 887, 911, 935, 959, 983, 1007, 1031, 1055, 1079, 1103, 1127, 1151, 1175, 1199, 1223, 1247, 1271, 1295, 1319, 1343, 1367, 1391, 1415, 1439]) == 60\n assert candidate(hours = [12, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360]) == 225\n assert candidate(hours = [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]) == 36\n assert candidate(hours = [14, 28, 42, 56, 70, 84, 98, 112, 126, 140, 154, 168, 182, 196, 210, 224, 238, 252, 266, 280, 294, 308, 322, 336, 350, 364, 378, 392, 406, 420]) == 34\n assert candidate(hours = [5, 29, 19, 43, 67, 91, 115, 139, 163, 187, 211, 235, 259, 283, 307, 331, 355, 379, 403, 427, 451, 475, 499, 523, 547, 571, 595, 619, 643, 667, 691, 715, 739, 763, 787, 811, 835, 859, 883, 907, 931, 955, 979]) == 82\n assert candidate(hours = [24, 48, 24, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576, 600, 12, 60, 84, 108, 132, 156, 180, 204, 228, 252, 276, 300, 324, 348, 372, 396, 420, 444, 468, 492, 516, 540, 564, 588]) == 601\n assert candidate(hours = [3, 21, 39, 57, 75, 93, 111, 129, 147, 165, 183, 201, 219, 237, 255, 273, 291, 309, 327, 345, 363, 381, 399, 417, 435, 453, 471, 489, 507, 525, 543, 561, 579, 597, 615, 633, 651, 669, 687, 705, 723, 741, 759, 777, 795, 813, 831, 849, 867, 885, 903, 921, 939, 957, 975, 993]) == 392\n assert candidate(hours = [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, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000]) == 408\n assert candidate(hours = [24, 48, 24, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576, 600, 12, 60, 84, 108, 132, 156, 180, 204, 228, 252, 276, 300, 324, 348, 372, 396, 420, 444, 468, 492, 516, 540, 564, 588, 123, 246, 369, 492, 615, 738, 861, 984, 1107, 1230, 1353, 1476, 1599, 1722, 1845, 1968, 2091, 2214, 2337, 2460]) == 747\n assert candidate(hours = [12, 36, 60, 84, 108, 132, 156, 180, 204, 228, 252, 276, 300, 324, 348, 372, 396, 420, 444, 468, 492, 516, 540, 564, 588, 612, 636, 660, 684, 708, 732, 756, 780, 804, 828, 852, 876, 900, 924, 948, 972, 996]) == 861\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300]) == 144\n assert candidate(hours = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220, 231, 242, 253, 264, 275, 286, 297, 308, 319, 330, 341, 352, 363, 374, 385, 396, 407, 418, 429, 440, 451, 462, 473, 484, 495, 506, 517, 528, 539, 550, 561, 572, 583, 594, 605, 616, 627, 638, 649, 660, 671, 682, 693, 704, 715, 726, 737, 748, 759, 770, 781, 792, 803, 814, 825, 836, 847, 858, 869, 880, 891, 902, 913, 924, 935, 946, 957, 968, 979, 990, 1001, 1012, 1023, 1034, 1045, 1056, 1067, 1078, 1089, 1100, 1111, 1122, 1133, 1144, 1155, 1166, 1177, 1188, 1199]) == 241\n assert candidate(hours = [12, 48, 84, 120, 156, 192, 228, 264, 300, 336, 372, 408, 444, 480, 516, 552, 588, 624, 660, 696, 732, 768, 804, 840, 876, 912, 948, 984, 1020, 1056, 1092, 1128, 1164, 1200, 1236, 1272, 1308, 1344, 1380, 1416, 1452, 1488, 1524, 1560, 1596, 1632, 1668, 1704, 1740, 1776, 1812, 1848, 1884, 1920, 1956, 1992, 2028, 2064, 2100, 2136, 2172, 2208, 2244, 2280, 2316, 2352, 2388, 2424, 2460, 2496, 2532, 2568, 2604, 2640, 2676, 2712, 2748, 2784, 2820, 2856, 2892, 2928, 2964, 3000]) == 1722\n assert candidate(hours = [5, 19, 29, 35, 43, 59, 65, 77, 83, 95, 101, 113, 119, 131, 137, 149, 155, 167, 173, 185, 191, 203, 209, 221, 227]) == 14\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600]) == 600\n assert candidate(hours = [1, 2, 3, 22, 23, 46, 47, 70, 71, 94, 95, 118, 119, 142, 143, 166, 167, 190, 191, 214, 215, 238, 239, 262, 263, 286, 287, 310, 311, 334, 335, 358, 359, 382, 383, 406, 407, 430, 431, 454, 455, 478, 479, 502, 503, 526, 527, 550, 551, 574, 575, 598, 599, 622, 623, 646, 647, 670, 671, 694, 695, 718, 719, 742, 743, 766, 767, 790, 791, 814, 815, 838, 839, 862, 863, 886, 887, 910, 911, 934, 935, 958, 959, 982, 983, 1006, 1007, 1030, 1031, 1054, 1055, 1078, 1079, 1102, 1103, 1126, 1127, 1150, 1151, 1174, 1175, 1198, 1199]) == 100\n assert candidate(hours = [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, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239]) == 600\n assert candidate(hours = [48, 96, 144, 192, 240, 288, 336, 384, 432, 480, 528, 576, 624, 672, 720, 768, 816, 864, 912, 960, 1008, 1056, 1104, 1152, 1200, 1248, 1296, 1344, 1392, 1440]) == 435\n assert candidate(hours = [1, 23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 287, 311, 335, 359, 383, 407, 431, 455, 479, 503, 527, 551, 575, 599, 623, 647, 671, 695, 719, 743, 767, 791, 815, 839, 863, 887, 911, 935, 959, 983, 1007, 1031, 1055, 1079, 1103, 1127, 1151, 1175, 1199, 1223, 1247, 1271, 1295, 1319, 1343, 1367, 1391, 1415, 1439, 1463, 1487, 1511, 1535, 1559, 1583, 1607, 1631, 1655, 1679, 1703, 1727, 1751, 1775, 1799, 1823, 1847, 1871, 1895, 1919, 1943, 1967, 1991, 2015]) == 84\n assert candidate(hours = [7, 17, 27, 37, 47, 57, 67, 77, 87, 97, 107, 117, 127, 137, 147, 157, 167, 177, 187, 197, 207, 217, 227, 237, 247, 257, 267, 277, 287, 297]) == 37\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 290, 292, 294, 296, 298, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600, 612, 624, 636, 648, 660, 672, 684, 696, 708, 720]) == 870\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576, 600, 624, 648, 672, 696, 720]) == 435\n assert candidate(hours = [23, 1, 22, 2, 21, 3, 20, 4, 19, 5, 18, 6, 17, 7, 16, 8, 15, 9, 14, 10, 13, 11]) == 11\n assert candidate(hours = [3, 21, 39, 57, 75, 93, 111, 129, 147, 165, 183, 201, 219, 237, 255, 273, 291, 309, 327, 345, 363, 381, 399, 417, 435]) == 78\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 299, 311, 323, 335, 347, 359]) == 132\n assert candidate(hours = [25, 19, 7, 23, 11, 17, 9, 15, 13, 1, 19, 21, 23, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 50\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600, 612, 624, 636, 648, 660, 672, 684, 696, 708, 720, 732, 744, 756, 768, 780, 792, 804, 816, 828, 840]) == 1190\n assert candidate(hours = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109]) == 40\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600, 612, 624, 636, 648, 660, 672, 684, 696, 708, 720, 732, 744, 756, 768, 780, 792, 804, 816, 828, 840, 852, 864, 876, 888, 900, 912, 924, 936, 948, 960, 972, 984, 996, 1008]) == 1722\n assert candidate(hours = [11, 13, 23, 35, 47, 59, 71, 83, 95, 107, 119, 131, 143, 155, 167, 179, 191, 203, 215, 227, 239, 251, 263, 275, 287, 299, 311, 323, 335, 347]) == 15\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 290, 292, 294, 296, 298, 300]) == 144\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 299]) == 132\n assert candidate(hours = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408, 432, 456, 480, 504, 528, 552, 576, 600, 624, 648, 672, 696, 720, 744, 768, 792, 816, 840, 864, 888, 912, 936, 960, 984, 1008, 1032, 1056, 1080, 1104, 1128, 1152, 1176, 1200, 1224, 1248, 1272, 1296, 1320, 1344, 1368, 1392, 1416, 1440]) == 1770\n assert candidate(hours = [1, 5, 11, 13, 19, 21, 25, 27, 31, 33, 37, 39, 43, 45, 49, 51, 55, 57, 61, 63, 67, 69, 73, 75, 79, 81, 85, 87, 91, 93, 97, 99, 103, 105, 109, 111, 115, 117, 121, 123, 127, 129, 133, 135, 139, 141, 145, 147, 151, 153, 157, 159, 163, 165, 169, 171, 175, 177, 181, 183, 187, 189, 193, 195, 199, 201, 205, 207, 211, 213, 217, 219, 223, 225, 229, 231, 235, 237, 241, 243, 247, 249, 253, 255, 259, 261, 265, 267, 271, 273, 277, 279, 283, 285, 289, 291, 295, 297, 301, 303, 307, 309, 313, 315, 319, 321, 325, 327, 331, 333, 337, 339, 343, 345, 349, 351, 355, 357, 361, 363, 367, 369, 373, 375, 379, 381, 385, 387, 391, 393, 397, 399, 403, 405, 409, 411, 415, 417, 421, 423, 427, 429, 433, 435, 439, 441, 445, 447, 451, 453, 457, 459, 463, 465, 469, 471, 475, 477, 481, 483, 487, 489, 493, 495, 499, 501, 505, 507, 511, 513, 517, 519, 523, 525, 529, 531, 535, 537, 541, 543, 547, 549, 553, 555, 559, 561, 565, 567, 571, 573, 577, 579, 583, 585, 589, 591, 595, 597, 601, 603, 607, 609, 613, 615, 619, 621, 625, 627, 631, 633, 637, 639, 643, 645, 649, 651, 655, 657, 661, 663, 667, 669, 673, 675, 679, 681, 685, 687, 691, 693, 697, 699, 703, 705, 709, 711, 715, 717, 721, 723, 727, 729, 733, 735, 739, 741, 745, 747, 751, 753, 757, 759, 763, 765, 769, 771, 775, 777, 781, 783, 787, 789, 793, 795, 799, 801, 805, 807, 811, 813, 817, 819, 823, 825, 829, 831, 835, 837, 841, 843, 847, 849, 853, 855, 859, 861, 865, 867, 871, 873, 877, 879, 883, 885, 889, 891, 895, 897, 901, 903, 907, 909, 913, 915, 919, 921, 925, 927, 931, 933, 937, 939, 943, 945, 949, 951, 955, 957, 961, 963, 967, 969, 973, 975, 979, 981, 985, 987, 991, 993, 997, 999]) == 3445\n assert candidate(hours = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000]) == 200\n assert candidate(hours = [12, 36, 60, 84, 108, 132, 156, 180, 204, 228, 252, 276, 300, 324, 348, 372, 396, 420, 444, 468, 492, 516, 540, 564, 588, 612, 636, 660, 684, 708]) == 435\n assert candidate(hours = [13, 37, 61, 85, 109, 133, 157, 181, 205, 229, 253, 277, 301, 325, 349, 373, 397, 421, 445, 469, 493, 517, 541, 565, 589, 613, 637, 661, 685, 709, 733, 757, 781, 805, 829, 853, 877, 901, 925, 949, 973, 997, 1021, 1045, 1069, 1093, 1117, 1141, 1165, 1189, 1213, 1237, 1261, 1285, 1309, 1333, 1357, 1381, 1405, 1429, 1453, 1477, 1501, 1525, 1549, 1573, 1597, 1621, 1645, 1669, 1693, 1717, 1741, 1765, 1789, 1813, 1837, 1861, 1885, 1909, 1933, 1957, 1981, 2005]) == 0\n assert candidate(hours = [23, 47, 71, 95, 119, 143, 167, 191, 215, 239, 263, 287, 311, 335, 359, 383, 407, 431, 455, 479, 503, 527, 551, 575, 599, 623, 647, 671, 695, 719, 743, 767, 791, 815, 839, 863, 887, 911, 935, 959, 983, 1007, 1031, 1055, 1079, 1103, 1127, 1151, 1175, 1199]) == 0\n assert candidate(hours = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600, 612, 624, 636, 648, 660, 672, 684, 696, 708, 720, 732, 744, 756, 768, 780, 792, 804, 816, 828, 840, 852, 864, 876, 888, 900, 912, 924, 936, 948, 960, 972, 984, 996]) == 1681\n assert candidate(hours = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 102, 105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240]) == 390\n assert candidate(hours = [5, 19, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 107, 113, 119, 125, 131, 137, 143, 149, 155, 161, 167, 173, 179, 185, 191, 197, 203, 209, 215, 221, 227, 233, 239]) == 10\n", "comparison": "exact"}, "public_tests": ["[12,12,30,24,24]", "[72,48,24,3]"], "hints": ["A pair (i, j) forms a valid complete day if (hours[i] + hours[j]) % 24 == 0.", "Using an array or a map, for each index j moving from left to right, increase the answer by the count of (24 - hours[j]) % 24, and then increase the count of hours[j]."], "metadata": {"canonical_parameter_names": ["hours"], "leetcode_dataset_entry_point": "Solution().countCompleteDayPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:07+00:00", "tests_total": 73, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def count_complete_day_pairs(hours)", "container": null, "callable": "count_complete_day_pairs", "parameters": [{"name": "hours", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3186, "task_id": "maximum-total-damage-with-spell-casting", "difficulty": "Medium", "problem_description": "A magician has various spells.\n\nYou are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value.\n\nIt is a known fact that if a magician decides to cast a spell with a damage of power[i], they cannot cast any spell with a damage of power[i] - 2, power[i] - 1, power[i] + 1, or power[i] + 2.\n\nEach spell can be cast only once.\n\nReturn the maximum possible total damage that a magician can cast.\n\nExample 1:\n\nInput: power = [1,1,3,4]\nOutput: 6\nExplanation:\nThe maximum possible damage of 6 is produced by casting spells 0, 1, 3 with damage 1, 1, 4.\n\nExample 2:\n\nInput: power = [7,1,6,6]\nOutput: 13\nExplanation:\nThe maximum possible damage of 13 is produced by casting spells 1, 2, 3 with damage 1, 6, 6.\n\nConstraints:\n\n- 1 <= power.length <= 10^5\n- 1 <= power[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(power = [5, 5, 5, 5, 5]) == 25\n assert candidate(power = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91]) == 506\n assert candidate(power = [5, 3, 8, 9, 2]) == 16\n assert candidate(power = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59]) == 320\n assert candidate(power = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 55\n assert candidate(power = [3, 8, 3, 10, 1, 3, 3, 9, 5]) == 22\n assert candidate(power = [10, 20, 30, 40, 50]) == 150\n assert candidate(power = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 60\n assert candidate(power = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5000000000\n assert candidate(power = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 60\n assert candidate(power = [10, 20, 30, 40, 50]) == 150\n assert candidate(power = [1000000000, 1, 2, 3, 1000000000]) == 2000000003\n assert candidate(power = [1, 1, 3, 4]) == 6\n assert candidate(power = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(power = [7, 1, 6, 6]) == 13\n assert candidate(power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 22\n assert candidate(power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 22\n assert candidate(power = [5, 5, 5, 5]) == 20\n assert candidate(power = [1, 2, 3, 6, 7, 8, 11, 12, 13]) == 24\n assert candidate(power = [1000000000, 1000000000, 1000000000, 1000000000]) == 4000000000\n assert candidate(power = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 55\n assert candidate(power = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(power = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82]) == 415\n assert candidate(power = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 2650\n assert candidate(power = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 100\n assert candidate(power = [5, 6, 8, 10, 11, 13, 15, 17, 18, 20]) == 66\n assert candidate(power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 77\n assert candidate(power = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 1111111111\n assert candidate(power = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74]) == 950\n assert candidate(power = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84]) == 1218\n assert candidate(power = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 18\n assert candidate(power = [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]) == 117\n assert candidate(power = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 6, 7, 8, 9, 1, 2, 3, 4, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22]) == 612\n assert candidate(power = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 210\n assert candidate(power = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1045\n assert candidate(power = [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]) == 3250\n assert candidate(power = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 21000\n assert candidate(power = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 44\n assert candidate(power = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96]) == 970\n assert candidate(power = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 1050\n assert candidate(power = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 120\n assert candidate(power = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 157\n assert candidate(power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 44\n assert candidate(power = [1000000000, 999999998, 999999996, 999999994, 999999992, 999999990, 999999988, 999999986, 999999984, 999999982, 999999980, 999999978, 999999976, 999999974, 999999972, 999999970, 999999968, 999999966, 999999964, 999999962]) == 9999999820\n assert candidate(power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 44\n assert candidate(power = [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]) == 66\n assert candidate(power = [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]) == 255\n assert candidate(power = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18]) == 42\n assert candidate(power = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120]) == 777\n assert candidate(power = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == 190\n assert candidate(power = [2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97]) == 990\n assert candidate(power = [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10, 11, 11, 12, 12]) == 66\n assert candidate(power = [1000000000, 999999998, 999999996, 999999994, 999999992, 999999990, 999999988, 999999986, 999999984, 999999982]) == 4999999960\n assert candidate(power = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 5500\n assert candidate(power = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 3999999982\n assert candidate(power = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 210\n assert candidate(power = [1000000000, 999999998, 999999996, 999999994, 999999992]) == 2999999988\n assert candidate(power = [1000000000, 999999998, 999999996, 999999994, 999999992, 999999990, 999999988]) == 3999999976\n assert candidate(power = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 150\n assert candidate(power = [1, 2, 5, 9, 10, 11, 14, 18, 20, 21, 23, 27, 28, 30, 31, 34, 38, 40, 41, 43]) == 251\n assert candidate(power = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97]) == 1225\n assert candidate(power = [1, 1000000000, 2, 999999998, 3, 999999996, 4, 999999994, 5, 999999992, 6, 999999990, 7, 999999988, 8, 999999986, 9, 999999984, 10, 999999982]) == 4999999982\n assert candidate(power = [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]) == 480\n assert candidate(power = [1, 3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33, 36, 38, 41, 43, 46, 48, 51, 53, 56, 58, 61, 63]) == 429\n assert candidate(power = [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]) == 325\n assert candidate(power = [10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45, 45, 50, 50, 55, 55]) == 650\n assert candidate(power = [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]) == 90\n assert candidate(power = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 1, 3, 5, 7, 9]) == 220\n assert candidate(power = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 105\n assert candidate(power = [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]) == 2325\n assert candidate(power = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15]) == 69\n assert candidate(power = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44]) == 345\n assert candidate(power = [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]) == 4650\n assert candidate(power = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993]) == 3000000006\n assert candidate(power = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 551\n assert candidate(power = [1, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == 73\n assert candidate(power = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 147\n assert candidate(power = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90]) == 1395\n assert candidate(power = [1000000000, 1000000000, 1000000000, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992]) == 4999999991\n assert candidate(power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 239\n assert candidate(power = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180]) == 1890\n assert candidate(power = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100]) == 1717\n assert candidate(power = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209]) == 1236\n assert candidate(power = [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]) == 465\n assert candidate(power = [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]) == 90\n assert candidate(power = [10, 12, 10, 14, 12, 16, 14, 18, 16, 20, 18, 22, 20, 24, 22, 26, 24, 28, 26, 30]) == 210\n assert candidate(power = [5, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 221\n assert candidate(power = [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]) == 90\n assert candidate(power = [9, 2, 8, 3, 7, 4, 6, 5, 1, 10, 19, 11, 18, 12, 17, 13, 16, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 165\n assert candidate(power = [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]) == 165\n assert candidate(power = [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]) == 30\n assert candidate(power = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 2100\n assert candidate(power = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46]) == 235\n assert candidate(power = [3, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]) == 325\n assert candidate(power = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 100\n assert candidate(power = [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]) == 1625\n assert candidate(power = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 28\n assert candidate(power = [1, 3, 6, 8, 10, 13, 15, 18, 20, 23, 25, 28, 30, 33, 35, 38, 40, 43, 45, 48, 50, 53, 55, 58, 60, 63, 65, 68, 70, 73, 75]) == 604\n assert candidate(power = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 12000\n", "comparison": "exact"}, "public_tests": ["[1,1,3,4]", "[7,1,6,6]"], "hints": ["If we ever decide to use some spell with power x, then we will use all spells with power x.", "Think of dynamic programming.", "dp[i][j] represents the maximum damage considering up to the i-th unique spell and j represents the number of spells skipped (up to 3 as per constraints)."], "metadata": {"canonical_parameter_names": ["power"], "leetcode_dataset_entry_point": "Solution().maximumTotalDamage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:10+00:00", "tests_total": 99, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "binary-search", "dynamic-programming", "sorting", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_total_damage(power)", "container": null, "callable": "maximum_total_damage", "parameters": [{"name": "power", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3187, "task_id": "peaks-in-array", "difficulty": "Hard", "problem_description": "A peak in an array arr is an element that is greater than its previous and next element in arr.\n\nYou are given an integer array nums and a 2D integer array queries.\n\nYou have to process queries of two types:\n\n- queries[i] = [1, l_i, r_i], determine the count of peak elements in the subarray nums[l_i..r_i].\n- queries[i] = [2, index_i, val_i], change nums[index_i] to val_i.\n\nReturn an array answer containing the results of the queries of the first type in order.\n\nNotes:\n\n- The first and the last element of an array or a subarray cannot be a peak.\n\nExample 1:\n\nInput: nums = [3,1,4,2,5], queries = [[2,3,4],[1,0,4]]\nOutput: [0]\nExplanation:\nFirst query: We change nums[3] to 4 and nums becomes [3,1,4,4,5].\nSecond query: The number of peaks in the [3,1,4,4,5] is 0.\n\nExample 2:\n\nInput: nums = [4,1,4,2,1,5], queries = [[2,2,4],[1,0,2],[1,0,4]]\nOutput: [0,1]\nExplanation:\nFirst query: nums[2] should become 4, but it is already set to 4.\nSecond query: The number of peaks in the [4,1,4] is 0.\nThird query: The second 4 is a peak in the [4,1,4,2,1].\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- 1 <= queries.length <= 10^5\n- queries[i][0] == 1 or queries[i][0] == 2\n- For all i that:\n - queries[i][0] == 1: 0 <= queries[i][1] <= queries[i][2] <= nums.length - 1\n - queries[i][0] == 2: 0 <= queries[i][1] <= nums.length - 1, 1 <= queries[i][2] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 4, 2, 5],queries = [[2, 3, 4], [1, 0, 4]]) == [0]\n assert candidate(nums = [4, 1, 4, 2, 1, 5],queries = [[2, 2, 4], [1, 0, 2], [1, 0, 4]]) == [0, 1]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5],queries = [[1, 1, 8], [2, 3, 1], [1, 1, 8], [2, 5, 7], [1, 0, 4]]) == [3, 2, 1]\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5],queries = [[1, 1, 7], [2, 2, 6], [2, 4, 3], [1, 0, 8]]) == [3, 3]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],queries = [[2, 0, 10], [1, 1, 11], [2, 1, 9], [1, 1, 11], [2, 2, 8], [1, 1, 11], [2, 3, 7], [1, 1, 11], [2, 4, 6], [1, 1, 11]]) == [3, 2, 2, 2, 2]\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],queries = [[2, 10, 8], [1, 0, 28], [2, 15, 13], [1, 8, 20]]) == [1, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[1, 1, 13], [2, 7, 1], [1, 1, 13]]) == [0, 1]\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5],queries = [[1, 1, 10], [2, 4, 3], [1, 3, 11], [2, 8, 4], [1, 0, 12]]) == [4, 4, 5]\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5],queries = [[1, 0, 8], [2, 1, 3], [1, 0, 8], [2, 3, 5], [1, 0, 8], [2, 5, 7], [1, 0, 8]]) == [3, 3, 1, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 0, 9], [2, 1, 10], [1, 0, 8], [2, 3, 9], [1, 2, 7]]) == [0, 0, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[1, 0, 14], [2, 6, 10], [1, 0, 14], [2, 4, 8], [1, 0, 14], [2, 7, 11], [1, 0, 14]]) == [0, 1, 2, 2]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 0, 14], [2, 7, 18], [1, 0, 14], [2, 10, 12], [1, 0, 14]]) == [0, 1, 2]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10],queries = [[1, 0, 8], [2, 1, 25], [1, 0, 8], [2, 3, 30], [1, 0, 8]]) == [4, 4, 4]\n assert candidate(nums = [100, 50, 100, 50, 100, 50, 100, 50, 100],queries = [[1, 1, 7], [2, 2, 150], [1, 0, 8], [2, 4, 200], [1, 0, 8]]) == [3, 3, 3]\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 1, 9], [2, 2, 8], [1, 1, 9], [2, 4, 6], [1, 1, 9], [2, 6, 4], [1, 1, 9]]) == [0, 1, 2, 2]\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],queries = [[2, 2, 5], [1, 0, 9], [2, 6, 8], [1, 1, 8]]) == [4, 3]\n assert candidate(nums = [7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12, 7, 13, 8, 14, 9, 15],queries = [[1, 0, 16], [2, 1, 5], [1, 3, 15], [2, 9, 12], [1, 0, 16]]) == [7, 6, 5]\n assert candidate(nums = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5],queries = [[1, 1, 8], [2, 4, 3], [1, 1, 8], [2, 6, 2], [1, 1, 8]]) == [3, 3, 3]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9],queries = [[2, 2, 4], [1, 0, 16], [2, 8, 7], [1, 6, 12]]) == [6, 1]\n assert candidate(nums = [5, 1, 4, 1, 5, 1, 4, 1, 5, 1, 4, 1, 5, 1, 4],queries = [[1, 1, 13], [2, 2, 3], [1, 1, 13], [2, 4, 5], [1, 1, 13], [2, 6, 7], [1, 1, 13], [2, 8, 9], [1, 1, 13], [2, 10, 11], [1, 1, 13], [2, 12, 13], [1, 1, 13]]) == [6, 6, 6, 6, 6, 6, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 1, 8], [2, 5, 10], [1, 1, 8]]) == [0, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[2, 5, 6], [1, 0, 18], [2, 10, 9], [1, 4, 14]]) == [1, 1]\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5],queries = [[1, 0, 10], [2, 4, 10], [1, 0, 10], [2, 2, 1], [1, 0, 10]]) == [5, 4, 4]\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 2, 18], [2, 9, 12], [1, 2, 18], [2, 12, 8], [1, 2, 18]]) == [1, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 0, 18], [2, 4, 5], [1, 0, 18], [2, 10, 11], [1, 0, 18]]) == [1, 1, 1]\n assert candidate(nums = [5, 3, 4, 2, 3, 1, 2, 3, 1, 2],queries = [[1, 0, 9], [2, 2, 5], [1, 1, 8], [2, 5, 3], [1, 0, 8]]) == [3, 3, 2]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],queries = [[1, 2, 8], [2, 3, 3], [1, 0, 9], [2, 5, 8], [1, 1, 7]]) == [3, 3, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[1, 0, 14], [2, 7, 20], [1, 0, 14], [2, 10, 15], [1, 0, 14]]) == [0, 1, 2]\n assert candidate(nums = [10, 20, 15, 25, 20, 30, 25, 35, 30, 40],queries = [[1, 1, 9], [2, 4, 25], [1, 0, 8], [2, 7, 34], [1, 2, 7]]) == [3, 3, 1]\n assert candidate(nums = [7, 3, 8, 2, 9, 1, 10, 4, 11, 5, 12, 6, 13],queries = [[1, 1, 12], [2, 5, 1], [1, 1, 12], [2, 9, 8], [1, 0, 13]]) == [5, 5, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[2, 5, 3], [1, 0, 9], [2, 4, 5], [1, 2, 7]]) == [1, 1]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],queries = [[1, 0, 12], [2, 5, 4], [1, 3, 9], [2, 6, 3], [1, 0, 12]]) == [3, 1, 3]\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9],queries = [[1, 0, 18], [2, 1, 2], [1, 0, 18], [2, 3, 4], [1, 0, 18], [2, 5, 6], [1, 0, 18], [2, 7, 8], [1, 0, 18], [2, 9, 10], [1, 0, 18], [2, 11, 12], [1, 0, 18]]) == [9, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [100, 90, 110, 80, 120, 70, 130, 60, 140, 50],queries = [[1, 2, 8], [2, 3, 100], [1, 0, 9], [2, 6, 90], [1, 1, 7]]) == [2, 4, 3]\n assert candidate(nums = [8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15, 8, 16, 9, 17, 10, 18],queries = [[1, 0, 20], [2, 2, 7], [1, 1, 19], [2, 6, 12], [1, 0, 20]]) == [9, 9, 9]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12],queries = [[1, 1, 12], [2, 3, 6], [1, 2, 11], [2, 7, 10], [1, 0, 13]]) == [5, 4, 6]\n assert candidate(nums = [5, 3, 4, 2, 5, 4, 3, 6, 4, 7, 5, 8, 6, 9, 7],queries = [[1, 1, 14], [2, 3, 3], [1, 1, 14], [2, 10, 10], [1, 1, 14]]) == [6, 6, 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],queries = [[1, 1, 17], [2, 9, 2], [1, 1, 17], [2, 12, 3], [1, 1, 17]]) == [0, 1, 2]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],queries = [[1, 2, 10], [2, 5, 5], [1, 2, 10], [2, 7, 7], [1, 2, 10]]) == [2, 3, 4]\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],queries = [[1, 1, 8], [2, 3, 3], [1, 0, 9], [2, 5, 2], [1, 1, 7]]) == [3, 3, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[2, 3, 6], [1, 1, 8], [2, 5, 7], [1, 3, 7]]) == [0, 1]\n assert candidate(nums = [5, 1, 4, 3, 2, 6, 7, 8, 9, 10, 5, 1],queries = [[2, 4, 7], [1, 0, 10], [2, 8, 2], [1, 3, 9]]) == [3, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],queries = [[1, 0, 10], [2, 5, 5], [2, 6, 6], [1, 0, 10]]) == [0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 0, 9], [2, 4, 5], [1, 0, 9], [2, 2, 3], [1, 0, 9], [2, 6, 7], [1, 0, 9]]) == [0, 0, 0, 0]\n assert candidate(nums = [5, 10, 5, 10, 5, 10, 5, 10, 5],queries = [[1, 0, 8], [2, 1, 7], [1, 0, 8], [2, 3, 9], [1, 0, 8], [2, 5, 8], [1, 0, 8]]) == [4, 4, 4, 4]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1],queries = [[1, 0, 9], [2, 1, 4], [1, 0, 9], [2, 3, 5], [1, 0, 9], [2, 5, 7], [1, 0, 9]]) == [3, 3, 3, 4]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8],queries = [[1, 0, 14], [2, 1, 1], [1, 0, 14], [2, 3, 4], [1, 0, 14], [2, 5, 6], [1, 0, 14]]) == [7, 6, 6, 6]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [[1, 2, 12], [2, 5, 55], [1, 2, 12], [2, 9, 95], [1, 2, 12]]) == [0, 0, 0]\n assert candidate(nums = [10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35, 45],queries = [[1, 1, 10], [2, 5, 28], [1, 2, 9], [2, 8, 33], [1, 3, 11]]) == [4, 3, 3]\n assert candidate(nums = [5, 1, 4, 3, 2, 8, 7, 9, 6, 10],queries = [[1, 1, 9], [2, 4, 7], [2, 6, 5], [1, 1, 9]]) == [3, 3]\n assert candidate(nums = [9, 1, 9, 1, 9, 1, 9, 1, 9],queries = [[1, 0, 8], [2, 1, 2], [1, 0, 8], [2, 3, 4], [1, 0, 8], [2, 5, 6], [1, 0, 8], [2, 7, 8], [1, 0, 8]]) == [3, 3, 3, 3, 3]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 0, 8], [2, 4, 10], [1, 0, 8]]) == [0, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 2, 8], [2, 3, 11], [1, 2, 8], [2, 7, 12], [1, 2, 8]]) == [0, 1, 2]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21],queries = [[1, 1, 19], [2, 2, 10], [1, 1, 19], [2, 4, 20], [1, 1, 19], [2, 6, 30], [1, 1, 19], [2, 8, 40], [1, 1, 19], [2, 10, 50], [1, 1, 19], [2, 12, 60], [1, 1, 19], [2, 14, 70], [1, 1, 19], [2, 16, 80], [1, 1, 19], [2, 18, 90], [1, 1, 19]]) == [8, 8, 8, 8, 8, 8, 8, 8, 8, 9]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 0, 8], [2, 3, 2], [1, 1, 7]]) == [0, 1]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [[1, 1, 8], [2, 3, 65], [1, 2, 9], [2, 6, 55], [1, 0, 9]]) == [0, 0, 1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],queries = [[2, 5, 5], [1, 0, 16], [2, 10, 10], [1, 5, 11]]) == [0, 1]\n assert candidate(nums = [1000, 999, 1001, 998, 1002, 997, 1003, 996, 1004, 995],queries = [[1, 0, 9], [2, 2, 1000], [1, 1, 8], [2, 4, 1001], [1, 0, 8]]) == [4, 3, 3]\n assert candidate(nums = [10, 20, 15, 25, 20, 30, 25, 35, 30, 40],queries = [[1, 0, 9], [2, 3, 50], [1, 2, 8], [2, 6, 10], [1, 0, 9]]) == [4, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 0, 9], [2, 4, 5], [1, 0, 9], [2, 3, 6], [1, 0, 9]]) == [0, 0, 1]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5],queries = [[1, 1, 8], [2, 2, 10], [2, 4, 20], [1, 0, 8]]) == [3, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],queries = [[1, 0, 16], [2, 6, 6], [1, 3, 13], [2, 10, 10], [1, 0, 16]]) == [2, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[2, 5, 3], [1, 0, 9], [2, 4, 10], [1, 1, 8], [2, 8, 5]]) == [1, 1]\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350, 500, 450, 600, 550],queries = [[1, 0, 10], [2, 2, 225], [1, 0, 10], [2, 6, 375], [1, 0, 10]]) == [5, 4, 4]\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40],queries = [[1, 0, 8], [2, 3, 15], [1, 0, 8], [1, 2, 6]]) == [4, 3, 1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 1, 7], [2, 5, 7], [1, 1, 7]]) == [0, 1]\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 35, 50, 45, 60, 55, 70, 65],queries = [[1, 1, 11], [2, 2, 18], [1, 1, 11], [2, 4, 28], [1, 1, 11], [2, 6, 38], [1, 1, 11], [2, 8, 48], [1, 1, 11]]) == [4, 4, 4, 4, 4]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5],queries = [[1, 0, 8], [2, 1, 2], [2, 3, 3], [1, 0, 8]]) == [4, 2]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],queries = [[1, 0, 20], [2, 1, 10], [1, 0, 20], [2, 3, 15], [1, 0, 20], [2, 5, 18], [1, 0, 20], [2, 7, 20], [1, 0, 20]]) == [7, 7, 7, 8, 8]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],queries = [[1, 0, 9], [2, 2, 3], [1, 1, 8], [2, 4, 5], [1, 2, 7]]) == [4, 3, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 0, 9], [2, 5, 6], [1, 0, 9], [2, 4, 7], [1, 0, 9]]) == [0, 0, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 1, 7], [2, 4, 5], [1, 1, 7]]) == [0, 0]\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 5, 7, 8, 9, 7, 11, 10],queries = [[1, 0, 12], [2, 2, 5], [1, 1, 11], [2, 5, 8], [1, 0, 12]]) == [4, 3, 4]\n assert candidate(nums = [5, 3, 4, 6, 7, 8, 2, 4, 5, 6, 3, 2, 1],queries = [[1, 1, 12], [2, 5, 10], [1, 1, 12], [2, 8, 9], [1, 1, 12]]) == [2, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],queries = [[1, 1, 7], [2, 3, 5], [1, 1, 7]]) == [0, 0]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7],queries = [[1, 0, 9], [2, 4, 6], [1, 0, 9], [2, 5, 8], [1, 0, 9]]) == [4, 3, 3]\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100],queries = [[2, 1, 50], [1, 0, 10], [2, 3, 50], [1, 2, 8]]) == [4, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 1, 8], [2, 4, 5], [1, 1, 8], [2, 7, 8], [1, 0, 9]]) == [0, 0, 0]\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 40, 35, 50, 45, 60],queries = [[1, 0, 10], [2, 4, 20], [1, 3, 9], [2, 6, 30], [1, 5, 8]]) == [4, 2, 0]\n assert candidate(nums = [10, 11, 10, 12, 11, 13, 12, 14, 13, 15],queries = [[1, 1, 8], [2, 3, 15], [1, 0, 9], [2, 6, 11], [1, 2, 7]]) == [3, 4, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],queries = [[1, 1, 7], [2, 4, 10], [1, 1, 7]]) == [0, 1]\n assert candidate(nums = [5, 3, 7, 5, 9, 7, 11, 9, 13, 11, 15],queries = [[1, 1, 9], [2, 4, 8], [1, 1, 9], [2, 6, 10], [1, 1, 9], [2, 8, 14], [1, 1, 9]]) == [4, 4, 4, 4]\n assert candidate(nums = [3, 1, 4, 2, 5, 3, 1, 4, 2, 5],queries = [[2, 3, 4], [1, 0, 4], [2, 5, 6], [1, 4, 9]]) == [0, 2]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 8, 9],queries = [[1, 2, 5], [2, 4, 6], [1, 2, 5], [2, 3, 5], [1, 2, 5]]) == [1, 0, 0]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1],queries = [[1, 0, 16], [2, 2, 10], [1, 0, 16], [2, 5, 8], [1, 0, 16], [2, 8, 12], [1, 0, 16]]) == [4, 4, 4, 5]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[1, 0, 9], [2, 5, 6], [1, 0, 9], [2, 4, 3], [1, 0, 9]]) == [0, 0, 1]\n", "comparison": "exact"}, "public_tests": ["[3,1,4,2,5]\n[[2,3,4],[1,0,4]]", "[4,1,4,2,1,5]\n[[2,2,4],[1,0,2],[1,0,4]]"], "hints": ["Let p[i] be whether nums[i] is a peak in the original array. Namely p[i] = nums[i] > nums[i - 1] && nums[i] > nums[i + 1].", "Updating nums[i], only affects p[i], p[i - 1] and p[i + 1]. We can recalculate the 3 values in constant time.", "The answer for [l_i, r_i] is p[l_i + 1] + p[l_i + 2] + … + p[r_i - 1] (note that l_i and r_i are not included).", "Use some data structures (i.e. segment tree or binary indexed tree) to maintain the subarray sum efficiently."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().countOfPeaks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:13+00:00", "tests_total": 86, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-indexed-tree", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def count_of_peaks(nums, queries)", "container": null, "callable": "count_of_peaks", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3190, "task_id": "find-minimum-operations-to-make-all-elements-divisible-by-three", "difficulty": "Easy", "problem_description": "You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums.\n\nReturn the minimum number of operations to make all elements of nums divisible by 3.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation:\nAll array elements can be made divisible by 3 using 3 operations:\n- Subtract 1 from 1.\n- Add 1 to 2.\n- Subtract 1 from 4.\n\nExample 2:\n\nInput: nums = [3,6,9]\nOutput: 0\n\nConstraints:\n\n- 1 <= nums.length <= 50\n- 1 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 5]) == 4\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 2, 4, 5, 7]) == 5\n assert candidate(nums = [1, 2, 4, 5, 7, 8]) == 6\n assert candidate(nums = [11, 22, 33, 44]) == 3\n assert candidate(nums = [15, 18, 21, 24]) == 0\n assert candidate(nums = [50, 49, 48, 47, 46]) == 4\n assert candidate(nums = [1, 2, 3, 4]) == 3\n assert candidate(nums = [47, 49, 50]) == 3\n assert candidate(nums = [2, 4, 8, 10]) == 4\n assert candidate(nums = [2, 4, 8, 16]) == 4\n assert candidate(nums = [1, 4, 7, 10]) == 4\n assert candidate(nums = [1, 5, 7, 10]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [33, 36, 39, 42]) == 0\n assert candidate(nums = [2, 2, 2, 2]) == 4\n assert candidate(nums = [2, 5, 8, 11]) == 4\n assert candidate(nums = [5, 10, 15, 20, 25]) == 4\n assert candidate(nums = [2, 5, 8, 11, 14]) == 5\n assert candidate(nums = [5, 10, 15, 20]) == 3\n assert candidate(nums = [4, 5, 6, 7]) == 3\n assert candidate(nums = [1, 2, 5]) == 3\n assert candidate(nums = [1, 5, 7]) == 3\n assert candidate(nums = [3, 6, 9]) == 0\n assert candidate(nums = [30, 33, 36, 39]) == 0\n assert candidate(nums = [7, 14, 21, 28]) == 3\n assert candidate(nums = [2, 2, 2, 2, 2]) == 5\n assert candidate(nums = [10, 20, 30, 40]) == 3\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 50, 1, 2, 3]) == 11\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49]) == 17\n assert candidate(nums = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 8\n assert candidate(nums = [8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50]) == 15\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29]) == 20\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33]) == 0\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35]) == 11\n assert candidate(nums = [15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 3, 6, 9, 12, 18, 21, 27, 33, 36, 39, 42, 48]) == 14\n assert candidate(nums = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 7\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44]) == 8\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50]) == 17\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]) == 8\n assert candidate(nums = [30, 32, 35, 38, 41, 44, 47, 50]) == 7\n assert candidate(nums = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 9\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == 14\n assert candidate(nums = [1, 5, 7, 8, 10]) == 5\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47]) == 16\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 50]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 8\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29]) == 10\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34]) == 12\n assert candidate(nums = [31, 32, 34, 35, 37, 38, 40, 41, 43, 44, 46, 47, 49]) == 13\n assert candidate(nums = [19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49]) == 11\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19]) == 7\n assert candidate(nums = [29, 30, 31, 32, 33, 34, 35, 36]) == 5\n assert candidate(nums = [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]) == 20\n assert candidate(nums = [2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18]) == 6\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]) == 8\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33]) == 6\n assert candidate(nums = [1, 5, 10, 15, 20, 25]) == 5\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26]) == 18\n assert candidate(nums = [1, 5, 7, 8, 11, 13]) == 6\n assert candidate(nums = [45, 46, 47, 48, 49, 1, 2, 3, 4, 5, 6]) == 7\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 10\n assert candidate(nums = [1, 5, 7, 8, 10, 12, 14, 16, 19, 22]) == 9\n assert candidate(nums = [49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33]) == 11\n assert candidate(nums = [10, 20, 30, 40, 50]) == 4\n assert candidate(nums = [41, 44, 47, 50, 1, 4, 7, 10, 13, 16]) == 10\n assert candidate(nums = [1, 5, 7, 11, 13, 17, 19]) == 7\n assert candidate(nums = [13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49]) == 13\n assert candidate(nums = [1, 5, 7, 11, 14, 17, 20, 23]) == 8\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43]) == 15\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10]) == 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]) == 14\n assert candidate(nums = [15, 16, 18, 20, 21, 23, 25, 27, 28, 30, 32, 34, 36, 38, 40]) == 9\n assert candidate(nums = [29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == 7\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16]) == 5\n assert candidate(nums = [1, 5, 7, 10, 11, 14, 16]) == 7\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 1, 2, 3]) == 6\n assert candidate(nums = [11, 13, 17, 19, 23, 29, 31]) == 7\n assert candidate(nums = [3, 5, 6, 9, 12, 15, 18, 21]) == 1\n assert candidate(nums = [4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49]) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 13\n assert candidate(nums = [37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 1, 2, 3, 4, 5, 6]) == 13\n assert candidate(nums = [29, 28, 27, 26, 25, 24, 23, 22, 21]) == 6\n assert candidate(nums = [29, 31, 32, 34, 35]) == 5\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 1, 2, 3, 4]) == 7\n assert candidate(nums = [2, 4, 8, 10, 14, 16, 20, 22, 26, 28, 32, 34, 38, 40, 44, 46, 50]) == 17\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 4, 4, 4, 5, 5, 5, 7, 7, 7, 8, 8, 8]) == 18\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]) == 0\n assert candidate(nums = [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 7\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14]) == 10\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 40, 41, 43, 44, 46, 47, 49]) == 33\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[3,6,9]"], "hints": ["If x % 3 != 0 we can always increment or decrement x such that we only need 1 operation.", "Add min(nums[i] % 3, 3 - (nums[i] % 3)) to the count of operations."], "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:16:18+00:00", "tests_total": 117, "tests_dropped": 22, "flags": [], "topic_tags": ["array", "math"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations(nums)", "container": null, "callable": "minimum_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3191, "task_id": "minimum-operations-to-make-binary-array-elements-equal-to-one-i", "difficulty": "Medium", "problem_description": "You are given a binary array nums.\n\nYou can do the following operation on the array any number of times (possibly zero):\n\n- Choose any 3 consecutive elements from the array and flip all of them.\n\nFlipping an element means changing its value from 0 to 1, and from 1 to 0.\n\nReturn the minimum number of operations required to make all elements in nums equal to 1. If it is impossible, return -1.\n\nExample 1:\n\nInput: nums = [0,1,1,1,0,0]\nOutput: 3\nExplanation:\nWe can do the following operations:\n- Choose the elements at indices 0, 1 and 2. The resulting array is nums = [1,0,0,1,0,0].\n- Choose the elements at indices 1, 2 and 3. The resulting array is nums = [1,1,1,0,0,0].\n- Choose the elements at indices 3, 4 and 5. The resulting array is nums = [1,1,1,1,1,1].\n\nExample 2:\n\nInput: nums = [0,1,1,1]\nOutput: -1\nExplanation:\nIt is impossible to make all elements equal to 1.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 0 <= nums[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 3\n assert candidate(nums = [0, 0, 1, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 1, 1, 0]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 0, 0, 1, 0, 0]) == 2\n assert candidate(nums = [0, 1, 1, 1]) == -1\n assert candidate(nums = [0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == 3\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 1, 1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [0, 1, 1, 1, 0, 0]) == 3\n assert candidate(nums = [0, 0, 0, 0, 0, 0]) == 2\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1]) == 1\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == -1\n assert candidate(nums = [1, 1, 1, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 6\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == -1\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1]) == 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]) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 3\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [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, 1, 0, 1]) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 24\n assert candidate(nums = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == -1\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 10\n assert candidate(nums = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == 8\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]) == 0\n assert candidate(nums = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]) == -1\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 8\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1]) == -1\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 4\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 9\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 11\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 2\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 5\n assert candidate(nums = [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]) == -1\n assert candidate(nums = [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, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 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]) == 0\n assert candidate(nums = [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 3\n assert candidate(nums = [0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) == 12\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 6\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == -1\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]) == 4\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == -1\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 4\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 4\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0]) == -1\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]) == -1\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 6\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == -1\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0]) == 3\n assert candidate(nums = [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]) == 12\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == -1\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == -1\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 9\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]) == 0\n assert candidate(nums = [1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 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]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1]) == -1\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == -1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]) == 2\n assert candidate(nums = [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0]) == -1\n assert candidate(nums = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0]) == 10\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == -1\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 2\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]) == -1\n", "comparison": "exact"}, "public_tests": ["[0,1,1,1,0,0]", "[0,1,1,1]"], "hints": ["If nums[0] is 0, then the only way to change it to 1 is by doing an operation on the first 3 elements of the array.", "After Changing nums[0] to 1, use the same logic on the remaining array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:20+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "bit-manipulation", "queue", "sliding-window", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3192, "task_id": "minimum-operations-to-make-binary-array-elements-equal-to-one-ii", "difficulty": "Medium", "problem_description": "You are given a binary array nums.\n\nYou can do the following operation on the array any number of times (possibly zero):\n\n- Choose any index i from the array and flip all the elements from index i to the end of the array.\n\nFlipping an element means changing its value from 0 to 1, and from 1 to 0.\n\nReturn the minimum number of operations required to make all elements in nums equal to 1.\n\nExample 1:\n\nInput: nums = [0,1,1,0,1]\nOutput: 4\nExplanation:\nWe can do the following operations:\n- Choose the index i = 1. The resulting array will be nums = [0,0,0,1,0].\n- Choose the index i = 0. The resulting array will be nums = [1,1,1,0,1].\n- Choose the index i = 4. The resulting array will be nums = [1,1,1,0,0].\n- Choose the index i = 3. The resulting array will be nums = [1,1,1,1,1].\n\nExample 2:\n\nInput: nums = [1,0,0,0]\nOutput: 1\nExplanation:\nWe can do the following operation:\n- Choose the index i = 1. The resulting array will be nums = [1,1,1,1].\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0]) == 5\n assert candidate(nums = [0, 0, 1, 1, 1, 0]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == 8\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0]) == 3\n assert candidate(nums = [1, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 0, 1, 0, 0]) == 3\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == 5\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0]) == 7\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1]) == 4\n assert candidate(nums = [0, 0, 0, 1, 1]) == 2\n assert candidate(nums = [1, 1, 0, 0, 0]) == 1\n assert candidate(nums = [0, 1, 1, 0, 1]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 8\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0]) == 9\n assert candidate(nums = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0]) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 14\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 16\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 11\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 18\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 14\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 11\n assert candidate(nums = [1, 1, 0, 0, 1, 0, 1, 0, 0]) == 5\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 1, 0, 1, 0, 0, 1, 0]) == 5\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 15\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 22\n assert candidate(nums = [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, 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, 1, 0, 1, 0, 1]) == 60\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 7\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1]) == 8\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 16\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 10\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 2\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1]) == 8\n assert candidate(nums = [0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 14\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1]) == 6\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0, 1, 0]) == 35\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 4\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 8\n assert candidate(nums = [0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0]) == 9\n assert candidate(nums = [1, 1, 0, 1, 0, 0, 1, 1, 0]) == 5\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 2\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]) == 29\n assert candidate(nums = [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]) == 25\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0]) == 5\n", "comparison": "exact"}, "public_tests": ["[0,1,1,0,1]", "[1,0,0,0]"], "hints": ["The only way to change nums[0] to 1 is by performing an operation with index i = 0.", "Iterate from left to right and perform an operation at each index i where nums[i] is 0, and keep track of how many operations are currently performed on the suffix."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:23+00:00", "tests_total": 68, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def min_operations(nums)", "container": null, "callable": "min_operations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3193, "task_id": "count-the-number-of-inversions", "difficulty": "Hard", "problem_description": "You are given an integer n and a 2D array requirements, where requirements[i] = [end_i, cnt_i] represents the end index and the inversion count of each requirement.\n\nA pair of indices (i, j) from an integer array nums is called an inversion if:\n\n- i < j and nums[i] > nums[j]\n\nReturn the number of permutations perm of [0, 1, 2, ..., n - 1] such that for all requirements[i], perm[0..end_i] has exactly cnt_i inversions.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 3, requirements = [[2,2],[0,0]]\nOutput: 2\nExplanation:\nThe two permutations are:\n- [2, 0, 1]\n - Prefix [2, 0, 1] has inversions (0, 1) and (0, 2).\n - Prefix [2] has 0 inversions.\n- [1, 2, 0]\n - Prefix [1, 2, 0] has inversions (0, 2) and (1, 2).\n - Prefix [1] has 0 inversions.\n\nExample 2:\n\nInput: n = 3, requirements = [[2,2],[1,1],[0,0]]\nOutput: 1\nExplanation:\nThe only satisfying permutation is [2, 0, 1]:\n- Prefix [2, 0, 1] has inversions (0, 1) and (0, 2).\n- Prefix [2, 0] has an inversion (0, 1).\n- Prefix [2] has 0 inversions.\n\nExample 3:\n\nInput: n = 2, requirements = [[0,0],[1,0]]\nOutput: 1\nExplanation:\nThe only satisfying permutation is [0, 1]:\n- Prefix [0] has 0 inversions.\n- Prefix [0, 1] has no inversions.\n\nConstraints:\n\n- 2 <= n <= 300\n- 1 <= requirements.length <= n\n- requirements[i] = [end_i, cnt_i]\n- 0 <= end_i <= n - 1\n- 0 <= cnt_i <= 400\n- The input is generated such that there is at least one i such that end_i == n - 1.\n- The input is generated such that all end_i are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,requirements = [[3, 3], [1, 1], [2, 2], [0, 0]]) == 1\n assert candidate(n = 5,requirements = [[4, 6], [2, 2], [3, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 2,requirements = [[0, 0], [1, 0]]) == 1\n assert candidate(n = 3,requirements = [[2, 2], [0, 0]]) == 2\n assert candidate(n = 3,requirements = [[2, 2], [1, 1], [0, 0]]) == 1\n assert candidate(n = 5,requirements = [[4, 5], [2, 2], [0, 0]]) == 8\n assert candidate(n = 15,requirements = [[14, 50], [10, 25], [6, 15], [4, 10], [2, 5], [0, 0]]) == 0\n assert candidate(n = 6,requirements = [[5, 6], [3, 3], [1, 1], [0, 0]]) == 12\n assert candidate(n = 7,requirements = [[6, 15], [4, 10], [2, 5], [0, 0]]) == 0\n assert candidate(n = 30,requirements = [[29, 150], [24, 75], [19, 40], [15, 20], [11, 10], [7, 5], [5, 3], [3, 1], [1, 0], [0, 0]]) == 363866727\n assert candidate(n = 15,requirements = [[14, 60], [8, 20], [9, 30], [4, 8], [5, 12], [2, 4], [3, 6], [6, 18], [7, 24], [10, 40], [11, 50], [12, 60], [13, 70], [1, 2], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 14], [5, 6], [3, 3], [1, 1], [2, 2], [4, 4], [6, 8], [0, 0]]) == 1\n assert candidate(n = 15,requirements = [[14, 85], [12, 45], [10, 20], [8, 10], [6, 6], [4, 3], [2, 2], [0, 0], [3, 5], [5, 8], [7, 12], [9, 18], [11, 30], [13, 50]]) == 0\n assert candidate(n = 20,requirements = [[19, 90], [16, 60], [13, 40], [10, 20], [7, 10], [4, 5], [2, 2], [0, 0]]) == 358259893\n assert candidate(n = 5,requirements = [[4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 15,requirements = [[14, 91], [13, 78], [12, 65], [11, 52], [10, 39], [9, 26], [8, 13], [7, 0], [6, 0], [5, 0], [4, 0], [3, 0], [2, 0], [1, 0], [0, 0]]) == 0\n assert candidate(n = 12,requirements = [[11, 40], [9, 25], [7, 15], [5, 10], [3, 5], [1, 2], [0, 0]]) == 0\n assert candidate(n = 7,requirements = [[6, 21], [5, 15], [4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 8,requirements = [[7, 18], [5, 10], [4, 7], [3, 4], [2, 3], [1, 2], [0, 0]]) == 0\n assert candidate(n = 10,requirements = [[9, 30], [7, 15], [5, 8], [3, 4], [1, 2], [0, 0]]) == 0\n assert candidate(n = 9,requirements = [[8, 20], [6, 12], [5, 8], [4, 5], [3, 3], [2, 2], [1, 1], [0, 0]]) == 8\n assert candidate(n = 6,requirements = [[5, 10], [3, 4], [2, 2], [1, 1], [0, 0]]) == 4\n assert candidate(n = 20,requirements = [[19, 171], [18, 153], [17, 136], [16, 119], [15, 102], [14, 85], [13, 68], [12, 51], [11, 34], [10, 17], [9, 0], [8, 0], [7, 0], [6, 0], [5, 0], [4, 0], [3, 0], [2, 0], [1, 0], [0, 0]]) == 0\n assert candidate(n = 15,requirements = [[14, 105], [11, 40], [8, 15], [6, 7], [3, 3], [2, 1], [1, 0], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 28], [6, 21], [5, 15], [4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 8,requirements = [[7, 20], [6, 15], [5, 10], [4, 6], [3, 4], [2, 3], [1, 2], [0, 0]]) == 0\n assert candidate(n = 12,requirements = [[11, 45], [9, 25], [7, 15], [5, 8], [3, 4], [1, 2], [0, 0]]) == 0\n assert candidate(n = 9,requirements = [[8, 18], [6, 12], [4, 8], [2, 4], [0, 0]]) == 0\n assert candidate(n = 10,requirements = [[9, 35], [8, 25], [7, 20], [6, 15], [5, 10], [4, 6], [3, 4], [2, 3], [1, 2], [0, 0]]) == 0\n assert candidate(n = 25,requirements = [[24, 100], [15, 30], [16, 40], [12, 20], [13, 25], [8, 10], [9, 15], [6, 5], [7, 10], [4, 3], [5, 6], [2, 2], [3, 3], [17, 50], [18, 60], [19, 70], [20, 80], [21, 90], [22, 100], [23, 110], [1, 1], [0, 0]]) == 0\n assert candidate(n = 12,requirements = [[11, 66], [8, 30], [6, 15], [4, 7], [2, 2], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 10], [4, 4], [5, 5], [2, 1], [3, 2], [6, 6], [1, 0], [0, 0]]) == 1\n assert candidate(n = 25,requirements = [[24, 150], [21, 105], [18, 70], [15, 45], [12, 30], [9, 20], [6, 15], [3, 10], [0, 0]]) == 0\n assert candidate(n = 9,requirements = [[8, 25], [7, 20], [6, 15], [5, 10], [4, 6], [3, 4], [2, 3], [1, 2], [0, 0]]) == 0\n assert candidate(n = 7,requirements = [[6, 15], [4, 8], [2, 4], [0, 0]]) == 0\n assert candidate(n = 6,requirements = [[5, 6], [4, 3], [3, 2], [2, 1], [1, 0], [0, 0]]) == 1\n assert candidate(n = 7,requirements = [[6, 10], [4, 5], [3, 3], [2, 1], [1, 0], [0, 0]]) == 6\n assert candidate(n = 10,requirements = [[9, 30], [5, 10], [6, 15], [3, 4], [4, 8], [2, 2], [7, 20], [8, 25], [1, 1], [0, 0]]) == 1\n assert candidate(n = 6,requirements = [[5, 10], [3, 5], [1, 2], [0, 0]]) == 0\n assert candidate(n = 6,requirements = [[5, 6], [3, 2], [2, 1], [1, 0], [0, 0]]) == 5\n assert candidate(n = 25,requirements = [[24, 250], [22, 170], [20, 100], [18, 60], [16, 40], [14, 20], [12, 10], [10, 6], [8, 4], [6, 3], [4, 2], [2, 1], [0, 0], [1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17], [19, 19], [21, 21], [23, 23]]) == 0\n assert candidate(n = 10,requirements = [[9, 45], [7, 21], [5, 10], [4, 6], [3, 4], [2, 2], [1, 1], [0, 0]]) == 0\n assert candidate(n = 10,requirements = [[9, 25], [7, 15], [5, 10], [3, 5], [1, 2], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 10], [5, 5], [3, 3], [1, 1], [0, 0]]) == 54\n assert candidate(n = 10,requirements = [[9, 28], [7, 15], [5, 6], [3, 3], [1, 1], [2, 2], [4, 4], [6, 8], [8, 20], [0, 0]]) == 1\n assert candidate(n = 6,requirements = [[5, 9], [4, 7], [3, 5], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 18,requirements = [[17, 60], [13, 30], [9, 15], [6, 10], [4, 5], [2, 2], [0, 0]]) == 217514306\n assert candidate(n = 7,requirements = [[6, 15], [5, 10], [4, 6], [3, 4], [2, 2], [1, 1], [0, 0]]) == 1\n assert candidate(n = 8,requirements = [[7, 21], [5, 10], [4, 6], [3, 4], [2, 2], [1, 1], [0, 0]]) == 3\n assert candidate(n = 15,requirements = [[14, 50], [12, 30], [10, 20], [8, 15], [6, 10], [4, 5], [2, 3], [0, 0]]) == 57024\n assert candidate(n = 8,requirements = [[7, 15], [3, 5], [5, 10], [2, 2], [1, 1], [0, 0]]) == 30\n assert candidate(n = 7,requirements = [[6, 15], [4, 10], [2, 3], [0, 0], [3, 4], [5, 9], [1, 1]]) == 0\n assert candidate(n = 20,requirements = [[19, 130], [17, 80], [15, 40], [13, 20], [11, 10], [9, 6], [7, 4], [5, 3], [3, 2], [1, 1], [0, 0], [2, 2], [4, 4], [6, 6], [8, 8], [10, 10], [12, 12], [14, 14], [16, 16], [18, 18]]) == 0\n assert candidate(n = 12,requirements = [[11, 66], [10, 55], [9, 45], [8, 36], [7, 28], [6, 21], [5, 15], [4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 6,requirements = [[5, 12], [4, 8], [3, 5], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 18,requirements = [[17, 63], [14, 42], [11, 28], [8, 21], [5, 14], [2, 7], [0, 0]]) == 0\n assert candidate(n = 15,requirements = [[14, 45], [11, 25], [8, 10], [5, 5], [2, 2], [0, 0]]) == 5518800\n assert candidate(n = 12,requirements = [[11, 28], [8, 15], [5, 8], [2, 3], [0, 0]]) == 51170\n assert candidate(n = 10,requirements = [[9, 45], [8, 36], [7, 28], [6, 21], [5, 15], [4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 25,requirements = [[24, 100], [20, 50], [15, 25], [11, 15], [7, 10], [5, 5], [3, 2], [1, 0], [0, 0]]) == 195391545\n assert candidate(n = 10,requirements = [[9, 35], [8, 25], [7, 18], [6, 12], [5, 8], [4, 5], [3, 3], [2, 2], [1, 1], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 21], [4, 10], [3, 5], [2, 3], [1, 1], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 10], [6, 5], [5, 2], [4, 1], [3, 0], [2, 0], [1, 0], [0, 0]]) == 1\n assert candidate(n = 9,requirements = [[8, 36], [7, 28], [6, 21], [5, 15], [4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 15,requirements = [[14, 105], [13, 84], [12, 63], [11, 42], [10, 28], [9, 21], [8, 15], [7, 10], [6, 6], [5, 4], [4, 2], [3, 1], [2, 1], [1, 0], [0, 0]]) == 0\n assert candidate(n = 12,requirements = [[11, 30], [8, 15], [5, 8], [3, 3], [1, 1], [0, 0]]) == 47250\n assert candidate(n = 20,requirements = [[19, 190], [18, 171], [17, 153], [16, 136], [15, 119], [14, 105], [13, 92], [12, 80], [11, 69], [10, 58], [9, 48], [8, 39], [7, 31], [6, 24], [5, 18], [4, 13], [3, 9], [2, 6], [1, 4], [0, 0]]) == 0\n assert candidate(n = 5,requirements = [[4, 6], [3, 4], [2, 3], [1, 2], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 14], [5, 7], [3, 3], [1, 1], [0, 0]]) == 105\n assert candidate(n = 10,requirements = [[9, 45], [5, 15], [3, 5], [2, 3], [1, 1], [0, 0]]) == 0\n assert candidate(n = 8,requirements = [[7, 20], [5, 10], [3, 5], [1, 2], [0, 0], [6, 12], [4, 6]]) == 0\n assert candidate(n = 8,requirements = [[7, 21], [5, 12], [3, 6], [1, 3], [0, 0]]) == 0\n assert candidate(n = 9,requirements = [[8, 28], [6, 18], [4, 10], [2, 5], [0, 0]]) == 0\n assert candidate(n = 10,requirements = [[9, 40], [7, 25], [5, 15], [4, 10], [3, 6], [2, 4], [1, 2], [0, 0]]) == 0\n assert candidate(n = 6,requirements = [[5, 6], [3, 3], [1, 1], [2, 2], [4, 4], [0, 0]]) == 1\n assert candidate(n = 10,requirements = [[9, 20], [6, 10], [4, 5], [2, 2], [0, 0]]) == 2688\n assert candidate(n = 7,requirements = [[6, 15], [5, 10], [4, 6], [2, 3], [0, 0]]) == 4\n assert candidate(n = 5,requirements = [[4, 6], [3, 4], [2, 2], [1, 1], [0, 0]]) == 1\n assert candidate(n = 20,requirements = [[19, 80], [15, 40], [11, 20], [7, 10], [5, 5], [3, 2], [1, 0], [0, 0]]) == 208478921\n assert candidate(n = 15,requirements = [[14, 91], [12, 50], [10, 25], [8, 15], [6, 8], [4, 4], [2, 2], [0, 0]]) == 0\n assert candidate(n = 6,requirements = [[5, 15], [4, 10], [3, 6], [2, 3], [1, 1], [0, 0]]) == 1\n assert candidate(n = 6,requirements = [[5, 6], [3, 3], [2, 1], [1, 0], [0, 0]]) == 4\n assert candidate(n = 10,requirements = [[9, 20], [8, 15], [7, 10], [6, 5], [5, 3], [4, 2], [3, 1], [2, 0], [1, 0], [0, 0]]) == 1\n assert candidate(n = 20,requirements = [[19, 150], [10, 50], [11, 60], [7, 20], [8, 30], [5, 10], [6, 15], [3, 5], [4, 10], [1, 2], [2, 3], [12, 70], [13, 80], [14, 90], [15, 100], [16, 110], [17, 120], [18, 130], [0, 0]]) == 0\n", "comparison": "exact"}, "public_tests": ["3\n[[2,2],[0,0]]", "3\n[[2,2],[1,1],[0,0]]", "2\n[[0,0],[1,0]]"], "hints": ["Let dp[i][j] denote the number of arrays of length i with j inversions.", "dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + … + dp[i - 1][0].", "dp[i][j] = 0 if for some x, requirements[x][0] == i and requirements[x][1] != j."], "metadata": {"canonical_parameter_names": ["n", "requirements"], "leetcode_dataset_entry_point": "Solution().numberOfPermutations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:25+00:00", "tests_total": 84, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_permutations(n, requirements)", "container": null, "callable": "number_of_permutations", "parameters": [{"name": "n", "type": "Integer"}, {"name": "requirements", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3194, "task_id": "minimum-average-of-smallest-and-largest-elements", "difficulty": "Easy", "problem_description": "You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even.\n\nYou repeat the following procedure n / 2 times:\n\n- Remove the smallest element, minElement, and the largest element maxElement, from nums.\n- Add (minElement + maxElement) / 2 to averages.\n\nReturn the minimum element in averages.\n\nExample 1:\n\nInput: nums = [7,8,3,4,15,13,4,1]\nOutput: 5.5\nExplanation:\n\nstep | nums | averages\n0 | [7,8,3,4,15,13,4,1] | []\n1 | [7,8,3,4,13,4] | [8]\n2 | [7,8,4,4] | [8,8]\n3 | [7,4] | [8,8,6]\n4 | [] | [8,8,6,5.5]\n\nThe smallest element of averages, 5.5, is returned.\n\nExample 2:\n\nInput: nums = [1,9,8,3,10,5]\nOutput: 5.5\nExplanation:\n\nstep | nums | averages\n0 | [1,9,8,3,10,5] | []\n1 | [9,8,3,5] | [5.5]\n2 | [8,5] | [5.5,6]\n3 | [] | [5.5,6,6.5]\n\nExample 3:\n\nInput: nums = [1,2,3,7,8,9]\nOutput: 5.0\nExplanation:\n\nstep | nums | averages\n0 | [1,2,3,7,8,9] | []\n1 | [2,3,7,8] | [5]\n2 | [3,7] | [5,5]\n3 | [] | [5,5,5]\n\nConstraints:\n\n- 2 <= n == nums.length <= 50\n- n is even.\n- 1 <= nums[i] <= 50\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(nums=[2, 1, 5, 4, 9, 8]), 4.5)\n assert answers_match(candidate(nums=[1, 9, 8, 3, 10, 5]), 5.5)\n assert answers_match(candidate(nums=[25, 25, 25, 25, 25, 25]), 25.0)\n assert answers_match(candidate(nums=[2, 3, 10, 1, 11, 5, 4, 8]), 4.5)\n assert answers_match(candidate(nums=[50, 49, 48, 47, 46, 45]), 47.5)\n assert answers_match(candidate(nums=[2, 4, 6, 8, 10, 12]), 7.0)\n assert answers_match(candidate(nums=[1, 5, 9, 13, 17, 21]), 11.0)\n assert answers_match(candidate(nums=[2, 3, 1, 4, 6, 5]), 3.5)\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11]), 6.0)\n assert answers_match(candidate(nums=[2, 2, 2, 2, 2, 2]), 2.0)\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6]), 3.5)\n assert answers_match(candidate(nums=[50, 1, 25, 2, 50, 24]), 24.5)\n assert answers_match(candidate(nums=[25, 10, 30, 5, 40, 15]), 20.0)\n assert answers_match(candidate(nums=[7, 8, 3, 4, 15, 13, 4, 1]), 5.5)\n assert answers_match(candidate(nums=[5, 5, 5, 5, 5, 5]), 5.0)\n assert answers_match(candidate(nums=[45, 30, 35, 20, 50, 40]), 35.0)\n assert answers_match(candidate(nums=[50, 1, 50, 2, 50, 3]), 25.5)\n assert answers_match(candidate(nums=[15, 15, 15, 15, 15, 15]), 15.0)\n assert answers_match(candidate(nums=[1, 2, 3, 7, 8, 9]), 5.0)\n assert answers_match(candidate(nums=[10, 20, 30, 40]), 25.0)\n assert answers_match(candidate(nums=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]), 19.5)\n assert answers_match(candidate(nums=[7, 3, 9, 1, 5, 11, 13, 2, 8, 6, 10, 4]), 6.5)\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5.5)\n assert answers_match(candidate(nums=[48, 46, 44, 42, 40, 38, 36, 34]), 41.0)\n assert answers_match(candidate(nums=[1, 5, 9, 13, 17, 21, 25, 29]), 15.0)\n assert answers_match(candidate(nums=[27, 37, 23, 33, 29, 39, 21, 31]), 30.0)\n assert answers_match(candidate(nums=[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), 2.0)\n assert answers_match(candidate(nums=[7, 14, 21, 28, 35, 42, 49, 1, 8, 15]), 18.0)\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), 6.5)\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), 8.5)\n assert answers_match(candidate(nums=[7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]), 7.0)\n assert answers_match(candidate(nums=[45, 30, 15, 5, 50, 35, 20, 10, 40, 25]), 27.5)\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 1]), 25.0)\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 1, 2, 3, 4, 5]), 7.5)\n assert answers_match(candidate(nums=[24, 12, 36, 6, 48, 24]), 24.0)\n assert answers_match(candidate(nums=[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]), 15.5)\n assert answers_match(candidate(nums=[23, 17, 11, 5, 31, 29, 25, 19, 35, 33, 37, 13]), 21.0)\n assert answers_match(candidate(nums=[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]), 30.0)\n assert answers_match(candidate(nums=[49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30]), 39.5)\n assert answers_match(candidate(nums=[20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10]), 15.0)\n assert answers_match(candidate(nums=[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]), 3.0)\n assert answers_match(candidate(nums=[29, 10, 34, 15, 40, 5, 30, 20]), 22.0)\n assert answers_match(candidate(nums=[49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38]), 43.5)\n assert answers_match(candidate(nums=[42, 42, 42, 42, 42, 42, 42, 42, 42, 42]), 42.0)\n assert answers_match(candidate(nums=[4, 8, 12, 16, 20, 24, 28, 32]), 18.0)\n assert answers_match(candidate(nums=[17, 18, 19, 20, 21, 22, 23, 24, 25, 26]), 21.5)\n assert answers_match(candidate(nums=[48, 49, 50, 1, 2, 3, 47, 46, 45, 44]), 25.5)\n assert answers_match(candidate(nums=[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]), 5.5)\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]), 10.0)\n assert answers_match(candidate(nums=[50, 25, 1, 30, 45, 20, 15, 40]), 25.5)\n assert answers_match(candidate(nums=[45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]), 45.0)\n assert answers_match(candidate(nums=[1, 50, 2, 49, 3, 48, 4, 47, 5, 46]), 25.5)\n assert answers_match(candidate(nums=[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]), 25.5)\n assert answers_match(candidate(nums=[28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28]), 28.0)\n assert answers_match(candidate(nums=[49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38]), 43.5)\n assert answers_match(candidate(nums=[29, 29, 29, 29, 1, 1, 1, 1, 14, 14, 14, 14]), 14.0)\n assert answers_match(candidate(nums=[29, 19, 28, 18, 27, 17, 26, 16, 25, 15, 24, 14]), 21.5)\n assert answers_match(candidate(nums=[50, 49, 48, 47, 46, 45, 44, 43, 42, 41]), 45.5)\n assert answers_match(candidate(nums=[3, 11, 7, 15, 9, 17, 5, 13]), 10.0)\n assert answers_match(candidate(nums=[1, 50, 2, 49, 3, 48, 4, 47, 5, 46, 6, 45, 7, 44, 8, 43, 9, 42, 10, 41]), 25.5)\n assert answers_match(candidate(nums=[4, 8, 12, 16, 20, 24, 28, 32, 36, 40]), 22.0)\n assert answers_match(candidate(nums=[47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47]), 47.0)\n assert answers_match(candidate(nums=[8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]), 8.0)\n assert answers_match(candidate(nums=[8, 16, 24, 32, 40, 48, 12, 20]), 22.0)\n assert answers_match(candidate(nums=[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]), 5.0)\n assert answers_match(candidate(nums=[50, 49, 48, 47, 46, 45, 44, 43, 42, 41]), 45.5)\n assert answers_match(candidate(nums=[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]), 10.5)\n assert answers_match(candidate(nums=[30, 30, 29, 29, 28, 28, 27, 27, 26, 26, 25, 25]), 27.5)\n assert answers_match(candidate(nums=[45, 42, 43, 41, 44, 46, 47, 48]), 44.5)\n assert answers_match(candidate(nums=[29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29]), 29.0)\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5.5)\n assert answers_match(candidate(nums=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]), 12.0)\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11, 13, 15]), 8.0)\n assert answers_match(candidate(nums=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]), 21.0)\n assert answers_match(candidate(nums=[28, 22, 16, 10, 4, 32, 26, 20, 14, 8, 30, 12]), 18.0)\n assert answers_match(candidate(nums=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]), 11.0)\n assert answers_match(candidate(nums=[22, 38, 26, 40, 24, 36, 28, 34]), 31.0)\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 1.0)\n assert answers_match(candidate(nums=[45, 46, 47, 48, 49, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 8.5)\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]), 10.5)\n assert answers_match(candidate(nums=[15, 25, 35, 5, 30, 20, 40, 10]), 22.5)\n assert answers_match(candidate(nums=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]), 16.5)\n assert answers_match(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]), 25.5)\n assert answers_match(candidate(nums=[2, 6, 10, 14, 18, 22, 26, 30, 34, 38]), 20.0)\n assert answers_match(candidate(nums=[7, 14, 21, 28, 35, 42, 49, 1, 8, 15, 22, 29]), 21.5)\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 1]), 25.0)\n assert answers_match(candidate(nums=[1, 50, 2, 49, 3, 48, 4, 47]), 25.5)\n assert answers_match(candidate(nums=[4, 8, 15, 16, 23, 42, 1, 2, 3, 5, 7, 11, 13, 17, 19, 29]), 11.0)\n assert answers_match(candidate(nums=[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]), 4.0)\n assert answers_match(candidate(nums=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]), 13.0)\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 30]), 15.5)\n assert answers_match(candidate(nums=[42, 43, 44, 45, 46, 47, 48, 49, 50, 1]), 25.5)\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 1, 2, 3, 4, 5]), 7.5)\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 5, 15, 25]), 22.5)\n assert answers_match(candidate(nums=[17, 18, 19, 20, 21, 22, 23, 24, 25, 26]), 21.5)\n assert answers_match(candidate(nums=[5, 15, 25, 35, 45, 50, 40, 30, 20, 10]), 27.5)\n assert answers_match(candidate(nums=[1, 5, 10, 15, 20, 25, 30, 35, 40, 45]), 22.5)\n assert answers_match(candidate(nums=[50, 1, 49, 2, 48, 3, 47, 4, 46, 5, 45, 6]), 25.5)\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 5, 15, 25, 35, 45]), 27.5)\n assert answers_match(candidate(nums=[25, 26, 27, 28, 29, 30, 31, 32, 33, 34]), 29.5)\n assert answers_match(candidate(nums=[25, 24, 23, 22, 21, 20, 19, 18]), 21.5)\n assert answers_match(candidate(nums=[7, 14, 21, 28, 35, 42, 49, 50]), 28.5)\n assert answers_match(candidate(nums=[49, 2, 48, 3, 47, 4, 46, 5, 45, 6]), 25.5)\n assert answers_match(candidate(nums=[45, 44, 43, 42, 41, 40, 39, 38, 37, 36]), 40.5)\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]), 12.0)\n assert answers_match(candidate(nums=[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), 2.0)\n assert answers_match(candidate(nums=[33, 17, 47, 31, 27, 13, 41, 23, 39, 29, 35, 19]), 29.0)\n", "comparison": "float"}, "public_tests": ["[7,8,3,4,15,13,4,1]", "[1,9,8,3,10,5]", "[1,2,3,7,8,9]"], "hints": ["If nums is sorted, then the elements of averages are (nums[i] + nums[n - i - 1]) / 2 for all i < n / 2."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumAverage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:27+00:00", "tests_total": 132, "tests_dropped": 25, "flags": ["decimal_answer"], "topic_tags": ["array", "two-pointers", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_average(nums)", "container": null, "callable": "minimum_average", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3195, "task_id": "find-the-minimum-area-to-cover-all-ones-i", "difficulty": "Medium", "problem_description": "You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle.\n\nReturn the minimum possible area of the rectangle.\n\nExample 1:\n\nInput: grid = [[0,1,0],[1,0,1]]\nOutput: 6\nExplanation:\nThe smallest rectangle has a height of 2 and a width of 3, so it has an area of 2 * 3 = 6.\n\nExample 2:\n\nInput: grid = [[1,0],[0,0]]\nOutput: 1\nExplanation:\nThe smallest rectangle has both height and width 1, so its area is 1 * 1 = 1.\n\nConstraints:\n\n- 1 <= grid.length, grid[i].length <= 1000\n- grid[i][j] is either 0 or 1.\n- The input is generated such that there is at least one 1 in grid.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [1, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]) == 20\n assert candidate(grid = [[0, 0, 0, 1], [0, 1, 0, 0], [1, 0, 0, 0]]) == 12\n assert candidate(grid = [[1, 0], [0, 0]]) == 1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[1, 0, 1, 0, 1]]) == 5\n assert candidate(grid = [[1], [0], [1], [0], [1]]) == 5\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) == 16\n assert candidate(grid = [[0, 1, 0, 1], [1, 1, 1, 1], [0, 1, 0, 1]]) == 12\n assert candidate(grid = [[0, 0, 1, 0], [0, 1, 1, 0], [1, 1, 1, 1]]) == 12\n assert candidate(grid = [[0], [1], [0]]) == 1\n assert candidate(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0]]) == 4\n assert candidate(grid = [[1, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 1]]) == 12\n assert candidate(grid = [[1, 1], [1, 1]]) == 4\n assert candidate(grid = [[0, 1, 0], [1, 0, 1]]) == 6\n assert candidate(grid = [[1]]) == 1\n assert candidate(grid = [[0, 0, 0, 1], [0, 1, 1, 1], [0, 0, 0, 1]]) == 9\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1]]) == 15\n assert candidate(grid = [[0, 0, 1, 0], [0, 0, 0, 0], [1, 0, 0, 1]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 20\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 100\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0]]) == 49\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 25\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, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 12\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, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 16\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 30\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 64\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0], [0, 1, 0, 1, 0, 0], [0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0]]) == 9\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, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 56\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 361\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]) == 49\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 90\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 72\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 20\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0]]) == 25\n assert candidate(grid = [[0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0]]) == 81\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 20\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0]]) == 64\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 25\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1]]) == 49\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 0, 1], [0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 24\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1]]) == 35\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [1, 0, 0, 0, 0, 1]]) == 30\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0]]) == 18\n assert candidate(grid = [[1, 1, 0, 0, 0, 1], [1, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 0]]) == 30\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 165\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 81\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, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 32\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1]]) == 42\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 420\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 1, 1, 1, 0]]) == 25\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 100\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1]]) == 35\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1]]) == 42\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 25\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, 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, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 72\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, 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, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 4\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, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 1, 1, 1, 1, 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]]) == 12\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 0, 1, 0, 0]]) == 25\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 0, 1, 0], [0, 1, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0]]) == 25\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0]]) == 20\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 81\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 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, 1]]) == 20\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 0, 0, 1], [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], [1, 0, 0, 0, 1, 0, 0, 0, 1]]) == 45\n assert candidate(grid = [[1, 1, 0, 0, 0, 1], [1, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 0, 1]]) == 30\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == 25\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, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 25\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 16\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 63\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 49\n", "comparison": "exact"}, "public_tests": ["[[0,1,0],[1,0,1]]", "[[0,0],[1,0]]"], "hints": ["Find the minimum and maximum coordinates of a cell with a value of 1 in both directions."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumArea", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:30+00:00", "tests_total": 76, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_area(grid)", "container": null, "callable": "minimum_area", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3196, "task_id": "maximize-total-cost-of-alternating-subarrays", "difficulty": "Medium", "problem_description": "You are given an integer array nums with length n.\n\nThe cost of a subarray nums[l..r], where 0 <= l <= r < n, is defined as:\n\ncost(l, r) = nums[l] - nums[l + 1] + ... + nums[r] * (-1)^{r - l}\n\nYour task is to split nums into subarrays such that the total cost of the subarrays is maximized, ensuring each element belongs to exactly one subarray.\n\nFormally, if nums is split into k subarrays, where k > 1, at indices i_1, i_2, ..., i_{k - 1}, where 0 <= i_1 < i_2 < ... < i_{k - 1} < n - 1, then the total cost will be:\n\ncost(0, i_1) + cost(i_1 + 1, i_2) + ... + cost(i_{k - 1} + 1, n - 1)\n\nReturn an integer denoting the maximum total cost of the subarrays after splitting the array optimally.\n\nNote: If nums is not split into subarrays, i.e. k = 1, the total cost is simply cost(0, n - 1).\n\nExample 1:\n\nInput: nums = [1,-2,3,4]\nOutput: 10\nExplanation:\nOne way to maximize the total cost is by splitting [1, -2, 3, 4] into subarrays [1, -2, 3] and [4]. The total cost will be (1 + 2 + 3) + 4 = 10.\n\nExample 2:\n\nInput: nums = [1,-1,1,-1]\nOutput: 4\nExplanation:\nOne way to maximize the total cost is by splitting [1, -1, 1, -1] into subarrays [1, -1] and [1, -1]. The total cost will be (1 + 1) + (1 + 1) = 4.\n\nExample 3:\n\nInput: nums = [0]\nOutput: 0\nExplanation:\nWe cannot split the array further, so the answer is 0.\n\nExample 4:\n\nInput: nums = [1,-1]\nOutput: 2\nExplanation:\nSelecting the whole array gives a total cost of 1 + 1 = 2, which is the maximum.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^9 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, -3, 8, 7, -2, 6]) == 31\n assert candidate(nums = [5, -3, 2, 7, -6, 1]) == 24\n assert candidate(nums = [5, -3, 2, -4, 6]) == 20\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, -1, 1, -1]) == 4\n assert candidate(nums = [1, -2, 3, 4]) == 10\n assert candidate(nums = [1, -1]) == 2\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 5000000000\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 1\n assert candidate(nums = [-5, -3, -8, -7, -2, -6]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [-5, 3, -2, 7, -6, 1]) == 14\n assert candidate(nums = [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 164\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [5, 3, -5, 2, -3, 3, 9, -1]) == 31\n assert candidate(nums = [-1, -2, -3, -4]) == 2\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000]) == 4000000000\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10]) == 100\n assert candidate(nums = [10, -5, 10, -5, 10, -5, 10, -5, 10, -5, 10, -5]) == 90\n assert candidate(nums = [-1, 0, 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]) == 194\n assert candidate(nums = [0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1]) == 10\n assert candidate(nums = [-1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 6000000000\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]) == 140\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 9000000000\n assert candidate(nums = [5, 3, 1, -2, -4, -6, 7, 9, -11, 13]) == 53\n assert candidate(nums = [1000000000, 1000000000, -1000000000, -1000000000, 1000000000, 1000000000, -1000000000, -1000000000]) == 4000000000\n assert candidate(nums = [1, 2, -1, 3, -4, 5, -6, 7, -8]) == 37\n assert candidate(nums = [-5, 4, -3, 2, -1, 0, 1, -2, 3, -4]) == 15\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000]) == 5500\n assert candidate(nums = [1000000000, -999999999, 999999998, -999999997, 999999996, -999999995]) == 5999999985\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 44\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]) == 465\n assert candidate(nums = [1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 36\n assert candidate(nums = [9, -8, 7, -6, 5, -4, 3, -2, 1, 0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == 100\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]) == 20\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20]) == 210\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]) == 820\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 530\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20]) == 208\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 20\n assert candidate(nums = [10, -1, 3, -2, 15, -8, 7, -6, 5, -4]) == 61\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 300\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16]) == 134\n assert candidate(nums = [0, 1, -1, 0, 1, -1, 0, 1, -1, 0]) == 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, 21, -22, 23, -24, 25, -26, 27, -28, 29, -30, 31]) == 496\n assert candidate(nums = [1, -3, 2, -4, 3, -5, 4, -6, 5, -7, 6, -8, 7, -9, 8, -10]) == 88\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 550\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 18\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 9999999955\n assert candidate(nums = [100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99]) == 1592\n assert candidate(nums = [-1000000000, 999999999, -999999998, 999999997, -999999996, 999999995]) == 3999999985\n assert candidate(nums = [1, -3, 5, -7, 9, -11, 13, -15, 17]) == 81\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [50, -30, 20, -10, 0, 10, -20, 30, -40, 50]) == 260\n assert candidate(nums = [1000000000, -500000000, 1000000000, -500000000, 1000000000, -500000000, 1000000000, -500000000, 1000000000, -500000000]) == 7500000000\n assert candidate(nums = [-1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31, -33, -35, -37, -39]) == 20\n assert candidate(nums = [10, -5, 3, -8, 2, 1, -4, 6, -7, 9]) == 55\n assert candidate(nums = [10, -1, 100, -10, 1000, -100, 10000, -1000, 100000, -10000]) == 122221\n assert candidate(nums = [-1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000]) == 6000\n assert candidate(nums = [100, 200, -300, 400, -500, 600, -700, 800, -900, 1000]) == 5500\n assert candidate(nums = [1000000000, 500000000, -500000000, 250000000, -250000000, 125000000, -125000000, 62500000, -62500000, 31250000]) == 2906250000\n assert candidate(nums = [-10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 530\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 110\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 15\n assert candidate(nums = [1, 3, -5, 7, -9, 11, -13, 15, -17, 19]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 60\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == 55\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12]) == 76\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -1000, -900, -800, -700, -600, -500, -400, -300, -200, -100]) == 6000\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == 12\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [5, -3, 8, 7, -2, 6, -1, 4, 3, -5, 2, -8, 9, -4, 7, -6, 1, -2, 3, -10]) == 96\n assert candidate(nums = [1000000000, 1000000000, -1000000000, -1000000000, 1000000000, 1000000000]) == 4000000000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == -5\n assert candidate(nums = [1, 2, -3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14]) == 99\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 550\n assert candidate(nums = [100, -50, 50, -50, 50, -50, 50, -50, 50, -50]) == 550\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000]) == 6000000000\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == 6\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 1100, -1200, 1300, -1400, 1500, -1600, 1700, -1800, 1900, -2000]) == 21000\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 18\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50]) == 250\n assert candidate(nums = [500000000, -500000000, 500000000, -500000000, 500000000, -500000000, 500000000, -500000000, 500000000, -500000000]) == 5000000000\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 5\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 10\n assert candidate(nums = [9, -7, 5, -3, 1, -8, 6, -4, 2, -9, 7, -5, 3, -1, 0]) == 70\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(nums = [1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1]) == 11\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 10\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 16\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15]) == 120\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 50\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 40\n", "comparison": "exact"}, "public_tests": ["[1,-2,3,4]", "[1,-1,1,-1]", "[0]", "[1,-1]"], "hints": ["The problem can be solved using dynamic programming.", "Since we can always start a new subarray, the problem is the same as selecting some elements in the array and flipping their signs to negative to maximize the sum. However, we cannot flip the signs of 2 consecutive elements, and the first element in the array cannot be negative.", "Let dp[i][0/1] be the largest sum we can get for prefix nums[0..i], where dp[i][0] is the maximum if the i^th element wasn't flipped, and dp[i][1] is the maximum if the i^th element was flipped.", "Based on the restriction:\ndp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + nums[i]\ndp[i][1] = dp[i - 1][0] - nums[i]", "The initial state is:\ndp[1][0] = nums[0] + nums[1]\ndp[1][1] = nums[0] - nums[1]\nand the answer is max(dp[n - 1][0], dp[n - 1][1]).", "Can you optimize the space complexity?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumTotalCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:32+00:00", "tests_total": 105, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_total_cost(nums)", "container": null, "callable": "maximum_total_cost", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3197, "task_id": "find-the-minimum-area-to-cover-all-ones-ii", "difficulty": "Hard", "problem_description": "You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles.\n\nReturn the minimum possible sum of the area of these rectangles.\n\nNote that the rectangles are allowed to touch.\n\nExample 1:\n\nInput: grid = [[1,0,1],[1,1,1]]\nOutput: 5\nExplanation:\n- The 1's at (0, 0) and (1, 0) are covered by a rectangle of area 2.\n- The 1's at (0, 2) and (1, 2) are covered by a rectangle of area 2.\n- The 1 at (1, 1) is covered by a rectangle of area 1.\n\nExample 2:\n\nInput: grid = [[1,0,1,0],[0,1,0,1]]\nOutput: 5\nExplanation:\n- The 1's at (0, 0) and (0, 2) are covered by a rectangle of area 3.\n- The 1 at (1, 1) is covered by a rectangle of area 1.\n- The 1 at (1, 3) is covered by a rectangle of area 1.\n\nConstraints:\n\n- 1 <= grid.length, grid[i].length <= 30\n- grid[i][j] is either 0 or 1.\n- The input is generated such that there are at least three 1's in grid.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1]]) == 5\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [0, 0, 1, 1, 0]]) == 10\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 1, 0, 0], [0, 1, 1, 0, 0], [1, 0, 0, 1, 0]]) == 13\n assert candidate(grid = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]) == 12\n assert candidate(grid = [[1, 0, 1], [1, 1, 1]]) == 5\n assert candidate(grid = [[1, 1, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]]) == 12\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 0, 1, 0], [0, 1, 1, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 1], [0, 0, 0, 0, 1, 0, 0]]) == 25\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 42\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0], [0, 1, 1, 0, 0, 0, 1], [1, 0, 0, 1, 0, 1, 1]]) == 24\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1]]) == 37\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 36\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 51\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 0, 1, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0, 0, 1], [0, 0, 0, 1, 1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 1, 0]]) == 53\n assert candidate(grid = [[1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 26\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 27\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1]]) == 37\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 1]]) == 44\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0, 1, 1]]) == 48\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0]]) == 16\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 36\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1]]) == 30\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1], [0, 0, 0, 1, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1]]) == 22\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], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1]]) == 47\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]]) == 20\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [1, 0, 0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 1]]) == 52\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1]]) == 34\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0, 1, 0], [1, 0, 0, 0, 1, 0, 1, 0, 1], [0, 1, 1, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0, 1, 0]]) == 47\n assert candidate(grid = [[0, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0]]) == 24\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 45\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, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 43\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 1, 0, 1, 1, 1, 0], [0, 1, 1, 1, 0, 1, 1, 1, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 1, 0, 1, 1, 1, 0], [0, 1, 1, 1, 0, 1, 1, 1, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1]]) == 72\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 1]]) == 39\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 0, 1, 0], [1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 0, 1, 0]]) == 24\n assert candidate(grid = [[0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0]]) == 21\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 0, 1], [0, 0, 1, 0, 0, 1]]) == 25\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1, 1, 0], [1, 0, 0, 1, 0, 0, 0, 1]]) == 24\n assert candidate(grid = [[1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0], [1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1]]) == 37\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 1, 1]]) == 26\n assert candidate(grid = [[0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0]]) == 24\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0]]) == 12\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 20\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0], [1, 0, 0, 1, 0, 0, 1]]) == 24\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0, 1, 1]]) == 52\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1]]) == 52\n assert candidate(grid = [[1, 0, 0, 0, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0, 1, 0], [0, 1, 1, 0, 0, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1, 1, 0, 0, 0]]) == 31\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 0, 0, 0]]) == 20\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]]) == 25\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 1, 1, 0, 0]]) == 40\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 1]]) == 36\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]]) == 25\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0, 0], [0, 1, 0, 1, 1, 0, 1, 0, 0], [0, 1, 1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 38\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 44\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 67\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1], [1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 1, 1, 1, 0], [1, 1, 1, 0, 0, 0, 1]]) == 26\n assert candidate(grid = [[1, 1, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1, 0]]) == 22\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 0, 0, 0], [1, 1, 1, 0, 1, 1, 1], [0, 0, 0, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]) == 29\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], [1, 0, 1, 0, 1, 0, 1]]) == 33\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0], [1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0]]) == 36\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 0, 0]]) == 31\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 10\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1]]) == 26\n assert candidate(grid = [[1, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 1, 0, 0, 1, 0, 0], [0, 1, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 1, 0]]) == 28\n", "comparison": "exact"}, "public_tests": ["[[1,0,1],[1,1,1]]", "[[1,0,1,0],[0,1,0,1]]"], "hints": ["Consider covering using 2 rectangles. As the rectangles don’t overlap, one of the rectangles must either be vertically above or horizontally left to the other.", "To find the minimum area, check all possible vertical and horizontal splits.", "For 3 rectangles, extend the idea to first covering using one rectangle, and then try splitting leftover ones both horizontally and vertically."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:34+00:00", "tests_total": 62, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "matrix", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_sum(grid)", "container": null, "callable": "minimum_sum", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3200, "task_id": "maximum-height-of-a-triangle", "difficulty": "Easy", "problem_description": "You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1^st row will have 1 ball, the 2^nd row will have 2 balls, the 3^rd row will have 3 balls, and so on.\n\nAll the balls in a particular row should be the same color, and adjacent rows should have different colors.\n\nReturn the maximum height of the triangle that can be achieved.\n\nExample 1:\n\nInput: red = 2, blue = 4\nOutput: 3\nExplanation:\nThe only possible arrangement is shown above.\n\nExample 2:\n\nInput: red = 2, blue = 1\nOutput: 2\nExplanation:\nThe only possible arrangement is shown above.\n\nExample 3:\n\nInput: red = 1, blue = 1\nOutput: 1\n\nExample 4:\n\nInput: red = 10, blue = 1\nOutput: 2\nExplanation:\nThe only possible arrangement is shown above.\n\nConstraints:\n\n- 1 <= red, blue <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(red = 100,blue = 1) == 2\n assert candidate(red = 3,blue = 7) == 3\n assert candidate(red = 50,blue = 50) == 13\n assert candidate(red = 5,blue = 5) == 3\n assert candidate(red = 1,blue = 1) == 1\n assert candidate(red = 10,blue = 1) == 2\n assert candidate(red = 1,blue = 100) == 2\n assert candidate(red = 2,blue = 1) == 2\n assert candidate(red = 2,blue = 4) == 3\n assert candidate(red = 100,blue = 100) == 19\n assert candidate(red = 15,blue = 10) == 6\n assert candidate(red = 20,blue = 15) == 7\n assert candidate(red = 30,blue = 30) == 10\n assert candidate(red = 25,blue = 25) == 9\n assert candidate(red = 8,blue = 8) == 4\n assert candidate(red = 15,blue = 14) == 6\n assert candidate(red = 30,blue = 10) == 6\n assert candidate(red = 33,blue = 66) == 11\n assert candidate(red = 7,blue = 12) == 5\n assert candidate(red = 40,blue = 40) == 11\n assert candidate(red = 15,blue = 85) == 7\n assert candidate(red = 10,blue = 15) == 6\n assert candidate(red = 70,blue = 30) == 11\n assert candidate(red = 30,blue = 70) == 11\n assert candidate(red = 50,blue = 30) == 11\n assert candidate(red = 40,blue = 39) == 11\n assert candidate(red = 49,blue = 49) == 13\n assert candidate(red = 10,blue = 90) == 6\n assert candidate(red = 3,blue = 5) == 3\n assert candidate(red = 42,blue = 42) == 12\n assert candidate(red = 7,blue = 9) == 5\n assert candidate(red = 7,blue = 3) == 3\n assert candidate(red = 15,blue = 15) == 6\n assert candidate(red = 30,blue = 20) == 9\n assert candidate(red = 55,blue = 45) == 13\n assert candidate(red = 40,blue = 60) == 12\n assert candidate(red = 12,blue = 12) == 6\n assert candidate(red = 50,blue = 60) == 14\n assert candidate(red = 30,blue = 40) == 11\n assert candidate(red = 20,blue = 20) == 8\n assert candidate(red = 10,blue = 20) == 6\n assert candidate(red = 99,blue = 99) == 18\n assert candidate(red = 3,blue = 97) == 3\n assert candidate(red = 99,blue = 100) == 19\n assert candidate(red = 90,blue = 10) == 6\n assert candidate(red = 99,blue = 2) == 3\n assert candidate(red = 45,blue = 55) == 13\n assert candidate(red = 99,blue = 1) == 2\n assert candidate(red = 35,blue = 65) == 11\n assert candidate(red = 60,blue = 40) == 12\n assert candidate(red = 25,blue = 75) == 10\n assert candidate(red = 2,blue = 2) == 2\n assert candidate(red = 50,blue = 100) == 14\n assert candidate(red = 1,blue = 99) == 2\n assert candidate(red = 20,blue = 10) == 6\n assert candidate(red = 100,blue = 50) == 14\n assert candidate(red = 8,blue = 7) == 4\n assert candidate(red = 50,blue = 25) == 10\n assert candidate(red = 10,blue = 10) == 5\n assert candidate(red = 15,blue = 20) == 7\n assert candidate(red = 75,blue = 25) == 10\n assert candidate(red = 5,blue = 95) == 4\n assert candidate(red = 80,blue = 20) == 9\n assert candidate(red = 20,blue = 80) == 9\n assert candidate(red = 30,blue = 50) == 11\n assert candidate(red = 33,blue = 67) == 11\n assert candidate(red = 100,blue = 99) == 19\n", "comparison": "exact"}, "public_tests": ["2\n4", "2\n1", "1\n1", "10\n1"], "hints": ["Count the max height using both possibilities. That is, red ball as top and blue ball as top.", "For counting the max height, use a simple for loop and remove the number of balls required at this level."], "metadata": {"canonical_parameter_names": ["red", "blue"], "leetcode_dataset_entry_point": "Solution().maxHeightOfTriangle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:39+00:00", "tests_total": 67, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def max_height_of_triangle(red, blue)", "container": null, "callable": "max_height_of_triangle", "parameters": [{"name": "red", "type": "Integer"}, {"name": "blue", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3201, "task_id": "find-the-maximum-length-of-valid-subsequence-i", "difficulty": "Medium", "problem_description": "You are given an integer array nums.\n\nA subsequence sub of nums with length x is called valid if it satisfies:\n\n- (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.\n\nReturn the length of the longest valid subsequence of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 4\nExplanation:\nThe longest valid subsequence is [1, 2, 3, 4].\n\nExample 2:\n\nInput: nums = [1,2,1,1,2,1,2]\nOutput: 6\nExplanation:\nThe longest valid subsequence is [1, 2, 1, 2, 1, 2].\n\nExample 3:\n\nInput: nums = [1,3]\nOutput: 2\nExplanation:\nThe longest valid subsequence is [1, 3].\n\nConstraints:\n\n- 2 <= nums.length <= 2 * 10^5\n- 1 <= nums[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums = [1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 2, 1, 1, 2, 1, 2]) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 6\n assert candidate(nums = [1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 6\n assert candidate(nums = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062, 19531]) == 8\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 3]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == 6\n assert candidate(nums = [2, 2, 2, 2]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 8\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [10000000, 1, 10000000, 1]) == 4\n assert candidate(nums = [2, 2, 2, 2, 2]) == 5\n assert candidate(nums = [2, 4, 6, 8]) == 4\n assert candidate(nums = [107, 106, 105, 104, 103, 102, 101, 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]) == 107\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 16\n assert candidate(nums = [10000000, 9999999, 10000000, 9999999, 10000000, 9999999, 10000000, 9999999, 10000000, 9999999]) == 10\n assert candidate(nums = [9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1]) == 20\n assert candidate(nums = [10000000, 9999999, 10000000, 9999999, 10000000, 9999999, 10000000, 9999999]) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 15\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23]) == 9\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 15\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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]) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 15\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 11\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 18\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84]) == 12\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 12\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 20\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 16\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2]) == 14\n assert candidate(nums = [2, 1, 3, 4, 3, 5, 2, 4, 3, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == 10\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 11\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 20\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 14\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 6\n assert candidate(nums = [9999999, 10000000, 9999999, 10000000, 9999999, 10000000]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 12\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 19\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]) == 25\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 12\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1]) == 11\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 20\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6]) == 12\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990, 9999989, 9999988, 9999987, 9999986, 9999985, 9999984, 9999983, 9999982, 9999981, 9999980, 9999979, 9999978, 9999977, 9999976, 9999975, 9999974, 9999973, 9999972, 9999971, 9999970, 9999969, 9999968, 9999967, 9999966, 9999965, 9999964, 9999963, 9999962, 9999961, 9999960, 9999959, 9999958, 9999957, 9999956, 9999955, 9999954, 9999953, 9999952, 9999951, 9999950, 9999949, 9999948, 9999947, 9999946, 9999945, 9999944, 9999943, 9999942, 9999941, 9999940, 9999939, 9999938, 9999937, 9999936, 9999935, 9999934, 9999933, 9999932, 9999931, 9999930, 9999929, 9999928, 9999927, 9999926, 9999925, 9999924, 9999923, 9999922, 9999921, 9999920]) == 81\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 14\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 30\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [5, 3, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 15\n assert candidate(nums = [1, 4, 3, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 10\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1, 6, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(nums = [2, 1, 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]) == 10\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 20\n assert candidate(nums = [9999999, 10000000, 9999999, 10000000, 9999999, 10000000, 9999999, 10000000, 9999999, 10000000]) == 10\n assert candidate(nums = [1000000, 1000001, 1000002, 1000001, 1000000, 1000001, 1000002]) == 7\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]) == 14\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 17\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 20\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 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]) == 20\n assert candidate(nums = [10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1]) == 10\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 1, 3, 5, 2, 4, 6, 1, 3, 5, 2, 4, 6, 1, 3]) == 11\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 10\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 8, 10, 12, 14]) == 7\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(nums = [107, 208, 309, 410, 511, 612, 713, 814, 915, 1016]) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == 11\n assert candidate(nums = [1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4]) == 10\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11]) == 15\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 15\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 10\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[1,2,1,1,2,1,2]", "[1,3]"], "hints": ["The possible sequence either contains all even elements, all odd elements, alternate even odd, or alternate odd even elements.", "Considering only the parity of elements, there are only 4 possibilities and we can try all of them.", "When selecting an element with any parity, try to select the earliest one."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:41+00:00", "tests_total": 115, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(nums)", "container": null, "callable": "maximum_length", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3202, "task_id": "find-the-maximum-length-of-valid-subsequence-ii", "difficulty": "Medium", "problem_description": "You are given an integer array nums and a positive integer k.\n\nA subsequence sub of nums with length x is called valid if it satisfies:\n\n- (sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k.\n\nReturn the length of the longest valid subsequence of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], k = 2\nOutput: 5\nExplanation:\nThe longest valid subsequence is [1, 2, 3, 4, 5].\n\nExample 2:\n\nInput: nums = [1,4,2,3,1,4], k = 3\nOutput: 4\nExplanation:\nThe longest valid subsequence is [1, 4, 1, 4].\n\nConstraints:\n\n- 2 <= nums.length <= 10^3\n- 1 <= nums[i] <= 10^7\n- 1 <= k <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 6, 8, 10],k = 4) == 3\n assert candidate(nums = [1, 4, 2, 3, 1, 4],k = 3) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 5\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3, 1],k = 2) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12],k = 4) == 6\n assert candidate(nums = [5, 10, 15, 20, 25],k = 5) == 5\n assert candidate(nums = [2, 4, 6, 8, 10],k = 4) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 5\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3],k = 2) == 7\n assert candidate(nums = [1, 3, 5, 7, 9],k = 2) == 5\n assert candidate(nums = [2, 3, 5, 8, 13, 21],k = 2) == 4\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],k = 2) == 7\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1],k = 3) == 7\n assert candidate(nums = [2, 4, 6, 8, 10],k = 2) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11],k = 2) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],k = 3) == 4\n assert candidate(nums = [3, 6, 9, 12, 15],k = 3) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 5\n assert candidate(nums = [7, 14, 21, 28, 35],k = 7) == 5\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],k = 7) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 6) == 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],k = 11) == 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],k = 3) == 8\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 5) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 2) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 3) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 7\n assert candidate(nums = [123, 246, 369, 492, 615, 738, 861, 984, 1107, 1230],k = 123) == 10\n assert candidate(nums = [1, 6, 3, 8, 5, 10, 7, 12, 9, 14, 11, 16, 13, 18, 15, 20],k = 5) == 4\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 12) == 8\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31],k = 3) == 14\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1000],k = 101) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 3) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 10) == 10\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225],k = 10) == 4\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 13) == 10\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143],k = 13) == 11\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 10) == 10\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120],k = 15) == 8\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 10\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 5) == 11\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 = 13) == 6\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164, 175, 186, 197, 208, 219, 230, 241, 252, 263, 274, 285, 296, 307, 318, 329],k = 11) == 30\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],k = 2) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 10\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 5) == 4\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55],k = 5) == 4\n assert candidate(nums = [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],k = 7) == 10\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 3) == 15\n assert candidate(nums = [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],k = 3) == 17\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987],k = 10) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 10\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91],k = 7) == 13\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],k = 3) == 20\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 5) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 10) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 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],k = 2) == 10\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 3) == 10\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],k = 9) == 11\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],k = 8) == 10\n assert candidate(nums = [2, 11, 20, 29, 38, 47, 56, 65, 74, 83, 92],k = 9) == 11\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 6\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 272, 289],k = 17) == 17\n assert candidate(nums = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 4) == 11\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015],k = 14) == 4\n assert candidate(nums = [1, 13, 25, 37, 49, 61, 73, 85, 97, 109, 121, 133, 145, 157, 169, 181, 193],k = 12) == 17\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152],k = 17) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 5\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120],k = 3) == 10\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],k = 2) == 21\n assert candidate(nums = [2, 5, 9, 14, 20, 27, 35, 44, 54, 65, 77, 90, 104, 119, 135, 152, 170, 189, 209, 230],k = 7) == 7\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],k = 7) == 14\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204],k = 17) == 12\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43],k = 3) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 10\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39],k = 3) == 13\n assert candidate(nums = [2, 5, 11, 23, 47, 95, 191, 383, 767, 1535, 3071, 6143, 12287, 24575, 49151],k = 11) == 4\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115],k = 13) == 4\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10],k = 3) == 13\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946],k = 15) == 4\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180],k = 12) == 15\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45],k = 5) == 8\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],k = 12) == 10\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) == 10\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 9) == 10\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15, 14, 16, 15, 17, 16, 18, 17, 19, 18, 20],k = 5) == 15\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155],k = 15) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 6\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 10) == 5\n assert candidate(nums = [3, 1, 7, 5, 9, 11, 13, 15, 17, 19],k = 6) == 6\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 9) == 10\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],k = 7) == 15\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],k = 1) == 12\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65],k = 7) == 4\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 9) == 10\n assert candidate(nums = [456, 912, 1368, 1824, 2280, 2736, 3192, 3648, 4104, 4560],k = 456) == 10\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049],k = 4) == 11\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 2) == 10\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80],k = 4) == 20\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135],k = 9) == 15\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 7) == 4\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112],k = 8) == 14\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 5) == 12\n assert candidate(nums = [25, 35, 45, 55, 65, 75, 85, 95, 105],k = 10) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 7\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 10\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 5) == 4\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 7) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 5) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 6\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],k = 7) == 14\n assert candidate(nums = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144],k = 7) == 3\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],k = 7) == 5\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 11) == 10\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994],k = 1000) == 2\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],k = 7) == 6\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]\n2", "[1,4,2,3,1,4]\n3"], "hints": ["Fix the value of (subs[0] + subs[1]) % k from the k possible values. Let it be val.", "Let dp[i] store the maximum length of a subsequence with its last element x such that x % k == i.", "Answer for a subsequence ending at index y is dp[(k + val - (y % k)) % k] + 1."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:44+00:00", "tests_total": 125, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_length(nums, k)", "container": null, "callable": "maximum_length", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3203, "task_id": "find-minimum-diameter-after-merging-two-trees", "difficulty": "Hard", "problem_description": "There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the first tree and edges2[i] = [u_i, v_i] indicates that there is an edge between nodes u_i and v_i in the second tree.\n\nYou must connect one node from the first tree with another node from the second tree with an edge.\n\nReturn the minimum possible diameter of the resulting tree.\n\nThe diameter of a tree is the length of the longest path between any two nodes in the tree.\n\nExample 1:\n\nInput: edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]]\nOutput: 3\nExplanation:\nWe can obtain a tree of diameter 3 by connecting node 0 from the first tree with any node from the second tree.\n\nExample 2:\n\nInput: edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]\nOutput: 5\nExplanation:\nWe can obtain a tree of diameter 5 by connecting node 0 from the first tree with node 0 from the second tree.\n\nConstraints:\n\n- 1 <= n, m <= 10^5\n- edges1.length == n - 1\n- edges2.length == m - 1\n- edges1[i].length == edges2[i].length == 2\n- edges1[i] = [a_i, b_i]\n- 0 <= a_i, b_i < n\n- edges2[i] = [u_i, v_i]\n- 0 <= u_i, v_i < m\n- The input is generated such that edges1 and edges2 represent valid trees.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 6\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3]],edges2 = [[0, 1]]) == 3\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [2, 4], [2, 5], [3, 6], [2, 7]],edges2 = [[0, 1], [0, 2], [0, 3], [2, 4], [2, 5], [3, 6], [2, 7]]) == 5\n assert candidate(edges1 = [[0, 1]],edges2 = [[0, 1]]) == 3\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4]],edges2 = [[0, 1], [0, 2], [1, 3], [2, 4]]) == 5\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 11\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 15\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 8\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],edges2 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10]]) == 6\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 9\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 10\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 14\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22]]) == 22\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 20\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16]]) == 17\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30]]) == 31\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 14\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 15\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],edges2 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]]) == 7\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 11\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 19\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 14\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(edges1 = [[0, 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]],edges2 = [[0, 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], [10, 18], [11, 19], [12, 20]]) == 8\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == 15\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 13\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [7, 8], [8, 9], [9, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 11\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],edges2 = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]]) == 6\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 9\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],edges2 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == 7\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 14\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]],edges2 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [7, 8], [8, 9], [9, 10]]) == 10\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17]]) == 17\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 12\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 10\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25]]) == 26\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25]]) == 25\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [11, 23], [12, 24], [13, 25], [14, 26], [15, 27], [16, 28], [17, 29], [18, 30], [19, 31], [20, 32], [21, 33], [22, 34], [23, 35], [24, 36], [25, 37], [26, 38], [27, 39], [28, 40], [29, 41], [30, 42], [31, 43], [32, 44], [33, 45]],edges2 = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [11, 23], [12, 24], [13, 25], [14, 26], [15, 27], [16, 28], [17, 29], [18, 30], [19, 31], [20, 32], [21, 33], [22, 34], [23, 35], [24, 36], [25, 37], [26, 38], [27, 39], [28, 40], [29, 41], [30, 42], [31, 43], [32, 44], [33, 45], [34, 46], [35, 47], [36, 48], [37, 49], [38, 50], [39, 51], [40, 52], [41, 53], [42, 54], [43, 55], [44, 56], [45, 57]]) == 12\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 21\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31]]) == 31\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 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]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31]]) == 31\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24]]) == 24\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35]]) == 36\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == 15\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32]]) == 32\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [7, 8], [8, 9], [9, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 14\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 10\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == 13\n assert candidate(edges1 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26]]) == 27\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],edges2 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]]) == 6\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],edges2 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 12]]) == 7\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [6, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 20\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27]]) == 27\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]],edges2 = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14]]) == 11\n assert candidate(edges1 = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]],edges2 = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [11, 23], [12, 24], [13, 25], [14, 26], [15, 27], [16, 28], [17, 29], [18, 30], [19, 31], [20, 32], [21, 33]]) == 8\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],edges2 = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7]]) == 6\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [5, 8]],edges2 = [[0, 1], [0, 2], [1, 3], [2, 4], [4, 5], [4, 6], [5, 7]]) == 7\n assert candidate(edges1 = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [5, 8], [6, 9], [6, 10]],edges2 = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 8\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,2],[0,3]]\n[[0,1]]", "[[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]\n[[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]"], "hints": ["Suppose that we connected node a in tree1 with node b in tree2. The diameter length of the resulting tree will be the largest of the following 3 values:\n1. The diameter of tree 1.\n2. The diameter of tree 2.\n3. The length of the longest path that starts at node a and that is completely within Tree 1 + The length of the longest path that starts at node b and that is completely within Tree 2 + 1.\n\nThe added one in the third value is due to the additional edge that we have added between trees 1 and 2.", "Values 1 and 2 are constant regardless of our choice of a and b. Therefore, we need to pick a and b in such a way that minimizes value 3.", "If we pick a and b optimally, they will be in the diameters of Tree 1 and Tree 2, respectively. Exactly which nodes of the diameter should we pick?", "a is the center of the diameter of tree 1, and b is the center of the diameter of tree 2."], "metadata": {"canonical_parameter_names": ["edges1", "edges2"], "leetcode_dataset_entry_point": "Solution().minimumDiameterAfterMerge", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:47+00:00", "tests_total": 60, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["tree", "depth-first-search", "breadth-first-search", "graph"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_diameter_after_merge(edges1, edges2)", "container": null, "callable": "minimum_diameter_after_merge", "parameters": [{"name": "edges1", "type": "Integer[][]"}, {"name": "edges2", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3206, "task_id": "alternating-groups-i", "difficulty": "Easy", "problem_description": "There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]:\n\n- colors[i] == 0 means that tile i is red.\n- colors[i] == 1 means that tile i is blue.\n\nEvery 3 contiguous tiles in the circle with alternating colors (the middle tile has a different color from its left and right tiles) is called an alternating group.\n\nReturn the number of alternating groups.\n\nNote that since colors represents a circle, the first and the last tiles are considered to be next to each other.\n\nExample 1:\n\nInput: colors = [1,1,1]\nOutput: 0\nExplanation:\n\nExample 2:\n\nInput: colors = [0,1,0,0,1]\nOutput: 3\nExplanation:\nAlternating groups:\n\nConstraints:\n\n- 3 <= colors.length <= 100\n- 0 <= colors[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(colors = [1, 1, 1, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(colors = [1, 0, 0, 0, 1, 1, 1, 0]) == 2\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == 7\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1]) == 1\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0]) == 0\n assert candidate(colors = [0, 1, 1, 0, 0, 1]) == 2\n assert candidate(colors = [0, 1, 0, 1, 0]) == 3\n assert candidate(colors = [1, 1, 0, 1, 1, 0, 1]) == 2\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1]) == 5\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1]) == 4\n assert candidate(colors = [1, 0, 0, 1, 1, 0]) == 2\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 1]) == 3\n assert candidate(colors = [1, 1, 1]) == 0\n assert candidate(colors = [1, 1, 0, 1, 0, 1]) == 3\n assert candidate(colors = [0, 1, 0, 1, 1, 0, 1, 0, 1]) == 7\n assert candidate(colors = [1, 0, 0, 1, 0, 0, 1, 0, 0]) == 3\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0]) == 0\n assert candidate(colors = [0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [1, 1, 0, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [1, 0, 1, 0, 1]) == 3\n assert candidate(colors = [0, 1, 0, 0, 1]) == 3\n assert candidate(colors = [1, 0, 1, 0, 1, 0]) == 6\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1]) == 7\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(colors = [1, 0, 0, 1, 0, 1, 1, 0, 1]) == 3\n assert candidate(colors = [1, 0, 0, 1, 0, 0, 1, 0]) == 4\n assert candidate(colors = [1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0]) == 6\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1]) == 10\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 20\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 9\n assert candidate(colors = [1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 3\n assert candidate(colors = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(colors = [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]) == 26\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [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, 1, 0, 1, 0]) == 32\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 15\n assert candidate(colors = [1, 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, 1, 0, 1, 0]) == 31\n assert candidate(colors = [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0]) == 6\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 8\n assert candidate(colors = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1]) == 0\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 14\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0]) == 12\n assert candidate(colors = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(colors = [0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1]) == 15\n assert candidate(colors = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == 11\n assert candidate(colors = [0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 12\n assert candidate(colors = [1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 20\n assert candidate(colors = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == 0\n assert candidate(colors = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == 9\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 19\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 12\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 13\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 5\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 19\n assert candidate(colors = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1]) == 1\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(colors = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 0\n assert candidate(colors = [1, 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, 1]) == 27\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 0\n assert candidate(colors = [1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1]) == 3\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 16\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0]) == 6\n assert candidate(colors = [1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0]) == 9\n assert candidate(colors = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]) == 7\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 12\n assert candidate(colors = [1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]) == 13\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == 5\n assert candidate(colors = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 1\n assert candidate(colors = [1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 20\n assert candidate(colors = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0]) == 7\n assert candidate(colors = [0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 3\n assert candidate(colors = [1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1]) == 8\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(colors = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(colors = [1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]) == 15\n assert candidate(colors = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 9\n assert candidate(colors = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 6\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 11\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 15\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]) == 0\n assert candidate(colors = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == 13\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == 9\n assert candidate(colors = [0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 11\n assert candidate(colors = [1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1]) == 11\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 11\n assert candidate(colors = [1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0]) == 9\n assert candidate(colors = [1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0]) == 13\n assert candidate(colors = [1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 1\n assert candidate(colors = [1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1]) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 10\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(colors = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0]) == 4\n assert candidate(colors = [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]) == 23\n assert candidate(colors = [0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1]) == 9\n assert candidate(colors = [0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 1\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 20\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 12\n assert candidate(colors = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0]) == 0\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 9\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 24\n assert candidate(colors = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0]) == 10\n assert candidate(colors = [1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == 4\n assert candidate(colors = [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1]) == 12\n assert candidate(colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(colors = [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1]) == 4\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 15\n assert candidate(colors = [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 2\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 18\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 13\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0]) == 9\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(colors = [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, 1, 0, 1, 0, 1]) == 32\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(colors = [0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1]) == 6\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0]) == 7\n assert candidate(colors = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]) == 2\n assert candidate(colors = [1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 1\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 1\n assert candidate(colors = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 1\n assert candidate(colors = [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1]) == 7\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(colors = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]) == 9\n", "comparison": "exact"}, "public_tests": ["[1,1,1]", "[0,1,0,0,1]"], "hints": ["For each tile, check that the previous and the next tile have different colors from that tile or not."], "metadata": {"canonical_parameter_names": ["colors"], "leetcode_dataset_entry_point": "Solution().numberOfAlternatingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:51+00:00", "tests_total": 131, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_alternating_groups(colors)", "container": null, "callable": "number_of_alternating_groups", "parameters": [{"name": "colors", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3207, "task_id": "maximum-points-after-enemy-battles", "difficulty": "Medium", "problem_description": "You are given an integer array enemyEnergies denoting the energy values of various enemies.\n\nYou are also given an integer currentEnergy denoting the amount of energy you have initially.\n\nYou start with 0 points, and all the enemies are unmarked initially.\n\nYou can perform either of the following operations zero or multiple times to gain points:\n\n- Choose an unmarked enemy, i, such that currentEnergy >= enemyEnergies[i]. By choosing this option:\n - You gain 1 point.\n - Your energy is reduced by the enemy's energy, i.e. currentEnergy = currentEnergy - enemyEnergies[i].\n- If you have at least 1 point, you can choose an unmarked enemy, i. By choosing this option:\n - Your energy increases by the enemy's energy, i.e. currentEnergy = currentEnergy + enemyEnergies[i].\n - The enemy i is marked.\n\nReturn an integer denoting the maximum points you can get in the end by optimally performing operations.\n\nExample 1:\n\nInput: enemyEnergies = [3,2,2], currentEnergy = 2\nOutput: 3\nExplanation:\nThe following operations can be performed to get 3 points, which is the maximum:\n- First operation on enemy 1: points increases by 1, and currentEnergy decreases by 2. So, points = 1, and currentEnergy = 0.\n- Second operation on enemy 0: currentEnergy increases by 3, and enemy 0 is marked. So, points = 1, currentEnergy = 3, and marked enemies = [0].\n- First operation on enemy 2: points increases by 1, and currentEnergy decreases by 2. So, points = 2, currentEnergy = 1, and marked enemies = [0].\n- Second operation on enemy 2: currentEnergy increases by 2, and enemy 2 is marked. So, points = 2, currentEnergy = 3, and marked enemies = [0, 2].\n- First operation on enemy 1: points increases by 1, and currentEnergy decreases by 2. So, points = 3, currentEnergy = 1, and marked enemies = [0, 2].\n\nExample 2:\n\nInput: enemyEnergies = [2], currentEnergy = 10\nOutput: 5\nExplanation:\nPerforming the first operation 5 times on enemy 0 results in the maximum number of points.\n\nConstraints:\n\n- 1 <= enemyEnergies.length <= 10^5\n- 1 <= enemyEnergies[i] <= 10^9\n- 0 <= currentEnergy <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1],currentEnergy = 1) == 5\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5],currentEnergy = 15) == 7\n assert candidate(enemyEnergies = [2],currentEnergy = 10) == 5\n assert candidate(enemyEnergies = [1],currentEnergy = 0) == 0\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],currentEnergy = 25) == 14\n assert candidate(enemyEnergies = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 55) == 109\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],currentEnergy = 55) == 109\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5],currentEnergy = 15) == 29\n assert candidate(enemyEnergies = [3, 2, 2],currentEnergy = 2) == 3\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],currentEnergy = 5) == 14\n assert candidate(enemyEnergies = [10, 20, 30],currentEnergy = 5) == 0\n assert candidate(enemyEnergies = [1000000000],currentEnergy = 1000000000) == 1\n assert candidate(enemyEnergies = [10, 10, 10, 10, 10],currentEnergy = 50) == 9\n assert candidate(enemyEnergies = [5, 4, 3, 2, 1],currentEnergy = 15) == 29\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1],currentEnergy = 5) == 9\n assert candidate(enemyEnergies = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 5) == 59\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],currentEnergy = 1) == 55\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5],currentEnergy = 10) == 24\n assert candidate(enemyEnergies = [10, 20, 30],currentEnergy = 15) == 6\n assert candidate(enemyEnergies = [10, 20, 30, 40, 50],currentEnergy = 100) == 24\n assert candidate(enemyEnergies = [100, 200, 300, 400, 500],currentEnergy = 150) == 15\n assert candidate(enemyEnergies = [100, 200, 300, 400, 500],currentEnergy = 100) == 15\n assert candidate(enemyEnergies = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],currentEnergy = 10) == 53\n assert candidate(enemyEnergies = [100, 200, 300, 400, 500],currentEnergy = 250) == 16\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],currentEnergy = 100) == 219\n assert candidate(enemyEnergies = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 10) == 64\n assert candidate(enemyEnergies = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],currentEnergy = 99) == 18\n assert candidate(enemyEnergies = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],currentEnergy = 10) == 39\n assert candidate(enemyEnergies = [100, 200, 300, 400, 500],currentEnergy = 1000) == 24\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],currentEnergy = 100) == 29\n assert candidate(enemyEnergies = [30, 20, 10, 5, 2, 1],currentEnergy = 20) == 87\n assert candidate(enemyEnergies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],currentEnergy = 55) == 59\n assert candidate(enemyEnergies = [1, 10, 100, 1000, 10000],currentEnergy = 5000) == 16110\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],currentEnergy = 15) == 29\n assert candidate(enemyEnergies = [9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 15) == 59\n assert candidate(enemyEnergies = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],currentEnergy = 10) == 17\n assert candidate(enemyEnergies = [1, 10, 100, 1000, 10000],currentEnergy = 10000) == 21110\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],currentEnergy = 1) == 55\n assert candidate(enemyEnergies = [2, 3, 5, 7, 11, 13, 17, 19],currentEnergy = 50) == 62\n assert candidate(enemyEnergies = [1000000000, 500000000, 250000000],currentEnergy = 1000000000) == 10\n assert candidate(enemyEnergies = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],currentEnergy = 15) == 44\n assert candidate(enemyEnergies = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],currentEnergy = 100) == 19\n assert candidate(enemyEnergies = [5, 3, 1, 2, 4, 6],currentEnergy = 3) == 23\n assert candidate(enemyEnergies = [9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 45) == 89\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],currentEnergy = 5) == 14\n assert candidate(enemyEnergies = [5, 4, 3, 2, 1],currentEnergy = 15) == 29\n assert candidate(enemyEnergies = [5, 3, 8, 2, 10],currentEnergy = 7) == 16\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],currentEnergy = 0) == 0\n assert candidate(enemyEnergies = [5, 3, 7, 2, 8, 1, 4],currentEnergy = 10) == 39\n assert candidate(enemyEnergies = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],currentEnergy = 27) == 18\n assert candidate(enemyEnergies = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],currentEnergy = 15) == 58\n assert candidate(enemyEnergies = [5, 3, 8, 6, 2, 7],currentEnergy = 10) == 19\n assert candidate(enemyEnergies = [1, 3, 5, 7, 9],currentEnergy = 20) == 44\n assert candidate(enemyEnergies = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],currentEnergy = 25) == 66\n assert candidate(enemyEnergies = [10, 5, 15, 20, 25, 30, 35, 40, 45, 50],currentEnergy = 50) == 64\n assert candidate(enemyEnergies = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],currentEnergy = 10) == 10\n assert candidate(enemyEnergies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],currentEnergy = 50) == 59\n assert candidate(enemyEnergies = [5, 3, 6, 2, 8, 1],currentEnergy = 10) == 34\n assert candidate(enemyEnergies = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],currentEnergy = 10) == 109\n assert candidate(enemyEnergies = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],currentEnergy = 500000000) == 1278\n assert candidate(enemyEnergies = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],currentEnergy = 2500) == 79\n assert candidate(enemyEnergies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],currentEnergy = 10) == 55\n assert candidate(enemyEnergies = [100, 200, 300, 400, 500],currentEnergy = 500) == 19\n assert candidate(enemyEnergies = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],currentEnergy = 1024) == 3070\n assert candidate(enemyEnergies = [9, 7, 5, 3, 1],currentEnergy = 15) == 39\n assert candidate(enemyEnergies = [1000000000, 500000000, 250000000, 125000000, 62500000],currentEnergy = 1000000000) == 46\n assert candidate(enemyEnergies = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],currentEnergy = 5) == 0\n assert candidate(enemyEnergies = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],currentEnergy = 50) == 109\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],currentEnergy = 15) == 69\n assert candidate(enemyEnergies = [50, 25, 75, 100, 200, 300, 400],currentEnergy = 100) == 49\n assert candidate(enemyEnergies = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],currentEnergy = 21) == 12\n assert candidate(enemyEnergies = [50, 25, 75, 100, 200, 150],currentEnergy = 125) == 28\n assert candidate(enemyEnergies = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],currentEnergy = 1) == 0\n assert candidate(enemyEnergies = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],currentEnergy = 10) == 14\n assert candidate(enemyEnergies = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 1) == 55\n assert candidate(enemyEnergies = [5, 3, 8, 1, 9],currentEnergy = 10) == 35\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],currentEnergy = 100) == 309\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],currentEnergy = 25) == 24\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5],currentEnergy = 15) == 29\n assert candidate(enemyEnergies = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],currentEnergy = 100) == 113\n assert candidate(enemyEnergies = [9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 20) == 64\n assert candidate(enemyEnergies = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],currentEnergy = 1000) == 2993\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],currentEnergy = 10) == 64\n assert candidate(enemyEnergies = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20],currentEnergy = 100) == 14\n assert candidate(enemyEnergies = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],currentEnergy = 1023) == 2045\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],currentEnergy = 55) == 109\n assert candidate(enemyEnergies = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],currentEnergy = 1024) == 2046\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],currentEnergy = 100) == 119\n assert candidate(enemyEnergies = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],currentEnergy = 100) == 368\n assert candidate(enemyEnergies = [5, 5, 5, 5, 5],currentEnergy = 15) == 7\n assert candidate(enemyEnergies = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],currentEnergy = 50) == 79\n assert candidate(enemyEnergies = [10, 20, 30, 40, 50],currentEnergy = 30) == 17\n assert candidate(enemyEnergies = [1, 2, 3, 4, 5],currentEnergy = 10) == 24\n assert candidate(enemyEnergies = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],currentEnergy = 20) == 63\n assert candidate(enemyEnergies = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],currentEnergy = 100) == 64\n assert candidate(enemyEnergies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],currentEnergy = 10) == 19\n assert candidate(enemyEnergies = [9, 8, 7, 6, 5, 4, 3, 2, 1],currentEnergy = 5) == 49\n assert candidate(enemyEnergies = [100, 200, 300],currentEnergy = 1000) == 15\n assert candidate(enemyEnergies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],currentEnergy = 500) == 104\n assert candidate(enemyEnergies = [3, 2, 2, 4, 1, 5],currentEnergy = 6) == 22\n assert candidate(enemyEnergies = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],currentEnergy = 100) == 199\n assert candidate(enemyEnergies = [10, 15, 20, 25, 30, 35, 40, 45, 50],currentEnergy = 100) == 36\n", "comparison": "exact"}, "public_tests": ["[3,2,2]\n2", "[2]\n10"], "hints": ["The problem can be solved greedily.", "Mark all the others except the smallest one first.", "Use the smallest one to increase the energy.", "Note that the initial energy should be no less than the smallest enemy."], "metadata": {"canonical_parameter_names": ["enemyEnergies", "currentEnergy"], "leetcode_dataset_entry_point": "Solution().maximumPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:54+00:00", "tests_total": 104, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_points(enemy_energies, current_energy)", "container": null, "callable": "maximum_points", "parameters": [{"name": "enemy_energies", "type": "Integer[]"}, {"name": "current_energy", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3208, "task_id": "alternating-groups-ii", "difficulty": "Medium", "problem_description": "There is a circle of red and blue tiles. You are given an array of integers colors and an integer k. The color of tile i is represented by colors[i]:\n\n- colors[i] == 0 means that tile i is red.\n- colors[i] == 1 means that tile i is blue.\n\nAn alternating group is every k contiguous tiles in the circle with alternating colors (each tile in the group except the first and last one has a different color from its left and right tiles).\n\nReturn the number of alternating groups.\n\nNote that since colors represents a circle, the first and the last tiles are considered to be next to each other.\n\nExample 1:\n\nInput: colors = [0,1,0,1,0], k = 3\nOutput: 3\nExplanation:\nAlternating groups:\n\nExample 2:\n\nInput: colors = [0,1,0,0,1,0,1], k = 6\nOutput: 2\nExplanation:\nAlternating groups:\n\nExample 3:\n\nInput: colors = [1,1,0,1], k = 4\nOutput: 0\nExplanation:\n\nConstraints:\n\n- 3 <= colors.length <= 10^5\n- 0 <= colors[i] <= 1\n- 3 <= k <= colors.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(colors = [1, 1, 0, 1],k = 4) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0],k = 3) == 8\n assert candidate(colors = [0, 1, 0, 0, 1, 0, 1],k = 6) == 2\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 7\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 4) == 0\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1],k = 4) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 6) == 12\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0],k = 4) == 8\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1],k = 5) == 0\n assert candidate(colors = [0, 1, 0, 1, 0],k = 3) == 3\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 5\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 7) == 5\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 10) == 22\n assert candidate(colors = [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 = 13) == 24\n assert candidate(colors = [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 = 5) == 26\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 7) == 12\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 22\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 10) == 18\n assert candidate(colors = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 6) == 0\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 6) == 0\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 20\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 5) == 20\n assert candidate(colors = [0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],k = 6) == 2\n assert candidate(colors = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0],k = 6) == 0\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 4) == 0\n assert candidate(colors = [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, 1, 0, 1, 0, 1, 0],k = 12) == 34\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 7) == 16\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 8) == 0\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1],k = 4) == 0\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0],k = 4) == 3\n assert candidate(colors = [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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 20) == 46\n assert candidate(colors = [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, 1],k = 15) == 28\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 6) == 0\n assert candidate(colors = [1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1],k = 5) == 0\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 6) == 0\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 12) == 0\n assert candidate(colors = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0],k = 5) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 8) == 16\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 16\n assert candidate(colors = [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 = 7) == 21\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0],k = 6) == 0\n assert candidate(colors = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 12) == 0\n assert candidate(colors = [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, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 15) == 59\n assert candidate(colors = [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, 1, 0, 1, 0, 1],k = 11) == 32\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 8) == 14\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 8) == 4\n assert candidate(colors = [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, 1, 0, 1, 0, 1, 0, 1, 0],k = 11) == 25\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 10) == 0\n assert candidate(colors = [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1],k = 5) == 3\n assert candidate(colors = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],k = 7) == 0\n assert candidate(colors = [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, 1, 0],k = 10) == 30\n assert candidate(colors = [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, 1, 0],k = 9) == 30\n assert candidate(colors = [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, 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, 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, 1, 0, 1, 0, 1, 0],k = 20) == 70\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1],k = 9) == 0\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 12\n assert candidate(colors = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1],k = 4) == 0\n assert candidate(colors = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1],k = 5) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 4) == 8\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 8) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 5) == 10\n assert candidate(colors = [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],k = 11) == 26\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0],k = 9) == 0\n assert candidate(colors = [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, 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, 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, 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, 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],k = 25) == 138\n assert candidate(colors = [0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 6) == 14\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 5) == 0\n assert candidate(colors = [0, 1, 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, 1],k = 10) == 22\n assert candidate(colors = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0],k = 9) == 0\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 8) == 0\n assert candidate(colors = [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],k = 10) == 18\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 14) == 0\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 1, 0, 1, 0],k = 5) == 4\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1],k = 8) == 0\n assert candidate(colors = [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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 20) == 20\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 11\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 10) == 14\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 9\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 7) == 7\n assert candidate(colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == 0\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 11) == 20\n assert candidate(colors = [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 = 11) == 17\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],k = 4) == 5\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 6) == 20\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 7) == 12\n assert candidate(colors = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 5) == 0\n assert candidate(colors = [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, 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, 1, 0, 1],k = 8) == 52\n assert candidate(colors = [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, 1, 0, 1, 0, 1],k = 15) == 19\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 7) == 17\n assert candidate(colors = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 5\n assert candidate(colors = [0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0],k = 5) == 4\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 16\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1],k = 13) == 0\n assert candidate(colors = [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, 1, 0, 1, 0],k = 8) == 32\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 10\n assert candidate(colors = [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],k = 12) == 26\n assert candidate(colors = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 6) == 6\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 11) == 20\n assert candidate(colors = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 4) == 0\n assert candidate(colors = [0, 1, 0, 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 6) == 44\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0],k = 6) == 0\n assert candidate(colors = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],k = 6) == 0\n assert candidate(colors = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 7) == 20\n assert candidate(colors = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1],k = 4) == 4\n", "comparison": "exact"}, "public_tests": ["[0,1,0,1,0]\n3", "[0,1,0,0,1,0,1]\n6", "[1,1,0,1]\n4"], "hints": ["Try to find a tile that has the same color as its next tile (if it exists).", "Then try to find maximal alternating groups by starting a single for loop from that tile."], "metadata": {"canonical_parameter_names": ["colors", "k"], "leetcode_dataset_entry_point": "Solution().numberOfAlternatingGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:56+00:00", "tests_total": 103, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "sliding-window"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_alternating_groups(colors, k)", "container": null, "callable": "number_of_alternating_groups", "parameters": [{"name": "colors", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3209, "task_id": "number-of-subarrays-with-and-value-of-k", "difficulty": "Hard", "problem_description": "Given an array of integers nums and an integer k, return the number of subarrays of nums where the bitwise AND of the elements of the subarray equals k.\n\nExample 1:\n\nInput: nums = [1,1,1], k = 1\nOutput: 6\nExplanation:\nAll subarrays contain only 1's.\n\nExample 2:\n\nInput: nums = [1,1,2], k = 1\nOutput: 3\nExplanation:\nSubarrays having an AND value of 1 are: [1,1,2], [1,1,2], [1,1,2].\n\nExample 3:\n\nInput: nums = [1,2,3], k = 2\nOutput: 2\nExplanation:\nSubarrays having an AND value of 2 are: [1,2,3], [1,2,3].\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i], k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(nums = [10, 9, 8, 7, 6],k = 10) == 1\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3],k = 3) == 21\n assert candidate(nums = [8, 8, 8, 8, 8],k = 8) == 15\n assert candidate(nums = [4, 6, 3, 7, 1],k = 3) == 2\n assert candidate(nums = [1, 2, 3],k = 2) == 2\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 1000000000) == 6\n assert candidate(nums = [0, 0, 0, 0, 0],k = 0) == 15\n assert candidate(nums = [10, 5, 3, 1],k = 1) == 4\n assert candidate(nums = [7, 7, 7, 7],k = 7) == 10\n assert candidate(nums = [1, 3, 5, 7, 9],k = 3) == 1\n assert candidate(nums = [8, 4, 2, 1],k = 8) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 1\n assert candidate(nums = [1, 1, 1],k = 1) == 6\n assert candidate(nums = [1, 3, 5, 7, 9],k = 1) == 10\n assert candidate(nums = [5, 3, 1, 4, 2],k = 0) == 7\n assert candidate(nums = [3, 3, 3, 3, 3],k = 3) == 15\n assert candidate(nums = [5, 3, 2, 1, 4],k = 1) == 2\n assert candidate(nums = [1, 1, 2],k = 1) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 1\n assert candidate(nums = [7, 14, 28, 56, 112],k = 7) == 1\n assert candidate(nums = [2, 4, 6, 8],k = 2) == 1\n assert candidate(nums = [4, 6, 7, 8],k = 6) == 2\n assert candidate(nums = [0, 0, 0],k = 0) == 6\n assert candidate(nums = [1, 2, 4, 8, 16],k = 8) == 1\n assert candidate(nums = [4, 6, 5, 3, 3, 2],k = 3) == 3\n assert candidate(nums = [0, 0, 0, 0],k = 0) == 10\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 1000000000) == 6\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],k = 1) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8],k = 2) == 6\n assert candidate(nums = [1023, 1023, 1023, 1022, 1023, 1022, 1022],k = 1022) == 21\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 0) == 55\n assert candidate(nums = [255, 255, 255, 255, 255, 255],k = 255) == 21\n assert candidate(nums = [7, 3, 15, 8, 8],k = 8) == 5\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31],k = 31) == 36\n assert candidate(nums = [7, 7, 3, 7, 7, 7, 7],k = 7) == 13\n assert candidate(nums = [31, 31, 31, 31, 30, 31],k = 30) == 10\n assert candidate(nums = [8, 4, 2, 1, 0],k = 0) == 11\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],k = 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],k = 1) == 210\n assert candidate(nums = [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, 1, 0, 1, 0],k = 0) == 512\n assert candidate(nums = [15, 30, 30, 60, 60, 120],k = 30) == 3\n assert candidate(nums = [8, 8, 12, 8, 8, 8],k = 8) == 20\n assert candidate(nums = [1, 2, 4, 8, 16, 32],k = 4) == 1\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023],k = 1023) == 15\n assert candidate(nums = [1023, 1023, 1023, 1022, 1023, 1023],k = 1022) == 12\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],k = 1) == 6\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 1\n assert candidate(nums = [15, 15, 15, 15, 15, 15],k = 15) == 21\n assert candidate(nums = [15, 15, 15, 15, 15, 0, 15, 15],k = 15) == 18\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0, 0],k = 0) == 65\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],k = 15) == 496\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 = 1) == 210\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 8) == 55\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],k = 255) == 55\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 0, 31],k = 31) == 56\n assert candidate(nums = [7, 6, 7, 6, 7],k = 6) == 12\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 1\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127],k = 1) == 7\n assert candidate(nums = [7, 7, 3, 7, 3, 3, 7],k = 3) == 23\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 1\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15],k = 15) == 36\n assert candidate(nums = [15, 14, 13, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 2\n assert candidate(nums = [8, 12, 8, 12, 8, 12, 8, 12, 8, 12],k = 8) == 50\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 0) == 55\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 = 1) == 1\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024],k = 1) == 3\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255],k = 255) == 55\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 1) == 22\n assert candidate(nums = [3, 7, 5, 3, 7, 5, 3, 7, 5],k = 5) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1) == 1\n assert candidate(nums = [7, 7, 7, 0, 7, 7],k = 7) == 9\n assert candidate(nums = [15, 15, 15, 15, 14, 14, 15],k = 14) == 17\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31],k = 31) == 28\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == 210\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31],k = 31) == 210\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],k = 1) == 1225\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 1) == 10\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575],k = 1) == 20\n assert candidate(nums = [63, 63, 63, 62, 63, 63, 63],k = 62) == 16\n assert candidate(nums = [31, 15, 7, 3, 1, 1, 3, 7, 15, 31],k = 3) == 8\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 7) == 465\n assert candidate(nums = [64, 32, 16, 8, 4, 2, 1, 2, 4, 8, 16, 32, 64],k = 1) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 1) == 120\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 8) == 210\n assert candidate(nums = [31, 31, 31, 31, 31, 31, 31],k = 31) == 28\n assert candidate(nums = [123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123],k = 123) == 496\n assert candidate(nums = [7, 14, 28, 28, 56],k = 28) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16],k = 2) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 0) == 1128\n assert candidate(nums = [4, 8, 8, 16, 32, 32, 64],k = 32) == 3\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 4) == 1\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 255],k = 255) == 79\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023],k = 1023) == 28\n assert candidate(nums = [255, 255, 255, 254, 255, 255, 255],k = 254) == 16\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 1128\n assert candidate(nums = [7, 14, 28, 14, 7],k = 7) == 2\n assert candidate(nums = [15, 15, 15, 14, 15, 15, 14, 15],k = 14) == 26\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256],k = 2) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 2) == 210\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],k = 0) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1024) == 1\n assert candidate(nums = [255, 255, 255, 254, 255, 254, 255, 254, 255, 254],k = 254) == 46\n assert candidate(nums = [8, 4, 2, 1, 2, 4, 8],k = 4) == 2\n assert candidate(nums = [2, 6, 2, 2, 6, 2, 2, 6, 2, 2],k = 2) == 52\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15],k = 3) == 1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1],k = 1) == 8\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 1) == 10\n assert candidate(nums = [7, 7, 11, 7, 7, 7, 11, 11, 7],k = 7) == 10\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128],k = 2) == 1\n assert candidate(nums = [255, 255, 255, 255, 255],k = 255) == 15\n assert candidate(nums = [2, 3, 1, 2, 1, 1, 2, 3],k = 1) == 5\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38],k = 2) == 38\n assert candidate(nums = [6, 6, 6, 6, 6, 7, 6, 6, 6, 6],k = 6) == 54\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 0, 1023],k = 1023) == 56\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 1) == 38\n assert candidate(nums = [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, 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, 8],k = 8) == 1326\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 1) == 10\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],k = 1000000000) == 10\n assert candidate(nums = [2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6],k = 2) == 72\n", "comparison": "exact"}, "public_tests": ["[1,1,1]\n1", "[1,1,2]\n1", "[1,2,3]\n2"], "hints": ["Let’s say we want to count the number of pairs (l, r) such that nums[l] & nums[l + 1] & … & nums[r] == k.", "Fix the left index l.", "Note that if you increase r for a fixed l, then the AND value of the subarray either decreases or remains unchanged.", "Therefore, consider using binary search.", "To calculate the AND value of a subarray, use sparse tables."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:16:59+00:00", "tests_total": 127, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "binary-search", "bit-manipulation", "segment-tree"]}, "language": "ruby", "interface": {"raw_signature": "def count_subarrays(nums, k)", "container": null, "callable": "count_subarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3210, "task_id": "find-the-encrypted-string", "difficulty": "Easy", "problem_description": "You are given a string s and an integer k. Encrypt the string using the following algorithm:\n\n- For each character c in s, replace c with the k^th character after c in the string (in a cyclic manner).\n\nReturn the encrypted string.\n\nExample 1:\n\nInput: s = \"dart\", k = 3\nOutput: \"tdar\"\nExplanation:\n- For i = 0, the 3^rd character after 'd' is 't'.\n- For i = 1, the 3^rd character after 'a' is 'd'.\n- For i = 2, the 3^rd character after 'r' is 'a'.\n- For i = 3, the 3^rd character after 't' is 'r'.\n\nExample 2:\n\nInput: s = \"aaa\", k = 1\nOutput: \"aaa\"\nExplanation:\nAs all the characters are the same, the encrypted string will also be the same.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- 1 <= k <= 10^4\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"hello\",k = 10) == \"hello\"\n assert candidate(s = \"abc\",k = 2) == \"cab\"\n assert candidate(s = \"hello\",k = 7) == \"llohe\"\n assert candidate(s = \"abcdef\",k = 2) == \"cdefab\"\n assert candidate(s = \"world\",k = 5) == \"world\"\n assert candidate(s = \"dart\",k = 3) == \"tdar\"\n assert candidate(s = \"aaa\",k = 1) == \"aaa\"\n assert candidate(s = \"abcxyz\",k = 10) == \"yzabcx\"\n assert candidate(s = \"xyz\",k = 5) == \"zxy\"\n assert candidate(s = \"hello\",k = 2) == \"llohe\"\n assert candidate(s = \"z\",k = 10000) == \"z\"\n assert candidate(s = \"wraparound\",k = 15) == \"roundwrapa\"\n assert candidate(s = \"jumps\",k = 30) == \"jumps\"\n assert candidate(s = \"cryptography\",k = 20) == \"aphycryptogr\"\n assert candidate(s = \"securedata\",k = 1234) == \"redatasecu\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 1) == \"abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzza\"\n assert candidate(s = \"abcdefg\",k = 1000) == \"gabcdef\"\n assert candidate(s = \"cryptography\",k = 11) == \"ycryptograph\"\n assert candidate(s = \"mfvnhg\",k = 9999) == \"nhgmfv\"\n assert candidate(s = \"alibabacloud\",k = 15) == \"babacloudali\"\n assert candidate(s = \"abacaxi\",k = 1) == \"bacaxia\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 13) == \"mlkjihgfedcbazyxwvutsrqpon\"\n assert candidate(s = \"cryptography\",k = 7) == \"raphycryptog\"\n assert candidate(s = \"programming\",k = 15) == \"rammingprog\"\n assert candidate(s = \"zebra\",k = 3) == \"razeb\"\n assert candidate(s = \"quickbrownfox\",k = 12) == \"xquickbrownfo\"\n assert candidate(s = \"programming\",k = 10) == \"gprogrammin\"\n assert candidate(s = \"cryptography\",k = 8) == \"aphycryptogr\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 20) == \"kkllmmnnooppqqrrssttuuvvwwxxyyzzaabbccddeeffgghhiijj\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 25) == \"zabcdefghijklmnopqrstuvwxy\"\n assert candidate(s = \"quickbrownfox\",k = 8) == \"wnfoxquickbro\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 50) == \"zzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy\"\n assert candidate(s = \"abcdabcd\",k = 4) == \"abcdabcd\"\n assert candidate(s = \"overthelazydog\",k = 28) == \"overthelazydog\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 1000) == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",k = 13) == \"foxjumpsoverthelazydogthequickbrown\"\n assert candidate(s = \"python\",k = 1) == \"ythonp\"\n assert candidate(s = \"cryptography\",k = 15) == \"ptographycry\"\n assert candidate(s = \"pythonprogramming\",k = 25) == \"ogrammingpythonpr\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 27) == \"bcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"thesecretcode\",k = 20) == \"etcodethesecr\"\n assert candidate(s = \"mississippi\",k = 9) == \"pimississip\"\n assert candidate(s = \"abcabcabc\",k = 9) == \"abcabcabc\"\n assert candidate(s = \"programming\",k = 97) == \"ngprogrammi\"\n assert candidate(s = \"programming\",k = 7) == \"mingprogram\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 27) == \"yxwvutsrqponmlkjihgfedcbaz\"\n assert candidate(s = \"thisisatest\",k = 13) == \"isisatestth\"\n assert candidate(s = \"alibabacloud\",k = 100) == \"abacloudalib\"\n assert candidate(s = \"zebra\",k = 10) == \"zebra\"\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",k = 10) == \"ownfoxjumpsoverthelazydogthequickbr\"\n assert candidate(s = \"repeatedcharactersssssss\",k = 7) == \"dcharactersssssssrepeate\"\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxyz\",k = 26) == \"zzabcdefghijklmnopqrstuvwxy\"\n assert candidate(s = \"abracadabra\",k = 7) == \"abraabracad\"\n assert candidate(s = \"quickbrownfox\",k = 50) == \"oxquickbrownf\"\n assert candidate(s = \"mississippi\",k = 26) == \"issippimiss\"\n assert candidate(s = \"aabbccddeeff\",k = 5) == \"cddeeffaabbc\"\n assert candidate(s = \"world\",k = 500) == \"world\"\n assert candidate(s = \"hello\",k = 100) == \"hello\"\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\",k = 26) == \"licovolcanoconiosispneumonoultramicroscopicsi\"\n assert candidate(s = \"abcdefg\",k = 10000) == \"efgabcd\"\n assert candidate(s = \"hello\",k = 1000) == \"hello\"\n assert candidate(s = \"programmingisfun\",k = 10) == \"gisfunprogrammin\"\n assert candidate(s = \"algorithms\",k = 50) == \"algorithms\"\n assert candidate(s = \"mississippi\",k = 3) == \"sissippimis\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 1) == \"bcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"programming\",k = 5) == \"ammingprogr\"\n assert candidate(s = \"qwen\",k = 50) == \"enqw\"\n assert candidate(s = \"thisisateststring\",k = 50) == \"gthisisateststrin\"\n assert candidate(s = \"cryptography\",k = 4) == \"tographycryp\"\n assert candidate(s = \"cycliccycliccycliccyclic\",k = 50) == \"cliccycliccycliccycliccy\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 3) == \"bccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaab\"\n assert candidate(s = \"abcdefg\",k = 105) == \"abcdefg\"\n assert candidate(s = \"abacaxi\",k = 7) == \"abacaxi\"\n assert candidate(s = \"aabbccddeeff\",k = 123) == \"bccddeeffaab\"\n assert candidate(s = \"supercalifragilisticexpialidocious\",k = 9) == \"fragilisticexpialidocioussupercali\"\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",k = 13) == \"jumpsoverthelazydogquickbrownfox\"\n assert candidate(s = \"thisisaverylongstringthatweneedtocrypt\",k = 15) == \"stringthatweneedtocryptthisisaverylong\"\n assert candidate(s = \"repeatedcharacters\",k = 50) == \"tersrepeatedcharac\"\n assert candidate(s = \"hello\",k = 10000) == \"hello\"\n assert candidate(s = \"abcdefghij\",k = 30) == \"abcdefghij\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 3) == \"wvutsrqponmlkjihgfedcbazyx\"\n assert candidate(s = \"abcdefg\",k = 10) == \"defgabc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 26) == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"qwen\",k = 12) == \"qwen\"\n assert candidate(s = \"ab\",k = 9999) == \"ba\"\n", "comparison": "exact"}, "public_tests": ["\"dart\"\n3", "\"aaa\"\n1"], "hints": ["Make a new string such that for each character in s, character i will correspond to (i + k) % s.length character in the original string."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().getEncryptedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:01+00:00", "tests_total": 88, "tests_dropped": 3, "flags": [], "topic_tags": ["string"]}, "language": "ruby", "interface": {"raw_signature": "def get_encrypted_string(s, k)", "container": null, "callable": "get_encrypted_string", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3211, "task_id": "generate-binary-strings-without-adjacent-zeros", "difficulty": "Medium", "problem_description": "You are given a positive integer n.\n\nA binary string x is valid if all substrings of x of length 2 contain at least one \"1\".\n\nReturn all valid strings with length n, in any order.\n\nExample 1:\n\nInput: n = 3\nOutput: [\"010\",\"011\",\"101\",\"110\",\"111\"]\nExplanation:\nThe valid strings of length 3 are: \"010\", \"011\", \"101\", \"110\", and \"111\".\n\nExample 2:\n\nInput: n = 1\nOutput: [\"0\",\"1\"]\nExplanation:\nThe valid strings of length 1 are: \"0\" and \"1\".\n\nConstraints:\n\n- 1 <= n <= 18\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"The answer may list its items in any order (only the top-level order is free).\"\"\"\n if isinstance(result, list) and isinstance(expected, list):\n return sorted(result, key=repr) == sorted(expected, key=repr)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(n=3), ['010', '011', '101', '110', '111'])\n assert answers_match(candidate(n=15), ['010101010101010', '010101010101011', '010101010101101', '010101010101110', '010101010101111', '010101010110101', '010101010110110', '010101010110111', '010101010111010', '010101010111011', '010101010111101', '010101010111110', '010101010111111', '010101011010101', '010101011010110', '010101011010111', '010101011011010', '010101011011011', '010101011011101', '010101011011110', '010101011011111', '010101011101010', '010101011101011', '010101011101101', '010101011101110', '010101011101111', '010101011110101', '010101011110110', '010101011110111', '010101011111010', '010101011111011', '010101011111101', '010101011111110', '010101011111111', '010101101010101', '010101101010110', '010101101010111', '010101101011010', '010101101011011', '010101101011101', '010101101011110', '010101101011111', '010101101101010', '010101101101011', '010101101101101', '010101101101110', '010101101101111', '010101101110101', '010101101110110', '010101101110111', '010101101111010', '010101101111011', '010101101111101', '010101101111110', '010101101111111', '010101110101010', '010101110101011', '010101110101101', '010101110101110', '010101110101111', '010101110110101', '010101110110110', '010101110110111', '010101110111010', '010101110111011', '010101110111101', '010101110111110', '010101110111111', '010101111010101', '010101111010110', '010101111010111', '010101111011010', '010101111011011', '010101111011101', '010101111011110', '010101111011111', '010101111101010', '010101111101011', '010101111101101', '010101111101110', '010101111101111', '010101111110101', '010101111110110', '010101111110111', '010101111111010', '010101111111011', '010101111111101', '010101111111110', '010101111111111', '010110101010101', '010110101010110', '010110101010111', '010110101011010', '010110101011011', '010110101011101', '010110101011110', '010110101011111', '010110101101010', '010110101101011', '010110101101101', '010110101101110', '010110101101111', '010110101110101', '010110101110110', '010110101110111', '010110101111010', '010110101111011', '010110101111101', '010110101111110', '010110101111111', '010110110101010', '010110110101011', '010110110101101', '010110110101110', '010110110101111', '010110110110101', '010110110110110', '010110110110111', '010110110111010', '010110110111011', '010110110111101', '010110110111110', '010110110111111', '010110111010101', '010110111010110', '010110111010111', '010110111011010', '010110111011011', '010110111011101', '010110111011110', '010110111011111', '010110111101010', '010110111101011', '010110111101101', '010110111101110', '010110111101111', '010110111110101', '010110111110110', '010110111110111', '010110111111010', '010110111111011', '010110111111101', '010110111111110', '010110111111111', '010111010101010', '010111010101011', '010111010101101', '010111010101110', '010111010101111', '010111010110101', '010111010110110', '010111010110111', '010111010111010', '010111010111011', '010111010111101', '010111010111110', '010111010111111', '010111011010101', '010111011010110', '010111011010111', '010111011011010', '010111011011011', '010111011011101', '010111011011110', '010111011011111', '010111011101010', '010111011101011', '010111011101101', '010111011101110', '010111011101111', '010111011110101', '010111011110110', '010111011110111', '010111011111010', '010111011111011', '010111011111101', '010111011111110', '010111011111111', '010111101010101', '010111101010110', '010111101010111', '010111101011010', '010111101011011', '010111101011101', '010111101011110', '010111101011111', '010111101101010', '010111101101011', '010111101101101', '010111101101110', '010111101101111', '010111101110101', '010111101110110', '010111101110111', '010111101111010', '010111101111011', '010111101111101', '010111101111110', '010111101111111', '010111110101010', '010111110101011', '010111110101101', '010111110101110', '010111110101111', '010111110110101', '010111110110110', '010111110110111', '010111110111010', '010111110111011', '010111110111101', '010111110111110', '010111110111111', '010111111010101', '010111111010110', '010111111010111', '010111111011010', '010111111011011', '010111111011101', '010111111011110', '010111111011111', '010111111101010', '010111111101011', '010111111101101', '010111111101110', '010111111101111', '010111111110101', '010111111110110', '010111111110111', '010111111111010', '010111111111011', '010111111111101', '010111111111110', '010111111111111', '011010101010101', '011010101010110', '011010101010111', '011010101011010', '011010101011011', '011010101011101', '011010101011110', '011010101011111', '011010101101010', '011010101101011', '011010101101101', '011010101101110', '011010101101111', '011010101110101', '011010101110110', '011010101110111', '011010101111010', '011010101111011', '011010101111101', '011010101111110', '011010101111111', '011010110101010', '011010110101011', '011010110101101', '011010110101110', '011010110101111', '011010110110101', '011010110110110', '011010110110111', '011010110111010', '011010110111011', '011010110111101', '011010110111110', '011010110111111', '011010111010101', '011010111010110', '011010111010111', '011010111011010', '011010111011011', '011010111011101', '011010111011110', '011010111011111', '011010111101010', '011010111101011', '011010111101101', '011010111101110', '011010111101111', '011010111110101', '011010111110110', '011010111110111', '011010111111010', '011010111111011', '011010111111101', '011010111111110', '011010111111111', '011011010101010', '011011010101011', '011011010101101', '011011010101110', '011011010101111', '011011010110101', '011011010110110', '011011010110111', '011011010111010', '011011010111011', '011011010111101', '011011010111110', '011011010111111', '011011011010101', '011011011010110', '011011011010111', '011011011011010', '011011011011011', '011011011011101', '011011011011110', '011011011011111', '011011011101010', '011011011101011', '011011011101101', '011011011101110', '011011011101111', '011011011110101', '011011011110110', '011011011110111', '011011011111010', '011011011111011', '011011011111101', '011011011111110', '011011011111111', '011011101010101', '011011101010110', '011011101010111', '011011101011010', '011011101011011', '011011101011101', '011011101011110', '011011101011111', '011011101101010', '011011101101011', '011011101101101', '011011101101110', '011011101101111', '011011101110101', '011011101110110', '011011101110111', '011011101111010', '011011101111011', '011011101111101', '011011101111110', '011011101111111', '011011110101010', '011011110101011', '011011110101101', '011011110101110', '011011110101111', '011011110110101', '011011110110110', '011011110110111', '011011110111010', '011011110111011', '011011110111101', '011011110111110', '011011110111111', '011011111010101', '011011111010110', '011011111010111', '011011111011010', '011011111011011', '011011111011101', '011011111011110', '011011111011111', '011011111101010', '011011111101011', '011011111101101', '011011111101110', '011011111101111', '011011111110101', '011011111110110', '011011111110111', '011011111111010', '011011111111011', '011011111111101', '011011111111110', '011011111111111', '011101010101010', '011101010101011', '011101010101101', '011101010101110', '011101010101111', '011101010110101', '011101010110110', '011101010110111', '011101010111010', '011101010111011', '011101010111101', '011101010111110', '011101010111111', '011101011010101', '011101011010110', '011101011010111', '011101011011010', '011101011011011', '011101011011101', '011101011011110', '011101011011111', '011101011101010', '011101011101011', '011101011101101', '011101011101110', '011101011101111', '011101011110101', '011101011110110', '011101011110111', '011101011111010', '011101011111011', '011101011111101', '011101011111110', '011101011111111', '011101101010101', '011101101010110', '011101101010111', '011101101011010', '011101101011011', '011101101011101', '011101101011110', '011101101011111', '011101101101010', '011101101101011', '011101101101101', '011101101101110', '011101101101111', '011101101110101', '011101101110110', '011101101110111', '011101101111010', '011101101111011', '011101101111101', '011101101111110', '011101101111111', '011101110101010', '011101110101011', '011101110101101', '011101110101110', '011101110101111', '011101110110101', '011101110110110', '011101110110111', '011101110111010', '011101110111011', '011101110111101', '011101110111110', '011101110111111', '011101111010101', '011101111010110', '011101111010111', '011101111011010', '011101111011011', '011101111011101', '011101111011110', '011101111011111', '011101111101010', '011101111101011', '011101111101101', '011101111101110', '011101111101111', '011101111110101', '011101111110110', '011101111110111', '011101111111010', '011101111111011', '011101111111101', '011101111111110', '011101111111111', '011110101010101', '011110101010110', '011110101010111', '011110101011010', '011110101011011', '011110101011101', '011110101011110', '011110101011111', '011110101101010', '011110101101011', '011110101101101', '011110101101110', '011110101101111', '011110101110101', '011110101110110', '011110101110111', '011110101111010', '011110101111011', '011110101111101', '011110101111110', '011110101111111', '011110110101010', '011110110101011', '011110110101101', '011110110101110', '011110110101111', '011110110110101', '011110110110110', '011110110110111', '011110110111010', '011110110111011', '011110110111101', '011110110111110', '011110110111111', '011110111010101', '011110111010110', '011110111010111', '011110111011010', '011110111011011', '011110111011101', '011110111011110', '011110111011111', '011110111101010', '011110111101011', '011110111101101', '011110111101110', '011110111101111', '011110111110101', '011110111110110', '011110111110111', '011110111111010', '011110111111011', '011110111111101', '011110111111110', '011110111111111', '011111010101010', '011111010101011', '011111010101101', '011111010101110', '011111010101111', '011111010110101', '011111010110110', '011111010110111', '011111010111010', '011111010111011', '011111010111101', '011111010111110', '011111010111111', '011111011010101', '011111011010110', '011111011010111', '011111011011010', '011111011011011', '011111011011101', '011111011011110', '011111011011111', '011111011101010', '011111011101011', '011111011101101', '011111011101110', '011111011101111', '011111011110101', '011111011110110', '011111011110111', '011111011111010', '011111011111011', '011111011111101', '011111011111110', '011111011111111', '011111101010101', '011111101010110', '011111101010111', '011111101011010', '011111101011011', '011111101011101', '011111101011110', '011111101011111', '011111101101010', '011111101101011', '011111101101101', '011111101101110', '011111101101111', '011111101110101', '011111101110110', '011111101110111', '011111101111010', '011111101111011', '011111101111101', '011111101111110', '011111101111111', '011111110101010', '011111110101011', '011111110101101', '011111110101110', '011111110101111', '011111110110101', '011111110110110', '011111110110111', '011111110111010', '011111110111011', '011111110111101', '011111110111110', '011111110111111', '011111111010101', '011111111010110', '011111111010111', '011111111011010', '011111111011011', '011111111011101', '011111111011110', '011111111011111', '011111111101010', '011111111101011', '011111111101101', '011111111101110', '011111111101111', '011111111110101', '011111111110110', '011111111110111', '011111111111010', '011111111111011', '011111111111101', '011111111111110', '011111111111111', '101010101010101', '101010101010110', '101010101010111', '101010101011010', '101010101011011', '101010101011101', '101010101011110', '101010101011111', '101010101101010', '101010101101011', '101010101101101', '101010101101110', '101010101101111', '101010101110101', '101010101110110', '101010101110111', '101010101111010', '101010101111011', '101010101111101', '101010101111110', '101010101111111', '101010110101010', '101010110101011', '101010110101101', '101010110101110', '101010110101111', '101010110110101', '101010110110110', '101010110110111', '101010110111010', '101010110111011', '101010110111101', '101010110111110', '101010110111111', '101010111010101', '101010111010110', '101010111010111', '101010111011010', '101010111011011', '101010111011101', '101010111011110', '101010111011111', '101010111101010', '101010111101011', '101010111101101', '101010111101110', '101010111101111', '101010111110101', '101010111110110', '101010111110111', '101010111111010', '101010111111011', '101010111111101', '101010111111110', '101010111111111', '101011010101010', '101011010101011', '101011010101101', '101011010101110', '101011010101111', '101011010110101', '101011010110110', '101011010110111', '101011010111010', '101011010111011', '101011010111101', '101011010111110', '101011010111111', '101011011010101', '101011011010110', '101011011010111', '101011011011010', '101011011011011', '101011011011101', '101011011011110', '101011011011111', '101011011101010', '101011011101011', '101011011101101', '101011011101110', '101011011101111', '101011011110101', '101011011110110', '101011011110111', '101011011111010', '101011011111011', '101011011111101', '101011011111110', '101011011111111', '101011101010101', '101011101010110', '101011101010111', '101011101011010', '101011101011011', '101011101011101', '101011101011110', '101011101011111', '101011101101010', '101011101101011', '101011101101101', '101011101101110', '101011101101111', '101011101110101', '101011101110110', '101011101110111', '101011101111010', '101011101111011', '101011101111101', '101011101111110', '101011101111111', '101011110101010', '101011110101011', '101011110101101', '101011110101110', '101011110101111', '101011110110101', '101011110110110', '101011110110111', '101011110111010', '101011110111011', '101011110111101', '101011110111110', '101011110111111', '101011111010101', '101011111010110', '101011111010111', '101011111011010', '101011111011011', '101011111011101', '101011111011110', '101011111011111', '101011111101010', '101011111101011', '101011111101101', '101011111101110', '101011111101111', '101011111110101', '101011111110110', '101011111110111', '101011111111010', '101011111111011', '101011111111101', '101011111111110', '101011111111111', '101101010101010', '101101010101011', '101101010101101', '101101010101110', '101101010101111', '101101010110101', '101101010110110', '101101010110111', '101101010111010', '101101010111011', '101101010111101', '101101010111110', '101101010111111', '101101011010101', '101101011010110', '101101011010111', '101101011011010', '101101011011011', '101101011011101', '101101011011110', '101101011011111', '101101011101010', '101101011101011', '101101011101101', '101101011101110', '101101011101111', '101101011110101', '101101011110110', '101101011110111', '101101011111010', '101101011111011', '101101011111101', '101101011111110', '101101011111111', '101101101010101', '101101101010110', '101101101010111', '101101101011010', '101101101011011', '101101101011101', '101101101011110', '101101101011111', '101101101101010', '101101101101011', '101101101101101', '101101101101110', '101101101101111', '101101101110101', '101101101110110', '101101101110111', '101101101111010', '101101101111011', '101101101111101', '101101101111110', '101101101111111', '101101110101010', '101101110101011', '101101110101101', '101101110101110', '101101110101111', '101101110110101', '101101110110110', '101101110110111', '101101110111010', '101101110111011', '101101110111101', '101101110111110', '101101110111111', '101101111010101', '101101111010110', '101101111010111', '101101111011010', '101101111011011', '101101111011101', '101101111011110', '101101111011111', '101101111101010', '101101111101011', '101101111101101', '101101111101110', '101101111101111', '101101111110101', '101101111110110', '101101111110111', '101101111111010', '101101111111011', '101101111111101', '101101111111110', '101101111111111', '101110101010101', '101110101010110', '101110101010111', '101110101011010', '101110101011011', '101110101011101', '101110101011110', '101110101011111', '101110101101010', '101110101101011', '101110101101101', '101110101101110', '101110101101111', '101110101110101', '101110101110110', '101110101110111', '101110101111010', '101110101111011', '101110101111101', '101110101111110', '101110101111111', '101110110101010', '101110110101011', '101110110101101', '101110110101110', '101110110101111', '101110110110101', '101110110110110', '101110110110111', '101110110111010', '101110110111011', '101110110111101', '101110110111110', '101110110111111', '101110111010101', '101110111010110', '101110111010111', '101110111011010', '101110111011011', '101110111011101', '101110111011110', '101110111011111', '101110111101010', '101110111101011', '101110111101101', '101110111101110', '101110111101111', '101110111110101', '101110111110110', '101110111110111', '101110111111010', '101110111111011', '101110111111101', '101110111111110', '101110111111111', '101111010101010', '101111010101011', '101111010101101', '101111010101110', '101111010101111', '101111010110101', '101111010110110', '101111010110111', '101111010111010', '101111010111011', '101111010111101', '101111010111110', '101111010111111', '101111011010101', '101111011010110', '101111011010111', '101111011011010', '101111011011011', '101111011011101', '101111011011110', '101111011011111', '101111011101010', '101111011101011', '101111011101101', '101111011101110', '101111011101111', '101111011110101', '101111011110110', '101111011110111', '101111011111010', '101111011111011', '101111011111101', '101111011111110', '101111011111111', '101111101010101', '101111101010110', '101111101010111', '101111101011010', '101111101011011', '101111101011101', '101111101011110', '101111101011111', '101111101101010', '101111101101011', '101111101101101', '101111101101110', '101111101101111', '101111101110101', '101111101110110', '101111101110111', '101111101111010', '101111101111011', '101111101111101', '101111101111110', '101111101111111', '101111110101010', '101111110101011', '101111110101101', '101111110101110', '101111110101111', '101111110110101', '101111110110110', '101111110110111', '101111110111010', '101111110111011', '101111110111101', '101111110111110', '101111110111111', '101111111010101', '101111111010110', '101111111010111', '101111111011010', '101111111011011', '101111111011101', '101111111011110', '101111111011111', '101111111101010', '101111111101011', '101111111101101', '101111111101110', '101111111101111', '101111111110101', '101111111110110', '101111111110111', '101111111111010', '101111111111011', '101111111111101', '101111111111110', '101111111111111', '110101010101010', '110101010101011', '110101010101101', '110101010101110', '110101010101111', '110101010110101', '110101010110110', '110101010110111', '110101010111010', '110101010111011', '110101010111101', '110101010111110', '110101010111111', '110101011010101', '110101011010110', '110101011010111', '110101011011010', '110101011011011', '110101011011101', '110101011011110', '110101011011111', '110101011101010', '110101011101011', '110101011101101', '110101011101110', '110101011101111', '110101011110101', '110101011110110', '110101011110111', '110101011111010', '110101011111011', '110101011111101', '110101011111110', '110101011111111', '110101101010101', '110101101010110', '110101101010111', '110101101011010', '110101101011011', '110101101011101', '110101101011110', '110101101011111', '110101101101010', '110101101101011', '110101101101101', '110101101101110', '110101101101111', '110101101110101', '110101101110110', '110101101110111', '110101101111010', '110101101111011', '110101101111101', '110101101111110', '110101101111111', '110101110101010', '110101110101011', '110101110101101', '110101110101110', '110101110101111', '110101110110101', '110101110110110', '110101110110111', '110101110111010', '110101110111011', '110101110111101', '110101110111110', '110101110111111', '110101111010101', '110101111010110', '110101111010111', '110101111011010', '110101111011011', '110101111011101', '110101111011110', '110101111011111', '110101111101010', '110101111101011', '110101111101101', '110101111101110', '110101111101111', '110101111110101', '110101111110110', '110101111110111', '110101111111010', '110101111111011', '110101111111101', '110101111111110', '110101111111111', '110110101010101', '110110101010110', '110110101010111', '110110101011010', '110110101011011', '110110101011101', '110110101011110', '110110101011111', '110110101101010', '110110101101011', '110110101101101', '110110101101110', '110110101101111', '110110101110101', '110110101110110', '110110101110111', '110110101111010', '110110101111011', '110110101111101', '110110101111110', '110110101111111', '110110110101010', '110110110101011', '110110110101101', '110110110101110', '110110110101111', '110110110110101', '110110110110110', '110110110110111', '110110110111010', '110110110111011', '110110110111101', '110110110111110', '110110110111111', '110110111010101', '110110111010110', '110110111010111', '110110111011010', '110110111011011', '110110111011101', '110110111011110', '110110111011111', '110110111101010', '110110111101011', '110110111101101', '110110111101110', '110110111101111', '110110111110101', '110110111110110', '110110111110111', '110110111111010', '110110111111011', '110110111111101', '110110111111110', '110110111111111', '110111010101010', '110111010101011', '110111010101101', '110111010101110', '110111010101111', '110111010110101', '110111010110110', '110111010110111', '110111010111010', '110111010111011', '110111010111101', '110111010111110', '110111010111111', '110111011010101', '110111011010110', '110111011010111', '110111011011010', '110111011011011', '110111011011101', '110111011011110', '110111011011111', '110111011101010', '110111011101011', '110111011101101', '110111011101110', '110111011101111', '110111011110101', '110111011110110', '110111011110111', '110111011111010', '110111011111011', '110111011111101', '110111011111110', '110111011111111', '110111101010101', '110111101010110', '110111101010111', '110111101011010', '110111101011011', '110111101011101', '110111101011110', '110111101011111', '110111101101010', '110111101101011', '110111101101101', '110111101101110', '110111101101111', '110111101110101', '110111101110110', '110111101110111', '110111101111010', '110111101111011', '110111101111101', '110111101111110', '110111101111111', '110111110101010', '110111110101011', '110111110101101', '110111110101110', '110111110101111', '110111110110101', '110111110110110', '110111110110111', '110111110111010', '110111110111011', '110111110111101', '110111110111110', '110111110111111', '110111111010101', '110111111010110', '110111111010111', '110111111011010', '110111111011011', '110111111011101', '110111111011110', '110111111011111', '110111111101010', '110111111101011', '110111111101101', '110111111101110', '110111111101111', '110111111110101', '110111111110110', '110111111110111', '110111111111010', '110111111111011', '110111111111101', '110111111111110', '110111111111111', '111010101010101', '111010101010110', '111010101010111', '111010101011010', '111010101011011', '111010101011101', '111010101011110', '111010101011111', '111010101101010', '111010101101011', '111010101101101', '111010101101110', '111010101101111', '111010101110101', '111010101110110', '111010101110111', '111010101111010', '111010101111011', '111010101111101', '111010101111110', '111010101111111', '111010110101010', '111010110101011', '111010110101101', '111010110101110', '111010110101111', '111010110110101', '111010110110110', '111010110110111', '111010110111010', '111010110111011', '111010110111101', '111010110111110', '111010110111111', '111010111010101', '111010111010110', '111010111010111', '111010111011010', '111010111011011', '111010111011101', '111010111011110', '111010111011111', '111010111101010', '111010111101011', '111010111101101', '111010111101110', '111010111101111', '111010111110101', '111010111110110', '111010111110111', '111010111111010', '111010111111011', '111010111111101', '111010111111110', '111010111111111', '111011010101010', '111011010101011', '111011010101101', '111011010101110', '111011010101111', '111011010110101', '111011010110110', '111011010110111', '111011010111010', '111011010111011', '111011010111101', '111011010111110', '111011010111111', '111011011010101', '111011011010110', '111011011010111', '111011011011010', '111011011011011', '111011011011101', '111011011011110', '111011011011111', '111011011101010', '111011011101011', '111011011101101', '111011011101110', '111011011101111', '111011011110101', '111011011110110', '111011011110111', '111011011111010', '111011011111011', '111011011111101', '111011011111110', '111011011111111', '111011101010101', '111011101010110', '111011101010111', '111011101011010', '111011101011011', '111011101011101', '111011101011110', '111011101011111', '111011101101010', '111011101101011', '111011101101101', '111011101101110', '111011101101111', '111011101110101', '111011101110110', '111011101110111', '111011101111010', '111011101111011', '111011101111101', '111011101111110', '111011101111111', '111011110101010', '111011110101011', '111011110101101', '111011110101110', '111011110101111', '111011110110101', '111011110110110', '111011110110111', '111011110111010', '111011110111011', '111011110111101', '111011110111110', '111011110111111', '111011111010101', '111011111010110', '111011111010111', '111011111011010', '111011111011011', '111011111011101', '111011111011110', '111011111011111', '111011111101010', '111011111101011', '111011111101101', '111011111101110', '111011111101111', '111011111110101', '111011111110110', '111011111110111', '111011111111010', '111011111111011', '111011111111101', '111011111111110', '111011111111111', '111101010101010', '111101010101011', '111101010101101', '111101010101110', '111101010101111', '111101010110101', '111101010110110', '111101010110111', '111101010111010', '111101010111011', '111101010111101', '111101010111110', '111101010111111', '111101011010101', '111101011010110', '111101011010111', '111101011011010', '111101011011011', '111101011011101', '111101011011110', '111101011011111', '111101011101010', '111101011101011', '111101011101101', '111101011101110', '111101011101111', '111101011110101', '111101011110110', '111101011110111', '111101011111010', '111101011111011', '111101011111101', '111101011111110', '111101011111111', '111101101010101', '111101101010110', '111101101010111', '111101101011010', '111101101011011', '111101101011101', '111101101011110', '111101101011111', '111101101101010', '111101101101011', '111101101101101', '111101101101110', '111101101101111', '111101101110101', '111101101110110', '111101101110111', '111101101111010', '111101101111011', '111101101111101', '111101101111110', '111101101111111', '111101110101010', '111101110101011', '111101110101101', '111101110101110', '111101110101111', '111101110110101', '111101110110110', '111101110110111', '111101110111010', '111101110111011', '111101110111101', '111101110111110', '111101110111111', '111101111010101', '111101111010110', '111101111010111', '111101111011010', '111101111011011', '111101111011101', '111101111011110', '111101111011111', '111101111101010', '111101111101011', '111101111101101', '111101111101110', '111101111101111', '111101111110101', '111101111110110', '111101111110111', '111101111111010', '111101111111011', '111101111111101', '111101111111110', '111101111111111', '111110101010101', '111110101010110', '111110101010111', '111110101011010', '111110101011011', '111110101011101', '111110101011110', '111110101011111', '111110101101010', '111110101101011', '111110101101101', '111110101101110', '111110101101111', '111110101110101', '111110101110110', '111110101110111', '111110101111010', '111110101111011', '111110101111101', '111110101111110', '111110101111111', '111110110101010', '111110110101011', '111110110101101', '111110110101110', '111110110101111', '111110110110101', '111110110110110', '111110110110111', '111110110111010', '111110110111011', '111110110111101', '111110110111110', '111110110111111', '111110111010101', '111110111010110', '111110111010111', '111110111011010', '111110111011011', '111110111011101', '111110111011110', '111110111011111', '111110111101010', '111110111101011', '111110111101101', '111110111101110', '111110111101111', '111110111110101', '111110111110110', '111110111110111', '111110111111010', '111110111111011', '111110111111101', '111110111111110', '111110111111111', '111111010101010', '111111010101011', '111111010101101', '111111010101110', '111111010101111', '111111010110101', '111111010110110', '111111010110111', '111111010111010', '111111010111011', '111111010111101', '111111010111110', '111111010111111', '111111011010101', '111111011010110', '111111011010111', '111111011011010', '111111011011011', '111111011011101', '111111011011110', '111111011011111', '111111011101010', '111111011101011', '111111011101101', '111111011101110', '111111011101111', '111111011110101', '111111011110110', '111111011110111', '111111011111010', '111111011111011', '111111011111101', '111111011111110', '111111011111111', '111111101010101', '111111101010110', '111111101010111', '111111101011010', '111111101011011', '111111101011101', '111111101011110', '111111101011111', '111111101101010', '111111101101011', '111111101101101', '111111101101110', '111111101101111', '111111101110101', '111111101110110', '111111101110111', '111111101111010', '111111101111011', '111111101111101', '111111101111110', '111111101111111', '111111110101010', '111111110101011', '111111110101101', '111111110101110', '111111110101111', '111111110110101', '111111110110110', '111111110110111', '111111110111010', '111111110111011', '111111110111101', '111111110111110', '111111110111111', '111111111010101', '111111111010110', '111111111010111', '111111111011010', '111111111011011', '111111111011101', '111111111011110', '111111111011111', '111111111101010', '111111111101011', '111111111101101', '111111111101110', '111111111101111', '111111111110101', '111111111110110', '111111111110111', '111111111111010', '111111111111011', '111111111111101', '111111111111110', '111111111111111'])\n assert answers_match(candidate(n=4), ['0101', '0110', '0111', '1010', '1011', '1101', '1110', '1111'])\n assert answers_match(candidate(n=2), ['01', '10', '11'])\n assert answers_match(candidate(n=1), ['0', '1'])\n assert answers_match(candidate(n=10), ['0101010101', '0101010110', '0101010111', '0101011010', '0101011011', '0101011101', '0101011110', '0101011111', '0101101010', '0101101011', '0101101101', '0101101110', '0101101111', '0101110101', '0101110110', '0101110111', '0101111010', '0101111011', '0101111101', '0101111110', '0101111111', '0110101010', '0110101011', '0110101101', '0110101110', '0110101111', '0110110101', '0110110110', '0110110111', '0110111010', '0110111011', '0110111101', '0110111110', '0110111111', '0111010101', '0111010110', '0111010111', '0111011010', '0111011011', '0111011101', '0111011110', '0111011111', '0111101010', '0111101011', '0111101101', '0111101110', '0111101111', '0111110101', '0111110110', '0111110111', '0111111010', '0111111011', '0111111101', '0111111110', '0111111111', '1010101010', '1010101011', '1010101101', '1010101110', '1010101111', '1010110101', '1010110110', '1010110111', '1010111010', '1010111011', '1010111101', '1010111110', '1010111111', '1011010101', '1011010110', '1011010111', '1011011010', '1011011011', '1011011101', '1011011110', '1011011111', '1011101010', '1011101011', '1011101101', '1011101110', '1011101111', '1011110101', '1011110110', '1011110111', '1011111010', '1011111011', '1011111101', '1011111110', '1011111111', '1101010101', '1101010110', '1101010111', '1101011010', '1101011011', '1101011101', '1101011110', '1101011111', '1101101010', '1101101011', '1101101101', '1101101110', '1101101111', '1101110101', '1101110110', '1101110111', '1101111010', '1101111011', '1101111101', '1101111110', '1101111111', '1110101010', '1110101011', '1110101101', '1110101110', '1110101111', '1110110101', '1110110110', '1110110111', '1110111010', '1110111011', '1110111101', '1110111110', '1110111111', '1111010101', '1111010110', '1111010111', '1111011010', '1111011011', '1111011101', '1111011110', '1111011111', '1111101010', '1111101011', '1111101101', '1111101110', '1111101111', '1111110101', '1111110110', '1111110111', '1111111010', '1111111011', '1111111101', '1111111110', '1111111111'])\n assert answers_match(candidate(n=5), ['01010', '01011', '01101', '01110', '01111', '10101', '10110', '10111', '11010', '11011', '11101', '11110', '11111'])\n assert answers_match(candidate(n=8), ['01010101', '01010110', '01010111', '01011010', '01011011', '01011101', '01011110', '01011111', '01101010', '01101011', '01101101', '01101110', '01101111', '01110101', '01110110', '01110111', '01111010', '01111011', '01111101', '01111110', '01111111', '10101010', '10101011', '10101101', '10101110', '10101111', '10110101', '10110110', '10110111', '10111010', '10111011', '10111101', '10111110', '10111111', '11010101', '11010110', '11010111', '11011010', '11011011', '11011101', '11011110', '11011111', '11101010', '11101011', '11101101', '11101110', '11101111', '11110101', '11110110', '11110111', '11111010', '11111011', '11111101', '11111110', '11111111'])\n assert answers_match(candidate(n=12), ['010101010101', '010101010110', '010101010111', '010101011010', '010101011011', '010101011101', '010101011110', '010101011111', '010101101010', '010101101011', '010101101101', '010101101110', '010101101111', '010101110101', '010101110110', '010101110111', '010101111010', '010101111011', '010101111101', '010101111110', '010101111111', '010110101010', '010110101011', '010110101101', '010110101110', '010110101111', '010110110101', '010110110110', '010110110111', '010110111010', '010110111011', '010110111101', '010110111110', '010110111111', '010111010101', '010111010110', '010111010111', '010111011010', '010111011011', '010111011101', '010111011110', '010111011111', '010111101010', '010111101011', '010111101101', '010111101110', '010111101111', '010111110101', '010111110110', '010111110111', '010111111010', '010111111011', '010111111101', '010111111110', '010111111111', '011010101010', '011010101011', '011010101101', '011010101110', '011010101111', '011010110101', '011010110110', '011010110111', '011010111010', '011010111011', '011010111101', '011010111110', '011010111111', '011011010101', '011011010110', '011011010111', '011011011010', '011011011011', '011011011101', '011011011110', '011011011111', '011011101010', '011011101011', '011011101101', '011011101110', '011011101111', '011011110101', '011011110110', '011011110111', '011011111010', '011011111011', '011011111101', '011011111110', '011011111111', '011101010101', '011101010110', '011101010111', '011101011010', '011101011011', '011101011101', '011101011110', '011101011111', '011101101010', '011101101011', '011101101101', '011101101110', '011101101111', '011101110101', '011101110110', '011101110111', '011101111010', '011101111011', '011101111101', '011101111110', '011101111111', '011110101010', '011110101011', '011110101101', '011110101110', '011110101111', '011110110101', '011110110110', '011110110111', '011110111010', '011110111011', '011110111101', '011110111110', '011110111111', '011111010101', '011111010110', '011111010111', '011111011010', '011111011011', '011111011101', '011111011110', '011111011111', '011111101010', '011111101011', '011111101101', '011111101110', '011111101111', '011111110101', '011111110110', '011111110111', '011111111010', '011111111011', '011111111101', '011111111110', '011111111111', '101010101010', '101010101011', '101010101101', '101010101110', '101010101111', '101010110101', '101010110110', '101010110111', '101010111010', '101010111011', '101010111101', '101010111110', '101010111111', '101011010101', '101011010110', '101011010111', '101011011010', '101011011011', '101011011101', '101011011110', '101011011111', '101011101010', '101011101011', '101011101101', '101011101110', '101011101111', '101011110101', '101011110110', '101011110111', '101011111010', '101011111011', '101011111101', '101011111110', '101011111111', '101101010101', '101101010110', '101101010111', '101101011010', '101101011011', '101101011101', '101101011110', '101101011111', '101101101010', '101101101011', '101101101101', '101101101110', '101101101111', '101101110101', '101101110110', '101101110111', '101101111010', '101101111011', '101101111101', '101101111110', '101101111111', '101110101010', '101110101011', '101110101101', '101110101110', '101110101111', '101110110101', '101110110110', '101110110111', '101110111010', '101110111011', '101110111101', '101110111110', '101110111111', '101111010101', '101111010110', '101111010111', '101111011010', '101111011011', '101111011101', '101111011110', '101111011111', '101111101010', '101111101011', '101111101101', '101111101110', '101111101111', '101111110101', '101111110110', '101111110111', '101111111010', '101111111011', '101111111101', '101111111110', '101111111111', '110101010101', '110101010110', '110101010111', '110101011010', '110101011011', '110101011101', '110101011110', '110101011111', '110101101010', '110101101011', '110101101101', '110101101110', '110101101111', '110101110101', '110101110110', '110101110111', '110101111010', '110101111011', '110101111101', '110101111110', '110101111111', '110110101010', '110110101011', '110110101101', '110110101110', '110110101111', '110110110101', '110110110110', '110110110111', '110110111010', '110110111011', '110110111101', '110110111110', '110110111111', '110111010101', '110111010110', '110111010111', '110111011010', '110111011011', '110111011101', '110111011110', '110111011111', '110111101010', '110111101011', '110111101101', '110111101110', '110111101111', '110111110101', '110111110110', '110111110111', '110111111010', '110111111011', '110111111101', '110111111110', '110111111111', '111010101010', '111010101011', '111010101101', '111010101110', '111010101111', '111010110101', '111010110110', '111010110111', '111010111010', '111010111011', '111010111101', '111010111110', '111010111111', '111011010101', '111011010110', '111011010111', '111011011010', '111011011011', '111011011101', '111011011110', '111011011111', '111011101010', '111011101011', '111011101101', '111011101110', '111011101111', '111011110101', '111011110110', '111011110111', '111011111010', '111011111011', '111011111101', '111011111110', '111011111111', '111101010101', '111101010110', '111101010111', '111101011010', '111101011011', '111101011101', '111101011110', '111101011111', '111101101010', '111101101011', '111101101101', '111101101110', '111101101111', '111101110101', '111101110110', '111101110111', '111101111010', '111101111011', '111101111101', '111101111110', '111101111111', '111110101010', '111110101011', '111110101101', '111110101110', '111110101111', '111110110101', '111110110110', '111110110111', '111110111010', '111110111011', '111110111101', '111110111110', '111110111111', '111111010101', '111111010110', '111111010111', '111111011010', '111111011011', '111111011101', '111111011110', '111111011111', '111111101010', '111111101011', '111111101101', '111111101110', '111111101111', '111111110101', '111111110110', '111111110111', '111111111010', '111111111011', '111111111101', '111111111110', '111111111111'])\n assert answers_match(candidate(n=9), ['010101010', '010101011', '010101101', '010101110', '010101111', '010110101', '010110110', '010110111', '010111010', '010111011', '010111101', '010111110', '010111111', '011010101', '011010110', '011010111', '011011010', '011011011', '011011101', '011011110', '011011111', '011101010', '011101011', '011101101', '011101110', '011101111', '011110101', '011110110', '011110111', '011111010', '011111011', '011111101', '011111110', '011111111', '101010101', '101010110', '101010111', '101011010', '101011011', '101011101', '101011110', '101011111', '101101010', '101101011', '101101101', '101101110', '101101111', '101110101', '101110110', '101110111', '101111010', '101111011', '101111101', '101111110', '101111111', '110101010', '110101011', '110101101', '110101110', '110101111', '110110101', '110110110', '110110111', '110111010', '110111011', '110111101', '110111110', '110111111', '111010101', '111010110', '111010111', '111011010', '111011011', '111011101', '111011110', '111011111', '111101010', '111101011', '111101101', '111101110', '111101111', '111110101', '111110110', '111110111', '111111010', '111111011', '111111101', '111111110', '111111111'])\n assert answers_match(candidate(n=6), ['010101', '010110', '010111', '011010', '011011', '011101', '011110', '011111', '101010', '101011', '101101', '101110', '101111', '110101', '110110', '110111', '111010', '111011', '111101', '111110', '111111'])\n assert answers_match(candidate(n=7), ['0101010', '0101011', '0101101', '0101110', '0101111', '0110101', '0110110', '0110111', '0111010', '0111011', '0111101', '0111110', '0111111', '1010101', '1010110', '1010111', '1011010', '1011011', '1011101', '1011110', '1011111', '1101010', '1101011', '1101101', '1101110', '1101111', '1110101', '1110110', '1110111', '1111010', '1111011', '1111101', '1111110', '1111111'])\n", "comparison": "unordered"}, "public_tests": ["3", "1"], "hints": ["If we have a string s of length x, we can generate all strings of length x + 1.", "If s has 0 as the last character, we can only append 1, whereas if the last character is 1, we can append both 0 and 1.", "We can use recursion and backtracking to generate all such strings."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().validStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:03+00:00", "tests_total": 12, "tests_dropped": 0, "flags": ["any_order"], "topic_tags": ["string", "backtracking", "bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def valid_strings(n)", "container": null, "callable": "valid_strings", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3212, "task_id": "count-submatrices-with-equal-frequency-of-x-and-y", "difficulty": "Medium", "problem_description": "Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contain:\n\n- grid[0][0]\n- an equal frequency of 'X' and 'Y'.\n- at least one 'X'.\n\nExample 1:\n\nInput: grid = [[\"X\",\"Y\",\".\"],[\"Y\",\".\",\".\"]]\nOutput: 3\nExplanation:\n\nExample 2:\n\nInput: grid = [[\"X\",\"X\"],[\"X\",\"Y\"]]\nOutput: 0\nExplanation:\nNo submatrix has an equal frequency of 'X' and 'Y'.\n\nExample 3:\n\nInput: grid = [[\".\",\".\"],[\".\",\".\"]]\nOutput: 0\nExplanation:\nNo submatrix has at least one 'X'.\n\nConstraints:\n\n- 1 <= grid.length, grid[i].length <= 1000\n- grid[i][j] is either 'X', 'Y', or '.'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [['X', 'Y', 'X'], ['Y', 'X', 'Y'], ['X', 'Y', 'X']]) == 5\n assert candidate(grid = [['.', '.'], ['.', '.']]) == 0\n assert candidate(grid = [['X', 'X'], ['X', 'Y']]) == 0\n assert candidate(grid = [['X', 'X', 'Y', 'Y'], ['Y', 'Y', 'X', 'X']]) == 5\n assert candidate(grid = [['X', 'X', 'X', 'X'], ['X', 'Y', 'Y', 'X'], ['X', 'Y', 'Y', 'X'], ['X', 'X', 'X', 'X']]) == 0\n assert candidate(grid = [['X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X'], ['X', 'Y', 'X', 'Y']]) == 8\n assert candidate(grid = [['X', '.', 'Y'], ['.', 'X', 'Y'], ['Y', '.', 'X']]) == 4\n assert candidate(grid = [['X'], ['Y'], ['X']]) == 1\n assert candidate(grid = [['X', 'Y', '.'], ['Y', '.', '.']]) == 3\n assert candidate(grid = [['X', 'Y'], ['X', 'Y'], ['X', 'Y']]) == 3\n assert candidate(grid = [['X', 'X', 'Y'], ['Y', 'Y', 'X'], ['X', 'Y', 'X']]) == 4\n assert candidate(grid = [['X', 'X', 'Y', 'Y'], ['Y', 'Y', 'X', 'X'], ['X', 'X', 'Y', 'Y']]) == 6\n assert candidate(grid = [['X', 'X', 'X'], ['X', 'X', 'X'], ['X', 'X', 'X']]) == 0\n assert candidate(grid = [['X', 'Y'], ['Y', 'X']]) == 3\n assert candidate(grid = [['X', 'X', 'X'], ['Y', 'Y', 'Y'], ['.', '.', '.']]) == 6\n assert candidate(grid = [['X', '.', 'Y'], ['.', 'X', '.'], ['Y', '.', 'X']]) == 2\n assert candidate(grid = [['X', 'Y', '.'], ['.', 'X', 'Y'], ['Y', 'X', '.']]) == 5\n assert candidate(grid = [['X', 'Y', 'X'], ['X', 'Y', 'X'], ['X', 'Y', 'X']]) == 3\n assert candidate(grid = [['X', 'Y', 'X', 'X', 'Y', 'Y'], ['Y', 'Y', 'X', 'Y', 'X', 'X'], ['X', 'X', 'Y', 'Y', 'X', 'Y'], ['X', 'Y', 'X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X', 'Y', 'X'], ['X', 'Y', 'X', 'Y', 'X', 'Y']]) == 19\n assert candidate(grid = [['Y', 'Y', 'Y', 'Y', 'Y'], ['Y', 'Y', 'Y', 'Y', 'Y'], ['Y', 'Y', 'Y', 'Y', 'Y'], ['Y', 'Y', 'Y', 'Y', 'Y'], ['Y', 'Y', 'Y', 'Y', 'Y']]) == 0\n assert candidate(grid = [['X', 'Y', 'X'], ['Y', '.', 'X'], ['X', 'Y', '.']]) == 2\n assert candidate(grid = [['.', '.', '.', 'X', 'Y'], ['.', 'X', 'Y', '.', '.'], ['.', 'Y', 'X', '.', '.'], ['X', '.', '.', 'Y', '.'], ['Y', '.', '.', '.', 'X']]) == 12\n assert candidate(grid = [['X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X']]) == 15\n assert candidate(grid = [['X', 'X', 'X'], ['Y', 'Y', 'Y'], ['X', 'Y', 'X'], ['Y', 'X', 'Y']]) == 7\n assert candidate(grid = [['X', 'Y', 'X', 'X', 'Y'], ['Y', 'X', 'Y', 'X', 'Y'], ['X', 'Y', 'X', 'X', 'Y'], ['X', 'X', 'Y', 'Y', 'X'], ['Y', 'X', 'Y', 'X', 'Y']]) == 6\n assert candidate(grid = [['X', 'Y', 'Y', 'X'], ['Y', 'X', 'X', 'Y'], ['X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X']]) == 12\n assert candidate(grid = [['X', '.', 'X', 'Y'], ['Y', 'X', 'Y', '.'], ['.', 'Y', 'X', 'X'], ['X', 'Y', '.', 'Y']]) == 6\n assert candidate(grid = [['X', 'X', 'X', 'X', 'X'], ['X', 'X', 'X', 'X', 'X'], ['X', 'X', 'X', 'X', 'X'], ['X', 'X', 'X', 'X', 'X'], ['X', 'X', 'X', 'X', 'X']]) == 0\n assert candidate(grid = [['.', '.', 'X', 'Y', '.'], ['X', 'Y', '.', 'X', 'Y'], ['Y', 'X', 'X', 'Y', 'X'], ['.', 'Y', 'X', '.', 'Y'], ['X', '.', 'Y', 'X', '.']]) == 9\n assert candidate(grid = [['X', 'X', 'X', 'Y'], ['Y', 'Y', 'X', 'X'], ['X', 'Y', 'X', 'X'], ['Y', 'X', 'Y', 'Y']]) == 5\n assert candidate(grid = [['X', 'X', 'Y', 'X'], ['Y', 'Y', 'X', 'Y'], ['X', 'X', 'Y', 'X'], ['Y', 'Y', 'X', 'Y']]) == 8\n assert candidate(grid = [['X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X'], ['X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X']]) == 12\n assert candidate(grid = [['X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X'], ['Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y']]) == 13\n assert candidate(grid = [['X', 'X', 'X', 'X', 'X', 'X'], ['X', 'X', 'X', 'X', 'X', 'X'], ['Y', 'Y', 'Y', 'Y', 'Y', 'Y'], ['Y', 'Y', 'Y', 'Y', 'Y', 'Y'], ['X', 'X', 'X', 'X', 'X', 'X'], ['X', 'X', 'X', 'X', 'X', 'X']]) == 6\n assert candidate(grid = [['X', '.', '.', 'Y', '.', '.', 'X', '.', 'Y', '.'], ['.', 'X', '.', '.', 'Y', '.', '.', 'X', '.', 'Y'], ['.', '.', 'X', '.', '.', 'Y', '.', '.', 'X', '.'], ['Y', '.', '.', 'X', '.', '.', 'Y', '.', '.', 'X']]) == 12\n assert candidate(grid = [['X', 'X', 'Y', 'Y', 'X', 'X', 'Y', 'Y'], ['Y', 'Y', 'X', 'X', 'Y', 'Y', 'X', 'X'], ['X', 'X', 'Y', 'Y', 'X', 'X', 'Y', 'Y']]) == 12\n assert candidate(grid = [['X', 'Y', 'X', 'Y', 'X'], ['Y', 'X', 'Y', 'X', 'Y'], ['X', 'Y', 'X', 'Y', 'X'], ['Y', 'X', 'Y', 'X', 'Y'], ['X', 'Y', 'X', 'Y', 'X']]) == 16\n assert candidate(grid = [['X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y'], ['Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X'], ['X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y']]) == 16\n assert candidate(grid = [['X', 'Y', '.', 'X'], ['Y', 'X', '.', 'Y'], ['.', '.', '.', '.'], ['X', 'Y', 'X', 'Y']]) == 12\n assert candidate(grid = [['X', 'Y', 'Y', 'Y'], ['X', 'Y', 'X', 'X'], ['X', 'X', 'Y', 'Y'], ['X', 'X', 'X', 'X']]) == 5\n assert candidate(grid = [['.', '.', 'X'], ['Y', 'X', 'Y'], ['X', 'Y', 'X'], ['Y', '.', 'Y']]) == 4\n assert candidate(grid = [['X', '.', 'Y', 'X'], ['Y', 'X', 'Y', 'X'], ['X', 'Y', 'X', '.'], ['.', 'X', 'Y', 'X']]) == 4\n assert candidate(grid = [['.', '.', '.', '.'], ['.', 'X', 'Y', '.'], ['.', 'Y', 'X', '.'], ['.', '.', '.', '.']]) == 8\n assert candidate(grid = [['.', '.', 'X', 'Y', '.'], ['X', 'Y', 'X', 'Y', 'X'], ['Y', 'X', 'Y', 'X', 'Y'], ['.', 'X', 'Y', 'X', 'Y']]) == 10\n assert candidate(grid = [['X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y', 'X', 'Y']]) == 10\n", "comparison": "exact"}, "public_tests": ["[[\"X\",\"Y\",\".\"],[\"Y\",\".\",\".\"]]", "[[\"X\",\"X\"],[\"X\",\"Y\"]]", "[[\".\",\".\"],[\".\",\".\"]]"], "hints": ["Replace ’X’ with 1, ’Y’ with -1 and ’.’ with 0.", "You need to find how many submatrices grid[0..x][0..y] have a sum of 0 and at least one ’X’.", "Use prefix sum to calculate submatrices sum."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().numberOfSubmatrices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:06+00:00", "tests_total": 45, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_submatrices(grid)", "container": null, "callable": "number_of_submatrices", "parameters": [{"name": "grid", "type": "Character[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3213, "task_id": "construct-string-with-minimum-cost", "difficulty": "Hard", "problem_description": "You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length.\n\nImagine an empty string s.\n\nYou can perform the following operation any number of times (including zero):\n\n- Choose an index i in the range [0, words.length - 1].\n- Append words[i] to s.\n- The cost of operation is costs[i].\n\nReturn the minimum cost to make s equal to target. If it's not possible, return -1.\n\nExample 1:\n\nInput: target = \"abcdef\", words = [\"abdef\",\"abc\",\"d\",\"def\",\"ef\"], costs = [100,1,1,10,5]\nOutput: 7\nExplanation:\nThe minimum cost can be achieved by performing the following operations:\n- Select index 1 and append \"abc\" to s at a cost of 1, resulting in s = \"abc\".\n- Select index 2 and append \"d\" to s at a cost of 1, resulting in s = \"abcd\".\n- Select index 4 and append \"ef\" to s at a cost of 5, resulting in s = \"abcdef\".\n\nExample 2:\n\nInput: target = \"aaaa\", words = [\"z\",\"zz\",\"zzz\"], costs = [1,10,100]\nOutput: -1\nExplanation:\nIt is impossible to make s equal to target, so we return -1.\n\nConstraints:\n\n- 1 <= target.length <= 5 * 10^4\n- 1 <= words.length == costs.length <= 5 * 10^4\n- 1 <= words[i].length <= target.length\n- The total sum of words[i].length is less than or equal to 5 * 10^4.\n- target and words[i] consist only of lowercase English letters.\n- 1 <= costs[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(target = \"xyz\",words = ['x', 'y', 'z'],costs = [1, 2, 3]) == 6\n assert candidate(target = \"abcd\",words = ['a', 'b', 'c', 'd'],costs = [1, 1, 1, 1]) == 4\n assert candidate(target = \"zzzz\",words = ['zz', 'zzzz'],costs = [2, 1]) == 1\n assert candidate(target = \"programming\",words = ['pro', 'gram', 'ming'],costs = [10, 20, 30]) == 60\n assert candidate(target = \"python\",words = ['py', 'th', 'on'],costs = [5, 7, 8]) == 20\n assert candidate(target = \"abacaba\",words = ['a', 'b', 'c'],costs = [1, 2, 3]) == 11\n assert candidate(target = \"hello\",words = ['he', 'll', 'o'],costs = [3, 5, 2]) == 10\n assert candidate(target = \"abcabc\",words = ['abc', 'ab', 'c'],costs = [5, 3, 2]) == 10\n assert candidate(target = \"abc\",words = ['a', 'b', 'c'],costs = [1, 2, 3]) == 6\n assert candidate(target = \"hello\",words = ['h', 'he', 'hel', 'hell', 'hello'],costs = [5, 4, 3, 2, 1]) == 1\n assert candidate(target = \"xyz\",words = ['xy', 'y', 'z'],costs = [5, 3, 2]) == 7\n assert candidate(target = \"aabbcc\",words = ['aa', 'bb', 'cc'],costs = [1, 1, 1]) == 3\n assert candidate(target = \"abcabcabc\",words = ['abc', 'bc', 'c'],costs = [3, 2, 1]) == 9\n assert candidate(target = \"abcde\",words = ['a', 'bc', 'de'],costs = [2, 3, 4]) == 9\n assert candidate(target = \"abcabc\",words = ['abc', 'ab', 'c'],costs = [3, 2, 1]) == 6\n assert candidate(target = \"zzzzz\",words = ['z', 'zz', 'zzz'],costs = [1, 1, 1]) == 2\n assert candidate(target = \"xyz\",words = ['xy', 'yz', 'x'],costs = [2, 3, 1]) == 4\n assert candidate(target = \"aaaa\",words = ['z', 'zz', 'zzz'],costs = [1, 10, 100]) == -1\n assert candidate(target = \"world\",words = ['w', 'o', 'r', 'l', 'd'],costs = [2, 3, 4, 5, 6]) == 20\n assert candidate(target = \"aabbcc\",words = ['aa', 'bb', 'cc'],costs = [3, 4, 5]) == 12\n assert candidate(target = \"abcdef\",words = ['abdef', 'abc', 'd', 'def', 'ef'],costs = [100, 1, 1, 10, 5]) == 7\n assert candidate(target = \"ababab\",words = ['ab', 'aba', 'bab'],costs = [3, 4, 5]) == 9\n assert candidate(target = \"testcase\",words = ['tes', 't', 'case'],costs = [10, 2, 5]) == 17\n assert candidate(target = \"abcde\",words = ['a', 'bc', 'de'],costs = [1, 2, 3]) == 6\n assert candidate(target = \"abcdefgabcdefg\",words = ['abc', 'def', 'g', 'abcde', 'fg'],costs = [6, 7, 1, 5, 3]) == 16\n assert candidate(target = \"aaaabbbbcccc\",words = ['a', 'aa', 'aaa', 'aaaa', 'b', 'bb', 'bbb', 'bbbb', 'c', 'cc', 'ccc', 'cccc'],costs = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 12\n assert candidate(target = \"xyxxyxyxyx\",words = ['xy', 'yx', 'xxy', 'xyx'],costs = [1, 2, 3, 4]) == 9\n assert candidate(target = \"zzzzzzzzzz\",words = ['z', 'zz', 'zzz', 'zzzz', 'zzzzz'],costs = [1, 3, 5, 7, 9]) == 10\n assert candidate(target = \"mnopqr\",words = ['mno', 'pqr', 'mnop', 'qr', 'qrs'],costs = [5, 6, 3, 8, 2]) == 11\n assert candidate(target = \"xyzxyzxyz\",words = ['xyz', 'xy', 'xz', 'yz'],costs = [10, 5, 6, 7]) == 30\n assert candidate(target = \"aaaabbbbccccdddd\",words = ['aaa', 'bbb', 'ccc', 'ddd', 'abcd'],costs = [10, 15, 20, 25, 30]) == -1\n assert candidate(target = \"zzzzzzzzzzzzzzzzzzzz\",words = ['zz', 'zzz', 'zzzz', 'zzzzz', 'zzzzzz'],costs = [1, 2, 3, 4, 5]) == 10\n assert candidate(target = \"hellohello\",words = ['he', 'll', 'o', 'hello'],costs = [3, 2, 1, 5]) == 10\n assert candidate(target = \"zzzzzzzzzz\",words = ['z', 'zz', 'zzz', 'zzzz'],costs = [1, 3, 6, 10]) == 10\n assert candidate(target = \"helloworld\",words = ['he', 'll', 'lo', 'wor', 'orl', 'ld'],costs = [1, 2, 3, 4, 5, 6]) == -1\n assert candidate(target = \"zzzzzzzzzzzz\",words = ['zz', 'zzz', 'z'],costs = [4, 2, 7]) == 8\n assert candidate(target = \"abcabcabcabc\",words = ['abc', 'cab', 'bca'],costs = [10, 20, 30]) == 40\n assert candidate(target = \"abcdabcdabcd\",words = ['abcd', 'ab', 'cd', 'abc'],costs = [10, 5, 3, 8]) == 24\n assert candidate(target = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",words = ['aabb', 'ccdd', 'eef', 'gghh', 'iijj', 'kkl', 'mnoon', 'popp', 'qqr', 'rss', 'ttu', 'vvww', 'xxy', 'yzz'],costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == -1\n assert candidate(target = \"abcdefghi\",words = ['abc', 'def', 'ghi', 'abcd', 'efgh', 'hij', 'abcd'],costs = [10, 20, 30, 15, 25, 35, 5]) == 60\n assert candidate(target = \"aabbaabbccddcc\",words = ['aa', 'bb', 'cc', 'dd'],costs = [1, 2, 3, 4]) == 16\n assert candidate(target = \"xyxyxyxyxyxy\",words = ['xy', 'yx', 'xxyy'],costs = [10, 5, 20]) == 60\n assert candidate(target = \"zzzzzzzzzzzz\",words = ['zzz', 'zzzz', 'zz', 'z'],costs = [15, 10, 8, 5]) == 30\n assert candidate(target = \"mississippi\",words = ['mis', 'issi', 'ppi', 'ippi', 'pi'],costs = [10, 12, 5, 8, 3]) == -1\n assert candidate(target = \"abcdefghijklmnop\",words = ['abcdefghijklmno', 'p', 'abcdefghijk', 'lmnop'],costs = [100, 1, 50, 50]) == 100\n assert candidate(target = \"aaaaaaaaaa\",words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],costs = [1, 2, 3, 4, 5]) == 10\n assert candidate(target = \"xyzxyzxyz\",words = ['xy', 'z', 'xyz'],costs = [5, 1, 3]) == 9\n assert candidate(target = \"alibaba\",words = ['ali', 'ba', 'ba', 'b', 'a'],costs = [5, 10, 20, 1, 2]) == 11\n assert candidate(target = \"abracadabra\",words = ['a', 'b', 'r', 'ac', 'ad', 'abra'],costs = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(target = \"bbaaccdd\",words = ['bb', 'aa', 'cc', 'dd', 'abcd'],costs = [5, 6, 7, 8, 9]) == 26\n assert candidate(target = \"xylophone\",words = ['xy', 'lo', 'phone', 'pho', 'ne', 'on'],costs = [3, 1, 2, 5, 4, 6]) == 6\n assert candidate(target = \"abcabcabcabc\",words = ['abc', 'ab', 'bc', 'a', 'b', 'c'],costs = [5, 2, 3, 1, 1, 1]) == 12\n assert candidate(target = \"abcdabcdabcd\",words = ['ab', 'bc', 'cd', 'abcd'],costs = [1, 2, 3, 4]) == 12\n assert candidate(target = \"aaaaaaaaaa\",words = ['a', 'aa', 'aaa', 'aaaa'],costs = [5, 3, 2, 1]) == 5\n assert candidate(target = \"abcdefghijk\",words = ['abc', 'def', 'gh', 'ijk'],costs = [10, 20, 30, 40]) == 100\n assert candidate(target = \"abracadabra\",words = ['abr', 'aca', 'dab', 'ra'],costs = [10, 20, 30, 5]) == 65\n assert candidate(target = \"abcdefghij\",words = ['ab', 'cde', 'fgh', 'ij'],costs = [2, 3, 4, 1]) == 10\n assert candidate(target = \"abcdefghijklmnopqrstuvwxyz\",words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],costs = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 450\n assert candidate(target = \"xyzabc\",words = ['xy', 'zabc', 'xyz', 'ab', 'c'],costs = [5, 10, 3, 7, 2]) == 12\n assert candidate(target = \"aabbccddeeff\",words = ['aabb', 'ccdd', 'eeff', 'abcd'],costs = [10, 15, 20, 25]) == 45\n assert candidate(target = \"zzzzzzzzzzz\",words = ['zz', 'zzz', 'zzzz'],costs = [2, 5, 7]) == 13\n assert candidate(target = \"zzzzzzzzzzzzzzzzzzzz\",words = ['z', 'zz', 'zzz', 'zzzz'],costs = [1, 2, 3, 4]) == 20\n assert candidate(target = \"xyxzyzyxzyzyxzyx\",words = ['xyx', 'zyz', 'yx', 'xyz'],costs = [7, 6, 5, 4]) == -1\n assert candidate(target = \"aaaaabbbbb\",words = ['a', 'b', 'ab', 'ba'],costs = [1, 2, 3, 4]) == 15\n assert candidate(target = \"mississippi\",words = ['mis', 'issi', 'ppi', 'ss', 'ippi', 's', 'i', 'm'],costs = [1, 3, 5, 1, 2, 2, 1, 1]) == 7\n assert candidate(target = \"hellohello\",words = ['he', 'llo', 'ell', 'o'],costs = [2, 3, 1, 4]) == 10\n assert candidate(target = \"pppppppppp\",words = ['p', 'pp', 'ppp'],costs = [10, 5, 3]) == 16\n assert candidate(target = \"zzzzzzzzzzzzzzzzzzzz\",words = ['zzz', 'zz', 'z'],costs = [10, 5, 1]) == 20\n assert candidate(target = \"abcdefghij\",words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(target = \"zzzzzzzzzz\",words = ['zz', 'zzz', 'z'],costs = [1, 2, 10]) == 5\n assert candidate(target = \"aabbccddeeff\",words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff'],costs = [1, 2, 1, 2, 1, 2]) == 9\n assert candidate(target = \"abcdefghi\",words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'],costs = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(target = \"aabbccddeeff\",words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'abcd', 'ef', 'fedc'],costs = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 21\n assert candidate(target = \"zzzzzzzzzzzzzzzzzzzz\",words = ['z', 'zz', 'zzz'],costs = [1, 10, 100]) == 20\n assert candidate(target = \"mnopqr\",words = ['m', 'no', 'pqr', 'op', 'qr', 'mnop', 'nopqr'],costs = [1, 2, 3, 4, 5, 6, 7]) == 6\n assert candidate(target = \"hellohellos\",words = ['he', 'llo', 'hel', 'los', 'o', 's'],costs = [1, 2, 3, 4, 5, 6]) == 10\n assert candidate(target = \"mamamamama\",words = ['ma', 'am'],costs = [2, 1]) == 10\n assert candidate(target = \"abcdabcdabcd\",words = ['abcd', 'abc', 'bca', 'cab', 'dab'],costs = [10, 7, 8, 9, 6]) == 30\n assert candidate(target = \"abcdabcdabcd\",words = ['abcd', 'abc', 'cd', 'd', 'a', 'bc'],costs = [10, 20, 30, 40, 50, 60]) == 30\n assert candidate(target = \"aaaabbbb\",words = ['a', 'aa', 'aaa', 'aaaa'],costs = [4, 3, 2, 1]) == -1\n assert candidate(target = \"abcdefghijklmnop\",words = ['a', 'bc', 'def', 'ghij', 'klmno', 'p'],costs = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(target = \"banana\",words = ['ba', 'an', 'na', 'ana', 'nana', 'banana'],costs = [1, 2, 3, 4, 5, 6]) == 6\n assert candidate(target = \"abcdefghijklmnopqrstuvwxyz\",words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],costs = [3, 5, 4, 7, 6, 8, 9, 2, 1]) == 45\n assert candidate(target = \"mnopqr\",words = ['mno', 'pq', 'r', 'mnopq', 'qrs'],costs = [10, 7, 5, 20, 8]) == 22\n assert candidate(target = \"aaabbbcccddd\",words = ['aaa', 'bbb', 'ccc', 'ddd', 'ab', 'bc', 'cd'],costs = [5, 6, 7, 8, 3, 4, 5]) == 26\n assert candidate(target = \"mississippi\",words = ['mis', 'is', 'sip', 'i', 'p'],costs = [1, 2, 3, 4, 5]) == -1\n assert candidate(target = \"abcdefg\",words = ['abc', 'def', 'g', 'abcd', 'efg'],costs = [10, 20, 5, 15, 25]) == 35\n assert candidate(target = \"aabbccddeeff\",words = ['aab', 'bcc', 'dde', 'eff'],costs = [6, 7, 8, 9]) == 30\n assert candidate(target = \"aaabbbcccddd\",words = ['aaa', 'bbb', 'ccc', 'ddd', 'aab', 'bcc', 'dde'],costs = [10, 11, 12, 13, 9, 8, 7]) == 46\n assert candidate(target = \"abababababab\",words = ['aba', 'bab', 'ab'],costs = [3, 4, 1]) == 6\n assert candidate(target = \"optimization\",words = ['opt', 'im', 'iza', 'tion'],costs = [10, 20, 30, 40]) == 100\n assert candidate(target = \"xyzxyzxyzxyz\",words = ['xyz', 'xy', 'zxyz', 'zxy'],costs = [7, 5, 10, 8]) == 28\n assert candidate(target = \"ababababab\",words = ['aba', 'bab', 'ab', 'ba'],costs = [7, 8, 2, 3]) == 10\n assert candidate(target = \"qwertyuiop\",words = ['qwe', 'rty', 'ui', 'op'],costs = [7, 8, 5, 6]) == 26\n assert candidate(target = \"aaaabbbbccccdddd\",words = ['aaaa', 'bbbb', 'cccc', 'dddd', 'abc', 'bcd', 'cde', 'def'],costs = [4, 5, 6, 7, 8, 9, 10, 11]) == 22\n assert candidate(target = \"abcabcabcabc\",words = ['abc', 'bc', 'ca'],costs = [1, 2, 3]) == 4\n assert candidate(target = \"abcdefghijklmnopqrstuvwxyz\",words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],costs = [10, 15, 20, 25, 30, 35, 40, 45, 50]) == 270\n assert candidate(target = \"abcdefghijklmnopqrstuvwxyz\",words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],costs = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 45\n assert candidate(target = \"xyxyxyxyxy\",words = ['xy', 'yx', 'x', 'y'],costs = [4, 5, 1, 2]) == 15\n assert candidate(target = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', 'tt', 'uu', 'vv', 'ww', 'xx', 'yy', 'zz'],costs = [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]) == 351\n assert candidate(target = \"abcdefghij\",words = ['abc', 'def', 'ghi', 'j', 'abcdefgh'],costs = [12, 15, 20, 5, 100]) == 52\n assert candidate(target = \"abcdefghijklmnopqrstuvwxyz\",words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],costs = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(target = \"ababababab\",words = ['ab', 'aba', 'bab', 'aab'],costs = [100, 200, 300, 400]) == 500\n assert candidate(target = \"mississippi\",words = ['i', 's', 'p', 'is', 'pi', 'sis', 'issi'],costs = [1, 2, 3, 4, 5, 6, 7]) == -1\n assert candidate(target = \"ababababab\",words = ['ab', 'aba', 'bab', 'ba'],costs = [1, 3, 2, 4]) == 5\n assert candidate(target = \"aabbccddeeff\",words = ['ab', 'bc', 'cd', 'de', 'ef', 'fe', 'dc', 'cb', 'ba', 'aa', 'bb', 'cc', 'dd', 'ee', 'ff'],costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 75\n assert candidate(target = \"lmnopqrstu\",words = ['lmn', 'opq', 'rst', 'u'],costs = [1, 2, 3, 4]) == 10\n assert candidate(target = \"aabbccddeeffgghhiijj\",words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj'],costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(target = \"ababababab\",words = ['aba', 'bab', 'ab', 'ba'],costs = [4, 5, 2, 3]) == 10\n assert candidate(target = \"xyxxyxyxyx\",words = ['xy', 'xxy', 'xyx', 'yxy'],costs = [5, 7, 6, 8]) == 22\n assert candidate(target = \"mississippi\",words = ['mis', 'issi', 'ppi', 'i', 'pi', 'miss', 'ippi'],costs = [3, 4, 2, 1, 5, 6, 7]) == 12\n assert candidate(target = \"aaaaaaaabaaaaaaa\",words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],costs = [1, 3, 5, 7, 9]) == -1\n assert candidate(target = \"abcdefghijklmnop\",words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],costs = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -1\n assert candidate(target = \"ababababab\",words = ['ab', 'aba', 'bab', 'ba', 'a', 'b'],costs = [2, 3, 4, 1, 5, 6]) == 9\n assert candidate(target = \"abcdefgabcdefg\",words = ['abc', 'def', 'gh', 'abcdef', 'gh', 'abcdefg'],costs = [10, 20, 30, 5, 50, 60]) == 120\n assert candidate(target = \"abcabcabcabcabcabc\",words = ['abc', 'abca', 'bcab', 'cabc', 'bca'],costs = [1, 2, 3, 4, 5]) == 6\n assert candidate(target = \"abacabadabacaba\",words = ['aba', 'cab', 'abc', 'bac'],costs = [3, 5, 2, 4]) == -1\n assert candidate(target = \"qwertyqwerty\",words = ['qw', 'er', 'ty', 'rt', 'yt'],costs = [1, 2, 3, 4, 5]) == 12\n assert candidate(target = \"abcabcabcabcabc\",words = ['ab', 'bc', 'ca', 'abc'],costs = [2, 1, 5, 3]) == 15\n assert candidate(target = \"abcabcabcabcabcabc\",words = ['abc', 'abcabc', 'abcabcabc', 'a', 'b', 'c'],costs = [10, 20, 30, 1, 2, 3]) == 36\n assert candidate(target = \"qwertyuiopasdfghjklzxcvbnm\",words = ['qwerty', 'uiop', 'asdf', 'ghjk', 'lzx', 'cvbn', 'm', 'qwer', 'tyui', 'opas', 'dfgh', 'jklz', 'xcvb', 'bnm'],costs = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 105\n assert candidate(target = \"abacabadabacaba\",words = ['aba', 'abac', 'abacaba', 'abacabad', 'abacabadaba'],costs = [5, 10, 15, 20, 25]) == 35\n", "comparison": "exact"}, "public_tests": ["\"abcdef\"\n[\"abdef\",\"abc\",\"d\",\"def\",\"ef\"]\n[100,1,1,10,5]", "\"aaaa\"\n[\"z\",\"zz\",\"zzz\"]\n[1,10,100]"], "hints": ["Use Dynamic Programming along with Aho-Corasick or Hashing."], "metadata": {"canonical_parameter_names": ["target", "words", "costs"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:09+00:00", "tests_total": 123, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "string", "dynamic-programming", "suffix-array"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(target, words, costs)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "target", "type": "String"}, {"name": "words", "type": "String[]"}, {"name": "costs", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3216, "task_id": "lexicographically-smallest-string-after-a-swap", "difficulty": "Easy", "problem_description": "Given a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once.\n\nDigits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.\n\nExample 1:\n\nInput: s = \"45320\"\nOutput: \"43520\"\nExplanation:\ns[1] == '5' and s[2] == '3' both have the same parity, and swapping them results in the lexicographically smallest string.\n\nExample 2:\n\nInput: s = \"001\"\nOutput: \"001\"\nExplanation:\nThere is no need to perform a swap because s is already the lexicographically smallest.\n\nConstraints:\n\n- 2 <= s.length <= 100\n- s consists only of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"9876543210\") == \"9876543210\"\n assert candidate(s = \"1324\") == \"1324\"\n assert candidate(s = \"111222333\") == \"111222333\"\n assert candidate(s = \"1352468709\") == \"1352468709\"\n assert candidate(s = \"2121212121\") == \"2121212121\"\n assert candidate(s = \"1234567890\") == \"1234567890\"\n assert candidate(s = \"9753186420\") == \"7953186420\"\n assert candidate(s = \"22222\") == \"22222\"\n assert candidate(s = \"97531\") == \"79531\"\n assert candidate(s = \"111222\") == \"111222\"\n assert candidate(s = \"001\") == \"001\"\n assert candidate(s = \"87654\") == \"87654\"\n assert candidate(s = \"1111111111\") == \"1111111111\"\n assert candidate(s = \"13579\") == \"13579\"\n assert candidate(s = \"99887766554433221100\") == \"99887766554433221100\"\n assert candidate(s = \"11111\") == \"11111\"\n assert candidate(s = \"34521\") == \"34521\"\n assert candidate(s = \"224466\") == \"224466\"\n assert candidate(s = \"24680\") == \"24608\"\n assert candidate(s = \"45320\") == \"43520\"\n assert candidate(s = \"1212121212\") == \"1212121212\"\n assert candidate(s = \"2222222222\") == \"2222222222\"\n assert candidate(s = \"86420\") == \"68420\"\n assert candidate(s = \"2204466880\") == \"2024466880\"\n assert candidate(s = \"555444333222111000\") == \"555444333222111000\"\n assert candidate(s = \"5937197531\") == \"5397197531\"\n assert candidate(s = \"8642086420\") == \"6842086420\"\n assert candidate(s = \"5432109876543210\") == \"5432109876543210\"\n assert candidate(s = \"9090909090\") == \"9090909090\"\n assert candidate(s = \"3214680975\") == \"3214608975\"\n assert candidate(s = \"555444333\") == \"555444333\"\n assert candidate(s = \"2046813579\") == \"0246813579\"\n assert candidate(s = \"999988887777\") == \"999988887777\"\n assert candidate(s = \"1232123212\") == \"1232123212\"\n assert candidate(s = \"0022446688\") == \"0022446688\"\n assert candidate(s = \"2143658709\") == \"2143658709\"\n assert candidate(s = \"4206813579\") == \"2406813579\"\n assert candidate(s = \"1222333344\") == \"1222333344\"\n assert candidate(s = \"122133445566778899\") == \"122133445566778899\"\n assert candidate(s = \"5937124680\") == \"5397124680\"\n assert candidate(s = \"1010101010\") == \"1010101010\"\n assert candidate(s = \"2718281828\") == \"2178281828\"\n assert candidate(s = \"1098765432\") == \"1098765432\"\n assert candidate(s = \"908070605040302010\") == \"900870605040302010\"\n assert candidate(s = \"98765432100987654321\") == \"98765432100987654321\"\n assert candidate(s = \"02468135791357\") == \"02468135719357\"\n assert candidate(s = \"9080706050\") == \"9008706050\"\n assert candidate(s = \"8642013579\") == \"6842013579\"\n assert candidate(s = \"9753124680\") == \"7953124680\"\n assert candidate(s = \"5973186420\") == \"5793186420\"\n assert candidate(s = \"8888888888\") == \"8888888888\"\n assert candidate(s = \"1122334455\") == \"1122334455\"\n assert candidate(s = \"4444444444\") == \"4444444444\"\n assert candidate(s = \"5432013579\") == \"5430213579\"\n assert candidate(s = \"8642097531\") == \"6842097531\"\n assert candidate(s = \"01234567890123456789\") == \"01234567890123456789\"\n assert candidate(s = \"2020202020\") == \"0220202020\"\n assert candidate(s = \"000011112222\") == \"000011112222\"\n assert candidate(s = \"1020304050\") == \"1002304050\"\n assert candidate(s = \"1357924680\") == \"1357924608\"\n assert candidate(s = \"4206842068\") == \"2406842068\"\n assert candidate(s = \"5555555555\") == \"5555555555\"\n assert candidate(s = \"6284095713\") == \"2684095713\"\n assert candidate(s = \"135792468097531\") == \"135792460897531\"\n assert candidate(s = \"5959595959\") == \"5599595959\"\n assert candidate(s = \"1357902468\") == \"1357902468\"\n assert candidate(s = \"0246813579\") == \"0246813579\"\n assert candidate(s = \"0426813579\") == \"0246813579\"\n assert candidate(s = \"5173924680\") == \"1573924680\"\n assert candidate(s = \"8886664442\") == \"8868664442\"\n assert candidate(s = \"98765432109876543210\") == \"98765432109876543210\"\n assert candidate(s = \"9988776655\") == \"9988776655\"\n assert candidate(s = \"2468024680\") == \"2460824680\"\n assert candidate(s = \"7931524860\") == \"7391524860\"\n assert candidate(s = \"6283185307\") == \"2683185307\"\n assert candidate(s = \"111222333444555666777888999\") == \"111222333444555666777888999\"\n assert candidate(s = \"3141592653\") == \"1341592653\"\n assert candidate(s = \"3852764190\") == \"3852746190\"\n assert candidate(s = \"22446688001133557799\") == \"22446680801133557799\"\n assert candidate(s = \"3658742910\") == \"3658724910\"\n assert candidate(s = \"9876543211\") == \"9876543211\"\n assert candidate(s = \"222221111\") == \"222221111\"\n assert candidate(s = \"6868686868\") == \"6688686868\"\n assert candidate(s = \"4826035791\") == \"4286035791\"\n assert candidate(s = \"4443332221\") == \"4443332221\"\n assert candidate(s = \"9182736450\") == \"1982736450\"\n assert candidate(s = \"24680246802468024680\") == \"24608246802468024680\"\n assert candidate(s = \"8064213579\") == \"0864213579\"\n assert candidate(s = \"5678904321\") == \"5678904321\"\n assert candidate(s = \"0123456789\") == \"0123456789\"\n assert candidate(s = \"2200446688\") == \"2020446688\"\n assert candidate(s = \"3322110099\") == \"3322110099\"\n assert candidate(s = \"8976543210\") == \"8796543210\"\n assert candidate(s = \"1133557799\") == \"1133557799\"\n assert candidate(s = \"1357913579\") == \"1357193579\"\n assert candidate(s = \"9864213579\") == \"9684213579\"\n assert candidate(s = \"999888777666555444333222111\") == \"999888777666555444333222111\"\n assert candidate(s = \"9999999999\") == \"9999999999\"\n assert candidate(s = \"5432109876\") == \"5432109876\"\n assert candidate(s = \"4321056789\") == \"4321056789\"\n assert candidate(s = \"1235467890\") == \"1235467890\"\n assert candidate(s = \"35791\") == \"35719\"\n assert candidate(s = \"0246802468\") == \"0246082468\"\n assert candidate(s = \"3131313131\") == \"1331313131\"\n assert candidate(s = \"0987654321\") == \"0987654321\"\n assert candidate(s = \"5024019292\") == \"5020419292\"\n assert candidate(s = \"999888777\") == \"999888777\"\n assert candidate(s = \"0909090909\") == \"0909090909\"\n assert candidate(s = \"4442220006\") == \"4424220006\"\n assert candidate(s = \"2468013579\") == \"2460813579\"\n assert candidate(s = \"123456789987654321\") == \"123456789987654321\"\n assert candidate(s = \"01010101010101010101\") == \"01010101010101010101\"\n assert candidate(s = \"8192837465\") == \"8192837465\"\n assert candidate(s = \"102030405060708090\") == \"100230405060708090\"\n assert candidate(s = \"5432101234\") == \"5432101234\"\n assert candidate(s = \"000999888\") == \"000999888\"\n assert candidate(s = \"1246835790\") == \"1246835790\"\n assert candidate(s = \"10101010101010101010\") == \"10101010101010101010\"\n assert candidate(s = \"4040404040\") == \"0440404040\"\n assert candidate(s = \"5937186420\") == \"5397186420\"\n assert candidate(s = \"7777777777\") == \"7777777777\"\n assert candidate(s = \"6789012345\") == \"6789012345\"\n assert candidate(s = \"2468097531\") == \"2460897531\"\n assert candidate(s = \"2132132132\") == \"2132132132\"\n", "comparison": "exact"}, "public_tests": ["\"45320\"", "\"001\""], "hints": ["Try all possible swaps satisfying the constraints and find the one that results in the lexicographically smallest string."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:14+00:00", "tests_total": 124, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "ruby", "interface": {"raw_signature": "def get_smallest_string(s)", "container": null, "callable": "get_smallest_string", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3218, "task_id": "minimum-cost-for-cutting-cake-i", "difficulty": "Medium", "problem_description": "There is an m x n cake that needs to be cut into 1 x 1 pieces.\n\nYou are given integers m, n, and two arrays:\n\n- horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.\n- verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line j.\n\nIn one operation, you can choose any piece of cake that is not yet a 1 x 1 square and perform one of the following cuts:\n\n1. Cut along a horizontal line i at a cost of horizontalCut[i].\n2. Cut along a vertical line j at a cost of verticalCut[j].\n\nAfter the cut, the piece of cake is divided into two distinct pieces.\n\nThe cost of a cut depends only on the initial cost of the line and does not change.\n\nReturn the minimum total cost to cut the entire cake into 1 x 1 pieces.\n\nExample 1:\n\nInput: m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]\nOutput: 13\nExplanation:\n- Perform a cut on the vertical line 0 with cost 5, current total cost is 5.\n- Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n- Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n- Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n- Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n\nThe total cost is 5 + 1 + 1 + 3 + 3 = 13.\n\nExample 2:\n\nInput: m = 2, n = 2, horizontalCut = [7], verticalCut = [4]\nOutput: 15\nExplanation:\n- Perform a cut on the horizontal line 0 with cost 7.\n- Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n- Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n\nThe total cost is 7 + 4 + 4 = 15.\n\nConstraints:\n\n- 1 <= m, n <= 20\n- horizontalCut.length == m - 1\n- verticalCut.length == n - 1\n- 1 <= horizontalCut[i], verticalCut[i] <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 4,horizontalCut = [1, 2, 3, 4],verticalCut = [2, 4, 6]) == 49\n assert candidate(m = 4,n = 3,horizontalCut = [2, 5, 7],verticalCut = [3, 8]) == 47\n assert candidate(m = 2,n = 2,horizontalCut = [7],verticalCut = [4]) == 15\n assert candidate(m = 4,n = 3,horizontalCut = [1, 2, 3],verticalCut = [1, 2]) == 17\n assert candidate(m = 5,n = 4,horizontalCut = [1, 4, 6, 8],verticalCut = [2, 3, 5]) == 61\n assert candidate(m = 6,n = 5,horizontalCut = [1, 3, 5, 7, 9],verticalCut = [2, 4, 6, 8]) == 115\n assert candidate(m = 3,n = 3,horizontalCut = [1, 2],verticalCut = [1, 2]) == 11\n assert candidate(m = 5,n = 4,horizontalCut = [1, 2, 3, 4],verticalCut = [1, 2, 3]) == 36\n assert candidate(m = 5,n = 4,horizontalCut = [1, 3, 6, 9],verticalCut = [2, 4, 7]) == 68\n assert candidate(m = 3,n = 2,horizontalCut = [1, 3],verticalCut = [5]) == 13\n assert candidate(m = 4,n = 3,horizontalCut = [2, 5, 7],verticalCut = [1, 6]) == 37\n assert candidate(m = 4,n = 3,horizontalCut = [2, 4, 6],verticalCut = [1, 3]) == 27\n assert candidate(m = 10,n = 10,horizontalCut = [3, 6, 9, 12, 15, 18, 21, 24, 27],verticalCut = [2, 5, 8, 11, 14, 17, 20, 23, 26]) == 1071\n assert candidate(m = 7,n = 6,horizontalCut = [1, 3, 5, 7, 9, 11],verticalCut = [2, 4, 6, 8, 10]) == 191\n assert candidate(m = 12,n = 12,horizontalCut = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],verticalCut = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == 1199\n assert candidate(m = 8,n = 7,horizontalCut = [2, 4, 6, 8, 10, 12, 14],verticalCut = [1, 3, 5, 7, 9, 11]) == 289\n assert candidate(m = 19,n = 14,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 1536\n assert candidate(m = 10,n = 10,horizontalCut = [2, 4, 6, 8, 10, 12, 14, 16, 18],verticalCut = [3, 6, 9, 12, 15, 18, 21, 24, 27]) == 888\n assert candidate(m = 20,n = 20,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 2850\n assert candidate(m = 16,n = 14,horizontalCut = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],verticalCut = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65]) == 7675\n assert candidate(m = 16,n = 14,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 1212\n assert candidate(m = 20,n = 15,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 1835\n assert candidate(m = 15,n = 15,horizontalCut = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70],verticalCut = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70]) == 6125\n assert candidate(m = 12,n = 9,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8]) == 414\n assert candidate(m = 7,n = 9,horizontalCut = [3, 6, 9, 12, 15, 18],verticalCut = [2, 4, 6, 8, 10, 12, 14, 16]) == 465\n", "comparison": "exact"}, "public_tests": ["3\n2\n[1,3]\n[5]", "2\n2\n[7]\n[4]"], "hints": ["The intended solution uses Dynamic Programming.", "Let dp[sx][sy][tx][ty] denote the minimum cost to cut the rectangle into 1 x 1 pieces.", "Iterate on the row or column on which you will perform the next cut, after the cut, the current rectangle will be decomposed into two sub-rectangles."], "metadata": {"canonical_parameter_names": ["m", "n", "horizontalCut", "verticalCut"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:19+00:00", "tests_total": 55, "tests_dropped": 30, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "dynamic-programming", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(m, n, horizontal_cut, vertical_cut)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "horizontal_cut", "type": "Integer[]"}, {"name": "vertical_cut", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3219, "task_id": "minimum-cost-for-cutting-cake-ii", "difficulty": "Hard", "problem_description": "There is an m x n cake that needs to be cut into 1 x 1 pieces.\n\nYou are given integers m, n, and two arrays:\n\n- horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i.\n- verticalCut of size n - 1, where verticalCut[j] represents the cost to cut along the vertical line j.\n\nIn one operation, you can choose any piece of cake that is not yet a 1 x 1 square and perform one of the following cuts:\n\n1. Cut along a horizontal line i at a cost of horizontalCut[i].\n2. Cut along a vertical line j at a cost of verticalCut[j].\n\nAfter the cut, the piece of cake is divided into two distinct pieces.\n\nThe cost of a cut depends only on the initial cost of the line and does not change.\n\nReturn the minimum total cost to cut the entire cake into 1 x 1 pieces.\n\nExample 1:\n\nInput: m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]\nOutput: 13\nExplanation:\n- Perform a cut on the vertical line 0 with cost 5, current total cost is 5.\n- Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n- Perform a cut on the horizontal line 0 on 3 x 1 subgrid with cost 1.\n- Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n- Perform a cut on the horizontal line 1 on 2 x 1 subgrid with cost 3.\n\nThe total cost is 5 + 1 + 1 + 3 + 3 = 13.\n\nExample 2:\n\nInput: m = 2, n = 2, horizontalCut = [7], verticalCut = [4]\nOutput: 15\nExplanation:\n- Perform a cut on the horizontal line 0 with cost 7.\n- Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n- Perform a cut on the vertical line 0 on 1 x 2 subgrid with cost 4.\n\nThe total cost is 7 + 4 + 4 = 15.\n\nConstraints:\n\n- 1 <= m, n <= 10^5\n- horizontalCut.length == m - 1\n- verticalCut.length == n - 1\n- 1 <= horizontalCut[i], verticalCut[i] <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 2,n = 2,horizontalCut = [7],verticalCut = [4]) == 15\n assert candidate(m = 4,n = 3,horizontalCut = [1, 2, 3],verticalCut = [1, 2]) == 17\n assert candidate(m = 3,n = 3,horizontalCut = [1, 2],verticalCut = [1, 2]) == 11\n assert candidate(m = 5,n = 4,horizontalCut = [1, 2, 3, 4],verticalCut = [1, 2, 3]) == 36\n assert candidate(m = 6,n = 3,horizontalCut = [1, 2, 3, 4, 5],verticalCut = [1, 2]) == 32\n assert candidate(m = 3,n = 2,horizontalCut = [1, 3],verticalCut = [5]) == 13\n assert candidate(m = 15,n = 10,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 660\n assert candidate(m = 8,n = 12,horizontalCut = [1, 2, 3, 4, 5, 6, 7],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 346\n assert candidate(m = 8,n = 12,horizontalCut = [1, 2, 3, 4, 5, 6, 7],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 346\n assert candidate(m = 15,n = 15,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 1225\n assert candidate(m = 10,n = 10,horizontalCut = [1, 3, 5, 7, 9, 11, 13, 15, 17],verticalCut = [2, 4, 6, 8, 10, 12, 14, 16, 18]) == 696\n assert candidate(m = 8,n = 7,horizontalCut = [1, 3, 5, 7, 9, 11, 13],verticalCut = [2, 4, 6, 8, 10, 12]) == 294\n assert candidate(m = 7,n = 8,horizontalCut = [10, 20, 30, 40, 50, 60],verticalCut = [5, 10, 15, 20, 25, 30, 35]) == 1080\n assert candidate(m = 9,n = 11,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 367\n assert candidate(m = 12,n = 8,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],verticalCut = [1, 2, 3, 4, 5, 6, 7]) == 346\n assert candidate(m = 10,n = 10,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 375\n assert candidate(m = 9,n = 9,horizontalCut = [5, 10, 15, 20, 25, 30, 35, 40],verticalCut = [5, 10, 15, 20, 25, 30, 35, 40]) == 1380\n assert candidate(m = 8,n = 6,horizontalCut = [1, 2, 3, 4, 5, 6, 7],verticalCut = [1, 2, 3, 4, 5]) == 128\n assert candidate(m = 12,n = 11,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 561\n assert candidate(m = 100,n = 100,horizontalCut = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],verticalCut = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == 338250\n assert candidate(m = 99,n = 100,horizontalCut = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98],verticalCut = [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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == 333201\n assert candidate(m = 8,n = 8,horizontalCut = [1, 2, 3, 4, 5, 6, 7],verticalCut = [1, 2, 3, 4, 5, 6, 7]) == 196\n assert candidate(m = 10,n = 10,horizontalCut = [10, 20, 30, 40, 50, 60, 70, 80, 90],verticalCut = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 3750\n assert candidate(m = 10,n = 10,horizontalCut = [1, 9, 2, 8, 3, 7, 4, 6, 5],verticalCut = [1, 9, 2, 8, 3, 7, 4, 6, 5]) == 375\n assert candidate(m = 10,n = 10,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 375\n assert candidate(m = 15,n = 10,horizontalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],verticalCut = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 660\n", "comparison": "exact"}, "public_tests": ["3\n2\n[1,3]\n[5]", "2\n2\n[7]\n[4]"], "hints": ["The intended solution uses a Greedy approach.", "At each step, we will perform a cut on the line with the highest cost.", "If you perform a horizontal cut, can you count the contribution that it adds to each row cut that comes afterward?"], "metadata": {"canonical_parameter_names": ["m", "n", "horizontalCut", "verticalCut"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:22+00:00", "tests_total": 27, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "greedy", "sorting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_cost(m, n, horizontal_cut, vertical_cut)", "container": null, "callable": "minimum_cost", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "horizontal_cut", "type": "Integer[]"}, {"name": "vertical_cut", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3222, "task_id": "find-the-winning-player-in-coin-game", "difficulty": "Easy", "problem_description": "You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively.\n\nAlice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value 115. If the player is unable to do so, they lose the game.\n\nReturn the name of the player who wins the game if both players play optimally.\n\nExample 1:\n\nInput: x = 2, y = 7\nOutput: \"Alice\"\nExplanation:\nThe game ends in a single turn:\n- Alice picks 1 coin with a value of 75 and 4 coins with a value of 10.\n\nExample 2:\n\nInput: x = 4, y = 11\nOutput: \"Bob\"\nExplanation:\nThe game ends in 2 turns:\n- Alice picks 1 coin with a value of 75 and 4 coins with a value of 10.\n- Bob picks 1 coin with a value of 75 and 4 coins with a value of 10.\n\nConstraints:\n\n- 1 <= x, y <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(x = 100,y = 1) == \"Bob\"\n assert candidate(x = 1,y = 100) == \"Alice\"\n assert candidate(x = 1,y = 10) == \"Alice\"\n assert candidate(x = 4,y = 11) == \"Bob\"\n assert candidate(x = 2,y = 7) == \"Alice\"\n assert candidate(x = 5,y = 5) == \"Alice\"\n assert candidate(x = 10,y = 1) == \"Bob\"\n assert candidate(x = 100,y = 100) == \"Alice\"\n assert candidate(x = 1,y = 1) == \"Bob\"\n assert candidate(x = 3,y = 5) == \"Alice\"\n assert candidate(x = 50,y = 50) == \"Bob\"\n assert candidate(x = 30,y = 50) == \"Bob\"\n assert candidate(x = 65,y = 48) == \"Bob\"\n assert candidate(x = 10,y = 30) == \"Alice\"\n assert candidate(x = 20,y = 5) == \"Alice\"\n assert candidate(x = 90,y = 5) == \"Alice\"\n assert candidate(x = 15,y = 20) == \"Alice\"\n assert candidate(x = 30,y = 30) == \"Alice\"\n assert candidate(x = 1,y = 99) == \"Alice\"\n assert candidate(x = 75,y = 75) == \"Bob\"\n assert candidate(x = 22,y = 33) == \"Bob\"\n assert candidate(x = 27,y = 8) == \"Bob\"\n assert candidate(x = 20,y = 80) == \"Bob\"\n assert candidate(x = 75,y = 5) == \"Alice\"\n assert candidate(x = 5,y = 50) == \"Alice\"\n assert candidate(x = 30,y = 60) == \"Alice\"\n assert candidate(x = 33,y = 27) == \"Bob\"\n assert candidate(x = 10,y = 100) == \"Bob\"\n assert candidate(x = 25,y = 25) == \"Bob\"\n assert candidate(x = 80,y = 20) == \"Alice\"\n assert candidate(x = 25,y = 30) == \"Alice\"\n assert candidate(x = 8,y = 17) == \"Bob\"\n assert candidate(x = 30,y = 25) == \"Bob\"\n assert candidate(x = 99,y = 1) == \"Bob\"\n assert candidate(x = 5,y = 2) == \"Bob\"\n assert candidate(x = 33,y = 66) == \"Bob\"\n assert candidate(x = 5,y = 60) == \"Alice\"\n assert candidate(x = 5,y = 95) == \"Alice\"\n assert candidate(x = 15,y = 25) == \"Bob\"\n assert candidate(x = 15,y = 70) == \"Alice\"\n assert candidate(x = 55,y = 55) == \"Alice\"\n assert candidate(x = 10,y = 15) == \"Alice\"\n assert candidate(x = 25,y = 50) == \"Bob\"\n assert candidate(x = 20,y = 25) == \"Bob\"\n assert candidate(x = 33,y = 50) == \"Bob\"\n assert candidate(x = 20,y = 30) == \"Alice\"\n assert candidate(x = 45,y = 55) == \"Alice\"\n assert candidate(x = 10,y = 10) == \"Bob\"\n assert candidate(x = 5,y = 10) == \"Bob\"\n assert candidate(x = 5,y = 20) == \"Alice\"\n assert candidate(x = 20,y = 15) == \"Alice\"\n assert candidate(x = 30,y = 70) == \"Alice\"\n assert candidate(x = 7,y = 3) == \"Bob\"\n assert candidate(x = 25,y = 75) == \"Bob\"\n assert candidate(x = 99,y = 99) == \"Bob\"\n assert candidate(x = 7,y = 14) == \"Alice\"\n assert candidate(x = 99,y = 100) == \"Alice\"\n assert candidate(x = 60,y = 40) == \"Bob\"\n assert candidate(x = 25,y = 100) == \"Alice\"\n assert candidate(x = 5,y = 90) == \"Alice\"\n assert candidate(x = 100,y = 50) == \"Bob\"\n assert candidate(x = 25,y = 20) == \"Alice\"\n assert candidate(x = 50,y = 30) == \"Alice\"\n assert candidate(x = 5,y = 15) == \"Alice\"\n assert candidate(x = 3,y = 25) == \"Alice\"\n assert candidate(x = 10,y = 75) == \"Bob\"\n assert candidate(x = 50,y = 100) == \"Alice\"\n assert candidate(x = 42,y = 13) == \"Alice\"\n assert candidate(x = 50,y = 5) == \"Alice\"\n assert candidate(x = 75,y = 10) == \"Bob\"\n assert candidate(x = 15,y = 40) == \"Bob\"\n assert candidate(x = 3,y = 8) == \"Bob\"\n assert candidate(x = 80,y = 30) == \"Alice\"\n assert candidate(x = 8,y = 3) == \"Bob\"\n assert candidate(x = 20,y = 50) == \"Bob\"\n assert candidate(x = 30,y = 5) == \"Alice\"\n assert candidate(x = 10,y = 2) == \"Bob\"\n assert candidate(x = 6,y = 2) == \"Bob\"\n assert candidate(x = 10,y = 20) == \"Alice\"\n assert candidate(x = 7,y = 6) == \"Alice\"\n assert candidate(x = 7,y = 2) == \"Bob\"\n assert candidate(x = 20,y = 10) == \"Bob\"\n assert candidate(x = 8,y = 15) == \"Alice\"\n assert candidate(x = 5,y = 3) == \"Bob\"\n assert candidate(x = 3,y = 10) == \"Bob\"\n assert candidate(x = 9,y = 12) == \"Alice\"\n assert candidate(x = 50,y = 25) == \"Bob\"\n assert candidate(x = 1,y = 20) == \"Alice\"\n assert candidate(x = 7,y = 7) == \"Alice\"\n assert candidate(x = 9,y = 9) == \"Bob\"\n assert candidate(x = 75,y = 11) == \"Bob\"\n assert candidate(x = 6,y = 3) == \"Bob\"\n assert candidate(x = 8,y = 2) == \"Bob\"\n assert candidate(x = 50,y = 20) == \"Alice\"\n assert candidate(x = 8,y = 5) == \"Alice\"\n assert candidate(x = 6,y = 8) == \"Bob\"\n assert candidate(x = 1,y = 15) == \"Alice\"\n assert candidate(x = 6,y = 9) == \"Bob\"\n assert candidate(x = 6,y = 6) == \"Alice\"\n assert candidate(x = 3,y = 3) == \"Bob\"\n assert candidate(x = 8,y = 8) == \"Bob\"\n assert candidate(x = 20,y = 20) == \"Alice\"\n", "comparison": "exact"}, "public_tests": ["2\n7", "4\n11"], "hints": ["The only way to make 115 is to use one coin of value 75 and four coins of value 10. Each turn uses up these many coins.", "Hence the number of turns is min(x, y / 4).", "Determine the winner from its parity."], "metadata": {"canonical_parameter_names": ["x", "y"], "leetcode_dataset_entry_point": "Solution().winningPlayer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:27+00:00", "tests_total": 104, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "simulation", "game-theory"]}, "language": "ruby", "interface": {"raw_signature": "def winning_player(x, y)", "container": null, "callable": "winning_player", "parameters": [{"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3223, "task_id": "minimum-length-of-string-after-operations", "difficulty": "Medium", "problem_description": "You are given a string s.\n\nYou can perform the following process on s any number of times:\n\n- Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i].\n- Delete the closest occurrence of s[i] located to the left of i.\n- Delete the closest occurrence of s[i] located to the right of i.\n\nReturn the minimum length of the final string s that you can achieve.\n\nExample 1:\n\nInput: s = \"abaacbcbb\"\nOutput: 5\nExplanation:\nWe do the following operations:\n- Choose index 2, then remove the characters at indices 0 and 3. The resulting string is s = \"bacbcbb\".\n- Choose index 3, then remove the characters at indices 0 and 5. The resulting string is s = \"acbcb\".\n\nExample 2:\n\nInput: s = \"aa\"\nOutput: 2\nExplanation:\nWe cannot perform any operations, so we return the length of the original string.\n\nConstraints:\n\n- 1 <= s.length <= 2 * 10^5\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzyzyzyyzzyzz\") == 3\n assert candidate(s = \"abcba\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abaacbcbb\") == 5\n assert candidate(s = \"aabbaa\") == 4\n assert candidate(s = \"aabbccddeeeedddccbaa\") == 8\n assert candidate(s = \"abababab\") == 4\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abacabadabacaba\") == 7\n assert candidate(s = \"abcabcabc\") == 3\n assert candidate(s = \"abcabcabcabc\") == 6\n assert candidate(s = \"aa\") == 2\n assert candidate(s = \"abcddcba\") == 8\n assert candidate(s = \"zzzzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzzzz\") == 3\n assert candidate(s = \"abcde\") == 5\n assert candidate(s = \"aabb\") == 4\n assert candidate(s = \"aabbccddeeeedddccba\") == 7\n assert candidate(s = \"abcdeedcba\") == 10\n assert candidate(s = \"zzzzzzzzzz\") == 2\n assert candidate(s = \"abcdefgfedcba\") == 13\n assert candidate(s = \"abcdabcdabcd\") == 4\n assert candidate(s = \"zzzyzzyyzzyyzzzzzyyzyzyzyz\") == 4\n assert candidate(s = \"abacabad\") == 6\n assert candidate(s = \"aabbaaabbbaaa\") == 3\n assert candidate(s = \"abcd\") == 4\n assert candidate(s = \"aabbccddeeff\") == 12\n assert candidate(s = \"aabbcc\") == 6\n assert candidate(s = \"mississippi\") == 7\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 52\n assert candidate(s = \"aabbccddeeffgghhiijj\") == 20\n assert candidate(s = \"aabbccddeeaabbccddeeff\") == 12\n assert candidate(s = \"aabbccdd\") == 8\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 52\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 2\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmnbvcxzlkjhgfdsapoiuytrewqqwertyuiopasdfghjklzxcvbnm\") == 27\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzxyz\") == 49\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababab\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == 51\n assert candidate(s = \"xyzzyxzyzxzyzyzyzyz\") == 3\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 4\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"aaabbbbccccddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\") == 18\n assert candidate(s = \"aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaab\") == 3\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 52\n", "comparison": "exact"}, "public_tests": ["\"abaacbcbb\"", "\"aa\""], "hints": ["Only the frequency of each character matters in finding the final answer.", "If a character occurs less than 3 times, we cannot perform any process with it.", "Suppose there is a character that occurs at least 3 times in the string, we can repeatedly delete two of these characters until there are at most 2 occurrences left of it."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumLength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:29+00:00", "tests_total": 47, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_length(s)", "container": null, "callable": "minimum_length", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3224, "task_id": "minimum-array-changes-to-make-differences-equal", "difficulty": "Medium", "problem_description": "You are given an integer array nums of size n where n is even, and an integer k.\n\nYou can perform some changes on the array, where in one change you can replace any element in the array with any integer in the range from 0 to k.\n\nYou need to perform some changes (possibly none) such that the final array satisfies the following condition:\n\n- There exists an integer X such that abs(a[i] - a[n - i - 1]) = X for all (0 <= i < n).\n\nReturn the minimum number of changes required to satisfy the above condition.\n\nExample 1:\n\nInput: nums = [1,0,1,2,4,3], k = 4\nOutput: 2\nExplanation:\nWe can perform the following changes:\n- Replace nums[1] by 2. The resulting array is nums = [1,2,1,2,4,3].\n- Replace nums[3] by 3. The resulting array is nums = [1,2,1,3,4,3].\n\nThe integer X will be 2.\n\nExample 2:\n\nInput: nums = [0,1,2,3,3,6,5,4], k = 6\nOutput: 2\nExplanation:\nWe can perform the following operations:\n- Replace nums[3] by 0. The resulting array is nums = [0,1,2,0,3,6,5,4].\n- Replace nums[4] by 4. The resulting array is nums = [0,1,2,0,4,6,5,4].\n\nThe integer X will be 4.\n\nConstraints:\n\n- 2 <= n == nums.length <= 10^5\n- n is even.\n- 0 <= nums[i] <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995],k = 100000) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 8) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 15) == 3\n assert candidate(nums = [1, 0, 1, 2, 4, 3],k = 4) == 2\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 4\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0],k = 0) == 0\n assert candidate(nums = [0, 2, 4, 6, 8, 10],k = 10) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],k = 100) == 4\n assert candidate(nums = [0, 1, 2, 3, 3, 6, 5, 4],k = 6) == 2\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1],k = 1) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2],k = 2) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 10) == 0\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14],k = 14) == 3\n assert candidate(nums = [100000, 0, 100000, 0, 100000, 0, 100000, 0],k = 100000) == 0\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3],k = 3) == 0\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992],k = 99999) == 3\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 1) == 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],k = 1) == 0\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992],k = 100000) == 3\n assert candidate(nums = [50000, 0, 49999, 1, 49998, 2, 49997, 3, 49996, 4, 49995, 5, 49994, 6, 49993, 7],k = 100000) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 0\n assert candidate(nums = [30, 20, 10, 0, 10, 20, 30, 40, 50, 60, 70, 80],k = 100) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160],k = 160) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 30) == 14\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 9) == 4\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 8, 6],k = 8) == 1\n assert candidate(nums = [99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0],k = 100000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 16) == 7\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 1200) == 5\n assert candidate(nums = [0, 1, 0, 3, 0, 5, 0, 7, 0, 9],k = 10) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 12) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],k = 20) == 9\n assert candidate(nums = [99999, 1, 99999, 1, 99999, 1, 99999, 1],k = 100000) == 0\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240],k = 240) == 14\n assert candidate(nums = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 55) == 5\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 11) == 5\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 30) == 7\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 100000) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10, 0],k = 100) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000, 0, 0, 0, 0, 100000, 100000, 100000, 100000],k = 100000) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 8) == 6\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40],k = 40) == 3\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 2) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 500, 400, 300, 200, 100, 0],k = 1000) == 0\n assert candidate(nums = [50000, 0, 50000, 0, 50000, 0, 50000, 0, 50000, 0],k = 100000) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 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],k = 20) == 9\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 40000, 30000, 20000, 10000, 0],k = 50000) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 10) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2],k = 10) == 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, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 4\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],k = 15) == 7\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 5) == 0\n assert candidate(nums = [30000, 20000, 10000, 0, 10000, 20000, 30000, 40000, 50000, 60000, 50000, 40000, 30000, 20000, 10000, 0],k = 60000) == 3\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 2) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112],k = 112) == 7\n assert candidate(nums = [99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0],k = 100000) == 0\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],k = 59) == 14\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 4) == 4\n assert candidate(nums = [42, 24, 42, 24, 42, 24, 42, 24, 42, 24, 42, 24],k = 100) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 19) == 4\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 30) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 4\n assert candidate(nums = [5, 10, 5, 15, 5, 20, 5, 25, 5, 30],k = 30) == 4\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 4000, 3000, 2000, 1000, 0],k = 5000) == 0\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 = 5) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5],k = 9) == 5\n assert candidate(nums = [0, 1, 2, 3, 0, 1, 2, 3, 0, 1],k = 3) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 500, 400, 300, 200, 100],k = 500) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 23) == 5\n assert candidate(nums = [1, 3, 2, 3, 4, 5, 3, 2, 5, 4],k = 5) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 8\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 20) == 4\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],k = 80) == 7\n assert candidate(nums = [2, 1, 3, 4, 1, 0, 2, 3, 4, 1, 0, 2, 3, 4, 1, 0],k = 4) == 3\n assert candidate(nums = [5, 1, 3, 7, 9, 2, 8, 4, 6, 0],k = 10) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 16) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 31) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 12) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 20) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10, 0],k = 60) == 0\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 7, 8],k = 8) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4],k = 9) == 5\n assert candidate(nums = [99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0, 99999, 0],k = 99999) == 0\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 1) == 0\n", "comparison": "exact"}, "public_tests": ["[1,0,1,2,4,3]\n4", "[0,1,2,3,3,6,5,4]\n6"], "hints": ["There are at most k + 1 possible values of the integer X.", "How do we calculate the minimum number of changes efficiently if we fix the value of X before applying any changes?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:32+00:00", "tests_total": 101, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def min_changes(nums, k)", "container": null, "callable": "min_changes", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3225, "task_id": "maximum-score-from-grid-operations", "difficulty": "Hard", "problem_description": "You are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j), and color black all the cells of the j^th column starting from the top row down to the i^th row.\n\nThe grid score is the sum of all grid[i][j] such that cell (i, j) is white and it has a horizontally adjacent black cell.\n\nReturn the maximum score that can be achieved after some number of operations.\n\nExample 1:\n\nInput: grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]\nOutput: 11\nExplanation:\nIn the first operation, we color all cells in column 1 down to row 3, and in the second operation, we color all cells in column 4 down to the last row. The score of the resulting grid is grid[3][0] + grid[1][2] + grid[3][3] which is equal to 11.\n\nExample 2:\n\nInput: grid = [[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]\nOutput: 94\nExplanation:\nWe perform operations on 1, 2, and 3 down to rows 1, 4, and 0, respectively. The score of the resulting grid is grid[0][0] + grid[1][0] + grid[2][1] + grid[4][1] + grid[1][3] + grid[2][3] + grid[3][3] + grid[4][3] + grid[0][4] which is equal to 94.\n\nConstraints:\n\n- 1 <= n == grid.length <= 100\n- n == grid[i].length\n- 0 <= grid[i][j] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 3, 0, 0], [0, 1, 0, 0, 0], [5, 0, 0, 3, 0], [0, 0, 0, 0, 2]]) == 11\n assert candidate(grid = [[10, 9, 0, 0, 15], [7, 1, 0, 8, 0], [5, 20, 0, 11, 0], [0, 0, 0, 1, 2], [8, 12, 1, 10, 3]]) == 94\n assert candidate(grid = [[0, 0], [0, 0]]) == 0\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 30\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) == 4\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 30\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == 2\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]]) == 9\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15, 17], [17, 15, 13, 11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18], [18, 16, 14, 12, 10, 8, 6, 4, 2], [3, 6, 9, 12, 15, 18, 21, 24, 27], [27, 24, 21, 18, 15, 12, 9, 6, 3], [4, 8, 12, 16, 20, 24, 28, 32, 36]]) == 588\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 3, 0, 4, 0], [0, 5, 0, 6, 0, 7, 0, 8, 0], [0, 9, 0, 10, 0, 11, 0, 12, 0], [0, 13, 0, 14, 0, 15, 0, 16, 0], [0, 17, 0, 18, 0, 19, 0, 20, 0], [0, 21, 0, 22, 0, 23, 0, 24, 0], [0, 25, 0, 26, 0, 27, 0, 28, 0], [0, 29, 0, 30, 0, 31, 0, 32, 0]]) == 528\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 2, 0, 3, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0]]) == 10\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == 72\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11], [11, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 12], [12, 10, 8, 6, 4, 2]]) == 132\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [10, 0, 0, 0, 0, 0], [10, 10, 0, 0, 0, 0], [10, 10, 10, 0, 0, 0], [10, 10, 10, 10, 0, 0], [10, 10, 10, 10, 10, 0]]) == 100\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 0, 9, 8, 7, 6, 5, 4, 3, 2], [2, 1, 0, 9, 8, 7, 6, 5, 4, 3], [3, 2, 1, 0, 9, 8, 7, 6, 5, 4], [4, 3, 2, 1, 0, 9, 8, 7, 6, 5], [5, 4, 3, 2, 1, 0, 9, 8, 7, 6], [6, 5, 4, 3, 2, 1, 0, 9, 8, 7], [7, 6, 5, 4, 3, 2, 1, 0, 9, 8], [8, 7, 6, 5, 4, 3, 2, 1, 0, 9]]) == 277\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], [0, 7, 8, 9, 10, 11, 12], [0, 13, 14, 15, 16, 17, 18], [0, 19, 20, 21, 22, 23, 24], [0, 25, 26, 27, 28, 29, 30], [0, 31, 32, 33, 34, 35, 36]]) == 444\n assert candidate(grid = [[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]]) == 140\n assert candidate(grid = [[10, 0, 0, 0, 0], [0, 20, 0, 0, 0], [0, 0, 30, 0, 0], [0, 0, 0, 40, 0], [0, 0, 0, 0, 50]]) == 110\n assert candidate(grid = [[0, 0, 0, 0], [0, 100, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 100\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, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 36\n assert candidate(grid = [[9, 0, 5, 0, 0], [0, 0, 0, 0, 0], [3, 0, 0, 0, 0], [0, 8, 0, 0, 0], [0, 0, 0, 0, 7]]) == 27\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, 1, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 0, 4]]) == 7\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 60\n assert candidate(grid = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [0, 10, 20, 30, 40], [5, 15, 25, 35, 45], [0, 10, 20, 30, 40]]) == 410\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]]) == 80\n assert candidate(grid = [[0, 2, 0, 0, 4, 0], [1, 0, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0], [0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 7]]) == 23\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8], [4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 10]]) == 110\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]]) == 28\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, 0, 0, 0, 0, 0, 0], [9, 8, 7, 6, 5, 4, 3]]) == 26\n assert candidate(grid = [[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]]) == 7\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0]]) == 10\n assert candidate(grid = [[9, 0, 0, 0, 0, 0], [0, 8, 0, 0, 0, 0], [0, 0, 7, 0, 0, 0], [0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 5, 0], [0, 0, 0, 0, 0, 4]]) == 35\n assert candidate(grid = [[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]]) == 200\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [1, 0, 2, 0, 3, 0], [0, 4, 0, 5, 0, 6], [7, 0, 8, 0, 9, 0], [0, 10, 0, 11, 0, 12], [13, 0, 14, 0, 15, 0]]) == 79\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6], [7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2], [3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3], [4, 5, 6, 7, 8, 9, 10]]) == 146\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]]) == 15\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 3], [0, 4, 0, 5, 0, 6], [0, 7, 0, 8, 0, 9], [0, 10, 0, 11, 0, 12], [0, 13, 0, 14, 0, 15]]) == 120\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 0], [0, 0, 0, 0, 3, 0], [4, 0, 0, 0, 0, 5], [0, 0, 6, 0, 0, 0], [0, 0, 0, 7, 0, 0]]) == 24\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [1, 2, 3, 4, 5, 0], [0, 0, 0, 0, 0, 6], [1, 1, 1, 1, 1, 1]]) == 38\n assert candidate(grid = [[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], [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], [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]]) == 271\n assert candidate(grid = [[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]]) == 714\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1]]) == 6\n assert candidate(grid = [[1000000000, 0, 0, 0, 0], [0, 1000000000, 0, 0, 0], [0, 0, 1000000000, 0, 0], [0, 0, 0, 1000000000, 0], [0, 0, 0, 0, 1000000000]]) == 4000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 5, 0]]) == 15\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [0, 0, 0, 0, 0, 0], [7, 8, 9, 10, 11, 12], [12, 11, 10, 9, 8, 7]]) == 104\n assert candidate(grid = [[1000000000, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000000]]) == 2000000000\n assert candidate(grid = [[50, 0, 0, 0, 0], [0, 50, 0, 0, 0], [0, 0, 50, 0, 0], [0, 0, 0, 50, 0], [0, 0, 0, 0, 50]]) == 200\n assert candidate(grid = [[10, 10, 10, 10, 10], [10, 9, 8, 7, 6], [10, 8, 6, 4, 2], [10, 7, 5, 3, 1], [10, 6, 4, 2, 0]]) == 109\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]]) == 5\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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 60\n assert candidate(grid = [[10, 0, 0, 0], [0, 20, 0, 0], [0, 0, 30, 0], [0, 0, 0, 40]]) == 70\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6], [0, 0, 0, 0, 0, 0], [7, 8, 9, 10, 11, 12], [0, 0, 0, 0, 0, 0], [13, 14, 15, 16, 17, 18]]) == 114\n assert candidate(grid = [[100, 0, 0, 0, 0], [0, 100, 0, 0, 0], [0, 0, 100, 0, 0], [0, 0, 0, 100, 0], [0, 0, 0, 0, 100]]) == 400\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [3, 4, 5, 6, 7]]) == 58\n assert candidate(grid = [[10, 0, 20, 0, 30], [0, 40, 0, 50, 0], [60, 0, 70, 0, 80], [0, 90, 0, 100, 0], [110, 0, 120, 0, 130]]) == 630\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]]) == 0\n assert candidate(grid = [[5, 0, 0, 0, 0], [0, 0, 5, 0, 0], [0, 5, 0, 5, 0], [0, 0, 5, 0, 5], [5, 0, 0, 5, 0]]) == 30\n assert candidate(grid = [[20, 19, 18, 17, 16], [15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1], [0, 0, 0, 0, 0]]) == 130\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, 2, 4, 6, 8, 10, 12, 14, 16, 18], [18, 16, 14, 12, 10, 8, 6, 4, 2, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27], [27, 24, 21, 18, 15, 12, 9, 6, 3, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 339\n assert candidate(grid = [[1, 2, 0, 0, 0], [0, 3, 4, 0, 0], [0, 0, 5, 6, 0], [0, 0, 0, 7, 8], [0, 0, 0, 0, 9]]) == 31\n assert candidate(grid = [[1000000000, 0, 0, 0, 0], [0, 1000000000, 0, 0, 0], [0, 0, 1000000000, 0, 0], [0, 0, 0, 1000000000, 0], [0, 0, 0, 0, 1000000000]]) == 4000000000\n assert candidate(grid = [[9, 0, 0, 0, 0], [8, 0, 0, 0, 0], [7, 0, 0, 0, 0], [6, 0, 0, 0, 0], [5, 0, 0, 0, 0]]) == 35\n assert candidate(grid = [[10, 20, 30, 40, 50, 60], [60, 50, 40, 30, 20, 10], [10, 30, 50, 70, 90, 110], [110, 90, 70, 50, 30, 10], [20, 40, 60, 80, 100, 120], [120, 100, 80, 60, 40, 20]]) == 1320\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\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == 130\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [0, 0, 0, 0, 0, 0], [6, 5, 4, 3, 2, 1], [0, 0, 0, 0, 0, 0], [7, 8, 9, 10, 11, 12], [12, 11, 10, 9, 8, 7]]) == 104\n assert candidate(grid = [[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]]) == 714\n assert candidate(grid = [[1000000000, 0, 0, 0, 0, 0], [0, 1000000000, 0, 0, 0, 0], [0, 0, 1000000000, 0, 0, 0], [0, 0, 0, 1000000000, 0, 0], [0, 0, 0, 0, 1000000000, 0], [0, 0, 0, 0, 0, 1000000000]]) == 5000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 3, 0, 4], [0, 5, 0, 6, 0, 7, 0, 8], [0, 9, 0, 10, 0, 11, 0, 12], [0, 13, 0, 14, 0, 15, 0, 16], [0, 17, 0, 18, 0, 19, 0, 20], [0, 21, 0, 22, 0, 23, 0, 24], [0, 25, 0, 26, 0, 27, 0, 28]]) == 406\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 0], [0, 0, 0, 0, 0, 3], [0, 0, 4, 0, 5, 0], [0, 6, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0]]) == 22\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0], [0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 0, 7]]) == 22\n", "comparison": "exact"}, "public_tests": ["[[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]", "[[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]"], "hints": ["Use dynamic programming.", "Solve the problem in O(N^4) using a 3-states dp.", "Let dp[i][lastHeight][beforeLastHeight] denote the maximum score if the grid was limited to column i, and the height of column i - 1 is lastHeight and the height of column i - 2 is beforeLastHeight.", "The third state, beforeLastHeight, is used to determine which values of column i - 1 will be added to the score. We can replace this state with another state that only takes two values 0 or 1.", "Let dp[i][lastHeight][isBigger] denote the maximum score if the grid was limited to column i, and where the height of column i - 1 is lastHeight. Additionally, if isBigger == 1, the number of black cells in column i is assumed to be larger than the number of black cells in column i - 2, and vice versa. Note that if our assumption is wrong, it would lead to a suboptimal score and, therefore, it would not be considered as the final answer."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:34+00:00", "tests_total": 75, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix", "prefix-sum"]}, "language": "ruby", "interface": {"raw_signature": "def maximum_score(grid)", "container": null, "callable": "maximum_score", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3226, "task_id": "number-of-bit-changes-to-make-two-integers-equal", "difficulty": "Easy", "problem_description": "You are given two positive integers n and k.\n\nYou can choose any bit in the binary representation of n that is equal to 1 and change it to 0.\n\nReturn the number of changes needed to make n equal to k. If it is impossible, return -1.\n\nExample 1:\n\nInput: n = 13, k = 4\nOutput: 2\nExplanation:\nInitially, the binary representations of n and k are n = (1101)_2 and k = (0100)_2.\nWe can change the first and fourth bits of n. The resulting integer is n = (0100)_2 = k.\n\nExample 2:\n\nInput: n = 21, k = 21\nOutput: 0\nExplanation:\nn and k are already equal, so no changes are needed.\n\nExample 3:\n\nInput: n = 14, k = 13\nOutput: -1\nExplanation:\nIt is not possible to make n equal to k.\n\nConstraints:\n\n- 1 <= n, k <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1,k = 2) == -1\n assert candidate(n = 31,k = 1) == 4\n assert candidate(n = 15,k = 9) == 2\n assert candidate(n = 8,k = 8) == 0\n assert candidate(n = 1000000,k = 999999) == -1\n assert candidate(n = 7,k = 11) == -1\n assert candidate(n = 7,k = 3) == 1\n assert candidate(n = 5,k = 3) == -1\n assert candidate(n = 9,k = 8) == 1\n assert candidate(n = 6,k = 5) == -1\n assert candidate(n = 31,k = 15) == 1\n assert candidate(n = 1023,k = 512) == 9\n assert candidate(n = 21,k = 21) == 0\n assert candidate(n = 13,k = 4) == 2\n assert candidate(n = 14,k = 13) == -1\n assert candidate(n = 1023,k = 511) == 1\n assert candidate(n = 1000000,k = 500000) == -1\n assert candidate(n = 32767,k = 16384) == 14\n assert candidate(n = 999999,k = 1000000) == -1\n assert candidate(n = 65535,k = 32767) == 1\n assert candidate(n = 111111,k = 222222) == -1\n assert candidate(n = 524287,k = 524288) == -1\n assert candidate(n = 8191,k = 4096) == 12\n assert candidate(n = 1000000,k = 1) == -1\n assert candidate(n = 255,k = 128) == 7\n assert candidate(n = 123456,k = 65536) == 5\n assert candidate(n = 983040,k = 524288) == 3\n assert candidate(n = 777777,k = 777777) == 0\n assert candidate(n = 8191,k = 8191) == 0\n assert candidate(n = 2,k = 1) == -1\n assert candidate(n = 123456,k = 123455) == -1\n assert candidate(n = 524287,k = 524286) == 1\n assert candidate(n = 123456,k = 123456) == 0\n assert candidate(n = 786432,k = 393216) == -1\n assert candidate(n = 777777,k = 888888) == -1\n assert candidate(n = 888888,k = 999999) == -1\n assert candidate(n = 65535,k = 65534) == 1\n assert candidate(n = 131071,k = 65535) == 1\n assert candidate(n = 999999,k = 1) == 11\n assert candidate(n = 983041,k = 262144) == 4\n assert candidate(n = 555555,k = 555554) == 1\n assert candidate(n = 987654,k = 123456) == -1\n assert candidate(n = 123456,k = 654321) == -1\n assert candidate(n = 8191,k = 4095) == 1\n assert candidate(n = 1024,k = 1023) == -1\n assert candidate(n = 1001,k = 1000) == 1\n assert candidate(n = 524287,k = 262143) == 1\n assert candidate(n = 888888,k = 888880) == 1\n assert candidate(n = 65535,k = 4095) == 4\n assert candidate(n = 333333,k = 666666) == -1\n assert candidate(n = 524287,k = 262144) == 18\n assert candidate(n = 524287,k = 1) == 18\n assert candidate(n = 131071,k = 131072) == -1\n assert candidate(n = 65535,k = 1) == 15\n assert candidate(n = 524287,k = 524287) == 0\n assert candidate(n = 987654,k = 987653) == -1\n assert candidate(n = 897531,k = 897532) == -1\n assert candidate(n = 777777,k = 666666) == -1\n assert candidate(n = 32768,k = 16384) == -1\n assert candidate(n = 987654,k = 987655) == -1\n assert candidate(n = 8192,k = 4096) == -1\n assert candidate(n = 65535,k = 32768) == 15\n assert candidate(n = 983040,k = 491520) == -1\n assert candidate(n = 131071,k = 262142) == -1\n assert candidate(n = 6143,k = 1024) == 11\n assert candidate(n = 131071,k = 1) == 16\n assert candidate(n = 262144,k = 131072) == -1\n assert candidate(n = 4095,k = 1023) == 2\n", "comparison": "exact"}, "public_tests": ["13\n4", "21\n21", "14\n13"], "hints": ["Find the binary representations of n and k.", "Any bit that is equal to 1 in n and equal to 0 in k needs to be changed."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().minChanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:37+00:00", "tests_total": 91, "tests_dropped": 23, "flags": [], "topic_tags": ["bit-manipulation"]}, "language": "ruby", "interface": {"raw_signature": "def min_changes(n, k)", "container": null, "callable": "min_changes", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3227, "task_id": "vowels-game-in-a-string", "difficulty": "Medium", "problem_description": "Alice and Bob are playing a game on a string.\n\nYou are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:\n\n- On Alice's turn, she has to remove any non-empty substring from s that contains an odd number of vowels.\n- On Bob's turn, he has to remove any non-empty substring from s that contains an even number of vowels.\n\nThe first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play optimally.\n\nReturn true if Alice wins the game, and false otherwise.\n\nThe English vowels are: a, e, i, o, and u.\n\nExample 1:\n\nInput: s = \"leetcoder\"\nOutput: true\nExplanation:\nAlice can win the game as follows:\n- Alice plays first, she can delete the underlined substring in s = \"leetcoder\" which contains 3 vowels. The resulting string is s = \"der\".\n- Bob plays second, he can delete the underlined substring in s = \"der\" which contains 0 vowels. The resulting string is s = \"er\".\n- Alice plays third, she can delete the whole string s = \"er\" which contains 1 vowel.\n- Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.\n\nExample 2:\n\nInput: s = \"bbcd\"\nOutput: false\nExplanation:\nThere is no valid play for Alice in her first turn, so Alice loses the game.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == False\n assert candidate(s = \"bcbcbc\") == False\n assert candidate(s = \"leetcodeisfun\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"uoiea\") == True\n assert candidate(s = \"aeiou\") == True\n assert candidate(s = \"a\") == True\n assert candidate(s = \"bbaebebebe\") == True\n assert candidate(s = \"ae\") == True\n assert candidate(s = \"bcdfe\") == True\n assert candidate(s = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\") == True\n assert candidate(s = \"xyz\") == False\n assert candidate(s = \"bcdf\") == False\n assert candidate(s = \"bbcd\") == False\n assert candidate(s = \"abcdefgh\") == True\n assert candidate(s = \"abcd\") == True\n assert candidate(s = \"bcbcbcbcbcbcbc\") == False\n assert candidate(s = \"abecidofug\") == True\n assert candidate(s = \"aeaaaeaa\") == True\n assert candidate(s = \"uuuuuu\") == True\n assert candidate(s = \"vozxqwx\") == True\n assert candidate(s = \"aabbccddeeff\") == True\n assert candidate(s = \"aabbcc\") == True\n assert candidate(s = \"bvdfndkvflspvlvhlmvfyckqjgnvjcjgvdpelbvclvsgjgygsvjvlp\") == True\n assert candidate(s = \"leetcoder\") == True\n assert candidate(s = \"aeiaeiaeiaeia\") == True\n assert candidate(s = \"aabbccdd\") == True\n assert candidate(s = \"bcdfg\") == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(s = \"bcd\") == False\n assert candidate(s = \"bababababababababa\") == True\n assert candidate(s = \"aabbccddeeefffrrtgyhyuujuyuyuyukjhjhgfdszxcvbnmaaeiou\") == True\n assert candidate(s = \"bbbbbaaaaaaaaa\") == True\n assert candidate(s = \"bbbbbaaaaabbbbbbbaaaaaaabbbbaaaaabbbbbaaaaaaabbbbbaaaaaaabbbbbaaaaaa\") == True\n assert candidate(s = \"anagram\") == True\n assert candidate(s = \"thisstringhasmanyvowelsaeiouanothersequenceofvowelsaeiou\") == True\n assert candidate(s = \"leetcodeiscrazyandfun\") == True\n assert candidate(s = \"aabbccddeeefffrrtgyhyuujuyuyuyukjhjhgfdszxcvbnm\") == True\n assert candidate(s = \"aliceandbobareplayingagame\") == True\n assert candidate(s = \"bbbbbbaaaaaabbbbbbaaaaaabbbbbbaaaaaabbbbbbaaaaaabbbbbbaaaaaabbbbbbaaaaaa\") == True\n assert candidate(s = \"leetcodedebuggingisfun\") == True\n assert candidate(s = \"vwxyz\") == False\n assert candidate(s = \"abacadaeafagahaiajakalamanaoapaqarasatauavawaxayaza\") == True\n assert candidate(s = \"consonant\") == True\n assert candidate(s = \"aoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiuiaoeuiui\") == True\n assert candidate(s = \"aeiaaioaaaaeiiiiouuuooaauuaeiuzyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(s = \"vozdfvoazefovoziaovozifvoaeiofvaeivoaeiofvaeivoaeiofvaeivoaeiofvaeivoaeiof\") == True\n assert candidate(s = \"zzzaaaiiiooouuuummmllooonnngggfffddeeerrrtttyy\") == True\n assert candidate(s = \"aebcideofuigohukimouoeqirouusotovowuy\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"thisisaverylongstringwithseveralvowels\") == True\n assert candidate(s = \"bcdfghjklmnpqrstvwxyzaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"optimallyplayingthegamewithvowels\") == True\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == True\n assert candidate(s = \"evennumberofvowels\") == True\n assert candidate(s = \"bbaaaacceeeeeddooouuuiiiaaaa\") == True\n assert candidate(s = \"aaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == True\n assert candidate(s = \"abcdefghijkllllllllllmnopqrstuvwxyz\") == True\n assert candidate(s = \"aeiaaioaaaaeiiiiouuuooaauuaeiuuuuuuuuuuuuuuuuuuuuuuu\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"bcaovkyutrfghjnmlopaeiouaeiouaeiou\") == True\n assert candidate(s = \"programmingisfun\") == True\n assert candidate(s = \"leetcodelovebaboon\") == True\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzaeiouabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"leetcodeleetcode\") == True\n assert candidate(s = \"aeioubcdfghjklmnpqrstvwxyz\") == True\n assert candidate(s = \"aeiouaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s = \"leetcodeword\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"abcdefghijklnmopqrstuvwxyz\") == True\n assert candidate(s = \"abcdefghijkloiuytrpqweoiuytrewqoiuytrewq\") == True\n assert candidate(s = \"leetcoderbbaaaabbaaabbbaaaabbaaabbbaaaabbaaabbbaaaab\") == True\n assert candidate(s = \"aeiouzyxwvutsrqponmlkjihgfedcb\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"aeioubcdfghjklmnpqrstvwxyzaeioubcdfghjklmnpqrstvwxyzaeioubcdfghjklmnpqrstvwxyz\") == True\n assert candidate(s = \"thisisalongstringwithmanyvowelsoooeiuaeiou\") == True\n assert candidate(s = \"uuuuuaaaaaeeeeeooooouuuuuaaaaa\") == True\n assert candidate(s = \"vowel\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"aevbocudifoguhoeaio\") == True\n assert candidate(s = \"babababababababababababababababababababababababababababababababababa\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"bbaaaacccceeeeedddd\") == True\n assert candidate(s = \"aevbocudifoguhoeaioaaaaeeeeeooooouuuuu\") == True\n assert candidate(s = \"eiouaeiouaeiou\") == True\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(s = \"bcdfghjklmnpqrstvwxyz\") == False\n assert candidate(s = \"vowelsareimportantinthisgame\") == True\n assert candidate(s = \"aabbccddeeffgg\") == True\n assert candidate(s = \"bbbbbaaaaabbbbbbaaaaabbbbbaaaa\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaeiouaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"leetcodeisreallyfun\") == True\n assert candidate(s = \"abcdefghij\") == True\n assert candidate(s = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s = \"zxcvbnmlkjhgfdsapoiuytrewq\") == True\n assert candidate(s = \"sequencepalindrome\") == True\n assert candidate(s = \"zaeiouzaeiouzaeiouzaeiou\") == True\n assert candidate(s = \"zxcvbnmasdfghjklqwertyuiopmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrew\") == True\n assert candidate(s = \"lkjihgfedcbponmlkjihgfedcba\") == True\n assert candidate(s = \"abcdefgheijouaeiouxyz\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaeiou\") == True\n assert candidate(s = \"aaabbbcccdddaabbccddeee\") == True\n assert candidate(s = \"vowelsareaeiou\") == True\n assert candidate(s = \"complexsubstringwithvariousvowels\") == True\n assert candidate(s = \"aeiaaioaaaaeiiiiouuuooaauuaeiuzyxwvutsrqponmlkjihgfedcbaaabbccddeeefffrrtgyhyuujuyuyuyukjhjhgfdszxcvbnmaaeiou\") == True\n assert candidate(s = \"consonantsnvbnmnbmhngftrds\") == True\n assert candidate(s = \"bbaaaabbaaabbbaaaabbaaabbbaaaabbaaabbbaaaab\") == True\n assert candidate(s = \"bcaovkyutrfghjnmlop\") == True\n assert candidate(s = \"aabbccddeeefffagggihiiiijjjjkkkkllllmmmmnnnnooooo\") == True\n assert candidate(s = \"aaaaabbbbbcccccdddddaaaaabbbbb\") == True\n assert candidate(s = \"oddnumberofvowels\") == True\n assert candidate(s = \"bbbaaaacceeeeeddooouuuiiiaaaabbbccc\") == True\n assert candidate(s = \"aebcdeoiufghijklmnoptqrstuwyxz\") == True\n assert candidate(s = \"aeiouvwxyzaeiouvwxyzaeiouvwxyz\") == True\n assert candidate(s = \"aliceandbob\") == True\n", "comparison": "exact"}, "public_tests": ["\"leetcoder\"", "\"bbcd\""], "hints": ["If there are no vowels in the initial string, then Bob wins.", "If the number of vowels in the initial string is odd, then Alice can remove the whole string on her first turn and win.", "What if the number of vowels in the initial string is even? What’s the optimal play for Alice’s first turn?"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().doesAliceWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:39+00:00", "tests_total": 121, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "string", "brainteaser", "game-theory"]}, "language": "ruby", "interface": {"raw_signature": "def does_alice_win(s)", "container": null, "callable": "does_alice_win", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3228, "task_id": "maximum-number-of-operations-to-move-ones-to-the-end", "difficulty": "Medium", "problem_description": "You are given a binary string s.\n\nYou can perform the following operation on the string any number of times:\n\n- Choose any index i from the string where i + 1 < s.length such that s[i] == '1' and s[i + 1] == '0'.\n- Move the character s[i] to the right until it reaches the end of the string or another '1'. For example, for s = \"010010\", if we choose i = 1, the resulting string will be s = \"000110\".\n\nReturn the maximum number of operations that you can perform.\n\nExample 1:\n\nInput: s = \"1001101\"\nOutput: 4\nExplanation:\nWe can perform the following operations:\n- Choose index i = 0. The resulting string is s = \"0011101\".\n- Choose index i = 4. The resulting string is s = \"0011011\".\n- Choose index i = 3. The resulting string is s = \"0010111\".\n- Choose index i = 2. The resulting string is s = \"0001111\".\n\nExample 2:\n\nInput: s = \"00111\"\nOutput: 0\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"00111\") == 0\n assert candidate(s = \"101100110\") == 9\n assert candidate(s = \"000111000\") == 3\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"010101010\") == 10\n assert candidate(s = \"1001001001001\") == 10\n assert candidate(s = \"100001110\") == 5\n assert candidate(s = \"1111111111\") == 0\n assert candidate(s = \"1010101\") == 6\n assert candidate(s = \"1000000000\") == 1\n assert candidate(s = \"00001111\") == 0\n assert candidate(s = \"10001\") == 1\n assert candidate(s = \"00000000\") == 0\n assert candidate(s = \"11111\") == 0\n assert candidate(s = \"1001001001\") == 6\n assert candidate(s = \"11111111\") == 0\n assert candidate(s = \"110001101\") == 6\n assert candidate(s = \"1001101\") == 4\n assert candidate(s = \"1010101010\") == 15\n assert candidate(s = \"1100011\") == 2\n assert candidate(s = \"1100110011\") == 6\n assert candidate(s = \"101000101\") == 6\n assert candidate(s = \"1101001\") == 5\n assert candidate(s = \"101010\") == 6\n assert candidate(s = \"0101010101\") == 10\n assert candidate(s = \"110000011\") == 2\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"100010001\") == 3\n assert candidate(s = \"11010000011100000111\") == 11\n assert candidate(s = \"111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"11001011001011001011\") == 33\n assert candidate(s = \"00000000000000000000000000000000\") == 0\n assert candidate(s = \"110010010101001\") == 20\n assert candidate(s = \"100001000010000100001\") == 10\n assert candidate(s = \"1010101010101010101\") == 45\n assert candidate(s = \"0110011001100110011001100110011001100110011001100110011001\") == 210\n assert candidate(s = \"10010010010010010010010010010010010010010010010010\") == 153\n assert candidate(s = \"00001111000011110000\") == 12\n assert candidate(s = \"111000111000111\") == 9\n assert candidate(s = \"000111000111000111\") == 9\n assert candidate(s = \"10101010101010101010101010101010101010101010101\") == 276\n assert candidate(s = \"0000000000000000000000000000000000000000000000000001\") == 0\n assert candidate(s = \"1111111111111111111111111111111111111\") == 0\n assert candidate(s = \"1010101010101010101010101010101010101010101010101\") == 300\n assert candidate(s = \"110000000000000000000000000000000000000000000000000000000000000000\") == 2\n assert candidate(s = \"110011001100\") == 12\n assert candidate(s = \"101010101010101010101010101010101010101010101\") == 253\n assert candidate(s = \"111100001111000011110000\") == 24\n assert candidate(s = \"00011110001111000111100011110001111000111100011110\") == 112\n assert candidate(s = \"0011001100110011\") == 12\n assert candidate(s = \"000000111111\") == 0\n assert candidate(s = \"01001001001001001001001001001001001001001001001001\") == 136\n assert candidate(s = \"10101010101010101010101\") == 66\n assert candidate(s = \"000011110000111100001111000011110000\") == 40\n assert candidate(s = \"0000111100001111000011110000\") == 24\n assert candidate(s = \"0000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"1001001001001001001001001001001\") == 55\n assert candidate(s = \"100000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000\") == 3\n assert candidate(s = \"01010101010101010101010101010101010101010101010101\") == 300\n assert candidate(s = \"100000000000000000000000000000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"10000000000000000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"1000000001000000010000000100000001\") == 10\n assert candidate(s = \"111000111000111000111000111000111000111000\") == 84\n assert candidate(s = \"00000000001111111111\") == 0\n assert candidate(s = \"10000000100000001000000010000000\") == 10\n assert candidate(s = \"00000111110000011111\") == 5\n assert candidate(s = \"111000111000111000111\") == 18\n assert candidate(s = \"1000000000000000000000000000000000000000000000000000\") == 1\n assert candidate(s = \"11111111110000000000\") == 10\n assert candidate(s = \"01010101010101010101010101010101\") == 120\n assert candidate(s = \"0101010101010101010101010101010101010101\") == 190\n assert candidate(s = \"1010101010101010101010101010\") == 105\n assert candidate(s = \"100000000000000000000000000000000000000000000000\") == 1\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"1111111100000000\") == 8\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111000111\") == 165\n assert candidate(s = \"11110000111100001111000011110000\") == 40\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000\") == 52\n assert candidate(s = \"1101101101101101101101101101101101101101\") == 182\n assert candidate(s = \"0101010101010101\") == 28\n assert candidate(s = \"11111111111111111111111111111111\") == 0\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010\") == 435\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000000000000001\") == 0\n assert candidate(s = \"11111000001111100000111110000011111000001111100000\") == 75\n assert candidate(s = \"1001001001001001001\") == 21\n assert candidate(s = \"1001001001001001001001001001001001001001\") == 91\n assert candidate(s = \"11111110000000\") == 7\n assert candidate(s = \"100000010000001\") == 3\n assert candidate(s = \"00001111000011110000111100001111\") == 24\n assert candidate(s = \"1111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"111000011100001110000111\") == 18\n assert candidate(s = \"1111000011110000\") == 12\n assert candidate(s = \"10101010101010101010101010101010\") == 136\n assert candidate(s = \"0000000011111111\") == 0\n assert candidate(s = \"1001100110011001100110011001100110011001100110011001100110\") == 225\n assert candidate(s = \"1100010010011010\") == 22\n assert candidate(s = \"0100101001010010100101001010010100101001\") == 120\n assert candidate(s = \"1100000011110000001111000000\") == 18\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 210\n assert candidate(s = \"0000111100001111000011110000111100001111\") == 40\n assert candidate(s = \"01010101010101010101\") == 45\n assert candidate(s = \"010101010101010101010101010101010101010101010101010101010101010101\") == 528\n assert candidate(s = \"0000000000000000000000000000000000000\") == 0\n assert candidate(s = \"10101010101010101010\") == 55\n assert candidate(s = \"00011110000111100001111\") == 12\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"0000111100001111\") == 4\n", "comparison": "exact"}, "public_tests": ["\"1001101\"", "\"00111\""], "hints": ["It is optimal to perform the operation on the lowest index possible each time.", "Traverse the string from left to right and perform the operation every time it is possible."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maxOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:42+00:00", "tests_total": 107, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def max_operations(s)", "container": null, "callable": "max_operations", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3229, "task_id": "minimum-operations-to-make-array-equal-to-target", "difficulty": "Hard", "problem_description": "You are given two positive integer arrays nums and target, of the same length.\n\nIn a single operation, you can select any subarray of nums and increment each element within that subarray by 1 or decrement each element within that subarray by 1.\n\nReturn the minimum number of operations required to make nums equal to the array target.\n\nExample 1:\n\nInput: nums = [3,5,1,2], target = [4,6,2,4]\nOutput: 2\nExplanation:\nWe will perform the following operations to make nums equal to target:\n- Increment nums[0..3] by 1, nums = [4,6,2,3].\n- Increment nums[3..3] by 1, nums = [4,6,2,4].\n\nExample 2:\n\nInput: nums = [1,3,2], target = [2,1,4]\nOutput: 5\nExplanation:\nWe will perform the following operations to make nums equal to target:\n- Increment nums[0..0] by 1, nums = [2,3,2].\n- Decrement nums[1..1] by 1, nums = [2,2,2].\n- Decrement nums[1..1] by 1, nums = [2,1,2].\n- Increment nums[2..2] by 1, nums = [2,1,3].\n- Increment nums[2..2] by 1, nums = [2,1,4].\n\nConstraints:\n\n- 1 <= nums.length == target.length <= 10^5\n- 1 <= nums[i], target[i] <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 100000000, 1],target = [100000000, 1, 100000000]) == 299999997\n assert candidate(nums = [1, 3, 2],target = [2, 1, 4]) == 5\n assert candidate(nums = [3, 5, 1, 2],target = [4, 6, 2, 4]) == 2\n assert candidate(nums = [100000000, 100000000, 100000000],target = [1, 1, 1]) == 99999999\n assert candidate(nums = [1, 1, 1, 1],target = [2, 2, 2, 2]) == 1\n assert candidate(nums = [10, 20, 30],target = [15, 25, 25]) == 10\n assert candidate(nums = [10, 20, 30],target = [15, 25, 35]) == 5\n assert candidate(nums = [1, 2, 3],target = [4, 5, 6]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 18\n assert candidate(nums = [5, 5, 5, 5, 5],target = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],target = [3, 4, 5, 6, 7]) == 4\n assert candidate(nums = [1, 2, 3],target = [4, 5, 6]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5],target = [1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1],target = [1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [100000000],target = [100000000]) == 0\n assert candidate(nums = [100, 200, 300, 400],target = [400, 300, 200, 100]) == 600\n assert candidate(nums = [100000000, 100000000],target = [1, 1]) == 99999999\n assert candidate(nums = [1, 2, 3, 4, 5],target = [5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 180\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 36\n assert candidate(nums = [1, 2, 3, 4, 5],target = [2, 3, 4, 5, 6]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 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],target = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 38\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6]) == 8\n assert candidate(nums = [1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],target = [31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 44\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [10, 30, 50, 70, 90, 110, 130, 150, 170, 190]) == 90\n assert candidate(nums = [1, 1, 2, 2, 3, 3],target = [3, 3, 2, 2, 1, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],target = [5, 1, 5, 1, 5]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9],target = [2, 4, 6, 8, 10]) == 1\n assert candidate(nums = [1, 10, 100, 1000, 10000],target = [10000, 1000, 100, 10, 1]) == 19998\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 28\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1],target = [9, 8, 7, 6, 5, 6, 7, 8, 9]) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 5\n assert candidate(nums = [10, 10, 10, 10, 10],target = [1, 2, 3, 4, 5]) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1],target = [1, 1, 1, 1, 100000000]) == 99999999\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 1, 1, 1, 1, 10, 10, 10, 10, 10]) == 8\n assert candidate(nums = [5, 4, 3, 2, 1],target = [1, 2, 3, 4, 5]) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 1800\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],target = [4, 4, 3, 3, 2, 2, 1, 1]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9],target = [9, 7, 5, 3, 1]) == 16\n assert candidate(nums = [1, 10, 100, 1000, 10000],target = [10000, 1000, 100, 10, 1]) == 19998\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 18\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 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],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 30]) == 29\n assert candidate(nums = [10, 20, 30, 40, 50],target = [1, 2, 3, 4, 5]) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],target = [4, 4, 4, 4, 3, 3, 3, 2, 2, 1]) == 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],target = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 38\n assert candidate(nums = [1, 100, 10000, 1000000],target = [1000000, 10000, 100, 1]) == 1999998\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50],target = [50, 40, 30, 20, 10]) == 80\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996],target = [1, 2, 3, 4, 5]) == 99999999\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],target = [4, 4, 3, 3, 2, 2, 1, 1]) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = [5, 6, 7, 8, 9, 10, 9, 8, 7, 6]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],target = [10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],target = [10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [9, 9, 9, 9, 9],target = [1, 2, 3, 4, 5]) == 8\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000]) == 99999999\n assert candidate(nums = [2, 4, 6, 8, 10],target = [1, 3, 5, 7, 9]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 90\n assert candidate(nums = [10, 20, 30, 40, 50],target = [50, 40, 30, 20, 10]) == 80\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],target = [3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 900\n assert candidate(nums = [3, 5, 2, 8, 4],target = [6, 8, 7, 4, 3]) == 9\n assert candidate(nums = [100, 200, 300, 400, 500],target = [500, 400, 300, 200, 100]) == 800\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 18\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],target = [25, 20, 15, 10, 5]) == 40\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 50\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],target = [4, 4, 4, 4, 3, 3, 3, 2, 2, 1]) == 6\n assert candidate(nums = [10, 20, 30, 40, 50],target = [15, 25, 35, 45, 55]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 16\n assert candidate(nums = [10, 10, 10, 10, 10],target = [1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 18\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9],target = [9, 7, 5, 3, 1]) == 16\n assert candidate(nums = [100000000, 90000000, 80000000, 70000000, 60000000],target = [10000000, 20000000, 30000000, 40000000, 50000000]) == 90000000\n assert candidate(nums = [5, 5, 5, 5, 5],target = [10, 9, 8, 7, 6]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5],target = [10, 5, 10, 5, 10]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],target = [13, 11, 9, 7, 5, 3, 1]) == 24\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 36\n assert candidate(nums = [10, 20, 30, 40, 50],target = [5, 15, 25, 35, 45]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 100000000]) == 100000006\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 8\n", "comparison": "exact"}, "public_tests": ["[3,5,1,2]\n[4,6,2,4]", "[1,3,2]\n[2,1,4]"], "hints": ["Change nums'[i] = nums[i] - target[i], so our goal is to make nums' into all 0s.", "Divide and conquer."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:45+00:00", "tests_total": 117, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "dynamic-programming", "stack", "greedy", "monotonic-stack"]}, "language": "ruby", "interface": {"raw_signature": "def minimum_operations(nums, target)", "container": null, "callable": "minimum_operations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3232, "task_id": "find-if-digit-game-can-be-won", "difficulty": "Easy", "problem_description": "You are given an array of positive integers nums.\n\nAlice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.\n\nReturn true if Alice can win this game, otherwise, return false.\n\nExample 1:\n\nInput: nums = [1,2,3,4,10]\nOutput: false\nExplanation:\nAlice cannot win by choosing either single-digit or double-digit numbers.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5,14]\nOutput: true\nExplanation:\nAlice can win by choosing single-digit numbers which have a sum equal to 15.\n\nExample 3:\n\nInput: nums = [5,5,5,25]\nOutput: true\nExplanation:\nAlice can win by choosing double-digit numbers which have a sum equal to 25.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 99\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [9, 9, 9, 10, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 14]) == True\n assert candidate(nums = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [50, 25, 10, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == True\n assert candidate(nums = [1, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == True\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == True\n assert candidate(nums = [5, 5, 5, 25]) == True\n assert candidate(nums = [1, 11, 22, 33, 44, 55, 66, 77, 88, 99]) == True\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 51, 52, 53, 54]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [1, 2, 3, 4, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [10, 20, 30, 40, 5]) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50]) == True\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10]) == True\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == True\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == True\n assert candidate(nums = [10, 10, 10, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == True\n assert candidate(nums = [9, 9, 9, 9, 9, 10, 10, 10]) == True\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 99]) == True\n assert candidate(nums = [10, 20, 30, 40]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]) == True\n assert candidate(nums = [9, 99, 8, 88, 7, 77, 6, 66, 5, 55, 4, 44, 3, 33, 2, 22, 1, 11]) == True\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 1, 11, 21, 31, 41]) == True\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [55, 44, 33, 22, 11, 99, 88, 77, 66, 55, 44, 33]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [9, 12, 15, 20, 25, 30, 35, 40, 45, 50]) == True\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\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, 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]) == True\n assert candidate(nums = [10, 20, 30, 40, 5, 15, 25, 35, 45, 55]) == True\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 99]) == True\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 2, 22, 32, 42, 52, 62, 72, 82, 92, 3, 33, 43, 53, 63, 73, 83, 93, 4, 44, 54, 64, 74, 84, 94, 5, 55, 65, 75, 85, 95, 6, 66, 76, 86, 96, 7, 77, 87, 97, 8, 88, 98, 9, 99, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 45, 46, 47, 49, 50, 51, 53, 54, 55, 57, 58, 59, 61, 62, 63, 65, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, 90, 91, 93, 94, 95, 97, 98, 99]) == True\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21, 32, 43, 54, 65, 76, 87, 98, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21, 32, 43, 54, 65, 76, 87, 98, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21, 32, 43, 54, 65, 76, 87, 98, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [8, 18, 28, 38, 48, 58, 68, 78, 88, 98, 9, 19, 29, 39, 49]) == True\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]) == True\n assert candidate(nums = [88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [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]) == True\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, 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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 55]) == True\n assert candidate(nums = [1, 20, 3, 40, 5, 60, 7, 80, 9, 10]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 99]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 11, 22, 33, 44, 55, 66, 77, 88, 99, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 5, 15, 25, 35, 45]) == True\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 1, 11, 22, 33, 44]) == True\n assert candidate(nums = [99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == True\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == True\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == True\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [45, 55, 65, 75, 85, 95, 5, 15, 25, 35, 45]) == True\n assert candidate(nums = [45, 55, 65, 75, 85, 95, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50]) == True\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 5, 10, 15, 20, 25, 30]) == True\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [12, 23, 34, 45, 56, 67, 78, 89, 90, 11]) == True\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]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == True\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, 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, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98]) == True\n assert candidate(nums = [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, 10, 20, 30, 40, 50]) == True\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == True\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]) == True\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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == True\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\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]) == True\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == True\n assert candidate(nums = [1, 11, 2, 22, 3, 33, 4, 44, 5, 55, 6, 66, 7, 77, 8, 88, 9, 99]) == True\n assert candidate(nums = [50, 40, 30, 20, 10, 1, 11, 21, 31, 41, 51, 61, 71, 81, 91]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [99, 88, 77, 66, 55, 44, 33, 22, 11, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [45, 54, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 1, 2, 3, 4, 6, 7, 8, 9]) == True\n assert candidate(nums = [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]) == True\n assert candidate(nums = [5, 15, 25, 35, 45, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == True\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 2, 12, 22, 32, 42, 52, 62, 72, 82, 92]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 99, 88, 77, 66, 55, 44, 33, 22, 11]) == True\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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 60, 70, 80, 90, 5]) == True\n assert candidate(nums = [8, 17, 26, 35, 44, 53, 62, 71, 80, 89, 10, 19, 28, 37, 46]) == True\n assert candidate(nums = [1, 12, 23, 34, 45, 56, 67, 78, 89, 90]) == True\n assert candidate(nums = [99, 88, 77, 66, 55, 44, 33, 22, 11, 1]) == True\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 10, 20, 30, 40, 50]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 1, 2]) == True\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == True\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65]) == True\n assert candidate(nums = [1, 10, 2, 20, 3, 30, 4, 40, 5, 50, 6, 60, 7, 70, 8, 80, 9, 90]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [45, 55, 65, 75, 85, 95, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 15, 15, 15, 15, 15]) == True\n assert candidate(nums = [1, 12, 3, 45, 6, 78, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 49, 51, 52, 53, 54, 56, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 84, 86, 87, 88, 89, 91, 92, 93, 94, 96, 97, 98, 99]) == True\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94, 6, 93, 7, 92, 8, 91, 9, 90]) == True\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, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) == True\n assert candidate(nums = [1, 12, 3, 14, 5, 16, 7, 18, 9, 10]) == True\n assert candidate(nums = [1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(nums = [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]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 90, 81, 72, 63, 54, 45]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 99, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 1, 2, 3, 4, 6, 7, 8, 9]) == True\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,10]", "[1,2,3,4,5,14]", "[5,5,5,25]"], "hints": ["Alice wins if the sum of all single-digit numbers and the sum of all double-digit numbers are different."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().canAliceWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:50+00:00", "tests_total": 121, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "math"]}, "language": "ruby", "interface": {"raw_signature": "def can_alice_win(nums)", "container": null, "callable": "can_alice_win", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3233, "task_id": "find-the-count-of-numbers-which-are-not-special", "difficulty": "Medium", "problem_description": "You are given 2 positive integers l and r. For any number x, all positive divisors of x except x are called the proper divisors of x.\n\nA number is called special if it has exactly 2 proper divisors. For example:\n\n- The number 4 is special because it has proper divisors 1 and 2.\n- The number 6 is not special because it has proper divisors 1, 2, and 3.\n\nReturn the count of numbers in the range [l, r] that are not special.\n\nExample 1:\n\nInput: l = 5, r = 7\nOutput: 3\nExplanation:\nThere are no special numbers in the range [5, 7].\n\nExample 2:\n\nInput: l = 4, r = 16\nOutput: 11\nExplanation:\nThe special numbers in the range [4, 16] are 4 and 9.\n\nConstraints:\n\n- 1 <= l <= r <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(l = 100,r = 200) == 99\n assert candidate(l = 5,r = 7) == 3\n assert candidate(l = 20,r = 50) == 29\n assert candidate(l = 1,r = 10) == 8\n assert candidate(l = 100,r = 150) == 50\n assert candidate(l = 4,r = 16) == 11\n assert candidate(l = 10,r = 20) == 11\n assert candidate(l = 1000,r = 10000) == 8987\n assert candidate(l = 25,r = 25) == 0\n assert candidate(l = 100000,r = 200000) == 99980\n assert candidate(l = 250000,r = 250100) == 101\n assert candidate(l = 1000000,r = 1000010) == 11\n assert candidate(l = 999999999,r = 1000000000) == 2\n assert candidate(l = 1,r = 100000000) == 99998771\n assert candidate(l = 100000,r = 150000) == 49990\n assert candidate(l = 1000000000,r = 1000000000) == 1\n assert candidate(l = 500000,r = 501000) == 1001\n assert candidate(l = 3,r = 3) == 1\n assert candidate(l = 1,r = 1000000) == 999832\n assert candidate(l = 5000,r = 6000) == 999\n assert candidate(l = 10000,r = 11000) == 999\n assert candidate(l = 2,r = 2) == 1\n assert candidate(l = 5000,r = 7000) == 1997\n assert candidate(l = 1000000,r = 1500000) == 499969\n assert candidate(l = 8,r = 8) == 1\n assert candidate(l = 1000000,r = 10000000) == 8999723\n assert candidate(l = 300000000,r = 400000000) == 99999729\n assert candidate(l = 500000,r = 1000000) == 499959\n assert candidate(l = 4,r = 1000000) == 999829\n assert candidate(l = 10000000,r = 10001000) == 1001\n assert candidate(l = 25,r = 50) == 24\n assert candidate(l = 1,r = 3) == 3\n assert candidate(l = 999999,r = 1000000) == 2\n assert candidate(l = 999900,r = 1000000) == 101\n assert candidate(l = 50,r = 100) == 51\n assert candidate(l = 8,r = 100) == 90\n assert candidate(l = 16,r = 25) == 9\n assert candidate(l = 1000000,r = 1001000) == 1001\n assert candidate(l = 16,r = 256) == 237\n assert candidate(l = 999,r = 1001) == 3\n assert candidate(l = 123456,r = 789012) == 665473\n assert candidate(l = 10000,r = 10100) == 101\n assert candidate(l = 999999950,r = 1000000000) == 51\n assert candidate(l = 50000,r = 60000) == 9996\n assert candidate(l = 123456,r = 123486) == 31\n assert candidate(l = 49,r = 50) == 1\n assert candidate(l = 97,r = 101) == 5\n assert candidate(l = 10000,r = 100000) == 89961\n assert candidate(l = 3000000,r = 3000100) == 101\n assert candidate(l = 500,r = 500) == 1\n assert candidate(l = 100000000,r = 100010000) == 10001\n assert candidate(l = 1234567,r = 8765432) == 7530626\n assert candidate(l = 150,r = 250) == 100\n assert candidate(l = 2,r = 3) == 2\n assert candidate(l = 8000000,r = 8000100) == 101\n assert candidate(l = 25,r = 36) == 11\n assert candidate(l = 987654,r = 987674) == 21\n assert candidate(l = 500,r = 1500) == 997\n assert candidate(l = 5000,r = 50000) == 44972\n assert candidate(l = 2000000,r = 2000050) == 51\n assert candidate(l = 500000,r = 500010) == 11\n assert candidate(l = 1,r = 100) == 96\n assert candidate(l = 500000,r = 600000) == 99990\n assert candidate(l = 1,r = 1000) == 989\n assert candidate(l = 1000,r = 2000) == 998\n assert candidate(l = 14,r = 28) == 14\n assert candidate(l = 100000000,r = 1000000000) == 899997829\n assert candidate(l = 1000000,r = 1000100) == 101\n assert candidate(l = 500000000,r = 600000000) == 99999786\n assert candidate(l = 101,r = 200) == 98\n assert candidate(l = 100,r = 1000) == 894\n assert candidate(l = 81,r = 81) == 1\n assert candidate(l = 49,r = 64) == 15\n assert candidate(l = 8,r = 25) == 16\n assert candidate(l = 5000,r = 7500) == 2497\n assert candidate(l = 25,r = 49) == 23\n assert candidate(l = 1000,r = 1500) == 500\n", "comparison": "exact"}, "public_tests": ["5\n7", "4\n16"], "hints": ["A special number must be a square of a prime number.", "We need to find all primes in the range [sqrt(l), sqrt(r)].", "Use sieve to find primes till sqrt(10^9)."], "metadata": {"canonical_parameter_names": ["l", "r"], "leetcode_dataset_entry_point": "Solution().nonSpecialCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:52+00:00", "tests_total": 77, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "number-theory"]}, "language": "ruby", "interface": {"raw_signature": "def non_special_count(l, r)", "container": null, "callable": "non_special_count", "parameters": [{"name": "l", "type": "Integer"}, {"name": "r", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3234, "task_id": "count-the-number-of-substrings-with-dominant-ones", "difficulty": "Medium", "problem_description": "You are given a binary string s.\n\nReturn the number of substrings with dominant ones.\n\nA string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string.\n\nExample 1:\n\nInput: s = \"00011\"\nOutput: 5\nExplanation:\nThe substrings with dominant ones are shown in the table below.\n\ni | j | s[i..j] | Number of Zeros | Number of Ones\n3 | 3 | 1 | 0 | 1\n4 | 4 | 1 | 0 | 1\n2 | 3 | 01 | 1 | 1\n3 | 4 | 11 | 0 | 2\n2 | 4 | 011 | 1 | 2\n\nExample 2:\n\nInput: s = \"101101\"\nOutput: 16\nExplanation:\nThe substrings with non-dominant ones are shown in the table below.\nSince there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.\n\ni | j | s[i..j] | Number of Zeros | Number of Ones\n1 | 1 | 0 | 1 | 0\n4 | 4 | 0 | 1 | 0\n1 | 4 | 0110 | 2 | 2\n0 | 4 | 10110 | 2 | 3\n1 | 5 | 01101 | 2 | 3\n\nConstraints:\n\n- 1 <= s.length <= 4 * 10^4\n- s consists only of characters '0' and '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 10\n assert candidate(s = \"100100100\") == 8\n assert candidate(s = \"1111010101\") == 33\n assert candidate(s = \"000111000\") == 12\n assert candidate(s = \"11110000\") == 15\n assert candidate(s = \"0000\") == 0\n assert candidate(s = \"111000\") == 9\n assert candidate(s = \"01010101111\") == 34\n assert candidate(s = \"0011110011\") == 31\n assert candidate(s = \"0000101010\") == 11\n assert candidate(s = \"00001111\") == 15\n assert candidate(s = \"000111\") == 9\n assert candidate(s = \"1001001001\") == 10\n assert candidate(s = \"11111\") == 15\n assert candidate(s = \"01010101\") == 14\n assert candidate(s = \"11010101\") == 18\n assert candidate(s = \"10101010\") == 14\n assert candidate(s = \"1010100000\") == 10\n assert candidate(s = \"010101\") == 10\n assert candidate(s = \"1100111100\") == 31\n assert candidate(s = \"101010\") == 10\n assert candidate(s = \"00011\") == 5\n assert candidate(s = \"11001100\") == 13\n assert candidate(s = \"101101\") == 16\n assert candidate(s = \"111000111\") == 18\n assert candidate(s = \"1010101010101010\") == 30\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"10010010\") == 8\n assert candidate(s = \"000111000111000111000\") == 36\n assert candidate(s = \"111111111111111111111111\") == 300\n assert candidate(s = \"000011000110001100011000\") == 28\n assert candidate(s = \"1111110000000011\") == 35\n assert candidate(s = \"111000111000111000\") == 33\n assert candidate(s = \"1111000000000011111\") == 37\n assert candidate(s = \"000000111111000000111111\") == 70\n assert candidate(s = \"0110110110110110110\") == 88\n assert candidate(s = \"1101010101010101\") == 34\n assert candidate(s = \"111111111100000000000000000000\") == 74\n assert candidate(s = \"10101010101010101010101010101010101010101010101010\") == 98\n assert candidate(s = \"11000000001111111111\") == 79\n assert candidate(s = \"00111111001111110011111100111111001111110011111100111111001111110011\") == 657\n assert candidate(s = \"11110000000000000000000000000000000\") == 15\n assert candidate(s = \"111110000011111000001111100000\") == 82\n assert candidate(s = \"1100110011001100\") == 29\n assert candidate(s = \"00000000000000000000000000001111111\") == 39\n assert candidate(s = \"010101010101010101010101\") == 46\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100110\") == 133\n assert candidate(s = \"0001110001110001\") == 26\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001001001\") == 64\n assert candidate(s = \"000111000111000111\") == 33\n assert candidate(s = \"101010101010101010101010\") == 46\n assert candidate(s = \"1100000000000011\") == 10\n assert candidate(s = \"1000000000001000\") == 5\n assert candidate(s = \"111111111111111111111111111100000000000000000000\") == 496\n assert candidate(s = \"1000000000000011\") == 7\n assert candidate(s = \"010101010101010101\") == 34\n assert candidate(s = \"1000000000000000000000000000\") == 2\n assert candidate(s = \"111000111000111000111000111000\") == 57\n assert candidate(s = \"1111111000000000000\") == 39\n assert candidate(s = \"0000000000000000\") == 0\n assert candidate(s = \"11111000001111100000111110000011111\") == 104\n assert candidate(s = \"101010101010101010101010101010\") == 58\n assert candidate(s = \"0100111101110010\") == 60\n assert candidate(s = \"100100100100100100100\") == 20\n assert candidate(s = \"111100001111000011110000\") == 57\n assert candidate(s = \"0000000001111111110000000000\") == 80\n assert candidate(s = \"0011001100110011\") == 29\n assert candidate(s = \"11000011000011000011000011\") == 31\n assert candidate(s = \"0000111100001111000011110000\") == 63\n assert candidate(s = \"1000000010000000100000001\") == 10\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"11111000000000001111111111\") == 96\n assert candidate(s = \"000000010000000100000001\") == 8\n assert candidate(s = \"100010001000100010001000\") == 17\n assert candidate(s = \"11111111111111111111000000000000\") == 264\n assert candidate(s = \"1001001001001001001001001001001\") == 31\n assert candidate(s = \"0000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"11110000111100001111\") == 51\n assert candidate(s = \"1111111110000000000000000000\") == 61\n assert candidate(s = \"010101010101010101010101010101010101010101010101\") == 94\n assert candidate(s = \"11111000001111100000111110000011111000001111100000111110000011111\") == 194\n assert candidate(s = \"111111111100000000001111111111\") == 148\n assert candidate(s = \"01010101010101010101010101010101010101010101010101\") == 98\n assert candidate(s = \"000000000000000000000000000000001111111111111111111111111111111\") == 601\n assert candidate(s = \"111000011111000\") == 39\n assert candidate(s = \"11111111111111111111\") == 210\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001\") == 52\n assert candidate(s = \"0000000000000000000000000000001111111111111111111111111111111\") == 601\n assert candidate(s = \"1111111111111111\") == 136\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111111\") == 2080\n assert candidate(s = \"0000000111111111111\") == 103\n assert candidate(s = \"0101010111111111\") == 96\n assert candidate(s = \"00000000000000000000000000000000111111111111111111111111111111111\") == 676\n assert candidate(s = \"111111000000111111000000111111\") == 100\n assert candidate(s = \"0000000001111111\") == 39\n assert candidate(s = \"0001010101101011\") == 37\n assert candidate(s = \"00000000001111111111\") == 74\n assert candidate(s = \"0011001100110011001100110011001100110011001100110011001100110011001\") == 129\n assert candidate(s = \"1111100000111110000011111\") == 74\n assert candidate(s = \"111000111000111000111\") == 42\n assert candidate(s = \"1001001001001001\") == 16\n assert candidate(s = \"11001100110011001100\") == 37\n assert candidate(s = \"01010101010101010101010101010101\") == 62\n assert candidate(s = \"1110010001100011110\") == 40\n assert candidate(s = \"1111000000000000000000000000000000000000\") == 15\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"1001001001001001001001\") == 22\n assert candidate(s = \"111000111000111000111000111\") == 54\n assert candidate(s = \"0000111111110000\") == 63\n assert candidate(s = \"0011110011110011\") == 65\n assert candidate(s = \"1111111100000000\") == 49\n assert candidate(s = \"1111000011110000111100001111000011110000\") == 99\n assert candidate(s = \"11100111001110011100111001110011100111001110011100\") == 171\n assert candidate(s = \"111110000111100001111\") == 58\n assert candidate(s = \"110000110000110000110000110000\") == 33\n assert candidate(s = \"0101010101010101\") == 30\n assert candidate(s = \"000000000000000000000000\") == 0\n assert candidate(s = \"111000111000111000111000111000111000111000111000\") == 93\n assert candidate(s = \"00000000000000000000000000000000000111111111111111\") == 154\n assert candidate(s = \"0000011111111100000\") == 80\n assert candidate(s = \"0000111111111111\") == 103\n assert candidate(s = \"000111000111000111000111000111\") == 57\n assert candidate(s = \"1000100010001000100\") == 14\n assert candidate(s = \"1001001001001001001\") == 19\n assert candidate(s = \"0110011001100110011001\") == 41\n assert candidate(s = \"11111111111111111000000000000000000000000000000000000000000000011\") == 200\n assert candidate(s = \"0010110101101011\") == 46\n assert candidate(s = \"000000000011111111110000000000\") == 96\n assert candidate(s = \"00000111110000011111000001111100000111110000011111000001111100000\") == 180\n assert candidate(s = \"11111111111111111111111111111111111111111111111111\") == 1275\n assert candidate(s = \"11011011011011011011011011011011011\") == 184\n assert candidate(s = \"1110001110001110\") == 33\n assert candidate(s = \"10010010010010010010010010010010\") == 32\n assert candidate(s = \"1110011100011100011\") == 44\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"1111000011110000\") == 36\n assert candidate(s = \"10101010101010101010101010101010\") == 62\n assert candidate(s = \"01001001001001001001001\") == 23\n assert candidate(s = \"1111111111000000\") == 74\n assert candidate(s = \"0000000011111111\") == 49\n assert candidate(s = \"1111000000001111\") == 30\n assert candidate(s = \"01001001001001001001001001001001\") == 32\n assert candidate(s = \"1000001111110000\") == 42\n assert candidate(s = \"000000000011111111111111111111\") == 264\n assert candidate(s = \"1100001100001100\") == 19\n assert candidate(s = \"1111111111\") == 55\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 78\n assert candidate(s = \"0110011001100110\") == 31\n assert candidate(s = \"1111000000000000111111111111\") == 118\n assert candidate(s = \"1111000011110000111100001111\") == 72\n assert candidate(s = \"00000000000000000001\") == 2\n assert candidate(s = \"0000000000111111\") == 30\n assert candidate(s = \"0011001100110011001100110011\") == 53\n assert candidate(s = \"01010101010101010101\") == 38\n assert candidate(s = \"111110111110111110111110111110\") == 453\n assert candidate(s = \"111110000000\") == 22\n assert candidate(s = \"1111111101010101\") == 84\n assert candidate(s = \"1101001010010100\") == 24\n assert candidate(s = \"1111010101010101\") == 45\n assert candidate(s = \"000001111100000111110000011111\") == 82\n assert candidate(s = \"0000000000000000000000000001\") == 2\n assert candidate(s = \"10101010101010101010\") == 38\n assert candidate(s = \"0110110110110110110110110110110\") == 156\n assert candidate(s = \"11111111111111110000000000\") == 174\n assert candidate(s = \"0000111100001111\") == 36\n", "comparison": "exact"}, "public_tests": ["\"00011\"", "\"101101\""], "hints": ["Let us fix the starting index l of the substring and count the number of indices r such that l <= r and the substring s[l..r] has dominant ones.", "A substring with dominant ones has at most sqrt(n) zeros.", "We cannot iterate over every r and check if the s[l..r] has dominant ones. Instead, we iterate over the next sqrt(n) zeros to the left of l and count the number of substrings with dominant ones where the current zero is the rightmost zero of the substring."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().numberOfSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:54+00:00", "tests_total": 165, "tests_dropped": 0, "flags": ["figure_reference"], "topic_tags": ["string", "enumeration"]}, "language": "ruby", "interface": {"raw_signature": "def number_of_substrings(s)", "container": null, "callable": "number_of_substrings", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3235, "task_id": "check-if-the-rectangle-corner-is-reachable", "difficulty": "Hard", "problem_description": "You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [x_i, y_i, r_i] denotes a circle with center at (x_i, y_i) and radius r_i.\n\nThere is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate (xCorner, yCorner). You need to check whether there is a path from the bottom left corner to the top right corner such that the entire path lies inside the rectangle, does not touch or lie inside any circle, and touches the rectangle only at the two corners.\n\nReturn true if such a path exists, and false otherwise.\n\nExample 1:\n\nInput: xCorner = 3, yCorner = 4, circles = [[2,1,1]]\nOutput: true\nExplanation:\nThe black curve shows a possible path between (0, 0) and (3, 4).\n\nExample 2:\n\nInput: xCorner = 3, yCorner = 3, circles = [[1,1,2]]\nOutput: false\nExplanation:\nNo path exists from (0, 0) to (3, 3).\n\nExample 3:\n\nInput: xCorner = 3, yCorner = 3, circles = [[2,1,1],[1,2,1]]\nOutput: false\nExplanation:\nNo path exists from (0, 0) to (3, 3).\n\nExample 4:\n\nInput: xCorner = 4, yCorner = 4, circles = [[5,5,1]]\nOutput: true\nExplanation:\n\nConstraints:\n\n- 3 <= xCorner, yCorner <= 10^9\n- 1 <= circles.length <= 1000\n- circles[i].length == 3\n- 1 <= x_i, y_i, r_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 1, 1], [9, 9, 1]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 499999999]]) == True\n assert candidate(xCorner = 5,yCorner = 5,circles = [[1, 1, 1], [4, 4, 1], [2, 2, 1]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 100000000]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[5, 5, 2], [2, 2, 1]]) == True\n assert candidate(xCorner = 5,yCorner = 5,circles = [[2, 2, 1], [3, 3, 1]]) == True\n assert candidate(xCorner = 5,yCorner = 5,circles = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 500000000]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 1]]) == True\n assert candidate(xCorner = 3,yCorner = 3,circles = [[2, 1, 1], [1, 2, 1]]) == False\n assert candidate(xCorner = 3,yCorner = 4,circles = [[2, 1, 1]]) == True\n assert candidate(xCorner = 4,yCorner = 4,circles = [[5, 5, 1]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[5, 5, 1], [3, 3, 2]]) == True\n assert candidate(xCorner = 3,yCorner = 3,circles = [[1, 1, 2]]) == False\n assert candidate(xCorner = 15,yCorner = 15,circles = [[3, 3, 3], [12, 12, 3], [7, 7, 2], [9, 9, 1]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 500000000]]) == False\n assert candidate(xCorner = 20,yCorner = 20,circles = [[10, 10, 5], [15, 15, 3], [5, 5, 2], [18, 2, 1], [2, 18, 1]]) == True\n assert candidate(xCorner = 25,yCorner = 25,circles = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]) == False\n assert candidate(xCorner = 8,yCorner = 8,circles = [[2, 2, 3], [6, 6, 3]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[5, 5, 2], [2, 2, 3], [8, 8, 3]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 5, 1], [9, 5, 1], [5, 1, 1], [5, 9, 1], [2, 2, 2], [8, 2, 2], [2, 8, 2], [8, 8, 2]]) == False\n assert candidate(xCorner = 8,yCorner = 8,circles = [[4, 4, 2], [2, 2, 1], [6, 6, 1], [1, 7, 2], [7, 1, 2]]) == True\n assert candidate(xCorner = 1000000,yCorner = 1000000,circles = [[500000, 500000, 300000], [300000, 300000, 100000], [700000, 700000, 100000], [100000, 100000, 50000], [900000, 900000, 50000], [100000, 900000, 50000], [900000, 100000, 50000], [500000, 100000, 200000], [500000, 900000, 200000]]) == False\n assert candidate(xCorner = 15,yCorner = 15,circles = [[1, 1, 1], [14, 14, 1], [7, 7, 5]]) == False\n assert candidate(xCorner = 7,yCorner = 7,circles = [[3, 3, 1], [4, 3, 1], [3, 4, 1], [4, 4, 1], [2, 2, 1], [2, 3, 1], [3, 2, 1], [2, 4, 1], [4, 2, 1]]) == True\n assert candidate(xCorner = 30,yCorner = 30,circles = [[1, 1, 1], [29, 29, 1], [15, 15, 10], [15, 15, 5]]) == False\n assert candidate(xCorner = 9,yCorner = 9,circles = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[5, 5, 4], [2, 2, 1], [8, 8, 1], [1, 1, 1], [9, 9, 1], [4, 1, 1], [1, 4, 1], [8, 4, 1], [4, 8, 1]]) == False\n assert candidate(xCorner = 3,yCorner = 10,circles = [[2, 5, 1], [1, 3, 1], [2, 8, 1], [1, 7, 1], [2, 2, 1], [1, 1, 1], [2, 9, 1], [1, 9, 1]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 5, 2], [5, 1, 2], [5, 9, 2], [9, 5, 2]]) == True\n assert candidate(xCorner = 15,yCorner = 15,circles = [[1, 1, 1], [15, 15, 1], [1, 15, 1], [15, 1, 1], [8, 8, 3], [7, 7, 2], [9, 9, 2]]) == False\n assert candidate(xCorner = 20,yCorner = 20,circles = [[1, 1, 1], [1, 20, 1], [20, 1, 1], [20, 20, 1], [10, 10, 5]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[999999999, 999999999, 1], [500000000, 500000000, 500000000]]) == False\n assert candidate(xCorner = 9,yCorner = 9,circles = [[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], [1, 9, 2], [9, 1, 2], [4.5, 4.5, 3]]) == False\n assert candidate(xCorner = 50,yCorner = 50,circles = [[5, 5, 5], [45, 45, 5], [25, 25, 10], [15, 15, 3], [35, 35, 3]]) == False\n assert candidate(xCorner = 150,yCorner = 150,circles = [[10, 10, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10], [50, 50, 10], [60, 60, 10], [70, 70, 10], [80, 80, 10], [90, 90, 10], [100, 100, 10], [110, 110, 10], [120, 120, 10], [130, 130, 10], [140, 140, 10], [150, 150, 10]]) == False\n assert candidate(xCorner = 20,yCorner = 15,circles = [[10, 10, 5], [15, 15, 3], [5, 5, 4]]) == True\n assert candidate(xCorner = 15,yCorner = 20,circles = [[1, 1, 1], [14, 19, 1], [8, 10, 2], [7, 8, 2], [9, 8, 2], [8, 7, 2], [8, 9, 2]]) == False\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 25, 20], [50, 75, 20], [25, 50, 20], [75, 50, 20]]) == True\n assert candidate(xCorner = 500,yCorner = 500,circles = [[100, 100, 50], [400, 400, 50], [250, 250, 150], [250, 250, 100]]) == True\n assert candidate(xCorner = 999999999,yCorner = 999999999,circles = [[500000000, 500000000, 100000000], [900000000, 900000000, 100000000], [100000000, 100000000, 100000000]]) == False\n assert candidate(xCorner = 500,yCorner = 500,circles = [[250, 250, 150], [100, 100, 50], [400, 400, 50], [50, 50, 20], [450, 450, 20], [100, 450, 20], [450, 100, 20], [250, 50, 100], [250, 450, 100]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[5, 5, 2], [5, 5, 1]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[3, 3, 1], [6, 6, 1], [2, 8, 2], [8, 2, 2]]) == True\n assert candidate(xCorner = 1000,yCorner = 1000,circles = [[500, 500, 300], [300, 300, 100], [700, 700, 100], [100, 100, 50], [900, 900, 50], [100, 900, 50], [900, 100, 50], [500, 100, 200], [500, 900, 200]]) == False\n assert candidate(xCorner = 6,yCorner = 8,circles = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [1, 8, 1], [6, 1, 1]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[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]]) == False\n assert candidate(xCorner = 100,yCorner = 100,circles = [[25, 25, 20], [75, 75, 20], [50, 50, 20], [25, 75, 20], [75, 25, 20]]) == True\n assert candidate(xCorner = 9,yCorner = 9,circles = [[2, 2, 2], [2, 6, 2], [6, 2, 2], [6, 6, 2], [5, 5, 1]]) == False\n assert candidate(xCorner = 7,yCorner = 7,circles = [[2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1]]) == False\n assert candidate(xCorner = 1000000,yCorner = 1000000,circles = [[100000, 100000, 50000], [900000, 900000, 50000], [500000, 500000, 150000], [500000, 500000, 100000]]) == True\n assert candidate(xCorner = 7,yCorner = 7,circles = [[1, 6, 1], [2, 5, 1], [3, 4, 1], [4, 3, 1], [5, 2, 1], [6, 1, 1], [7, 7, 1], [7, 6, 1], [7, 5, 1], [7, 4, 1], [7, 3, 1], [7, 2, 1], [7, 1, 1]]) == False\n assert candidate(xCorner = 30,yCorner = 40,circles = [[15, 20, 5], [10, 25, 6], [20, 10, 4], [5, 30, 3], [25, 5, 2]]) == True\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 50, 30], [70, 70, 20], [30, 30, 25], [10, 10, 10], [90, 90, 10]]) == False\n assert candidate(xCorner = 12,yCorner = 12,circles = [[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], [11, 11, 1], [12, 12, 1], [1, 12, 1], [12, 1, 1]]) == False\n assert candidate(xCorner = 12,yCorner = 12,circles = [[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]]) == False\n assert candidate(xCorner = 20,yCorner = 20,circles = [[5, 10, 3], [10, 5, 3], [10, 15, 3], [15, 10, 3], [10, 10, 5]]) == True\n assert candidate(xCorner = 8,yCorner = 8,circles = [[1, 8, 1], [8, 1, 1], [4, 4, 2], [2, 2, 1], [6, 6, 1], [5, 5, 1], [3, 3, 1], [7, 7, 1]]) == False\n assert candidate(xCorner = 10,yCorner = 3,circles = [[5, 2, 1], [4, 2, 1], [6, 2, 1], [3, 2, 1], [7, 2, 1], [2, 2, 1], [8, 2, 1], [5, 1, 1]]) == False\n assert candidate(xCorner = 20,yCorner = 20,circles = [[1, 1, 1], [20, 20, 1], [10, 10, 5], [15, 5, 3]]) == False\n assert candidate(xCorner = 25,yCorner = 25,circles = [[5, 10, 5], [10, 5, 5], [20, 20, 5], [15, 15, 5], [25, 5, 5], [5, 25, 5]]) == False\n assert candidate(xCorner = 50,yCorner = 50,circles = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [45, 45, 1], [46, 46, 1], [47, 47, 1], [48, 48, 1], [49, 49, 1]]) == False\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 1, 1], [9, 9, 1], [5, 5, 2], [3, 3, 1], [7, 7, 1]]) == False\n assert candidate(xCorner = 15,yCorner = 15,circles = [[8, 8, 3], [7, 7, 2], [6, 6, 1], [9, 9, 2], [10, 10, 3], [11, 11, 4]]) == False\n assert candidate(xCorner = 50,yCorner = 50,circles = [[10, 10, 5], [20, 20, 5], [30, 30, 5], [40, 40, 5], [50, 50, 5]]) == False\n assert candidate(xCorner = 80,yCorner = 60,circles = [[10, 10, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10], [50, 50, 10], [60, 60, 10], [70, 70, 10]]) == False\n assert candidate(xCorner = 10000,yCorner = 10000,circles = [[1000, 1000, 500], [9000, 9000, 500], [5000, 5000, 1500], [5000, 5000, 1000]]) == True\n assert candidate(xCorner = 7,yCorner = 7,circles = [[1, 1, 1], [1, 7, 1], [7, 1, 1], [7, 7, 1], [3, 4, 1], [4, 3, 1], [4, 5, 1], [5, 4, 1]]) == False\n assert candidate(xCorner = 9,yCorner = 9,circles = [[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]]) == False\n assert candidate(xCorner = 30,yCorner = 40,circles = [[10, 10, 5], [20, 20, 10], [5, 5, 2], [25, 25, 4]]) == True\n assert candidate(xCorner = 50,yCorner = 50,circles = [[25, 25, 10], [30, 30, 15], [20, 20, 5], [10, 40, 5]]) == True\n assert candidate(xCorner = 100000,yCorner = 100000,circles = [[10000, 10000, 5000], [90000, 90000, 5000], [50000, 50000, 15000], [50000, 50000, 10000]]) == True\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 50, 20], [30, 30, 5], [70, 70, 5], [10, 10, 2], [90, 90, 2], [10, 90, 2], [90, 10, 2], [50, 10, 10], [50, 90, 10]]) == True\n assert candidate(xCorner = 500000000,yCorner = 500000000,circles = [[250000000, 250000000, 100000000], [300000000, 300000000, 150000000]]) == True\n assert candidate(xCorner = 100,yCorner = 100,circles = [[10, 10, 5], [90, 90, 5], [50, 50, 20], [50, 50, 10]]) == True\n assert candidate(xCorner = 1000,yCorner = 1000,circles = [[100, 100, 100], [900, 900, 100], [500, 500, 500], [300, 700, 200], [700, 300, 200]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 500000000], [1000000000, 1000000000, 1]]) == False\n assert candidate(xCorner = 1000,yCorner = 1000,circles = [[1, 1, 1], [1000, 1000, 1], [500, 500, 100], [900, 900, 50]]) == False\n assert candidate(xCorner = 1000000000,yCorner = 1000000000,circles = [[500000000, 500000000, 499999999], [1000000000, 1000000000, 1]]) == False\n assert candidate(xCorner = 9,yCorner = 9,circles = [[3, 3, 2], [6, 6, 2], [4, 4, 1], [5, 5, 1]]) == True\n assert candidate(xCorner = 50,yCorner = 50,circles = [[25, 25, 10], [10, 10, 5], [40, 40, 5], [5, 5, 2], [45, 45, 2], [10, 40, 2], [40, 10, 2]]) == True\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 50, 10], [40, 40, 10], [60, 60, 10], [50, 30, 10], [50, 70, 10]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 1, 1], [9, 9, 1], [5, 5, 2], [2, 5, 1], [5, 2, 1]]) == False\n assert candidate(xCorner = 50,yCorner = 50,circles = [[10, 10, 5], [20, 20, 5], [30, 30, 5], [40, 40, 5]]) == True\n assert candidate(xCorner = 1000,yCorner = 1000,circles = [[100, 100, 100], [900, 900, 100], [500, 500, 300], [500, 500, 200]]) == False\n assert candidate(xCorner = 25,yCorner = 25,circles = [[5, 5, 4], [20, 20, 4], [15, 15, 4], [10, 10, 3], [25, 25, 1]]) == False\n assert candidate(xCorner = 20,yCorner = 20,circles = [[5, 5, 4], [15, 15, 4], [10, 10, 6]]) == True\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 50, 10], [20, 20, 5], [80, 80, 5], [10, 10, 2], [90, 90, 2], [10, 90, 2], [90, 10, 2], [50, 10, 5], [50, 90, 5], [10, 50, 5], [90, 50, 5]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[1, 1, 2], [9, 9, 2], [5, 5, 3]]) == False\n assert candidate(xCorner = 50,yCorner = 50,circles = [[10, 10, 5], [40, 40, 5], [10, 40, 5], [40, 10, 5], [25, 25, 10]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[2, 2, 2], [3, 3, 1], [4, 4, 2], [5, 5, 1], [6, 6, 2], [7, 7, 1], [8, 8, 2]]) == False\n assert candidate(xCorner = 100,yCorner = 50,circles = [[25, 25, 15], [75, 25, 15], [50, 45, 10]]) == True\n assert candidate(xCorner = 15,yCorner = 15,circles = [[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]]) == False\n assert candidate(xCorner = 25,yCorner = 25,circles = [[5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1], [11, 11, 1], [12, 12, 1], [13, 13, 1], [14, 14, 1], [15, 15, 1], [16, 16, 1], [17, 17, 1], [18, 18, 1], [19, 19, 1], [20, 20, 1], [21, 21, 1], [22, 22, 1], [23, 23, 1], [24, 24, 1], [25, 25, 1], [1, 1, 12], [25, 25, 12]]) == False\n assert candidate(xCorner = 100,yCorner = 100,circles = [[25, 25, 20], [75, 75, 20], [50, 50, 10], [10, 90, 10], [90, 10, 10]]) == True\n assert candidate(xCorner = 999999999,yCorner = 999999999,circles = [[499999999, 499999999, 100000000], [500000000, 500000000, 200000000]]) == True\n assert candidate(xCorner = 999999999,yCorner = 999999999,circles = [[999999999, 999999999, 10], [1, 1, 100], [500000000, 500000000, 1000000]]) == False\n assert candidate(xCorner = 18,yCorner = 18,circles = [[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], [11, 11, 1], [12, 12, 1], [13, 13, 1], [14, 14, 1], [15, 15, 1], [16, 16, 1], [17, 17, 1], [18, 18, 1], [9, 9, 5]]) == False\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 50, 20], [30, 70, 15], [70, 30, 15], [10, 10, 5], [90, 90, 5], [20, 20, 3], [80, 80, 3]]) == True\n assert candidate(xCorner = 12,yCorner = 12,circles = [[6, 6, 3], [3, 3, 2], [9, 9, 2], [1, 1, 1], [11, 11, 1]]) == False\n assert candidate(xCorner = 18,yCorner = 18,circles = [[9, 9, 5], [1, 1, 1], [17, 17, 1], [1, 17, 1], [17, 1, 1], [5, 5, 1], [13, 13, 1], [7, 13, 1], [13, 7, 1]]) == False\n assert candidate(xCorner = 20,yCorner = 20,circles = [[5, 5, 3], [10, 10, 3], [15, 15, 3], [2, 2, 1], [18, 18, 1]]) == True\n assert candidate(xCorner = 10,yCorner = 10,circles = [[3, 3, 2], [7, 7, 2], [5, 5, 1]]) == True\n assert candidate(xCorner = 100,yCorner = 100,circles = [[50, 50, 40], [70, 30, 20], [30, 70, 25], [10, 10, 5], [90, 90, 5]]) == True\n assert candidate(xCorner = 20,yCorner = 20,circles = [[5, 5, 1], [15, 15, 1], [10, 10, 5], [5, 15, 1], [15, 5, 1]]) == True\n", "comparison": "exact"}, "public_tests": ["3\n4\n[[2,1,1]]", "3\n3\n[[1,1,2]]", "3\n3\n[[2,1,1],[1,2,1]]", "4\n4\n[[5,5,1]]"], "hints": ["Create a graph with n + 4 vertices.", "Vertices 0 to n - 1 represent the circles, vertex n represents upper edge, vertex n + 1 represents right edge, vertex n + 2 represents lower edge, and vertex n + 3 represents left edge.", "Add an edge between these vertices if they intersect or touch.", "Answer will be false when any of two sides left-right, left-bottom, right-top or top-bottom are reachable using the edges."], "metadata": {"canonical_parameter_names": ["xCorner", "yCorner", "circles"], "leetcode_dataset_entry_point": "Solution().canReachCorner", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:17:56+00:00", "tests_total": 105, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "depth-first-search", "breadth-first-search", "union-find", "geometry"]}, "language": "ruby", "interface": {"raw_signature": "def can_reach_corner(x_corner, y_corner, circles)", "container": null, "callable": "can_reach_corner", "parameters": [{"name": "x_corner", "type": "Integer"}, {"name": "y_corner", "type": "Integer"}, {"name": "circles", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3238, "task_id": "find-the-number-of-winning-players", "difficulty": "Easy", "problem_description": "You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [x_i, y_i] represents that the player x_i picked a ball of color y_i.\n\nPlayer i wins the game if they pick strictly more than i balls of the same color. In other words,\n\n- Player 0 wins if they pick any ball.\n- Player 1 wins if they pick at least two balls of the same color.\n- ...\n- Player i wins if they pick at least i + 1 balls of the same color.\n\nReturn the number of players who win the game.\n\nNote that multiple players can win the game.\n\nExample 1:\n\nInput: n = 4, pick = [[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]\nOutput: 2\nExplanation:\nPlayer 0 and player 1 win the game, while players 2 and 3 do not win.\n\nExample 2:\n\nInput: n = 5, pick = [[1,1],[1,2],[1,3],[1,4]]\nOutput: 0\nExplanation:\nNo player wins the game.\n\nExample 3:\n\nInput: n = 5, pick = [[1,1],[2,4],[2,4],[2,4]]\nOutput: 1\nExplanation:\nPlayer 2 wins the game by picking 3 balls with color 4.\n\nConstraints:\n\n- 2 <= n <= 10\n- 1 <= pick.length <= 100\n- pick[i].length == 2\n- 0 <= x_i <= n - 1\n- 0 <= y_i <= 10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,pick = [[0, 0], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2], [3, 3], [3, 3], [3, 3], [3, 3]]) == 4\n assert candidate(n = 10,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 1\n assert candidate(n = 3,pick = [[0, 0], [1, 0], [1, 0], [1, 0]]) == 2\n assert candidate(n = 5,pick = [[1, 1], [2, 4], [2, 4], [2, 4]]) == 1\n assert candidate(n = 2,pick = [[0, 0], [1, 1], [1, 1]]) == 2\n assert candidate(n = 5,pick = [[1, 1], [1, 2], [1, 3], [1, 4]]) == 0\n assert candidate(n = 2,pick = [[0, 0], [1, 0], [1, 0], [1, 0]]) == 2\n assert candidate(n = 4,pick = [[0, 0], [1, 0], [1, 0], [2, 1], [2, 1], [2, 0]]) == 2\n assert candidate(n = 3,pick = [[0, 0], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2]]) == 3\n assert candidate(n = 4,pick = [[0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]) == 2\n assert candidate(n = 10,pick = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [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, 4]]) == 5\n assert candidate(n = 4,pick = [[0, 1], [1, 1], [1, 2], [2, 2], [2, 2], [2, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2]]) == 3\n assert candidate(n = 5,pick = [[0, 1], [1, 1], [1, 2], [2, 2], [2, 2], [2, 3], [2, 3], [3, 3], [3, 3], [3, 4], [3, 4], [4, 4], [4, 5], [4, 5], [4, 6]]) == 1\n assert candidate(n = 6,pick = [[0, 0], [1, 1], [1, 1], [1, 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], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]]) == 6\n assert candidate(n = 10,pick = [[0, 0], [1, 0], [1, 0], [2, 0], [2, 0], [2, 0], [2, 1], [3, 0], [3, 1], [3, 2], [3, 2], [3, 2], [4, 0], [4, 1], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 4], [5, 4], [6, 0], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 5], [6, 5], [7, 0], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 6], [7, 6], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 7], [8, 7], [9, 0], [9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 8], [9, 8]]) == 3\n assert candidate(n = 7,pick = [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [3, 4], [3, 4], [3, 4], [3, 4], [4, 5], [4, 5], [4, 5], [4, 5], [5, 6], [5, 6], [5, 6], [5, 6], [6, 7], [6, 7], [6, 7], [6, 7], [6, 7], [6, 7], [6, 7]]) == 5\n assert candidate(n = 3,pick = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [2, 0], [2, 1], [2, 2], [2, 0], [2, 1], [2, 2], [2, 0], [2, 1], [2, 2]]) == 3\n assert candidate(n = 4,pick = [[0, 1], [0, 2], [0, 3], [1, 1], [1, 1], [1, 2], [2, 1], [2, 2], [2, 2], [3, 1], [3, 2], [3, 3], [3, 3], [3, 3]]) == 2\n assert candidate(n = 6,pick = [[0, 0], [1, 0], [1, 0], [1, 1], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [3, 3], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 2\n assert candidate(n = 7,pick = [[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [2, 2], [3, 2], [3, 3], [3, 3], [3, 3], [4, 3], [4, 4], [4, 4], [4, 4], [5, 4], [5, 4], [5, 5], [5, 5], [5, 5], [5, 5], [6, 5], [6, 5], [6, 5], [6, 6], [6, 6]]) == 1\n assert candidate(n = 3,pick = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]) == 2\n assert candidate(n = 5,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(n = 5,pick = [[0, 0], [0, 0], [0, 0], [0, 0], [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], [3, 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]]) == 5\n assert candidate(n = 8,pick = [[0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 1], [1, 1], [2, 0], [2, 0], [2, 0], [2, 1], [2, 1], [2, 2], [2, 2], [3, 0], [3, 0], [3, 0], [3, 1], [3, 1], [3, 1], [3, 2], [3, 2], [3, 2], [3, 3], [3, 3], [4, 0], [4, 0], [4, 0], [4, 0], [4, 1], [4, 1], [4, 1], [4, 1], [4, 2], [4, 2], [4, 2], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 4], [4, 4], [4, 4]]) == 3\n assert candidate(n = 7,pick = [[0, 1], [0, 2], [0, 3], [1, 1], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [4, 4], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]]) == 2\n assert candidate(n = 5,pick = [[0, 0], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2], [3, 3], [3, 3], [3, 3], [3, 3]]) == 4\n assert candidate(n = 6,pick = [[0, 0], [1, 0], [1, 0], [1, 0], [2, 0], [2, 0], [2, 0], [2, 0], [3, 0], [3, 0], [3, 0], [3, 0], [3, 0], [4, 0], [4, 0], [4, 0], [4, 0], [4, 0], [5, 0], [5, 0], [5, 0], [5, 0], [5, 0], [5, 0]]) == 6\n assert candidate(n = 5,pick = [[0, 0], [0, 1], [1, 0], [1, 0], [1, 1], [2, 1], [2, 1], [2, 1], [3, 2], [3, 2], [3, 2], [3, 2]]) == 4\n assert candidate(n = 10,pick = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2]]) == 1\n assert candidate(n = 7,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]) == 4\n assert candidate(n = 6,pick = [[0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [1, 2], [1, 2], [2, 2], [2, 2], [2, 2], [2, 3], [2, 3], [2, 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, 5], [5, 5]]) == 6\n assert candidate(n = 10,pick = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == 1\n assert candidate(n = 5,pick = [[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [2, 2], [3, 2], [3, 2], [3, 3], [4, 3], [4, 4], [4, 4], [4, 4]]) == 1\n assert candidate(n = 4,pick = [[0, 0], [0, 0], [0, 0], [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, 3]]) == 4\n assert candidate(n = 7,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [0, 0], [1, 1], [2, 2]]) == 3\n assert candidate(n = 5,pick = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [3, 0], [3, 1], [3, 2], [3, 3], [3, 4], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4]]) == 1\n assert candidate(n = 6,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]]) == 1\n assert candidate(n = 4,pick = [[0, 1], [0, 1], [0, 1], [1, 1], [1, 1], [1, 1], [1, 1], [2, 1], [2, 1], [2, 1], [2, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1]]) == 4\n assert candidate(n = 8,pick = [[0, 0], [0, 0], [0, 0], [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, 3]]) == 4\n assert candidate(n = 5,pick = [[0, 0], [1, 0], [1, 1], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [3, 3], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4]]) == 1\n assert candidate(n = 5,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == 4\n assert candidate(n = 5,pick = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 0], [1, 1], [1, 1], [1, 2], [1, 2], [2, 0], [2, 0], [2, 1], [2, 2], [3, 0], [3, 0], [3, 0], [4, 0]]) == 2\n assert candidate(n = 10,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [9, 0], [9, 0], [9, 0], [9, 0]]) == 1\n assert candidate(n = 10,pick = [[0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 0], [1, 1], [1, 1], [2, 0], [2, 0], [2, 0], [2, 1], [2, 1], [2, 2], [2, 2], [3, 0], [3, 0], [3, 0], [3, 1], [3, 1], [3, 1], [3, 2], [3, 2], [3, 2], [3, 3], [3, 3], [4, 0], [4, 0], [4, 0], [4, 0], [4, 1], [4, 1], [4, 1], [4, 1], [4, 2], [4, 2], [4, 2], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 4], [4, 4], [4, 4], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [6, 6], [6, 6], [6, 6], [6, 6], [6, 6], [6, 6], [6, 6], [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], [8, 8], [8, 8], [8, 8], [8, 8], [9, 9], [9, 9], [9, 9], [9, 9], [9, 9], [9, 9], [9, 9], [9, 9], [9, 9], [9, 9]]) == 8\n assert candidate(n = 6,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 5\n assert candidate(n = 6,pick = [[0, 1], [0, 1], [1, 2], [1, 2], [1, 2], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [3, 4], [3, 4], [3, 4], [4, 5], [4, 5], [5, 6]]) == 3\n assert candidate(n = 10,pick = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == 1\n assert candidate(n = 5,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7]]) == 1\n assert candidate(n = 5,pick = [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5]]) == 5\n assert candidate(n = 10,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 4\n assert candidate(n = 4,pick = [[0, 0], [0, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [2, 0], [2, 0], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [3, 0], [3, 1], [3, 2], [3, 0], [3, 1], [3, 2], [3, 0], [3, 1], [3, 2], [3, 0], [3, 1], [3, 2]]) == 4\n assert candidate(n = 5,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == 5\n assert candidate(n = 10,pick = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 3\n assert candidate(n = 6,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 1], [0, 1], [1, 2], [1, 2], [2, 3], [2, 3], [3, 4], [3, 4], [4, 5], [4, 5], [5, 6], [5, 6], [0, 1], [0, 1], [0, 1], [1, 2], [1, 2], [1, 2], [1, 2], [2, 3], [2, 3], [2, 3], [2, 3], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [5, 6], [5, 6], [5, 6], [5, 6], [5, 6], [5, 6], [5, 6]]) == 6\n assert candidate(n = 4,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 1], [1, 2], [2, 3], [3, 4], [0, 1], [1, 2]]) == 2\n assert candidate(n = 7,pick = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [3, 1], [4, 1], [5, 1], [6, 1], [4, 1], [5, 1], [6, 1], [5, 1], [6, 1], [6, 1]]) == 7\n assert candidate(n = 9,pick = [[0, 0], [1, 0], [1, 1], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [3, 3], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [6, 0], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [7, 0], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8]]) == 1\n assert candidate(n = 6,pick = [[0, 0], [0, 1], [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, 4]]) == 5\n assert candidate(n = 5,pick = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [4, 0]]) == 1\n assert candidate(n = 5,pick = [[0, 0], [1, 1], [1, 2], [2, 2], [2, 3], [3, 3], [3, 3], [3, 4], [4, 0], [4, 1], [4, 1]]) == 1\n assert candidate(n = 10,pick = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [0, 1], [0, 1], [1, 2], [1, 2], [1, 2], [2, 3], [2, 3], [2, 3], [2, 3], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4]]) == 4\n assert candidate(n = 5,pick = [[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [2, 2], [3, 2], [3, 3], [3, 3], [3, 3]]) == 1\n assert candidate(n = 5,pick = [[0, 1], [1, 1], [1, 2], [2, 2], [2, 3], [2, 3], [3, 3], [3, 4], [3, 4], [3, 4], [4, 4]]) == 1\n assert candidate(n = 10,pick = [[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [2, 2], [3, 2], [3, 3], [3, 3], [3, 3], [4, 3], [4, 4], [4, 4], [4, 4], [5, 4], [5, 4], [5, 5], [5, 5], [5, 5], [5, 5], [6, 5], [6, 5], [6, 5], [6, 6], [6, 6], [7, 6], [7, 6], [7, 6], [7, 6], [7, 7], [8, 7], [8, 7], [8, 7], [8, 7], [8, 8], [8, 8], [9, 8], [9, 8], [9, 8], [9, 8], [9, 9], [9, 9], [9, 9], [9, 9]]) == 1\n assert candidate(n = 6,pick = [[0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [1, 1], [2, 2], [2, 2], [2, 2], [3, 3], [3, 3], [4, 4], [4, 4], [4, 4], [4, 4], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]]) == 4\n assert candidate(n = 6,pick = [[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [2, 2], [3, 2], [3, 3], [3, 3], [3, 3], [4, 3], [4, 4], [4, 4], [4, 4], [5, 4], [5, 4], [5, 5], [5, 5], [5, 5], [5, 5]]) == 1\n assert candidate(n = 5,pick = [[0, 1], [1, 1], [1, 1], [1, 1], [1, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]]) == 3\n assert candidate(n = 7,pick = [[0, 0], [1, 0], [1, 1], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [3, 3], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [6, 0], [6, 0], [6, 1], [6, 1], [6, 2], [6, 2], [6, 3], [6, 3], [6, 4], [6, 4], [6, 5], [6, 5]]) == 1\n assert candidate(n = 5,pick = [[0, 0], [1, 0], [1, 0], [1, 0], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3]]) == 5\n", "comparison": "exact"}, "public_tests": ["4\n[[0,0],[1,0],[1,0],[2,1],[2,1],[2,0]]", "5\n[[1,1],[1,2],[1,3],[1,4]]", "5\n[[1,1],[2,4],[2,4],[2,4]]"], "hints": ["Keep track of the number of balls of each color for each user using hashing.", "Find the maximum color that occurred for each player."], "metadata": {"canonical_parameter_names": ["n", "pick"], "leetcode_dataset_entry_point": "Solution().winningPlayerCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:02+00:00", "tests_total": 69, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "ruby", "interface": {"raw_signature": "def winning_player_count(n, pick)", "container": null, "callable": "winning_player_count", "parameters": [{"name": "n", "type": "Integer"}, {"name": "pick", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3239, "task_id": "minimum-number-of-flips-to-make-binary-grid-palindromic-i", "difficulty": "Medium", "problem_description": "You are given an m x n binary matrix grid.\n\nA row or column is considered palindromic if its values read the same forward and backward.\n\nYou can flip any number of cells in grid from 0 to 1, or from 1 to 0.\n\nReturn the minimum number of cells that need to be flipped to make either all rows palindromic or all columns palindromic.\n\nExample 1:\n\nInput: grid = [[1,0,0],[0,0,0],[0,0,1]]\nOutput: 2\nExplanation:\nFlipping the highlighted cells makes all the rows palindromic.\n\nExample 2:\n\nInput: grid = [[0,1],[0,1],[0,0]]\nOutput: 1\nExplanation:\nFlipping the highlighted cell makes all the columns palindromic.\n\nExample 3:\n\nInput: grid = [[1],[0]]\nOutput: 0\nExplanation:\nAll rows are already palindromic.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m * n <= 2 * 10^5\n- 0 <= grid[i][j] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 1, 1], [1, 1, 0, 0], [1, 0, 1, 0]]) == 2\n assert candidate(grid = [[1], [0]]) == 0\n assert candidate(grid = [[0, 1], [0, 1], [0, 0]]) == 1\n assert candidate(grid = [[1, 1, 0], [0, 1, 0], [0, 1, 1]]) == 2\n assert candidate(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]) == 0\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0], [0, 0, 0], [0, 0, 1]]) == 2\n assert candidate(grid = [[0, 0, 1, 1], [1, 1, 0, 0], [1, 1, 0, 0]]) == 4\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[0, 1, 1, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 1, 1], [1, 0, 1, 0, 0], [0, 0, 1, 1, 1]]) == 6\n assert candidate(grid = [[0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 2\n assert candidate(grid = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1, 1], [1, 0, 1, 0, 0, 0, 1, 0, 1]]) == 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\n assert candidate(grid = [[1, 1, 1, 1, 0], [0, 1, 1, 0, 1], [1, 0, 0, 1, 1], [0, 1, 1, 0, 1]]) == 6\n assert candidate(grid = [[0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0]]) == 4\n assert candidate(grid = [[1, 1, 1, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 0, 1, 1, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 0, 1, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1]]) == 2\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 1, 1, 0, 1, 1], [1, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0]]) == 6\n assert candidate(grid = [[0, 1, 1, 0, 0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0, 0, 1, 1, 0]]) == 20\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]]) == 12\n assert candidate(grid = [[1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0]]) == 6\n assert candidate(grid = [[0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 1, 0, 0, 1, 1], [0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]]) == 8\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 24\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 12\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]]) == 16\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0]]) == 6\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0]]) == 12\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\n assert candidate(grid = [[0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 5\n assert candidate(grid = [[0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [0, 1, 0, 0, 0, 1, 0]]) == 4\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\n assert candidate(grid = [[0, 1, 1, 0], [1, 0, 0, 1], [0, 1, 1, 0], [1, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 0, 1], [1, 1, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1]]) == 3\n assert candidate(grid = [[1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1]]) == 16\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1]]) == 6\n assert candidate(grid = [[1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 6\n assert candidate(grid = [[1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1]]) == 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, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[0, 1, 0, 0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 1, 1], [0, 1, 0, 1, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 7\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\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 9\n assert candidate(grid = [[0, 0, 0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0]]) == 4\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1], [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]]) == 16\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 20\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1]]) == 3\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == 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]]) == 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], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 20\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\n assert candidate(grid = [[1, 1, 0, 1, 1, 1, 1, 0, 1], [0, 0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 1, 0], [1, 1, 0, 1, 1, 1, 1, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 2\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]]) == 16\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 0, 1, 0, 1, 0, 1, 0, 0], [1, 0, 0, 1, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 0, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]]) == 3\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]]) == 0\n", "comparison": "exact"}, "public_tests": ["[[1,0,0],[0,0,0],[0,0,1]]", "[[0,1],[0,1],[0,0]]", "[[1],[0]]"], "hints": ["We need to perform the operation only when the equivalent element of i from the back is not equal."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:05+00:00", "tests_total": 77, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def min_flips(grid)", "container": null, "callable": "min_flips", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3240, "task_id": "minimum-number-of-flips-to-make-binary-grid-palindromic-ii", "difficulty": "Medium", "problem_description": "You are given an m x n binary matrix grid.\n\nA row or column is considered palindromic if its values read the same forward and backward.\n\nYou can flip any number of cells in grid from 0 to 1, or from 1 to 0.\n\nReturn the minimum number of cells that need to be flipped to make all rows and columns palindromic, and the total number of 1's in grid divisible by 4.\n\nExample 1:\n\nInput: grid = [[1,0,0],[0,1,0],[0,0,1]]\nOutput: 3\nExplanation:\n\nExample 2:\n\nInput: grid = [[0,1],[0,1],[0,0]]\nOutput: 2\nExplanation:\n\nExample 3:\n\nInput: grid = [[1],[1]]\nOutput: 2\nExplanation:\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m * n <= 2 * 10^5\n- 0 <= grid[i][j] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == 3\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == 1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 1\n assert candidate(grid = [[0, 1], [0, 1], [0, 0]]) == 2\n assert candidate(grid = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 2\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0]]) == 6\n assert candidate(grid = [[1], [1]]) == 2\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 0], [0, 1], [1, 0]]) == 3\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1]]) == 8\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 8\n assert candidate(grid = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 6\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == 0\n assert candidate(grid = [[0, 1, 0], [1, 0, 1], [0, 1, 0]]) == 0\n assert candidate(grid = [[1, 0], [0, 1], [1, 0], [0, 1]]) == 4\n assert candidate(grid = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 1, 0]]) == 2\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0, 0], [1, 0, 0, 1, 0, 0, 1]]) == 7\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [1, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 0, 1], [0, 1, 0, 1, 1, 0]]) == 12\n assert candidate(grid = [[1, 1, 0, 1], [0, 0, 0, 0], [1, 0, 0, 1], [1, 1, 1, 1]]) == 3\n assert candidate(grid = [[1, 1, 0, 1], [1, 1, 0, 1], [0, 0, 1, 0], [0, 0, 1, 0], [1, 1, 0, 1], [1, 1, 0, 1]]) == 6\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == 1\n assert candidate(grid = [[1, 0, 1, 1, 0, 1], [0, 1, 0, 0, 1, 0], [1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0], [1, 0, 0, 1, 0, 1]]) == 6\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]]) == 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]]) == 10\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1]]) == 8\n assert candidate(grid = [[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, 1]]) == 14\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, 1, 0, 1, 0, 1, 0, 1, 0]]) == 18\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) == 1\n assert candidate(grid = [[1, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0]]) == 12\n assert candidate(grid = [[1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1]]) == 6\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 1, 1, 0]]) == 8\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0, 1], [1, 1, 0, 0, 0, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0, 1]]) == 15\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 12\n assert candidate(grid = [[1, 0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1]]) == 12\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\n assert candidate(grid = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 0, 1, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 1, 0], [1, 0, 1, 1, 0, 1, 0, 1]]) == 4\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 0], [1, 0, 1, 1, 1, 1, 0, 1], [1, 1, 0, 1, 1, 0, 1, 1], [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 0, 1, 1, 0, 1, 1], [1, 0, 1, 1, 1, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0]]) == 2\n assert candidate(grid = [[1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 1, 0, 0, 1]]) == 4\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 15\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 8\n assert candidate(grid = [[1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1]]) == 12\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]) == 10\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 0, 1, 0, 1]]) == 1\n assert candidate(grid = [[1, 1, 1, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 1], [1, 1, 1, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 1]]) == 14\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]]) == 0\n assert candidate(grid = [[1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1]]) == 16\n assert candidate(grid = [[1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 1]]) == 4\n assert candidate(grid = [[1, 1, 0, 0, 1], [0, 1, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 1, 0, 0, 1]]) == 3\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 1, 0, 0], [0, 0, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 0, 0]]) == 7\n assert candidate(grid = [[1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0], [1, 0, 0, 0, 0, 1]]) == 0\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0]]) == 18\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1], [1, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1]]) == 10\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], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 20\n assert candidate(grid = [[1, 1, 0, 0, 1, 1, 1], [0, 0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 1, 1, 1, 0], [1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 1]]) == 7\n assert candidate(grid = [[0, 0, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0], [1, 1, 0, 0, 1, 1], [0, 1, 1, 1, 1, 0], [0, 0, 1, 1, 0, 0]]) == 0\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0], [1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0]]) == 14\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 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]]) == 14\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == 10\n assert candidate(grid = [[0, 0, 1, 0, 1, 0], [1, 0, 1, 1, 0, 1], [0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0]]) == 8\n assert candidate(grid = [[1, 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, 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, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 35\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 50\n assert candidate(grid = [[0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 9\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 1, 1, 0]]) == 9\n assert candidate(grid = [[1, 1, 0, 1, 1, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 1, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 1, 0, 1, 1]]) == 10\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]]) == 1\n assert candidate(grid = [[1, 0, 1, 1, 0], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 0, 1, 1, 0]]) == 5\n assert candidate(grid = [[0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1], [0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1]]) == 12\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]]) == 12\n assert candidate(grid = [[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, 1]]) == 14\n assert candidate(grid = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]) == 0\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == 10\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 1, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 1, 0, 0, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1]]) == 2\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]]) == 0\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1]]) == 4\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, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 22\n assert candidate(grid = [[1, 0, 1, 1, 0, 1], [0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1], [0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1]]) == 0\n", "comparison": "exact"}, "public_tests": ["[[1,0,0],[0,1,0],[0,0,1]]", "[[0,1],[0,1],[0,0]]", "[[1],[1]]"], "hints": ["For each (x, y), find (m - 1 - x, y), (m - 1 - x, n - 1 - y), and (x, n - 1 - y); they should be the same.", "Note that we need to specially handle the middle row (column) if the number of rows (columns) is odd."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:07+00:00", "tests_total": 88, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "matrix"]}, "language": "ruby", "interface": {"raw_signature": "def min_flips(grid)", "container": null, "callable": "min_flips", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3241, "task_id": "time-taken-to-mark-all-nodes", "difficulty": "Hard", "problem_description": "There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [u_i, v_i] indicates that there is an edge between nodes u_i and v_i in the tree.\n\nInitially, all nodes are unmarked. For each node i:\n\n- If i is odd, the node will get marked at time x if there is at least one node adjacent to it which was marked at time x - 1.\n- If i is even, the node will get marked at time x if there is at least one node adjacent to it which was marked at time x - 2.\n\nReturn an array times where times[i] is the time when all nodes get marked in the tree, if you mark node i at time t = 0.\n\nNote that the answer for each times[i] is independent, i.e. when you mark node i all other nodes are unmarked.\n\nExample 1:\n\nInput: edges = [[0,1],[0,2]]\nOutput: [2,4,3]\nExplanation:\n- For i = 0:\n - Node 1 is marked at t = 1, and Node 2 at t = 2.\n- For i = 1:\n - Node 0 is marked at t = 2, and Node 2 at t = 4.\n- For i = 2:\n - Node 0 is marked at t = 2, and Node 1 at t = 3.\n\nExample 2:\n\nInput: edges = [[0,1]]\nOutput: [1,2]\nExplanation:\n- For i = 0:\n - Node 1 is marked at t = 1.\n- For i = 1:\n - Node 0 is marked at t = 2.\n\nExample 3:\n\nInput: edges = [[2,4],[0,1],[2,3],[0,2]]\nOutput: [4,6,3,5,5]\nExplanation:\n\nConstraints:\n\n- 2 <= n <= 10^5\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= edges[i][0], edges[i][1] <= n - 1\n- The input is generated such that edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [0, 2]]) == [2, 4, 3]\n assert candidate(edges = [[3, 1], [3, 0], [1, 2]]) == [4, 3, 4, 3]\n assert candidate(edges = [[1, 0], [2, 0], [3, 0], [4, 1], [5, 2]]) == [3, 5, 5, 5, 6, 7]\n assert candidate(edges = [[0, 3], [1, 2], [2, 3], [3, 4]]) == [4, 5, 3, 3, 4]\n assert candidate(edges = [[3, 1], [3, 0], [3, 2], [5, 3], [4, 3]]) == [3, 3, 3, 2, 3, 3]\n assert candidate(edges = [[0, 3], [1, 2], [1, 3], [4, 3]]) == [4, 3, 4, 3, 4]\n assert candidate(edges = [[3, 1], [3, 2], [3, 0]]) == [3, 3, 3, 2]\n assert candidate(edges = [[2, 4], [0, 1], [2, 3], [0, 2]]) == [4, 6, 3, 5, 5]\n assert candidate(edges = [[0, 1]]) == [1, 2]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30]]) == [45, 44, 42, 41, 39, 38, 36, 35, 33, 32, 30, 29, 27, 26, 24, 23, 24, 26, 27, 29, 30, 32, 33, 35, 36, 38, 39, 41, 42, 44, 45]\n assert candidate(edges = [[22, 12], [22, 10], [22, 13], [22, 11], [22, 14], [22, 9], [22, 8], [22, 7], [22, 6], [22, 5], [22, 4], [22, 3], [22, 2], [22, 1], [22, 0], [22, 15], [22, 16], [22, 17], [22, 18], [22, 19], [22, 20], [22, 21]]) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30]]) == [8, 10, 9, 11, 11, 11, 11, 12, 12, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 13, 13, 14, 14, 14, 14, 15, 15]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == [5, 6, 7, 7, 7, 9, 9, 8, 8, 9, 9]\n assert candidate(edges = [[0, 10], [0, 11], [0, 12], [10, 1], [11, 2], [12, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == [6, 10, 9, 10, 11, 11, 11, 13, 12, 13, 8, 8, 8]\n assert candidate(edges = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5], [4, 6], [6, 7], [6, 8], [8, 9], [8, 10], [10, 11], [10, 12], [12, 13], [12, 14], [14, 15], [14, 16], [16, 17], [16, 18], [18, 19], [18, 20], [20, 21], [20, 22], [22, 23], [22, 24], [24, 25], [24, 26], [26, 27], [26, 28], [28, 29], [28, 30]]) == [30, 32, 28, 30, 26, 28, 24, 26, 22, 24, 20, 22, 18, 20, 16, 18, 17, 19, 19, 21, 21, 23, 23, 25, 25, 27, 27, 29, 29, 31, 31]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30]]) == [8, 10, 9, 11, 11, 11, 11, 12, 12, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 13, 13, 14, 14, 14, 14, 15, 15]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [4, 5], [4, 6], [6, 7], [7, 8], [7, 9]]) == [9, 8, 9, 7, 5, 7, 6, 8, 9, 9]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == [9, 11, 12, 14, 11, 13, 14, 16, 17, 19, 11, 13, 14, 16, 17, 19]\n assert candidate(edges = [[1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3], [9, 4], [10, 4], [11, 5], [12, 5], [13, 6], [14, 6], [15, 7], [16, 7], [17, 8], [18, 8], [19, 9], [20, 9], [21, 10], [22, 10], [23, 11], [24, 11], [25, 12], [26, 12], [27, 13], [28, 13], [29, 14], [30, 14], [31, 15], [32, 15], [33, 16], [34, 16], [35, 17], [36, 17], [37, 18], [38, 18], [39, 19], [40, 19]]) == [8, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 13, 13, 14, 14, 14, 14, 15, 15, 14, 14, 15, 15, 15, 15, 16, 16, 14, 14, 15, 15, 15, 15, 16, 16, 15, 15]\n assert candidate(edges = [[7, 3], [3, 1], [3, 0], [3, 2], [5, 3], [4, 3], [6, 3]]) == [3, 3, 3, 2, 3, 3, 3, 3]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == [30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 17, 18, 20, 21, 23, 24, 26, 27, 29, 30]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]]) == [22, 21, 19, 18, 16, 15, 13, 12, 12, 14, 15, 17, 18, 20, 21, 23]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13]]) == [6, 8, 6, 9, 9, 8, 8, 10, 10, 11, 9, 9, 10, 10]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21]]) == [6, 8, 7, 8, 9, 9, 9, 9, 9, 9, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11, 10, 10]\n assert candidate(edges = [[0, 1], [0, 2], [1, 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], [11, 21], [11, 22], [12, 23], [12, 24], [13, 25], [13, 26], [14, 27], [14, 28], [15, 29], [15, 30], [16, 31], [16, 32], [17, 33], [17, 34], [18, 35], [18, 36], [19, 37], [19, 38], [20, 39], [20, 40]]) == [10, 12, 11, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 16, 16, 17, 17, 17, 17, 18, 18, 17, 17, 18, 18, 18, 18, 19, 19, 17, 17, 18, 18, 18, 18, 19, 19]\n assert candidate(edges = [[1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3], [9, 4], [10, 4], [11, 5], [12, 5], [13, 6], [14, 6], [15, 7], [16, 7], [17, 8], [18, 8], [19, 9], [20, 9], [21, 10], [22, 10], [23, 11], [24, 11], [25, 12], [26, 12], [27, 13], [28, 13], [29, 14], [30, 14]]) == [8, 10, 9, 11, 11, 11, 11, 12, 12, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 13, 13, 14, 14, 14, 14, 15, 15]\n assert candidate(edges = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5], [4, 6], [4, 7], [6, 8], [6, 9], [6, 10], [8, 11], [8, 12], [8, 13], [10, 14], [10, 15], [10, 16]]) == [10, 12, 8, 10, 6, 8, 7, 8, 9, 9, 9, 11, 11, 11, 11, 11, 11]\n assert candidate(edges = [[2, 3], [1, 2], [5, 3], [0, 5], [4, 5], [6, 5], [7, 6], [8, 7], [9, 8], [10, 9], [11, 10], [12, 11], [13, 12], [14, 13], [15, 14], [16, 15], [17, 16], [18, 17], [19, 18], [20, 19], [21, 20], [22, 21], [23, 22], [24, 23], [25, 24], [26, 25], [27, 26], [28, 27], [29, 28]]) == [37, 40, 38, 37, 37, 36, 34, 33, 31, 30, 28, 27, 25, 24, 22, 21, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 40]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39]]) == [58, 57, 55, 54, 52, 51, 49, 48, 46, 45, 43, 42, 40, 39, 37, 36, 34, 33, 31, 30, 30, 32, 33, 35, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51, 53, 54, 56, 57, 59]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 10], [10, 11], [11, 12], [12, 13], [13, 14], [0, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == [8, 10, 11, 13, 14, 10, 11, 13, 14, 16, 9, 11, 12, 14, 15, 10, 11, 13, 14, 16]\n assert candidate(edges = [[0, 1], [1, 2], [0, 3], [3, 4], [4, 5], [0, 6], [6, 7], [7, 8], [8, 9]]) == [6, 8, 9, 8, 9, 11, 6, 8, 9, 11]\n assert candidate(edges = [[10, 0], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19]]) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [13, 12, 10, 9, 7, 8, 9, 11, 12, 14]\n assert candidate(edges = [[1, 0], [2, 0], [3, 0], [4, 1], [5, 1], [6, 2], [7, 2], [8, 3], [9, 3], [10, 4], [11, 4], [12, 5], [13, 5], [14, 6], [15, 6], [16, 7], [17, 7], [18, 8], [19, 8], [20, 9], [21, 9]]) == [6, 8, 7, 8, 9, 9, 9, 9, 9, 9, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11, 10, 10]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11], [5, 12], [5, 13], [6, 14], [6, 15], [7, 16], [7, 17], [8, 18], [8, 19], [9, 20], [9, 21], [10, 22], [10, 23], [11, 24], [11, 25], [12, 26], [12, 27], [13, 28], [13, 29], [14, 30], [14, 31], [15, 32], [15, 33], [16, 34], [16, 35], [17, 36], [17, 37], [18, 38], [18, 39], [19, 40], [19, 41]]) == [8, 10, 9, 10, 11, 11, 11, 11, 11, 11, 13, 13, 12, 12, 13, 13, 12, 12, 13, 13, 12, 12, 15, 15, 14, 14, 14, 14, 13, 13, 15, 15, 14, 14, 14, 14, 13, 13, 15, 15, 14, 14]\n assert candidate(edges = [[8, 6], [8, 7], [0, 5], [0, 4], [0, 3], [0, 8], [0, 1], [0, 2]]) == [4, 6, 6, 6, 6, 6, 6, 6, 4]\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]]) == [4, 6, 5, 6, 7, 7, 7, 7, 7, 7]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == [6, 8, 7, 9, 9, 9, 9, 10, 10, 11, 11, 10, 10, 11, 11]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22]]) == [7, 8, 9, 9, 9, 11, 11, 10, 10, 11, 11, 12, 12, 13, 13, 11, 11, 12, 12, 12, 12, 13, 13]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == [5, 6, 7, 7, 7, 9, 9, 8, 8, 9, 9]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [13, 12, 10, 9, 7, 8, 9, 11, 12, 14]\n assert candidate(edges = [[10, 0], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9]]) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2]\n assert candidate(edges = [[1, 0], [2, 0], [3, 1], [4, 1], [5, 2], [6, 2], [7, 3], [8, 3], [9, 4], [10, 4], [11, 5], [12, 5], [13, 6], [14, 6], [15, 7], [16, 7], [17, 8], [18, 8], [19, 9], [20, 9]]) == [6, 8, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 11, 11, 12, 12, 12, 12]\n assert candidate(edges = [[1, 0], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == [19, 18, 16, 15, 13, 12, 10, 11, 12, 14, 15, 17, 18, 20]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26]]) == [7, 9, 9, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 13, 13, 14, 14]\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [10, 9, 7, 6, 6, 8, 9, 11]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [9, 20], [10, 21], [10, 22], [11, 23], [11, 24], [12, 25], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30], [15, 31], [15, 32], [16, 33], [16, 34], [17, 35], [17, 36], [18, 37], [18, 38], [19, 39], [19, 40], [20, 41], [20, 42], [21, 43], [21, 44], [22, 45], [22, 46], [23, 47], [23, 48], [24, 49], [24, 50]]) == [9, 10, 11, 11, 11, 13, 13, 12, 12, 13, 13, 14, 14, 15, 15, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 14, 14, 15, 15, 15, 15, 16, 16, 15, 15, 16, 16, 16, 16, 17, 17, 16, 16, 17, 17]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 12], [6, 13], [7, 14], [7, 15], [8, 16], [8, 17], [9, 18], [9, 19], [10, 20], [10, 21], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [13, 27], [14, 28], [14, 29], [15, 30], [15, 31], [16, 32], [16, 33], [17, 34], [17, 35], [18, 36], [18, 37], [19, 38], [19, 39], [20, 40], [20, 41], [21, 42], [21, 43], [22, 44], [22, 45], [23, 46], [23, 47], [24, 48], [24, 49], [25, 50], [25, 51], [26, 52], [26, 53], [27, 54], [27, 55], [28, 56], [28, 57], [29, 58], [29, 59]]) == [11, 10, 10, 11, 12, 12, 12, 12, 14, 14, 13, 13, 14, 14, 13, 13, 16, 16, 15, 15, 15, 15, 14, 14, 16, 16, 15, 15, 15, 15, 14, 14, 18, 18, 17, 17, 17, 17, 16, 16, 17, 17, 16, 16, 16, 16, 15, 15, 18, 18, 17, 17, 17, 17, 16, 16, 17, 17, 16, 16]\n assert candidate(edges = [[15, 11], [15, 10], [15, 12], [15, 9], [15, 14], [15, 8], [15, 13], [15, 7], [15, 6], [15, 5], [15, 4], [15, 3], [15, 2], [15, 1], [15, 0]]) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7], [7, 8], [7, 9]]) == [6, 5, 6, 4, 5, 4, 5, 5, 6, 6]\n assert candidate(edges = [[6, 3], [6, 0], [6, 4], [1, 6], [2, 6], [5, 6]]) == [4, 4, 4, 4, 4, 4, 2]\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [5, 8], [5, 9]]) == [6, 5, 4, 6, 6, 6, 7, 7, 7, 7]\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [5, 9], [5, 10], [6, 11], [6, 12]]) == [6, 8, 6, 9, 9, 8, 8, 10, 10, 9, 9, 10, 10]\n assert candidate(edges = [[25, 18], [25, 24], [25, 19], [25, 20], [25, 21], [25, 22], [25, 23], [25, 2], [25, 0], [25, 1], [25, 10], [25, 11], [25, 12], [25, 13], [25, 14], [25, 15], [25, 16], [25, 17], [25, 3], [25, 4], [25, 5], [25, 6], [25, 7], [25, 8], [25, 9]]) == [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, 2]\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,2]]", "[[0,1]]", "[[2,4],[0,1],[2,3],[0,2]]"], "hints": ["Can we use dp on trees?", "Store the two most distant children for each node.", "When re-rooting the tree, keep a variable for distance to the root node."], "metadata": {"canonical_parameter_names": ["edges"], "leetcode_dataset_entry_point": "Solution().timeTaken", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:18:10+00:00", "tests_total": 54, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "tree", "depth-first-search", "graph", "dp-on-trees"]}, "language": "ruby", "interface": {"raw_signature": "def time_taken(edges)", "container": null, "callable": "time_taken", "parameters": [{"name": "edges", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}}